var sysT = require('../../../tool/sys-tool.js') var verify = require('../../../tool/verify.js') var businessT = require('../../../tool/business-tool.js') var publicData = require('../../../constant/data.js') var url = require('../../../constant/url.js') import Net from '../../../tool/net.js' var net = new Net() var app = getApp() Page({ /** * 页面的初始数据 */ data: { adapter: { isIos: false, bgHeight: '', suffix: '' }, customer: {},//自动同步(引用) data: {}, inputValue: '', textareaValue: '', textareaPlaceholderHide: false, bankIcon: '', refreshBank: false, isInput: false }, getBankIcon: function (bank) { var icon = publicData.bankDic[bank] if (icon) { icon = '../../../icon/bank/' + icon + '.png' } else { icon = '' } return icon }, chooseBank: businessT.action(function () { if (this.data.isInput) { this.data.isInput = false this.getBankWithInChooseBank(true) return } this.intoChooseBank() }), inputAction: function (sender) { businessT.debugLog(sender) this.data.inputValue = sender.detail.value this.setData({ inputValue: this.data.inputValue }) }, inputFocus: function (sender) { businessT.debugLog('inputfocus') this.data.isInput = true }, inputBlur: function (sender) { businessT.debugLog('inputblur') if (this.data.isInput) { this.data.isInput = false this.getBankWithInChooseBank(false) } }, getBankWithInChooseBank: function (flag) { var that = this net.connect({ url: url.alipayGetBank + this.data.inputValue, data: {}, method: 'GET', success: (err, res) => {}, fail: (err, res) => { businessT.debugLog(res) if (res && res['bank']) { var dic = publicData.alipayBankDic if (dic[res['bank']]) { that.data.data.bank = dic[res['bank']] that.data.bankIcon = that.getBankIcon(that.data.data.bank) that.setData({ data: that.data.data, bankIcon: that.data.bankIcon }) return } } if (flag) { businessT.debugLog('flag') that.intoChooseBank() } } }, false) }, intoChooseBank: function () { wx.navigateTo({ url: '../choose-bank/choose-bank', }) }, textareaInput: function (sender) { businessT.debugLog(sender) this.data.textareaValue = sender.detail.value this.setData({ textareaValue: this.data.textareaValue }) }, textareaFocus: function (sender) { if (!this.data.textareaPlaceholderHide) { this.data.textareaPlaceholderHide = true; this.setData({ textareaPlaceholderHide: this.data.textareaPlaceholderHide }) } }, textareaBlur: function (sender) { if (this.data.textareaValue.length == 0 && this.data.textareaPlaceholderHide) { this.data.textareaPlaceholderHide = false; this.setData({ textareaPlaceholderHide: this.data.textareaPlaceholderHide }) } }, saveAction: businessT.action(function (sender) { businessT.debugLog(this.data.inputValue) if (!verify.isNumber(this.data.inputValue) || this.data.inputValue.length < publicData.minBankCodeLength) { wx.showToast({ title: '请输入正确的银行卡号', icon: 'none' }) return } if (this.data.data.bank.length < publicData.minBankNameLength) { wx.showToast({ title: '请输入正确的银行名称', icon: 'none' }) return } wx.showLoading({ title: '正在保存', mask: true }) net.connectNeedLogin({ url: url.app_host + url.modifyBank, data: { sbu_id: this.data.customer.id, bank: this.data.data.bank, bank_branch: this.data.textareaValue, bank_code: this.data.inputValue }, success: (err, res) => { this.data.customer.bank = this.data.data.bank this.data.customer.bank_branch = this.data.textareaValue this.data.customer.bank_code = this.data.inputValue wx.hideLoading() wx.showToast({ title: '保存成功', icon: 'none' }) wx.navigateBack({}) }, fail: (err, res) => { businessT.showFailTips(err, '保存失败') } }) }), /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { sysT.adaptor() businessT.debugLog(sysT.usableHeight(112)) this.data.customer = app.globalData.customerList[options.i] businessT.debugLog(this.data.customer) this.data.data = { bank_code: this.data.customer.bank_code, bank_branch: this.data.customer.bank_branch, bank: this.data.customer.bank, user_name: this.data.customer.user_name } var isIos = sysT.sysInfo().system.indexOf("iOS") == 0 this.data.adapter = { isIos: isIos, bgHeight: sysT.usableHeight(112), suffix: sysT.suffixOfClass(), } this.data.textareaPlaceholderHide = this.data.data.bank_branch.length > 0 this.data.bankIcon = this.getBankIcon(this.data.data.bank) this.setData({ textareaValue: this.data.data.bank_branch, textareaPlaceholderHide: this.data.textareaPlaceholderHide, inputValue: this.data.data.bank_code, adapter: this.data.adapter, data: this.data.data, bankIcon: this.data.bankIcon }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { if (this.data.refreshBank) { this.data.refreshBank = false this.data.bankIcon = this.getBankIcon(this.data.data.bank) this.setData({ data: this.data.data, bankIcon: this.data.bankIcon }) } }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { } })