add.vue 9.9 KB
<template>
  <div class="new-tmp">
    <h2>新建活动模版</h2>
    <hr/>
    <div class="activity-wrap">
        <div class="activity-content"><glsx-combi-form
            ref="formRef"
            :isEdit="true"
            :isBlock="true"
            :formObj="configForm"
            :formData="formData"
            :formRules="rule"
        >
          <template #merchantId>
            <el-select
                v-model="configForm.merchantId"
                placeholder="请选择"
                filterable
                remote
                :remote-method="remoteMethod"
                v-reachbottom="onReachBottom"
                @focus="selectFocus"
                :loading="loading"
                :disabled="disabled"
                @change="change"
            >
              <el-option
                  v-for="item in merchantObj.data"
                  :key="item.confId"
                  :label="item.confName"
                  :value="item.confId"
              ></el-option>
              <template v-if="merchantObj.nothing">
                <div class="select-nothing">到底了!</div>
              </template>
            </el-select>
          </template>

          <template #pageTheme>
            <div class="page-theme">
              <el-form-item label="第一行" prop="theme1" >
                <el-input v-model="configForm.theme1" maxlength="5"  show-word-limit></el-input>
              </el-form-item>
              <el-form-item label="第二行" prop="theme2" >
                <el-input v-model="configForm.theme2"  maxlength="5"  show-word-limit></el-input>
              </el-form-item>
            </div>
          </template>

          <p
              slot="cardCover"
              class="cover-tips"
          >建议格式:高度88px,png</p>

          <template #activityRuleDes>
            <textBox style="width:45vw" @change="writeChange" ref="textBox" @forbid="forbidEdit"></textBox>
          </template>

          <template #physicalWinningCfg>
            <div class="physical-winning">
                <el-form-item
                    label="活动形式:"
                    prop="exchangeType"
                    class="m-t-20"
                >
                  <el-radio-group
                      v-model="configForm.exchangeType"
                      class="fit-width radio"
                  >
                    <el-radio :label="0">快递到家</el-radio>
                    <el-radio :label="1">到店核销</el-radio>
                  </el-radio-group>

                </el-form-item>
                <el-form-item label="填写信息:" prop="describeId" v-if="configForm.exchangeType == 0">
                  <el-checkbox-group v-model="configForm.describeId">
                    <el-checkbox v-for="(item,index) in expressList" :key="index" :label="item"><span>{{ item.describeMsg }}</span></el-checkbox>
                  </el-checkbox-group>
                </el-form-item>
            </div>
          </template>
        </glsx-combi-form></div>
        <div class="redEnvelope-bg">
          <img v-if="configForm.logo" :src="configForm.logo">
          <p v-html="configForm.theme1"></p>
          <p class="p2" v-html="configForm.theme2"></p>
        </div>
    </div>
    <GLFooter>
      <el-button @click="handleCancel">取消</el-button>
      <el-button type="primary" @click="handleSave">确定</el-button>
    </GLFooter>
  </div>
</template>

<script type="text/ecmascript-6">
import {getMerchantListMixin} from '@/mixins'
import textBox from '@/components/text-box'

