add.vue 15.4 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.trim="configForm.theme1" maxlength="5"  show-word-limit></el-input>
              </el-form-item>
              <el-form-item label="第二行" prop="theme2" >
                <el-input v-model.trim="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>
            <el-form-item >
              <textBox style="width:45vw" @change="writeChange" ref="textBox" @forbid="forbidEdit"></textBox>
            </el-form-item>

          </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 class="checkboxs-setting" 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'}],
        ruleDescribe:[{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: '活动规则描述',
          name: 'ruleDescribe',
          addHtml: 'activityRuleDes'
        },
        {
          label: '实物中奖配置',
          addHtml: 'physicalWinningCfg'
        }
      ],
    }
  },
  watch: {},
  mounted() {
    sessionStorage.setItem('returnFromAddPage', 'ActiveTemplateManagement')
    this.getExpressInfo()
    this.handleEditorReady()
  },
  methods: {
    handleEditorReady() {
      let defaultText = `一、活动期间:2024年1月20日~2024年2月29日。<br/>
                         二、活动范围:中海康城花园一期、中信领航里程花园小区福利群内客户。<br/>
三、活动产品:实物奖品 / 现金红包。<br/>
四、参与方式:打开微信,领取会员卡后,点击随机红包领取页即可领取。<br/>
五、参与限制:本次活动需授权手机号和微信昵称方可参与,仅限指定客户群内消费者参与,每个微信号仅可参与一次,实物奖品需提交资料后,前往物业管理处领取,现金红包在中奖后,金额会在24小时内到账。
现金红包中奖后请于24小时内领取,超过24小时逾期不领取,视为视为客户自愿放弃现金红包。<br/>
六、奖品内容:<br/>
本次活动总共2000+份礼品,综合中奖率99.99%,具体金额及对应数量如下:<br/>
1、特等奖:松下直发器(中奖后需前往物业管理处领取);<br/>
2、一等奖:韩国大宇多功能空气炸锅(中奖后需前往物业管理处领取);<br/>
3、二等奖:皮卡丘加湿器(中奖后需前往物业管理处领取);<br/>
4、三等奖:摩飞电蒸笼 或 B.Duck 儿童相机(中奖后需前往物业管理处领取);<br/>
5、四等奖:精选年货礼盒(中奖后需前往物业管理处领取);<br/>
6、五等奖:18.88元微信红包;<br/>
7、六等奖:8.88元微信红包;<br/>
8、七等奖:1.68元微信红包;<br/>
9、八等奖:0.68元微信红包;<br/>
七、奖品发放与领取<br/>
1、微信现金红包中奖消费者根据页面提示领取完成后红包将以转账的形式发送至您的微信账户。消费者成功领取后,现金红包金额将自动存入消费者的微信零钱中。逾期不领取的,视为消费者自愿放弃现金红包,系统将自动将该红包金额退回到活动方账户,且活动方不对此作任何形式的补偿。<br/>
2、若微信红包发放或领取过程中出现被微信平台系统自动拦截或因其他非活动方原因导致消费者无法领取微信红包的(包括但不限于因消费者微信账号活跃度低;朋友圈互动、好友关系较少;有过不正当手段刷奖记录;红包领取次数超过上限;未绑定或绑定的银行卡无法接收红包金额等),均不视为活动方的过错,且活动方将不作任何形式的补偿。如遇突发情况(如服务器异常等)导致红包的发放或领取失败,活动方将视具体情况为中奖的消费者安排补发,具体请留意并按照微信平台的提示进行操作领取。<br/>
八、注意事项<br/>
1、请在参加本活动前仔细阅读本规则的各项条款,如果消费者参加了本活动,则视为消费者已理解并同意本规则中的所有条款。<br/>
2、如消费者中奖后未按照活动提示操作或未在活动期间和/或兑奖期间内参与活动、进行奖品的抽取、领取、兑换的,均视为消费者自愿放弃参与活动和/或领取奖品,奖项自动失效,活动方不作任何形式的补偿。<br/>
3、本活动期间和/或兑奖期间内,如发现消费者存在违法违规行为(包括但不限于恶意套取资金、使用外挂或机器作弊、虚假交易,或其他违反诚实信用原则等行为),或在购买产品后的奖品抽取、领取、兑换中使用任何不正当的手段(包括但不限于软件作弊、通过系统漏洞、利用黑客工具等)获取中奖机会的,则活动方有权采取取消该消费者参加本活动的资格、取消该消费者领取奖品的资格、收回已发放的奖品、追究该消费者法律责任等一项或多项措施。如因消费者原因导致活动方或其他第三方遭受任何处罚或产生损失的,由消费者承担。<br/>
4、消费者需自行承担在参加本次促销活动中发生的费用,包括网络服务费、电话费、交通费及其他费用。<br/>
5、如遇不可抗力事件,包括但不限于地震、台风、洪水、火灾、战争、罢工、暴动、政府行为、疫情等,活动方有权取消、修改、暂停、提前终止本次活动且不作任何形式的补偿。<br/>
6、在法律允许的范围内,活动方有权对本活动规则进行调整,具体以调整后的活动规则为准。调整后的活动规则将公布在活动方的微信小程序上,公布后依法生效。如活动方调整活动规则后,消费者继续参与活动的,则视为消费者知悉并同意接受调整后的活动规则;如果消费者不接受上述活动规则的调整,可选择放弃参与变更规则后的活动。`
      // 确保编辑器已初始化
      this.$nextTick(() => {
        this.$refs.textBox.setEdit(defaultText);
      });
    },
    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,ruleDescribe,...params} = this.configForm
        // 页面主题判断
        if (!params.theme1) return  this.$message.error('请填写页面主题');
        // 判断富文本编辑器是不是只有空格(不改变ruleDescribe的值)
        const plainTextCheck = ruleDescribe.replace(/&nbsp;|<[^>]+>/g, ' ').replace(/\s+/g, ' ');
        if (plainTextCheck.trim() === '') {
          this.$message.error('活动规则描述不能只输入空格');
          return;
        }

        // 如果不是只有空格,使用原始的ruleDescribe
        params.ruleDescribe = ruleDescribe;
        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: 650px;
        padding: 10px;
        .el-form-item{
          /deep/.el-form-item__label{
            width: auto;
          }
        }
        /deep/ .checkboxs-setting{
          width:600px;
        }
      }
    }
    .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>