aiCard.vue 19.7 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 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663
<template>
  <div class="ai-main">
    <div class="ai-main-header">
      <div class="ai-main-title">离店客户加企微</div>
      <div class="ai-main-desc">系统将通过AI机器人,使用门店的福利官企微号自动添加客户,并自动发放客户福利权益。</div>
    </div>
    <div class="ai-main-guidance scrm-box-f">
      <div class="ai-main-guidance-item">
        <div class="ai-main-guidance-item-head">
          <img src="@/assets/img/ai/edit.png" />
          <div class="ai-main-guidance-item-title">导入待添加客户手机号</div>
        </div>
        <div class="ai-main-guidance-item-info">提供完善的客户信息,有助于提升好友通过率</div>
      </div>
      <div class="ai-arrow">
        <img src="@/assets/img/ai/arrow.png" />
      </div>
      <div class="ai-main-guidance-item">
        <div class="ai-main-guidance-item-head">
          <img src="@/assets/img/ai/add.png" />
          <div class="ai-main-guidance-item-title">平台专员全程操作添加</div>
        </div>
        <div class="ai-main-guidance-item-info">需授权平台专员登录您企微账号,以便让客户添加至您的企微。</div>
      </div>
      <div class="ai-arrow">
        <img src="@/assets/img/ai/arrow.png" />
      </div>
      <div class="ai-main-guidance-item">
        <div class="ai-main-guidance-item-head">
          <img src="@/assets/img/ai/text.png" />
          <div class="ai-main-guidance-item-title">查看添加好友结果</div>
        </div>
        <div class="ai-main-guidance-item-info">系统将对执行结果进行自动分类,并提供报表直观呈现。</div>
      </div>
    </div>
    <el-button type="primary" icon="el-icon-plus" size="small" @click="handleAdd">创建加好友任务</el-button>
    <el-tabs v-model="activeIndex" type="card" class="ai-tab">
      <el-tab-pane label="任务队列" :name="1"></el-tab-pane>
      <el-tab-pane label="任务记录" :name="2"></el-tab-pane>
    </el-tabs>
    <ai-tabel :activeIndex="activeIndex" ref="AiForm" @update="update"></ai-tabel>
    <GLDialog :title="!isEdit ? '创建任务' : '编辑任务'" destroy-on-close="true" okText="保存" class="gl-form-page gl-form-min" v-loading="loading" @onOk="handleSure" @onCancel="dialogVisible = false" :visible.sync="dialogVisible">
      <el-form ref="addForm" class="code-body-form" label-width="154px">
        <div class="el-form-item is-required el-form-item--small">
          <label for="remark" class="el-form-item__label" style="width: 154px">任务名称:</label>
          <div class="el-form-item__content" style="margin-left: 154px">
            <div class="el-input el-input--small">
              <input type="text" @blur="checkTask" :disabled="isEdit" v-model.trim="taskName" autocomplete="off" placeholder="请输入任务名称" maxlength="10" class="el-input__inner" />
            </div>
            <!-- <div class="tips-error" v-if="taskStatus">请输入任务名称</div> -->
          </div>
        </div>
        <div class="el-form-item is-required el-form-item--small">
          <label for="remark" class="el-form-item__label" style="width: 154px">导入手机号:</label>
          <div class="el-form-item__content" style="margin-left: 154px">
            <div class="import-link">
              <div class="upload-btn">
                <el-button size="small" :disabled="isEdit">
                  <i class="el-icon-plus"></i>
                  上传手机号
                </el-button>
                <input type="file" v-if="!isEdit" style="opacity: 0" ref="file" accept="*" @change="uploadFile" />
              </div>
              <a href="https://img01.glsx.com.cn/weapp/resource/saas/scrm/xlsx/待加客户好友模板.xlsx">手机号模板</a>
            </div>
            <div class="upload-result" v-if="fileName">
              <div class="upload-name">{{ fileName }}</div>
              <div class="upload-del">
                <i
                  v-if="!isEdit"
                  class="el-icon-delete"
                  @click="
                    fileName = ''
                    url = ''
                  "
                ></i>
              </div>
            </div>
            <div class="form-tips" v-if="fileName">共{{ ImportResult.success }}条数据</div>
            <div class="form-tips">提示:文件最大允许1000条手机号数据</div>
            <!-- <div class="tips-error" v-if="fileStatus">请上传上传手机号</div> -->
          </div>
        </div>
        <div class="el-form-item is-required el-form-item--small">
          <label for="remark" class="el-form-item__label" style="width: 154px">选择专员:</label>
          <div class="el-form-item__content" style="margin-left: 154px">
            <div class="market-content">
              <el-button size="small" @click="handleAddEmp">
                <i class="el-icon-plus"></i>
                选择专员
              </el-button>
              <div class="el-input-tag input-tag-wrapper" v-show="staffInfo.length">
                <GLFull :label="tag.staffName" :identi="`${tag.staffId}`" labelWidth="110" textType="user" :haveClose="true" v-for="(tag, idx) in staffInfo" :key="idx" @handleRemove="removeStaff(idx)"></GLFull>
              </div>
            </div>
            <div class="form-tips">选择专员后,将会生成带该专员企微二维码链接的短信给到客户来加好友,以提高加微率</div>
            <!-- <div class="tips-error" v-if="staffStatus">请选择专员</div> -->
          </div>
        </div>
        <div class="el-form-item el-form-item--small">
          <label for="remark" class="el-form-item__label" style="width: 154px">自动发送欢迎语:</label>
          <div class="el-form-item__content" style="margin-left: 154px">
            <el-switch v-model="autoSend" active-color="#5850FF" inactive-color="#F2F3F5"></el-switch>
          </div>
        </div>

        <div style="margin-left: 154px; margin-top: -8px" v-if="autoSend">
          <GLEditor :boxHeight="240" ref="welcome" :btnList="btnList"></GLEditor>
        </div>
      </el-form>
    </GLDialog>
    <GLDialog title="导入数据失败" :hasFooter="true" mode="small" :visible.sync="importVisible">
      <div class="dialog-body-panel">
        <div class="import-result">
          <label>{{ ImportResult.error }}</label>
          条数据异常
        </div>
        <div class="import-tips">数据异常的可能原因:</div>
        <div class="import-reason">
          <div class="import-reason-content">1、存在不正确的手机号格式数据</div>
          <div class="import-reason-content">2、存在重复的手机号数据</div>
          <div class="import-reason-content">3、文件数据超出1000条限制</div>
        </div>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button size="small" @click="importVisible = false">取消</el-button>
        <el-button size="small" type="primary" @click="handleImport">导出错误数据</el-button>
      </span>
    </GLDialog>
    <select-emp @selectTable="selectTable" ref="selectEmpForm"></select-emp>
  </div>
