// shopping/pages/withdrawal/withdrawal.js
// 获取应用实例
const app = getApp()
Page({

    /**
     * 页面的初始数据
     */
    data: {
      pingtainame:'微信',
      pingtaiimage:'/shopping/image/WeChat.png',
      second:'',
      money:'',
      allmoney:'',
      show: false,
      type:1,//1为微信，2为支付宝
      name:'',
      alipay_no:'',
      is_ok_click:false,
      actions: [
        { name: '支付宝',color: '#464646;',imagesrc:'/shopping/image/Alipay.png'},
      ],
    },
    onClose() {
      // wx.showToast({ title: '点击成功', icon: 'none' });
      this.setData({ show: false });
    },
    onCancel(){
      // wx.showToast({ title: '点击成功', icon: 'none' });
      this.setData({ show: false });
    },
    openSelect(){
      // wx.showToast({ title: '点击成功', icon: 'none' });
      this.setData({ show: true });
    },
  
    onSelect() {
      if(this.data.type==1){
          this.setData({
          show: false ,
          type:2,
          pingtainame:'支付宝',
          pingtaiimage:'/shopping/image/Alipay.png',
          actions: [
           { name: '微信',color: '#464646;',imagesrc:'/shopping/image/WeChat.png'},
       ],
     });
    }else{
      this.setData({
        show: false ,
        type:1,
        pingtainame:'微信',
        pingtaiimage:'/shopping/image/WeChat.png',
        actions: [
          { name: '支付宝',color: '#464646;',imagesrc:'/shopping/image/Alipay.png'},
        ],
     });
     }
   
      
      // wx.navigateTo({
      //   url: '../payment/payment',
      // })
    },
   

    switch(){
    wx.navigateTo({
      url: '../payment/payment',
    })
    },
    cancel(){
        wx.switchTab({
          url: '/pages/my/my',
        })
      },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
      console.log(options.money)
      this.setData({
        money:options.money
      })
     
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    },
 
     // 提现
  confirm_pay: async function (){
    var that = this;
    if (!this.data.is_ok_click){
      that.setData({
        is_ok_click:true
      })
    
           
       //你要执行的操作      
       this.tixian()
      setTimeout(function () {
        that.setData({
          is_ok_click: false
        })
      }, 10000) //阻止一秒点击多次
    }else{
      // wx.showToast({ title: '请勿重复操作！', icon: 'none' });
    }
  },

    tixian:function(e){
      app.console(this.data.second+"================="+this.data.name+"==================="+this.data.alipay_no)
      if(this.data.type==1){
        this.wechatWithdrawal();
      }else{
        this.alipayWithdrawal()
      }
     
    }
  //这个函数一定要写在标签上才能用e.detail.value获取到
  ,
    moneyInput:function( e ){
    this.setData({
      second: e.detail.value
    });
    
  } ,
  //支付宝账号
  zfzhanghao:function(e){
    this.setData({
      alipay_no: e.detail.value
    });
  },
  //收款人姓名
  zfname:function(e){
    this.setData({
      name: e.detail.value
    });
  },
  //点击全部
  allmoney:function(e){
  
    app.console(this.data.money+"================="+222)
    this.setData({
      allmoney:this.data.money,
      second:this.data.money
    });
  },
 
  //微信提现
  wechatWithdrawal: function () {
    var that = this;
    wx.request({
        url: app.buildUrl("/app/Goddesswechat/wechatWithdrawal"),
        header: app.getRequestHeader(),
        method:'POST',
        data: {
          version_number: app.globalData.version_number,
          uid:wx.getStorageSync('uid'),
          token:wx.getStorageSync('token'),
          money:this.data.second  
        },
        success: (res)=>  {
            var resp = res.data;
            console.log(resp+"=================dddddddddddddddddddddddddddddddddddddddddddd")
           
            if(resp.erro==0){
              wx.showToast({ title: res.data.msg, icon: 'none' });
              setTimeout(function () {
              //要延时执行的代码
              wx.navigateBack()
              }, 2000) //延迟时间 这里是2秒     

            }else{
              wx.showToast({ title: res.data.msg, icon: 'none' });
            }
        }
    });
},

//支付宝提现
alipayWithdrawal: function () {
  var that = this;
  wx.request({
      url: app.buildUrl("app/Goddesswechat/alipayWithdrawal"),
      header: app.getRequestHeader(),
      method:'POST',
      data: {
        version_number: app.globalData.version_number,
        uid:wx.getStorageSync('uid'),
        token:wx.getStorageSync('token'),
        money:this.data.second,
        name:this.data.name,
        alipay_no:this.data.alipay_no
      },
      success: (res)=>  {
          var resp = res.data;
          console.log(resp+"=================dddddddddddddddddddddddddddddddddddddddddddd")
        
          if(resp.erro==0){
            wx.showToast({ title: res.data.msg, icon: 'none' });
            setTimeout(function () {
              //要延时执行的代码
              wx.navigateBack()
            }, 2000) //延迟时间 这里是2秒     
         
          }
      }
  });
},
})