1.派发优惠券给用户

This commit is contained in:
邱贞招 2024-09-05 09:03:39 +08:00
parent 8f0af93d04
commit d14b303899
3 changed files with 229 additions and 38 deletions

View File

@ -42,3 +42,12 @@ export function delCoupon(couponId) {
method: 'delete' method: 'delete'
}) })
} }
// 派发优惠券
export function issueCoupon(data) {
return request({
url: '/system/coupon/issue',
method: 'post',
data: data
})
}

View File

@ -84,6 +84,7 @@
<el-table v-loading="loading" :data="couponList" @selection-change="handleSelectionChange"> <el-table v-loading="loading" :data="couponList" @selection-change="handleSelectionChange">
<el-table-column type="selection" width="55" align="center" /> <el-table-column type="selection" width="55" align="center" />
<el-table-column label="优惠券id" align="center" prop="couponId" /> <el-table-column label="优惠券id" align="center" prop="couponId" />
<el-table-column label="运营区" align="center" prop="areaName" />
<el-table-column label="名称" align="center" prop="name" /> <el-table-column label="名称" align="center" prop="name" />
<el-table-column label="类型" align="center" prop="type"> <el-table-column label="类型" align="center" prop="type">
<template slot-scope="scope"> <template slot-scope="scope">
@ -96,16 +97,28 @@
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="折扣比例" align="center" prop="discountPercent" :formatter="formatDiscountPercent"/> <el-table-column label="折扣比例" align="center" prop="discountPercent" :formatter="formatDiscountPercent"/>
<el-table-column label="运营区" align="center" prop="areaName" />
<el-table-column label="抵扣金额" align="center" prop="discountAmount" :formatter="formatDiscountAmount"/> <el-table-column label="抵扣金额" align="center" prop="discountAmount" :formatter="formatDiscountAmount"/>
<el-table-column label="零售价" align="center" prop="retailPrice" :formatter="formatRetailPrice"/> <el-table-column label="零售价" align="center" prop="retailPrice" :formatter="formatRetailPrice"/>
<el-table-column label="原价" align="center" prop="originalPrice" :formatter="formatOriginalPrice"/>
<el-table-column label="有效期" align="center" >
<template slot-scope="scope">
{{ formatValidity(scope.row.validityValue, scope.row.validityUnit) }}
</template>
</el-table-column>
<el-table-column label="状态" align="center" prop="status"> <el-table-column label="状态" align="center" prop="status">
<template slot-scope="scope"> <template slot-scope="scope">
<dict-tag :options="dict.type.sys_normal_disable" :value="scope.row.status"/> <dict-tag :options="dict.type.sys_normal_disable" :value="scope.row.status"/>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="操作" align="center" class-name="small-padding fixed-width"> <el-table-column label="操作" align="center" width="150" class-name="small-padding fixed-width">
<template slot-scope="scope"> <template slot-scope="scope">
<el-button
size="mini"
type="text"
icon="el-icon-present"
@click="distributeCoupons(scope.row)"
v-hasPermi="['system:coupon:present']"
>派发</el-button>
<el-button <el-button
size="mini" size="mini"
type="text" type="text"
@ -178,6 +191,9 @@
<el-form-item label="零售价" prop="retailPrice"> <el-form-item label="零售价" prop="retailPrice">
<el-input-number v-model='form.retailPrice' :precision="2" :step="0.1" /> <el-input-number v-model='form.retailPrice' :precision="2" :step="0.1" />
</el-form-item> </el-form-item>
<el-form-item label="原价" prop="originalPrice">
<el-input-number v-model='form.originalPrice' :precision="2" :step="0.1" />
</el-form-item>
<el-row> <el-row>
<el-col :span="12"> <el-col :span="12">
<el-form-item label="是否热门" prop="isHot"> <el-form-item label="是否热门" prop="isHot">
@ -185,36 +201,103 @@
</el-form-item> </el-form-item>
</el-col> </el-col>
</el-row> </el-row>
<!-- <el-form-item label="有效时间" prop="expirationTime">--> <el-form-item label="描述" prop="descr">
<!-- <el-date-picker clearable--> <el-input v-model="form.descr" type="textarea" placeholder="用于前端展示" />
<!-- v-model="form.expirationTime"--> </el-form-item>
<!-- type="date"--> <el-form-item label="有效期" prop="validityValue">
<!-- value-format="yyyy-MM-dd HH:mm:ss"--> <el-input v-model="form.validityValue" placeholder="请输入有效期" type="number">
<!-- placeholder="请选择有效时间">--> <template #append>
<!-- </el-date-picker>--> <el-select v-model="form.validityUnit" placeholder="请选择时间单位" style="width: 6em">
<!-- </el-form-item>--> <el-option
v-for="dict in dict.type.et_validity_unit"
:key="dict.value"
:label="dict.label"
:value="dict.value"
/>
</el-select>
</template>
</el-input>
</el-form-item>
</el-form> </el-form>
<div slot="footer" class="dialog-footer"> <div slot="footer" class="dialog-footer">
<el-button type="primary" @click="submitForm"> </el-button> <el-button type="primary" @click="submitForm"> </el-button>
<el-button @click="cancel"> </el-button> <el-button @click="cancel"> </el-button>
</div> </div>
</el-dialog> </el-dialog>
<el-dialog :title="title3" :visible.sync="open3" width="1000px" append-to-body>
<el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
<el-form-item label="手机号码" prop="phonenumber">
<el-input
v-model="queryParams.phonenumber"
placeholder="请输入手机号码"
clearable
style="width: 240px"
@keyup.enter.native="handleQuery"
/>
</el-form-item>
<el-form-item>
<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQueryUser">搜索</el-button>
<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
</el-form-item>
</el-form>
<el-table v-loading="loading" :data="userList" @selection-change="handleSelectionChange2">
<el-table-column type="selection" width="50" align="center" />
<el-table-column label="用户名称" align="center" key="userName" prop="userName" width="100" />
<el-table-column label="手机号" align="center" key="phonenumber" prop="phonenumber" width="100" />
<el-table-column label="移动端" align="center" key="appName" prop="appName" width="120" />
<el-table-column label="最后登录时间" align="center" prop="createTime" width="160">
<template slot-scope="scope">
<span>{{ parseTime(scope.row.loginDate) }}</span>
</template>
</el-table-column>
<el-table-column label="注册时间" align="center" prop="createTime" width="160">
<template slot-scope="scope">
<span>{{ parseTime(scope.row.createTime) }}</span>
</template>
</el-table-column>
<el-table-column label="状态" align="center" key="status" >
<template slot-scope="scope">
<el-switch
v-model="scope.row.status"
active-value="0"
inactive-value="1"
@change="handleStatusChange(scope.row)"
></el-switch>
</template>
</el-table-column>
<el-table-column label="是否实名" align="center" prop="isAuthentication">
<template slot-scope="scope">
<dict-tag :options="dict.type.et_user_is_authentication" :value="scope.row.isAuthentication" />
</template>
</el-table-column>
</el-table>
<div slot="footer" class="dialog-footer">
<el-button type="primary" @click="submitIssueForm"> </el-button>
<el-button @click="cancel3"> </el-button>
</div>
</el-dialog>
</div> </div>
</template> </template>
<script> <script>
import { listCoupon, getCoupon, delCoupon, addCoupon, updateCoupon } from "@/api/system/coupon"; import { listCoupon, getCoupon, delCoupon, addCoupon, updateCoupon, issueCoupon } from '@/api/system/coupon'
import { optionselect as getAreaOptionselect } from '@/api/system/area' import { optionselect as getAreaOptionselect } from '@/api/system/area'
import { changeUserStatus, listUser } from '@/api/user/user'
export default { export default {
name: "Coupon", name: "Coupon",
dicts: ['et_coupon_type', 'et_coupon_status','et_coupon_time_limit','sys_normal_disable'], dicts: ['et_coupon_type', 'et_coupon_status','et_coupon_time_limit','sys_normal_disable','et_validity_unit','et_user_is_authentication'],
data() { data() {
return { return {
// //
loading: true, loading: true,
// //
ids: [], ids: [],
userIds: [],
couponId: null,
// //
single: true, single: true,
// //
@ -227,10 +310,16 @@ export default {
couponList: [], couponList: [],
// //
title: "", title: "",
title3: "",
// //
open: false, open: false,
open3: false,
// //
areaOptions:[], areaOptions:[],
//
dateRange: [],
//
userList: null,
// //
queryParams: { queryParams: {
pageNum: 1, pageNum: 1,
@ -241,6 +330,10 @@ export default {
userId: null, userId: null,
discountAmount: null, discountAmount: null,
retailPrice: null, retailPrice: null,
originalPrice: null,
descr: null,
validityValue: null,
validityUnit: null,
expirationTime: null, expirationTime: null,
status: null status: null
}, },
@ -248,9 +341,24 @@ export default {
form: {}, form: {},
// //
rules: { rules: {
// userId: [ areaId: [
// { required: true, message: "", trigger: "blur" } { required: true, message: '运营区不能为空', trigger: 'blur' },
// ], ],
name: [
{ required: true, message: '名称不能为空', trigger: 'blur' },
],
type: [
{ required: true, message: '类型不能为空', trigger: 'change' },
],
retailPrice: [
{ required: true, message: '零售价不能为空', trigger: 'blur' },
],
validityValue: [
{ required: true, message: '有效期值不能为空', trigger: 'blur' },
],
validityUnit: [
{ required: true, message: '有效期单位不能为空', trigger: 'change' },
],
} }
}; };
}, },
@ -261,6 +369,30 @@ export default {
}); });
}, },
methods: { methods: {
//
handleStatusChange(row) {
let text = row.status === "0" ? "启用" : "停用";
this.$modal.confirm('确认要"' + text + '""' + row.userName + '"用户吗?').then(function() {
return changeUserStatus(row.userId, row.status);
}).then(() => {
this.$modal.msgSuccess(text + "成功");
}).catch(function() {
row.status = row.status === "0" ? "1" : "0";
});
},
/** 派发优惠券 */
distributeCoupons(row){
this.couponId = row.couponId;
this.reset();
this.open3 = true;
this.title3 = "派发优惠券";
this.resetQuery();
listUser(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
this.userList = response.rows;
this.total = response.total;
}
);
},
// discountPercent // discountPercent
convertDiscountPercentToInteger() { convertDiscountPercentToInteger() {
// discountPercent // discountPercent
@ -270,6 +402,20 @@ export default {
this.form.discountPercent = ''; // this.form.discountPercent = ''; //
} }
}, },
formatValidity(value, unit) {
if (value == null || unit == null) {
return '';
}
const unitLabel = this.dict.type.et_validity_unit.find(item => item.value === unit)?.label || '';
const formattedUnitLabel = (unitLabel === '月' || unitLabel === '季度') ? `${unitLabel}` : unitLabel;
return formattedUnitLabel ? `${value}${formattedUnitLabel}` : '';
},
formatOriginalPrice(row){
if (row.originalPrice === null || row.originalPrice === '') {
return '';
}
return row.originalPrice + '元';
},
formatRetailPrice(row){ formatRetailPrice(row){
if (row.retailPrice === null || row.retailPrice === '') { if (row.retailPrice === null || row.retailPrice === '') {
return ''; return '';
@ -303,6 +449,11 @@ export default {
this.open = false; this.open = false;
this.reset(); this.reset();
}, },
//
cancel3() {
this.open3 = false;
this.reset();
},
// //
reset() { reset() {
this.form = { this.form = {
@ -323,6 +474,14 @@ export default {
this.queryParams.pageNum = 1; this.queryParams.pageNum = 1;
this.getList(); this.getList();
}, },
handleQueryUser(){
this.loading = true;
listUser(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
this.userList = response.rows;
this.total = response.total;
this.loading = false;
});
},
/** 重置按钮操作 */ /** 重置按钮操作 */
resetQuery() { resetQuery() {
this.resetForm("queryForm"); this.resetForm("queryForm");
@ -334,6 +493,11 @@ export default {
this.single = selection.length!==1 this.single = selection.length!==1
this.multiple = !selection.length this.multiple = !selection.length
}, },
handleSelectionChange2(selection) {
this.userIds = selection.map(item => item.userId)
this.single = selection.length!==1
this.multiple = !selection.length
},
/** 新增按钮操作 */ /** 新增按钮操作 */
handleAdd() { handleAdd() {
this.reset(); this.reset();
@ -379,6 +543,16 @@ export default {
} }
}); });
}, },
/** 提交派发 */
submitIssueForm() {
const userId = this.userIds;
// console.log("userId---------------",userId)
// console.log("this.couponId============",this.couponId)
issueCoupon({userIds:userId, couponId:this.couponId}).then(response => {
this.open3 = false;
this.$modal.msgSuccess("派发成功");
});
},
/** 删除按钮操作 */ /** 删除按钮操作 */
handleDelete(row) { handleDelete(row) {
const couponIds = row.couponId || this.ids; const couponIds = row.couponId || this.ids;

View File

@ -145,22 +145,22 @@
<dict-tag :options="dict.type.et_user_is_authentication" :value="scope.row.isAuthentication" /> <dict-tag :options="dict.type.et_user_is_authentication" :value="scope.row.isAuthentication" />
</template> </template>
</el-table-column> </el-table-column>
<el-table-column <!-- <el-table-column-->
label="操作" <!-- label="操作"-->
align="center" <!-- align="center"-->
width="240" <!-- width="240"-->
class-name="small-padding fixed-width"> <!-- class-name="small-padding fixed-width">-->
<template slot-scope="scope"> <!-- <template slot-scope="scope">-->
<el-button <!-- <el-button-->
size="mini" <!-- size="mini"-->
plain <!-- plain-->
type="text" <!-- type="text"-->
icon="el-icon-present" <!-- icon="el-icon-present"-->
@click="distributeCoupons(scope.row)" <!-- @click="distributeCoupons(scope.row)"-->
v-hasPermi="['system:user:edit']" <!-- v-hasPermi="['system:user:edit']"-->
>派发优惠券</el-button> <!-- >派发优惠券</el-button>-->
</template> <!-- </template>-->
</el-table-column> <!-- </el-table-column>-->
</el-table> </el-table>
<pagination <pagination
@ -318,6 +318,7 @@
</el-form-item> </el-form-item>
<el-table v-loading="loading" :data="couponList" @selection-change="handleSelectionChange2"> <el-table v-loading="loading" :data="couponList" @selection-change="handleSelectionChange2">
<el-table-column type="selection" width="55" align="center" /> <el-table-column type="selection" width="55" align="center" />
<el-table-column label="运营区" align="center" prop="areaName" />
<el-table-column label="类型" align="center" prop="type"> <el-table-column label="类型" align="center" prop="type">
<template slot-scope="scope"> <template slot-scope="scope">
<dict-tag :options="dict.type.et_coupon_type" :value="scope.row.type"/> <dict-tag :options="dict.type.et_coupon_type" :value="scope.row.type"/>
@ -329,14 +330,9 @@
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="折扣比例" align="center" prop="discountPercent" :formatter="formatDiscountPercent"/> <el-table-column label="折扣比例" align="center" prop="discountPercent" :formatter="formatDiscountPercent"/>
<el-table-column label="运营区" align="center" prop="areaName" />
<el-table-column label="用户" align="center" prop="userName" width="120"/>
<el-table-column label="抵扣金额" align="center" prop="discountAmount" :formatter="formatDiscountAmount"/> <el-table-column label="抵扣金额" align="center" prop="discountAmount" :formatter="formatDiscountAmount"/>
<el-table-column label="有效期" align="center" prop="validityValue" width="180"> <el-table-column label="零售价" align="center" prop="retailPrice" :formatter="formatRetailPrice"/>
<template slot-scope="scope"> <el-table-column label="原价" align="center" prop="originalPrice" :formatter="formatOriginalPrice"/>
<span>{{ formatValidity(scope.row)}}</span>
</template>
</el-table-column>
<el-table-column label="状态" align="center" prop="status"> <el-table-column label="状态" align="center" prop="status">
<template slot-scope="scope"> <template slot-scope="scope">
<dict-tag :options="dict.type.sys_normal_disable" :value="scope.row.status"/> <dict-tag :options="dict.type.sys_normal_disable" :value="scope.row.status"/>
@ -519,6 +515,18 @@ export default {
this.areaOptions = response.data; this.areaOptions = response.data;
}); });
}, },
formatOriginalPrice(row){
if (row.originalPrice === null || row.originalPrice === '') {
return '';
}
return row.originalPrice + '元';
},
formatRetailPrice(row){
if (row.retailPrice === null || row.retailPrice === '') {
return '';
}
return row.retailPrice + '元';
},
formatValidity(row){ formatValidity(row){
let selectDictLabel = this.selectDictLabel(this.dict.type.et_validity_unit, row.validityUnit) let selectDictLabel = this.selectDictLabel(this.dict.type.et_validity_unit, row.validityUnit)
if (selectDictLabel != null) { if (selectDictLabel != null) {