</template>

<script>
import selectEmp from '@/components/selectEmp'
import aiTabel from './components/ai-tabel.vue'
import util from '@/utils/util'
export default {
  name: 'aiCard',
  components: {
    selectEmp,
    aiTabel
  },
  data() {
    return {
      isRedeem: true,
      isEdit: false,
      loading: false,
      taskStatus: false,
      fileStatus: false,
      staffStatus: false,
      activeIndex: 1,
      taskId: '',
      dialogVisible: false,
      importVisible: false,
      dialogVisibleDel: false,
      autoSend: true,
      staffInfo: [],
      ImportResult: {},
      taskName: '',
      url: '',
      fileName: '',
      btnList: [
        {
          name: '表情',
          funcName: '',
          type: 'expression',
          limitSize: 10
        },
        {
          name: '图片',
          funcName: '',
          type: 'img',
          uploadApi: this.$apis.common.pictureUpload
        },
        {
          name: '昵称',
          type: 'nickname',
          funName: 'nickname'
        },
        {
          name: '活动',
          type: 'activity',
          funName: 'activity',
          funParams: [
            {
              itemName: '权益卡试用',
              itemValue: 3,
              itemType: 'card',
              getInterfaceApi: this.$apis.welcomeword.getCard,
              params: {
                tryAble: 1,
                merchantId: this.$globalState.session.merchantId
              }
            },
            {
              itemName: '权益套餐',
              itemValue: 4,
              itemType: 'package',
              getInterfaceApi: this.$apis.welcomeword.getPackage,
              params: {}
            },
            {
              itemName: '商城券',
              itemValue: 2,
              itemType: 'coupon',
              getInterfaceApi: this.$apis.welcomeword.getMerchant,
              params: {
                discountTypes: [2, 3, 4],
                directionalFlag: 1, // 1所有人可用2定向礼包专用3关联优惠券
                validType: 'valid'
              }
            },
            {
              itemName: '秒杀活动',
              itemValue: 5,
              itemType: 'activity',
              getInterfaceApi: this.$apis.welcomeword.getActivity,
              params: {
                activityStatus: 2,
                currentPage: 1
              }
            },
            {
              itemName: '无忧服务',
              itemValue: 6,
              itemType: 'merchant',
              getInterfaceApi: this.$apis.welcomeword.merchant,
              merchantOpen: {
                merchantOpenApi: this.$apis.welcomeword.merchantOpen,
                params: {
                  merchantId: this.$globalState.session.merchantId
                }
              },
              params: {
                merchantId: this.$globalState.session.merchantId
              }
            }
          ]
        },
        {
          name: '素材',
          type: 'material',
          funName: 'material',
          groupListApi: this.$apis.welcomeword.getGroupListApi,
          materialListApi: this.$apis.welcomeword.getMaterialListApi
          // videoNo: true
          // pdfNo: true
        },
        {
          name: '兑换码',
          type: 'code',
          funName: 'code'
        }
      ]
    }
  },
  methods: {
    handleImport() {
      util.openUrl(this.ImportResult.errUrl.replace(/https?:/, ''))
    },
    handleAdd() {
      this.isEdit = false
      this.staffInfo = []
      this.taskName = ''
      this.url = ''
      this.fileName = ''
      this.dialogVisible = true
      this.taskStatus = false
      this.autoSend = true
    },
    update(data) {
      this.isEdit = true
      this.taskId = data.id
      this.$apis.aiCard.getTaskContent({ id: this.taskId }).then(res => {
        if (res.code == 0) {
          this.taskName = data.taskName
          this.phoneCheck(res.data.excelName, res.data.excelUrl)
          this.staffInfo = res.data.staffs
          this.autoSend = res.data.autoSend == 1 ? true : false
          const attachmentList = res.data && res.data.attachmentList ? res.data.attachmentList : []
          const preview = this.$common.utils.deepClone(attachmentList)
          this.$nextTick(() => {
            preview.map(item => {
              if (item.attType == 7) {
                item.attContent = JSON.parse(item.attContent)
              }
            })
            preview.length > 0 && this.$refs.welcome.updateList(preview)
          })
          this.dialogVisible = true
        }
      })
    },
    selectTable(item) {
      this.staffInfo = item.map(item => {
        return {
          staffId: item.id,
          staffName: item.staffName
        }
      })
    },
    uploadFile(e) {
      const file = e.srcElement.files[0]
      let AllImgExt = '.xls|.xlsx'
      let extName = file.name.substring(file.name.lastIndexOf('.')).toLowerCase()
      if (AllImgExt.indexOf(extName) === -1) {
        this.$message.error('上传格式不正确')
        return false
      }
      const size = file.size / 1024 / 1024
      // if (size > 8) {
      //   this.$message.error('单文件体积需小于8M')
      //   return
      // }
      const reader = new FileReader()
      reader.readAsDataURL(file)
      reader.onload = event => {
        const imgFile = event.target.result
        const arrBase64 = imgFile.split(',')
        const splitStr = file.name.split('.')
        const fileUrl = splitStr[splitStr.length - 1] + '@' + arrBase64[1]
        this.$apis.common.pictureUpload({ file: fileUrl }).then(res => {
          if (res) {
            this.phoneCheck(file.name, res)
          }
          this.$refs.file.value = ''
        })
      }
    },
    removeStaff(index) {
      this.staffInfo.splice(index, 1)
    },
    phoneCheck(fileName, url) {
      this.$apis.aiCard.phoneCheck({ url }).then(res => {
        if (res) {
          this.ImportResult = res
          if (res.error > 0) {
            this.importVisible = true
          } else {
            this.fileName = fileName
            this.url = url
          }
        }
      })
    },
    checkTask() {
      this.taskName = this.taskName.replace(/[^[\u4E00-\u9FA5\w]/g, '').replace(/^_/, '')
      const { taskName } = this
      if (!taskName) {
        return
      }
      this.$apis.aiCard.checkTask({ taskName }).then(res => {
        this.taskStatus = res
      })
    },
    handleSure() {
      const staffIds = this.staffInfo.map(item => item.staffId)
      const { url, fileName, taskName } = this
      if (!taskName) {
        this.$message.error('请输入任务名称')
        return
      }
      if (this.taskStatus) {
        this.$message.error('任务名称已重复')
        return
      }
      if (!fileName) {
        this.$message.error('请上传手机号')
        return
      }
      if (staffIds.length == 0) {
        this.$message.error('请选择专员')
        return
      }
      this.isRedeem = true
      const previewList = this.autoSend && this.$refs.welcome.previewList ? this.$common.utils.deepClone(this.$refs.welcome.previewList) : []

      const attachmentList = previewList.map(item => {
        if (item.attType == 1) {
          item.attContent = item.attContent.replace(/\[(@昵称|#兑换码)\]/g, '$1')
          item.attContent = item.attContent.replace(/(@昵称|#兑换码)/g, '[$1]')
          if (item.attContent.match(/\[#兑换码\]/g)&&item.attContent.match(/\[#兑换码\]/g).length > 10) {
            this.$message({
              message: '最多输入10个兑换码',
              type: 'error'
            })
            this.isRedeem = false
            return
          }
        } else if (item.attType == 7) {
          item.attContent = JSON.stringify(item.attContent)
        }
        return item
      })
      const autoSend = this.autoSend ? 1 : 0
      this.loading = true
      const methods = this.isEdit ? 'updateTaskContent' : 'createTask'
      const message = this.isEdit ? '编辑成功' : '创建成功'
      let params = {
        url,
        fileName,
        taskName,
        staffIds,
        attachmentList,
        autoSend
      }
      if (this.isEdit) params.taskId = this.taskId
      if (!this.isRedeem) return
      this.$apis.aiCard[methods](params).then(res => {
        this.$message({
          message: res.code == '0' ? message : res.message,
          type: res.code == '0' ? 'success' : 'error'
        })
        if (res.code == 0) {
          this.dialogVisible = false
          this.$refs.AiForm.handleSeach()
          this.loading = false
        }
      })
    },
    handleAddEmp() {
      this.staffStatus = false
      this.$refs.selectEmpForm.init(this.staffInfo)
    }
  },
  created() {
    if(!util.isShowBtn(null,'兑换码')) {
      this.btnList.splice(-1)
    }
  }
}
</script>

<style lang="scss" scoped>
.dialog-body-panel {
  .import-result {
    font-size: 16px;
    font-weight: 600;
    color: #333333;
    line-height: 22px;
    label {
      color: #eb4e4e;
    }
  }
  .import-tips {
    font-size: 14px;
    font-weight: 400;
    color: #666666;
    line-height: 20px;
    margin: 6px 0px;
  }
  .import-reason {
    height: 92px;
    background: #f5f5f5;
    padding: 16px;
    box-sizing: border-box;
    &-content {
      font-size: 14px;
      font-weight: 400;
      color: #333333;
      line-height: 20px;
    }
  }
}
.ai-tab {
  /deep/ {
    .el-tabs__nav {
      border: none;
    }
    .el-tabs__header {
      margin: 0px;
    }
    .el-tabs__item.is-active {
      background: #fff;
      border-bottom: none !important;
    }
    .el-tabs__item {
      border: 1px solid #e5e5e5 !important;
      border-bottom: none;
      border-radius: 4px 4px 0px 0px;

      &:first-child {
        margin-right: 5px;
      }
    }
  }
}
.tips-error {
  color: #f56c6c;
  font-size: 12px;
  line-height: 20px;
  height: 20px;
}
.ai-main-header {
  background: #fff;
  padding: 16px 20px;
  .ai-main-title {
    font-size: 20px;
    color: #333333;
    font-weight: 600;
  }
  .ai-main-desc {
    margin-top: 10px;
    font-size: 14px;
    font-weight: 400;
    color: #666666;
    line-height: 22px;
  }
}
.ai-main-guidance {
  display: flex;
  padding: 20px;
  box-sizing: border-box;
  align-items: center;
  margin: 16px 0px;
  .ai-main-guidance-item {
    flex: 1;
    height: 112px;
    background: linear-gradient(180deg, #f3f2f8 0%, #f9f9fc 100%);
    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: 600;
      color: #333333;
      line-height: 22px;
    }
    &-info {
      font-size: 14px;
      font-weight: 400;
      color: #999999;
      line-height: 20px;
    }
  }
  .ai-arrow {
    margin: 0 16px;
    width: 20px;
    height: 15px;
    img {
      width: 100%;
    }
  }
}
.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;
  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;
  }
}
.form-tips {
  font-size: 12px;
  font-weight: 400;
  color: #999999;
  line-height: 17px;
  margin-top: 5px;
}
.upload-result {
  display: flex;
  align-items: center;
  .upload-name {
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
    margin-right: 5px;
    padding-left: 10px;
    height: 26px;
    line-height: 26px;
    background: #f5f7fa;
    border-radius: 2px;
    flex: 1;
  }
  i {
    cursor: pointer;
    color: #c6c6c6;
  }
}
.import-link {
  display: flex;
  cursor: pointer;
  margin-bottom: 8px;
  .upload-btn {
    position: relative;
    display: inline-block;
    input {
      cursor: pointer;
      position: absolute;
      height: 100%;
      width: 100%;
      top: 0px;
      left: 0px;
      font-size: 0px;
    }
  }
  a {
    margin-left: 6px;
    color: #5850ff;
  }
}
.ai-tab {
  margin-top: 16px;
}
.preview-panel {
  /deep/ {
    .el-image-viewer__img {
      width: 320px;
      height: 624px;
    }
  }
}
.market-content /deep/ {
  .full-container {
    margin-bottom: 5px;
  }
}
.gl-form-min /deep/.el-form .welcome-box {
  width: 100% !important;
  .add-btn:nth-last-child(1) {
    padding-right: 0px;
  }
  .text-num {
    color: #999999;
  }
}
.gl-form-page .el-form {
  padding-left: 0px !important;
}
.code-body-form /deep/ .w-textarea_input{
  height:230px;
  overflow-y: auto;
}
</style>