couponAdd.vue 15.1 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518
<template>
  <div class="edit_add_page">
    <div class="content">
      <el-form ref="form" :model="form" :rules="rules" label-width="150px">
        <h2>基础信息</h2>
        <br>
        <el-form-item label="活动名称:" prop="activityName">
          <el-input v-model="form.activityName" placeholder="请输入活动名称" :disabled="unStart" />
        </el-form-item>

        <el-form-item label="活动介绍:"  prop="activityIntroduce">
          <el-input
            v-model="form.activityIntroduce"
            type="textarea"
            placeholder="请输入活动介绍"
            :disabled="unStart"
            style="width: 400px"
          />
        </el-form-item>

        <el-form-item label="报名时间:"  prop="date2">
          <el-date-picker
            v-model="date2"
            type="datetimerange"
            range-separator="至"
            start-placeholder="开始时间"
            end-placeholder="结束时间"
            value-format="yyyy-MM-dd HH:mm:ss"
          />
          <p class="timeInfo">报名时间不能交叉且报名时间不能大于活动时间</p>
        </el-form-item>

        <el-form-item label="活动时间:"  prop="date1">
          <el-date-picker
            v-model="date1"
            type="datetimerange"
            range-separator="至"
            start-placeholder="开始时间"
            end-placeholder="结束时间"
            value-format="yyyy-MM-dd HH:mm:ss"
            :disabled="applyEnd"
          />
          <p class="timeInfo">平台活动时间不能交叉并且活动时间不能小于报名时间</p>
        </el-form-item>

        <el-form-item label="活动保证金:">
          <el-radio-group v-model="form.ifBond">
            <el-radio :label="1" :disabled="unStart">需要</el-radio>
            <el-radio :label="0" :disabled="unStart">不需要</el-radio>
          </el-radio-group>
        </el-form-item>

        <el-form-item v-if="form.ifBond === 1" label="保证金金额:">
          <el-input v-model="form.bondMoney" placeholder="请输入活动保证金金额" :disabled="unStart" />
        </el-form-item>

        <!-- <el-form-item label="活动标签">
          <el-input v-model="form.activityLabel" placeholder="请输入活动标签" :disabled="unStart" />
        </el-form-item> -->

        <h2>优惠规则</h2>
        <br>
        <el-form-item label="使用门槛:">
          满<el-input v-model="form.threshold" :disabled="unStart" style="width: 100px;margin: 0 12px;" />元
        </el-form-item>
        <el-form-item label="优惠方式:">
          <el-radio-group v-model="form.discountMode">
            <el-radio :label="1" :disabled="unStart">满减</el-radio>
            <el-radio :label="2" :disabled="unStart">折扣</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="优惠内容:">
          <div v-if="form.discountMode === 1">
            减<el-input v-model="form.couponContent" :disabled="unStart" style="width: 100px;margin: 0 12px;" />元
          </div>
          <div v-if="form.discountMode === 2">
            <el-input v-model="form.couponContent" :disabled="unStart" style="width: 100px;margin-right: 12px;" />折
          </div>
        </el-form-item>

        <el-form-item label="发放数量:">
          <el-input v-model="form.number" :disabled="unStart" style="width: 100px;margin-right: 12px;" />张
        </el-form-item>
        <el-form-item label="是否限领:">
          <el-radio-group v-model="form.receiveType">
            <el-radio :label="1" :disabled="unStart">不限制</el-radio>
            <el-radio :label="2" :disabled="unStart">限制领取</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item v-if="form.receiveType === 2" label="限制领取次数:">
          <el-input v-model="form.frequency" type="number" :disabled="unStart" style="width: 100px;margin-right: 12px;" />次
        </el-form-item>
        <el-form-item label="是否开启积分兑换:">
          <el-radio-group v-model="form.ifCredit">
            <el-radio :label="1" :disabled="unStart">是</el-radio>
            <el-radio :label="0" :disabled="unStart">否</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item v-if="form.ifCredit" label="所需积分:">
          <el-input v-model="form.credit" type="number" :disabled="unStart" style="width: 150px" /> 分
        </el-form-item>
        <el-form-item label="可用范围:">
          <el-radio-group v-model="form.applyType" @change="changeType">
            <el-radio :label="1" :disabled="unStart">全部</el-radio>
            <el-radio :label="2" :disabled="unStart">选择类别</el-radio>
            <el-select v-if="form.applyType === 2" v-model="form.applyCategory" placeholder="请选择">
              <el-option
                v-for="item in classList"
                :key="item.classifyId"
                :label="item.classifyName"
                :value="item.classifyId"
              />
            </el-select>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="微信卡券:">
          <el-checkbox v-model="form.syncCard" :true-label="1" :false-label="0" :disabled="unStart">领取后可同步微信卡包</el-checkbox>
        </el-form-item>
        <div v-show="form.syncCard === 1">
          <h2>卡券同步设置</h2>
          <br>
          <!--          <el-form-item label="券跳转配置:">-->
          <!--            <div>券跳转路径</div>-->
          <!--            <el-input v-model="form.appletAppId" type="text" :disabled="unStart" placeholder="请输入券跳转路径" />-->
          <!--          </el-form-item>-->
          <el-form-item label="卡券标题:">
            <el-input v-model="form.cardTitle" maxlength="21" show-word-limit type="text" :disabled="isEdit" placeholder="请输入卡券标题" />
          </el-form-item>
          <el-form-item label="券主题颜色:">
            <!--            <el-color-picker v-model="form.color" />-->
            <el-select v-model="form.cardColor" class="color-select" placeholder="请选择" :disabled="isEdit">
              <el-option
                v-for="item in bgColors"
                :key="item.value"
                :label="item.value"
                :value="item.value"
              >
                <span class="color-box" :style="{'width':'30px','height':'30px','float':'left','backgroundColor': item.label}" />
                <span class="color-val" :style="{'float':'right'}">{{ item.value }}</span>
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="使用需知:">
            <el-input
              v-model="form.cardNotice"
              maxlength="15"
              show-word-limit
              type="textarea"
              placeholder="使用需知"
              :disabled="isEdit"
              style="width: 400px;"
            />
          </el-form-item>
        </div>
      </el-form>
    </div>
    <div class="footer">
      <div class="btn_list">
        <span @click="cancel" class="buttonHover"
              style="color: #606266;border: 1px solid #dddfe5;background-color: #fff;">取消</span>
        <span @click="save" style="background-color: #3F9B6A;color: #fff">保存</span>
      </div>
    </div>
  </div>