export default {
  name: 'add',
  mixins: [getMerchantListMixin],
  props: {
    disabled: Boolean
  },
  components: {
    textBox
  },
  data() {
    return {
      merchantObj: {
        nothing: false,
        data: [],
        currentPage: 1,
        name: '',
        loading: false,
        total: 0
      },
      expressList:[],
      configForm: {
        templateName: '',
        merchantId: '',
        activityType: '0',
        theme1:'',
        theme2:'',
        logo: '',
        merchantName: '',
        pageTheme:'11',
        exchangeType: '',
        ruleDescribe:'',
        describeId: [],

      },
      rule: {
        templateName: [{required: true, message: '请输入模板名称', trigger: 'change'}],
        merchantId: [{required: true, message: '请选择所属渠道', trigger: 'change'}],
        activityType: [{required: true, message: '请选择活动形式', trigger: 'change'}],
        logo: [{required: true, message: '请上传卡片封面', trigger: 'change'}],
        pageTheme: [{required: true, message: '请输入页面主题'}],
        exchangeType: [{required: true, message: '请选择活动形式', trigger: 'change'}],
        describeId: [{required: true, message: '请选择填写信息', trigger: 'change'}]
      },
      formData: [
        {
          label: '模板名称',
          name: 'templateName',
          type: 'input',
          maxlength: 25,
          showLimit:true
        },
        {
          label: '所属渠道',
          type: 'select',
          name: 'merchantId',
          addHtml: 'merchantId'
        },
        {
          label: '活动形式',
          name: 'activityType',
          type: 'radio',
          optionList: [
            {text: '随机红包', id: '0'}
          ],
          optionId: 'id',
          optionLabel: 'text',
        },
        {
          label: '页面主题',
          name: 'pageTheme',
          addHtml: 'pageTheme'
        },
        {
          label: 'logo图片',
          name: 'logo',
          type: 'upload',
          width: '320px',
          limitSize: 10,
          maxPhotoNum: 1,
          suffixSlot: 'cardCover',
          handleUpload: async (e, file, targetItem) => {
            let loading = this.$loading({
              target: document.querySelector('.activity-img'),
            })
            try {
              const imgFile = e.target.result,
                  arrBase64 = imgFile.split(',')[1],
                  str = file.name.split('.'),
                  base64 = str.at(-1) + '@' + arrBase64,
                  res = await this.$apis.common.pictureUpload({file: base64, fileType: 'image'})
              if (res) {
                this.configForm[targetItem.name] = res
                this.formRef().validateField(targetItem.name)
                loading.close()
              } else throw '上传失败'
            } catch (error) {
              loading.close()
              this.$message(error)
            }
          }
        },
        {
          label: '活动规则描述',
          addHtml: 'activityRuleDes'
        },
        {
          label: '实物中奖配置',
          addHtml: 'physicalWinningCfg'
        }
      ],
    }
  },
  watch: {},
  mounted() {
    sessionStorage.setItem('returnFromAddPage', 'ActiveTemplateManagement')
    this.getExpressInfo()
  },
  methods: {
    getExpressInfo(){
      this.$apis.redenvelope.expressConfigList({}
      ).then(res => {
        this.expressList = res.map(item => ({'describeMsg':item.describeMsg,'describeId':item.describeId}))
      })
    },
    validateForm() {
      return new Promise((resolve, reject) => {
        this.formRef().validate((valid) => {
          if (valid) {
            resolve();
          } else {
            // reject(new Error('缺少必填内容'));
          }
        });
      });
    },
    writeChange(val) {
      this.configForm.ruleDescribe = val
    },
    change(id) {
      this.configForm.merchantName = ''
      if (id) {
        this.configForm.merchantName = this.merchantObj.data.find(e => e.confId == id).confName
      }
    },
    formRef() {
      return this.$refs.formRef.$refs.formRef
    },
    handleCancel() {
      this.$router.back()
    },
    handleSave() {
      this.validateForm().then(() => {
        const {describeId,pageTheme,...params} = this.configForm
        if (!params.theme1 && !params.theme2) return  this.$message.error('请填写页面主题');
        params.writeInfoList = [...describeId]
        this.$apis.redenvelope.newActivityTemplate(params).then(res => {
         if (res.code == 0){
           this.$message.success('新建活动模板成功');
           this.handleCancel()
         }else{
           this.$message.error(res.message);
         }
        })
      }).catch(error => {
        this.$message.error(error.message);
      });
    }

  },

}
</script>

<style scoped lang="scss">
.new-tmp{
  background: #fff;
  h2{
    padding: 10px 0 0 16px;
  }
  .activity-wrap{
    display: flex;
    .cover-tips{
      position: absolute;
      color: #999999;
      left: 90px;
      top: 60px;
    }
    .activity-content {
      width: 70%;
      padding: 20px;
      .page-theme{
        .el-form-item{
          display: flex;
          width: 340px;
          /deep/.el-form-item__label{
            margin-right: 8px;
          }
        }
      }
      .physical-winning {
        background: #F9F9F9;
        width: 400px;
        padding: 10px;
        .el-form-item{
          /deep/.el-form-item__label{
            width: auto;
          }
        }
      }
    }
    .redEnvelope-bg{
      position: relative;
      width: 500px;
      height: 800px;
      background-image: url("./../../../../assets/redEnvelope-bg.png");
      background-repeat: no-repeat;
      img{
        position: absolute;
        width: 98px;
        height: 33px;
        top: 55px;
        left:28px;
      }
      p{
        position: absolute;
        font-family: SourceHanSansCN-Heavy;
        font-weight: 900;
        font-size: 35.5px;
        letter-spacing: 0;
        text-align: center;
        background: linear-gradient(to bottom, #FFFFFF, #FFD58E); /* 设置背景渐变 */
        -webkit-background-clip: text; /* Safari/Chrome */
        -webkit-text-fill-color: transparent; /* Safari/Chrome */
        color: transparent; /* Firefox/Opera */
        text-shadow: 0 1px 3px #ffe9e9de;
        top: 100px;
        left: 45px;
      }
      .p2{
        top: 150px;
      }
    }
  }

}

</style>