<template>
  <h-view class="public-style electronic-contract-list" title="合同文本清单">
    <h-content>
      <div style="margin-top:20px">
        <div class="contract-list-item" v-for="(item,index) in data " :key="index">
          <img src="../../../assets/electronicContract/contract-list.png" alt />
          <div class="contract-list-text">
            <div>合同下载</div>
            <p style="margin-top:3px">{{item.file_sign_name}}</p>
          </div>
          <button
            style="float:right;margin-top:5px;background-color:#09bb07;color:#ffffff;width:70px;border-radius:3px"
            @click="downloadContract(item.attachment_id)"
          >下载</button>
        </div>
      </div>
      <!-- <div class="footer" @click="createSign()">签约</div> -->
    </h-content>
  </h-view>
</template>

<script>
export default {
  data() {
    return {
      isModalVisible: false,
      con_list: [],
      infoShow: {},
      info: null,
      searchCondition: {
        input: null
      },
      data: []
    };
  },
  components: {},
  created() {
    this.wxConfig();
    if (this.$route.params.itemData) {
      window.localStorage.SignDownloadData = JSON.stringify(
        this.$route.params.itemData.sign_file_list
      );
    }
    // console.log(JSON.parse(window.localStorage.unSignData));
    this.data = JSON.parse(window.localStorage.SignDownloadData);
    this.offsize = 1;
    this.pagesize = 10;
    this.index = [1, 0, 0];
  },
  mounted() {
    // this._initLoad()
  },
  activated(){
    this.wxConfig();
    if (this.$route.params.itemData) {
      window.localStorage.SignDownloadData = JSON.stringify(
        this.$route.params.itemData.sign_file_list
      );
    }
    // console.log(JSON.parse(window.localStorage.unSignData));
    this.data = JSON.parse(window.localStorage.SignDownloadData);
  },
  methods: {
    // createSign() {
    //     let url = "http://sign.hitachics.com/core/r/api/app/fileViewSvc?attachment_id=13435&apiName=download&sysName=HCL_UPLOAD_FILE&access_token="+window.localStorage.access_token_rl
    //     // this.hlsPopup.showLoading("请稍等");
    //     window.open(url, "_self");

    // },
    // 合同下载
    downloadContract(id) {
      if (id) {
        let url =
          process.env.rootPath +
          "/app/fileViewSvc?attachment_id=" +
          id +
          "&apiName=download&sysName=HCL_UPLOAD_FILE&access_token=" +
          window.localStorage.access_token_rl;
          //  let url = "http://sign.hitachics.com/core/r/api/app/fileViewSvc?attachment_id=13435&apiName=download&sysName=HCL_UPLOAD_FILE&access_token="+window.localStorage.access_token_rl
        window.open(url);
      }else{
        this.$vux.toast.text("合同id不存在，无法下载!", "middle");
      }

    },
    // 调用微信接口的基础配置
    wxConfig() {
      let clientUrl = "";
      let u = navigator.userAgent;
      let isAndroid = u.indexOf("Android") > -1 || u.indexOf("Linux") > -1; //g
      let isIOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
      if (isAndroid) {
        //这个是安卓操作系统
        console.log("机型：android");
        clientUrl = location.href;
      }
      if (isIOS) {
        //这个是ios操作系统
        console.log("机型：ios");
        clientUrl = location.href.split("#")[0];
      }
      // let url = $config.rootPath + '/js/sdk/getWxConfig?wxCode=' + $config.wxCode + '&clientUrl=' + clientUrl
      let url = process.env.basePathRl + "getSignature";
      let param = {
        apiKey: "handexinxi",
        url: clientUrl
      };
      hlsHttp.post(url, param).then(function(res) {
        wx.config({
          beta: true,
          debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
          appId: res.result.appId, // 必填，公众号的唯一标识
          timestamp: res.result.timestamp, // 必填，生成签名的时间戳
          nonceStr: res.result.nonceStr, // 必填，生成签名的随机串
          signature: res.result.signature, // 必填，签名，见附录1
          jsApiList: [
            "chooseImage",
            "previewImage",
            "downloadImage",
            "getLocalImgData",
            "uploadImage",
            "hideOptionMenu"
          ] // 必填，需要使用的JS接口列表，所有JS接口列表见附录2
        });
        wx.ready(function() {
          wx.hideOptionMenu();
        });
      });
    }
  }
};
</script>

<style lang="less" rel="stylesheet">
.electronic-contract-list {
  .content {
    // overflow: hidden;
    font-size: 14px;
    .contract-list-item {
      height: 60px;
      margin: 10px 20px;
      border: 1px solid #b2b2b2;
      padding: 14px 10px 0 10px;
      img {
      }
      .contract-list-text {
        display: inline-block;
        margin-left: 30px;
      }
    }
    .footer {
      width: 120px;
      line-height: 30px;
      background-color: #09bb07;
      text-align: center;
      color: #ffffff;
      border-radius: 5px;
      margin: 50px auto;
    }
  }
}
</style>
