marketing.vue 8.49 KB
<template>
  <div class="marking-container" v-if="flag">
    <div class="marking-container-content m-b-16">
      <div class="font-16 color-3 fw5 m-b-12 line-24">发送内容</div>
      <template v-if="marketingDetails.attachmentList && marketingDetails.attachmentList.length > 0">
        <div v-for="(item, index) in marketingDetails.attachmentList" :key="index">
          <template v-if="item.attType == 1">
            <div class="font-14 color-3 m-b-12" v-html="item.attContent"></div>
          </template>
          <template v-else-if="item.attType == 2">
            <div class="marking-image m-b-12">
              <img :src="item.attContent" />
            </div>
          </template>
          <template v-else-if="item.attType == 7">
            <div class="preview-activity">
              <img class="applet-logo" src="@/assets/images/solicit/icon-applet.png" alt />
              <span style="color: #999; line-height:18px">小程序</span>
              <div class="activity-name">{{ activityContent[item.attContent.marketingType] }}</div>
              <img v-if="item.attContent.marketingType == 1 || item.attContent.marketingType == 2" class="activity-logo" src="@/assets/images/solicit/activity-logo.png" alt />
              <img v-if="item.attContent.marketingType == 3 || item.attContent.marketingType == 4" class="activity-logo" src="@/assets/images/solicit/activity-equity.png" alt />
              <img v-if="item.attContent.marketingType == 5" class="activity-logo" src="@/assets/images/solicit/activity-spike.png" alt />
              <div class="activity-footer">
                <img src="@/assets/images/solicit/applet-footer.png" alt />
                <span>小程序</span>
              </div>
            </div>
          </template>
        </div>
        <!-- <div class="font-14 color-3">尊敬的客户,您好!我店本月推出自费喷漆特惠活动,折扣后单面喷漆低至200元,点击下方链接享受优惠:</div> -->
      </template>
      <template v-else>
        <empty class="marking-empty" description="门店尚未针对该人群设置营销物料"></empty>
      </template>
    </div>
    <div class="marking-container-customer flex-between">
      <div class="font-16 color-3 fw5">发送客户</div>
      <div class="color-2f font-14 flex" @click="goTo('solicit.customer')">
        共{{ marketingDetails.customerInfoList ? marketingDetails.customerInfoList.length : 0 }}人
        <div class="sprite-icon icon-arrow m-l-8"></div>
      </div>
    </div>
    <div class="footer">
      <div
        :class="{
          'marking-button': true,
          disabled: !marketingDetails.attachmentList || !marketingDetails.customerInfoList || (marketingDetails.customerInfoList && marketingDetails.customerInfoList.length == 0)
        }"
        @click="sendHandle"
      >
        一键发送
      </div>
    </div>
  </div>
