Vue.component('m-send-coupon', {
template: `
批量投放
指定投放
{{ sendForm.name }}
关闭
发放
`,
props: {
'showSendCoupon': {
type: Boolean,
default: false,
},//是否显示发放优惠券
'couponData': {
type: Object,
default: () => {
return {}
},
},//发放的券信息
'storeId': {
type: String,
default: '',
}
},
data() {
return {
showChooseGrantTypeDialog: false,//是否显示选择发放类型
showBatchSendDialog: false,//是否显示批量发放弹框
showChooseVipDialog: false,//是否显示选择会员列表
sendForm: {},//优惠券发放条件
vipList: [], //会员列表
vipForm: {
search_info: '',
page: 1, //会员列表页码
limit: 10, //会员列表每页读取数量
},//会员列表搜索内容
store_list: [],//限制的门店名称列表
grade_list: [],//限制的会员等级列表
total: 0, //会员数据总条数
loading: false, //会员列表loading框显示状态
sendLoading: false, //投放按钮loading状态
}
},
methods: {
//取消投放
closeSend() {
this.showChooseGrantTypeDialog = false;
this.showChooseVipDialog = false;
this.showBatchSendDialog = false;
this.loading = false;
this.sendLoading = false;
this.sendForm = {};
this.vipList = [];
this.total = 0;
this.vipForm = {
search_info: '',
page: 1, //会员列表页码
limit: 10, //会员列表每页读取数量
};//会员列表搜索内容;
this.$emit('end');
},
//选择发放方式
setGrantType(grant_type) {
this.sendForm.grant_type = grant_type;
if (grant_type == 1) {
//开始批量投放
this.$confirm("批量投放将会根据优惠券剩余数量投放给会员,确认投放吗?", "温馨提示", {
confirmButtonText: '确定',
type: 'info'
}).then(() => {
this.appointPutIn();
this.showBatchSendDialog = true;
this.showChooseGrantTypeDialog = false;
}).catch(() => {
})
} else {
//获取优惠券、券包限制的门店和会员等级
this.getAppointList();
//获取优惠券、券包限制的会员列表
this.showChooseVipDialog = true;
this.vipPageChange(1);
this.showChooseGrantTypeDialog = false;
}
},
//确认投放
appointPutIn() {
this.sendLoading = true;
$.ajax({
url: '/index.php/Retail/' + (this.storeId ? 'StoreCoupon' : 'Mcoupon') + '/BatchGrantCoupon',
type: "post",
data: this.sendForm,
success: (res) => {
if (res.status == 1) {
if (res.data.vip_count == this.sendForm.limit) {
this.sendForm.page++;
this.$nextTick(() => {
this.appointPutIn();
})
} else {
this.$message.success(res.message);
//批量投放结束则关闭投放
this.sendLoading = false;
if (this.sendForm.grant_type == 1) this.closeSend();
}
} else {
this.$message.error(res.message);
this.sendLoading = false;
if (this.sendForm.grant_type == 1) this.closeSend();
}
}
})
},
//指定投放-选择会员
chooseVipList(data) {
let arr = [];
data.forEach((item) => {
arr.push(item.id);
});
this.sendForm.vip_id_arr = arr.join(',');
},
//指定投放-获取优惠券可使用的门店列表和会员等级列表
getAppointList() {
$.ajax({
url: '/index.php/Retail/' + (this.storeId ? 'StoreCoupon' : 'Mcoupon') + '/getAppointList',
type: "post",
data: {
id: this.sendForm.id,
coupon_type: this.sendForm.batch_type,
},
success: (res) => {
if (res.status == 1) {
this.store_list = res.data.store_list;
this.grade_list = res.data.grade_list;
} else {
this.store_list = res.data.store_list;
this.grade_list = res.data.grade_list;
}
}
})
},
//指定投放-会员列表每页数量修改
vipSizeChange(val) {
this.vipForm.limit = val;
this.getGrantVipList();
},
//指定投放-会员列表页码修改
vipPageChange(val) {
this.vipForm.page = val;
this.getGrantVipList();
},
//指定投放-获取指定投放会员列表
getGrantVipList() {
this.loading = true;
$.ajax({
url: '/index.php/Retail/' + (this.storeId ? 'StoreCoupon' : 'Mcoupon') + '/getStoreGradeVipInfo',
type: "post",
data: {
coupon_type: this.sendForm.batch_type,
id: this.sendForm.id,
...this.vipForm,
},
success: (res) => {
this.loading = false;
if (res.status == 1) {
this.vipList = res.data.list;
this.total = res.data.count * 1;
} else {
this.vipList = [];
}
}
})
},
},
mounted() {
},
watch: {
couponData: {
deep: true,
handler(n, o) {
console.log(n, o);
this.sendForm = {
id: n.id, //优惠券或券包ID
name: n.name, //优惠券、券包名称
batch_type: n.batch_type, //1优惠券 2券包
grant_type: '', //1批量投放 2指定投放
vip_id_arr: '', //指定投放的会员ID字符串,号拼接集合
page: 1, //批量投放的页码
limit: 10, //批量投放时每页投放的会员数量
};
if (n.id > 0) {
this.$nextTick(() => {
this.showChooseGrantTypeDialog = true;
})
}
let zIndex = [...document.all].reduce((r, e) => Math.max(r, +window.getComputedStyle(e).zIndex || 0), 0);
console.log(zIndex);
},
}
}
});