CreatePayTransfer.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <template>
  2. <Dialog title="发起转账" v-model="dialogVisible" width="800px">
  3. <el-card style="margin-top: 10px">
  4. <el-descriptions title="转账信息" :column="2" border>
  5. <el-descriptions-item label="转账类型">
  6. {{ typeName }}
  7. </el-descriptions-item>
  8. <el-descriptions-item label="转账金额(元)">
  9. ¥{{ (transfer.price / 100.0).toFixed(2) }}
  10. </el-descriptions-item>
  11. <el-descriptions-item label="收款人姓名">
  12. {{ transfer.userName }}
  13. </el-descriptions-item>
  14. <el-descriptions-item label="支付宝登录账号" v-if="transfer.type === 1">
  15. {{ transfer.alipayLogonId }}
  16. </el-descriptions-item>
  17. <el-descriptions-item label="微信 openid" v-if="transfer.type === 2">
  18. {{ transfer.openid }}
  19. </el-descriptions-item>
  20. </el-descriptions>
  21. </el-card>
  22. <el-card style="margin-top: 20px">
  23. <template #header>
  24. <div class="card-header">
  25. <span>选择转账渠道</span>
  26. </div>
  27. </template>
  28. <div>
  29. <el-radio-group v-model="channelCode">
  30. <el-radio
  31. label="alipay_pc"
  32. :disabled="transfer.type === 2 || transfer.type === 3 || transfer.type === 4"
  33. >
  34. <img :src="svg_alipay_app" />
  35. </el-radio>
  36. <el-radio
  37. label="wx_app"
  38. :disabled="transfer.type === 1 || transfer.type === 3 || transfer.type === 4"
  39. >
  40. <img :src="svg_wx_app" />
  41. </el-radio>
  42. </el-radio-group>
  43. </div>
  44. </el-card>
  45. <el-divider />
  46. <div style="text-align: right">
  47. <el-button @click="submitForm" type="primary" :disabled="formLoading">确 定</el-button>
  48. <el-button @click="dialogVisible = false">取 消</el-button>
  49. </div>
  50. </Dialog>
  51. </template>
  52. <script lang="ts" setup>
  53. import * as PayTransferApi from '@/api/pay/transfer'
  54. import { computed, PropType } from 'vue'
  55. import { DICT_TYPE, getDictLabel } from '@/utils/dict'
  56. // 导入图标
  57. import svg_alipay_app from '@/assets/svgs/pay/icon/alipay_app.svg'
  58. import svg_wx_app from '@/assets/svgs/pay/icon/wx_app.svg'
  59. import { yuanToFen } from '@/utils'
  60. const { t } = useI18n() // 国际化
  61. const message = useMessage() // 消息弹窗
  62. const formLoading = ref(false) // 提交的按钮禁用
  63. const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调
  64. defineOptions({ name: 'CreatePayTransfer' })
  65. // 提交数据
  66. let submitTransferData: PayTransferApi.TransferVO
  67. const transfer = reactive({
  68. appId: undefined,
  69. channelCode: undefined,
  70. merchantTransferId: undefined,
  71. type: undefined,
  72. price: undefined,
  73. subject: undefined,
  74. userName: undefined,
  75. alipayLogonId: undefined,
  76. openid: undefined
  77. })
  78. const dialogVisible = ref(false)
  79. const typeName = computed(() => {
  80. return getDictLabel(DICT_TYPE.PAY_TRANSFER_TYPE, transfer.type)
  81. })
  82. const channelCode = computed(() => {
  83. let channelCode = 'alipay_pc'
  84. if (transfer.type === 2) {
  85. channelCode = 'wx_app'
  86. }
  87. // TODO 银行卡和钱包 转账待实现
  88. return channelCode
  89. })
  90. /** 打开弹窗 */
  91. const showPayTransfer = async (payTransfer: PayTransferApi.TransferVO) => {
  92. dialogVisible.value = true
  93. submitTransferData = payTransfer
  94. transfer.merchantTransferId = payTransfer.merchantTransferId
  95. transfer.price = payTransfer.price
  96. transfer.userName = payTransfer.userName
  97. transfer.type = payTransfer.type
  98. transfer.appId = payTransfer.appId
  99. transfer.subject = payTransfer.subject
  100. transfer.alipayLogonId = payTransfer.alipayLogonId
  101. transfer.openid = payTransfer.openid
  102. }
  103. /** 关闭弹窗 */
  104. const close = async () => {
  105. dialogVisible.value = false
  106. }
  107. defineExpose({ showPayTransfer, close }) // 提供 showPayTransfer, close 方法,用于打开, 关闭弹窗
  108. const submitForm = async () => {
  109. // 校验表单
  110. formLoading.value = true
  111. try {
  112. submitTransferData.channelCode = channelCode.value
  113. await PayTransferApi.createTransfer(submitTransferData)
  114. message.success('发起转账成功. 是否转账成功,以转账订单状态为准')
  115. // 发送操作成功的事件
  116. emit('success')
  117. dialogVisible.value = false
  118. } finally {
  119. formLoading.value = false
  120. }
  121. }
  122. </script>
  123. <style lang="scss" scoped>
  124. .card-header {
  125. display: flex;
  126. justify-content: space-between;
  127. align-items: center;
  128. }
  129. </style>