addCode.vue 15.5 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484
<template>
  <div class="scrm-main">
    <div class="channel-main-guidance scrm-box-f">
      <div class="channel-main-guidance-item">
        <div class="channel-main-guidance-item-head">
          <img src="@/assets/img/channel/staff.png" />
          <div class="channel-main-guidance-item-title">配置名片关联的员工</div>
        </div>
        <div class="channel-main-guidance-item-info">名片可关联一个或多个员工。配置多名员工时,客户扫码后仅会添加随机的某个员工。</div>
      </div>
      <div class="channel-arrow">
        <img src="@/assets/img/channel/channel-arrow.png" />
      </div>
      <div class="channel-main-guidance-item">
        <div class="channel-main-guidance-item-head">
          <img src="@/assets/img/channel/equity.png" />
          <div class="channel-main-guidance-item-title">配置客户领取的权益</div>
        </div>
        <div class="channel-main-guidance-item-info">客户添加员工为好友后,系统将通过欢迎语发送相关的权益礼包。 礼包内容可结合互联网权益、自店权益。由于企微官方限制,使用前请先确认已取消统一的欢迎语。</div>
      </div>
      <div class="channel-arrow">
        <img src="@/assets/img/channel/channel-arrow.png" />
      </div>
      <div class="channel-main-guidance-item">
        <div class="channel-main-guidance-item-head">
          <img src="@/assets/img/channel/card.png" />
          <div class="channel-main-guidance-item-title">生成智能员工名片</div>
        </div>
        <div class="channel-main-guidance-item-info">名片生成后长期有效,可结合门店业务需要,添加到门店活动易拉宝、员工卡座立牌、活动海报,实现灵活的集客。</div>
      </div>
    </div>
    <div class="channel-main scrm-box-f">
      <div class="chanel-form-title">基本信息</div>
      <div class="chanel-form-box  gl-form-page">
        <el-form ref="codeForm" :model="addCodeForm" class="code-body-form" label-width="154px" :rules="codeRules">
          <!-- <el-row> -->
          <el-form-item label="渠道名称:" prop="codeName">
            <el-input size="small" v-model.trim="addCodeForm.codeName" placeholder="请输入渠道名称" maxlength="30"></el-input>
          </el-form-item>
          <!-- </el-row>
          <el-row> -->
          <el-form-item label="备注:">
            <el-input size="small" v-model.trim="addCodeForm.codeRemark" placeholder="请输入备注" maxlength="30"></el-input>
            <div class="form-tips">设置备注,便于后续管理查找</div>
          </el-form-item>
          <!-- </el-row>
          <el-row> -->
          <el-form-item label="自动通过验证:">
            <el-switch v-model="addCodeForm.autoAdd" active-color="#5850FF" inactive-color="#999999"></el-switch>
            <span class="form-tips-btn">开启后,客户添加使用人员无需好友验证</span>
          </el-form-item>
          <!-- </el-row>
          <el-row> -->
          <el-form-item label="选择标签:">
            <el-button size="small" @click="handleAddTag">
              <i class="el-icon-plus"></i>
              选择标签
            </el-button>
            <span class="form-tips-btn">
              已选择
              <span>{{ taggingLength }}</span>
              个标签
            </span>
            <div class="form-tips">自动为通过该活码添加的客户打上所选标签</div>
            <div class="el-input-tag input-tag-wrapper" v-show="taggingLength">
              <template v-if="tagging && tagging.length > 0">
                <template v-for="(item, index) in tagging">
                  <el-tag type="info" v-for="(tag, idx) in item.labelList" :key="idx" closable :disable-transitions="false" @close="removeTag(item, idx, index)">
                    {{ tag ? tag.name : '' }}
                  </el-tag>
                </template>
              </template>
            </div>
          </el-form-item>
          <!-- </el-row>
          <el-row> -->
          <div class="el-form-item is-required">
            <label for="codeName" class="el-form-item__label" style="width: 154px">选择专员:</label>
            <div class="el-form-item__content" style="margin-left: 154px">
              <el-button size="small" @click="handleAddEmp">
                <i class="el-icon-plus"></i>
                选择专员
              </el-button>
              <span class="form-tips-btn">
                已选择
                <span>{{ staffInfo.length }}</span>
                人
              </span>
              <div class="form-tips">客户扫码后将添加所选专员为好友,选择多名专员则按ABAB的顺序添加客户</div>
              <div class="el-input-tag input-tag-wrapper" v-show="staffInfo.length">
                <el-tag effect="plain" type="info" v-for="(tag, idx) in staffInfo" :key="idx" closable :disable-transitions="false" @close="removeStaff(idx)">
                  <i class="el-icon-user-solid"></i>
                  {{ tag.staffName }}
                </el-tag>
              </div>
              <div class="el-form-item__error" v-if="staffStatus">请选择专员</div>
            </div>
          </div>
          <!-- </el-row> -->
        </el-form>
      </div>
    </div>
    <div class="channel-main-welcome scrm-box-f">
      <div class="chanel-form-title">欢迎语</div>
      <div class="welcome-panel">
        <div class="welcome-switch">
          <label>自动发送欢迎语:</label>
          <el-switch v-model="autoWelcome" active-color="#5850FF" inactive-color="#999999"></el-switch>
        </div>
        <div class="welcome-box" v-show="autoWelcome">
          <GLEditor ref="welcome" :form="'customer'" :btnList="btnList" @previewWord="previewForm"></GLEditor>
        </div>
      </div>
    </div>
    <GLFooter>
      <el-button type="primary" @click="handleSave">提交</el-button>
      <el-button @click="goback">取消</el-button>
    </GLFooter>
    <GLDialog title="提示" @onOk="handleSure" @onCancel="dialogVisible = false" type="warning" content="当前有内容信息未保存,是否继续返回?" :visible.sync="dialogVisible" mode="small"></GLDialog>
    <select-emp @selectTable="selectTable" ref="selectEmpForm"></select-emp>
    <select-tag ref="selectTagForm" @tagSelected="tagSelected"></select-tag>
  </div>
