index.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. <template>
  2. <!-- 统计信息展示 -->
  3. <el-row :gutter="12">
  4. <el-col :span="6">
  5. <ContentWrap class="h-[110px] pb-0!">
  6. <div class="flex items-center">
  7. <div
  8. class="h-[50px] w-[50px] flex items-center justify-center"
  9. style="color: rgb(24, 144, 255); background-color: rgba(24, 144, 255, 0.1)"
  10. >
  11. <Icon :size="23" icon="fa:user-times" />
  12. </div>
  13. <div class="ml-[20px]">
  14. <div class="mb-8px text-14px text-gray-400">参与人数(个)</div>
  15. <CountTo
  16. :duration="2600"
  17. :end-val="recordSummary.userCount"
  18. :start-val="0"
  19. class="text-20px"
  20. />
  21. </div>
  22. </div>
  23. </ContentWrap>
  24. </el-col>
  25. <el-col :span="6">
  26. <ContentWrap class="h-[110px]">
  27. <div class="flex items-center">
  28. <div
  29. class="h-[50px] w-[50px] flex items-center justify-center"
  30. style="color: rgb(162, 119, 255); background-color: rgba(162, 119, 255, 0.1)"
  31. >
  32. <Icon :size="23" icon="fa:user-plus" />
  33. </div>
  34. <div class="ml-[20px]">
  35. <div class="mb-8px text-14px text-gray-400">成团数量(个)</div>
  36. <CountTo
  37. :duration="2600"
  38. :end-val="recordSummary.successCount"
  39. :start-val="0"
  40. class="text-20px"
  41. />
  42. </div>
  43. </div>
  44. </ContentWrap>
  45. </el-col>
  46. <el-col :span="6">
  47. <ContentWrap class="h-[110px]">
  48. <div class="flex items-center">
  49. <div
  50. class="h-[50px] w-[50px] flex items-center justify-center"
  51. style="color: rgb(162, 119, 255); background-color: rgba(162, 119, 255, 0.1)"
  52. >
  53. <Icon :size="23" icon="fa:user-plus" />
  54. </div>
  55. <div class="ml-[20px]">
  56. <div class="mb-8px text-14px text-gray-400">虚拟成团(个)</div>
  57. <CountTo
  58. :duration="2600"
  59. :end-val="recordSummary.virtualGroupCount"
  60. :start-val="0"
  61. class="text-20px"
  62. />
  63. </div>
  64. </div>
  65. </ContentWrap>
  66. </el-col>
  67. </el-row>
  68. <ContentWrap>
  69. <!-- 搜索工作栏 -->
  70. <el-form
  71. ref="queryFormRef"
  72. :inline="true"
  73. :model="queryParams"
  74. class="-mb-15px"
  75. label-width="68px"
  76. >
  77. <el-form-item label="创建时间" prop="createTime">
  78. <el-date-picker
  79. v-model="queryParams.createTime"
  80. :shortcuts="shortcuts"
  81. class="!w-240px"
  82. end-placeholder="结束日期"
  83. start-placeholder="开始日期"
  84. type="daterange"
  85. value-format="YYYY-MM-DD HH:mm:ss"
  86. />
  87. </el-form-item>
  88. <el-form-item label="拼团状态" prop="status">
  89. <el-select v-model="queryParams.status" class="!w-240px" clearable placeholder="全部">
  90. <el-option
  91. v-for="(dict, index) in getIntDictOptions(
  92. DICT_TYPE.PROMOTION_COMBINATION_RECORD_STATUS
  93. )"
  94. :key="index"
  95. :label="dict.label"
  96. :value="dict.value"
  97. />
  98. </el-select>
  99. </el-form-item>
  100. <el-form-item>
  101. <el-button @click="handleQuery">
  102. <Icon class="mr-5px" icon="ep:search" />
  103. 搜索
  104. </el-button>
  105. <el-button @click="resetQuery">
  106. <Icon class="mr-5px" icon="ep:refresh" />
  107. 重置
  108. </el-button>
  109. </el-form-item>
  110. </el-form>
  111. </ContentWrap>
  112. <ContentWrap>
  113. <!-- 分页列表数据展示 -->
  114. <el-table v-loading="loading" :data="pageList">
  115. <el-table-column align="center" label="编号" prop="id" />
  116. <!-- TODO 是否需要做一个点击用户头像跳转或查看用户信息的功能 -->
  117. <el-table-column align="center" label="头像" prop="avatar" />
  118. <el-table-column align="center" label="开团团长" prop="headId">
  119. <template #default="{ row }: { row: CombinationRecordApi.CombinationRecordVO }">
  120. {{
  121. row.headId ? pageList.find((item) => item.id === row.headId)?.nickname : row.nickname
  122. }}
  123. </template>
  124. </el-table-column>
  125. <el-table-column
  126. :formatter="dateFormatter"
  127. align="center"
  128. label="开团时间"
  129. prop="startTime"
  130. width="180"
  131. />
  132. <el-table-column
  133. align="center"
  134. label="拼团商品"
  135. prop="type"
  136. show-overflow-tooltip
  137. width="300"
  138. >
  139. <template #defaul="{ row }">
  140. <el-image
  141. :src="row.picUrl"
  142. class="mr-5px h-30px w-30px align-middle"
  143. @click="imagePreview(row.picUrl)"
  144. />
  145. <span class="align-middle">{{ row.spuName }}</span>
  146. </template>
  147. </el-table-column>
  148. <el-table-column align="center" label="几人团" prop="userSize" />
  149. <el-table-column align="center" label="参与人数" prop="userCount" />
  150. <el-table-column
  151. :formatter="dateFormatter"
  152. align="center"
  153. label="结束时间"
  154. prop="endTime"
  155. width="180"
  156. />
  157. <el-table-column align="center" label="拼团状态" prop="status">
  158. <template #default="scope">
  159. <dict-tag
  160. :type="DICT_TYPE.PROMOTION_COMBINATION_RECORD_STATUS"
  161. :value="scope.row.status"
  162. />
  163. </template>
  164. </el-table-column>
  165. <el-table-column align="center" fixed="right" label="操作">
  166. <template #default></template>
  167. </el-table-column>
  168. </el-table>
  169. <!-- 分页 -->
  170. <Pagination
  171. v-model:limit="queryParams.pageSize"
  172. v-model:page="queryParams.pageNo"
  173. :total="total"
  174. @pagination="getList"
  175. />
  176. </ContentWrap>
  177. </template>
  178. <script lang="ts" setup>
  179. import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
  180. import { dateFormatter } from '@/utils/formatTime'
  181. import { createImageViewer } from '@/components/ImageViewer'
  182. import * as CombinationRecordApi from '@/api/mall/promotion/combination/combinationRecord'
  183. defineOptions({ name: 'CombinationRecord' })
  184. const queryParams = ref({
  185. dateType: 0, // 日期类型
  186. status: undefined, // 拼团状态
  187. createTime: undefined, // 创建时间
  188. pageSize: 10,
  189. pageNo: 1
  190. })
  191. const queryFormRef = ref() // 搜索的表单
  192. const loading = ref(true) // 列表的加载中
  193. const total = ref(0) // 总记录数
  194. const pageList = ref<CombinationRecordApi.CombinationRecordVO[]>([]) // 分页数据
  195. /** 查询列表 */
  196. const getList = async () => {
  197. loading.value = true
  198. try {
  199. const data = await CombinationRecordApi.getCombinationRecordPage(queryParams.value)
  200. pageList.value = data.list as CombinationRecordApi.CombinationRecordVO[]
  201. total.value = data.total
  202. } finally {
  203. loading.value = false
  204. }
  205. }
  206. // 拼团统计数据
  207. const recordSummary = ref({
  208. successCount: 0,
  209. userCount: 0,
  210. virtualGroupCount: 0
  211. })
  212. /** 获得拼团记录统计信息 */
  213. const getSummary = async () => {
  214. recordSummary.value = await CombinationRecordApi.getCombinationRecordSummary()
  215. }
  216. // 日期快捷选项
  217. const shortcuts = ref([
  218. {
  219. text: '今天',
  220. type: 'toDay',
  221. value: () => {
  222. queryParams.value.dateType = 1
  223. return new Date()
  224. }
  225. },
  226. {
  227. text: '昨天',
  228. type: 'yesterday',
  229. value: () => {
  230. const date = new Date()
  231. date.setTime(date.getTime() - 3600 * 1000 * 24)
  232. queryParams.value.dateType = 2
  233. return [date, date]
  234. }
  235. },
  236. {
  237. text: '最近七天',
  238. type: 'lastSevenDays',
  239. value: () => {
  240. const date = new Date()
  241. date.setTime(date.getTime() - 3600 * 1000 * 24 * 7)
  242. queryParams.value.dateType = 3
  243. return [date, new Date()]
  244. }
  245. },
  246. {
  247. text: '最近30天',
  248. type: 'last30Days',
  249. value: () => {
  250. const date = new Date()
  251. date.setTime(date.getTime() - 3600 * 1000 * 24 * 30)
  252. queryParams.value.dateType = 4
  253. return [date, new Date()]
  254. }
  255. },
  256. {
  257. text: '本月',
  258. type: 'thisMonth',
  259. value: () => {
  260. const date = new Date()
  261. date.setDate(1) // 设置为当前月的第一天
  262. queryParams.value.dateType = 5
  263. return [date, new Date()]
  264. }
  265. },
  266. {
  267. text: '今年',
  268. type: 'thisYear',
  269. value: () => {
  270. const date = new Date()
  271. queryParams.value.dateType = 6
  272. return [new Date(`${date.getFullYear()}-01-01`), date]
  273. }
  274. }
  275. ])
  276. /** 获得每个 Tab 的数量 */
  277. const getTabsCount = async () => {
  278. const res = await CombinationRecordApi.getCombinationRecordCount()
  279. shortcuts.value.forEach((tab) => {
  280. tab.text += `(${res[tab.type]})`
  281. })
  282. }
  283. /** 搜索按钮操作 */
  284. const handleQuery = () => {
  285. queryParams.value.pageNo = 1
  286. getList()
  287. }
  288. /** 重置按钮操作 */
  289. const resetQuery = () => {
  290. queryFormRef.value.resetFields()
  291. handleQuery()
  292. }
  293. /** 商品图预览 */
  294. const imagePreview = (imgUrl: string) => {
  295. createImageViewer({
  296. urlList: [imgUrl]
  297. })
  298. }
  299. /** 初始化 **/
  300. onMounted(async () => {
  301. await getSummary()
  302. await getTabsCount()
  303. await getList()
  304. })
  305. </script>