381 行
20 KiB
JavaScript
可执行文件
381 行
20 KiB
JavaScript
可执行文件
Vue.component('m-coupon-index', {
|
|
template: `<div>
|
|
<!--搜索项-->
|
|
<el-form ref="form" size="small" :inline="true">
|
|
<el-form-item label="优惠券名称:">
|
|
<el-input v-model="searchForm.coupon_name"
|
|
placeholder="请输入优惠券名称"
|
|
clearable
|
|
@keydown.enter.exact.native.prevent="couponPageChange(1)"
|
|
style="width: 220px;"></el-input>
|
|
</el-form-item>
|
|
<el-form-item label="创建时间:">
|
|
<el-date-picker
|
|
v-model="searchForm.start_time"
|
|
type="datetime"
|
|
placeholder="创建时间(起)"
|
|
value-format="yyyy-MM-dd HH:mm:ss"
|
|
align="right">
|
|
</el-date-picker>
|
|
<span style="color:#c6c6c6">-</span>
|
|
<el-date-picker
|
|
v-model="searchForm.end_time"
|
|
type="datetime"
|
|
placeholder="创建时间(止)"
|
|
value-format="yyyy-MM-dd HH:mm:ss"
|
|
align="right">
|
|
</el-date-picker>
|
|
</el-form-item>
|
|
<el-form-item>
|
|
<el-button type="primary" @click="couponPageChange(1)">搜索</el-button>
|
|
<el-button type="primary" plain
|
|
v-if="(storeId && storeAuth.operate_vip_coupon==1 || !storeId) && operate.createCoupon"
|
|
@click="editCoupon('')">新建
|
|
</el-button>
|
|
</el-form-item>
|
|
<br/>
|
|
<el-form-item label="使用限制:">
|
|
<el-radio-group v-model="searchForm.appoint_type" @change="couponPageChange(1)">
|
|
<el-radio-button :label="''">不限制</el-radio-button>
|
|
<el-radio-button :label="1">全部商品</el-radio-button>
|
|
<el-radio-button :label="2">指定分类</el-radio-button>
|
|
<el-radio-button :label="3">指定商品</el-radio-button>
|
|
</el-radio-group>
|
|
</el-form-item>
|
|
<el-form-item label="状态:">
|
|
<el-radio-group v-model="searchForm.coupon_state" @change="couponPageChange(1)">
|
|
<el-radio-button :label="1">全部</el-radio-button>
|
|
<el-radio-button :label="2">未开始</el-radio-button>
|
|
<el-radio-button :label="3">进行中</el-radio-button>
|
|
<el-radio-button :label="4">已结束</el-radio-button>
|
|
</el-radio-group>
|
|
</el-form-item>
|
|
</el-form>
|
|
<!--优惠券列表-->
|
|
<div v-loading="loading" element-loading-text="数据加载中,请等待" element-loading-spinner="el-icon-loading">
|
|
<el-table border :data="couponList" size="small"
|
|
:header-cell-style="{background:'#F5F7FA',color:'#606266'}">
|
|
<el-table-column type="index" label="序号" fixed="left" width="50" align="center"></el-table-column>
|
|
<el-table-column align="center" prop="store_name" label="门店" min-width="100"
|
|
show-overflow-tooltip></el-table-column>
|
|
<el-table-column align="center" prop="coupon_name" label="优惠券名称" min-width="150"
|
|
show-overflow-tooltip></el-table-column>
|
|
<el-table-column align="center" prop="coupon_allnum" label="总库存" min-width="70"></el-table-column>
|
|
<el-table-column align="center" prop="coupon_num" label="剩余" min-width="70"></el-table-column>
|
|
<el-table-column align="center" prop="needmoney" label="优惠门槛" min-width="80"></el-table-column>
|
|
<el-table-column align="center" prop="reducemoney" label="优惠金额" min-width="80"></el-table-column>
|
|
<el-table-column align="center" prop="validity_time" label="有效期" min-width="146"
|
|
show-overflow-tooltip></el-table-column>
|
|
<el-table-column align="center" prop="give_name" label="发放类型" min-width="80"></el-table-column>
|
|
<el-table-column align="center" prop="addtime" label="创建时间" min-width="146"></el-table-column>
|
|
<el-table-column align="center" prop="type_name" label="状态" min-width="80"></el-table-column>
|
|
<el-table-column align="center" fixed="right" label="操作" width="200">
|
|
<template slot-scope="scope">
|
|
<el-button type="text" v-if="operate.couponRecordList" size="mini" @click="seeRecord(scope.row.id)">发放记录</el-button>
|
|
<template v-if="canOperate(scope.row.user_type)">
|
|
<el-button type="text" size="mini"
|
|
style="margin: 0 10px"
|
|
v-if="(storeId && storeAuth.operate_vip_coupon==1 || !storeId) && operate.editCoupon&&scope.row.status == 1 && scope.row.state==1"
|
|
@click="editCoupon(scope.row.id)">编辑
|
|
</el-button>
|
|
<el-button type="text" size="mini"
|
|
style="margin: 0 10px"
|
|
v-else
|
|
@click="editCoupon(scope.row.id,1)">查看
|
|
</el-button>
|
|
<template v-if="(storeId && storeAuth.operate_vip_coupon==1 || !storeId) && operate.batchGrantCoupon&&scope.row.state==1&&scope.row.give_status==1">
|
|
<el-button type="text" size="mini"
|
|
style="margin: 0 10px;color: #67C23A;"
|
|
@click="sendCouponBefore(scope.row)">投放
|
|
</el-button>
|
|
</template>
|
|
<template v-if="(storeId && storeAuth.operate_vip_coupon==1 || !storeId) && scope.row.status == 1 && scope.row.state==1">
|
|
<el-button type="text" size="mini"
|
|
style="margin: 0 10px"
|
|
@click="getRechargeState(scope.row)"
|
|
v-if="operate.setRechargeState&&scope.row.give_status==2">充值设置
|
|
</el-button>
|
|
<el-button type="text" size="mini" @click="getPayState(scope.row)"
|
|
style="margin: 0 10px"
|
|
v-if="operate.setPaymentState&&scope.row.give_status == 3">支付设置
|
|
</el-button>
|
|
<el-button type="text" size="mini"
|
|
v-if="operate.couponFailure"
|
|
style="margin: 0 10px;color:#aaaaaa"
|
|
@click="couponFailure(scope.row.id)">下架
|
|
</el-button>
|
|
</template>
|
|
</template>
|
|
<el-button type="text" size="mini"
|
|
style="margin: 0 10px"
|
|
v-else
|
|
@click="editCoupon(scope.row.id,1)">查看
|
|
</el-button>
|
|
</template>
|
|
</el-table-column>
|
|
</el-table>
|
|
<el-pagination
|
|
@size-change="couponLimitChange"
|
|
@current-change="couponPageChange"
|
|
:current-page="page"
|
|
:page-size="limit"
|
|
:total="total"
|
|
:pager-count="5"
|
|
:page-sizes="[10,20,30,40,50,60,70,80,90,100]"
|
|
layout="total, sizes, prev, pager, next, jumper">
|
|
</el-pagination>
|
|
</div>
|
|
<!-- 充值设置 -->
|
|
<el-dialog :append-to-body="true" :visible.sync="showRechargeDialog"
|
|
custom-class="customer-el-dialog__body"
|
|
:close-on-click-modal="false">
|
|
<el-form :model="rechargeForm" :rules="rules" ref="rechargeForm" label-width="100px" size="small"
|
|
style="padding-left: 20px;padding-bottom: 20px;color: #409EFF;">
|
|
<div class="title">充值设置</div>
|
|
<el-form-item label="充值赠送:">
|
|
<el-switch v-model="rechargeForm.recharge_state"
|
|
active-value="1"
|
|
inactive-value="0"
|
|
:active-text="rechargeForm.recharge_state == 1 ? '开启' : '关闭'"></el-switch>
|
|
</el-form-item>
|
|
<el-form-item label="充值金额:" prop="money">
|
|
<el-input v-model="rechargeForm.money"
|
|
:disabled="rechargeForm.recharge_state == 1 ? false : true"
|
|
onkeyup="value=value.replace(/[^\\d|.]/g,'')"
|
|
style="width: 215px;"></el-input>
|
|
</el-form-item>
|
|
<el-form-item>
|
|
<el-button type="primary" @click="setRechargeState">保存</el-button>
|
|
</el-form-item>
|
|
</el-form>
|
|
</el-dialog>
|
|
<!-- 支付设置 -->
|
|
<el-dialog :append-to-body="true" :visible.sync="showPaymentDialog"
|
|
custom-class="customer-el-dialog__body"
|
|
:close-on-click-modal="false">
|
|
<el-form :model="paymentForm" :rules="rules" ref="paymentForm" label-width="100px" size="small"
|
|
style="padding-left: 20px;padding-bottom: 20px;color: #409EFF;">
|
|
<div class="title">支付设置</div>
|
|
<el-form-item label="支付赠送:">
|
|
<el-switch v-model="paymentForm.payment_state"
|
|
active-value="1"
|
|
inactive-value="0"
|
|
:active-text="paymentForm.payment_state == 1 ? '开启' : '关闭'"></el-switch>
|
|
</el-form-item>
|
|
<el-form-item label="消费门槛:" prop="payment_money">
|
|
<el-input v-model="paymentForm.payment_money"
|
|
:disabled="paymentForm.payment_state == 1 ? false : true"
|
|
onkeyup="value=value.replace(/[^\\d|.]/g,'')"
|
|
style="width: 215px;"></el-input>
|
|
</el-form-item>
|
|
<el-form-item>
|
|
<el-button type="primary" @click="setPaymentState">保存</el-button>
|
|
</el-form-item>
|
|
</el-form>
|
|
</el-dialog>
|
|
</div>`,
|
|
props: {
|
|
'operate': {
|
|
type: Object,
|
|
default: () => {
|
|
return {}
|
|
},
|
|
},
|
|
'storeId': {
|
|
type: String,
|
|
default: '',
|
|
},//门店ID,只有门店操作时会传
|
|
},
|
|
data() {
|
|
let _t = this;
|
|
return {
|
|
searchForm: {
|
|
coupon_state: 1, //1全部 2未开始 3进行中 4已结束
|
|
coupon_name: '', //优惠券名称
|
|
start_time: '', //新增开始时间
|
|
end_time: '', //新增结束时间
|
|
appoint_type: '', //1全部商品 2指定分类 3指定商品
|
|
},//优惠券搜索条件
|
|
couponList: [], //优惠券列表
|
|
loading: false, //表格loading框显示状态
|
|
total: 0, //数据总条数
|
|
page: 1, //页码
|
|
limit: 10, //每页获取数量
|
|
|
|
|
|
showRechargeDialog: false,//是否显示充值设置
|
|
rechargeForm: {
|
|
id: '',
|
|
recharge_state: '',
|
|
money: '',
|
|
},//优惠券充值设置信息
|
|
showPaymentDialog: false,//是否显示支付设置
|
|
paymentForm: {
|
|
id: '',
|
|
payment_state: '',
|
|
payment_money: '',
|
|
},//支付设置设置信息
|
|
rules: {
|
|
money: [{message: '请设置充值金额', required: false, trigger: 'blur'}, {
|
|
validator: (rule, value, callback) => {
|
|
var reg = /^[+]{0,1}(\d+)$|^[+]{0,1}(\d+\.\d{0,2})$/;
|
|
if (_t.rechargeForm.recharge_state == 1 && (value === '' || value === undefined)) {
|
|
callback(new Error("请设置充值金额"));
|
|
} else if (_t.rechargeForm.recharge_state == 1 && (reg.test(value) == false || value < 0.01)) {
|
|
callback(new Error("请设置正确的充值金额"));
|
|
} else {
|
|
callback();
|
|
}
|
|
}, trigger: 'blur'
|
|
}],
|
|
payment_money: [{message: '请设置支付金额', required: false, trigger: 'blur'}, {
|
|
validator: (rule, value, callback) => {
|
|
var reg = /^[+]{0,1}(\d+)$|^[+]{0,1}(\d+\.\d{0,2})$/;
|
|
if (_t.paymentForm.payment_state == 1 && (value === '' || value === undefined)) {
|
|
callback(new Error("请设置支付金额"));
|
|
} else if (_t.paymentForm.payment_state == 1 && (reg.test(value) == false || value < 0.01)) {
|
|
callback(new Error("请设置正确的支付金额"));
|
|
} else {
|
|
callback();
|
|
}
|
|
}, trigger: 'blur'
|
|
}],
|
|
},//充值、支付信息验证
|
|
}
|
|
},
|
|
methods: {
|
|
//验证身份是否可编辑
|
|
canOperate(user_type) {
|
|
return user_type == 3 && !this.storeId || user_type == 4 && this.storeId ? true : false;
|
|
},
|
|
//新增、编辑优惠券
|
|
editCoupon(id, type) {
|
|
this.$root.$refs.base.editCoupon(id, type == 1 ? true : false);
|
|
},
|
|
//投放
|
|
sendCouponBefore(item) {
|
|
this.$root.$refs.base.sendOutToVip({
|
|
id: item.id, //优惠券或券包ID
|
|
name: item.coupon_name,//优惠券、券包名称
|
|
batch_type: 1, //1优惠券 2券包
|
|
});
|
|
},
|
|
//查看发放记录
|
|
seeRecord(id) {
|
|
this.$root.$refs.base.seeRecord(id, 1);
|
|
},
|
|
//使优惠券失效
|
|
couponFailure(id) {
|
|
this.$root.$refs.base.couponFailure(id, 1, () => {
|
|
this.getCouponList();
|
|
});
|
|
},
|
|
// 显示充值设置
|
|
getRechargeState(item) {
|
|
let obj = {
|
|
id: item.id,
|
|
recharge_state: item.recharge_state,
|
|
money: item.money,
|
|
};
|
|
this.rechargeForm = JSON.parse(JSON.stringify(obj));
|
|
this.showRechargeDialog = true;
|
|
},
|
|
// 保存充值设置
|
|
setRechargeState() {
|
|
this.$refs.rechargeForm.validate(valid => {
|
|
if (!valid) return;
|
|
this.$confirm('确认保存该优惠券的充值设置吗?', "提示", {
|
|
confirmButtonText: '确定',
|
|
}).then(() => {
|
|
$.ajax({
|
|
url: `/index.php/Retail/${this.storeId ? 'StoreCoupon' : 'Mcoupon'}/setRechargeState`,
|
|
type: "post",
|
|
data: this.rechargeForm,
|
|
success: (res) => {
|
|
if (res.status == 1) {
|
|
this.$message.success(res.message);
|
|
this.showRechargeDialog = false;
|
|
this.getCouponList();
|
|
} else {
|
|
this.$message.error(res.message)
|
|
}
|
|
}
|
|
})
|
|
}).catch(() => {
|
|
})
|
|
});
|
|
},
|
|
// 显示支付设置
|
|
getPayState(item) {
|
|
let obj = {
|
|
id: item.id,
|
|
payment_state: item.payment_state,
|
|
payment_money: item.payment_money,
|
|
};
|
|
this.paymentForm = JSON.parse(JSON.stringify(obj));
|
|
this.showPaymentDialog = true;
|
|
},
|
|
//支付设置保存
|
|
setPaymentState() {
|
|
this.$refs.paymentForm.validate(valid => {
|
|
if (!valid) return;
|
|
this.$confirm('确认保存该优惠券的支付设置吗?', "提示", {
|
|
confirmButtonText: '确定',
|
|
}).then(() => {
|
|
$.ajax({
|
|
url: `/index.php/Retail/${this.storeId ? 'StoreCoupon' : 'Mcoupon'}/setPaymentState`,
|
|
type: "post",
|
|
data: this.paymentForm,
|
|
success: (res) => {
|
|
if (res.status == 1) {
|
|
this.$message.success(res.message);
|
|
this.showPaymentDialog = false;
|
|
this.getCouponList();
|
|
} else {
|
|
this.$message.error(res.message)
|
|
}
|
|
}
|
|
})
|
|
}).catch(() => {
|
|
})
|
|
});
|
|
},
|
|
|
|
/* 切换每页数量 */
|
|
couponLimitChange(val) {
|
|
this.limit = val;
|
|
this.page = 1;
|
|
this.getCouponList();
|
|
},
|
|
/* 切换页数 */
|
|
couponPageChange(val) {
|
|
this.page = val;
|
|
this.getCouponList();
|
|
},
|
|
// 获取优惠券列表
|
|
getCouponList() {
|
|
$.ajax({
|
|
url: `/index.php/Retail/${this.storeId ? 'StoreCoupon' : 'Mcoupon'}/getCouponList`,
|
|
type: "post",
|
|
data: {
|
|
page: this.page,
|
|
limit: this.limit,
|
|
search_info: this.searchForm,
|
|
},
|
|
success: (res) => {
|
|
this.loading = false;
|
|
if (res.status == 1) {
|
|
this.couponList = res.data.list;
|
|
this.total = res.data.count;
|
|
} else {
|
|
this.couponList = [];
|
|
}
|
|
}
|
|
})
|
|
},
|
|
},
|
|
mounted() {
|
|
this.getCouponList();
|
|
},
|
|
});
|