// pages/balance_withdrawals/balance_withdrawals.js import {payKeyboardAsync} from "../../../../mycomponent/payKeyboard/PayKeyboardAsync.js"; var app = getApp(); Page({ /** * 页面的初始数据 */ data: { mailLanguage:{}, language: '', // 是否提现到微信 withdrawToWechat: 0, // 是否提现到支付宝 withdrawToAlipay: 0, withdrawToManual: 0, supplier: '', balance: 0, service_money: 0, withdrawType: {}, // 提现方法 info_form: { balance_money: '' }, // 选择提现方法 pay_type: '', eupshow: false, popupVisible: false, hxShow: false, action: '', msg: '', notice: '', // 余额字样 balanceLang: '余额', member_id: '', converge_pay: false, // 汇聚按钮显示 show2: false, // 判断 show3: false, // 银行卡列表 withList: [], // 银行卡列表 checkObj: {}, // 选中的银行卡 actual_amount: '', // 实际到账金额 poundageHj: '', // 手续费 cost_money: '', // 提现金额 poundage_name:'', //支付键盘 payKeyboardShow:false, //是否需要支付密码 need_password:false, //是否设置支付密码 has_password:false, manual_name:'' }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { if (options.supplier) { this.setData({ supplier: options.supplier }); } if (options.member_id) { this.setData({ member_id: options.member_id }); } this.customizeIncome(); try { var mailLanguage=JSON.parse(wx.getStorageSync('mailLanguage')); if (mailLanguage) { this.setData({ mailLanguage:mailLanguage, manual_name: mailLanguage.income.name_of_withdrawal + mailLanguage.income.manual_withdrawal }); wx.setNavigationBarTitle({ title: this.data.mailLanguage.income&&this.data.mailLanguage.income.name_of_withdrawal?this.data.mailLanguage.income.name_of_withdrawal:'提现' }); } } catch (e) { console.log(e); } try { var value = wx.getStorageSync('balance'); if (value) { this.setData({ balanceLang: value }); // Do something with return value } } catch (e) { // Do something when catch error } }, //自定义提现收入语言 customizeIncome() { try { var value = wx.getStorageSync('mailLanguage'); if (value) { let mailLanguage = JSON.parse(value); // Do something with return value this.setData({ poundage_name: mailLanguage.income.poundage_name }); } } catch (e) { // Do something when catch error } }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { let language = wx.getStorageSync('langIndex'); this.setData({ 'language': language.en}); }, /** * 生命周期函数--监听页面显示 */ onShow: function () { if (this.data.supplier === 'supplier') { this.getData2(); } else { this.getData(); } }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () {}, /** * 生命周期函数--监听页面卸载 */ onUnload: function () {}, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () {}, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () {}, /** * 用户点击右上角分享 */ onShareAppMessage: function () {}, getData2() { var that = this; let urlStr = app.getNetAddresss('plugin.supplier.frontend.withdraw.index'); urlStr += '&member_id=' + this.data.member_id; app._getNetWork({ url: urlStr, success: function (resdata) { var res = resdata.data; if (res.result == 1) { that.setData({ balance: res.data.cost_money, service_money: res.data.service_money, withdrawType: res.data.type }); console.log(this.data.withdrawType, '类型'); } else { wx.showToast({ icon: 'none', title: res.msg, duration: 1500 }); } }, fail: function (res) { console.log(res); } }); }, // 获取数据 getData() { let that = this; let urlStr = app.getNetAddresss('finance.balance-withdraw.page'); app._getNetWork({ url: urlStr, success: function (resdata) { var res = resdata.data; if (res.result == 1) { that.setData({ balance: res.data.balance, withdrawToAlipay: res.data.alipay, withdrawToWechat: res.data.wechat, withdrawToManual: res.data.manual, poundage: res.data.poundage, eupshow: res.data.eup_pay, converge_pay: res.data.converge_pay, need_password:res.data.need_password, has_password:res.data.has_password }); } else { wx.showToast({ icon: 'none', title: res.msg, duration: 1500 }); } }, fail: function (res) { console.log(res); } }); }, payKeyboardComplete(evt){ payKeyboardAsync.complete(evt.detail); }, getPayKeyboardPassword(){ this.setData({ show2: false, show3: false, payKeyboardShow:true }); return new Promise((resove,reject)=>{ payKeyboardAsync.addCompleteFn((pass)=>{ resove(pass); }); }); // let pass = await this.getPayKeyboardPassword(); // console.log(pass); }, payKeyboardClose(){ this.setData({payKeyboardShow:false}); }, confirm(e) { // this.setData({payKeyboardShow:true}) // return; let type = e.currentTarget.dataset.num; this.setData({ pay_type: type }); switch (this.data.pay_type) { case '1': this.confirmPost(this.data.pay_type); break; case '2': this.confirmPost(this.data.pay_type); break; case '3': this.manualVerify(this.data.pay_type); break; case '4': this.checkEup(this.data.pay_type); break; case '5': this.checkHx(this.data.pay_type); break; case '6': if (this.data.info_form.balance_money == '') { wx.showToast({ title: '请输入提现金额', icon: 'none' }); return; } this.checkHJ(this.data.pay_type); break; default: break; } }, checkOut(e) { let item = e.target.dataset.item || e.currentTarget.dataset.item; item.check = !item.check; let data = this.data.withList; data.map(items => { if (items.id == item.id) { items.check = item.check; } else { items.check = false; } }); if (item.check == true) { this.setData({ show3: false, show2: true, checkObj: item, withList: data }); } }, getToTitle() { let urlStr = app.getNetAddresss('plugin.converge_pay.frontend.controllers.converge-pay-bank-card.set-bank-card'); app._postNetWork({ url: urlStr, data: { set: this.data.checkObj }, success: (resdata) => { var res = resdata.data; if (res.result == 1) { // 有资格提现 this.confirmPost(this.data.pay_type); } else { wx.showToast({ title: res.msg, icon: 'none', duration: 1500 }); } }, fail: function (res) { console.log(res); } }); }, withGotiem() { console.log(this.data.checkObj, '选中的项'); this.getToTitle(); return; }, backGo() { this.setData({ show2: true, show3: false }); }, backTap() { this.setData({ show2: false, show3: false }); }, gotoList() { this.setData({ show2: false, show3: true }); }, async confirmPost(type) { // withdraw_money var that = this; if (parseFloat(this.data.info_form.balance_money) > parseFloat(this.data.balance)) { wx.showToast({ icon: 'none', title: '提现金额不可大于您的'+that.data.balanceLang, duration: 1500 }); return; } if ( this.data.info_form.balance_money == undefined || this.data.info_form.balance_money <= 0 || this.data.info_form.balance_money == 0 ) { wx.showToast({ icon: 'none', title: '提现金额不可低于0', duration: 1500 }); return; } if(this.data.need_password==true && this.data.has_password==false){ let confirmFlag = await app.confirm("请先设置支付密码"); if(confirmFlag) { wx.navigateTo({ url: '/packageA/member/set_balance_password/set_balance_password' }); } return; } let urlStr = app.getNetAddresss('finance.balance-withdraw.withdraw'); urlStr += '&withdraw_type=' + type; urlStr += '&withdraw_money=' + this.data.info_form.balance_money; if(this.data.need_password==true){ //开启支付密码验证 let pass = await this.getPayKeyboardPassword(); urlStr += '&password=' + pass; } app._getNetWork({ url: urlStr, success: function (resdata) { var res = resdata.data; if (res.result == 1) { that.setData({ show2: false }); wx.showToast({ title: res.msg, icon: 'none', duration: 1500, success: function () { setTimeout(function () { // 要延时执行的代码 wx.navigateBack({ delta: 1 }); }, 1500); // 延迟时间 } }); } else { wx.showToast({ icon: 'none', title: res.msg, duration: 1500 }); } }, fail: function (res) { console.log(res); } }); }, // 手动提现验证 manualVerify(type) { var that = this; if (parseFloat(this.data.info_form.balance_money) > parseFloat(this.data.balance)) { wx.showToast({ icon: 'none', title: '提现金额不可大于您的'+that.data.balanceLang, duration: 1500 }); return; } if ( this.data.info_form.balance_money == undefined || this.data.info_form.balance_money <= 0 || this.data.info_form.balance_money == 0 ) { wx.showToast({ icon: 'none', title: '提现金额不可低于0', duration: 1500 }); return; } let urlStr = app.getNetAddresss('finance.balance-withdraw.is-can-submit'); app._postNetWork({ url: urlStr, showToastIn: false, // data: _url, success: function (resdata) { var res = resdata; if (res.data.result == 1) { if (res.data.data.status) { that.confirmPost(type); // 提现 } else { that.setManualInfo(type, res.data.data.manual_type); } } else { wx.showToast({ icon: 'none', title: res.msg, duration: 1500 }); } }, fail: function (res) { console.log(res.msg); } }); }, setManualInfo(type, manual_type) { let msg = ''; let routerPath = ''; switch (manual_type) { case 'bank': msg = '请先填写银行卡信息'; routerPath = 'memberBank'; break; case 'wechat': msg = '请先填写微信信息'; routerPath = 'info'; break; case 'alipay': msg = '请先填写支付宝信息'; routerPath = 'info'; break; default: break; } // let that = this; wx.showModal({ title: '提示', content: msg, success(res) { if (res.confirm) { if (routerPath == 'memberBank') { wx.navigateTo({ url: '/packageA/member/memberBank/memberBank' }); } else if (routerPath == 'info') { wx.navigateTo({ url: '/packageA/member/info/info' }); } } else if (res.cancel) { console.log('用户点击取消'); } } }); }, checkEup(type) { var that = this; let urlStr = app.getNetAddresss('plugin.eup-pay.api.account.pi-account'); app._postNetWork({ url: urlStr, showToastIn: false, data: _url, success: function (resdata) { var res = resdata; if (res.result == 1) { if (res.data.bool == 1) { that.confirmPost(type); // 提现 } } else if (res.result == 0) { wx.showModal({ title: '提示', content: msg, success(res) { if (res.confirm) { wx.navigateTo({ url: '/packageA/member/info/info' }); } else if (res.cancel) { console.log('用户点击取消'); } } }); } }, fail: function (res) { console.log(res.msg); } }); }, _initHxpay() { this.setData({ action: '', msg: '', notice: '' }); }, // 获取银行卡列表 getwithList() { let urlStr = app.getNetAddresss('plugin.converge_pay.frontend.controllers.converge-pay-bank-card.get-bank-card-list'); app._getNetWork({ url: urlStr, success: (resdata) => { var res = resdata.data; if (res.result == 1) { if (res.data.length == 0) { wx.showToast({ title: '请先去添加银行卡', icon: 'none' }); wx.navigateTo({ url: '/packageA/others/HJinfo/bankCardInformation/bankCardInformation' }); } res.data.map(item => { item.check = false; if (item.receiverAccountNoEnc != '' && item.receiverAccountNoEnc != null) { item.bankName += '(' + item.receiverAccountNoEnc.substring(item.receiverAccountNoEnc.length - 4) + ')'; } }); this.setData({ withList: res.data }); } else { wx.showToast({ icon: 'none', title: res.msg, duration: 1500 }); setTimeout(() => { }, 2000); } }, fail: function (res) { console.log(res); } }); }, show1CloseBtn() { this.setData({ show2: false, show3: false }); }, // 获取手续费 getCartWith(type) { let urlStr = ''; if (type == 'suppier') { urlStr = app.getNetAddresss('plugin.supplier.frontend.withdraw.converge-withdraw'); } else { urlStr = app.getNetAddresss('finance.balance-withdraw.converge-withdraw'); urlStr += '&withdraw_money=' + this.data.info_form.balance_money; } app._getNetWork({ url: urlStr, success: (resdata) => { var res = resdata.data; if (res.result == 1) { this.setData({ poundageHj: res.data.poundage, actual_amount: res.data.actual_amount, cost_money: res.data.cost_money }); } else { wx.showModal({ title: '提示', content: res.msg }); } }, fail: function (res) { console.log(res.msg); } }); }, // 汇聚提现 checkHJ(type) { let urlStr = app.getNetAddresss('plugin.converge_pay.frontend.controllers.converge-pay-bank-card.get-bank-card'); app._getNetWork({ url: urlStr, success: (resdata) => { var res = resdata.data; if (res.result == 1) { this.setData({ checkObj: res.data }); let name = res.data.bankName + '(' + res.data.receiverAccountNoEnc.substring(res.data.receiverAccountNoEnc.length - 4) + ')'; this.setData({ show2: true, 'checkObj.bankName': name }); this.getwithList(); this.getCartWith(); // this.confirmPost(type) } else { if (res.data.status == -1) { wx.navigateTo({ url: '/packageA/others/HJinfo/bankCardInformation/bankCardInformation' }); } wx.showModal({ title: '提示', content: res.msg }); } }, fail: function (res) { console.log(res.msg); } }); }, submitbrank() { app._postNetWork({ url: this.data.action, showToastIn: false, data: { ipsRequest: this.data.msg }, success: function (resdata) { wx.navigateBack({ delta: 1 }); }, fail: function (res) {} }); }, towithdrawal(type) { this.setData({ pay_type: type }); const that = this; if (that.data.balance == undefined || this.data.balance <= 0 || this.data.balance == 0) { wx.showToast({ icon: 'none', title: '提现金额不可低于0', duration: 1500 }); return; } let urlStr = app.getNetAddresss('plugin.supplier.frontend.withdraw.withdraw'); urlStr += '&apply_type=' + this.data.pay_type; urlStr += '&member_id=' + this.data.member_id; app._getNetWork({ url: urlStr, success: function (resdata) { var res = resdata.data; if (res.result == 1) { wx.showToast({ title: res.msg, icon: 'none', duration: 1500, success: function () { setTimeout(function () { // 要延时执行的代码 wx.navigateBack({ delta: 1 }); }, 1500); // 延迟时间 } }); } else { wx.showToast({ icon: 'none', title: res.msg, duration: 1500 }); } }, fail: function (res) { console.log(res); } }); }, balanceMoneyinp(e) { let val = e.detail.value; this.setData({ 'info_form.balance_money': val }); } });