</template>

<script>
import { utils } from 'glsx-common'
import selectEmp from '@/components/selectEmp'
import selectTag from '@/components/selectTag'
import word from '@/mixins/word'
export default {
  mixins: [word],
  name: 'addCode',
  components: { selectEmp, selectTag },
  data() {
    return {
      dialogVisible: false,
      addCodeForm: {
        codeName: '',
        codeRemark: '',
        autoAdd: true
      },
      staffStatus: false,
      staffInfo: [],
      tagging: [],
      taggingLength: 0,
      codeId: null,
      footerLeft: 0,
      footerWidth: 0,
      autoWelcome: true,
      editStatus: false,
      previewListStart: [],
      codeRules: {
        codeName: [{ required: true, message: '请输入渠道名称', trigger: 'blur' }]
      }
    }
  },
  watch: {
    tagging: {
      handler() {
        this.taggingLength = 0
        this.tagging.forEach(item => {
          this.taggingLength += item.labelList.length
        })
        this.editStatus = true
      },
      deep: true
    },
    addCodeForm: {
      handler() {
        this.editStatus = true
      },
      deep: true
    },
    staffInfo: {
      handler() {
        this.editStatus = true
      },
      deep: true
    }
  },
  methods: {
    goback() {
      this.previewListStart.forEach(item => {
        this.$refs.welcome.previewList.forEach(itm => {
          if (item.attType == itm.attType) {
            if (typeof item.attContent != 'object' && item.attContent != itm.attContent) {
              this.editStatus = true
            }
            if (typeof item.attContent == 'object' && item.attContent.marketingName != itm.attContent.marketingName) {
              this.editStatus = true
            }
          }
        })
      })
      if (this.editStatus || (this.$refs.welcome.previewList.length > 0 && !this.codeId)) {
        this.dialogVisible = true
      } else {
        this.$router.push('/channel/index')
      }
    },
    handleSure() {
      this.$router.push('/channel/index')
    },
    removeTag(item, idx, index) {
      item.labelList.splice(idx, 1)
      if (item.labelList.length == 0) {
        this.tagging.splice(index, 1)
      }
    },
    removeStaff(index) {
      this.staffInfo.splice(index, 1)
    },
    handleAddEmp() {
      this.staffStatus = false
      this.$refs.selectEmpForm.init(this.staffInfo)
    },
    handleAddTag() {
      this.$refs.selectTagForm.init(this.tagging)
    },
    selectTable(item) {
      this.staffInfo = item.map(item => {
        return {
          staffId: item.relationId,
          staffName: item.staffName
        }
      })
    },
    tagSelected(item) {
      this.tagging = item
    },
    handleSave: utils.debounce(function() {
      if (this.staffInfo.length == 0) {
        this.staffStatus = true
        return
      }
      this.$refs['codeForm'].validate(valid => {
        if (valid) {
          let param = Object.assign({ id: this.codeId }, this.addCodeForm)
          if (this.tagging && this.tagging.length) {
            let tagging = this.tagging.map(item => {
              let tagIds = item.labelList.map(tag => {
                return tag.id
              })
              let name = item.labelList.map(tag => {
                return tag.name
              })
              return {
                groupId: item.labelGroup.id,
                tagIds: tagIds.join(','),
                name: name.join(','),
                labelType: item.labelGroup.name
              }
            })
            param.tagging = JSON.stringify(tagging)
          }
          param.autoWelcome = this.autoWelcome ? 1 : 0
          param.codeSystem = 0
          let staffId = []
          this.staffInfo.forEach(item => {
            staffId.push(item.staffId)
          })
          let channel
          if (this.codeId) {
            channel = 'updateChannelCode'
          } else {
            channel = 'saveChannelCode'
          }
          delete param.staffInfo
          param.staffId = staffId.join(',')
          param.autoAdd ? (param.autoAdd = 1) : (param.autoAdd = 0)
          const previewList = this.$common ? this.$common.utils.deepClone(this.$refs.welcome.previewList) : this.$refs.welcome.previewList
          const attachmentList = previewList.map(item => {
            if (item.attType == 1) {
              item.attContent = item.attContent.replaceAll('[@昵称]', '@昵称')
              item.attContent = item.attContent.replaceAll('@昵称', '[@昵称]')
            } else if (item.attType == 7) {
              item.attContent = JSON.stringify(item.attContent)
            }
            return item
          })
          param.welcomeInfo = attachmentList
          this.$apis.channel[channel](param).then(res => {
            if (res) this.$router.push('/channel/index')
          })
        }
      })
    }, 300),
    detailChannelCode(id, codeUuid) {
      let param = {
        id,
        codeUuid
      }
      this.$apis.channel.detailChannelCode(param).then(res => {
        this.addCodeForm = Object.assign({}, res)
        this.addCodeForm.autoAdd = this.addCodeForm.autoAdd == 1 ? true : false
        this.staffInfo = res.staffInfo
        const tagging = eval(res.tagging)
        if (tagging && tagging.length) {
          const taggingList = tagging.map(item => {
            let name = item.name.split(',')
            let ids = item.tagIds.split(',')
            console.log(ids)
            let labelList = name.map((tag, index) => {
              return { id: ids[index], name: tag }
            })
            return {
              labelGroup: {
                id: item.groupId,
                name: item.labelType
              },
              labelList
            }
          })
          this.tagging = taggingList
        }

        this.autoWelcome = res.autoWelcome ? true : false
        if (res.welcomeInfo.length != 0) {
          const previewList = res.welcomeInfo.map(item => {
            if (item.attType == 7) item.attContent = JSON.parse(item.attContent)
            return item
          })
          this.$refs.welcome.updateList(previewList)
        }
        this.$nextTick(() => {
          this.editStatus = false
          this.previewListStart = this.$common.utils.deepClone(this.$refs.welcome.previewList)
        })
      })
    }
    // resize() {
    //   this.footerLeft = document.querySelector('.base-container-right').offsetLeft
    //   this.footerWidth = document.documentElement.clientWidth - this.footerLeft
    // }
  },
  // destroyed() {
  //   window.removeEventListener('resize', this.resize)
  // },
  mounted() {
    const { id, codeUuid } = this.$route.params
    if (id) {
      this.codeId = id
      this.detailChannelCode(id, codeUuid)
    }
  }
}
</script>

