import { FunCode } from "../../../constants/enum/funcode" import Toast from "../../../miniprogram_npm/@vant/weapp/toast/toast" import { queryBankAccountSign, queryCusBankSignBank } from "../../../services/api/account/index" import { sendMsgToMQ } from "../../../services/api/common/index" import { accountid, getEnumdicValue, getErrorMsg, isEncrypted, loginQuery, protoHeader, timetample, userid } from "../../../services/utils" import { hideLoading, showLoading, showModel } from "../../../utils/message/index" import { decryptAES, encryptBody } from "../../../utils/websocket/crypto" Page({ /** * 页面的初始数据 */ data: { /// 开户银行 bankName: '', /// 银行卡号 bankNo: '', /// 姓名 accountName: '', /// 支行名称 branchBankName: '', /// 开户行信息 bankInfos: [], /// 显示的开户行信息 bankNames: [], /// 选中的银行信息 bankInfo: {}, /// 是否显示银行 showBank: false, /// 托管银行信息 cusBankInfo: {}, /// 签约账户信息 bankAccountSign: {}, /// 签约状态 signStatus: '' }, /** * 返回上层视图 */ backToParent() { /// 返回上层视图 wx.navigateBack() }, /** * onCancel */ onCancel() { this.setData({ showBank: false }) }, /** * onConfirm */ onConfirm(e: any) { const { index } = e.detail; /// 赋值 this.setData({ showBank: false, bankInfo: this.data.bankInfos[index], bankName: this.data.bankInfos[index].bankname }) }, /** * 按钮点击响应事件 */ onButtonPressed(e: any) { switch (e.currentTarget.id) { case 'submit': /// 签约提交 this.doBankAccountSign() break; case 'cancel': /// 解约请求 showModel(() => { this.doCancelBankAccountSign() }, '提示', '确定要申请解约吗?') break default: break; } }, /** * showBankInfos */ showBankInfos() { this.setData({ showBank: true }) }, /** * 查询托管银行信息 */ queryCusBankInfo() { /// showLoading showLoading(()=>{ /// 发送请求 queryCusBankSignBank({ success: (res) => { /// 请求失败 if (res.code != 200) { hideLoading(()=>{}, '托管银行请求失败,原因:'+res.msg, 'error') return } hideLoading(()=>{ /// 数据赋值 this.setData({ cusBankInfo: res.data[0], /// 银行信息 bankInfos: res.data[0].Banklst, /// 银行名称信息 bankNames: res.data[0].Banklst.map(obj => { return obj.bankname }) }) }) }, fail: (emsg) => { hideLoading(()=>{}, emsg, 'error') } }) }) }, /** * 查询用户已签约信息 */ queryBankAccountSign() { /// showLoading showLoading(()=>{ /// 发送请求 queryBankAccountSign({ data: { userid: userid() }, success: (res) => { /// 请求失败 if (res.code != 200) { hideLoading(()=>{}, '用户签约信息请求失败,原因:'+res.msg, 'error') return } /// hideLoading hideLoading(()=>{ const sign = res.data.filter(obj => { return obj.signstatus === 2 || obj.signstatus === 3 || obj.signstatus === 4 })[0] /// 数据赋值 this.setData({ bankAccountSign: sign, bankName: sign.bankname, bankNo: sign.bankaccountno, accountName: sign.bankaccountname, branchBankName: sign.branchbankname, signStatus: getEnumdicValue('signstatus', sign.signstatus), bankInfo: this.data.bankInfos.filter(obj => { return obj.bankid === sign.bankid })[0], }) }) }, fail: (emsg) => { hideLoading(()=>{}, emsg, 'error') } }) }) }, /** * 签约请求 */ doBankAccountSign() { /// 合规性校验 if (!this.check()) { return } const { cusbankid } = this.data.bankAccountSign const operateType = cusbankid != undefined ? 2 : 1 const msg = operateType === 1 ? '签约请求' : '签约修改' /// showModel showModel(() => { /// loading showLoading(()=>{ /// 用户信息 const userinfo = loginQuery().userInfo /// 银行卡号 const bankid = cusbankid != undefined ? this.data.bankAccountSign.bankid : this.data.bankInfo.bankid /// 数据信息 const data = { /// 账户类型[1-对私;2-对公] AccountType: 1, /// 是否强制[0-否;1-是]强制,只更新中心签约信息,不发送银行。用于银行信息不一致的情况 IsForce: 0, /// 授权代理人证件类型 AgentCertType: 0, /// 银行卡类型 BankCardType: 0, /// 银行账户类型 BankAccountType: 1, /// 账户 AccountCode: accountid().toString(), /// 外部操作流水号 ExtOperatorID: timetample(), /// 扩展信息(JSON串,参考配置要求进行填充) extend_info: JSON.stringify({ "sex" : 1 }), /// 头部 Header: protoHeader(FunCode.T2bBankSignReq) } /// 参数信息 const info = JSON.stringify({ /// 交易所业务日期 TradeDate: this.data.cusBankInfo.tradedate, /// 币种 Currency: this.data.cusBankInfo.currency, /// 变更类型[1-增加;2-修改;4-绑卡; OperateType: operateType, /// 客户名称 AccountName: this.data.accountName, /// 银行账户名称 BankAccountName: this.data.accountName, /// 银行账户 BankAccountNo: this.data.bankNo, /// 开户支行名称 OpenBankName: this.data.branchBankName, /// 银行卡行号 OpenBankAccId: bankid, /// 托管银行编号 CusBankID: this.data.cusBankInfo.cusbankid, /// 开户行名称 ExBankName: this.data.bankName, /// 证件号码 CertID: decryptAES(userinfo.cardnum), /// 证件类型 CertType: userinfo.cardtypeid.toString(), /// 数据信息 ...data }) /// 发送请求 sendMsgToMQ({ data: { funCodeReq: FunCode.T2bBankSignReq, funCodeRsp: FunCode.T2bBankSignRsp, isEncrypted: isEncrypted(), data: encryptBody(info) }, success: (res) => { /// 解析对象 const data = JSON.parse(res.data.data) if (data.Status != 0) { hideLoading(() => {}, getErrorMsg(data.Status), 'error') return } /// 请求成功 hideLoading(()=>{ /// 返回上层视图 wx.navigateBack() }, msg+'成功', 'success') }, fail: (emsg) => { hideLoading(()=>{}, emsg, 'error') } }) }, msg+'中.....') }, '提示', '确定要'+msg+'?') }, /** * 解约请求 */ doCancelBankAccountSign() { /// loading showLoading(()=>{ /// 参数信息 const info = JSON.stringify({ /// 头部 Header: protoHeader(FunCode.T2bBankCancelSignReq), /// 外部操作流水号 ExtOperatorID: timetample().toString(), /// 账户 AccountCode: this.data.bankAccountSign.accountcode, /// 托管银行编号 CusBankID: this.data.bankAccountSign.cusbankid, /// 币种 Currency: this.data.bankAccountSign.currency, /// 交易所业务日期 TradeDate: this.data.cusBankInfo.tradedate, /// 是否强制 IsForce: 0, /// 银行子账号 BankChildAcc: this.data.bankAccountSign.bankaccountno, /// 银行子账号名 BankChildAccName: this.data.bankAccountSign.bankaccountname }) /// 发送请求 sendMsgToMQ({ data: { isEncrypted: isEncrypted(), funCodeReq: FunCode.T2bBankCancelSignReq, funCodeRsp: FunCode.T2bBankCancelSignRsp, data: encryptBody(info) }, success: (res) => { /// 解析对象 const data = JSON.parse(res.data.data) if (data.RetCode != 0) { hideLoading(() => {}, getErrorMsg(data.RetCode), 'error') return } /// 请求成功 hideLoading(()=>{ /// 返回上层视图 wx.navigateBack() }, '解约请求成功', 'success') }, fail: (emsg) => { debugger hideLoading(()=>{}, emsg, 'error') } }) }, '解约请求中.....') }, /** * 合规性校验 */ check(): boolean { /// 请选择开户行 if (this.data.bankName.length === 0) { Toast({message: '请选择开户行!'}) return false } /// 请输入银行卡号! if (this.data.bankNo.length === 0) { Toast({message: '请输入银行卡号!'}) return false } /// 请输入支行名称! if (this.data.branchBankName.length === 0) { Toast({message: '请输入支行名称!'}) return false } return true }, /** * 生命周期函数--监听页面加载 */ onLoad() { /// 查询托管银行信息 this.queryCusBankInfo() /// 查询账户已签约信息 this.queryBankAccountSign() /// 账户名称 this.setData({ accountName: loginQuery().userInfo.customername }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { }, /** * 用户点击右上角分享 */ onShareAppMessage() { } })