<template>
  <div class="content">
    <div class="title-box">
      <div class="title">{{ infoObj.title }}</div>
      <div class="title-time">
        <p class="time">{{ infoObj.publish_time | globalTime }}</p>
        <p class="read-count">
          阅读量
          {{
            Number(infoObj.base_read_count) + Number(infoObj.real_read_count)
          }}
        </p>
      </div>
    </div>
    <div class="video-box" v-if="infoObj.video_url">
      <video :src="infoObj.video_url" id="myVideo" controls="true"></video>
    </div>
    <!-- 企业研发投入补贴 -->
    <div class="card-input-content">
      <div class="card-input">
        <div class="card-title">{{ infoObj.project_name }}</div>
        <div class="table">
          <p class="table-item">
            <span>项目金额:</span>
            <span>{{ infoObj.project_money }}</span>
          </p>
          <p class="table-item">
            <span>申报时间:</span>
            <span
              >{{ infoObj.project_start_date }} 至
              {{ infoObj.project_end_date }}</span
            >
          </p>
          <p class="table-item">
            <span>申报状态:</span>
            <span>剩
              {{
                Math.floor(new Date(
                  new Date(infoObj.project_end_date).getTime() -
                    new Date().getTime()
                ).getTime() /
                  (1 * 24 * 60 * 60 * 1000)) + 1
              }}
              天</span>
          </p>
        </div>
      </div>
    </div>
    <!-- 项目概况 -->
    <div class="card-situation" v-if="infoObj.project_desc">
      <div class="card-title">项目概况</div>
      <p>
        {{ infoObj.project_desc }}
      </p>
    </div>

    <!-- 	<div class="card-group" v-for="(item, idx) in model" :key="idx">
	  <policy-deatil-card :model="item" :isMar="idx == model.length - 1"></policy-deatil-card>
	</div> -->
    <div class="card-group">
      <div class="content-basic">
        <div class="card-title">基本信息</div>
        <div class="item-list">
          <div class="term">
            <div class="term-name">项目名称:</div>
            <div class="term-value-group">
              <p class="term-value-item">{{ infoObj.project_name }}</p>
            </div>
          </div>
          <div class="term">
            <div class="term-name">受理部门:</div>
            <div class="term-value-group">
              <p class="term-value-item">{{ infoObj.sponsor_name }}</p>
            </div>
          </div>
          <div class="term">
            <div class="term-name">政策层级:</div>
            <div class="term-value-group">
              <p class="term-value-item">{{ infoObj.level }}</p>
            </div>
          </div>
          <div class="term">
            <div class="term-name">信息提供日期:</div>
            <div class="term-value-group">
              <p class="term-value-item">
                {{ infoObj.publish_time | globalTime }}
              </p>
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="card-group">
      <div class="content-basic">
        <div class="card-title">支持力度</div>
        <div class="item-list">
          <div class="term">
            <div class="term-name">支持金额:</div>
            <div class="term-value-group">
              <p class="term-value-item">{{ infoObj.project_money }}</p>
            </div>
          </div>
          <div class="term">
            <div class="term-name">资助标准:</div>
            <div class="term-value-group">
              <p class="term-value-item" v-html="infoObj.lidu"></p>
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="content-rich" :class="{ 'margin-bottom-80': true }">
      <div class="card-title">{{ textModel1.title }}</div>
      <div class="item-list">
        <div class="term">
          <div class="term-value-group">
            <p class="term-value-item" v-html="textModel1.text"></p>
          </div>
        </div>
      </div>
    </div>
    <div class="content-rich" :class="{ 'margin-bottom-80': true }">
      <div class="card-title">{{ textModel2.title }}</div>
      <div class="item-list">
        <div class="term">
          <div class="term-value-group">
            <p class="term-value-item" v-html="textModel2.text"></p>
          </div>
        </div>
      </div>
    </div>
    <div class="content-rich" :class="{ 'margin-bottom-80': true }">
      <div class="card-title">{{ textModel3.title }}</div>
      <div class="item-list">
        <div class="term">
          <div class="term-value-group">
            <p class="term-value-item" v-html="textModel3.text"></p>
          </div>
        </div>
      </div>
    </div>
    <div class="content-rich" :class="{ 'margin-bottom-80': true }">
      <div class="card-title">联系方式</div>
      <div class="item-list">
        <div class="term">
          <div class="term-value-group">
            <p class="term-value-item">{{ infoObj.contact }}</p>
          </div>
        </div>
      </div>
    </div>
    <div style="width: 100%">
      <footer-share
        style="width: 100%"
        :isCollection="true"
        :isCollectedIcon="infoObj.if_collect"
        @collectionPages="collectionPage"
        @sharePages="sharePage"
      ></footer-share>
    </div>
  </div>
</template>

<script>
import policy_deatil_card from "./policy_deatil_card";
import policy_rich_card from "./policy_rich_card";
import md5 from "@/common/md5.js";
export default {
  components: {
    policyDeatilCard: policy_deatil_card,
    policyRichCard: policy_rich_card,
  },
  data() {
    return {
      model: [],
      levelList: {
        1: "省级政策",
        2: "市级政策",
        3: "区级政策",
        4: "新城政策",
      },
      id: "",
	  pageId:'',
      textModel1: {
        title: "申报条件",
        text: "",
      },
      textModel2: {
        title: "申报材料",
        text: "",
      },
      textModel3: {
        title: "申报途径",
        text: "",
      },
      // textModel4: {
      //   title: "联系方式",
      //   text: "",
      // },
      scrollTop: 0,
      infoObj: {},
    };
  },
  onLoad(option) {
    this.pageId = option.id;
   // this.getDetailInfo(id);
	this.getUserAuth();
  },
  onShow() {
	this.getDetailInfo(this.pageId);
  },
  methods: {
	goAuthPage(){
		uni.navigateTo({
			url:'../auth/index'
		})
	},
	getUserAuth(){
		let md5Sign = md5("method="+'user'+"&timestamp="+getApp().globalData.globalTimestamp+"&secret="+getApp().globalData.secret)
		let url = getApp().globalData.shareUrl+'api/api.php'+'?method=user&action=info_by_openid&timestamp='+getApp().globalData.globalTimestamp +'&sign='+md5Sign
		uni.request({
			url:url,
			method: 'POST',
			header: {
				'content-type': 'application/x-www-form-urlencoded'
			},
			data: {
					openId:getApp().globalData.open_id
			},
			success: (res) => {
				if(res.data.code === 200){
					res.data.data.nickname ? getApp().globalData.user_name = res.data.data.nickname :getApp().globalData.user_name = ''
				}
			},
			fail: () => {
				console.log("连接失败");
			}
		});
	},
    getDetailInfo(ids) {
      let md5Sign = md5(
        "method=" +
          "common" +
          "&timestamp=" +
          getApp().globalData.globalTimestamp +
          "&secret=" +
          getApp().globalData.secret
      );
      let url =
        getApp().globalData.shareUrl +
        "api/api.php" +
        "?method=common&source=policy&action=info_by_id&timestamp=" +
        getApp().globalData.globalTimestamp +
        "&sign=" +
        md5Sign;
      uni.request({
        url: url,
        method: "POST",
        header: {
          "content-type": "application/x-www-form-urlencoded",
        },
        data: {
          id: ids,
          openId: getApp().globalData.open_id,
        },
        success: (res) => {
          if (res.data.code === 200) {
            if (res.data.data.video_url) {
              res.data.data.video_url =
                getApp().globalData.shareUrl + res.data.data.video_url;
            }
            res.data.data.level = this.levelList[res.data.data.level];
            this.infoObj = res.data.data;
            this.getRich1(ids);
            this.getRich2(ids);
            this.getRich3(ids);
            this.getRich4(ids);
          }
        },
        fail: () => {
          console.log("连接失败");
        },
      });
    },
    getRich1(ids) {
      uni.request({
        url: `https://kiq.xazhima.com/content/policy/${Math.floor(
          ids / 1000
        )}/${ids}_1.html`,
        method: "GET",
        header: {
          "content-type": "application/x-www-form-urlencoded",
        },
        success: (res) => {
          if (res.statusCode === 200) {
            this.$set(this.infoObj, "lidu", res.data);
          }
        },
        fail: () => {
          console.log("连接失败");
        },
      });
    },
    getRich2(ids) {
      uni.request({
        url: `https://kiq.xazhima.com/content/policy/${Math.floor(
          ids / 1000
        )}/${ids}_2.html`,
        method: "GET",
        header: {
          "content-type": "application/x-www-form-urlencoded",
        },
        success: (res) => {
          if (res.statusCode === 200) {
            this.$set(this.textModel1, "text", res.data);
          }
        },
        fail: () => {
          console.log("连接失败");
        },
      });
    },
    getRich3(ids) {
      uni.request({
        url: `https://kiq.xazhima.com/content/policy/${Math.floor(
          ids / 1000
        )}/${ids}_3.html`,
        method: "GET",
        header: {
          "content-type": "application/x-www-form-urlencoded",
        },
        success: (res) => {
          if (res.statusCode === 200) {
            this.$set(this.textModel2, "text", res.data);
          }
        },
        fail: () => {
          console.log("连接失败");
        },
      });
    },
    getRich4(ids) {
      uni.request({
        url: `https://kiq.xazhima.com/content/policy/${Math.floor(
          ids / 1000
        )}/${ids}_4.html`,
        method: "GET",
        header: {
          "content-type": "application/x-www-form-urlencoded",
        },
        success: (res) => {
          if (res.statusCode === 200) {
            this.$set(this.textModel3, "text", res.data);
          }
        },
        fail: () => {
          console.log("连接失败");
        },
      });
    },
    collectionPage() {
	if(!getApp().globalData.user_name){
				this.goAuthPage();
				return
	   }
      let md5Sign = md5(
        "method=" +
          "user" +
          "&timestamp=" +
          getApp().globalData.globalTimestamp +
          "&secret=" +
          getApp().globalData.secret
      );
      let url =
        getApp().globalData.shareUrl +
        "api/api.php" +
        "?method=user&source=policy&action=collect_add&timestamp=" +
        getApp().globalData.globalTimestamp +
        "&sign=" +
        md5Sign;
      uni.request({
        url: url,
        method: "POST",
        header: {
          "content-type": "application/x-www-form-urlencoded",
        },
        data: {
          openId: getApp().globalData.open_id,
          source: "policy",
          source_name: "政策",
          source_id: this.infoObj.id,
          source_title: this.infoObj.title,
        },
        success: (res) => {
          if (res.data.code === 200) {
            res.data.data
              ? (this.infoObj.if_collect = true)
              : (this.infoObj.if_collect = false);
            this.$forceUpdate();
            uni.showToast({
              duration: 3000,
              title: res.data.msg,
              icon: "none",
            });
          }
        },
        fail: () => {
          console.log("连接失败");
        },
      });
    },
    shareRequest() {
      let md5Sign = md5(
        "method=" +
          "user" +
          "&timestamp=" +
          getApp().globalData.globalTimestamp +
          "&secret=" +
          getApp().globalData.secret
      );
      let url =
        getApp().globalData.shareUrl +
        "api/api.php" +
        "?method=user&source=policy&action=repost&timestamp=" +
        getApp().globalData.globalTimestamp +
        "&sign=" +
        md5Sign;
      uni.request({
        url: url,
        method: "POST",
        header: {
          "content-type": "application/x-www-form-urlencoded",
        },
        data: {
          openId: getApp().globalData.open_id,
          source_id: this.infoObj.id,
          source: "policy",
        },
        success: (res) => {
          if (res.data.code === 200) {
            console.log(res);
          }
        },
        fail: () => {
          console.log("连接失败");
        },
      });
    },
    sharePage() {
      let that = this;
	  uni.showShareMenu({
	    title: that.infoObj.title,
	    path: "pages/policy/policy_detail?id=" + that.infoObj.id,
	    success(res) {
	      that.shareRequest();
	    },
	  });
	  // if(!getApp().globalData.user_phone){
	  // 			that.goAuthPage();
	  // 		}else {
			// 	// uni.showShareMenu({
			// 	//   title: that.infoObj.title,
			// 	//   path: "pages/policy/policy_detail?id=" + that.infoObj.id,
			// 	//   success(res) {
			// 	//     that.shareRequest();
			// 	//   },
			// 	// });
			// }
    },
    changeScroll(height) {
      //点的时候触发这个函数 height 是之前的高度
      uni.pageScrollTo({
        scrollTop: this.scrollTop,
        duration: 0,
      });
    },
  },
  onPageScroll(e) {
    this.scrollTop = e.scrollTop;
  },
};
</script>

