add.vue 6.4 KB
<template>
  <div class="box">
    <div class="content">
      <div class="title">{{title}}</div>
      <el-scrollbar class="form-box">
        <glsx-combi-form
          class="from"
          ref="formRef"
          :isEdit="true"
          :isBlock="true"
          :formObj="configForm"
          :formData="formData"
          :formRules="rule"
        >
          <div
            slot="cardCover"
            class="edit-tips"
          >图片大小10M</div>
          <template #endTimeType>
            <div
              v-if="configForm.endTimeType == 1"
              class="item-box"
            >
              <el-date-picker
                v-model="configForm.endTime"
                type="datetime"
                placeholder="选择日期时间"
                :picker-options="afterRangePickerOptions"
                value-format="yyyy-MM-dd HH:mm:ss"
                class="end-time"
              >
              </el-date-picker>
            </div>
          </template>
          <template #winningTime>
            <el-date-picker
              v-model="configForm.winningTime"
              type="datetime"
              placeholder="选择日期时间"
              :picker-options="afterRangePickerOptions"
              value-format="yyyy-MM-dd HH:mm:ss"
              class="end-time"
            >
            </el-date-picker>
          </template>
          <template #groupType>
            <div
              v-if="configForm.groupType == 1"
              class="item-box"
            >
              <div class="label">群聊列表:</div>
              <el-select
                v-model="configForm.groupList"
                multiple
                placeholder="请选择"
                filterable
                multiple-limit="10"
                class="options"
                collapse-tags
              >
                <el-option
                  v-for="item in groupList"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                >
                </el-option>
              </el-select>
            </div>
          </template>
          <template #prizeId>
            <prize-box
              :form="configForm"
              @choose="choose"
              ref="prizeRef"
            />
          </template>
        </glsx-combi-form>
      </el-scrollbar>
    </div>
    <GLFooter>
      <el-button
        @click="$router.go(-1)"
        size="medium"
      >取消</el-button>
      <el-button
        type="primary"
        @click="handleConfirm"
        size="medium"
      >确定</el-button>
    </GLFooter>
  </div>
</template>

<script type='text/ecmascript-6'>
import { formData, rule, afterRangePickerOptions } from './addJS/add.js'
import PrizeBox from './components/PrizeBox.vue'

export default {
  components: { PrizeBox },
  name: '',
  data () {
    return {
      afterRangePickerOptions,
      title: this.$route.query.$title,
      configForm: {
        type: 1,
        description: '',
        merchantId: '',
        // 44212575
        cardTitle: '',
        cardCover: '',
        maxNumber: 9,
        winningNumber: 0,
        endTimeType: 0,
        endTime: '',
        winningTime: '',
        groupType: 0,
        groupList: [],
        prizeId: '',
        prizeType: ''
      },
      rule: rule(this),
      formData: formData(this),
      groupList: [],
    }
  },

  watch: {
    'configForm.merchantId' (n) {
      this.$refs.prizeRef.reset()
      this.configForm.groupList = []
      this.choose({
        prizeId: '',
        prizeType: ''
      })
    },
    'configForm.maxNumber' (n) {
      this.configForm.winningNumber = 0
      this.formData.find(e => e.name == 'winningNumber').optionList.map(i => {
        i.isDisabled = i.optionId > n
      })
    },
    'configForm.groupType' (n) {
      if (n == 1 && !this.configForm.merchantId) {
        this.configForm.groupType = 0
        this.showError()
      }
    }
  },
  computed: {
    formRef () {
      return this.$refs.formRef.$refs.formRef
    }
  },
  mounted () {
  },
  methods: {
    showError (message) {
      this.$message.error(message || '请先选择所属渠道!')
    },
    async getMerchantList (merchantName = '') {
      this.$loading()
      try {
        const { list } = await this.$apis.redenvelope.getRedEnvelopeMerchantList({
          currentPage: 1,
          merchantName,
          pageSize: 100
        }),
          data = []
        list && list.map(e => {
          data.push({
            confId: e.merchantNo,
            confName: e.merchantName,
          })
        })
        this.formData.find(e => e.name == 'merchantId').optionList = data
        this.$loading().close()
      } catch (error) {
        console.log(error)
        this.$loading().close()
      }

    },
    choose ({ prizeId, prizeType }) {
      this.configForm.prizeId = prizeId
      this.configForm.prizeType = prizeType
      this.formRef.clearValidate('prizeId')
    },
    handleConfirm () {
      this.formRef.validate(valid => {
        console.log(valid)
      })
    },

  }
}
</script>

<style scoped lang='scss'>
.box {
  position: absolute;
  width: 100%;
  height: calc(100vh - 48px);
  top: 0;
  left: 0;
  .content {
    height: calc(100% - 88px);
    background-color: #fff;
    border-radius: 0 4px 4px 4px;
    margin: 16px;
    .form-box {
      width: 100%;
      height: calc(100% - 59px);
      box-sizing: border-box;
      .from {
        margin-top: 30px;
        /deep/.activity-img {
          width: 104px;
          height: 104px;
        }
        /deep/.muti-imgs {
          .img-w-h,
          .img-btns {
            width: 106px;
            height: 106px;
          }
        }
      }
      /deep/.el-scrollbar__wrap {
        &::-webkit-scrollbar {
          width: 0;
          height: 0;
          color: transparent;
        }
      }
    }
  }
  .title {
    font-weight: 500;
    font-size: 16px;
    color: #333333;
    line-height: 28px;
    padding: 15px 20px;
    border-bottom: 1px solid #e5e5e5;
    background-color: #fff;
  }
  .edit-tips {
    font-size: 14px;
    color: #999999;
  }
  .item-box {
    width: 480px;
    height: 52px;
    background: #f9f9f9;
    display: flex;
    align-items: center;
    padding-left: 20px;
    box-sizing: border-box;
    .end-time,
    .options {
      width: 284px;
      /deep/.el-input {
        width: 100% !important;
      }
      /deep/.el-tag--info {
        max-width: 50%;
      }
    }
  }
}
</style>