index.vue 5.6 KB

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