|
| 1 | +<template> |
| 2 | + <Dialog v-model="dialogVisible" :title="dialogTitle" width="65%"> |
| 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-form-item> |
| 72 | + </el-form> |
| 73 | + </ContentWrap> |
| 74 | + |
| 75 | + <!-- 列表 --> |
| 76 | + <ContentWrap> |
| 77 | + <el-table v-loading="loading" :data="list" @selection-change="handleSelectionChange"> |
| 78 | + <el-table-column type="selection" width="55" /> |
| 79 | + <el-table-column label="优惠券名称" min-width="140" prop="name" /> |
| 80 | + <el-table-column label="类型" min-width="80" prop="productScope"> |
| 81 | + <template #default="scope"> |
| 82 | + <dict-tag :type="DICT_TYPE.PROMOTION_PRODUCT_SCOPE" :value="scope.row.productScope" /> |
| 83 | + </template> |
| 84 | + </el-table-column> |
| 85 | + <el-table-column label="优惠" min-width="100" prop="discount"> |
| 86 | + <template #default="scope"> |
| 87 | + <dict-tag :type="DICT_TYPE.PROMOTION_DISCOUNT_TYPE" :value="scope.row.discountType" /> |
| 88 | + {{ discountFormat(scope.row) }} |
| 89 | + </template> |
| 90 | + </el-table-column> |
| 91 | + <el-table-column label="领取方式" min-width="100" prop="takeType"> |
| 92 | + <template #default="scope"> |
| 93 | + <dict-tag :type="DICT_TYPE.PROMOTION_COUPON_TAKE_TYPE" :value="scope.row.takeType" /> |
| 94 | + </template> |
| 95 | + </el-table-column> |
| 96 | + <el-table-column |
| 97 | + :formatter="validityTypeFormat" |
| 98 | + align="center" |
| 99 | + label="使用时间" |
| 100 | + prop="validityType" |
| 101 | + width="185" |
| 102 | + /> |
| 103 | + <el-table-column align="center" label="发放数量" prop="totalCount" /> |
| 104 | + <el-table-column |
| 105 | + :formatter="remainedCountFormat" |
| 106 | + align="center" |
| 107 | + label="剩余数量" |
| 108 | + prop="totalCount" |
| 109 | + /> |
| 110 | + <el-table-column |
| 111 | + :formatter="takeLimitCountFormat" |
| 112 | + align="center" |
| 113 | + label="领取上限" |
| 114 | + prop="takeLimitCount" |
| 115 | + /> |
| 116 | + <el-table-column align="center" label="状态" prop="status"> |
| 117 | + <template #default="scope"> |
| 118 | + <dict-tag :type="DICT_TYPE.COMMON_STATUS" :value="scope.row.status" /> |
| 119 | + </template> |
| 120 | + </el-table-column> |
| 121 | + <el-table-column |
| 122 | + :formatter="dateFormatter" |
| 123 | + align="center" |
| 124 | + label="创建时间" |
| 125 | + prop="createTime" |
| 126 | + width="180" |
| 127 | + /> |
| 128 | + </el-table> |
| 129 | + <!-- 分页 --> |
| 130 | + <Pagination |
| 131 | + v-model:limit="queryParams.pageSize" |
| 132 | + v-model:page="queryParams.pageNo" |
| 133 | + :total="total" |
| 134 | + @pagination="getList" |
| 135 | + /> |
| 136 | + </ContentWrap> |
| 137 | + <template #footer> |
| 138 | + <el-button :disabled="formLoading" type="primary" @click="submitForm">确 定</el-button> |
| 139 | + <el-button @click="dialogVisible = false">取 消</el-button> |
| 140 | + </template> |
| 141 | + </Dialog> |
| 142 | +</template> |
| 143 | +<script lang="ts" setup> |
| 144 | +import { DICT_TYPE, getIntDictOptions } from '@/utils/dict' |
| 145 | +import { |
| 146 | + discountFormat, |
| 147 | + remainedCountFormat, |
| 148 | + takeLimitCountFormat, |
| 149 | + validityTypeFormat |
| 150 | +} from '@/views/mall/promotion/coupon/formatter' |
| 151 | +import { dateFormatter } from '@/utils/formatTime' |
| 152 | +import * as CouponTemplateApi from '@/api/mall/promotion/coupon/couponTemplate' |
| 153 | +
|
| 154 | +defineOptions({ name: 'CouponSelect' }) |
| 155 | +
|
| 156 | +defineProps<{ |
| 157 | + multipleSelection: { id: number; name: string }[] |
| 158 | +}>() |
| 159 | +const emit = defineEmits<{ |
| 160 | + (e: 'update:multipleSelection', v: { id: number; name: string }[]) |
| 161 | +}>() |
| 162 | +const dialogVisible = ref(false) // 弹窗的是否展示 |
| 163 | +const dialogTitle = ref('选择优惠卷') // 弹窗的标题 |
| 164 | +const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用 |
| 165 | +const loading = ref(true) // 列表的加载中 |
| 166 | +const total = ref(0) // 列表的总页数 |
| 167 | +const list = ref([]) // 字典表格数据 |
| 168 | +const queryParams = reactive({ |
| 169 | + pageNo: 1, |
| 170 | + pageSize: 10, |
| 171 | + name: null, |
| 172 | + status: null, |
| 173 | + discountType: null, |
| 174 | + type: null, |
| 175 | + createTime: [] |
| 176 | +}) |
| 177 | +const queryFormRef = ref() // 搜索的表单 |
| 178 | +
|
| 179 | +/** 查询列表 */ |
| 180 | +const getList = async () => { |
| 181 | + loading.value = true |
| 182 | + try { |
| 183 | + // 执行查询 |
| 184 | + const data = await CouponTemplateApi.getCouponTemplatePage(queryParams) |
| 185 | + list.value = data.list |
| 186 | + total.value = data.total |
| 187 | + } finally { |
| 188 | + loading.value = false |
| 189 | + } |
| 190 | +} |
| 191 | +
|
| 192 | +/** 搜索按钮操作 */ |
| 193 | +const handleQuery = () => { |
| 194 | + queryParams.pageNo = 1 |
| 195 | + getList() |
| 196 | +} |
| 197 | +
|
| 198 | +/** 重置按钮操作 */ |
| 199 | +const resetQuery = () => { |
| 200 | + queryFormRef?.value?.resetFields() |
| 201 | + handleQuery() |
| 202 | +} |
| 203 | +/** 打开弹窗 */ |
| 204 | +const open = async () => { |
| 205 | + dialogVisible.value = true |
| 206 | + resetQuery() |
| 207 | +} |
| 208 | +defineExpose({ open }) // 提供 open 方法,用于打开弹窗 |
| 209 | +const handleSelectionChange = (val: CouponTemplateApi.CouponTemplateVO[]) => { |
| 210 | + emit( |
| 211 | + 'update:multipleSelection', |
| 212 | + val.map((item) => ({ id: item.id, name: item.name })) |
| 213 | + ) |
| 214 | +} |
| 215 | +const submitForm = async () => {} |
| 216 | +</script> |
| 217 | +<style lang="scss" scoped></style> |
0 commit comments