index.ts 11 KB

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