</template>

<script>
import { activeAdd, activeUpdate, activeGetById } from '@/api/active'
import { commdityClassGetAll } from '@/api/renovation';
// import shopList from '@/views/active/couponlist/component/shopList';
import {
} from '@/api/active/active_seckill.js'
import Form from './module'
export default {
  components: {
    // shopList
  },
  props: {
    activityForm: {
      type: Object,
      default: () => {}
    },
    isEdit: {
      type: Boolean,
      default: true
    }
  },
  data () {
    return {
      form: new Form(),
      date1: [], // 活动时间
      date2: [], // 报名时间
      type: false,
      classList: [],
      formParams: {
        page: 1,
        pageSize: 100
      },
      classifyId: null,
      shopListShow: false,
      shopList: [],
      bgColors: [{
        value: 'Color010',
        label: '#638359'
      }, {
        value: 'Color020',
        label: '#2C9F67'
      }, {
        value: 'Color030',
        label: '#509FC9'
      }, {
        value: 'Color040',
        label: '#5885CF'
      }, {
        value: 'Color050',
        label: '#9062C0'
      }, {
        value: 'Color060',
        label: '#D09A45'
      }, {
        value: 'Color070',
        label: '#E48138'
      }, {
        value: 'Color080',
        label: '#EE903C'
      }, {
        value: 'Color090',
        label: '#DD6549'
      }, {
        value: 'Color100',
        label: '#CC463D'
      }],
      rules: {
        activityName: [{
          required: true,
          message: '请输入活动名称',
          trigger: 'blur'
        }],
        activityIntroduce:[{
          required: true,
          message: '请输入活动介绍',
          trigger: 'blur'
        }],
      },
    }
  },
  computed: {
    // 其他修改
    unStart () {
      const t = this.isEdit ? this.activityForm : null
      return t && !(t.state === 0)
    },
    // 时间修改
    applyEnd () {
      const t = this.isEdit ? this.activityForm : null
      return t && (t.state === 3 || t.state === 4)
    }
  },
  watch: {
    isEdit: {
      handler (nVal, oVal) {
        if (nVal) {
          this.getDetails()
        } else {
          this.reset()
        }
      }
    },
    activityForm: {
      handler (nVal, oVal) {
        if (nVal) {
          this.getDetails()
        }
      }
    }
  },
  mounted () {
    this.getAll(this.formParams)
    if (this.isEdit) { // 初始化watch无法监听isEdit,手动获取数据
      this.getDetails()
    }
  },
  methods: {
    // 获取类别
    async getAll (formParams) {
      const res = await commdityClassGetAll(formParams)
      this.classList = res.data.list
    },
    async getDetails () {
      const res = await activeGetById({ activityId: this.activityForm.activityId })
      if (JSON.stringify(res.data) !== '{}') {
        this.form = res.data
        this.date1 = [res.data.activityStartTime, res.data.activityEndTime] // 活动时间
        this.date2 = [res.data.signStartTime, res.data.signEndTime] // 报名时间
      }
    },
    showShopLst () {
      this.shopListShow = !this.shopListShow
    },
    // 商家
    cleanShopList () {
      this.shopListShow = false
    },
    cancel () {
      this.$emit('cancel')
      this.form = new Form()
      this.date1 = [] // 活动时间
      this.date2 = [] // 报名时间
    },
    refersh () { this.$emit('refersh') },
    save () {
      const params = Object.assign({}, this.form, {
        activityStartTime: this.date1[0] || '',
        activityEndTime: this.date1[1] || '',
        signStartTime: this.date2[0] || '',
        signEndTime: this.date2[1] || '',
        bondMoney: this.form.bondMoney * 1
      })
      // if (this.shopList.length) {
      //   this.shopList.forEach((item) => {
      //     this.form.shopIdList.push(item.shopId)
      //   })
      // }
      console.log(this.form.shopIdList, 'shopIdList')
      const errArr = []
      if (params.activityName === '') {
        errArr.push('请输入活动名称')
      }
      if (params.activityIntroduce === '') {
        errArr.push('请输入活动介绍')
      }
      if (this.date2.length === 0) {
        errArr.push('请选择报名时间')
      }
      if (this.date1.length === 0) {
        errArr.push('请选择活动时间')
      }
      if (errArr.length !== 0) {
        errArr.forEach((item, index) => {
          this.$message({
            type: 'error',
            message: item,
            offset: (index) * 40 + 20,
            duration: 5000
          })
        })
        return
      }
      if (this.isEdit) {
        return activeUpdate(
          Object.assign(params, { activityId: this.activityForm.activityId })
        ).then(res => {
          if (res.code === '') {
            this.$message.success('修改成功')
            this.reset()
            this.refersh()
          }
        })
      }
      return activeAdd(params).then(res => {
        if (res.code === '') {
          this.$message.success('新增成功')
          this.reset()
          this.refersh()
        }
      })
    },
    reset () {
      this.form = new Form()
      this.list = [{ fullMoney: '', reduceMoney: '' }]
      this.date1 = []
      this.date2 = []
    },
    selectShop (val) {
      this.shopList = val
    },
    changeType () {
    }
  }
}
</script>

