| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775 |
- <!-- 引一个当前组件 -->
- <?php
- use common\helpers\ComponentHelper;
- use common\helpers\AddonHelper;
- if ($has_coupon) {
- ComponentHelper::loadComponentView('coupon-select', AddonHelper::getAddonRootPath('Coupon') . 'backend/views/components');
- }
- ComponentHelper::loadComponentView('com-dialog-select');
- ?>
- <div id="app" v-cloak>
- <el-card shadow="never" style="border:0;min-width: 1200px;">
- <el-form ref="formData" :model="formData" label-width="150px" :rules="rules">
- <el-form-item label="活动名称" prop="name">
- <el-input v-model="formData.name" size="small" style="max-width: 200px;"></el-input>
- </el-form-item>
- <el-form-item label="活动时间" prop="active_time">
- <el-date-picker
- v-model="formData.active_time"
- type="datetimerange"
- unlink-panels
- size="small"
- range-separator="至"
- start-placeholder="开始日期"
- end-placeholder="结束日期"
- :picker-options="pickerOptions"
- @change="updateTime">
- </el-date-picker>
- </el-form-item>
- <el-form-item label="奖励类型">
- <el-radio-group v-model="formData.type" @change="switchReward">
- <el-radio :label="1" border size="small">条件奖励</el-radio>
- <el-radio :label="2" border size="small">阶梯奖励</el-radio>
- </el-radio-group>
- </el-form-item>
- <el-form-item label="推荐人奖励方式">
- <el-radio-group v-model="formData.settle_type">
- <el-radio :label="0" border size="small">用户注册后</el-radio>
- <el-radio :label="4" border size="small">订单完成后</el-radio>
- </el-radio-group>
- </el-form-item>
- <el-form-item>
- <br>
- <br>
- <el-table :data="rewardInfo" stripe style="width: 100%">
- <el-table-column prop="num" label="人数条件" width="300" class="accon">
- <template slot-scope="scope">
- {{ formData.type == 1 ? '每' : '' }}推荐
- <el-input v-model.number="scope.row.arrive_num" type="number" size="small" style="max-width: 200px;padding-left: 10px;" @input="HandleInput($event,scope.$index, 'arrive_num')">
- <template slot="append">注册</template>
- </el-input>
- </template>
- </el-table-column>
- <el-table-column label="消费条件" width="300" class="accon" v-if="formData.settle_type == 4">
- <template slot-scope="scope">
- 消费满<el-input v-model="scope.row.consumption_amount" size="small" type="number" style="max-width: 200px;padding-left: 10px;" @input="HandleInput($event,scope.$index, 'consumption_amount')">
- <template slot="append">元</template>
- </el-input>
- </template>
- </el-table-column>
- <el-table-column prop="data" label="奖励内容">
- <template slot-scope="scope">
- <div style="margin-bottom: 14px;" v-for="(type,index) in scope.row.data" :key="index">
- <div style="margin-bottom: 10px;" flex>
- <el-select v-model="scope.row.data[index].key" size="small" placeholder="请选择" @change="updateType($event,scope.$index,index)">
- <el-option
- v-for="item in rechargeType"
- :key="item.value"
- :label="item.label"
- :value="item.value"
- :disabled="scope.row.data.findIndex(v => v.key == item.value) != -1"
- >
- </el-option>
- </el-select>
- <el-button v-if="scope.row.data[index].key == 0" size="small" style="margin-left: 12px;" @click="openCouponPop(scope.$index)">选择优惠券</el-button>
- <div style="margin-left: 10px;" v-else>
- <el-input v-model="scope.row.data[index].data" size="small" type="number" @input="validatorInfo($event,scope.$index,2,scope.row.data[index].key)">
- <template slot="append">{{scope.row.data[index].key == 2?'分':'元'}}</template>
- </el-input>
- </div>
- <el-button @click="delAward(scope.row.data[index].key,scope.$index)" size="small" v-if="scope.row.data.length > 1" type="text" icon="el-icon-close" style="color: #ec1717;font-size: 20px;padding: 0;margin-left: 12px;"></el-button>
- </div>
- <el-table v-if="scope.row.data[index].key == 0" :data="scope.row.data[index].data" stripe style="width: 100%;">
- <el-table-column prop="name" label="优惠券名称" width="160"></el-table-column>
- <el-table-column prop="discount_method" label="优惠券内容"></el-table-column>
- <el-table-column label="库存(张)" width="160">
- <template slot-scope="couponScope">
- {{couponScope.row.total_count == -1?'不限量':couponScope.row.total_count}}
- </template>
- </el-table-column>
- <el-table-column prop="dcount" label="奖励张数" width="160">
- <template slot-scope="couponScope">
- <el-input v-model="couponScope.row.num" size="small" type="number" @input="validatorInfo($event,scope.$index,3,0,couponScope.$index)">
- <template slot="append">张</template>
- </el-input>
- </template>
- </el-table-column>
- <el-table-column label="操作" width="100" align="center">
- <template slot-scope="couponScope">
- <el-button type="text" size="small" @click="delCoupon(couponScope.$index,scope.$index)">删除</el-button>
- </template>
- </el-table-column>
- </el-table>
- </div>
- <div v-if="scope.row.data.length != rechargeType.length">
- <el-button @click="addAward(scope.$index)" size="small" plain>添加奖励内容</el-button>
- </div>
- </template>
- </el-table-column>
- <el-table-column label="操作" width="100" align="center">
- <template slot-scope="scope">
- <el-button @click="deleteReward(scope.$index)" size="small" type="text" size="small">删除</el-button>
- </template>
- </el-table-column>
- </el-table>
- <div>
- <el-button size="small" style="margin-top: 10px;" @click="addRewardInfo" v-if="(formData.type == 1 && rewardInfo && rewardInfo.length == 0) || formData.type == 2">添加奖励条件</el-button>
- </div>
- </el-form-item>
- <el-form-item label="被推荐人参加奖励">
- <el-radio-group v-model="formData.be_status">
- <el-radio :label="1" border size="small">关闭</el-radio>
- <el-radio :label="2" border size="small">开启</el-radio>
- </el-radio-group>
- </el-form-item>
- <el-form-item label="被推荐人奖励方式" v-if="formData.be_status == 2">
- <el-radio-group v-model="formData.be_settle_type">
- <el-radio :label="0" border size="small">用户注册后</el-radio>
- </el-radio-group>
- </el-form-item>
- <el-form-item>
- <el-table v-if="formData.be_status == 2" :data="berewardInfo" stripe style="width: 100%">
- <el-table-column prop="data" label="奖励内容">
- <template slot-scope="scope">
- <div style="margin-bottom: 14px;" v-for="(type,index) in scope.row.data" :key="index">
- <div style="margin-bottom: 10px;" flex>
- <el-select v-model="scope.row.data[index].key" size="small" placeholder="请选择" @change="beupdateType($event,scope.$index,index)">
- <el-option
- v-for="item in rechargeType"
- :key="item.value"
- :label="item.label"
- :value="item.value"
- :disabled="scope.row.data.findIndex(v => v.key == item.value) != -1"
- >
- </el-option>
- </el-select>
- <el-button v-if="scope.row.data[index].key == 0" size="small" style="margin-left: 12px;" @click="openbeCouponPop(scope.$index)">选择优惠券</el-button>
- <div style="margin-left: 10px;" v-else>
- <el-input v-model="scope.row.data[index].data" size="small" type="number" @input="validatorInfo2($event,scope.$index,2,scope.row.data[index].key)">
- <template slot="append">{{scope.row.data[index].key == 2?'分':'元'}}</template>
- </el-input>
- </div>
- <el-button @click="delbeAward(scope.row.data[index].key,scope.$index)" size="small" v-if="scope.row.data.length > 1" type="text" icon="el-icon-close" style="color: #ec1717;font-size: 20px;padding: 0;margin-left: 12px;"></el-button>
- </div>
- <el-table v-if="scope.row.data[index].key == 0" :data="scope.row.data[index].data" stripe style="width: 100%;">
- <el-table-column prop="name" label="优惠券名称" width="160"></el-table-column>
- <el-table-column prop="discount_method" label="优惠券内容"></el-table-column>
- <el-table-column label="库存(张)" width="160">
- <template slot-scope="couponScope">
- {{couponScope.row.total_count == -1?'不限量':couponScope.row.total_count}}
- </template>
- </el-table-column>
- <el-table-column prop="dcount" label="奖励张数" width="160">
- <template slot-scope="couponScope">
- <el-input v-model="couponScope.row.num" size="small" type="number" @input="validatorInfo2($event,scope.$index,3,0,couponScope.$index)">
- <template slot="append">张</template>
- </el-input>
- </template>
- </el-table-column>
- <el-table-column label="操作" width="100" align="center">
- <template slot-scope="couponScope">
- <el-button size="small" type="text" size="small" @click="delbeCoupon(couponScope.$index,scope.$index)">删除</el-button>
- </template>
- </el-table-column>
- </el-table>
- </div>
- <div v-if="scope.row.data.length != rechargeType.length">
- <el-button @click="addBeAward(scope.$index)" size="small" plain>添加奖励内容</el-button>
- </div>
- </template>
- </el-table-column>
- </el-table>
- </el-form-item>
- <el-form-item>
- <el-button type="primary" @click="submitForm" size="small" :loading="subLoading">保存</el-button>
- </el-form-item>
- </el-form>
- <!-- 推荐人优惠券弹窗 -->
- <coupon-select v-if="has_coupon" :coupon-loading="couponPop" :coupon_arr="selCoupon" @submit="determine" @close="showCoupon"></coupon-select>
- <!-- 被推荐优惠券弹窗 -->
- <coupon-select v-if="has_coupon" :coupon-loading="becouponPop" :coupon_arr="beselCoupon" @submit="determine" @close="showCoupon"></coupon-select>
- </el-card>
- </div>
- <script>
- const app = new Vue({
- el: '#app',
- data() {
- return {
- id: null,
- formData: {
- name: "",
- start_time: "",
- end_time: "",
- item_id: [],
- type: 1,
- arrive_num:1,
- active_time: [],
- reward_info: [],
- be_reward_info: [],
- be_status:1,
- be_settle_type: 0,
- settle_type: 4,
- },
- has_coupon: <?php echo $has_coupon ? 'true' : 'false'; ?>,
- rewardTemp1: [{
- num: 0,
- arrive_num: 0,
- consumption_amount:0,
- data: [{
- key: 0,
- name: "优惠券",
- type: 'coupon',
- data: []
- }],
- }],// 临时存储条件奖励类型值
- rewardTemp2: [{
- num: 0,
- arrive_num: 0,
- consumption_amount:0,
- data: [{
- key: 0,
- name: "优惠券",
- type: 'coupon',
- data: []
- }],
- }],// 临时存储阶梯奖励类型值
- rewardInfo: [{
- num: 0,
- arrive_num: 0,
- consumption_amount:0,
- data: [{
- key: 0,
- name: "优惠券",
- type: 'coupon',
- data: []
- }],
- }],//奖励内容
- berewardInfo: [{
- num: 0,
- arrive_num: 0,
- consumption_amount:0,
- data: [{
- key: 0,
- name: "优惠券",
- type: 'coupon',
- data: []
- }],
- }],//被奖励内容
- rechargeType: [
- {
- value: 0,
- label: '优惠券'
- },
- {
- value: 1,
- label: '余额'
- },
- {
- value: 2,
- label: '积分'
- },
- ],
- typeArr: ['coupon','balance','score'], //跟rechargeType对应
- couponPop: false,
- becouponPop: false,
- couponPopIndex: -1,
- becouponPopIndex: -1,
- rules: {
- name: [
- { required: true, message: '活动名称不能为空', trigger: 'blur' },
- {
- validator: (rule, value, callback) => {
- if(value.length>12||value.length<0){
- callback('最大长度在1-12个字内');
- }
- callback();
- }
- },
- ],
- active_time: [{ required: true, message: '活动时间不能为空', trigger: 'blur' }],
- },
- subLoading: false,
- selCoupon: [],//打开优惠券弹窗传递已选中的优惠券
- beselCoupon: [],//被推荐人打开优惠券弹窗传递已选中的优惠券
- pickerOptions: {
- shortcuts: [{
- text: '7天',
- onClick(picker) {
- const end = new Date();
- const start = new Date();
- end.setTime(end.getTime() + 3600 * 1000 * 24 * 7);
- picker.$emit('pick', [start, end]);
- }
- }, {
- text: '15天',
- onClick(picker) {
- const end = new Date();
- const start = new Date();
- end.setTime(end.getTime() + 3600 * 1000 * 24 * 15);
- picker.$emit('pick', [start, end]);
- }
- }, {
- text: '30天',
- onClick(picker) {
- const end = new Date();
- const start = new Date();
- end.setTime(end.getTime() + 3600 * 1000 * 24 * 30);
- picker.$emit('pick', [start, end]);
- }
- }]
- },
- }
- },
- created(){
- if (getQuery('id') && getQuery('id') != 0) {
- this.id = getQuery('id');
- this.getDetail();
- }
- },
- methods: {
- // 获取充值信息
- getDetail(){
- request({
- params: {
- r: 'recommen/default/edit',
- id: this.id,
- },
- method: 'get',
- }).then(res => {
- console.info(res);
- if(res.data.code == 0){
- if(res.data.data.detail) {
- this.formData = res.data.data.detail;
- this.formData.be_settle_type = 0;
- if(res.data.data.detail.recommen_reward) this.rewardInfo = res.data.data.detail.recommen_reward;
- if(res.data.data.detail.be_recommen_reward) this.berewardInfo = res.data.data.detail.be_recommen_reward;
- this.$set(this.formData, 'active_time', [new Date(res.data.data.detail.start_time * 1000),new Date(res.data.data.detail.end_time * 1000)]);
- }
- }
- })
- },
- // 添加奖励条件
- addAward(index){
- let key = 0;
- for(let i = 0;i<this.rechargeType.length;i++){
- let dataIndex = this.rewardInfo[index].data.findIndex(v => v.key == this.rechargeType[i].value);
- if(dataIndex == -1){
- key = i + key;
- break;
- }
- }
- let obj = {
- key,
- name: this.rechargeType[key].label,
- type: this.typeArr[key],
- data: key == 0?[]:"",
- }
- if(key != 0){
- obj.data = 0;
- }
- this.rewardInfo[index].data.push(obj);
- },
- // 添加奖励条件
- addBeAward(index){
- let key = 0;
- for(let i = 0;i<this.rechargeType.length;i++){
- let dataIndex = this.berewardInfo[index].data.findIndex(v => v.key == this.rechargeType[i].value);
- if(dataIndex == -1){
- key = i + key;
- break;
- }
- }
- let obj = {
- key,
- name: this.rechargeType[key].label,
- type: this.typeArr[key],
- data: key == 0?[]:"",
- }
- if(key != 0){
- obj.data = 0;
- }
- this.berewardInfo[index].data.push(obj);
- },
- // 删除奖励条件
- delAward(key,index){
- let couponIndex = this.rewardInfo[index].data.findIndex(v => v.key == key);
- this.rewardInfo[index].data.splice(couponIndex,1);
- },
- // 删除奖励条件
- delbeAward(key,index){
- let couponIndex = this.berewardInfo[index].data.findIndex(v => v.key == key);
- this.berewardInfo[index].data.splice(couponIndex,1);
- },
- // 打开优惠券弹窗
- openCouponPop(index){
- if (this.has_coupon == false) {
- this.$message.error("请安装优惠券插件");
- return;
- }
- this.couponPopIndex = index;
- let dataIndex = this.rewardInfo[index].data.findIndex(v => v.type == 'coupon');
- this.selCoupon = this.rewardInfo[index].data[dataIndex].data;
- this.couponPop = true;
- },
- openbeCouponPop(index){
- if (this.has_coupon == false) {
- this.$message.error("请安装优惠券插件");
- return;
- }
- this.becouponPopIndex = index;
- let dataIndex = this.berewardInfo[index].data.findIndex(v => v.type == 'coupon');
- this.beselCoupon = this.berewardInfo[index].data[dataIndex].data;
- this.becouponPop = true;
- },
- showCoupon(){
- this.couponPopIndex = -1;
- this.couponPop = false;
- this.becouponPopIndex = -1;
- this.becouponPop = false;
- },
- //弹窗确定
- determine(arr) {
- if(this.becouponPop){
- console.log(this.berewardInfo,88,this.becouponPopIndex);
- let couponPopData = this.berewardInfo[this.becouponPopIndex].data;
- let couponIndex = couponPopData.findIndex(v => v.key == 0);
- if(couponIndex != -1){
- this.$set(this.berewardInfo[this.becouponPopIndex].data[couponIndex],'data',arr);
- //this.berewardInfo[this.becouponPopIndex].data[couponIndex].data = arr;
- }
- this.becouponPop = false;
- }else{
- console.log(this.rewardInfo,99);
- let couponPopData = this.rewardInfo[this.couponPopIndex].data;
- let couponIndex = couponPopData.findIndex(v => v.key == 0);
- if(couponIndex != -1){
- this.rewardInfo[this.couponPopIndex].data[couponIndex].data = arr;
- }
- this.couponPop = false;
- }
- },
- // 删除优惠券
- delCoupon(selCouponIndex,index){
- let couponPopData = this.rewardInfo[index].data;
- let couponIndex = couponPopData.findIndex(v => v.key == 0);
- if(couponIndex != -1){
- this.rewardInfo[index].data[couponIndex].data.splice(selCouponIndex,1);
- }
- },
- // 删除优惠券
- delbeCoupon(selCouponIndex,index){
- let couponPopData = this.berewardInfo[index].data;
- let couponIndex = couponPopData.findIndex(v => v.key == 0);
- if(couponIndex != -1){
- this.berewardInfo[index].data[couponIndex].data.splice(selCouponIndex,1);
- }
- },
- // 添加奖励条件
- addRewardInfo(){
- this.rewardInfo.push({
- num: 0,
- arrive_num: 0,
- consumption_amount:0,
- data: [{
- key: 0,
- name: "优惠券",
- type: 'coupon',
- data: []
- }],
- });
- },
- // 删除奖励条件
- deleteReward(index){
- this.rewardInfo.splice(index,1);
- },
- // 删除奖励条件
- deletebeReward(index){
- console.log(index,999);
- this.berewardInfo.splice(index,1);
- },
- // 切换奖励类型
- switchReward(event){
- let self = this;
- if(event == 1) {
- self.rewardTemp2 = self.rewardInfo;
- self.rewardInfo = self.rewardTemp1;
- } else {
- self.rewardTemp1 = self.rewardInfo;
- self.rewardInfo = self.rewardTemp2;
- }
- },
- updateTime(val){
- if(val){
- this.formData.start_time = parseInt(val[0].getTime() / 1000);
- this.formData.end_time = parseInt(val[1].getTime() / 1000);
- } else {
- this.formData.start_time = "";
- this.formData.end_time = "";
- }
- },
- // 表单数值验证
- validatorInfo(val,index,type = 1,key,couponIndex){
- console.info(val,index,type,key,couponIndex);
- if(val == ''){
- return;
- }
- let dataIndex = -1;
- if(type != 1){
- dataIndex = this.rewardInfo[index].data.findIndex(v => v.key == key);
- }
- if(val <= 0){
- if(type == 2){
- this.rewardInfo[index].data[dataIndex].data = 0;
- } else if(type == 3){
- this.rewardInfo[index].data[dataIndex].data[couponIndex].num = 0;
- } else {
- this.rewardInfo[index].num = 0;
- }
- return;
- }
- // 是否能最多保留两位小数
- let reg = /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/;
- if(!reg.test(val) && type != 3){
- let i = val.indexOf(".") + 3;
- val = val.substr(0,i)
- if(type == 2){
- this.rewardInfo[index].data[dataIndex].data = val;
- } else {
- this.rewardInfo[index].num = val;
- }
- }
- if(type == 3){
- // total_count
- val = parseInt(val);
- let totalCount = this.rewardInfo[index].data[dataIndex].data[couponIndex].total_count;
- if(totalCount < val && totalCount != -1){
- this.rewardInfo[index].data[dataIndex].data[couponIndex].num = totalCount;
- } else {
- this.rewardInfo[index].data[dataIndex].data[couponIndex].num = val;
- }
- }
- },
- validatorInfo2(val,index,type = 1,key,couponIndex){
- console.info(val,index,type,key,couponIndex);
- if(val == ''){
- return;
- }
- let dataIndex = -1;
- if(type != 1){
- dataIndex = this.berewardInfo[index].data.findIndex(v => v.key == key);
- }
- if(val <= 0){
- if(type == 2){
- this.berewardInfo[index].data[dataIndex].data = 0;
- } else if(type == 3){
- this.berewardInfo[index].data[dataIndex].data[couponIndex].num = 0;
- } else {
- this.berewardInfo[index].num = 0;
- }
- return;
- }
- // 是否能最多保留两位小数
- let reg = /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/;
- if(!reg.test(val) && type != 3){
- let i = val.indexOf(".") + 3;
- val = val.substr(0,i)
- if(type == 2){
- this.berewardInfo[index].data[dataIndex].data = val;
- } else {
- this.berewardInfo[index].num = val;
- }
- }
- if(type == 3){
- // total_count
- val = parseInt(val);
- let totalCount = this.berewardInfo[index].data[dataIndex].data[couponIndex].total_count;
- if(totalCount < val && totalCount != -1){
- this.berewardInfo[index].data[dataIndex].data[couponIndex].num = totalCount;
- } else {
- this.berewardInfo[index].data[dataIndex].data[couponIndex].num = val;
- }
- }
- },
- HandleInput(e,index,name) {
- console.log(e,index,name);
- if (name == 'arrive_num') {
- this.rewardInfo[index][name] = parseInt(e);
- } else {
- this.rewardInfo[index][name] = ('' + e)
- .replace(/[^\d^\.]+/g, '')
- .replace(/^0+(\d)/, '$1')
- .replace(/^\./, '0.')
- .match(/^\d*(\.?\d{0,2})/g)[0] || ''
- }
- },
- // limitInput(value, index, name) {
- // this.rewardInfo[index][name] = ('' + value)
- // .replace(/[^\d^\.]+/g, '')
- // .replace(/^0+(\d)/, '$1')
- // .replace(/^\./, '0.')
- // .match(/^\d*(\.?\d{0,2})/g)[0] || ''
- // },
- // 奖励奖励表单严重
- validatorForm(){
- let arr = ['优惠券','余额','积分'];
- if(this.rewardInfo.length<=0){
- return "推荐人奖励至少添加一项";
- }
- for(let i = 0;i<this.rewardInfo.length;i++){
- if(this.rewardInfo[i].arrive_num <= 0 || !this.rewardInfo[i].arrive_num){
- return "推荐人数不能小于等于0 或者不能为空";
- }
- //推荐人
- for(let j = 0;j<this.rewardInfo[i].data.length;j++){
- if(this.rewardInfo[i].data[j].key == 0){
- if(this.rewardInfo[i].data[j].data.length == 0) {
- return "请选择奖励内容的优惠券";
- }
- text = this.validatorCoupon(this.rewardInfo[i].data[j].data);
- if(text) return text;
- } else {
- if(!this.rewardInfo[i].data[j].data || this.rewardInfo[i].data[j].data <= 0){
- return "奖励内容的" + arr[this.rewardInfo[i].data[j].key] + "值不能为空或小于等于0";
- }
- }
- }
- }
- if(this.berewardInfo){
- for(let i = 0;i<this.berewardInfo.length;i++){
- //被推荐人
- if(this.formData.be_status==2){ console.log(this.berewardInfo);
- for(let j = 0;j<this.berewardInfo[i].data.length;j++){
- if(this.berewardInfo[i].data[j].key == 0){
- if( this.berewardInfo[i].data[j].data ) {
- if(this.berewardInfo[i].data[j].data.length == 0){
- return "请选择奖励内容的优惠券";
- }
- text = this.validatorCoupon(this.berewardInfo[i].data[j].data);
- if(text) return text;
- }else{
- return "请选择奖励内容的优惠券";
- }
- } else {
- if(!this.berewardInfo[i].data[j].data || this.berewardInfo[i].data[j].data <= 0){
- return "奖励内容的" + arr[this.berewardInfo[i].data[j].key] + "值不能为空或小于等于0";
- }
- }
- }
- }
- }
- }
- for(let i = 0;i<this.rewardInfo.length;i++) {
- let num = this.rewardInfo[i].arrive_num;
- let arr = this.rewardInfo.filter(v => v.arrive_num == num);
- if(arr.length > 1){
- return "奖励条件不能重复"
- }
- }
- return "";
- },
- // 验证优惠券
- validatorCoupon(couponList){
- for(let i = 0;i<couponList.length;i++){
- if(couponList[i].num <= 0){
- return "优惠券奖励数量不能小于等于0";
- }
- }
- return "";
- },
- // 更改奖励内容类型
- updateType(key,index,dataIndex){
- this.rewardInfo[index].data[dataIndex].name = this.rechargeType[key].label;
- this.rewardInfo[index].data[dataIndex].type = this.typeArr[key];
- if(key == 0){
- this.rewardInfo[index].data[dataIndex].data = [];
- } else {
- if(Array.isArray(this.rewardInfo[index].data[dataIndex].data)){
- this.rewardInfo[index].data[dataIndex].data = 0;
- }
- }
- },
- // 更改奖励内容类型
- beupdateType(key,index,dataIndex){
- this.berewardInfo[index].data[dataIndex].name = this.rechargeType[key].label;
- this.berewardInfo[index].data[dataIndex].type = this.typeArr[key];
- if(key == 0){
- this.berewardInfo[index].data[dataIndex].data = [];
- } else {
- if(Array.isArray(this.berewardInfo[index].data[dataIndex].data)){
- this.berewardInfo[index].data[dataIndex].data = 0;
- }
- }
- },
- // 保存
- submitForm(){
- this.$refs['formData'].validate((valid) => {
- if (valid) {
- let text = this.validatorForm();
- if(text){
- this.$message.error(text);
- return;
- }
- if(!this.formData.id){
- if(this.formData.start_time > this.formData.end_time){
- this.$message.error('开始时间只能结束时间之后');
- return;
- }
- }
- this.$set(this.formData,'reward_info',this.rewardInfo);
- this.$set(this.formData,'be_reward_info',this.berewardInfo);
- //this.subLoading = true;
- request({
- params: {
- r: 'recommen/default/edit',
- },
- method: 'post',
- data: this.formData
- }).then(res => {
- console.info(res);
- this.subLoading = false;
- if(res.data.code == 0){
- this.$message.success("保存成功");
- navigateTo({
- r: "recommen/default/index"
- })
- } else {
- this.$message.error(res.data.msg);
- }
- })
- }
- });
- },
- },
- })
- </script>
- <style>
- .el-table_1_column_1 .cell{
- display: flex;
- align-items: center;
- }
- </style>
|