index.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. <template>
  2. <!-- <doc-alert title="功能开启" url="https://doc.iocoder.cn/mall/build/" /> -->
  3. <!-- 搜索工作栏 -->
  4. <ContentWrap>
  5. <el-form
  6. ref="queryFormRef"
  7. :inline="true"
  8. :model="queryParams"
  9. class="-mb-15px"
  10. label-width="82px"
  11. >
  12. <el-form-item label="优惠券名称" prop="name">
  13. <el-input
  14. v-model="queryParams.name"
  15. class="!w-240px"
  16. clearable
  17. placeholder="请输入优惠劵名"
  18. @keyup="handleQuery"
  19. />
  20. </el-form-item>
  21. <el-form-item label="优惠类型" prop="discountType">
  22. <el-select
  23. v-model="queryParams.discountType"
  24. class="!w-240px"
  25. clearable
  26. placeholder="请选择优惠券类型"
  27. >
  28. <el-option
  29. v-for="dict in getIntDictOptions(DICT_TYPE.PROMOTION_DISCOUNT_TYPE)"
  30. :key="dict.value"
  31. :label="dict.label"
  32. :value="dict.value"
  33. />
  34. </el-select>
  35. </el-form-item>
  36. <el-form-item label="优惠券状态" prop="status">
  37. <el-select
  38. v-model="queryParams.status"
  39. class="!w-240px"
  40. clearable
  41. placeholder="请选择优惠券状态"
  42. >
  43. <el-option
  44. v-for="dict in getIntDictOptions(DICT_TYPE.COMMON_STATUS)"
  45. :key="dict.value"
  46. :label="dict.label"
  47. :value="dict.value"
  48. />
  49. </el-select>
  50. </el-form-item>
  51. <el-form-item label="创建时间" prop="createTime">
  52. <el-date-picker
  53. v-model="queryParams.createTime"
  54. :default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]"
  55. class="!w-240px"
  56. end-placeholder="结束日期"
  57. start-placeholder="开始日期"
  58. type="daterange"
  59. value-format="YYYY-MM-DD HH:mm:ss"
  60. />
  61. </el-form-item>
  62. <el-form-item>
  63. <el-button @click="handleQuery">
  64. <Icon class="mr-5px" icon="ep:search" />
  65. 搜索
  66. </el-button>
  67. <el-button @click="resetQuery">
  68. <Icon class="mr-5px" icon="ep:refresh" />
  69. 重置
  70. </el-button>
  71. <el-button
  72. v-hasPermi="['promotion:coupon-template:create']"
  73. plain
  74. type="primary"
  75. @click="openForm('create')"
  76. >
  77. <Icon class="mr-5px" icon="ep:plus" />
  78. 新增
  79. </el-button>
  80. </el-form-item>
  81. </el-form>
  82. </ContentWrap>
  83. <!-- 列表 -->
  84. <ContentWrap>
  85. <el-table v-loading="loading" :data="list">
  86. <el-table-column label="优惠券名称" min-width="140" prop="name" />
  87. <el-table-column label="类型" min-width="130" prop="productScope">
  88. <template #default="scope">
  89. <dict-tag :type="DICT_TYPE.PROMOTION_PRODUCT_SCOPE" :value="scope.row.productScope" />
  90. </template>
  91. </el-table-column>
  92. <el-table-column label="优惠" min-width="110" prop="discount">
  93. <template #default="scope">
  94. <dict-tag :type="DICT_TYPE.PROMOTION_DISCOUNT_TYPE" :value="scope.row.discountType" />
  95. <div>{{ discountFormat(scope.row) }}</div>
  96. </template>
  97. </el-table-column>
  98. <el-table-column label="领取方式" min-width="100" prop="takeType">
  99. <template #default="scope">
  100. <dict-tag :type="DICT_TYPE.PROMOTION_COUPON_TAKE_TYPE" :value="scope.row.takeType" />
  101. </template>
  102. </el-table-column>
  103. <el-table-column
  104. :formatter="validityTypeFormat"
  105. align="center"
  106. label="使用时间"
  107. prop="validityType"
  108. width="185"
  109. />
  110. <el-table-column align="center" label="发放数量" prop="totalCount" />
  111. <el-table-column
  112. :formatter="remainedCountFormat"
  113. align="center"
  114. label="剩余数量"
  115. prop="totalCount"
  116. />
  117. <el-table-column
  118. :formatter="takeLimitCountFormat"
  119. align="center"
  120. label="领取上限"
  121. prop="takeLimitCount"
  122. />
  123. <el-table-column align="center" label="状态" prop="status">
  124. <template #default="scope">
  125. <el-switch
  126. v-model="scope.row.status"
  127. :active-value="0"
  128. :inactive-value="1"
  129. @change="handleStatusChange(scope.row)"
  130. />
  131. </template>
  132. </el-table-column>
  133. <el-table-column
  134. :formatter="dateFormatter"
  135. align="center"
  136. label="创建时间"
  137. prop="createTime"
  138. width="180"
  139. />
  140. <el-table-column
  141. align="center"
  142. class-name="small-padding fixed-width"
  143. fixed="right"
  144. label="操作"
  145. width="120"
  146. >
  147. <template #default="scope">
  148. <el-button
  149. v-hasPermi="['promotion:coupon-template:update']"
  150. link
  151. type="primary"
  152. @click="openForm('update', scope.row.id)"
  153. >
  154. 修改
  155. </el-button>
  156. <el-button
  157. v-hasPermi="['promotion:coupon-template:delete']"
  158. link
  159. type="danger"
  160. @click="handleDelete(scope.row.id)"
  161. >
  162. 删除
  163. </el-button>
  164. </template>
  165. </el-table-column>
  166. </el-table>
  167. <!-- 分页 -->
  168. <Pagination
  169. v-model:limit="queryParams.pageSize"
  170. v-model:page="queryParams.pageNo"
  171. :total="total"
  172. @pagination="getList"
  173. />
  174. </ContentWrap>
  175. <!-- 表单弹窗:添加/修改 -->
  176. <CouponTemplateForm ref="formRef" @success="getList" />
  177. </template>
  178. <script lang="ts" setup>
  179. import * as CouponTemplateApi from '@/api/mall/promotion/coupon/couponTemplate'
  180. import { CommonStatusEnum } from '@/utils/constants'
  181. import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
  182. import { dateFormatter } from '@/utils/formatTime'
  183. import CouponTemplateForm from './CouponTemplateForm.vue'
  184. import {
  185. discountFormat,
  186. remainedCountFormat,
  187. takeLimitCountFormat,
  188. validityTypeFormat
  189. } from '@/views/mall/promotion/coupon/formatter'
  190. defineOptions({ name: 'PromotionCouponTemplate' })
  191. const message = useMessage() // 消息弹窗
  192. const { t } = useI18n() // 国际化
  193. const loading = ref(true) // 列表的加载中
  194. const total = ref(0) // 列表的总页数
  195. const list = ref([]) // 字典表格数据
  196. const queryParams = reactive({
  197. pageNo: 1,
  198. pageSize: 10,
  199. name: null,
  200. status: null,
  201. discountType: null,
  202. type: null,
  203. createTime: []
  204. })
  205. const queryFormRef = ref() // 搜索的表单
  206. /** 查询列表 */
  207. const getList = async () => {
  208. loading.value = true
  209. try {
  210. // 执行查询
  211. const data = await CouponTemplateApi.getCouponTemplatePage(queryParams)
  212. list.value = data.list
  213. total.value = data.total
  214. } finally {
  215. loading.value = false
  216. }
  217. }
  218. /** 搜索按钮操作 */
  219. const handleQuery = () => {
  220. queryParams.pageNo = 1
  221. getList()
  222. }
  223. /** 重置按钮操作 */
  224. const resetQuery = () => {
  225. queryFormRef?.value?.resetFields()
  226. handleQuery()
  227. }
  228. /** 添加/修改操作 */
  229. const formRef = ref()
  230. const openForm = (type: string, id?: number) => {
  231. formRef.value.open(type, id)
  232. }
  233. /** 优惠劵模板状态修改 */
  234. const handleStatusChange = async (row: any) => {
  235. // 此时,row 已经变成目标状态了,所以可以直接提交请求和提示
  236. let text = row.status === CommonStatusEnum.ENABLE ? '启用' : '停用'
  237. try {
  238. await message.confirm('确认要"' + text + '""' + row.name + '"优惠劵吗?')
  239. await CouponTemplateApi.updateCouponTemplateStatus(row.id, row.status)
  240. message.success(text + '成功')
  241. } catch {
  242. // 异常时,需要将 row.status 状态重置回之前的
  243. row.status =
  244. row.status === CommonStatusEnum.ENABLE ? CommonStatusEnum.DISABLE : CommonStatusEnum.ENABLE
  245. }
  246. }
  247. /** 删除按钮操作 */
  248. const handleDelete = async (id: number) => {
  249. try {
  250. // 删除的二次确认
  251. await message.confirm('是否确认删除优惠劵编号为"' + id + '"的数据项?')
  252. // 发起删除
  253. await CouponTemplateApi.deleteCouponTemplate(id)
  254. message.success(t('common.delSuccess'))
  255. // 刷新列表
  256. await getList()
  257. } catch {}
  258. }
  259. /** 初始化 **/
  260. onMounted(() => {
  261. getList()
  262. })
  263. </script>