<style lang="scss" scoped>
.channel-main-welcome {
  margin: 20px 0px 16px;
  .welcome-panel {
    margin: 10px;
    padding: 0px 20px 20px;
    .welcome-switch {
      margin-bottom: 20px;
      label {
        margin-right: 10px;
        font-size: 14px;
        font-weight: 400;
        color: #666666;
      }
    }
    .welcome-box {
      margin-left: 62px;
    }
  }
}
.footer-panel {
  display: flex;
  align-items: center;
  justify-content: center;
  position: fixed;
  bottom: 0px;
  height: 64px;
  background: #ffffff;
  box-shadow: 0px -1px 1px 0px rgba(88, 80, 255, 0.1);
}
.chanel-form-title {
  padding: 20px;
  font-size: 16px;
  font-weight: 600;
  color: #333333;
  line-height: 16px;
  border-bottom: 1px solid #d8d8d8;
}
.code-body-form {
  padding: 20px;
  width: 60%;
  .form-tips {
    font-size: 14px;
    font-weight: 400;
    color: #999999;
    line-height: 20px;
  }
  .form-tips-btn {
    font-size: 14px;
    font-weight: 400;
    color: #999999;
    line-height: 20px;
    margin-left: 10px;
    > span {
      color: #5850ff;
    }
  }
  .input-tag-wrapper {
    position: relative;
    font-size: 14px;
    background-color: #fff;
    background-image: none;
    border-radius: 4px;
    border: 1px solid #dcdfe6;
    box-sizing: border-box;
    color: #666;
    display: inline-block;
    outline: none;
    padding: 5px 5px 0px 5px;
    max-height: 68px;
    overflow: auto;
    flex-wrap: wrap;
    transition: border-color 0.2s cubic-bezier(0.645, 0.045, 0.355, 1);
    width: 450px;
    display: flex;
    align-items: center;
    margin-top: 6px;
    font-size: 14px;
    i {
      color: #75acff;
      margin-right: 3px;
      font-size: 14px;
    }
  }
  .el-tag {
    margin-right: 4px;
    height: 26px;
    line-height: 24px;
    margin-bottom: 5px;
  }
}
.channel-main-guidance {
  display: flex;
  padding: 20px;
  box-sizing: border-box;
  align-items: center;
  margin-bottom: 20px;
  .channel-main-guidance-item {
    flex: 1;
    height: 142px;
    background: url('../../assets/img/channel/bg.png'), no-repeat;
    padding: 16px 20px;
    box-sizing: border-box;
    &-head {
      display: flex;
      align-items: center;
      margin-bottom: 8px;
      img {
        width: 22px;
        height: 22px;
        margin-right: 10px;
      }
    }
    &-title {
      font-size: 16px;
      font-weight: 500;
      color: #333333;
      line-height: 22px;
    }
    &-info {
      font-size: 14px;
      font-weight: 400;
      color: #999999;
      line-height: 20px;
    }
  }
  .channel-arrow {
    margin: 0 16px;
    width: 20px;
    height: 15px;
    img {
      width: 100%;
    }
  }
}
</style>