index.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. <template>
  2. <ContentWrap>
  3. <!-- 搜索工作栏 -->
  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="status">
  12. <el-select
  13. v-model="queryParams.status"
  14. class="!w-240px"
  15. clearable
  16. placeholder="请选择活动状态"
  17. >
  18. <el-option
  19. v-for="dict in getIntDictOptions(DICT_TYPE.COMMON_STATUS)"
  20. :key="dict.value"
  21. :label="dict.label"
  22. :value="dict.value"
  23. />
  24. </el-select>
  25. </el-form-item>
  26. <el-form-item>
  27. <el-button @click="handleQuery">
  28. <Icon class="mr-5px" icon="ep:search" />
  29. 搜索
  30. </el-button>
  31. <el-button @click="resetQuery">
  32. <Icon class="mr-5px" icon="ep:refresh" />
  33. 重置
  34. </el-button>
  35. <el-button
  36. v-hasPermi="['promotion:point-activity:create']"
  37. plain
  38. type="primary"
  39. @click="openForm('create')"
  40. >
  41. <Icon class="mr-5px" icon="ep:plus" />
  42. 新增
  43. </el-button>
  44. </el-form-item>
  45. </el-form>
  46. </ContentWrap>
  47. <!-- 列表 -->
  48. <ContentWrap>
  49. <el-table v-loading="loading" :data="list" :show-overflow-tooltip="true" :stripe="true">
  50. <el-table-column label="活动编号" min-width="80" prop="id" />
  51. <el-table-column label="产品图片" min-width="80" prop="spuName">
  52. <template #default="scope">
  53. <el-image
  54. :preview-src-list="[scope.row.picUrl]"
  55. :src="scope.row.picUrl"
  56. class="h-40px w-40px"
  57. preview-teleported
  58. />
  59. </template>
  60. </el-table-column>
  61. <el-table-column label="产品标题" min-width="300" prop="spuName" />
  62. <el-table-column
  63. :formatter="fenToYuanFormat"
  64. label="原价"
  65. min-width="100"
  66. prop="marketPrice"
  67. />
  68. <el-table-column label="原价" min-width="100" prop="marketPrice" />
  69. <el-table-column align="center" label="活动状态" min-width="100" prop="status">
  70. <template #default="scope">
  71. <dict-tag :type="DICT_TYPE.COMMON_STATUS" :value="scope.row.status" />
  72. </template>
  73. </el-table-column>
  74. <el-table-column align="center" label="库存" min-width="80" prop="stock" />
  75. <el-table-column align="center" label="总库存" min-width="80" prop="totalStock" />
  76. <el-table-column align="center" label="已兑换数量" min-width="100" prop="redeemedQuantity">
  77. <template #default="{ row }">
  78. {{ getRedeemedQuantity(row) }}
  79. </template>
  80. </el-table-column>
  81. <el-table-column
  82. :formatter="dateFormatter"
  83. align="center"
  84. label="创建时间"
  85. prop="createTime"
  86. width="180px"
  87. />
  88. <el-table-column align="center" fixed="right" label="操作" width="150px">
  89. <template #default="scope">
  90. <el-button
  91. v-hasPermi="['promotion:point-activity:update']"
  92. link
  93. type="primary"
  94. @click="openForm('update', scope.row.id)"
  95. >
  96. 编辑
  97. </el-button>
  98. <el-button
  99. v-if="scope.row.status === 0"
  100. v-hasPermi="['promotion:point-activity:close']"
  101. link
  102. type="danger"
  103. @click="handleClose(scope.row.id)"
  104. >
  105. 关闭
  106. </el-button>
  107. <el-button
  108. v-else
  109. v-hasPermi="['promotion:point-activity:delete']"
  110. link
  111. type="danger"
  112. @click="handleDelete(scope.row.id)"
  113. >
  114. 删除
  115. </el-button>
  116. </template>
  117. </el-table-column>
  118. </el-table>
  119. <!-- 分页 -->
  120. <Pagination
  121. v-model:limit="queryParams.pageSize"
  122. v-model:page="queryParams.pageNo"
  123. :total="total"
  124. @pagination="getList"
  125. />
  126. </ContentWrap>
  127. <!-- 表单弹窗:添加/修改 -->
  128. <PointActivityForm ref="formRef" @success="getList" />
  129. </template>
  130. <script lang="ts" setup>
  131. import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
  132. import { dateFormatter } from '@/utils/formatTime'
  133. import PointActivityForm from './PointActivityForm.vue'
  134. import { fenToYuanFormat } from '@/utils/formatter'
  135. import { PointActivityApi } from '@/api/mall/promotion/point'
  136. defineOptions({ name: 'PointActivity' })
  137. const message = useMessage() // 消息弹窗
  138. const { t } = useI18n() // 国际化
  139. const loading = ref(true) // 列表的加载中
  140. const total = ref(0) // 列表的总页数
  141. const list = ref([]) // 列表的数据
  142. const queryParams = reactive({
  143. pageNo: 1,
  144. pageSize: 10,
  145. name: null,
  146. status: null
  147. })
  148. const queryFormRef = ref() // 搜索的表单
  149. const getRedeemedQuantity = computed(() => (row: any) => (row.totalStock || 0) - (row.stock || 0)) // 获得产品已兑换数量
  150. /** 查询列表 */
  151. const getList = async () => {
  152. loading.value = true
  153. try {
  154. const data = await PointActivityApi.getPointActivityPage(queryParams)
  155. list.value = data.list
  156. total.value = data.total
  157. } finally {
  158. loading.value = false
  159. }
  160. }
  161. /** 搜索按钮操作 */
  162. const handleQuery = () => {
  163. queryParams.pageNo = 1
  164. getList()
  165. }
  166. /** 重置按钮操作 */
  167. const resetQuery = () => {
  168. queryFormRef.value.resetFields()
  169. handleQuery()
  170. }
  171. /** 添加/修改操作 */
  172. const formRef = ref()
  173. const openForm = (type: string, id?: number) => {
  174. formRef.value.open(type, id)
  175. }
  176. /** 关闭按钮操作 */
  177. const handleClose = async (id: number) => {
  178. try {
  179. // 关闭的二次确认
  180. await message.confirm('确认关闭该积分商城活动吗?')
  181. // 发起关闭
  182. await PointActivityApi.closePointActivity(id)
  183. message.success('关闭成功')
  184. // 刷新列表
  185. await getList()
  186. } catch {}
  187. }
  188. /** 删除按钮操作 */
  189. const handleDelete = async (id: number) => {
  190. try {
  191. // 删除的二次确认
  192. await message.delConfirm()
  193. // 发起删除
  194. await PointActivityApi.deletePointActivity(id)
  195. message.success(t('common.delSuccess'))
  196. // 刷新列表
  197. await getList()
  198. } catch {}
  199. }
  200. /** 初始化 **/
  201. onMounted(async () => {
  202. await getList()
  203. })
  204. </script>