index.ts 11 KB

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