index.ts 11 KB

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