// const extConfig = tt.getExtConfigSync ? tt.getExtConfigSync() : {}
// let appVersion = extConfig.appVersion;
var app = getApp();
const config = require('../../config/config.js')
const Http = require('../../utils/HttpBasics.js')

Page({
  data: {
    cashOutOpenHeadImg:"",//用户头像
    cashOutOpenNickName:"",//用户名
    cashOutCount: "",//当日已提现次数
    cashOutNumber: "", // 可提现余额
    cashOutSupport: "",//  1 - 支持提现  0-不支持提现
    cashOutLimit: "",//  当日提现次数限制
    city: '',
    userInfo: {},
    flag: 'hidden',
    isSet:false,
    haveData: false
  },
  toDetail() {
    tt.navigateTo({
      url: `./signInDetail/signInDetail?userInfo=${this.data.userInfo}`
    })
  },
  phone(e){
    tt.makePhoneCall({
      phoneNumber: e.currentTarget.dataset.phone 
    })
  },
  toExit() {
    console.log(1)
    tt.reLaunch({
      url: '/pages/login/login',
    })
  },
  showVersion: function () {
    /**
     * 长按显示版本号
     */
    let that = this;
    if (that.data.flag == 'hidden') {
      that.setData({
        flag: 'show'
      });
    }
    console.log(that.data.flag)
  },
  //获取提现信息
  getTx(){
    Http.get({
      url: config.api.balance
    }).then(res=>{
      console.log(111)
      this.setData({
        cashOutCount: res.data.cashOutCount,//当日已提现次数
        cashOutNumber: res.data.cashOutNumber, // 可提现余额
        cashOutSupport: res.data.cashOutSupport,//  1 - 支持提现  0-不支持提现
        cashOutLimit: res.data.cashOutLimit,//  当日提现次数限制
        withdrawNun: res.data.cashOutLimit - res.data.cashOutCount,
        cashOutOpenHeadImg: res.data.cashOutOpenHeadImg,
        cashOutOpenNickName: res.data.cashOutOpenNickName

      })
    }).catch(err=>{
      tt.showToast({
        title: err.message,
        icon:"none",
        duration:2000
      })
    })
  },
  onLoad(){
    // this.findJurisdiction()
  },
  onShow(){
    this.getTx()
    app.globalData.userInfo().then(res => {
      this.setData({
        userInfo: res
      })
      console.log(this.data.userInfo)
      if (this.data.userInfo.merchant_id){
        this.findAccountById(this.data.userInfo.merchant_id);
      }
    })
    // this.setData({
    //   appVersion:appVersion
    // })
  },
  //提现按钮
  withdraw(){
    console.log(this.data.cashOutOpenNickName)
    tt.navigateTo({
      url: `/pages/withdraw/withdraw?money=${this.data.cashOutNumber}&userTop=${this.data.cashOutOpenHeadImg}&userName=${this.data.cashOutOpenNickName}`,
    })
  },
  /**
   * 查询是否有修改账户权限
   */
  findJurisdiction(){
    Http.get({
      url: config.api.permitModifiy,
    }).then(res => {
      console.log(res)
      /**
       * data:true
       * 如有：显示
       * 没有；不显示
       */
      if (res && res.data == true) {
        this.setData({
          haveData: true,
        })
      } else {
        this.setData({
          haveData: false,
        })
      }
    }).catch(error => {
      console.log(error)
    })
  },

  /**
   * 查询收款账户状态
   */
  findAccountById(merchant_id){
    Http.get({
      url: config.api.findAccountById,
      data:{
        id: merchant_id
      }
    }).then(res=>{
      console.log(res)
      /**
       * receiverAccount
       * 如有：已设置收款账户
       * 没有；未设置收款账户
       */
      if (res && res.data && res.data.receiverAccount){
        this.setData({
          isSet: true,
          receiverAccount: res.data.receiverAccount,
          receiverComments: res.data.receiverComments,
          receiverType: res.data.receiverType
        })
      }else{
        this.setData({
          isSet: false
        })
      }
    }).catch(error=>{
      console.log(error)
    })
  }
})