index.ts 10 KB

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