<style lang='scss' scoped>
.edit_add_page {
  h2 {
    font-size: 24px;
    font-weight: 500;
    position: relative;
    &::before {
      content: "";
      height: 24px;
      width: 4px;
      background-color: #3f9b6a;
      position: absolute;
      left: -10px;
      top: 2px;
      display: block;
    }
  }
  .content {
    background-color: #fff;
    padding: 0 50px 20px;
    overflow: hidden;
    .el-form {
      .el-form-item {
        label.el-form-item__label {
          font-size: 16px !important;
          color: red !important;
        }
      }
    }
    .photo {
      padding: 70px 100px;
      .avatar-uploader {
        width: 180px;
        .el-icon-plus,
        img {
          width: 180px;
          height: 180px;
          line-height: 180px;
          border: 1px #bbb solid;
          border-radius: 4px 4px 0px 4px;
          margin-bottom: 10px;
          text-align: center;
        }
        img {
          border: none;
        }
      }
    }
  }
  .footer{
    font-size: 24px;
    position: relative;
    border-top: 1px solid #e0e5eb;
    .btn_list {
      position: absolute;
      right: 0;
      top: 0;

      span {
        padding: 0;
        margin: 0;
        width: 100px;
        height:32px;
        line-height:32px;
        text-align: center;
        display: inline-block;
        font-size: 16px;
        border-radius: 4px;
        box-sizing: border-box;
        &:hover {
          cursor: pointer;
        }
        &:nth-child(1) {
          background: rgba(255, 255, 255, 1);
          order: 1px solid rgba(224, 229, 235, 1);
          margin-right: 20px;
          border: 1px solid rgba(224, 229, 235, 1);
        }
        &:nth-child(2) {
          background: #3f9b6a;
          color: #fff;
        }
      }
    }
  }
  .timeInfo {
    font-size: 12px;
    color: #999999;
  }
  .el-input{
    width: 400px;
  }
  .addShop {
    color: #3f9b6a;
    cursor: pointer;
  }
  .arrow {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-top: 1px solid #CCCCCC;
    border-right: 1px solid #CCCCCC;
  }
  .arrowUp {
    transform: rotate(-45deg);
  }

  .arrowDown {
    transform: rotate(135deg);
  }
  .selectShopBox {
    .leftTit {
      font-size: 14px;
      color: #666666;
      float: left;
      margin-right: 15px;
    }
    .rightBox {
      float: left;
      span {
        padding: 5px 8px;
        border: 1px solid #e1e1e1;
        color: #999999;
        font-size: 12px;
        margin-right: 10px;
      }
    }
  }
}
 .buttonHover:hover{
    color:#3f9b6a !important;
    border-color: #c5e1d2 !important;
    background-color: #ecf5f0 !important;
    outline: none;
  }
</style>