CouponSendForm.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <template>
  2. <Dialog v-model="dialogVisible" :appendToBody="true" title="发送优惠券" width="70%">
  3. <!-- 搜索工作栏 -->
  4. <el-form
  5. ref="queryFormRef"
  6. :inline="true"
  7. :model="queryParams"
  8. class="-mb-15px"
  9. label-width="82px"
  10. >
  11. <el-form-item label="优惠券名称" prop="name">
  12. <el-input
  13. v-model="queryParams.name"
  14. class="!w-240px"
  15. placeholder="请输入优惠劵名"
  16. clearable
  17. @keyup="handleQuery"
  18. />
  19. </el-form-item>
  20. <el-form-item>
  21. <el-button @click="handleQuery">
  22. <Icon class="mr-5px" icon="ep:search" />
  23. 搜索
  24. </el-button>
  25. <el-button @click="resetQuery">
  26. <Icon class="mr-5px" icon="ep:refresh" />
  27. 重置
  28. </el-button>
  29. </el-form-item>
  30. </el-form>
  31. <!-- 列表 -->
  32. <el-table v-loading="loading" :data="list" show-overflow-tooltip>
  33. <el-table-column align="center" label="优惠券名称" prop="name" min-width="60" />
  34. <el-table-column
  35. label="优惠金额 / 折扣"
  36. align="center"
  37. prop="discount"
  38. :formatter="discountFormat"
  39. min-width="60"
  40. />
  41. <el-table-column
  42. align="center"
  43. label="最低消费"
  44. prop="usePrice"
  45. min-width="60"
  46. :formatter="usePriceFormat"
  47. />
  48. <el-table-column
  49. align="center"
  50. label="有效期限"
  51. prop="validityType"
  52. min-width="140"
  53. :formatter="validityTypeFormat"
  54. />
  55. <el-table-column
  56. align="center"
  57. label="剩余数量"
  58. min-width="60"
  59. :formatter="remainedCountFormat"
  60. />
  61. <el-table-column label="操作" align="center" min-width="60px" fixed="right">
  62. <template #default="scope">
  63. <el-button
  64. link
  65. type="primary"
  66. :disabled="sendLoading"
  67. :loading="sendLoading"
  68. @click="handleSendCoupon(scope.row.id)"
  69. v-hasPermi="['member:level:update']"
  70. >
  71. 发送
  72. </el-button>
  73. </template>
  74. </el-table-column>
  75. </el-table>
  76. <!-- 分页 -->
  77. <Pagination
  78. v-model:limit="queryParams.pageSize"
  79. v-model:page="queryParams.pageNo"
  80. :total="total"
  81. @pagination="getList"
  82. />
  83. <div class="clear-both"></div>
  84. </Dialog>
  85. </template>
  86. <script lang="ts" setup>
  87. import * as CouponTemplateApi from '@/api/mall/promotion/coupon/couponTemplate'
  88. import * as CouponApi from '@/api/mall/promotion/coupon/coupon'
  89. import {
  90. discountFormat,
  91. remainedCountFormat,
  92. usePriceFormat,
  93. validityTypeFormat
  94. } from '@/views/mall/promotion/coupon/formatter'
  95. import { CouponTemplateTakeTypeEnum } from '@/utils/constants'
  96. defineOptions({ name: 'PromotionCouponSendForm' })
  97. const message = useMessage() // 消息弹窗
  98. const total = ref(0) // 列表的总页数
  99. const list = ref<any[]>([]) // 列表的数据
  100. const loading = ref(false) // 列表的加载中
  101. const sendLoading = ref(false) // 发送按钮的加载中
  102. const dialogVisible = ref(false) // 弹窗的是否展示
  103. const queryParams = ref({
  104. pageNo: 1,
  105. pageSize: 10,
  106. name: null,
  107. canTakeTypes: [CouponTemplateTakeTypeEnum.ADMIN.type]
  108. }) // 查询参数
  109. const queryFormRef = ref() // 搜索的表单
  110. // 领取人的编号列表
  111. let userIds: number[] = []
  112. /** 打开弹窗 */
  113. const open = (ids: number[]) => {
  114. userIds = ids
  115. // 打开时重置查询,防止发送列表剩余数量未更新的问题
  116. resetQuery()
  117. dialogVisible.value = true
  118. }
  119. defineExpose({ open }) // 提供 open 方法,用于打开弹窗
  120. /** 查询列表 */
  121. const getList = async () => {
  122. loading.value = true
  123. try {
  124. const data = await CouponTemplateApi.getCouponTemplatePage(queryParams.value)
  125. list.value = data.list
  126. total.value = data.total
  127. } finally {
  128. loading.value = false
  129. }
  130. }
  131. /** 搜索按钮操作 */
  132. const handleQuery = () => {
  133. queryParams.value.pageNo = 1
  134. getList()
  135. }
  136. /** 重置按钮操作 */
  137. const resetQuery = () => {
  138. queryFormRef?.value?.resetFields()
  139. handleQuery()
  140. }
  141. /** 发送操作 **/
  142. const handleSendCoupon = async (templateId: number) => {
  143. try {
  144. sendLoading.value = true
  145. await CouponApi.sendCoupon({ templateId, userIds })
  146. // 提示
  147. message.success('发送成功')
  148. dialogVisible.value = false
  149. } finally {
  150. sendLoading.value = false
  151. }
  152. }
  153. </script>