wallet.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. <template>
  2. <cl-crud ref="Crud">
  3. <cl-row>
  4. <!-- 刷新按钮 -->
  5. <cl-refresh-btn />
  6. <!-- 新增按钮 -->
  7. <cl-add-btn />
  8. <!-- 删除按钮 -->
  9. <cl-multi-delete-btn />
  10. <cl-flex1 />
  11. <!-- 关键字搜索 -->
  12. <cl-search-key placeholder="搜索关键字" />
  13. </cl-row>
  14. <cl-row>
  15. <!-- 数据表格 -->
  16. <cl-table ref="Table">
  17. <template #slot-btn="{ scope }">
  18. <el-button text bg type="success" @click="rechange(scope.row)">充值</el-button>
  19. <el-button text bg type="success" @click="showWithdraw(scope.row)"
  20. >提现</el-button
  21. >
  22. <el-button text bg type="success" @click="showTransfer(scope.row)"
  23. >划转</el-button
  24. >
  25. </template>
  26. </cl-table>
  27. </cl-row>
  28. <cl-row>
  29. <cl-flex1 />
  30. <!-- 分页控件 -->
  31. <cl-pagination />
  32. </cl-row>
  33. <!-- 新增、编辑 -->
  34. <cl-upsert ref="Upsert">
  35. <template #slot-currency="{ scope }">
  36. <el-select v-model="scope.currency" clearable>
  37. <el-option
  38. v-for="item in currencyList.filter(
  39. item =>
  40. channelList
  41. .find(v => v.code == scope.channel)
  42. ?.supportedCurrencies.includes(item.id) || item.type == '2'
  43. )"
  44. :key="item.id"
  45. :label="item.label"
  46. :value="item.value"
  47. />
  48. </el-select>
  49. </template>
  50. </cl-upsert>
  51. <withdraw
  52. v-if="WithdrawVisible"
  53. :channel="channel"
  54. :currency="currency"
  55. v-model:show="WithdrawVisible"
  56. @refresh="refresh"
  57. />
  58. <transfer
  59. v-if="TransferVisible"
  60. :fromWalletId="fromWalletId"
  61. :channel="channel"
  62. v-model:show="TransferVisible"
  63. @refresh="refresh"
  64. />
  65. <cl-dialog title="充值信息" v-model="rechangeVisible" width="80%">
  66. <div v-if="rechangeInfo && rechangeInfo.currency === 'EUR'" class="currency-box">
  67. <el-row style="margin-bottom: 12px">
  68. <el-col :span="12">
  69. <span class="label">bic:</span>
  70. <span class="content">{{ rechangeInfo.config[0].bic }}</span>
  71. </el-col>
  72. <el-col :span="12">
  73. <span class="label">iBan:</span
  74. ><span class="content">{{ rechangeInfo.config[0].iBan }}</span>
  75. </el-col>
  76. </el-row>
  77. <el-row style="margin-bottom: 12px">
  78. <el-col :span="12">
  79. <span class="label">status:</span
  80. ><span class="content">{{ rechangeInfo.config[0].status }}</span>
  81. </el-col>
  82. <el-col :span="12">
  83. <span class="label">bankName:</span
  84. ><span class="content">{{ rechangeInfo.config[0].bankName }}</span>
  85. </el-col>
  86. </el-row>
  87. <el-row style="margin-bottom: 12px">
  88. <el-col :span="12">
  89. <span class="label">currency:</span
  90. ><span class="content">{{ rechangeInfo.config[0].currency }}</span>
  91. </el-col>
  92. <el-col :span="12">
  93. <span class="label">bankAddress:</span
  94. ><span class="content">{{ rechangeInfo.config[0].bankAddress }}</span>
  95. </el-col>
  96. </el-row>
  97. <el-row style="margin-bottom: 12px">
  98. <el-col :span="12">
  99. <span class="label">bankCountry:</span
  100. ><span class="content">{{ rechangeInfo.config[0].bankCountry }}</span>
  101. </el-col>
  102. <el-col :span="12">
  103. <span class="label">accountNumber:</span
  104. ><span class="content">{{ rechangeInfo.config[0].accountNumber }}</span>
  105. </el-col>
  106. </el-row>
  107. <el-row style="margin-bottom: 12px">
  108. <el-col :span="12">
  109. <span class="label">routingCodeEntries:</span
  110. ><span class="content">{{
  111. rechangeInfo.config[0].routingCodeEntries
  112. }}</span>
  113. </el-col>
  114. <el-col :span="12">
  115. <span class="label">bankAccountHolderName:</span
  116. ><span class="content">{{
  117. rechangeInfo.config[0].bankAccountHolderName
  118. }}</span>
  119. </el-col>
  120. </el-row>
  121. </div>
  122. <div v-else>
  123. <pre class="json-content">{{ rechangeInfo.config[0] }}</pre>
  124. </div>
  125. </cl-dialog>
  126. </cl-crud>
  127. </template>
  128. <script lang="ts" name="payment-wallet" setup>
  129. import Withdraw from './components/withdraw.vue';
  130. import Transfer from './components/transfer.vue';
  131. import { useCrud, useTable, useUpsert } from '@cool-vue/crud';
  132. import { useCool } from '/@/cool';
  133. import { ref } from 'vue';
  134. import { ElMessage } from 'element-plus';
  135. import ClCrud from '/~/crud/src/components/crud';
  136. const { service } = useCool();
  137. const WithdrawVisible = ref(false);
  138. const TransferVisible = ref(false);
  139. const channel = ref('');
  140. const currency = ref('');
  141. const fromWalletId = ref('');
  142. const rechangeVisible = ref(false);
  143. const currencyList = ref([] as any);
  144. const rechangeInfo: any = ref({});
  145. service.payment.currency.list().then(res => {
  146. currencyList.value = res.map(v => ({ label: v.name, value: v.code, id: v.id, type: v.type }));
  147. });
  148. const channelList = ref([] as any);
  149. const getCustomerList = ref([] as any);
  150. // cl-upsert
  151. const Upsert = useUpsert({
  152. items: [
  153. {
  154. label: '渠道',
  155. prop: 'channel',
  156. component: { name: 'el-select', props: { clearable: true } },
  157. required: true
  158. },
  159. {
  160. label: '货币类型',
  161. prop: 'currency',
  162. component: { name: 'slot-currency', props: { clearable: true } },
  163. required: true
  164. }
  165. ],
  166. async onOpen() {
  167. channelList.value = await service.payment.channel.list();
  168. Upsert.value?.setOptions(
  169. 'channel',
  170. channelList.value.map(v => ({ label: v.name, value: v.code }))
  171. );
  172. // console.log(11300000888, channelList.value);
  173. // getCustomerList.value = await service.payment.customer.list({ merchantId: 24 });
  174. // console.log(1130000, getCustomerList.value);
  175. // getCustomerList = await service.payment.customer.list({});
  176. }
  177. });
  178. // cl-table
  179. const Table = useTable({
  180. columns: [
  181. { type: 'selection' },
  182. { label: '渠道', prop: 'channel', minWidth: 140 },
  183. { label: '货币类型', prop: 'currency', minWidth: 140 },
  184. { label: '余额', prop: 'balance', minWidth: 140 },
  185. { label: '状态', prop: 'status', minWidth: 140 },
  186. { type: 'op', buttons: ['slot-btn', 'edit', 'delete'], width: 300 }
  187. ]
  188. });
  189. // cl-crud
  190. const Crud = useCrud(
  191. {
  192. service: service.payment.wallet
  193. },
  194. app => {
  195. app.refresh();
  196. }
  197. );
  198. const showWithdraw = (row: any) => {
  199. channel.value = row.channel;
  200. currency.value = row.currency;
  201. WithdrawVisible.value = true;
  202. };
  203. const showTransfer = (row: any) => {
  204. fromWalletId.value = row.id;
  205. channel.value = row.channel;
  206. TransferVisible.value = true;
  207. };
  208. const rechange = async row => {
  209. rechangeInfo.value = null;
  210. if (!/^(TRC20|ERC20)$/.test(row.currency)) {
  211. rechangeInfo.value = row;
  212. } else {
  213. try {
  214. const res = await service.payment.wallet.order({
  215. channel: row.channel,
  216. currency: row.currency
  217. });
  218. rechangeInfo.value = {
  219. config: {
  220. 充值链接: res.payment_url,
  221. 充值地址: res.address
  222. }
  223. };
  224. } catch (e: any) {
  225. console.log(e);
  226. ElMessage.error(e.message);
  227. }
  228. }
  229. rechangeVisible.value = true;
  230. };
  231. // 刷新
  232. function refresh(params?: any) {
  233. Crud.value?.refresh(params);
  234. }
  235. </script>
  236. <style lang="scss" scoped>
  237. .json-content {
  238. white-space: pre-wrap;
  239. /* 保留空格和换行 */
  240. word-wrap: break-word;
  241. /* 允许长单词或 URL 地址换行到下一行 */
  242. font-family: monospace;
  243. /* 使用等宽字体 */
  244. background: #f5f5f5;
  245. /* 浅灰色背景 */
  246. color: #333;
  247. padding: 15px;
  248. /* 内边距 */
  249. border-radius: 4px;
  250. /* 圆角 */
  251. max-height: 500px;
  252. /* 最大高度 */
  253. overflow: auto;
  254. /* 内容过多时显示滚动条 */
  255. }
  256. .currency-box {
  257. .el-col-12 {
  258. display: flex;
  259. align-items: center;
  260. .label {
  261. flex: 0 0 200px;
  262. font-weight: bold;
  263. display: block;
  264. }
  265. .content {
  266. display: block;
  267. }
  268. }
  269. }
  270. </style>