index.vue 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. <style scoped lang="scss">
  2. .system-container {
  3. :deep(.el-card__body) {
  4. display: flex;
  5. flex-direction: column;
  6. justify-content: space-between;
  7. flex: 1;
  8. overflow: auto;
  9. .el-table {
  10. flex: 1;
  11. }
  12. }
  13. }
  14. .page-content {
  15. margin-bottom: 20px;
  16. }
  17. .page-pager {
  18. background-color: #fff;
  19. height: 24px;
  20. }
  21. </style>
  22. <template>
  23. <div class="system-container layout-padding">
  24. <el-card shadow="hover" class="layout-padding-auto">
  25. <el-form
  26. :model="state.formQuery"
  27. ref="queryRef"
  28. size="default" label-width="0px" class="mt5 mb5">
  29. <el-input
  30. v-model="state.formQuery.activityName"
  31. placeholder="活动名称"
  32. clearable
  33. @blur="loadData(true)"
  34. class="wd150 mr10">
  35. </el-input>
  36. <el-input
  37. v-model="state.formQuery.couponName"
  38. placeholder="优惠券名称"
  39. clearable
  40. @blur="loadData(true)"
  41. class="wd150 mr10">
  42. </el-input>
  43. <el-input
  44. v-model="state.formQuery.userName"
  45. placeholder="用户名称"
  46. clearable
  47. @blur="loadData(true)"
  48. class="wd150 mr10">
  49. </el-input>
  50. <el-input
  51. v-model="state.formQuery.mobilePhone"
  52. placeholder="手机号"
  53. clearable
  54. @blur="loadData(true)"
  55. class="wd150 mr10">
  56. </el-input>
  57. <ext-d-select
  58. v-model="state.formQuery.couponType"
  59. placeholder="券种"
  60. type="Activity.couponType"
  61. clearable
  62. @blur="loadData(true)"
  63. class="wd150 mr10">
  64. </ext-d-select>
  65. <ext-d-select
  66. placeholder="用户状态"
  67. v-model="state.formQuery.status"
  68. type="User.status"
  69. clearable
  70. @blur="loadData(true)"
  71. class="wd150 mr10">
  72. </ext-d-select>
  73. <ext-d-select
  74. placeholder="使用状态"
  75. v-model="state.formQuery.usageStatus"
  76. type="UserCoupon.usage"
  77. clearable
  78. @blur="loadData(true)"
  79. class="wd150 mr10">
  80. </ext-d-select>
  81. <el-button class="ml10" plain size="default" type="success" @click="loadData(true)">
  82. <SvgIcon name="ele-Search"/>
  83. 查询
  84. </el-button>
  85. </el-form>
  86. <el-table
  87. border
  88. stripe="stripe"
  89. :height="state.tableData.height"
  90. highlight-current-row
  91. current-row-key="id"
  92. row-key="id"
  93. :data="state.tableData.data"
  94. v-loading="state.tableData.loading"
  95. @row-dblclick="onRowClick('view',$event)"
  96. @selection-change="handleTableSelectionChange"
  97. @sort-change="handleTableSortChange">
  98. <template #empty>
  99. <el-empty></el-empty>
  100. </template>
  101. <el-table-column
  102. v-for="field in state.tableData.columns"
  103. :key="field.prop"
  104. :label="field.label"
  105. :column-key="field.prop"
  106. :width="field.width"
  107. :min-width="field.minWidth"
  108. :fixed="field.fixed"
  109. :sortable="field.sortable"
  110. :show-overflow-tooltip="!field.fixed&&field.width>150"
  111. >
  112. <template #default="{row}">
  113. <template v-if="field.prop==='expand'">
  114. <p style="padding-left: 2em;" v-html="row[field.prop]"></p>
  115. </template>
  116. <template v-else-if="field.prop==='period'">
  117. {{ row.startTime }} ~ {{ row.endTime }}
  118. </template>
  119. <template v-else-if="field.prop==='couponType'">
  120. <ext-d-label type="Activity.couponType" v-model="row[field.prop]"></ext-d-label>
  121. </template>
  122. <template v-else-if="field.prop==='status'">
  123. <ext-d-label type="User.status" v-model="row[field.prop]"></ext-d-label>
  124. </template>
  125. <template v-else-if="field.prop==='usageStatus'">
  126. <ext-d-label type="UserCoupon.usageStatus" v-model="row[field.prop]"></ext-d-label>
  127. </template>
  128. <template v-else-if="field.prop==='allowStacke'">
  129. <ext-d-label type="Activity.allowStacke" v-model="row[field.prop]"></ext-d-label>
  130. </template>
  131. <template v-else-if="field.prop==='action'">
  132. <!-- <el-button size="small" plain type="danger" @click="onRowTerminal(row)">终止</el-button>-->
  133. </template>
  134. <template v-else>
  135. <div>{{ row[field.prop] }}</div>
  136. </template>
  137. </template>
  138. </el-table-column>
  139. </el-table>
  140. <ext-page class="page-pager" v-model:value="state.pageQuery" @change="loadData(false)"/>
  141. </el-card>
  142. </div>
  143. <ActivityDialog ref="activityDialogRef" @refresh="loadData(true)"/>
  144. </template>
  145. <script setup lang="ts" name="ActivityList">
  146. import {defineAsyncComponent, reactive, onMounted, onBeforeMount, ref, getCurrentInstance, nextTick, onBeforeUnmount} from 'vue';
  147. import {$body, $get} from "/@/utils/request";
  148. import {Msg} from "/@/utils/message";
  149. import ExtPage from '/@/components/form/ExtPage.vue'
  150. import mittBus from '/@/utils/mitt';
  151. import ExtDSelect from "/@/components/form/ExtDSelect.vue";
  152. import ExtDLabel from "/@/components/form/ExtDLabel.vue";
  153. const ActivityDialog = defineAsyncComponent(() => import("/@/views/admin/activity/dialog.vue"));
  154. //定义引用
  155. const queryRef = ref();
  156. const activityDialogRef = ref();
  157. //定义变量
  158. const state = reactive({
  159. formQuery: {},
  160. pageQuery: {
  161. pageNum: 1,
  162. pageSize: 10,
  163. total: 0
  164. },
  165. tableData: {
  166. height: 500,
  167. data: [] as Array<any>,
  168. loading: false,
  169. columns: [
  170. {
  171. label: '活动名称', prop: 'activityName', resizable: true, width: 170, fixed: 'left'
  172. },
  173. {label: '活动时间', prop: 'period', resizable: true, width: 350},
  174. {label: '优惠券名称', prop: 'couponName', align: 'center', width: 230},
  175. {label: '用户名', prop: 'userName', resizable: true, width: 130},
  176. {label: '手机号', prop: 'mobilePhone', resizable: true, width: 130},
  177. {label: '有效期', prop: 'validity', resizable: true, width: 130},
  178. {label: '用户状态', prop: 'status', resizable: true, width: 130},
  179. {label: '使用状态', prop: 'usageStatus', resizable: true, width: 130},
  180. {label: '优惠允许叠加', prop: 'allowStacke', resizable: true, width: 130},
  181. {label: '创建时间', prop: 'createTime', resizable: true, width: 180},
  182. {label: '更新时间', prop: 'updateTime', resizable: true, width: 180},
  183. /* {
  184. label: '操作', prop: 'action', width: 180, align: 'center', fixed: 'right',
  185. }*/
  186. ],
  187. },
  188. })
  189. // 监听双向绑定 modelValue 的变化
  190. // watch(
  191. // () => state.pageIndex,
  192. // () => {
  193. //
  194. // }
  195. // );
  196. //生命周期钩子
  197. onBeforeMount(() => {
  198. })
  199. onMounted(() => {
  200. loadData();
  201. nextTick(() => {
  202. let bodyHeight = document.body.clientHeight;
  203. let queryHeight = queryRef.value.$el.clientHeight;
  204. state.tableData.height = bodyHeight - queryHeight - 320
  205. })
  206. mittBus.on("activity.refresh", () => {
  207. loadData();
  208. })
  209. });
  210. onBeforeUnmount(() => {
  211. mittBus.off("activity.refresh")
  212. })
  213. //region 方法区
  214. // 初始化表格数据
  215. const loadData = (refresh: boolean = false) => {
  216. if (refresh) {
  217. state.pageQuery.pageNum = 1;
  218. }
  219. state.tableData.loading = true;
  220. $get(`/coupon/listUserCoupons`, {...state.formQuery, ...state.pageQuery}).then((res: any) => {
  221. let {list, total} = res;
  222. state.tableData.data = list;
  223. state.pageQuery.total = total;
  224. state.tableData.loading = false;
  225. }).catch(e => {
  226. console.error(e)
  227. state.tableData.loading = false;
  228. })
  229. };
  230. // 打开修改用户弹窗
  231. const handleRowClick = (event) => {
  232. console.log(event)
  233. activityDialogRef.value.open("view", event);
  234. };
  235. // 打开修改用户弹窗
  236. const onRowClick = (type: string, row: any) => {
  237. activityDialogRef.value.open(type, row);
  238. };
  239. // 删除用户
  240. const onRowTerminal = (row: any) => {
  241. Msg.confirm(`此操作将终止:『${row.name}』,是否继续?`).then(() => {
  242. $get(`/activity/terminateActivity/${row.id}`).then(() => {
  243. Msg.message("终止成功", 'success')
  244. loadData(true)
  245. }).catch(() => {
  246. Msg.message("终止失败", 'error')
  247. })
  248. });
  249. };
  250. const handleTableSelectionChange = (selection: any) => {
  251. console.log("handleTableSelectionChange>>", selection)
  252. // emit("on-check-change", selection)
  253. }
  254. const handleTableSortChange = (column, prop, order) => {
  255. console.log("handleTableSortChange>>", column, prop, order)
  256. // emit("on-sort-change", column)
  257. }
  258. //endregion
  259. // 暴露变量
  260. // defineExpose({
  261. // loadData,
  262. // });
  263. </script>