MrShi
7 小时以前 41115bb4b6d0161ff6d2c15ef6b3d5386a14ac9c
admin/src/components/business/OperaCouponWindow.vue
@@ -6,7 +6,7 @@
      :confirm-working="isWorking"
      @confirm="confirm"
  >
    <el-form :model="form" ref="form" :rules="rules" label-width="120px" label-suffix=":" inline>
    <el-form :model="form" ref="form" :rules="rules" label-width="120px" label-suffix=":" >
      <p class="tip-header" >基本属性</p>
      <el-form-item label="优惠券名称" prop="name">
        <el-input v-model="form.name" placeholder="请输入优惠券名称" :maxlength="12" v-trim/>
@@ -38,14 +38,12 @@
        <el-input type="textarea" v-model="form.info" placeholder="请输入优惠券说明" maxlength="500"  v-trim/>
      </el-form-item>
      <p class="tip-header" >使用限制</p>
      <el-form-item label="有效期" prop="useType">
        <el-radio-group v-model="form.useType">
      <el-form-item label="有效期" prop="getDate">
        <el-radio-group v-model="form.useType" @change="changeApplyType">
          <el-radio :label="0">固定时段</el-radio>
          <el-radio :label="1">固定时长</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="使用时段" prop="getDate" v-if="form.useType===0">
        <div class="date-style">
        <div class="date-style" v-if="form.useType===0">
          <el-date-picker
              v-model="getDate"
              type="datetimerange"
@@ -57,9 +55,7 @@
              @change="selectDate"
          ></el-date-picker>
        </div>
      </el-form-item>
      <el-form-item label="固定时长" prop="validDays" v-if="form.useType===1">
        <div class="coupon-rule">
        <div class="coupon-rule" v-if="form.useType===1">
          <div class="discrep">领劵后</div>
          <el-input
              v-model="form.validDays"
@@ -72,13 +68,22 @@
        </div>
      </el-form-item>
      <el-form-item label="适用对象" prop="applyType">
        <el-radio-group v-model="form.applyType">
        <el-radio-group v-model="form.applyType" @change="changeApplyType">
          <el-radio :label="0">全场通用</el-radio>
          <el-radio :label="1">按品类</el-radio>
          <el-radio :label="2">指定商品</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item v-if="form.applyType===1" label="选择品类" prop="applyCateIdList" >
      <el-form-item label="选择品类"   prop="applyTypeRule" v-if="form.applyType===1">
          <el-select style="margin-left:10px;width: 300px;" v-model="form.applyCateIdList"  placeholder="请选择商品分类,支持多选" filterable multiple clearable >
            <el-option  v-for="item in categorys" :key="'optCate'+item.id"  :label="item.name"  :value="item.id">  </el-option>
          </el-select>
      </el-form-item>
      <el-form-item label="选中商品" prop="applyTypeRule"  v-if="form.applyType===2">
          <span style="font-size: 12px;color: #216EEE"   @click="selectGoods">已指定【 {{applyDataList.length}} 】件商品</span>
          <el-button style="margin-left:30px;display: inline-block;width: 80px;" type="primary"  @click="selectGoods">去选择 </el-button>
      </el-form-item>
<!--      <el-form-item v-if="form.applyType===1" label="选择品类" prop="applyCateIdList" >
        <el-select v-model="form.applyCateIdList"  placeholder="请选择商品分类,支持多选" filterable multiple clearable >
          <el-option  v-for="item in categorys" :key="'optCate'+item.id"  :label="item.name"  :value="item.id">  </el-option>
        </el-select>
@@ -86,11 +91,11 @@
      <el-form-item v-if="form.applyType===2" label="选择商品" prop="applyIdList" style="display: flex">
          <span style="font-size: 12px;color: #216EEE"   @click="selectGoods">已指定【 {{applyDataList.length}} 】件商品</span>
        <el-button style="margin-left:30px;display: inline-block;width: 80px;" type="primary"  @click="selectGoods">去选择 </el-button>
      </el-form-item>
      </el-form-item>-->
      <p class="tip-header" >发放规则</p>
      <el-form-item label="发放总量" prop="num">
        <div class="num-style">
          <el-input-number  v-model="form.num" :controls="false" :min="0" :max="99999" placeholder="请输入发放总量(0~99999)" v-trim></el-input-number>
          <el-input   v-model="form.num" type="number" :controls="false" :min="0" :max="99999" placeholder="请输入发放总量(0~99999)" v-trim></el-input >
        </div>
        <p class="tip-warn" style="margin-bottom: 1px;"><i class="el-icon-warning"></i>提醒:发放总量为0表示不限制</p>
      </el-form-item>
