add.vue 10.8 KB
<template>
  <div class="sms-container">
    <div class="sms-content">
      <glsx-combi-form :isInline="false" class="glsx-combi-form" ref="baseInfoRef" labelWidth="154px" defaultWidth="432px" :formObj.sync="formObj" :formData="formData" :formRules="myRule">
        <template v-for="(item, index) in form_solt">
          <div :key="index" :slot="item.name">
            <el-switch v-model="formObj[item.attr].switch" :active-value="true" :inactive-value="false"></el-switch>
            <div style="position: relative" class="wrapper">
              <div class="topSet flex">
                <span>发送时间:积分到账</span>
                <div class="set-int">
                  <el-input class="intTime" v-model="formObj[item.attr].time" maxlength="4" oninput="if(value){value=value.replace(/[^\d]/g,'')} if(value<=0){value=''} if(value>1000){value=1000}" placeholder="请输入"></el-input>
                </div>
                <span>小时后,未提现或兑换发送</span>
              </div>
              <div class="sms-box">
                <div class="left">群发内容:</div>
                <div class="right">
                  <wTextarea maxlength="500" :value="formObj[item.attr].messageContext" :ref="item.attr" class="textarea" @updateText="updateText($event, item.attr)" :style="{ 'min-height': boxHeight + 'px' }"></wTextarea>
                  <div class="word-limit">
                    <span :class="[{ redColorText: formObj[item.attr].text.length > 500 }]">{{ formObj[item.attr].text.length || 0 }}</span>
                    /500
                  </div>
                  <div class="select-panel">
                    <div @click="handleSelectMessage($event, item.attr, '短链')" class="flex marl24">
                      <img src="@/images/link.png" class="link" />
                      <span class="">短链</span>
                    </div>
                    <div @click="handleSelectMessage($event, item.attr, '客户积分')" class="flex marl24">
                      <img src="@/images/jifen.png" class="link" />
                      <span class="">客户积分</span>
                    </div>
                    <div @click="handleSelectMessage($event, item.attr, '客户姓名')" class="flex">
                      <img src="@/images/username.png" class="link" />
                      <span class="">客户姓名</span>
                    </div>
                  </div>
                  <div class="showSmsModel">
                    <span>【{{ formObj.miniId }}】</span>
                    <span v-html="highText(formObj[item.attr].model)" v-if="formObj[item.attr].model"></span>
                    <span>拒收请回复R</span>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </template>
      </glsx-combi-form>
    </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 glsxCombiForm from '@/components/glsx-combi-form'
