index.ts 10 KB

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