UserCouponList.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. <template>
  2. <!-- 搜索工作栏 -->
  3. <ContentWrap>
  4. <el-form
  5. ref="queryFormRef"
  6. :inline="true"
  7. :model="queryParams"
  8. class="-mb-15px"
  9. label-width="68px"
  10. >
  11. <el-form-item label="创建时间" prop="createTime">
  12. <el-date-picker
  13. v-model="queryParams.createTime"
  14. value-format="YYYY-MM-DD HH:mm:ss"
  15. type="daterange"
  16. start-placeholder="开始日期"
  17. end-placeholder="结束日期"
  18. :default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]"
  19. class="!w-240px"
  20. />
  21. </el-form-item>
  22. <el-form-item>
  23. <el-button @click="handleQuery"> <Icon icon="ep:search" class="mr-5px" />搜索 </el-button>
  24. <el-button @click="resetQuery"> <Icon icon="ep:refresh" class="mr-5px" />重置 </el-button>
  25. </el-form-item>
  26. </el-form>
  27. </ContentWrap>
  28. <ContentWrap>
  29. <!-- Tab 选项:真正的内容在 Lab -->
  30. <el-tabs v-model="activeTab" type="card" @tab-change="onTabChange">
  31. <el-tab-pane
  32. v-for="tab in statusTabs"
  33. :key="tab.value"
  34. :label="tab.label"
  35. :name="tab.value"
  36. />
  37. </el-tabs>
  38. <!-- 列表 -->
  39. <el-table v-loading="loading" :data="list">
  40. <el-table-column label="优惠劵" align="center" prop="name" />
  41. <el-table-column label="优惠券类型" align="center" prop="discountType">
  42. <template #default="scope">
  43. <dict-tag :type="DICT_TYPE.PROMOTION_DISCOUNT_TYPE" :value="scope.row.discountType" />
  44. </template>
  45. </el-table-column>
  46. <el-table-column label="领取方式" align="center" prop="takeType">
  47. <template #default="scope">
  48. <dict-tag :type="DICT_TYPE.PROMOTION_COUPON_TAKE_TYPE" :value="scope.row.takeType" />
  49. </template>
  50. </el-table-column>
  51. <el-table-column label="状态" align="center" prop="status">
  52. <template #default="scope">
  53. <dict-tag :type="DICT_TYPE.PROMOTION_COUPON_STATUS" :value="scope.row.status" />
  54. </template>
  55. </el-table-column>
  56. <el-table-column
  57. label="领取时间"
  58. align="center"
  59. prop="createTime"
  60. :formatter="dateFormatter"
  61. width="180"
  62. />
  63. <el-table-column
  64. label="使用时间"
  65. align="center"
  66. prop="useTime"
  67. :formatter="dateFormatter"
  68. width="180"
  69. />
  70. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  71. <template #default="scope">
  72. <el-button
  73. v-hasPermi="['promotion:coupon:delete']"
  74. type="danger"
  75. link
  76. @click="handleDelete(scope.row.id)"
  77. >
  78. 回收
  79. </el-button>
  80. </template>
  81. </el-table-column>
  82. </el-table>
  83. <!-- 分页 -->
  84. <Pagination
  85. v-model:limit="queryParams.pageSize"
  86. v-model:page="queryParams.pageNo"
  87. :total="total"
  88. @pagination="getList"
  89. />
  90. </ContentWrap>
  91. </template>
  92. <script setup lang="ts" name="UserCouponList">
  93. import { deleteCoupon, getCouponPage } from '@/api/mall/promotion/coupon/coupon'
  94. import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
  95. import { dateFormatter } from '@/utils/formatTime'
  96. defineOptions({ name: 'UserCouponList' })
  97. const { userId }: { userId: number } = defineProps({
  98. userId: {
  99. type: Number,
  100. required: true
  101. }
  102. }) //用户编号
  103. const message = useMessage() // 消息弹窗
  104. const loading = ref(true) // 列表的加载中
  105. const total = ref(0) // 列表的总页数
  106. const list = ref([]) // 字典表格数据
  107. // 查询参数
  108. const queryParams = reactive({
  109. pageNo: 1,
  110. pageSize: 10,
  111. createTime: [],
  112. status: undefined,
  113. userIds: undefined
  114. })
  115. const queryFormRef = ref() // 搜索的表单
  116. const activeTab = ref('all') // Tab 筛选
  117. const statusTabs = reactive([
  118. {
  119. label: '全部',
  120. value: 'all'
  121. }
  122. ])
  123. /** 查询列表 */
  124. const getList = async () => {
  125. loading.value = true
  126. // 执行查询
  127. try {
  128. queryParams.userIds = userId
  129. const data = await getCouponPage(queryParams)
  130. list.value = data.list
  131. total.value = data.total
  132. } finally {
  133. loading.value = false
  134. }
  135. }
  136. /** 搜索按钮操作 */
  137. const handleQuery = () => {
  138. queryParams.pageNo = 1
  139. getList()
  140. }
  141. /** 重置按钮操作 */
  142. const resetQuery = () => {
  143. queryFormRef.value?.resetFields()
  144. handleQuery()
  145. }
  146. /** 删除按钮操作 */
  147. const handleDelete = async (id: number) => {
  148. try {
  149. // 二次确认
  150. await message.confirm(
  151. '回收将会收回会员领取的待使用的优惠券,已使用的将无法回收,确定要回收所选优惠券吗?'
  152. )
  153. // 发起删除
  154. await deleteCoupon(id)
  155. message.notifySuccess('回收成功')
  156. // 重新加载列表
  157. await getList()
  158. } catch {}
  159. }
  160. /** tab 切换 */
  161. const onTabChange = (tabName) => {
  162. queryParams.status = tabName === 'all' ? undefined : tabName
  163. getList()
  164. }
  165. /** 初始化 **/
  166. onMounted(() => {
  167. getList()
  168. // 设置 statuses 过滤
  169. for (const dict of getIntDictOptions(DICT_TYPE.PROMOTION_COUPON_STATUS)) {
  170. statusTabs.push({
  171. label: dict.label,
  172. value: dict.value as string
  173. })
  174. }
  175. })
  176. </script>