Vue.component('m-coupon-index', {
template: `
-
搜索
新建
不限制
全部商品
指定分类
指定商品
全部
未开始
进行中
已结束
发放记录
编辑
查看
投放
充值设置
支付设置
下架
查看
充值设置
保存
支付设置
保存
`,
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();
},
});