index.ts 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  1. import { ref, reactive, shallowRef, computed } from 'vue'
  2. import { useAccountStore, useUserStore, useLoginStore } from '@/stores'
  3. import {
  4. t2bBankWithdraw,
  5. queryBankAccountSign,
  6. t2bBankDeposit,
  7. queryCusBankSignBank,
  8. t2bBankSign,
  9. t2bBankCancelSign,
  10. accountFundInfoReq,
  11. queryBankCusBankExtendConfigs,
  12. t2bSMSVerificationCode
  13. } from '@/services/api/bank'
  14. import { SignStatus } from '@/constants/bank'
  15. import { decryptAES } from '@/services/websocket/package/crypto'
  16. import moment from "moment"
  17. const accountStore = useAccountStore()
  18. const loginStore = useLoginStore()
  19. const useStore = useUserStore()
  20. const { getSystemParamValue } = useUserStore()
  21. // 出金请求
  22. export function useDoWithdraw() {
  23. const loading = shallowRef(false)
  24. /// 获取当前是否已签约
  25. const bankAccountSign = shallowRef<Model.BankAccountSignRsp[]>([])
  26. const sign = computed<Partial<Model.BankAccountSignRsp>>(() => {
  27. if (bankAccountSign.value.length) {
  28. return bankAccountSign.value[0]
  29. }
  30. return {}
  31. })
  32. const formData = reactive<Partial<Proto.t2bBankWithdrawReq>>({
  33. AccountType: useStore.userInfo?.userinfotype,
  34. AppDateTime: moment(new Date()).format('YYYY-MM-DD HH:mm:ss')
  35. })
  36. /// 查询签约信息
  37. const request = queryBankAccountSign().then((res) => {
  38. if (res.data.length) {
  39. bankAccountSign.value = res.data
  40. const data = res.data[0]
  41. formData.Currency = data.currency
  42. formData.CusBankID = data.cusbankid
  43. formData.BankAccoutName = data.bankaccountname
  44. formData.OpenCardBankId = data.bankid
  45. formData.AccountCode = data.accountcode
  46. formData.BranchBankName = data.branchbankname
  47. formData.BankAccoutName = data.bankaccountname2
  48. formData.BankAccoutNum = data.bankaccountno2
  49. }
  50. })
  51. const onSubmit = async () => {
  52. await request
  53. loading.value = true
  54. return t2bBankWithdraw({
  55. data: {
  56. ...formData,
  57. ExtOperatorID: new Date().getTime()
  58. }
  59. }).finally(() => {
  60. loading.value = false
  61. })
  62. }
  63. return {
  64. loading,
  65. onSubmit,
  66. formData,
  67. sign
  68. }
  69. }
  70. // 充值请求
  71. export function useDoDeposit(userid?: number) {
  72. const loading = shallowRef(false)
  73. /// 获取当前是否已签约
  74. const sign = shallowRef<Model.BankAccountSignRsp[]>([])
  75. /// formData
  76. const formData = reactive<Partial<Proto.t2bBankDepositReq>>({})
  77. const request = queryBankAccountSign({
  78. data: {
  79. userid: userid ?? loginStore.userId
  80. }
  81. }).then((res) => {
  82. if (res.data.length) {
  83. sign.value = res.data
  84. const data = res.data[0]
  85. formData.Currency = data.currency
  86. formData.CusBankID = data.cusbankid
  87. formData.BankAccoutName = data.bankaccountname2
  88. formData.OpenCardBankId = data.bankid
  89. formData.AccountCode = data.accountcode
  90. formData.BankAccoutNum = data.bankaccountno2
  91. }
  92. })
  93. const onSubmit = async () => {
  94. await request
  95. loading.value = true
  96. return t2bBankDeposit({
  97. data: {
  98. ...formData,
  99. ExtOperatorID: new Date().getTime(),
  100. }
  101. }).finally(() => {
  102. loading.value = false
  103. })
  104. }
  105. return {
  106. loading,
  107. onSubmit,
  108. formData,
  109. sign
  110. }
  111. }
  112. /// 银行签约请求
  113. export function useDoBankSign() {
  114. const { userInfo } = useUserStore()
  115. const loading = shallowRef(false)
  116. const bankInfo = shallowRef<Model.BankAccountSignRsp>()
  117. /// 托管银行信息
  118. const cusSignBank = shallowRef<Model.CusBankSignBankRsp>()
  119. /// 查询签约银行信息
  120. const request = queryCusBankSignBank().then((res) => {
  121. if (res.data.length) {
  122. const data = res.data[0]
  123. cusSignBank.value = data
  124. formData.Currency = data.currency
  125. formData.CusBankID = data.cusbankid
  126. formData.TradeDate = data.tradedate
  127. }
  128. })
  129. /// 银行列表
  130. const banklist = computed(() => {
  131. return (cusSignBank.value?.Banklst ?? []).filter(e => e.status == 0)
  132. })
  133. /// 判断是否有签约信息 有就做修改
  134. queryBankAccountSign().then((res) => {
  135. bankInfo.value = res.data.filter(obj => {
  136. return ![SignStatus.Rescinded].includes(obj.signstatus)
  137. })[0]
  138. if (bankInfo.value) {
  139. ({
  140. currency: formData.Currency,
  141. cusbankid: formData.CusBankID,
  142. accountcode: formData.AccountCode,
  143. branchbankname: formData.OpenBankName,
  144. bankaccountno: formData.BankAccountNo,
  145. bankid: formData.OpenBankAccId,
  146. } = bankInfo.value)
  147. }
  148. })
  149. /// 数据
  150. const formData = reactive<Partial<Proto.t2bBankSignReq>>({
  151. AccountType: useStore.userInfo?.userinfotype,
  152. IsForce: 0,
  153. AgentCertType: 0,
  154. BankCardType: 0,
  155. BankAccountType: useStore.userInfo?.userinfotype,
  156. AccountCode: accountStore.currentAccountId.toString(),
  157. CertID: decryptAES(userInfo?.cardnum ?? ''),
  158. CertType: userInfo?.cardtypeid.toString(),
  159. BankAccountName: userInfo?.customername,
  160. MobilePhone: userInfo?.mobile2,
  161. AccountName: userInfo?.customername,
  162. })
  163. const onSubmit = async () => {
  164. await request
  165. loading.value = true
  166. // 默认未签约状态
  167. const { signstatus = SignStatus.Unsigned } = bankInfo.value ?? {}
  168. return t2bBankSign({
  169. data: {
  170. ...formData,
  171. OperateType: signstatus === SignStatus.Unsigned ? 1 : 2,
  172. ExtOperatorID: new Date().getTime(),
  173. AccountName: userInfo?.customername,
  174. ExBankName: banklist.value.find(obj => obj.bankid === formData.OpenBankAccId)?.bankname
  175. }
  176. }).finally(() => {
  177. loading.value = false
  178. })
  179. }
  180. return {
  181. loading,
  182. formData,
  183. banklist,
  184. onSubmit,
  185. bankInfo
  186. }
  187. }
  188. /// 银行解约请求
  189. export function useDoCancelBankSign() {
  190. /// 获取UserId
  191. const loading = shallowRef(false)
  192. const isloaded = shallowRef(false)
  193. const bankInfo = shallowRef<Model.BankAccountSignRsp>()
  194. /// 表单信息
  195. const formData = reactive<Partial<Proto.t2bBankCancelSignReq>>({
  196. IsForce: 0,
  197. })
  198. /// 获取当前是否已签约
  199. const sign = shallowRef<Model.BankAccountSignRsp[]>([])
  200. const formRefresh = () => {
  201. queryBankAccountSign().then((res) => {
  202. bankInfo.value = res.data[0];
  203. ({
  204. currency: formData.Currency,
  205. cusbankid: formData.CusBankID,
  206. accountcode: formData.AccountCode,
  207. } = bankInfo.value ?? {})
  208. }).finally(() => {
  209. isloaded.value = true
  210. })
  211. }
  212. const cancelSubmit = async () => {
  213. loading.value = true
  214. /// 发起请求
  215. return t2bBankCancelSign({
  216. data: {
  217. ...formData,
  218. ExtOperatorID: new Date().getTime(),
  219. }
  220. }).finally(() => {
  221. loading.value = false
  222. })
  223. }
  224. return {
  225. loading,
  226. isloaded,
  227. cancelSubmit,
  228. formData,
  229. sign,
  230. bankInfo,
  231. formRefresh
  232. }
  233. }
  234. /// 账户资金信息请求
  235. export function useAccountFundInfo() {
  236. /// 数据
  237. const fund = shallowRef<Partial<Proto.AccountFundInfoRsp>>({})
  238. /// 账户资金信息
  239. accountFundInfoReq({
  240. data: {
  241. QueryBitMask: 2,
  242. OrderId: new Date().getTime(),
  243. AccountId: accountStore.currentAccountId,
  244. }
  245. }).then((res) => {
  246. fund.value = res
  247. })
  248. return {
  249. fund
  250. }
  251. }
  252. /// 账户资金信息请求
  253. export function useBankAccouuntSign() {
  254. /// 数据
  255. const fund = shallowRef<Partial<Proto.AccountFundInfoRsp>>({})
  256. /// 账户资金信息
  257. accountFundInfoReq({
  258. data: {
  259. QueryBitMask: 2,
  260. OrderId: new Date().getTime(),
  261. AccountId: accountStore.currentAccountId,
  262. }
  263. }).then((res) => {
  264. fund.value = res
  265. })
  266. return {
  267. fund
  268. }
  269. }
  270. /// 查询托管银行扩展配置信息
  271. export function useDoCusBankExtendConfigs(extendbiztype?: number) {
  272. /// 托管银行拓展信息
  273. const configs = ref<(Model.BankCusBankExtendConfigRsp & { value: string })[]>([])
  274. /// 托管银行信息
  275. const cusBank = shallowRef<Partial<Model.CusBankSignBankRsp>>({})
  276. const end = shallowRef<string>('')
  277. /// 查询签约银行信息
  278. queryCusBankSignBank().then((res) => {
  279. if (res.data.length) {
  280. const data = res.data[0]
  281. cusBank.value = data
  282. end.value = (data.cusbankid === 'jdjs' ? getSystemParamValue('1003') : getSystemParamValue('013')) ?? ''
  283. /// 查询配置信息
  284. queryBankCusBankExtendConfigs({
  285. data: {
  286. cusbankid: data?.cusbankid,
  287. extendbiztype: extendbiztype
  288. },
  289. }).then((res) => {
  290. if (res.data.length != 0) {
  291. configs.value = res.data.map(obj => ({
  292. ...obj,
  293. value: obj.fieldcode === 'legal_name' ? (useStore.userInfo?.legalpersonname ?? '') : ''
  294. }))
  295. }
  296. })
  297. }
  298. })
  299. return {
  300. configs,
  301. end,
  302. cusBank
  303. }
  304. }
  305. /// 查询托管银行信息
  306. export function useQueryCusBankSignBank() {
  307. /// 数据
  308. const cusBank = shallowRef<Partial<Model.CusBankSignBankRsp>>({})
  309. /// 查询签约银行信息
  310. const request = queryCusBankSignBank().then((res) => {
  311. if (res.data.length) {
  312. const data = res.data[0]
  313. cusBank.value = data
  314. }
  315. })
  316. /// 银行列表
  317. const banklist = computed(() => {
  318. return (cusBank.value?.Banklst ?? []).filter(e => e.status == 0)
  319. })
  320. return { cusBank, banklist, request }
  321. }
  322. /// 银行获取手机验证码请求
  323. export function useT2bSMSVerificationCode() {
  324. const loading = shallowRef(false)
  325. /// 查询签约银行信息
  326. const request = queryCusBankSignBank().then((res) => {
  327. if (res.data.length) {
  328. const data = res.data[0]
  329. swsFormData.CusBankID = data.cusbankid
  330. swsFormData.TradeDate = data.tradedate
  331. }
  332. })
  333. /// 数据
  334. const swsFormData = reactive<Partial<Proto.t2bSWSVerificationCodeReq>>({
  335. Mobile: useStore.userInfo?.mobile2,
  336. AccountCode: accountStore.currentAccountId.toString(),
  337. extend_info: JSON.stringify({ "sex": 1 })
  338. })
  339. const smsVerificationCode = async () => {
  340. await request
  341. loading.value = true
  342. return t2bSMSVerificationCode({
  343. data: {
  344. ExtOperatorID: new Date().getTime(),
  345. ...swsFormData,
  346. }
  347. }).finally(() => {
  348. loading.value = false
  349. })
  350. }
  351. return {
  352. loading,
  353. swsFormData,
  354. smsVerificationCode
  355. }
  356. }