index.ts 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410
  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, 'error')
  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(),
  154. })
  155. /// 发送请求
  156. sendMsgToMQ({
  157. data: {
  158. isEncrypted: isEncrypted(),
  159. funCodeReq: FunCode.AccountFundInfoReq,
  160. funCodeRsp: FunCode.AccountFundInfoRsp,
  161. data: encryptBody(info)
  162. },
  163. success: (res) => {
  164. /// 解析对象
  165. const data = JSON.parse(res.data.data)
  166. if (data.RetCode != 0) {
  167. hideLoading(() => {}, getErrorMsg(data.RetCode), 'error')
  168. return
  169. }
  170. },
  171. fail: (emsg) => {
  172. hideLoading(()=>{}, emsg, 'error')
  173. }
  174. })
  175. }, '账户资金信息请求中......')
  176. },
  177. /// 入金申请请求
  178. doInMoneyApply() {
  179. /// 合规性校验
  180. if (!this.check()) { return }
  181. /// showLoading
  182. showLoading(()=>{
  183. /// 参数信息
  184. const info = JSON.stringify({
  185. /// 头部
  186. Header: protoHeader(FunCode.T2bBankDepositReq),
  187. /// 外部操作流水号
  188. ExtOperatorID: timetample().toString(),
  189. /// 托管银行编号
  190. CusBankID: this.data.bankAccountSign.cusbankid,
  191. /// 金额
  192. Amount: Number(this.data.inamount),
  193. /// 币种
  194. Currency: this.data.bankAccountSign.currency,
  195. /// 银行卡号
  196. BankAccoutNum: this.data.bankAccountSign.bankaccountno2,
  197. /// 银行子账号名
  198. BankAccoutName: this.data.bankAccountSign.bankaccountname2,
  199. /// 资金账户
  200. AccountCode: this.data.bankAccountSign.accountcode,
  201. /// 扩展信息(JSON串,参考配置要求进行填充)
  202. extend_info: JSON.stringify({"sex": 1, "certificate_photo_url": this.data.filePath}),
  203. })
  204. /// 发送请求
  205. sendMsgToMQ({
  206. data: {
  207. isEncrypted: isEncrypted(),
  208. funCodeReq: FunCode.T2bBankDepositReq,
  209. funCodeRsp: FunCode.T2bBankDepositRsp,
  210. data: encryptBody(info)
  211. },
  212. success: (res) => {
  213. /// 解析对象
  214. const data = JSON.parse(res.data.data)
  215. if (data.Status != 0) {
  216. hideLoading(() => {}, getErrorMsg(data.Status), 'error')
  217. return
  218. }
  219. /// 请求成功
  220. hideLoading(()=>{
  221. /// 返回上层视图
  222. wx.navigateBack()
  223. }, '入金申请请求成功', 'success')
  224. },
  225. fail: (emsg) => {
  226. hideLoading(()=>{}, emsg, 'error')
  227. }
  228. })
  229. }, '入金请求中......')
  230. },
  231. /// 出金申请请求
  232. doOutMoneyApply() {
  233. /// 合规性校验
  234. if (!this.check()) { return }
  235. /// loding....
  236. showLoading(()=>{
  237. /// 参数信息
  238. const info = JSON.stringify({
  239. /// 头部
  240. Header: protoHeader(FunCode.T2bBankWithdrawReq),
  241. /// 外部操作流水号
  242. ExtOperatorID: timetample().toString(),
  243. /// 托管银行编号
  244. CusBankID: this.data.bankAccountSign.cusbankid,
  245. /// 金额
  246. Amount: Number(this.data.outamount),
  247. /// 币种
  248. Currency: this.data.bankAccountSign.currency,
  249. /// 银行卡号
  250. BankAccoutNum: this.data.bankAccountSign.bankaccountno2,
  251. /// 银行子账号名
  252. BankAccoutName: this.data.bankAccountSign.bankaccountname2,
  253. /// 资金账户
  254. AccountCode: this.data.bankAccountSign.accountcode,
  255. /// 扩展信息(JSON串,参考配置要求进行填充)
  256. extend_info: JSON.stringify({"sex": 1}),
  257. /// 银行卡行号
  258. OpenCardBankId: this.data.bankAccountSign.bankid,
  259. /// 收款支行名称
  260. BranchBankName: this.data.bankAccountSign.branchbankname,
  261. /// 申请日期和时间
  262. AppDateTime: formatDate(new Date()),
  263. /// 账户类型
  264. AccountType: 0
  265. })
  266. /// 发送请求
  267. sendMsgToMQ({
  268. data: {
  269. isEncrypted: isEncrypted(),
  270. funCodeReq: FunCode.T2bBankWithdrawReq,
  271. funCodeRsp: FunCode.T2bBankWithdrawRsp,
  272. data: encryptBody(info)
  273. },
  274. success: (res) => {
  275. /// 解析对象
  276. const data = JSON.parse(res.data.data)
  277. if (data.Status != 0) {
  278. hideLoading(() => {}, getErrorMsg(data.Status), 'error')
  279. return
  280. }
  281. /// 请求成功
  282. hideLoading(()=>{
  283. /// 返回上层视图
  284. wx.navigateBack()
  285. }, '出金申请请求成功', 'success')
  286. },
  287. fail: (emsg) => {
  288. hideLoading(()=>{}, emsg, 'error')
  289. }
  290. })
  291. }, '出金请求中......')
  292. },
  293. /// 合规性校验
  294. check(): boolean {
  295. /// 获取账户签约信息失败
  296. if (this.data.bankAccountSign === undefined) {
  297. Toast({message: '获取账户签约信息失败!'})
  298. return false
  299. }
  300. /// 充值
  301. if (this.data.active === 0) {
  302. /// 请输入充值金额
  303. if (this.data.inamount === 0.00) {
  304. Toast({message: '请输入充值金额!'})
  305. return false
  306. }
  307. /// 请上传转账凭证
  308. if (this.data.fileList.length === 0) {
  309. Toast({message: '请上传转账凭证!'})
  310. return false
  311. }
  312. }
  313. /// 提现
  314. if (this.data.active === 1) {
  315. /// 请输入提现金额
  316. if (this.data.outamount === 0.00) {
  317. Toast({message: '请输入提现金额!'})
  318. return false
  319. }
  320. /// 提现金额不能超过可提金额
  321. if (this.data.outamount > this.data.enableOutAmount) {
  322. Toast({message: '提现金额不能超过可提金额!'})
  323. return false
  324. }
  325. }
  326. return true
  327. },
  328. /**
  329. * 生命周期函数--监听页面加载
  330. */
  331. onLoad(options: any) {
  332. /// 查询账户签约信息
  333. this.queryBankAccountSign()
  334. /// 资金账户查询
  335. this.accountFundInfo()
  336. /// 开始结束时间
  337. const start = loginQuery().systemParams.filter(obj => { return obj.paramcode === "012" })[0].paramvalue
  338. /// 开始结束时间
  339. const end = loginQuery().systemParams.filter(obj => { return obj.paramcode === "013" })[0].paramvalue
  340. const id = options.id
  341. /// 显示时间
  342. this.setData({ time: start+'-'+end, active: id })
  343. },
  344. /**
  345. * 生命周期函数--监听页面初次渲染完成
  346. */
  347. onReady() {
  348. },
  349. /**
  350. * 生命周期函数--监听页面显示
  351. */
  352. onShow() {
  353. this.setData({ active: this.data.active })
  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. })