addClewConfig.vue 18.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 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
<template>
  <div class="marketing">
    <div class="addConfig-wrap">
      <div class="header color-3 weight-6 text-16">
        门店配置
        <!-- <span class="weight-5 color6 font-14 ml12" v-if="merchantName">{{ merchantName }}</span> -->
      </div>
      <div class="config-wrap gl-form-page">
        <el-form ref="battleRef" :model="config" label-width="154px" :rules="rules">
          <el-form-item label="门店信息:" prop="merchantId">
            <el-button type="default" class="el-icon-plus" @click="handleRelateStoreClose" :disabled="id != ''">选择门店</el-button>
            <div class="merchantNameLabel" v-if="config.merchantName">
              <p>所属门店</p>
              <div class="merchantName ellipsis-1">{{ config.merchantName }}</div>
            </div>
          </el-form-item>
          <!--  所属企业-->
          <el-form-item label="所属企业:" prop="groupMerchantId">
            <el-select v-model="config.groupMerchantId" placeholder="请选择" @change="handleMerchatChange" @visible-change="hideSelect">
              <el-option v-for="item in merchantList" :key="item.merchantId" :label="item.merchantName" :value="item.merchantId"></el-option>
            </el-select>
          </el-form-item>
          <!-- 推送人 -->
          <el-form-item class="select-wrap" label="推送人:" prop="staffId">
            <div class="common el-form-item__content">
              <div class="el-input" ref="automaticRef">
                <div class="el-input__inner" @click="openAutomatic">
                  <span v-if="config.automaticName == ''" class="placeholder">选择成员</span>
                  {{ config.automaticName }}
                </div>
                <span class="el-input__suffix" @click="openAutomatic">
                  <span class="el-input__suffix-inner"><i :class="['el-select__caret', 'el-input__icon', 'el-icon-arrow-up', isAutomatic ? 'is-reverse' : '']"></i></span>
                </span>
              </div>
            </div>
            <transition name="el-zoom-in-top" v-if="!isAutomatic">
              <gl-select-menu :domEl="automaticEl" @changeStatu="hideSelect" style="width: 432px">
                <el-form-item class="search-groomname">
                  <el-input placeholder="请输入搜索关键词" v-model="filterText"></el-input>
                </el-form-item>
                <div class="el-select-dropdown__wrap el-scrollbar__wrap">
                  <template v-if="automaticData.length > 0">
                    <el-tree class="filter-tree" :data="automaticData" node-key="id" :default-expanded-keys="expandedKeys" :props="defaultProps" default-expand-all :filter-node-method="filterNode" ref="tree" @node-click="handleNodeClick"></el-tree>
                  </template>
                  <div class="empty" v-else>暂无数据</div>
                </div>
              </gl-select-menu>
            </transition>
          </el-form-item>
          <!-- #喜报>> : -->
          <template v-for="(bulletin, index) in buttetinList">
            <el-form-item :label="bulletin.label + ':'" class="group-item-box" :key="index">
              <div class="group-box">
                <div class="input-box" v-for="(i, k) in groupCofListInput[bulletin.storageList]" :key="k">
                  <!-- <el-input v-model="i.name" ></el-input> -->
                  <el-select v-model="i.name" :placeholder="'将' + bulletin.label + '推送至群聊'" filterable clearable @change="changeGroupName(i.name, k, groupCofListInput[bulletin.storageList])">
                    <el-option v-for="item in selectGroupName" :key="item.groupName" :label="item.groupName" :value="item.groupName"></el-option>
                  </el-select>
                  <i class="el-icon-circle-plus" v-if="k == 0" @click="addGroup(groupCofListInput[bulletin.storageList])"></i>
                  <i class="el-icon-remove" v-else @click="delGroup(groupCofListInput[bulletin.storageList], k)"></i>
                </div>
              </div>
              <span class="group-config-text" @click="openConfigDialog(bulletin.componentName)">配置</span>
            </el-form-item>
          </template>
        </el-form>
      </div>
    </div>
    <GLFooter class="footer-panel">
      <el-button @click="handlebattleClose" size="medium">取消</el-button>
      <el-button type="primary" @click="handlebattleConfirm" size="medium" :loading="loading">保存</el-button>
    </GLFooter>
    <component :is="dialogComponent" ref="componentRef" v-if="isDialogVisible" :isDialogVisible="isDialogVisible" :content="config.content" @handlePreview="handlePreview" @handleClose="handleClose"></component>
    <select-store v-if="relateStoreVisible" ref="relateStore" :dialogVisible="relateStoreVisible" :storeSelected="selectedList" :merchantInfo="config.merchantId" @handleRelateStoreConfirm="handleRelateStoreConfirm" @handleRelateStoreClose="handleRelateStoreClose"></select-store>
  </div>
