init: import production code mss.nahaichuan.com (exclude Runtime/Uploads/backups/logs)
这个提交包含在:
773
Public/plug/m-coupon/js/edit-coupon.js
可执行文件
773
Public/plug/m-coupon/js/edit-coupon.js
可执行文件
@@ -0,0 +1,773 @@
|
||||
Vue.component('m-edit-coupon', {
|
||||
template: `<el-dialog :append-to-body="true"
|
||||
:title="editId?(isSee?'查看优惠券':'编辑优惠券'):'新增优惠券'"
|
||||
:visible.sync="showEdit" width="80%" :top="'20px'"
|
||||
custom-class="customer-el-dialog__body"
|
||||
:before-close="closeDialog"
|
||||
:close-on-click-modal="false">
|
||||
<el-scrollbar style="height: calc(100vh - 200px);padding-right: 8px" v-loading="formLoading">
|
||||
<el-form :model="ruleForm" ref="ruleForm" :disabled="isSee" :rules="rules"
|
||||
label-width="140px" size="small"
|
||||
style="padding-top: 10px">
|
||||
<el-divider content-position="left">优惠券基础信息</el-divider>
|
||||
<el-form-item label="优惠券名称:" prop="coupon_name">
|
||||
<el-input v-model="ruleForm.coupon_name" style="width: 215px;"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item label="发放总量:" prop="coupon_amount">
|
||||
<el-input v-model="ruleForm.coupon_amount"
|
||||
oninput="value=this.value.replace(/^[0]|\\D/,'')"
|
||||
style="width: 215px;"><template slot="append">张</template></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item label="优惠券面额:" prop="discount_amount">
|
||||
<el-input v-model="ruleForm.discount_amount"
|
||||
oninput="value=value.replace(/[^\\d|.]/g,'')"
|
||||
:disabled="formDis"
|
||||
style="width: 215px;"><template slot="prepend">¥</template></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item label="消费门槛:" prop="consumption_threshold">
|
||||
<el-input v-model="ruleForm.consumption_threshold"
|
||||
style="width: 215px;"
|
||||
:disabled="formDis"
|
||||
oninput="value=value.replace(/[^\\d|.]/g,'')">
|
||||
<template slot="prepend">¥</template>
|
||||
</el-input>
|
||||
<span>即满【{{ruleForm.consumption_threshold||'?'}}】元减【{{ruleForm.discount_amount||'?'}}】元</span>
|
||||
</el-form-item>
|
||||
<el-divider content-position="left">基本规则</el-divider>
|
||||
<el-form-item label="发放类型:" prop="grant_type">
|
||||
<el-radio-group v-model="ruleForm.grant_type" @change="changeGrantType" :disabled="formDis">
|
||||
<el-radio label="1">自主发放</el-radio>
|
||||
<el-radio label="2">充值赠送</el-radio>
|
||||
<el-radio label="3">支付发放</el-radio>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
<template v-if="ruleForm.grant_type==1||ruleForm.grant_type==3">
|
||||
<el-form-item label="指定会员等级:" prop="choose_grade">
|
||||
<el-radio-group v-model="ruleForm.choose_grade" :disabled="formDis" @change="changeGradeType">
|
||||
<el-radio label="0">所有会员</el-radio>
|
||||
<el-radio label="1">指定会员等级</el-radio>
|
||||
<el-radio label="-1">plus会员</el-radio>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
<el-form-item v-if="ruleForm.choose_grade == 1" prop="vip_grade_id">
|
||||
<select-vip-grade-multiple :grade-id-arr.sync="ruleForm.vip_grade_id"
|
||||
:show-discount="true"
|
||||
:is-disabled="formDis"
|
||||
:placeholder="'请选择会员等级'"></select-vip-grade-multiple>
|
||||
</el-form-item>
|
||||
</template>
|
||||
<el-form-item label="指定门店:" prop="choose_store" @change="changeLimitStore">
|
||||
<template slot="label">
|
||||
<span>指定门店</span>
|
||||
<el-tooltip class="item" effect="dark" placement="right-start">
|
||||
<template slot="content">
|
||||
<p>限制后:</p>
|
||||
<p>①自主发放只能发放给属于指定门店内的会员</p>
|
||||
<p>②会员只能在指定门店内充值才能获得优惠券,绑定充值活动例外</p>
|
||||
<p>③会员只能在指定门店购买商品才能获得优惠券</p>
|
||||
<p>④获得券的会员只能在指定门店内使用该优惠券</p>
|
||||
<p>⑤只有指定单个门店时才能指定分类或商品</p>
|
||||
</template>
|
||||
<i class="el-icon-question"></i>
|
||||
</el-tooltip>
|
||||
<span>:</span>
|
||||
</template>
|
||||
<el-radio-group v-model="ruleForm.choose_store" :disabled="formDis||storeId?true:false" @change="changeLimitStore">
|
||||
<el-radio label="0">所有门店</el-radio>
|
||||
<el-radio label="1">指定门店</el-radio>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
<el-form-item v-if="ruleForm.choose_store == 1" prop="store_id_arr">
|
||||
<select-store-multiple :store-id-arr.sync="ruleForm.store_id_arr"
|
||||
:store-status="3" :is-disabled="formDis||storeId?true:false"
|
||||
:show-status="true"
|
||||
@change="changeChooseStore"
|
||||
:placeholder="'请选择指定门店'"></select-store-multiple>
|
||||
</el-form-item>
|
||||
<template v-if="ruleForm.choose_store==1&&ruleForm.store_id_arr&&ruleForm.store_id_arr.length==1">
|
||||
<el-form-item label="使用商品限制:" prop="appoint_type">
|
||||
<template slot="label">
|
||||
<span>使用商品限制</span>
|
||||
<el-tooltip class="item" effect="dark" placement="right-start">
|
||||
<template slot="content">
|
||||
<p>限制后:用户只能购买指定的商品或分类才能使用该优惠券</p>
|
||||
</template>
|
||||
<i class="el-icon-question"></i>
|
||||
</el-tooltip>
|
||||
<span>:</span>
|
||||
</template>
|
||||
<el-radio-group v-model="ruleForm.appoint_type" :disabled="formDis" @change="changeAppointType">
|
||||
<el-radio label="1">所有商品</el-radio>
|
||||
<el-radio label="2">指定分类</el-radio>
|
||||
<el-radio label="3">指定商品</el-radio>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
<el-form-item v-if="ruleForm.appoint_type == 2" label="商品分类" prop="appoint_id_arr">
|
||||
<template v-if="!formDis">
|
||||
<el-button type="primary" plain size="mini"
|
||||
:disabled="chooseClassList.length==20?true:false"
|
||||
@click="chooseClass">添加分类</el-button>
|
||||
<span style="font-size: 12px;color: #aaaaaa">已选 {{chooseClassList.length}}/20</span>
|
||||
</template>
|
||||
<m-show-choose-class :class-list="chooseClassList"
|
||||
:store-id="ruleForm.store_id_arr[0]"
|
||||
:operate-state="!formDis"
|
||||
@del="removeAppointId"></m-show-choose-class>
|
||||
</el-form-item>
|
||||
<el-form-item v-if="ruleForm.appoint_type == 3" label="商品列表" prop="appoint_id_arr">
|
||||
<template v-if="!formDis">
|
||||
<el-button type="primary" plain size="mini"
|
||||
:disabled="chooseGoodsList.length==20?true:false"
|
||||
@click="chooseGoods">添加商品</el-button>
|
||||
<span style="font-size: 12px;color: #aaaaaa">已选 {{chooseGoodsList.length}}/20</span>
|
||||
</template>
|
||||
<m-show-choose-goods :goods-list="chooseGoodsList"
|
||||
:operate-state="!formDis"
|
||||
@del="removeAppointId"></m-show-choose-goods>
|
||||
</el-form-item>
|
||||
</template>
|
||||
|
||||
<el-form-item label="有效期:" prop="validity_time_type">
|
||||
<el-radio-group v-model="ruleForm.validity_time_type"
|
||||
:disabled="formDis"
|
||||
@change="changeValidityTimeType">
|
||||
<el-radio label="1">固定日期</el-radio>
|
||||
<el-radio label="2">领券当日开始</el-radio>
|
||||
<el-radio label="3">领券次日开始</el-radio>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
<div v-if="ruleForm.validity_time_type == 1" style="display: flex;align-items: flex-start">
|
||||
<el-form-item label="固定时间:" prop="start_time">
|
||||
<el-date-picker
|
||||
v-model="ruleForm.start_time"
|
||||
:disabled="formDis"
|
||||
type="datetime"
|
||||
size="small"
|
||||
placeholder="起始时间"
|
||||
value-format="yyyy-MM-dd HH:mm:ss"
|
||||
:picker-options="datePickerStartOptions"
|
||||
align="center">
|
||||
</el-date-picker>
|
||||
</el-form-item>
|
||||
<span style="color:#c6c6c6;padding: 0 10px;line-height: 30px;">-</span>
|
||||
<el-form-item label-width="0" prop="end_time">
|
||||
<el-date-picker
|
||||
v-model="ruleForm.end_time"
|
||||
:disabled="formDis"
|
||||
type="datetime"
|
||||
size="small"
|
||||
placeholder="截止时间"
|
||||
value-format="yyyy-MM-dd HH:mm:ss"
|
||||
:picker-options="datePickerEndOptions"
|
||||
align="center">
|
||||
</el-date-picker>
|
||||
</el-form-item>
|
||||
</div>
|
||||
|
||||
<el-form-item v-if="ruleForm.validity_time_type==2||ruleForm.validity_time_type==3"
|
||||
:label="(ruleForm.validity_time_type==2?'当':'次')+'日开始:'" prop="day_num">
|
||||
<el-input v-model="ruleForm.day_num"
|
||||
:disabled="formDis"
|
||||
oninput="value=this.value.replace(/^[0]|\\D/,'')"
|
||||
style="width: 155px;"></el-input>
|
||||
<span>天内有效</span>
|
||||
</el-form-item>
|
||||
<el-form-item label="使用说明:" :disabled="false" prop="explain">
|
||||
<el-input type="textarea" class="el-textarea-customer"
|
||||
style="max-width: 600px"
|
||||
:autosize="{ minRows: 2, maxRows: 12}"
|
||||
maxlength="500"
|
||||
show-word-limit
|
||||
v-model="ruleForm.explain"></el-input>
|
||||
</el-form-item>
|
||||
<template v-if="!editId && storeId">
|
||||
<el-divider content-position="left">指定发送会员(可选)</el-divider>
|
||||
<el-form-item>
|
||||
<template slot="label">
|
||||
<span>创建后发送</span>
|
||||
<el-tooltip class="item" effect="dark" placement="right-start">
|
||||
<template slot="content">
|
||||
<p>开启后,优惠券创建成功将自动发送给指定用户</p>
|
||||
<p>支持搜索该商户所有登录用户,无需是会员</p>
|
||||
<p>访客发券后将自动注册为会员</p>
|
||||
</template>
|
||||
<i class="el-icon-question"></i>
|
||||
</el-tooltip>
|
||||
<span>:</span>
|
||||
</template>
|
||||
<el-switch v-model="appointSendVip"
|
||||
@change="onAppointSendVipChange"
|
||||
active-text="发送给指定用户"
|
||||
inactive-text="不指定">
|
||||
</el-switch>
|
||||
</el-form-item>
|
||||
<template v-if="appointSendVip">
|
||||
<el-form-item label="搜索用户:">
|
||||
<el-input v-model="vipSearchInput"
|
||||
placeholder="请输入手机号"
|
||||
style="width: 260px;"
|
||||
clearable
|
||||
@keydown.enter.exact.native.prevent="searchVipForCoupon">
|
||||
<el-button slot="append"
|
||||
@click="searchVipForCoupon"
|
||||
:loading="vipSearchLoading"
|
||||
icon="el-icon-search"></el-button>
|
||||
</el-input>
|
||||
</el-form-item>
|
||||
<el-form-item v-if="vipSearchList.length > 0" label="搜索结果:">
|
||||
<el-table :data="vipSearchList" border size="mini"
|
||||
:header-cell-style="{background:'#F5F7FA',color:'#606266'}"
|
||||
highlight-current-row
|
||||
@current-change="selectVipRow"
|
||||
style="max-width: 600px">
|
||||
<el-table-column align="center" type="index" label="#" width="40"></el-table-column>
|
||||
<el-table-column align="center" prop="user_name" label="昵称" min-width="120" show-overflow-tooltip></el-table-column>
|
||||
<el-table-column align="center" prop="mobile_phone" label="手机号" min-width="110"></el-table-column>
|
||||
<el-table-column align="center" label="状态" width="70">
|
||||
<template slot-scope="scope">
|
||||
<el-tag v-if="scope.row.is_member==1" type="success" size="mini">会员</el-tag>
|
||||
<el-tag v-else type="info" size="mini">访客</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<div style="margin-top:4px;color:#909399;font-size:12px">点击行即可选中;访客发券后将自动注册为会员</div>
|
||||
</el-form-item>
|
||||
<el-form-item v-if="selectedVip" label="已选用户:">
|
||||
<div style="display:inline-flex;align-items:center;gap:12px;padding:6px 12px;background:#f0f9eb;border:1px solid #c2e7b0;border-radius:4px;">
|
||||
<span style="color:#303133;">{{ selectedVip.user_name }}</span>
|
||||
<span style="color:#606266;">{{ selectedVip.mobile_phone }}</span>
|
||||
<el-tag v-if="selectedVip.is_member==1" type="success" size="mini">会员</el-tag>
|
||||
<el-tag v-else type="info" size="mini">访客</el-tag>
|
||||
<el-button type="text" size="mini" style="color:#f56c6c;" @click="clearSelectedVip">取消选中</el-button>
|
||||
</div>
|
||||
</el-form-item>
|
||||
</template>
|
||||
</template>
|
||||
</el-form>
|
||||
</el-scrollbar>
|
||||
<div v-if="!isSee" style="text-align: center;padding-top: 10px;border-top: 1px solid #DCDFE6;">
|
||||
<el-button size="medium" @click="closeDialog">取消</el-button>
|
||||
<el-button type="primary"
|
||||
size="medium"
|
||||
:disabled="btnLoading"
|
||||
@click="saveCoupon">
|
||||
<span>保存</span>
|
||||
<i v-if="btnLoading" class="el-icon-loading"></i>
|
||||
</el-button>
|
||||
</div>
|
||||
</el-dialog>`,
|
||||
props: {
|
||||
'showEdit': {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},//是否显示
|
||||
'editId': {
|
||||
type: String,
|
||||
default: '',
|
||||
},//编辑的优惠券ID
|
||||
'storeId': {
|
||||
type: String,
|
||||
default: '',
|
||||
},//门店ID,只有门店操作时会传
|
||||
'isSee': {
|
||||
type: Boolean,
|
||||
default: true,
|
||||
},//是否只是查看
|
||||
},
|
||||
data() {
|
||||
let _t = this;
|
||||
return {
|
||||
formLoading: false,//表单初始化loading
|
||||
chooseClassList: [],//已选分类列表
|
||||
chooseGoodsList: [],//已选商品列表
|
||||
datePickerStartOptions: {
|
||||
disabledDate: (time) => {
|
||||
let nowDate = new Date();
|
||||
let oneDay = 86400000;
|
||||
let endDate = _t.ruleForm.end_time ? (new Date(_t.ruleForm.end_time)) : new Date(nowDate.getTime() + (oneDay * 60));
|
||||
return time.getTime() < nowDate - oneDay || time.getTime() > endDate;
|
||||
}
|
||||
},//开始时间限制
|
||||
datePickerEndOptions: {
|
||||
disabledDate: (time) => {
|
||||
let nowDate = new Date();
|
||||
let oneDay = 86400000;
|
||||
let startDate = _t.ruleForm.start_time ? (new Date(_t.ruleForm.start_time)) : nowDate;
|
||||
let endDate = new Date(nowDate.getTime() + (oneDay * 90));
|
||||
return time.getTime() < startDate || time.getTime() > endDate;
|
||||
}
|
||||
},//结束时间限制
|
||||
ruleForm: {
|
||||
coupon_name: '',//优惠券名称
|
||||
coupon_amount: '',//发放总量
|
||||
discount_amount: '',//优惠券面额
|
||||
consumption_threshold: '',//消费门槛
|
||||
grant_type: '1',//发放类型
|
||||
choose_store: '0',//是否限制门店
|
||||
store_id_arr: [],//指定的门店id
|
||||
choose_grade: '0',//是否限制会员等级
|
||||
vip_grade_id: [],//指定的会员等级
|
||||
appoint_type: '1',//商品限制
|
||||
appoint_id_arr: [],//商品/类目id
|
||||
validity_time_type: '1',//有效期类型
|
||||
start_time: '',//开始时间
|
||||
end_time: '',//结束时间
|
||||
day_num: '',//有效天数
|
||||
explain: '',//使用说明
|
||||
},
|
||||
rules: {
|
||||
coupon_name: [{message: '请设置优惠券名称', required: true, trigger: 'change'}, {
|
||||
max: '30',
|
||||
message: '最大长度为 30 个字符',
|
||||
}],
|
||||
coupon_amount: [{message: '请设置发放总量', required: true, trigger: 'change'}, {
|
||||
validator: (rule, value, callback) => {
|
||||
let reg = /^[+]{0,1}(\d+)$/;
|
||||
if (value === '' || value === undefined) {
|
||||
callback(new Error("请设置发放总量"));
|
||||
} else if (!reg.test(value) || value * 1 > 10000000) {
|
||||
callback(new Error("发放总量最大为一千万"));
|
||||
} else {
|
||||
callback();
|
||||
}
|
||||
}, trigger: 'change'
|
||||
}],
|
||||
discount_amount: [{message: '请设置优惠券面额', required: true, trigger: 'change'}, {
|
||||
validator: (rule, value, callback) => {
|
||||
let reg = /^[+]{0,1}(\d+)$|^[+]{0,1}(\d+\.\d{0,2})$/;
|
||||
if (value === '' || value === undefined) {
|
||||
callback(new Error("请设置优惠券面额"));
|
||||
} else if (!reg.test(value) || value < 0.01) {
|
||||
callback(new Error("请设置正确的优惠券面额"));
|
||||
} else if (value * 1 > 10000000) {
|
||||
callback(new Error("优惠券面额最大为一千万"));
|
||||
} else {
|
||||
callback();
|
||||
}
|
||||
}, trigger: 'change'
|
||||
}],
|
||||
consumption_threshold: [{message: '请设置消费门槛', required: true, trigger: 'change'}, {
|
||||
validator: (rule, value, callback) => {
|
||||
let reg = /^[+]{0,1}(\d+)$|^[+]{0,1}(\d+\.\d{0,2})$/;
|
||||
if (value === '' || value === undefined) {
|
||||
callback(new Error("请设置消费门槛"));
|
||||
} else if (!reg.test(value) || value < 0.01) {
|
||||
callback(new Error("请设置正确的消费门槛"));
|
||||
} else if (_t.ruleForm.discount_amount * 1 >= value * 1) {
|
||||
callback(new Error("消费门槛不得小于优惠券面额"));
|
||||
} else if (value * 1 > 10000000) {
|
||||
callback(new Error("消费门槛最大为一千万"));
|
||||
} else {
|
||||
callback();
|
||||
}
|
||||
}, trigger: 'change'
|
||||
}],
|
||||
grant_type: [{message: '请选择发放类型', required: true, trigger: 'change'}],
|
||||
choose_store: [{message: '请选是否限制门店', required: true, trigger: 'change'}],
|
||||
store_id_arr: [{message: '请选择指定的门店', required: true, trigger: 'change'}, {
|
||||
validator: (rule, value, callback) => {
|
||||
if (_t.ruleForm.choose_store == 1 && (!value || !value.length)) {
|
||||
callback(new Error("请选择指定的门店"));
|
||||
} else {
|
||||
callback();
|
||||
}
|
||||
|
||||
}, trigger: 'blur'
|
||||
}],
|
||||
choose_grade: [{message: '请选择是否限制会员等级', required: true, trigger: 'change'}],
|
||||
vip_grade_id: [{message: '请选择指定的会员等级', required: true, trigger: 'change'}, {
|
||||
validator: (rule, value, callback) => {
|
||||
if (_t.ruleForm.choose_grade == 1 && (!value || !value.length)) {
|
||||
callback(new Error("请选择指定的会员等级"));
|
||||
} else {
|
||||
callback();
|
||||
}
|
||||
|
||||
}, trigger: 'blur'
|
||||
}],
|
||||
appoint_type: [{message: '请选择使用商品限制', required: true, trigger: 'change'}],
|
||||
appoint_id_arr: [{message: '请选择商品/类目', required: true, trigger: 'change'}, {
|
||||
validator: (rule, value, callback) => {
|
||||
if (_t.ruleForm.appoint_type == 1 || value && value.length) {
|
||||
callback();
|
||||
} else {
|
||||
let str = _t.ruleForm.appoint_type == 2 ? '类目' : '商品';
|
||||
callback(new Error("请选择指定的" + str));
|
||||
}
|
||||
|
||||
}, trigger: 'blur'
|
||||
}],
|
||||
validity_time_type: [{message: '请选择有效期类型', required: true, trigger: 'change'}],
|
||||
start_time: [{message: '请选择开始时间', required: true, trigger: ['change', 'blur']}, {
|
||||
validator: (rule, value, callback) => {
|
||||
if (!value) {
|
||||
callback(new Error('请选择开始时间'));
|
||||
} else {
|
||||
if (!_t.editId) {
|
||||
let start = Date.parse(new Date());
|
||||
let end = start + 86400000 * 60;
|
||||
|
||||
let a = Date.parse(new Date(value));
|
||||
if (start > a) {
|
||||
callback(new Error('开始时间不得小于当前时间'));
|
||||
} else if (a > end) {
|
||||
callback(new Error('开始时间不得小于当前时间后60天'));
|
||||
} else {
|
||||
callback();
|
||||
}
|
||||
} else {
|
||||
callback();
|
||||
}
|
||||
}
|
||||
}, trigger: ['change', 'blur']
|
||||
}],
|
||||
end_time: [{message: '请选择结束时间', required: true, trigger: ['change', 'blur']}, {
|
||||
validator: (rule, value, callback) => {
|
||||
if (!value) {
|
||||
callback(new Error('请选择结束时间'));
|
||||
} else {
|
||||
if (!_t.editId) {
|
||||
let start = Date.parse(new Date());
|
||||
let end = start + 86400000 * 90;
|
||||
let a = Date.parse(new Date(value));
|
||||
if (_t.ruleForm.start_time) {
|
||||
let b = Date.parse(new Date(_t.ruleForm.start_time));
|
||||
if (a <= b) {
|
||||
callback(new Error('结束时间不得小于等于开始时间'));
|
||||
}
|
||||
}
|
||||
if (start > a) {
|
||||
callback(new Error('结束时间不得小于当前时间'));
|
||||
} else if (a > end) {
|
||||
callback(new Error('结束时间不得小于当前时间后90天'));
|
||||
} else {
|
||||
callback();
|
||||
}
|
||||
} else {
|
||||
callback();
|
||||
}
|
||||
}
|
||||
}, trigger: ['change', 'blur']
|
||||
}],
|
||||
day_num: [{message: '请设置有效天数', required: true, trigger: 'change'}, {
|
||||
validator: (rule, value, callback) => {
|
||||
if (!value) {
|
||||
callback(new Error('请设置有效天数'));
|
||||
} else if (value * 1 > 90) {
|
||||
callback(new Error('有效天数不得大于90天'));
|
||||
} else {
|
||||
callback();
|
||||
}
|
||||
}, trigger: ['change', 'blur']
|
||||
}],
|
||||
explain: [{message: '请设置使用说明', required: false, trigger: 'change'}, {
|
||||
max: '500',
|
||||
message: '最大长度为 500',
|
||||
}],
|
||||
},
|
||||
btnLoading: false,//提交按钮状态
|
||||
formDis: false,//表单是否能编辑
|
||||
appointSendVip: false, //是否指定发送给某会员(仅新建时)
|
||||
vipSearchInput: '', //会员搜索关键字
|
||||
vipSearchLoading: false,//会员搜索loading
|
||||
vipSearchList: [], //会员搜索结果列表
|
||||
selectedVip: null, //已选中的会员
|
||||
}
|
||||
},
|
||||
computed: {},
|
||||
methods: {
|
||||
//搜索会员(用于新建时指定发送)
|
||||
searchVipForCoupon() {
|
||||
if (!this.vipSearchInput || !this.vipSearchInput.trim()) {
|
||||
this.$message.warning('请输入手机号');
|
||||
return;
|
||||
}
|
||||
this.vipSearchLoading = true;
|
||||
this.selectedVip = null;
|
||||
this.vipSearchList = [];
|
||||
$.ajax({
|
||||
url: '/index.php/Retail/StoreCoupon/searchVipForCoupon',
|
||||
type: 'post',
|
||||
data: {search_info: this.vipSearchInput.trim()},
|
||||
success: (res) => {
|
||||
this.vipSearchLoading = false;
|
||||
if (res.status == 1) {
|
||||
this.vipSearchList = res.data.list || [];
|
||||
if (this.vipSearchList.length === 0) {
|
||||
this.$message.warning('未找到匹配的用户,请确认手机号');
|
||||
}
|
||||
} else {
|
||||
this.$message.error(res.message);
|
||||
}
|
||||
},
|
||||
error: () => {
|
||||
this.vipSearchLoading = false;
|
||||
this.$message.error('搜索失败,请重试');
|
||||
}
|
||||
});
|
||||
},
|
||||
//选中搜索结果中的某一行会员
|
||||
selectVipRow(row) {
|
||||
this.selectedVip = row;
|
||||
},
|
||||
//取消选中会员
|
||||
clearSelectedVip() {
|
||||
this.selectedVip = null;
|
||||
},
|
||||
//指定发送开关变化时清空选中
|
||||
onAppointSendVipChange(val) {
|
||||
if (!val) {
|
||||
this.vipSearchInput = '';
|
||||
this.vipSearchList = [];
|
||||
this.selectedVip = null;
|
||||
}
|
||||
},
|
||||
//关闭弹框
|
||||
closeDialog() {
|
||||
this.$refs.ruleForm.resetFields();
|
||||
this.chooseClassList = [];
|
||||
this.chooseGoodsList = [];
|
||||
this.btnLoading = false;
|
||||
this.ruleForm.appoint_type = '1';
|
||||
this.ruleForm.choose_grade = '0';
|
||||
this.ruleForm.vip_grade_id = [];
|
||||
this.appointSendVip = false;
|
||||
this.vipSearchInput = '';
|
||||
this.vipSearchList = [];
|
||||
this.selectedVip = null;
|
||||
this.vipSearchLoading = false;
|
||||
this.$nextTick(() => {
|
||||
this.$emit('close');
|
||||
});
|
||||
},
|
||||
//修改发放类型
|
||||
changeGrantType() {
|
||||
if (!this.editId && this.storeId) {
|
||||
this.ruleForm.choose_store = '1';
|
||||
this.ruleForm.store_id_arr = [this.storeId];
|
||||
this.changeChooseStore();
|
||||
} else {
|
||||
this.ruleForm.choose_store = '0';
|
||||
this.ruleForm.store_id_arr = [];
|
||||
this.changeLimitStore();
|
||||
}
|
||||
this.ruleForm.choose_grade = '0';
|
||||
this.ruleForm.vip_grade_id = [];
|
||||
},
|
||||
//修改会员类型限制
|
||||
changeGradeType() {
|
||||
this.ruleForm.vip_grade_id = [];
|
||||
},
|
||||
//修改门店限制
|
||||
changeLimitStore() {
|
||||
this.ruleForm.store_id_arr = [];
|
||||
this.changeChooseStore();
|
||||
},
|
||||
//修改指定门店
|
||||
changeChooseStore() {
|
||||
this.ruleForm.appoint_type = '1';
|
||||
this.ruleForm.appoint_id_arr = [];
|
||||
},
|
||||
//修改商品限制类型
|
||||
changeAppointType() {
|
||||
this.chooseClassList = [];
|
||||
this.chooseGoodsList = [];
|
||||
this.ruleForm.appoint_id_arr = [];
|
||||
},
|
||||
//修改有效期限制类型
|
||||
changeValidityTimeType() {
|
||||
this.ruleForm.start_time = '';
|
||||
this.ruleForm.end_time = '';
|
||||
this.ruleForm.day_num = '';
|
||||
},
|
||||
//选择分类
|
||||
chooseClass() {
|
||||
this.$root.$refs.base.chooseClass(this.ruleForm.appoint_id_arr, this.ruleForm.store_id_arr[0], (data) => {
|
||||
let classList = this.chooseClassList;
|
||||
classList.push.apply(classList, data);
|
||||
this.chooseClassList = [];
|
||||
this.chooseClassList = classList;
|
||||
data.forEach((item) => {
|
||||
this.ruleForm.appoint_id_arr.push(item.id);
|
||||
})
|
||||
this.$refs.ruleForm.validateField('appoint_id_arr');
|
||||
});
|
||||
},
|
||||
//选择商品
|
||||
chooseGoods() {
|
||||
this.$root.$refs.base.chooseGoods({
|
||||
goods_ids: this.appoint_id_arr,
|
||||
store_id: this.ruleForm.store_id_arr[0],
|
||||
class_id: [],
|
||||
}, (data) => {
|
||||
let goodsList = this.chooseGoodsList;
|
||||
goodsList.push.apply(goodsList, data);
|
||||
this.chooseGoodsList = [];
|
||||
this.chooseGoodsList = goodsList;
|
||||
data.forEach((item) => {
|
||||
let key = item.goods_id;
|
||||
if (item.attribute_state == 2) {
|
||||
key += '_' + item.sku_id;
|
||||
}
|
||||
this.ruleForm.appoint_id_arr.push(key);
|
||||
})
|
||||
this.$refs.ruleForm.validateField('appoint_id_arr');
|
||||
});
|
||||
},
|
||||
//移除已选商品、分类ID
|
||||
removeAppointId(appoint_id) {
|
||||
let arr = [];
|
||||
this.ruleForm.appoint_id_arr.forEach((id) => {
|
||||
if (appoint_id != id) {
|
||||
arr.push(id);
|
||||
}
|
||||
});
|
||||
this.ruleForm.appoint_id_arr = arr;
|
||||
},
|
||||
//保存优惠券设置
|
||||
saveCoupon() {
|
||||
this.$refs.ruleForm.validate(valid => {
|
||||
if (!valid) return this.$message.warning('请检查必填项');
|
||||
this.$confirm('确认保存该优惠券吗?', "提示", {
|
||||
confirmButtonText: '确定',
|
||||
}).then(() => {
|
||||
this.btnLoading = true;
|
||||
let data = {};
|
||||
if (this.editId) {
|
||||
//编辑只允许修改以下字段
|
||||
data.coupon_name = this.ruleForm.coupon_name;
|
||||
data.coupon_amount = this.ruleForm.coupon_amount;
|
||||
data.explain = this.ruleForm.explain;
|
||||
data.id = this.editId;
|
||||
} else {
|
||||
data = {
|
||||
...this.ruleForm
|
||||
};
|
||||
data.appoint_id_arr = data.appoint_id_arr.join(',');
|
||||
data.vip_grade_id = data.choose_grade == '1' ? data.vip_grade_id.join(',') : '';
|
||||
if (!data.vip_grade_id) {
|
||||
data.vip_grade_id = '0';
|
||||
}
|
||||
data.store_id_arr = data.store_id_arr.join(',');
|
||||
if (!data.store_id_arr) {
|
||||
data.store_id_arr = '0';
|
||||
}
|
||||
}
|
||||
$.ajax({
|
||||
url: '/index.php/Retail/' + (this.storeId ? 'StoreCoupon' : 'Mcoupon') + '/' + (this.editId ? 'editCoupon' : 'createCoupon'),
|
||||
type: "post",
|
||||
data: {
|
||||
coupon: JSON.stringify(data),
|
||||
},
|
||||
success: (res) => {
|
||||
if (res.status == 1) {
|
||||
//新建且指定了发送会员时,创建后自动发放
|
||||
if (!this.editId && this.storeId && this.appointSendVip && this.selectedVip && res.data && res.data.coupon_id) {
|
||||
$.ajax({
|
||||
url: '/index.php/Retail/StoreCoupon/grantCouponToUser',
|
||||
type: 'post',
|
||||
data: {
|
||||
coupon_id: res.data.coupon_id,
|
||||
xcxvip_id: this.selectedVip.xcxvip_id,
|
||||
},
|
||||
success: (grantRes) => {
|
||||
this.btnLoading = false;
|
||||
if (grantRes.status == 1) {
|
||||
this.$message.success('优惠券创建成功,已发送给指定用户');
|
||||
} else {
|
||||
this.$message.warning('优惠券创建成功,但发送给用户失败:' + grantRes.message);
|
||||
}
|
||||
this.closeDialog();
|
||||
},
|
||||
error: () => {
|
||||
this.btnLoading = false;
|
||||
this.$message.warning('优惠券创建成功,但发送给用户时发生错误');
|
||||
this.closeDialog();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
this.btnLoading = false;
|
||||
this.$message.success(res.message);
|
||||
this.closeDialog();
|
||||
}
|
||||
} else {
|
||||
this.btnLoading = false;
|
||||
this.$message.error(res.message);
|
||||
}
|
||||
},
|
||||
error: (error) => {
|
||||
console.log(error);
|
||||
this.btnLoading = false;
|
||||
}
|
||||
})
|
||||
}).catch((err) => {
|
||||
console.log(err);
|
||||
})
|
||||
});
|
||||
},
|
||||
//获取券详情
|
||||
getCouponDetails() {
|
||||
this.formLoading = true;
|
||||
$.ajax({
|
||||
url: '/index.php/Retail/' + (this.storeId ? 'StoreCoupon' : 'Mcoupon') + '/couponInfo',
|
||||
type: 'post',
|
||||
data: {
|
||||
id: this.editId,
|
||||
},
|
||||
success: res => {
|
||||
this.formLoading = false;
|
||||
this.$nextTick(() => {
|
||||
if (res.status == 1) {
|
||||
try {
|
||||
let data = res.data.coupon;
|
||||
data.appoint_id_arr = data.choose_store == 1 && (data.appoint_type == 2 || data.appoint_type == 3) ? data.appoint_id_arr.split(',') : [];
|
||||
data.vip_grade_id = (data.choose_grade == 1) ? data.vip_grade_id.split(',') : [];
|
||||
data.store_id_arr = (data.choose_store == 1) ? data.store_id_arr.split(',') : [];
|
||||
for (let k in this.ruleForm) {
|
||||
this.ruleForm[k] = data[k];
|
||||
}
|
||||
this.chooseClassList = res.data.class_list;
|
||||
this.chooseGoodsList = res.data.goods_list;
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
this.$alert('该优惠券异常', '错误提示', {
|
||||
confirmButtonText: '关闭',
|
||||
callback: action => {
|
||||
this.closeDialog();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
},
|
||||
},
|
||||
mounted() {
|
||||
if (!this.editId && this.storeId) {
|
||||
this.$nextTick(() => {
|
||||
this.ruleForm.store_id_arr = [this.storeId];
|
||||
this.ruleForm.choose_store = '1';
|
||||
})
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
showEdit(n) {
|
||||
if (n) {
|
||||
this.ruleForm.validity_time_type = '1';
|
||||
this.appointSendVip = false;
|
||||
this.vipSearchInput = '';
|
||||
this.vipSearchList = [];
|
||||
this.selectedVip = null;
|
||||
if (this.editId) {
|
||||
this.getCouponDetails();
|
||||
}
|
||||
this.formDis = this.editId ? true : false;
|
||||
if (!this.editId) {
|
||||
this.ruleForm.store_id_arr = this.storeId ? [this.storeId] : [];
|
||||
this.ruleForm.choose_store = this.storeId ? '1' : '0';
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
});
|
||||
在新工单中引用
屏蔽一个用户