index.ts 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  1. import { FunCode } from "../../../constants/enum/funcode"
  2. import Toast from "../../../miniprogram_npm/@vant/weapp/toast/toast"
  3. import { queryBankAccountSign, queryCusBankSignBank } from "../../../services/api/account/index"
  4. import { sendMsgToMQ } from "../../../services/api/common/index"
  5. import { accountid, getEnumdicValue, getErrorMsg, isEncrypted, loginQuery, protoHeader, timetample, userid } from "../../../services/utils"
  6. import { hideLoading, showLoading, showModel } from "../../../utils/message/index"
  7. import { decryptAES, encryptBody } from "../../../utils/websocket/crypto"
  8. Page({
  9. /**
  10. * 页面的初始数据
  11. */
  12. data: {
  13. /// 开户银行
  14. bankName: '',
  15. /// 银行卡号
  16. bankNo: '',
  17. /// 姓名
  18. accountName: '',
  19. /// 支行名称
  20. branchBankName: '',
  21. /// 开户行信息
  22. bankInfos: <GuangZuan.BankInfo[]>[],
  23. /// 显示的开户行信息
  24. bankNames: <string[]>[],
  25. /// 选中的银行信息
  26. bankInfo: <GuangZuan.BankInfo>{},
  27. /// 是否显示银行
  28. showBank: false,
  29. /// 托管银行信息
  30. cusBankInfo: <GuangZuan.CusBankInfo>{},
  31. /// 签约账户信息
  32. bankAccountSign: <GuangZuan.BankAccountSign>{},
  33. /// 签约状态
  34. signStatus: '',
  35. /// 签约状态
  36. status: 0
  37. },
  38. /**
  39. * 返回上层视图
  40. */
  41. backToParent() {
  42. /// 返回上层视图
  43. wx.navigateBack()
  44. },
  45. /**
  46. * onCancel
  47. */
  48. onCancel() {
  49. this.setData({ showBank: false })
  50. },
  51. /**
  52. * onConfirm
  53. */
  54. onConfirm(e: any) {
  55. const { index } = e.detail;
  56. /// 赋值
  57. this.setData({
  58. showBank: false,
  59. bankInfo: this.data.bankInfos[index],
  60. bankName: this.data.bankInfos[index].bankname
  61. })
  62. },
  63. /**
  64. * 按钮点击响应事件
  65. */
  66. onButtonPressed(e: any) {
  67. switch (e.currentTarget.id) {
  68. case 'submit': /// 签约提交
  69. this.doBankAccountSign()
  70. break;
  71. case 'cancel': /// 解约请求
  72. this.doCancelBankAccountSign()
  73. break
  74. default:
  75. break;
  76. }
  77. },
  78. /**
  79. * showBankInfos
  80. */
  81. showBankInfos() {
  82. /// 签约待审核或者签约中 不能修改
  83. if (this.data.status === 2 || this.data.status === 4) {
  84. return
  85. }
  86. this.setData({ showBank: true })
  87. },
  88. /**
  89. * 查询托管银行信息
  90. */
  91. queryCusBankInfo() {
  92. /// showLoading
  93. showLoading(()=>{
  94. /// 发送请求
  95. queryCusBankSignBank({
  96. success: (res) => {
  97. /// 请求失败
  98. if (res.code != 200) {
  99. hideLoading(()=>{}, '托管银行请求失败,原因:'+res.msg)
  100. return
  101. }
  102. hideLoading(()=>{
  103. /// 数据赋值
  104. this.setData({
  105. cusBankInfo: res.data[0],
  106. /// 银行信息
  107. bankInfos: res.data[0].Banklst,
  108. /// 银行名称信息
  109. bankNames: res.data[0].Banklst.map(obj => { return obj.bankname })
  110. })
  111. })
  112. },
  113. fail: (emsg) => {
  114. hideLoading(()=>{}, emsg)
  115. }
  116. })
  117. })
  118. },
  119. /**
  120. * 查询用户已签约信息
  121. */
  122. queryBankAccountSign() {
  123. /// showLoading
  124. showLoading(()=>{
  125. /// 发送请求
  126. queryBankAccountSign({
  127. data: {
  128. userid: userid()
  129. },
  130. success: (res) => {
  131. /// 请求失败
  132. if (res.code != 200) {
  133. hideLoading(()=>{}, '用户签约信息请求失败,原因:'+res.msg)
  134. return
  135. }
  136. /// hideLoading
  137. hideLoading(()=>{
  138. const sign = res.data.filter(obj => {
  139. return obj.signstatus === 2 || obj.signstatus === 3 || obj.signstatus === 4
  140. })[0]
  141. if (sign) {
  142. /// 数据赋值
  143. this.setData({
  144. bankAccountSign: sign,
  145. bankName: sign.bankname ?? '',
  146. bankNo: sign.bankaccountno,
  147. accountName: sign.bankaccountname,
  148. branchBankName: sign.branchbankname,
  149. signStatus: getEnumdicValue('signstatus', sign.signstatus),
  150. status: sign?.signstatus,
  151. bankInfo: this.data.bankInfos.filter(obj => {
  152. return obj.bankid === sign.bankid
  153. })[0],
  154. })
  155. }
  156. })
  157. },
  158. fail: (emsg) => { hideLoading(()=>{}, emsg) }
  159. })
  160. })
  161. },
  162. /**
  163. * 签约请求
  164. */
  165. doBankAccountSign() {
  166. /// 合规性校验
  167. if (!this.check()) { return }
  168. const { cusbankid } = this.data.bankAccountSign
  169. const operateType = cusbankid != undefined ? 2 : 1
  170. const msg = operateType === 1 ? '签约' : '修改签约信息'
  171. /// showModel
  172. showModel(() => {
  173. /// loading
  174. showLoading(()=>{
  175. /// 用户信息
  176. const userinfo = loginQuery().userInfo
  177. /// 银行卡号
  178. const bankid = cusbankid != undefined ? this.data.bankAccountSign.bankid : this.data.bankInfo.bankid
  179. /// 数据信息
  180. const data = {
  181. /// 账户类型[1-对私;2-对公]
  182. AccountType: 1,
  183. /// 是否强制[0-否;1-是]强制,只更新中心签约信息,不发送银行。用于银行信息不一致的情况
  184. IsForce: 0,
  185. /// 授权代理人证件类型
  186. AgentCertType: 0,
  187. /// 银行卡类型
  188. BankCardType: 0,
  189. /// 银行账户类型
  190. BankAccountType: 1,
  191. /// 账户
  192. AccountCode: accountid().toString(),
  193. /// 外部操作流水号
  194. ExtOperatorID: timetample(),
  195. /// 扩展信息(JSON串,参考配置要求进行填充)
  196. extend_info: JSON.stringify({ "sex" : 1 }),
  197. /// 头部
  198. Header: protoHeader(FunCode.T2bBankSignReq)
  199. }
  200. /// 参数信息
  201. const info = JSON.stringify({
  202. /// 交易所业务日期
  203. TradeDate: this.data.cusBankInfo.tradedate,
  204. /// 币种
  205. Currency: this.data.cusBankInfo.currency,
  206. /// 变更类型[1-增加;2-修改;4-绑卡;
  207. OperateType: operateType,
  208. /// 客户名称
  209. AccountName: this.data.accountName,
  210. /// 银行账户名称
  211. BankAccountName: this.data.accountName,
  212. /// 银行账户
  213. BankAccountNo: this.data.bankNo,
  214. /// 开户支行名称
  215. OpenBankName: this.data.branchBankName,
  216. /// 银行卡行号
  217. OpenBankAccId: bankid,
  218. /// 托管银行编号
  219. CusBankID: this.data.cusBankInfo.cusbankid,
  220. /// 开户行名称
  221. ExBankName: this.data.bankName,
  222. /// 证件号码
  223. CertID: decryptAES(userinfo.cardnum),
  224. /// 证件类型
  225. CertType: userinfo.cardtypeid.toString(),
  226. /// 数据信息
  227. ...data
  228. })
  229. /// 发送请求
  230. sendMsgToMQ({
  231. data: {
  232. funCodeReq: FunCode.T2bBankSignReq,
  233. funCodeRsp: FunCode.T2bBankSignRsp,
  234. isEncrypted: isEncrypted(),
  235. data: encryptBody(info)
  236. },
  237. success: (res) => {
  238. /// 解析对象
  239. const data = JSON.parse(res.data.data)
  240. if ( data.Status != 0 && data.Status != 6007 ) {
  241. hideLoading(() => {}, getErrorMsg(data.Status))
  242. return
  243. }
  244. /// 请求成功
  245. hideLoading(()=>{}, '操作请求成功')
  246. /// 返回上层视图
  247. wx.navigateBack()
  248. },
  249. fail: (emsg) => {
  250. hideLoading(()=>{}, emsg)
  251. }
  252. })
  253. }, msg+'中.....')
  254. }, '提示', '确定要'+msg+'?')
  255. },
  256. /**
  257. * 解约请求
  258. */
  259. doCancelBankAccountSign() {
  260. /// showModel
  261. showModel(()=> {
  262. /// loading
  263. showLoading(()=>{
  264. /// 参数信息
  265. const info = JSON.stringify({
  266. /// 头部
  267. Header: protoHeader(FunCode.T2bBankCancelSignReq),
  268. /// 外部操作流水号
  269. ExtOperatorID: timetample().toString(),
  270. /// 账户
  271. AccountCode: this.data.bankAccountSign.accountcode,
  272. /// 托管银行编号
  273. CusBankID: this.data.bankAccountSign.cusbankid,
  274. /// 币种
  275. Currency: this.data.bankAccountSign.currency,
  276. /// 交易所业务日期
  277. TradeDate: this.data.cusBankInfo.tradedate,
  278. /// 是否强制
  279. IsForce: 0,
  280. /// 银行子账号
  281. BankChildAcc: this.data.bankAccountSign.bankaccountno,
  282. /// 银行子账号名
  283. BankChildAccName: this.data.bankAccountSign.bankaccountname
  284. })
  285. /// 发送请求
  286. sendMsgToMQ({
  287. data: {
  288. isEncrypted: isEncrypted(),
  289. funCodeReq: FunCode.T2bBankCancelSignReq,
  290. funCodeRsp: FunCode.T2bBankCancelSignRsp,
  291. data: encryptBody(info)
  292. },
  293. success: (res) => {
  294. /// 解析对象
  295. const data = JSON.parse(res.data.data)
  296. if (data.Status != 0) {
  297. console.log('xxxxx')
  298. hideLoading(() => {}, getErrorMsg(data.RetCode))
  299. return
  300. }
  301. /// 请求成功
  302. hideLoading(()=>{}, '解约请求成功')
  303. /// 返回上层视图
  304. wx.navigateBack()
  305. },
  306. fail: (emsg) => {
  307. hideLoading(()=>{}, emsg)
  308. }
  309. })
  310. }, '解约请求中.....')
  311. }, '提示', '确定要解约吗?')
  312. },
  313. /**
  314. * 合规性校验
  315. */
  316. check(): boolean {
  317. /// 请选择开户行
  318. if (this.data.bankName.length === 0) {
  319. Toast({message: '请选择开户行!'})
  320. return false
  321. }
  322. /// 请输入银行卡号!
  323. if (this.data.bankNo.length === 0) {
  324. Toast({message: '请输入银行卡号!'})
  325. return false
  326. }
  327. /// 请输入支行名称!
  328. // if (this.data.branchBankName.length === 0) {
  329. // Toast({message: '请输入支行名称!'})
  330. // return false
  331. // }
  332. return true
  333. },
  334. /**
  335. * 生命周期函数--监听页面加载
  336. */
  337. onLoad() {
  338. /// 查询托管银行信息
  339. this.queryCusBankInfo()
  340. /// 查询账户已签约信息
  341. this.queryBankAccountSign()
  342. /// 账户名称
  343. this.setData({ accountName: loginQuery().userInfo.customername })
  344. },
  345. /**
  346. * 生命周期函数--监听页面初次渲染完成
  347. */
  348. onReady() {
  349. },
  350. /**
  351. * 生命周期函数--监听页面显示
  352. */
  353. onShow() {
  354. },
  355. /**
  356. * 生命周期函数--监听页面隐藏
  357. */
  358. onHide() {
  359. },
  360. /**
  361. * 生命周期函数--监听页面卸载
  362. */
  363. onUnload() {
  364. },
  365. /**
  366. * 页面相关事件处理函数--监听用户下拉动作
  367. */
  368. onPullDownRefresh() {
  369. },
  370. /**
  371. * 页面上拉触底事件的处理函数
  372. */
  373. onReachBottom() {
  374. },
  375. /**
  376. * 用户点击右上角分享
  377. */
  378. onShareAppMessage() {
  379. }
  380. })