@@ -123,16 +128,33 @@
      }
    }
    const getDateRules = (rule, value, callback) => {
      if (!this.form.startDate) {
      if (!this.form.useType < 0) {
        callback(new Error('请选择有效期'))
      } else if (this.form.useType == 1 && !this.form.validDays) {
        callback(new Error('请输入固定时长天数'))
      } else if (this.form.useType == 0 && !this.form.startDate) {
        callback(new Error('请选择开始时间'))
      } else if (!this.form.endDate) {
      } else if (this.form.useType == 0 && !this.form.endDate) {
        callback(new Error('请输入结束时间'))
      } else {
        callback()
      }
    }
    const getApplyTypeRule = (rule, value, callback) => {
      if (!this.form.applyType < 0) {
        callback(new Error('请选择适用范围'))
      } else if (this.form.applyType == 1 && (!this.form.applyCateIdList  || !this.form.applyCateIdList.length)) {
        callback(new Error('请选择使用品类'))
      } else if (this.form.applyType == 2 && (!this.form.applyIdList  || !this.form.applyIdList.length)) {
        callback(new Error('请选择指定商品'))
      } else {
        callback()
      }
    }
    const numRule = (rule, value, callBack) => {
      if (value < 0) {
      if (value ==='') {
        callBack(new Error())
      } else if (value < 0) {
        callBack(new Error())
      } else {
        callBack()
@@ -155,6 +177,7 @@
        applyCateIdList: [],
        type: 0,
        limitPrice: '',
        maxPrice:'',
        price: '',
        startDate: '',
        endDate: '',
@@ -163,7 +186,7 @@
        getMethod: '',
        integral: '',
        status: '',
        num: '',
        num: 0,
        info: ''
      },
      shops: [],
@@ -187,16 +210,16 @@
        ],
        num: [
          { required: true, validator: numRule, message: '请输入发放总数', tigger: 'blur' }
        ]
        ],
        /* integral: [
          { required: true, validator: numRule, message: '请输入兑换条件', tigger: 'blur' }
        ], */
        // validDays: [
        //   { required: true, message: '请输入可用时间', tigger: 'blur' }
        // ],
        // getDate: [
        //   { required: true, validator: getDateRules, tigger: 'change' }
        // ],
        getDate: [
          { required: true, validator: getDateRules }
        ],
        applyTypeRule: [
          { required: true, validator: getApplyTypeRule }
        ]
        // shopId: [
        //   { required: true, validator: numRule, message: '请选择关联店铺', tigger: 'change' }
        // ]
@@ -231,6 +254,9 @@
        this.applyDataList = res || []
      })
    },
    changeApplyType(){
      this.$refs.form.clearValidate()
    },
    doSelect (rows) {
      console.log(rows, this.applyDataList)
      this.applyDataList = []
@@ -241,6 +267,7 @@
          this.form.applyIdList.push(item.id)
        })
      }
      this.$refs.form.clearValidate();
    },
    open (title, target, type) {
      this.showGoods = false
@@ -250,6 +277,8 @@
      this.getDate = []
      this.form.startDate = ''
      this.form.endDate = ''
      this.form.validDays=''
      this.form.maxPrice =''
      this.applyDataList = []
      this.form.applyIdList = []
      this.form.applyCateIdList = []
@@ -258,7 +287,7 @@
      this.form.price = null
      this.form.startDate = null
      this.form.endDate = null
      this.form.num = 1
      this.form.num = 0
      // 新建
      if (target == null) {
        this.$nextTick(() => {
@@ -273,7 +302,9 @@
        for (const key in this.form) {
          this.form[key] = target[key]
        }
        this.getDate = [target.startDate, target.endDate]
        if (target.startDate && target.endDate) {
          this.getDate = [target.startDate, target.endDate]
        }
        if (this.form.applyType === 1) {
          this.form.applyCateIdList = []
          var ta = this.form.applyIds.split(',')