Vue.component('m-coupon', { template: `
`, props: { 'storeId': { type: String, default: '', }, }, data() { return { operate: {},//操作权限 coupon_mold: '1', // 类型 1.普通优惠券 2.券包 record_model_type: null,//优惠券发放记录类型 1优惠券 2券包 showSendCoupon: false, //是否显示投放优惠券 couponData: { id: '', //优惠券或券包ID name: '', //优惠券、券包名称 batch_type: 1, //1优惠券 2券包 },//投放的优惠券信息 storeList: [],//新增券时可选门店列表 gradeList: [],//新增券时可选会员等级列表 showRecordDialog: false,// 发放记录显示 record_id: '', // 记录id couponIsSee: false,//是否只能查看优惠券不能编辑 showCouponEdit: false,//是否显示创建/编辑优惠券 editCouponId: '',//编辑的优惠券ID editPackageId: '',//编辑的券包ID showChooseClass: false,//是否显示选择分类 usedClassIdList: [],//已选分类ID列表 showChooseGoods: false,//是否显示选择商品 usedGoodsIdList: [],//已选商品ID列表 chooseStoreId: '',//需要选择分类、商品所属的门店ID selectedClassId: [],//已选择的分类ID列表(单选:[一级,二级,三级]) classCallback: null,//选择分类页面调用回调函数 goodsCallback: null,//选择商品页面调用回调函数 merchant_id: localStorage.merchant_id,//商户ID needChoose: true,//是否需要选择商品 showPackageEdit: false,//是否显示创建/编辑券包 packageIsSee: false,//是否只能查看券包不能编辑 } }, methods: { //新增、编辑优惠券 editCoupon(id, isSee) { this.editCouponId = id; this.getStoreListAndVipGrade(); this.couponIsSee = isSee; this.showCouponEdit = true; }, //关闭编辑优惠券 editCouponEnd() { this.editCouponId = ''; this.showCouponEdit = false; this.$refs.couponList.getCouponList(); }, //新增、编辑券包 editPackage(id, isSee) { this.editPackageId = id; this.getStoreListAndVipGrade(); this.packageIsSee = isSee; this.showPackageEdit = true; }, //关闭编辑优惠券 editPackageEnd() { this.editPackageId = ''; this.showPackageEdit = false; this.$refs.packageList.getCouponGroupList(); }, //关闭投放 优惠券、券包 closeSendCouponDialog() { this.showSendCoupon = false; }, // 优惠券、券包 发放记录 seeRecord(record_id, model_type) { this.record_id = record_id; this.record_model_type = model_type; this.showRecordDialog = true; }, //关闭优惠券、券包发放记录 closeRecordDialog() { this.showRecordDialog = false; }, //使优惠券、券包失效 couponFailure(id, model_type, callBack) { this.$confirm(`下架不影响已领取的用户使用,确认下架该${model_type == 1 ? '优惠券' : '券包'}吗?`, "温馨提示", { confirmButtonText: '确定', showCancelButton: false, type: 'info' }).then(() => { $.ajax({ url: '/index.php/Retail/' + (this.storeId ? 'StoreCoupon' : 'Mcoupon') + '/couponFailure', type: "post", data: { coupon_type: model_type, id: id, }, success: (res) => { if (res.status == 1) { this.$message.success(res.message); this.getCouponList(); if (typeof callBack == "function") callBack(); } else { this.$message.error(res.message ? res.message : '操作失败'); } } }) }).catch(() => { }) }, //准备投放优惠券、券包 sendOutToVip(data) { this.couponData = data; this.$nextTick(() => { this.showSendCoupon = true; }); }, //投放结束 sendEnd() { this.showSendCoupon = false; this.couponData = {}; }, //调用选择分类 chooseClass(class_ids, store_id, callback) { this.usedClassIdList = class_ids; this.chooseStoreId = store_id; if (callback) this.classCallback = callback; this.showChooseClass = true; }, //选择分类结束 chooseClassEnd(data) { if (this.classCallback) this.classCallback(data); this.classCallback = null; this.showChooseClass = false; }, //调用选择商品 chooseGoods(options, callback) { this.usedGoodsIdList = options.goods_ids || []; this.chooseStoreId = options.store_id || ''; this.needChoose = options.needChoose === false ? false : true; this.selectedClassId = options.class_id || []; if (callback) this.goodsCallback = callback; this.showChooseGoods = true; }, //选择商品结束 chooseGoodsEnd(data) { if (this.goodsCallback) this.goodsCallback(data); this.goodsCallback = null; this.showChooseGoods = false; }, //获取新增券或券包时可选的门店列表与等级列表 getStoreListAndVipGrade() { if (!this.storeList.length) $.ajax({ url: `/index.php/Retail/${this.storeId ? 'StoreCoupon' : 'Mcoupon'}/getStoreListAndVipGrade`, type: 'post', data: {}, success: res => { if (res.status == 1) { this.storeList = res.store_list; this.gradeList = res.vip_grade_list; } } }) }, //获取操作权限 getOperate() { let Ctrl = this.storeId ? 'StoreCoupon' : 'Mcoupon'; let auth_list = { batchGrantCoupon: `/index.php/Retail/${Ctrl}/batchGrantCoupon`, //优惠券或券包的投放 couponFailure: `/index.php/Retail/${Ctrl}/couponFailure`, //优惠券或券包下架 createCoupon: `/index.php/Retail/${Ctrl}/createCoupon`, //创建券 couponRecordList: `/index.php/Retail/${Ctrl}/couponRecordList`, //优惠券发放记录 setRechargeState: `/index.php/Retail/${Ctrl}/setRechargeState`, //充值设置 setPaymentState: `/index.php/Retail/${Ctrl}/setPaymentState`, //支付设置 editCoupon: `/index.php/Retail/${Ctrl}/editCoupon`, //编辑优惠券 createCouponGroup: `/index.php/Retail/${Ctrl}/createCouponGroup`, //创建券包 couponGroupRecordList: `/index.php/Retail/${Ctrl}/couponGroupRecordList`, //券包发放记录 editPackage: `/index.php/Retail/${Ctrl}/editPackage`, //编辑券包 }; $.ajax({ url: '/index.php/Retail/Component/checkOperateAuth', type: "post", data: { auth_list: JSON.stringify(auth_list), }, success: (res) => { if (res.status == 1) { this.operate = res.data; } } }) } }, created() { this.getOperate(); }, });