import wTextarea from './tag-textarea.vue'
const DJ_MINI_APPID = '车生活助手'
const MINI = [
  {
    confId: DJ_MINI_APPID,
    confName: '车生活助手'
  }
]
export default {
  name: 'add',
  props: {},
  components: {
    glsxCombiForm,
    wTextarea
  },
  data() {
    return {
      boxHeight: 178,
      myRule: {
        miniId: [{ required: true, message: '短信签名', trigger: 'change' }]
      },
      formObj: {
        miniId: DJ_MINI_APPID,
        message_first: {
          messageContext: '',
          switch: false,
          time: null,
          model: null,
          text: '',
          name: '短信一'
        },
        message_second: {
          messageContext: '',
          switch: false,
          time: null,
          model: null,
          text: '',
          name: '短信二'
        },
        message_three: {
          messageContext: '',
          switch: false,
          time: null,
          model: null,
          text: '',
          name: '短信三'
        }
      },
      formData: [
        {
          label: '短信签名',
          name: 'miniId',
          type: 'select',
          isDisabled: false,
          optionList: MINI,
          optionId: 'confId',
          optionLabel: 'confName',
          changeAttr: val => {}
        },
        {
          label: '短信一',
          name: 'smsFirst',
          addHtml: 'smsSlot1'
        },
        {
          label: '短信二',
          name: 'smsFirst',
          addHtml: 'smsSlot2'
        },
        {
          label: '短信三',
          name: 'smsFirst',
          addHtml: 'smsSlot3'
        }
      ],
      form_solt: [
        {
          name: 'smsSlot1',
          attr: 'message_first'
        },
        {
          name: 'smsSlot2',
          attr: 'message_second'
        },
        {
          name: 'smsSlot3',
          attr: 'message_three'
        }
      ]
    }
  },
  mounted() {},
  methods: {
    // 信息文案处理高亮和字数限制
    highText(title) {
      const shortLink = '#短链#',
        customerJf = '#客户积分#',
        customerName = '#客户姓名#'
      // 如果标题中包含,关键字就替换一下
      if (title.includes(shortLink)) {
        title = title.replaceAll(shortLink, '<font style="color:#5092FF !important;">' + shortLink + '</font>')
      }
      if (title.includes(customerJf)) {
        title = title.replaceAll(customerJf, '<font style="color:#5850ff !important;">' + customerJf + '</font>')
      }
      if (title.includes(customerName)) {
        title = title.replaceAll(customerName, '<font style="color:#5850ff !important;">' + customerName + '</font>')
      }
      if (title.length > 500) {
        title = title.substring(0, 500)
      }
      return title
    },
    // 获取标签文案
    subText(htm) {
      const cutImg = htm
        .replace(/<wise.+?>(.+?)(?:<\/wise>)/g, '$1')
        .replace(/&lt;/g, '<')
        .replace(/&gt;/g, '>')
        .replace(/&amp;/g, '&')
        .replace(/(\n|\s|&nbsp;)/g, '')
        .replace(/<br>/g, '\n')
        .replace(/<span>([\s\S]*?)<\/span>/g, '$1')
        .replace(/<div>([\s\S]*?)<\/div>/g, '$1')
      return cutImg
    },
    // 编辑器文案获取
    updateText(html, type) {
      const text = JSON.stringify(html)
      const linkText = JSON.parse(this.subText(text))
      if (html) {
        this.formObj[type].model = linkText
      } else {
        this.formObj[type].model = null
      }
      this.formObj[type].messageContext = html
      this.formObj[type].text = linkText
    },
    // 点击标签
    handleSelectMessage(e, type, textName) {
      const _refs = this.$refs[type][0]
      if (_refs.currentText.indexOf(`#${textName}#`) != -1) {
        return
      }
      _refs.addTag(`#${textName}#`)
      //   this.formObj[type].messageContext = _refs.currentText
    },
    // 提交
    handleSave() {
      const params = this.handlerParams()
      console.log(params)
    },
    handleCancel() {
      this.$router.back()
    },
    //处理提交参数
    handlerParams() {
      const _temp = this.$common.utils.deepClone(this.formObj)
      delete _temp.miniId
      let isHaveOpen = false,
        needCheckList = [],
        params = []
      // 筛选已打开的短信模块
      for (let k in _temp) {
        const target = _temp[k]
        if (target.switch) {
          isHaveOpen = true
          needCheckList.push(target)
        }
      }
      // 检查已打开的短信模块内容
      if (isHaveOpen) {
        let isHaveBlack = false,
          errName = '',
          errTitle = '发送时间'
        needCheckList.forEach(el => {
          if (!el.time) {
            isHaveBlack = true
            errName = el.name
            errTitle = '发送时间'
          } else if (!el.text) {
            isHaveBlack = true
            errName = el.name
            errTitle = '群发内容'
          }
        })
        if (isHaveBlack) return this.$message.error(`请填写${errName}${errTitle}`)
        // 比较发送时间是否填写正确短信1<短信2<短信3
        let isHaveTimeErr = false,
          errName2 = ''
        for (let i = 0; i < needCheckList.length; i++) {
          let start = needCheckList[i],
            end = needCheckList[i + 1]
          if (end && (Number(start.time) > Number(end.time) || Number(start.time) == Number(end.time))) {
            isHaveTimeErr = true
            errName = start.name
            errName2 = end.name
          }
        }
        if (isHaveTimeErr) return this.$message.error(`${errName2}发送时间需大于${errName}发送时间`)
        needCheckList.forEach(el => {
          let obj = {
            open: el.switch,
            time: el.time,
            text: el.text
          }
          params.push(obj)
        })
      }
      return params
    }
  }
}
</script>

<style scoped lang='scss'>
.sms-content {
  background: white;
  padding: 38px 20px;
  margin-bottom: 16px;
  .textarea {
    width: 592px !important;
    background: white;
    border-bottom: none;
  }
  .wrapper {
    width: 778px;
    box-sizing: border-box;
    padding: 22px 20px 16px;
    background: #f9f9f9;
    .topSet {
      font-weight: 400;
      font-size: 14px;
      color: #333333;
      margin-bottom: 20px;
      .set-int {
        margin: 0 8px;
        .intTime {
          width: 80px;
          height: 32px;
          background: #ffffff;
          font-weight: 400;
          font-size: 14px;
          color: #666666;
        }
      }
    }
  }
  .sms-box {
    display: flex;
    .left {
      font-weight: 400;
      font-size: 14px;
      color: #333333;
    }
    .right {
      .word-limit {
        background: white;
        text-align: right;
        font-weight: 400;
        font-size: 14px;
        color: #999999;
        border: 1px solid #e5e5e5;
        width: 592px !important;
        box-sizing: border-box;
        padding-right: 8px;
        border-top: none;
        height: 28px;
        line-height: 28px;
      }
      .redColorText {
        color: red !important;
      }
      .showSmsModel {
        font-size: 14px;
        font-weight: 400;
        color: #333333;
        width: 592px !important;
        box-sizing: border-box;
        margin-top: 8px;
        line-height: 22px;
      }
    }
  }
  .select-panel {
    padding-left: 20px;
    background: #fafbfe;
    display: flex;
    font-size: 14px;
    font-weight: 400;
    color: #666666;
    line-height: 40px;
    border: 1px solid #e5e5e5;
    width: 592px !important;
    border-top: 0px;
    box-sizing: border-box;
    border-radius: 0 0 4px 4px;
    cursor: pointer;
    .flex {
      display: flex;
      align-items: center;
    }
    .marl24 {
      margin-right: 24px;
    }
    .link {
      width: 18px;
      height: 18px;
      margin-right: 4px;
    }
  }
}
</style>