index.ts 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  1. import { FunCode } from "../../../constants/enum/funcode"
  2. import Toast from "../../../miniprogram_npm/@vant/weapp/toast/toast"
  3. import services from "../../../services/index"
  4. import { queryBankAccountSign } from "../../../services/api/account/index"
  5. import { sendMsgToMQ } from "../../../services/api/common/index"
  6. import { accountid, getErrorMsg, isEncrypted, loginQuery, protoHeader, timetample, userid } from "../../../services/utils"
  7. import { formatDate, isnullstr } from "../../../utils/util"
  8. import { hideLoading, showLoading, showModel } from "../../../utils/message/index"
  9. import { encryptBody } from "../../../utils/websocket/crypto"
  10. Page({
  11. /**
  12. * 页面的初始数据
  13. */
  14. data: {
  15. /// tab激活索引
  16. active: Number(0),
  17. /// tabs
  18. tabs: [{id: 0, name: '充值'}, {id: 1, name: '提现'}],
  19. /// 签约账户信息
  20. bankAccountSign: <GuangZuan.BankAccountSign>{},
  21. /// 入金金额
  22. inamount: '',
  23. /// 出金金额
  24. outamount: '',
  25. /// 当前可出金额
  26. enableOutAmount: 0.0,
  27. /// 出入金时间
  28. time: '',
  29. /// 文件上传列表
  30. fileList: <GuangZuan.UploadRsp[]>[],
  31. /// 显示信息
  32. sign: {}
  33. },
  34. /**
  35. * 返回上层视图
  36. */
  37. backToParent() {
  38. /// 返回上层视图
  39. wx.navigateBack()
  40. },
  41. /**
  42. * tab触发事件
  43. */
  44. onTabChange(e: any) {
  45. /// 设置激活项
  46. this.setData({ active: Number(e.detail.index) })
  47. },
  48. /**
  49. * 按钮点击响应事件
  50. */
  51. onButtonPressed(e: any) {
  52. switch (e.currentTarget.id) {
  53. case "submit": /// 提交申请
  54. if (this.data.active == 0) {
  55. showModel(() => {
  56. this.doInMoneyApply()
  57. }, '提示', '确定要进行入金操作吗?')
  58. } else {
  59. showModel(() => {
  60. this.doOutMoneyApply()
  61. }, '提示', '确定要进行出金操作吗?')
  62. }
  63. break;
  64. default: /// 全部
  65. this.setData({ outamount: String(this.data.enableOutAmount) })
  66. break;
  67. }
  68. },
  69. /// 照片上传
  70. afterRead(e: any) {
  71. const { file } = e.detail;
  72. // 当设置 mutiple 为 true 时, file 为数组格式,否则为对象格式
  73. wx.uploadFile({
  74. url: services.config.uploadUrl,
  75. filePath: file.url,
  76. name: 'file',
  77. formData: { user: 'test' },
  78. success: (res) => {
  79. if (res.statusCode != 200) {
  80. Toast({message: '图片上传失败,原因:'+res.errMsg})
  81. return
  82. }
  83. // 上传完成需要更新 fileList
  84. const { fileList = [] } = this.data;
  85. fileList.push({ ...file, url: JSON.parse(res.data) });
  86. this.setData({ fileList });
  87. },
  88. });
  89. },
  90. /// 删除图片
  91. deleteImage(e: any) {
  92. const {index} = e.detail.index
  93. // 上传完成需要更新 fileList
  94. const { fileList = [] } = this.data;
  95. fileList.splice(index, 1)
  96. this.setData({ fileList });
  97. },
  98. /**
  99. * 查询用户已签约信息
  100. */
  101. queryBankAccountSign() {
  102. /// loding.....
  103. showLoading(() => {
  104. /// 发送请求
  105. queryBankAccountSign({
  106. data: {
  107. userid: userid()
  108. },
  109. success: (res) => {
  110. /// 请求失败
  111. if (res.code != 200) {
  112. hideLoading(() => {}, '用户签约信息请求失败,原因:'+res.msg)
  113. return
  114. }
  115. hideLoading(() => {
  116. const sign = res.data.filter(obj => {
  117. return obj.signstatus === 2 || obj.signstatus === 3 || obj.signstatus === 4
  118. })[0]
  119. /// 数据赋值
  120. this.setData({
  121. bankAccountSign: sign,
  122. sign: {
  123. bankname: sign.bankname,
  124. cardno: isnullstr(sign.cardno),
  125. bankaccountname: isnullstr(sign.bankaccountname),
  126. branchbankname: isnullstr(sign.branchbankname),
  127. bankaccountno: isnullstr(sign.bankaccountno)
  128. }
  129. })
  130. })
  131. },
  132. fail: (emsg) => {
  133. hideLoading(() => {}, emsg)
  134. },
  135. complete: () => {}
  136. })
  137. })
  138. },
  139. /// 账户资金信息请求
  140. accountFundInfo() {
  141. /// loding....
  142. showLoading(()=>{
  143. /// 参数信息
  144. const info = JSON.stringify({
  145. /// 头部
  146. Header: protoHeader(FunCode.AccountFundInfoReq),
  147. /// uint32 查询位掩码
  148. QueryBitMask: 2,
  149. /// uint64 查询资金账号
  150. AccountId: accountid().toString(),
  151. OrderId: timetample().toString()
  152. })
  153. /// 发送请求
  154. sendMsgToMQ({
  155. data: {
  156. isEncrypted: isEncrypted(),
  157. funCodeReq: FunCode.AccountFundInfoReq,
  158. funCodeRsp: FunCode.AccountFundInfoRsp,
  159. data: encryptBody(info)
  160. },
  161. success: (res) => {
  162. /// 解析对象
  163. const data = JSON.parse(res.data.data)
  164. if (data.RetCode != 0) {
  165. hideLoading(() => {}, getErrorMsg(data.RetCode))
  166. return
  167. }
  168. hideLoading(() => {
  169. /// 可出金额
  170. this.setData({ enableOutAmount: data.AvailableOutMoney })
  171. })
  172. },
  173. fail: (emsg) => {
  174. hideLoading(()=>{}, emsg)
  175. }
  176. })
  177. }, '账户资金信息请求中......')
  178. },
  179. /// 入金申请请求
  180. doInMoneyApply() {
  181. /// 合规性校验
  182. if (!this.check()) { return }
  183. /// showLoading
  184. showLoading(()=>{
  185. /// 参数信息
  186. const info = JSON.stringify({
  187. /// 头部
  188. Header: protoHeader(FunCode.T2bBankDepositReq),
  189. /// 外部操作流水号
  190. ExtOperatorID: timetample().toString(),
  191. /// 托管银行编号
  192. CusBankID: this.data.bankAccountSign.cusbankid,
  193. /// 金额
  194. Amount: Number(this.data.inamount),
  195. /// 币种
  196. Currency: this.data.bankAccountSign.currency,
  197. /// 银行卡号
  198. BankAccoutNum: this.data.bankAccountSign.bankaccountno2,
  199. /// 银行子账号名
  200. BankAccoutName: this.data.bankAccountSign.bankaccountname2,
  201. /// 资金账户
  202. AccountCode: this.data.bankAccountSign.accountcode,
  203. /// 扩展信息(JSON串,参考配置要求进行填充)
  204. extend_info: JSON.stringify({"sex": 1, "certificate_photo_url": this.data.fileList[0].url[0].filePath }),
  205. })
  206. /// 发送请求
  207. sendMsgToMQ({
  208. data: {
  209. isEncrypted: isEncrypted(),
  210. funCodeReq: FunCode.T2bBankDepositReq,
  211. funCodeRsp: FunCode.T2bBankDepositRsp,
  212. data: encryptBody(info)
  213. },
  214. success: (res) => {
  215. /// 解析对象
  216. const data = JSON.parse(res.data.data)
  217. if (data.Status != 0) {
  218. hideLoading(() => {}, getErrorMsg(data.Status))
  219. return
  220. }
  221. /// 请求成功
  222. hideLoading(()=>{
  223. /// 返回上层视图
  224. wx.navigateBack()
  225. }, '入金申请请求成功', 'success')
  226. },
  227. fail: (emsg) => {
  228. hideLoading(()=>{}, emsg)
  229. }
  230. })
  231. }, '入金请求中......')
  232. },
  233. /// 出金申请请求
  234. doOutMoneyApply() {
  235. /// 合规性校验
  236. if (!this.check()) { return }
  237. /// loding....
  238. showLoading(()=>{
  239. /// 参数信息
  240. const info = JSON.stringify({
  241. /// 头部
  242. Header: protoHeader(FunCode.T2bBankWithdrawReq),
  243. /// 外部操作流水号
  244. ExtOperatorID: timetample().toString(),
  245. /// 托管银行编号
  246. CusBankID: this.data.bankAccountSign.cusbankid,
  247. /// 金额
  248. Amount: Number(this.data.outamount),
  249. /// 币种
  250. Currency: this.data.bankAccountSign.currency,
  251. /// 银行卡号
  252. BankAccoutNum: this.data.bankAccountSign.bankaccountno2,
  253. /// 银行子账号名
  254. BankAccoutName: this.data.bankAccountSign.bankaccountname2,
  255. /// 资金账户
  256. AccountCode: this.data.bankAccountSign.accountcode,
  257. /// 扩展信息(JSON串,参考配置要求进行填充)
  258. extend_info: JSON.stringify({"sex": 1}),
  259. /// 银行卡行号
  260. OpenCardBankId: this.data.bankAccountSign.bankid,
  261. /// 收款支行名称
  262. BranchBankName: this.data.bankAccountSign.branchbankname,
  263. /// 申请日期和时间
  264. AppDateTime: formatDate(new Date()),
  265. /// 账户类型
  266. AccountType: 0
  267. })
  268. /// 发送请求
  269. sendMsgToMQ({
  270. data: {
  271. isEncrypted: isEncrypted(),
  272. funCodeReq: FunCode.T2bBankWithdrawReq,
  273. funCodeRsp: FunCode.T2bBankWithdrawRsp,
  274. data: encryptBody(info)
  275. },
  276. success: (res) => {
  277. /// 解析对象
  278. const data = JSON.parse(res.data.data)
  279. if (data.Status != 0) {
  280. hideLoading(() => {}, getErrorMsg(data.Status))
  281. return
  282. }
  283. /// 请求成功
  284. hideLoading(()=>{
  285. /// 返回上层视图
  286. wx.navigateBack()
  287. }, '出金申请请求成功', 'success')
  288. },
  289. fail: (emsg) => {
  290. hideLoading(()=>{}, emsg)
  291. }
  292. })
  293. }, '出金请求中......')
  294. },
  295. /// 合规性校验
  296. check(): boolean {
  297. /// 获取账户签约信息失败
  298. if (this.data.bankAccountSign === undefined) {
  299. Toast({message: '获取账户签约信息失败!'})
  300. return false
  301. }
  302. /// 充值
  303. if (this.data.active === 0) {
  304. /// 请输入充值金额
  305. if (Number(this.data.inamount) === 0.00 || this.data.inamount === '') {
  306. Toast({message: '请输入充值金额!'})
  307. return false
  308. }
  309. /// 请上传转账凭证
  310. if (this.data.fileList.length === 0) {
  311. Toast({message: '请上传转账凭证!'})
  312. return false
  313. }
  314. }
  315. /// 提现
  316. if (this.data.active === 1) {
  317. /// 请输入提现金额
  318. if (Number(this.data.outamount) === 0.00 || this.data.outamount === '') {
  319. Toast({message: '请输入提现金额!'})
  320. return false
  321. }
  322. /// 提现金额不能超过可提金额
  323. if (Number(this.data.outamount) > this.data.enableOutAmount) {
  324. Toast({message: '提现金额不能超过可提金额!'})
  325. return false
  326. }
  327. }
  328. return true
  329. },
  330. /**
  331. * 生命周期函数--监听页面加载
  332. */
  333. onLoad(options: any) {
  334. /// 查询账户签约信息
  335. this.queryBankAccountSign()
  336. /// 资金账户查询
  337. this.accountFundInfo()
  338. /// 开始结束时间
  339. const start = loginQuery().systemParams.filter(obj => { return obj.paramcode === "012" })[0].paramvalue
  340. /// 开始结束时间
  341. const end = loginQuery().systemParams.filter(obj => { return obj.paramcode === "013" })[0].paramvalue
  342. const id = options.id
  343. /// 显示时间
  344. this.setData({ time: start+'-'+end, active: Number(id) })
  345. },
  346. /**
  347. * 生命周期函数--监听页面初次渲染完成
  348. */
  349. onReady() {
  350. },
  351. /**
  352. * 生命周期函数--监听页面显示
  353. */
  354. onShow() {
  355. },
  356. /**
  357. * 生命周期函数--监听页面隐藏
  358. */
  359. onHide() {
  360. },
  361. /**
  362. * 生命周期函数--监听页面卸载
  363. */
  364. onUnload() {
  365. },
  366. /**
  367. * 页面相关事件处理函数--监听用户下拉动作
  368. */
  369. onPullDownRefresh() {
  370. },
  371. /**
  372. * 页面上拉触底事件的处理函数
  373. */
  374. onReachBottom() {
  375. },
  376. /**
  377. * 用户点击右上角分享
  378. */
  379. onShareAppMessage() {
  380. }
  381. })