|
|
@@ -72,7 +72,7 @@
|
|
|
:disabled="multiple"
|
|
|
size="mini"
|
|
|
type="success"
|
|
|
- @click="handleBatchPublish"
|
|
|
+ @click="handleDirectBatchPublish"
|
|
|
>批量发布
|
|
|
</el-button>
|
|
|
</el-col>
|
|
|
@@ -82,10 +82,11 @@
|
|
|
|
|
|
<el-table v-loading="loading" :data="storeCouponList" border height="500" @selection-change="handleSelectionChange">
|
|
|
<el-table-column align="center" type="selection" width="55"/>
|
|
|
- <el-table-column align="center" label="优惠券表ID" prop="couponId"/>
|
|
|
- <el-table-column align="center" label="优惠券名称" prop="title"/>
|
|
|
- <el-table-column align="center" label="优惠券面值" prop="couponPrice"/>
|
|
|
+ <el-table-column align="center" label="立减金表ID" prop="couponId"/>
|
|
|
+ <el-table-column align="center" label="立减金名称" prop="title"/>
|
|
|
+ <el-table-column align="center" label="立减金面值" prop="couponPrice"/>
|
|
|
<el-table-column align="center" label="用户购买金额" prop="payPrice"/>
|
|
|
+ <el-table-column align="center" label="使用最低金额" prop="useMinPrice"/>
|
|
|
<el-table-column align="center" label="排序" prop="sort"/>
|
|
|
<el-table-column align="center" label="类型" prop="type">
|
|
|
<template slot-scope="scope">
|
|
|
@@ -107,7 +108,7 @@
|
|
|
v-hasPermi="['store:storeCoupon:publish']"
|
|
|
size="mini"
|
|
|
type="text"
|
|
|
- @click="handlePublish(scope.row)"
|
|
|
+ @click="handleDirectPublish(scope.row)"
|
|
|
>发布
|
|
|
</el-button>
|
|
|
<el-button
|
|
|
@@ -141,15 +142,18 @@
|
|
|
<!-- 添加或修改优惠券对话框 -->
|
|
|
<el-dialog :title="title" :visible.sync="open" append-to-body width="600px">
|
|
|
<el-form ref="form" :model="form" :rules="rules" label-width="150px">
|
|
|
- <el-form-item label="立减金卷名称" prop="title">
|
|
|
- <el-input v-model="form.title" placeholder="请输入立减金卷名称"/>
|
|
|
+ <el-form-item label="立减金券名称" prop="title">
|
|
|
+ <el-input v-model="form.title" placeholder="请输入立减金券名称"/>
|
|
|
</el-form-item>
|
|
|
<el-form-item label="面值" prop="couponPrice">
|
|
|
- <el-input-number v-model="form.couponPrice" :min="0" placeholder="请输入优惠券面值"/>
|
|
|
+ <el-input-number v-model="form.couponPrice" :min="0" placeholder="请输入立减金面值"/>
|
|
|
</el-form-item>
|
|
|
<el-form-item label="用户购买金额" prop="payPrice">
|
|
|
<el-input-number v-model="form.payPrice" :min="0" placeholder="支付金额"/>
|
|
|
</el-form-item>
|
|
|
+ <el-form-item label="最低消费金额" prop="useMinPrice">
|
|
|
+ <el-input-number v-model="form.useMinPrice" :min="0" placeholder="请输入最低消费金额"/>
|
|
|
+ </el-form-item>
|
|
|
<el-form-item label="排序" prop="sort">
|
|
|
<el-input-number v-model="form.sort" :min="0" placeholder="请输入排序"/>
|
|
|
</el-form-item>
|
|
|
@@ -164,62 +168,7 @@
|
|
|
<el-button @click="cancel">取 消</el-button>
|
|
|
</div>
|
|
|
</el-dialog>
|
|
|
- <el-dialog :title="publish.title" :visible.sync="publish.open" append-to-body width="500px">
|
|
|
- <el-form ref="publishForm" :model="publishForm" :rules="publishRules" label-width="150px">
|
|
|
- <el-form-item label="优惠券名称" prop="title">
|
|
|
- <el-input v-model="publishForm.title" disabled/>
|
|
|
- </el-form-item>
|
|
|
- <el-form-item label="优惠券开始时间" prop="startTime">
|
|
|
- <el-date-picker v-model="publishForm.startTime" clearable placeholder="选择开始时间"
|
|
|
- size="small"
|
|
|
- style="width: 200px"
|
|
|
- type="date"
|
|
|
- value-format="yyyy-MM-dd"
|
|
|
- >
|
|
|
- </el-date-picker>
|
|
|
- </el-form-item>
|
|
|
- <el-form-item label="优惠券结束时间" prop="limitTime">
|
|
|
- <el-date-picker v-model="publishForm.limitTime" clearable placeholder="选择结束时间"
|
|
|
- size="small"
|
|
|
- style="width: 200px"
|
|
|
- type="date"
|
|
|
- value-format="yyyy-MM-dd"
|
|
|
- >
|
|
|
- </el-date-picker>
|
|
|
- </el-form-item>
|
|
|
- <el-form-item label="优惠券领取数量" prop="totalCount">
|
|
|
- <el-input-number v-model="publishForm.totalCount" :min="0" placeholder="请输入优惠券领取数量"/>
|
|
|
- </el-form-item>
|
|
|
-
|
|
|
- <el-form-item label="状态">
|
|
|
- <el-radio-group v-model="publishForm.status">
|
|
|
- <el-radio v-for="item in statusOptions" :label="item.dictValue">{{ item.dictLabel }}</el-radio>
|
|
|
- </el-radio-group>
|
|
|
- </el-form-item>
|
|
|
- </el-form>
|
|
|
- <div slot="footer" class="dialog-footer">
|
|
|
- <el-button type="primary" @click="submitPublishForm">确 定</el-button>
|
|
|
- <el-button @click="cancelPublish">取 消</el-button>
|
|
|
- </div>
|
|
|
- </el-dialog>
|
|
|
- <el-dialog :title="batchPublish.title" :visible.sync="batchPublish.open" append-to-body width="500px">
|
|
|
- <div class="warning-content">
|
|
|
- <h2 style="color: red; margin-bottom: 16px;">
|
|
|
- {{ ids.length === 1 ? '是否发布当前勾选1张立减金券!' : `是否发布当前勾选${ids.length}张立减金券` }}
|
|
|
- </h2>
|
|
|
- <div class="alert-warning" style="padding: 12px; background-color: #fff3cd; border-left: 4px solid #ffc107; margin-bottom: 16px;">
|
|
|
- <p style="margin: 0; color: #856404;">
|
|
|
- <i class="el-icon-warning" style="margin-right: 6px;"></i>
|
|
|
- 请确认立减金券的发布面值与购买金额设置正确,避免因设置错误导致损失。
|
|
|
- </p>
|
|
|
- </div>
|
|
|
- </div>
|
|
|
|
|
|
- <div slot="footer" class="dialog-footer">
|
|
|
- <el-button @click="batchPublish.open = false">取消</el-button>
|
|
|
- <el-button type="primary" @click="handlePublish">确认发布</el-button>
|
|
|
- </div>
|
|
|
- </el-dialog>
|
|
|
</div>
|
|
|
</template>
|
|
|
|
|
|
@@ -242,14 +191,7 @@ export default {
|
|
|
return {
|
|
|
cateOptions: [],
|
|
|
couponTypeOptions: [],
|
|
|
- publish: {
|
|
|
- title: '发布',
|
|
|
- open: false
|
|
|
- },
|
|
|
- batchPublish: {
|
|
|
- title: '批量发布',
|
|
|
- open: false
|
|
|
- },
|
|
|
+
|
|
|
dateRange: [],
|
|
|
statusOptions: [],
|
|
|
// 遮罩层
|
|
|
@@ -290,59 +232,25 @@ export default {
|
|
|
// 表单校验
|
|
|
rules: {
|
|
|
title: [
|
|
|
- { required: true, message: '优惠券名称不能为空', trigger: 'blur' }
|
|
|
- ],
|
|
|
- integral: [
|
|
|
- { required: true, message: '兑换消耗积分值不能为空', trigger: 'blur' }
|
|
|
+ { required: true, message: '立减金券名称不能为空', trigger: 'blur' }
|
|
|
],
|
|
|
couponPrice: [
|
|
|
- { required: true, message: '兑换的优惠券面值不能为空', trigger: 'blur' }
|
|
|
+ { required: true, message: '立减金面值不能为空', trigger: 'blur' }
|
|
|
],
|
|
|
useMinPrice: [
|
|
|
- { required: true, message: '最低消费多少金额可用优惠券不能为空', trigger: 'blur' }
|
|
|
+ { required: true, message: '最低消费金额不能为空', trigger: 'blur' }
|
|
|
],
|
|
|
payPrice: [
|
|
|
{ required: true, message: '支付金额不能为空', trigger: 'blur' }
|
|
|
],
|
|
|
- couponTime: [
|
|
|
- { required: true, message: '优惠券有效期限不能为空', trigger: 'blur' }
|
|
|
- ],
|
|
|
sort: [
|
|
|
{ required: true, message: '排序不能为空', trigger: 'blur' }
|
|
|
],
|
|
|
status: [
|
|
|
{ required: true, message: '状态不能为空', trigger: 'blur' }
|
|
|
- ],
|
|
|
- createTime: [
|
|
|
- { required: true, message: '兑换项目添加时间不能为空', trigger: 'blur' }
|
|
|
- ],
|
|
|
- type: [
|
|
|
- { required: true, message: '类型不能为空', trigger: 'blur' }
|
|
|
- ],
|
|
|
- packageCateIds: [
|
|
|
- { required: true, message: '套餐分类不能为空', trigger: 'blur' }
|
|
|
- ],
|
|
|
- isDel: [
|
|
|
- { required: true, message: '是否删除不能为空', trigger: 'blur' }
|
|
|
]
|
|
|
-
|
|
|
},
|
|
|
- publishForm: {
|
|
|
- totalCount: 0,
|
|
|
- status: '0'
|
|
|
- },
|
|
|
- // 表单校验
|
|
|
- publishRules: {
|
|
|
- totalCount: [
|
|
|
- { required: true, message: '数量不能为空', trigger: 'blur' }
|
|
|
- ],
|
|
|
- startTime: [
|
|
|
- { required: true, message: '开始时间不能为空', trigger: 'blur' }
|
|
|
- ],
|
|
|
- limitTime: [
|
|
|
- { required: true, message: '结束时间不能为空', trigger: 'blur' }
|
|
|
- ]
|
|
|
- }
|
|
|
+
|
|
|
}
|
|
|
},
|
|
|
created() {
|
|
|
@@ -381,15 +289,11 @@ export default {
|
|
|
this.form = {
|
|
|
couponId: null,
|
|
|
title: null,
|
|
|
- integral: null,
|
|
|
couponPrice: null,
|
|
|
useMinPrice: null,
|
|
|
- couponTime: null,
|
|
|
+ payPrice: null,
|
|
|
sort: null,
|
|
|
status: '0',
|
|
|
- type: '0',
|
|
|
- productIds: null,
|
|
|
- packageCateIds: [],
|
|
|
createTime: null,
|
|
|
updateTime: null,
|
|
|
isDel: null
|
|
|
@@ -426,25 +330,19 @@ export default {
|
|
|
getStoreCoupon(couponId).then(response => {
|
|
|
this.form = response.data
|
|
|
this.form.status = response.data.status.toString()
|
|
|
- this.form.type = response.data.type.toString()
|
|
|
- if (this.form.packageCateIds != null) {
|
|
|
- this.form.packageCateIds = this.form.packageCateIds.split(',')
|
|
|
- }
|
|
|
this.open = true
|
|
|
- this.title = '修改优惠券'
|
|
|
+ this.title = '修改立减金券'
|
|
|
})
|
|
|
},
|
|
|
/** 提交按钮 */
|
|
|
submitForm() {
|
|
|
this.$refs['form'].validate(valid => {
|
|
|
if (valid) {
|
|
|
- if (this.form.packageCateIds != null) {
|
|
|
- this.form.packageCateIds = this.form.packageCateIds.toString()
|
|
|
- }
|
|
|
-
|
|
|
//验证金额
|
|
|
if (this.form.couponPrice <= 0) {
|
|
|
return this.$message.warning('提交失败,面值要大于0')
|
|
|
+ } else if (this.form.useMinPrice < 0) {
|
|
|
+ return this.$message.warning('提交失败,最低消费金额不能小于0')
|
|
|
} else if (this.form.payPrice <= 0) {
|
|
|
return this.$message.warning('提交失败,立减金金额要大于0')
|
|
|
}
|
|
|
@@ -470,38 +368,119 @@ export default {
|
|
|
}
|
|
|
})
|
|
|
},
|
|
|
- handleBatchPublish() {
|
|
|
- this.batchPublish.open = true
|
|
|
- var that = this
|
|
|
- setTimeout(() => {
|
|
|
- that.$refs.batchPublish.handleBatch(that.ids)
|
|
|
- }, 200)
|
|
|
- },
|
|
|
- closeBatchPublish() {
|
|
|
- this.batchPublish.open = false
|
|
|
- this.getList()
|
|
|
- },
|
|
|
- handlePublish(row) {
|
|
|
- this.publish.open = true
|
|
|
- this.publishForm.title = row.title
|
|
|
- this.publishForm.couponId = row.couponId
|
|
|
- },
|
|
|
- cancelPublish() {
|
|
|
- this.publish.open = false
|
|
|
- this.reset()
|
|
|
+ /** 直接发布单个立减金券 */
|
|
|
+ handleDirectPublish(row) {
|
|
|
+ this.$confirm(`确认发布立减金券"${row.title}"?发布后将设置为无限张数、永不过期的立减金券。`, '发布立减金券', {
|
|
|
+ confirmButtonText: '确定',
|
|
|
+ cancelButtonText: '取消',
|
|
|
+ type: 'warning'
|
|
|
+ }).then(() => {
|
|
|
+ // 构建立减金券发布参数,按照后端逻辑设置
|
|
|
+ const publishParams = {
|
|
|
+ couponId: row.couponId,
|
|
|
+ title: row.title,
|
|
|
+ // startTime 由后端自动设置为当前时间
|
|
|
+ limitTime: null, // 永不过期
|
|
|
+ totalCount: 99999, // 设置大数量(后端会设置为无限)
|
|
|
+ remainCount: 99999, // 剩余数量与总数量相同
|
|
|
+ isPermanent: 1, // 标识为无限张数
|
|
|
+ status: 1 // 启用状态
|
|
|
+ }
|
|
|
+
|
|
|
+ publishCoupon(publishParams).then(response => {
|
|
|
+ if (response.code === 200) {
|
|
|
+ this.msgSuccess('立减金券发布成功,已设置为无限张数、永不过期')
|
|
|
+ this.getList()
|
|
|
+ } else {
|
|
|
+ this.msgError(response.msg || '发布失败')
|
|
|
+ }
|
|
|
+ }).catch(error => {
|
|
|
+ console.error('发布立减金券失败:', error)
|
|
|
+ this.msgError('发布失败,请重试')
|
|
|
+ })
|
|
|
+ }).catch(() => {
|
|
|
+ // 用户取消操作
|
|
|
+ })
|
|
|
},
|
|
|
- submitPublishForm() {
|
|
|
- this.$refs['publishForm'].validate(valid => {
|
|
|
- if (valid) {
|
|
|
- publishCoupon(this.publishForm).then(response => {
|
|
|
- if (response.code === 200) {
|
|
|
- this.msgSuccess('发布成功')
|
|
|
- this.publish.open = false
|
|
|
- }
|
|
|
+ /** 直接批量发布立减金券 */
|
|
|
+ handleDirectBatchPublish() {
|
|
|
+ if (this.ids.length === 0) {
|
|
|
+ this.msgWarning('请先选择要发布的立减金券')
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ this.$confirm(`确认发布选中的${this.ids.length}张立减金券?所有立减金券将设置为无限张数、永不过期。`, '批量发布立减金券', {
|
|
|
+ confirmButtonText: '确定',
|
|
|
+ cancelButtonText: '取消',
|
|
|
+ type: 'warning'
|
|
|
+ }).then(() => {
|
|
|
+ // 显示发布进度
|
|
|
+ const loading = this.$loading({
|
|
|
+ lock: true,
|
|
|
+ text: `正在发布立减金券 0/${this.ids.length}`,
|
|
|
+ spinner: 'el-icon-loading',
|
|
|
+ background: 'rgba(0, 0, 0, 0.7)'
|
|
|
+ })
|
|
|
+
|
|
|
+ // 批量发布处理
|
|
|
+ const promises = this.ids.map((couponId, index) => {
|
|
|
+ const publishParams = {
|
|
|
+ couponId: couponId,
|
|
|
+ // startTime 由后端自动设置为当前时间
|
|
|
+ limitTime: null, // 永不过期
|
|
|
+ totalCount: 99999, // 设置大数量(后端会设置为无限)
|
|
|
+ remainCount: 99999, // 剩余数量与总数量相同
|
|
|
+ isPermanent: 1, // 标识为无限张数
|
|
|
+ status: 1 // 启用状态
|
|
|
+ }
|
|
|
+
|
|
|
+ return publishCoupon(publishParams).then(response => {
|
|
|
+ // 更新进度
|
|
|
+ loading.text = `正在发布立减金券 ${index + 1}/${this.ids.length}`
|
|
|
+ return response
|
|
|
})
|
|
|
- }
|
|
|
+ })
|
|
|
+
|
|
|
+ Promise.allSettled(promises).then(results => {
|
|
|
+ loading.close()
|
|
|
+
|
|
|
+ const successResults = results.filter(result =>
|
|
|
+ result.status === 'fulfilled' && result.value.code === 200
|
|
|
+ )
|
|
|
+ const failedResults = results.filter(result =>
|
|
|
+ result.status === 'rejected' || (result.status === 'fulfilled' && result.value.code !== 200)
|
|
|
+ )
|
|
|
+
|
|
|
+ const successCount = successResults.length
|
|
|
+ const failedCount = failedResults.length
|
|
|
+
|
|
|
+ if (failedCount === 0) {
|
|
|
+ this.msgSuccess(`批量发布成功!共发布${successCount}张立减金券,均已设置为无限张数、永不过期`)
|
|
|
+ } else if (successCount > 0) {
|
|
|
+ this.msgWarning(`部分发布成功:成功${successCount}张,失败${failedCount}张`)
|
|
|
+ } else {
|
|
|
+ this.msgError('批量发布失败,请检查网络连接后重试')
|
|
|
+ }
|
|
|
+
|
|
|
+ this.getList()
|
|
|
+ }).catch(error => {
|
|
|
+ loading.close()
|
|
|
+ console.error('批量发布立减金券失败:', error)
|
|
|
+ this.msgError('批量发布失败,请重试')
|
|
|
+ })
|
|
|
+ }).catch(() => {
|
|
|
+ // 用户取消操作
|
|
|
})
|
|
|
},
|
|
|
+ /** 获取默认结束日期(用于非立减金券) */
|
|
|
+ getDefaultEndDate() {
|
|
|
+ const now = new Date()
|
|
|
+ now.setDate(now.getDate() + 30) // 30天后
|
|
|
+ const year = now.getFullYear()
|
|
|
+ const month = String(now.getMonth() + 1).padStart(2, '0')
|
|
|
+ const day = String(now.getDate()).padStart(2, '0')
|
|
|
+ return `${year}-${month}-${day}`
|
|
|
+ },
|
|
|
/** 删除按钮操作 */
|
|
|
handleDelete(row) {
|
|
|
const couponIds = row.couponId || this.ids
|