</template>
<script>
const activityContent = {
  2: '送您一张商城优惠券',
  3: '送您一张专属权益服务卡',
  4: '专属权益服务套餐',
  5: '您有一个秒杀活动可参加'
}
import { solicitApi } from '@/api'
import { Toast, Notify } from 'vant'
import { mapState, mapMutations } from 'vuex'
import emoji from '@/utils/emo'
export default {
  data() {
    return {
      flag:false,
      activityContent,
      isEmpty: true,
      marketingDetails: {
        customerInfoList: [],
        attachmentList: []
      }
    }
  },
  created() {
    this.groupId = this.getQuery().groupId 
    this.getocmarketingList()
  },
  computed: {
    ...mapState({
      activityId: state => state.solicit.activityId,
      staffId: state => state.solicit.staffId
    })
  },
  methods: {
    ...mapMutations({
      SET_COUSTOMER_LIST: 'solicit/SET_COUSTOMER_LIST'
    }),
    //一键营销内容回显
    getocmarketingList() {
      let params = {
        id: this.activityId,
        staffId: this.staffId,
        groupId: this.groupId
      }
      this.showLoading()
      solicitApi.getocmarketingList(params).then(({ code, data, message }) => {
        this.hideLoading()
        if (code == '0') {
          this.marketingDetails = data
          if (data.attachmentList) {
            const attachmentList = this.marketingDetails.attachmentList.map(item => {
              if (item.attType == 1) {
                this.getEmoImg()
              } else if (item.attType == 7) {
                item.attContent = JSON.parse(item.attContent)
              }
              return item
            })
            this.$set(this.marketingDetails, 'attachmentList', attachmentList)
            this.$set(this.marketingDetails, 'customerInfoList', data.customerInfoList)
          }
          this.SET_COUSTOMER_LIST({ customerInfoList: data.customerInfoList })
        } else {
          Notify(message)
        }
        this.flag = true
      })
    },
    // 一键营销
    sendHandle() {
      if (!this.marketingDetails.attachmentList.length) {
        return
      }
      if (this.marketingDetails.massFlag) {
        Toast('您已进行企微营销,请查看营销统计')
        return
      }
      if (this.marketingDetails.customerInfoList.length > 0) {
        let params = {
          groupId: this.groupId,
          id: this.activityId,
          businessUuid: this.marketingDetails.businessUuid,
          configId: this.marketingDetails.configId,
          staffId: this.staffId
        }
        solicitApi.createdOcmarketing(params).then(res => {
          if (res) {
            Toast('营销活动已创建,请及时在「企业微信-群发助手」中确认发送')
            setTimeout(() => {
              this.$router.go(-1)
            }, 1000)
          } else {
            Notify('营销活动创建失败')
          }
        })
      }
    },
    goTo(name) {
      this.$router.push({ name })
    },
    // 表情包转化图片
    getEmoImg() {
      const attContent = this.marketingDetails.attachmentList[0].attContent
      const htm = attContent.replace(/\[[\u4E00-\u9FA56]{1,4}]/gi, function (res) {
        let word = res.replace(/\[|\]/gi, '')
        const list = emoji.flat(Infinity)
        let index = parseInt(list.indexOf(word)) + 1
        if (index < 10) {
          index = '00' + index
        } else if (index >= 10 && index < 100) {
          index = '0' + index
        }
        return `<img class="emo_img" src="https://img01.glsx.com.cn/weapp/resource/saas/scrm/emoji/${index}.png">`
      })
      this.marketingDetails.attachmentList[0].attContent = htm
      this.$set(this.marketingDetails.attachmentList, 0, {
        attType: 1,
        attContent: htm
      })
    }
  }
}
</script>
<style lang="scss" scoped>
.marking-container {
  padding: 16px;

  &-content {
    background: #fff;
    padding: 16px;
    box-shadow: 0px 3px 10px 0px rgba(223, 228, 234, 0.81);
    border-radius: 4px;
    .marking-image {
      width: 152px;
      height: auto;
      // margin: 12px 32px 16px 32px;

      img {
        width: 100%;
        height: 100%;
      }
    }

    .marking-empty {
      padding: 39px 0 24px 0 !important;

      /deep/ .van-empty__description {
        padding: 0;
      }
    }
  }

  &-customer {
    height: 56px;
    background: #ffffff;
    box-shadow: 0px 3px 10px 0px rgba(223, 228, 234, 0.81);
    border-radius: 4px;
    padding: 0 16px;
    margin-bottom: 50px;
  }

  .footer {
    width: 343px;
    height: 58px;
    background: #f7f7f7;
    z-index: 100;
    position: fixed;
    bottom: 0;
  }

  .marking-button {
    width: 343px;
    height: 42px;
    background: #3975c6;
    border-radius: 21px;
    font-size: 14px;
    font-weight: 500;
    color: #ffffff;
    line-height: 42px;
    text-align: center;
    margin-bottom: 16px;
  }

  .disabled {
    background: #d5d8db !important;
  }

  .preview-activity {
    width: 232px;
    // height: 184px;
    background-color: #fff;
    border-radius: 4px;
    border: 1px solid #e8e8ea;
    padding: 12px 12px 0;
    font-size: 11px;
    box-sizing: border-box;

    .applet-logo {
      width: 18px;
      height: 18px;
      margin-right: 4px;
    }

    .activity-logo {
      width: 208px;
      height: 166px;
      margin-bottom: 8px;
    }

    .activity-name {
      font-size: 12px;
      color: #333;
      margin: 7px 0 4px;
      width: 160px;
      text-overflow: ellipsis;
      overflow: hidden;
      white-space: nowrap;
    }

    .activity-footer {
      display: flex;
      align-items: center;
      padding: 3px 0;

      img {
        width: 10px;
        height: 10px;
        margin-right: 3px;
      }

      margin-top: 4px;
      border-top: 1px solid #dfe4ea;
    }
  }
}
</style>