// packageH/signPage/identifyResult/identifyResult.js
const app = getApp();
Page({
  data: {
    show: "",
    company: {},
    person: {},
    noIdentify: false,
  },

  onLoad: function (options) {
    let show = options.show;
    this.setNavigationBar(show);
    this.setData({
      show: show,
    });
    if (this.timer) {
      clearInterval(this.timer);
    }
    if (show === "company") {
      this.getCompanyData();
    } else {
      this.getPersonData();
    }
  },

  // 设置导航栏标题
  setNavigationBar (type) {
    if (type == "person") {
      wx.setNavigationBarTitle({
        title: '个人认证结果'
      });
    } else {
      wx.setNavigationBarTitle({
        title: '企业认证结果'
      });
    }
  },
  // methods
  toSign(event) {
    let str = '';
    let url = '';
    let eventData = event.target.dataset;
    if (eventData.str) str = eventData.str;
    console.log(eventData);
    if (str == 1) {
      url = '/packageH/signPage/signCompany/signCompany';
    } else if (str == "home") {
      url = '/packageH/signPage/contractList/contractList';
    } else {
      url = '/packageH/signPage/personBank/personBank';
    }
    wx.redirectTo({
      url,
    });
  },


  // 获取个人信息
  getPersonData() {
    let requestUrl = app.getNetAddresss("plugin.yun-sign.frontend.h5.person.check-person-approve");
    app._getNetWork({
      url: requestUrl,
      success: (resdata)=> {
        let res = resdata.data;
        if (res.result === 1) {
          this.setData({
            person: res.data
          });
        } else {
          this.setData({
            noIdentify: true
          });
          // wx.showModal({
          //   content: res.msg,
          //   showCancel: false
          // });
          app.tips(res.msg);
        }
      }
    });
  },

  // 获取企业信息
  getCompanyData() {
    let that = this;
    let requestUrl = app.getNetAddresss("plugin.yun-sign.frontend.company.check-company-approve");
    app._getNetWork({
      url: requestUrl,
      success (resdata) {
        let res = resdata.data;
        if (res.result === 1) {
          that.setData({
            company: res.data,
            status: res.data.status
          });
          if (that.data.status == "NO_INIT") {
            if (that.timer) {
              clearInterval(that.timer);
            }
          } else if (that.data.status == "ING") {
            if (!that.timer) {
              that.timer = setInterval(() => {
                this.getCompanyData();
              }, 30000);
            }
          } else {
            if (that.timer) {
              clearInterval(that.timer);
            }
            setTimeout(()=>{
              wx.redirectTo({
                url: '/packageH/signPage/contractList/contractList',
              });
            },3000);
          }
        }
      },
      fial (err) {
        console.log(err, "-------err--------");
      }
    });
  },

  // 拨打电话
  freeTell () {
    wx.makePhoneCall({
      phoneNumber: '0755-66635068',
    });
  }
});