<style lang="scss" scoped>
* {
  box-sizing: border-box;
}
.footer-share-box {
  margin-left: -20rpx;
}
.content {
  margin-top: 20rpx;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20rpx;
  height: auto;
  .title-box {
    width: 100%;
    display: flex;
    flex-direction: column;
    padding-bottom: 10rpx;
    margin-left: 30rpx;
    .title {
      letter-spacing: 5rpx;
      font-size: 35rpx;
      font-weight: 500;
    }
    .title-time {
      display: flex;
      font-size: 20rpx;
      color: $uni-text-color-grey;
      margin-top: 20rpx;
      .time {
        margin-right: 100rpx;
      }
    }
  }
  .video-box {
    width: 100%;
    // image {
    //   width: 100%;
    //   height: 400rpx;
    //   border-radius: 32rpx;
    // }
  }
  #myVideo {
    width: 100%;
    border-radius: 10rpx;
  }
  .card-input-content {
    width: 100%;
    margin-top: 20rpx;
    .card-input {
      padding: 30rpx 30rpx;
      box-shadow: 0px 4rpx 32rpx rgba(0, 0, 0, 0.1);
      border-radius: 32rpx;
      .card-title {
        font-weight: 600;
        padding: 20rpx 20rpx 0rpx 20rpx;
      }
      .table {
        border-radius: 32rpx;
        background-color: #f2f2f2;
        margin-top: 20rpx;
        display: flex;
        padding: 0 20rpx;
        flex-direction: column;
        .table-item {
          box-sizing: border-box;
          width: 100%;
          margin: 20rpx 0;
          font-size: 27rpx;
          font-weight: 300;
          display: flex;
          justify-content: space-between;
        }
      }
    }
  }

  .card-situation {
    margin-top: 20rpx;
    padding: 20rpx;
    border-top: 8rpx solid #f2f2f2;
    box-shadow: 0px 4rpx 32rpx rgba(0, 0, 0, 0.1);
    border-radius: 32rpx;
    .card-title {
      font-weight: 600;
      padding: 20rpx 20rpx 0rpx 20rpx;
    }
    p {
      padding: 20rpx;
      margin-top: 20rpx;
      font-size: 27rpx;
      letter-spacing: 1rpx;
      line-height: 50rpx;
    }
  }
  .card-group {
    width: 100%;
  }
  .share-collection {
    background-color: #ffffff;
    position: fixed;
    bottom: 0;
    width: 100%;
    height: 80rpx;
    display: flex;
    align-items: center;
    justify-content: space-between;
    .share,
    .collection {
      width: 50%;
      display: flex;
      justify-content: center;
      align-items: center;
      height: 100%;
    }
    .share {
      border-right: 1px solid $uni-border-color;
    }
    image {
      width: 50rpx;
      height: 50rpx;
      margin-left: 40rpx;
    }
  }
  .content-basic {
    box-sizing: border-box;
    margin-top: 20rpx;
    padding: 20rpx;
    box-shadow: 0px 4rpx 32rpx rgba(0, 0, 0, 0.1);
    border-radius: 32rpx;
    width: 100%;
    display: flex;
    flex-direction: column;
    // margin-bottom: 80rpx;
    .card-title {
      padding: 20rpx 20rpx 0rpx 20rpx;
      font-weight: 600;
    }
    .item-list {
      margin-left: 20rpx;
      display: flex;
      flex-direction: column;

      .term {
        display: flex;
        padding: 20rpx;
        .term-name {
          font-size: 27rpx;
          width: 30%;
          display: flex;
          margin: 20rpx;
          color: #7f7f7f;
        }
        .term-value-group {
          flex: 1;
          display: flex;
          flex-direction: column;
          font-size: 27rpx;
          .term-value-item {
            margin: 20rpx;
          }
        }
      }
    }
  }
  .content-rich {
    box-sizing: border-box;
    margin-top: 20rpx;
    padding: 20rpx;
    box-shadow: 0px 4rpx 32rpx rgba(0, 0, 0, 0.1);
    border-radius: 32rpx;
    width: 100%;
    display: flex;
    flex-direction: column;
    // margin-bottom: 80rpx;
    .card-title {
      padding: 20rpx 20rpx 0rpx 20rpx;
      font-weight: 600;
    }
    .item-list {
      margin-left: 20rpx;
      display: flex;
      flex-direction: column;

      .term {
        display: flex;
        padding: 20rpx;
        .term-name {
          font-size: 27rpx;
          width: 30%;
          display: flex;
          margin: 20rpx;
          color: #7f7f7f;
        }
        .term-value-group {
          flex: 1;
          display: flex;
          flex-direction: column;
          font-size: 27rpx;
          .term-value-item {
            margin: 20rpx;
          }
        }
      }
    }
  }
  .margin-bottom-80 {
    margin-bottom: 80rpx;
  }
}
</style>