</template>
<script>
import GlSelectMenu from '../battle/components/select-dropdown.vue'
import clewWordDialog from './components/dialogs/clewWordDialog.vue'
import selectStore from './components/selectStore'
export default {
  components: {
    GlSelectMenu,
    clewWordDialog,
    selectStore
  },
  data() {
    return {
      id: this.$route.query.id ? this.$route.query.id : '',
      selectGroupName: [],
      isDialogVisible: false,
      relateStoreVisible: false, // 选择门店
      dialogComponent: '',
      merchantList: [],
      automaticData: [],
      expandedKeys: [],
      defaultProps: {
        children: 'children',
        label: 'name'
      },
      config: {
        merchantId: '',
        merchantName: '',
        staffId: '',
        automaticName: '',
        groupMerchantId: ''
      },
      isAutomatic: true,
      filterText: '',
      groupCofList: {
        clewWordReport: []
      },
      rules: {
        merchantId: [{ required: true, message: '请选择门店信息', trigger: 'change' }],
        groupMerchantId: { required: true, message: '请选择所属企业', trigger: ['blur', 'change'], type: 'number' },
        staffId: [{ required: true, message: '请选择推送人', trigger: 'change' }]
      },
      groupCofListInput: {
        clewWordReportValue: [
          {
            name: ''
          }
        ]
      },
      groupToType: [
        {
          attr: 'clewWordReport',
          type: 7
        }
      ],
      buttetinList: [
        {
          label: '线索文字喜报',
          storageList: 'clewWordReportValue',
          componentName: 'clewWordDialog'
        }
      ]
    }
  },
  watch: {
    filterText(val) {
      this.$refs.tree.filter(val)
    }
  },
  computed: {
    automaticEl() {
      return this.$refs.automaticRef
    }
  },
  mounted() {
    this.getMerchantList()
    if (this.id) this.getClueDetailById()
  },
  methods: {
    changeGroupName(name, index, data) {
      let result
      for (let i = 0; i < data.length; i++) {
        if (i !== index) {
          if (data[i].name == name) result = true
        }
      }
      if (result) {
        this.$message({
          message: '勿选择相同的群',
          type: 'error'
        })
        data[index].name = ''
      }
    },
    // 选择门店
    handleRelateStoreClose() {
      this.relateStoreVisible = !this.relateStoreVisible
    },
    handleRelateStoreConfirm(selectedData) {
      selectedData.merchantId && (this.config.merchantId = selectedData.merchantId)
      selectedData.merchantName && (this.config.merchantName = selectedData.merchantName)
      this.$refs.battleRef.clearValidate('merchantId')
      this.handleRelateStoreClose()
    },
    handlePreview(params) {
      let { data } = params
      this.config.content = data
      this.isDialogVisible = false
    },
    handleClose() {
      this.isDialogVisible = false
    },

    openConfigDialog(componentName) {
      this.dialogComponent = componentName
      this.isDialogVisible = true
    },
    addGroup(group) {
      group.push({ name: '' })
    },
    delGroup(group, i) {
      group.splice(i, 1)
    },
    hideSelect() {
      this.isAutomatic = true
    },
    openAutomatic() {
      this.isAutomatic = !this.isAutomatic
    },
    getMerchantList(sign) {
      this.$apis.battle.getMerchantList({}).then(res => {
        this.merchantList = res
        if (!this.id) {
          this.config.groupMerchantId = res[0]?.merchantId
          this.config.groupMerchantName = res[0]?.merchantName
          this.getDepartmentTree()
        }
      })
    },
    filterNode(value, data) {
      if (!value) return true
      return data.name.indexOf(value) !== -1
    },
    handleNodeClick(data) {
      this.hideSelect()
      if (this.config.automaticName == data.name) return
      this.config.automaticName = data.name
      this.config.staffId = data.staffId
      this.idBefEncryption = data.idBefEncryption ? data.idBefEncryption : '1688855154413617'
      this.$refs.battleRef.clearValidate('staffId')
      this.$apis.battle.activityreportWorktool({ cloudId: this.idBefEncryption }).then(res => {
        this.selectGroupName = res.data.result || []
        this.groupCofListInput = { clewWordReportValue: [{ name: '' }] }
      })
    },
    //编辑回显
    getClueDetailById() {
      this.groupCofListInput = {
        // xiReportValue: [],
        clewWordReportValue: []
      }
      this.$apis.clewOrder.getClueDetailById({ id: this.id }).then(res => {
        let data = res.data
        // 编辑
        this.config.staffId = data.staffId
        this.config.automaticName = data.staffName
        this.config.merchantId = data.merchantId
        this.config.merchantName = data.merchantName
        this.config.groupMerchantId = data.groupMerchantId
        this.config.groupMerchantName = data.groupMerchantName
        this.config.content = data.content
        data.groupConfigList.forEach(item => {
          // let groupHideAttr = this.groupToType.find(k => k.type == item.actionReportType)?.attr
          let groupHideAttr = 'clewWordReport'
          if (!groupHideAttr) return
          if (item.groupId) {
            const separatorIndex = item.groupId.indexOf('_R:')
            if (separatorIndex !== -1) {
              const cloudId = item.groupId.substring(0, separatorIndex)
              const groupNameFromId = item.groupId.substring(separatorIndex + 3) // 3 是 "_R:" 的长度
              if (groupNameFromId && groupNameFromId == item.groupName) {
                groupHideAttr && this.groupCofListInput[groupHideAttr + 'Value'].push({ name: item.groupName })
                this.idBefEncryption = cloudId
              } else if (item.groupName) {
                groupHideAttr &&
                  this.groupCofList[groupHideAttr].push({
                    groupId: item.groupId,
                    roomName: item.groupName
                  })
              } else {
                this.idBefEncryption = cloudId
                groupHideAttr && this.groupCofListInput[groupHideAttr + 'Value'].push({ name: '' })
              }
            } else {
              if (item.groupName) {
                groupHideAttr &&
                  this.groupCofList[groupHideAttr].push({
                    groupId: item.groupId,
                    roomName: item.groupName
                  })
              }
            }
          }
        })
        for (let k in this.groupCofListInput) {
          if (this.groupCofListInput.hasOwnProperty(k) && !this.groupCofListInput[k][0]) {
            this.groupCofListInput[k] = [{ name: '' }]
          }
        }
        this.$apis.battle.activityreportWorktool({ cloudId: this.idBefEncryption }).then(res => {
          this.selectGroupName = res.data.result || []
        })

        this.getDepartmentTree()
      })
    },
    //所属企业
    handleMerchatChange(val) {
      this.getDepartmentTree()
      this.merchantList.forEach(item => {
        item.merchantId == val ? (this.config.groupMerchantName = item.merchantName) : ''
      })
      this.config.staffId = ''
      this.config.automaticName = ''
    },
    async getDepartmentTree() {
      let params = { addChildrensFlag: true, queryMerchantId: this.config.groupMerchantId, loginStatus: 1 }
      let data = await this.$apis.saasOrder.getlistDepartmentTree(params)
      this.ids = []
      this.automaticData = data
      await this.initData(this.automaticData)
    },
    initData(data) {
      data.forEach((item, index) => {
        this.$set(item, 'name', item.staffName ? item.staffName : item.departmentName)
        let entmicroStaffResponses = this.$common.utils.deepClone(item.entmicroStaffResponses) || []
        entmicroStaffResponses = entmicroStaffResponses.filter((staff, idx) => {
          if (staff.staffName) {
            this.$set(staff, 'name', staff.staffName)
          } else {
            this.$set(staff, 'name', staff.departmentName)
          }
          if (staff.staffId && !this.ids.includes(staff.staffId)) {
            this.ids.push(staff.staffId)
            return true
          } else if (staff.staffId && this.ids.includes(staff.staffId)) {
            return false
          }
        })
        let child = this.$common.utils.deepClone(item.children) || []
        child = child.filter((staff, idx) => {
          if (staff.staffName) {
            this.$set(staff, 'name', staff.staffName)
          } else {
            this.$set(staff, 'name', staff.departmentName)
          }
          if (staff.staffId && !this.ids.includes(staff.staffId)) {
            this.ids.push(staff.staffId)
            return true
          } else if (staff.staffId && this.ids.includes(staff.staffId)) {
            return false
          } else if (staff.entmicroStaffResponses) {
            staff.staffId = staff.id
            return true
          }
        })
        const children = [...child, ...entmicroStaffResponses]
        item.children = children
        //清除没有员工的部门
        if (!item.staffName && item.entmicroStaffResponses === null) {
          // data.splice(index, 1)
        }
        children.length && this.initData(children)
      })
    },
    clearData() {
      // this.$refs.battleRef.clearMutiSelect()
      //所属企业默认选择第一个
      this.config.groupMerchantId = this.merchantList[0]?.merchantId
      this.config = {
        staffId: '',
        automaticName: ''
      }
      this.hideSelect()
    },
    handlebattleConfirm() {
      this.$refs.battleRef.validate(valid => {
        if (valid) {
          let isGroupEmpty = Object.keys(this.groupCofList)
            .map(item => this.groupCofList[item].length)
            .every(item => item == 0)
          let isGroupEmptyInput = Object.keys(this.groupCofListInput)
            .map(item => this.groupCofListInput[item].length)
            .every(item => item == 0)
          if (isGroupEmpty && isGroupEmptyInput) {
            this.$message({
              message: '推送配置必须配置至少一项',
              type: 'error',
              customClass: 'message-Z-zinde'
            })
            return true
          }
          var params = {
            merchantId: this.config.merchantId,
            merchantName: this.config.merchantName,
            staffId: this.config.staffId,
            staffName: this.config.automaticName,
            groupConfigList: [],
            content: this.config.content
          }
          if (this.id) params.id = this.id
          Object.keys(this.groupCofList).map(item => {
            if (this.groupCofList[item].length) {
              this.groupCofList[item].forEach(k => {
                params.groupConfigList.push({
                  groupId: k.groupId,
                  groupName: k.roomName,
                  groupMerchantId: this.config.groupMerchantId,
                  groupMerchantName: this.config.groupMerchantName
                })
              })
            } else if (this.groupCofListInput[item + 'Value'].length) {
              this.groupCofListInput[item + 'Value'].forEach(k => {
                params.groupConfigList.push({
                  groupId: this.idBefEncryption + '_R:' + k.name,
                  groupName: k.name,
                  groupMerchantId: this.config.groupMerchantId,
                  groupMerchantName: this.config.groupMerchantName
                })
              })
            }
          })
          this.$apis.clewOrder.updateClueReportConfig(params).then(res => {
            this.$message({
              message: res.code == '0' ? '配置成功' : res.message,
              type: res.code == '0' ? 'success' : 'error'
            })
            if (res.data) {
              this.$router.push({
                path: '/bulletin/index',
                query: {
                  activeName: '3'
                }
              })
            }
          })
        }
      })
    },
    handlebattleClose() {
      this.$router.push({
        path: '/bulletin/index',
        query: {
          activeName: '3'
        }
      })
      this.clearData()
    }
  }
}
</script>
<style lang="scss" scoped>
.footer-panel {
  margin-top: 20px;
}
.search-groomname {
  width: 402px;
  margin: 12px 16px 0;
  /deep/.el-input {
    width: 402px;
  }
}
.addConfig-wrap {
  background: #fff;
  .header {
    width: 100%;
    height: 58px;
    border-bottom: 1px solid #e5e5e5;
    line-height: 58px;
    padding-left: 20px;
  }
  .ml12 {
    margin-left: 12px;
  }
  .config-wrap {
    padding: 32px 20px;
    min-height: 600px;
  }
  .group-item-box {
    /deep/.el-form-item__content {
      width: 392px;
    }
  }
  .group-box {
    width: 100%;
    padding: 20px;
    background: #f9f9f9;
    .input-box {
      display: flex;
      align-items: center;
      /deep/ {
        .el-select,
        .el-input {
          width: 355px !important;
        }
      }
      i {
        cursor: pointer;
        font-size: 20px;
        color: #5850ff;
        margin-left: 6px;
      }
    }
  }
  .group-config-text {
    font-size: 12px;
    color: #5850ff;
    position: absolute;
    left: 450px;
    top: 20px;
    white-space: nowrap;
    cursor: pointer;
  }
  .placeholder {
    font-size: 14px;
    color: #c0c6ce;
    line-height: 20px;
  }
  .merchantNameLabel {
    width: 510px;
    color: #1d1d1d;
    // margin-left: 50px;
    padding: 16px;
    margin-top: 8px;
    border: 1px solid #e6e6e6;
    border-radius: 8rpx;
    background: #f9f9f9;
    .merchantName {
      box-sizing: border-box;
      width: 284px;
      height: 32px;
      background: #ffffff;
      border: 1px solid #e6e6e6;
      border-radius: 4px;
      font-family: PingFangSC-Regular;
      font-weight: 400;
      font-size: 14px;
      color: #999999;
      line-height: 32px;
      padding: 0 8px;
    }
  }
}
.is-reverse {
  transform: rotate(180deg);
}
</style>