detail.vue 20.8 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 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760
<template>
  <div v-if="flag" class="layout">
    <div class="detail-bg detail-first">
      <div class="detail-customer">
        <template v-if="userInfo.info.avatar">
          <img :src="userInfo.info.avatar" class="avatar" />
        </template>
        <template v-else>
          <div class="sprite-icon icon-avatar"></div>
        </template>
        <div class="detail-customer-name">
          <span class="name">{{ userInfo.info.customerName }}</span>
          <span class="wechat">@{{ userInfo.info.type == 1 ? '微信' : '企微' }}</span>
          <div>
            {{ customerSex[userInfo.info.customerSex] }}
          </div>
        </div>
      </div>
      <div class="detail-member">
        <span class="name">所属成员</span>
        <div class="name-list">
          {{ staffNameList }}
        </div>
      </div>
    </div>
    <div class="detail-second">
      <van-cell-group :class="[isMore ? '' : 'more-hidden']">
        <template v-for="(i, index) in detailObj">
          <van-cell :key="index" :title="i.title" @click="setDetail(i)" title-class="cell-title">
            <template #default>
              <div v-if="i.value(userInfo) && i.special !== 'special'">{{ i.value(userInfo) }}</div>
              <div v-else-if="i.special == 'special'">{{ i.value(userInfo) }} {{ i.valueTrain(userInfo) }} {{ i.valueType(userInfo) }}</div>
              <div v-else class="placeholder">
                <template v-if="i.placeholder && customerId == 0">{{ i.placeholder }}</template>
              </div>
            </template>
          </van-cell>
        </template>
      </van-cell-group>
      <div class="detail-more text-center" @click="moreInfo">
        <div class="btn text-center">
          {{ isMore ? '收起' : '展开全部' }}
          <div :class="['sprite-icon', 'icon-open-arrow', { more: isMore }]"></div>
        </div>
      </div>
    </div>
    <template v-for="(label, ids) in labelArray">
      <template v-if="(merchantModel == 2 && label.labelGroupType != '自店标签') || merchantModel == 1">
        <div class="detail-bg detail-third" :key="ids">
          <div class="title">
            {{ merchantModel == 1 && label.labelGroupType == '企业标签' ? '集团标签' : label.labelGroupType }}
            <span v-if="label.labelGroupType == '系统标签'" class="prompt-text">系统标签不支持手动修改</span>
          </div>
          <div class="detail-label">
            <div v-if="label.labelGroupType !== '系统标签' && customerId == 0" class="no-label">
              <div class="btn text-center" @click="handleTag(label.labelGroupType)">
                <van-icon name="plus" class="plus" />
                <span>标签</span>
              </div>
            </div>
            <div class="has-label" v-if="label.isShow && label.children.length > 0">
              <template v-for="(i, index) in label.children">
                <div class="label-box" :key="index">
                  <div class="label-title">{{ i.labelGroupInfo.labelGroupName }}</div>
                  <div v-for="item in i.labelInfoList" :key="item.id" class="label-text text-center">{{ item.labelName }}</div>
                </div>
              </template>
              <!-- <div class="btn-box">
                <div class="btn text-center" @click="handleTag">
                  <van-icon name="plus" class="plus" />
                  <span>标签8888</span>
                </div>
              </div> -->
            </div>
          </div>
          <template v-if="label.children.length > 0">
            <div class="detail-more text-center" @click="moreInfoLabel(ids)">
              <div class="btn text-center">
                {{ label.isShow ? '收起' : '展开全部' }}
                <div :class="['sprite-icon', 'icon-open-arrow', { more: label.isShow }]"></div>
              </div>
            </div>
          </template>
        </div>
      </template>
    </template>

    <div class="detail-bg detail-fourth">
      <div class="title">所属群聊</div>
      <div class="detail-group">
        <div v-if="userInfo.customerBases.length == 0" class="no-data">暂无数据</div>
        <div v-else>
          <div v-for="itm in userInfo.customerBases" :key="itm.id" class="group-item">
            <div class="group-avatar">
              <img src="@/assets/images/bases.png" />
            </div>
            <div class="name">{{ itm.groupName }}({{ itm.membersNumber }})</div>
          </div>
        </div>
      </div>
    </div>
    <template v-if="!userAgent && isTrue">
      <div class="button" @click="goBack">返回</div>
    </template>

    <van-popup v-model="showDatePicker" position="bottom" round>
      <van-datetime-picker v-model="selectDate" type="date" title="选择年月日" :min-date="minDate" :max-date="maxDate" @confirm="confirmDate" @cancel="showDatePicker = false" />
    </van-popup>
    <make @success="successHandle" :externalUserIds="[id]" :chooseItems="userInfo.labelInfos" :isCustomer="false" ref="popRefs"></make>
  </div>
</template>

<script>
import make from '@/views/tag/make.vue'
import { detailApi, wxConfig, entmicroApi } from '@/api'
import { Dialog } from 'vant'
export default {
  components: { make },
  data() {
    return {
      labelType: '',
      flag: false,
      isMore: false,
      labels: [],
      userInfo: {
        labels: [],
        vehicleInfo: {},
        customerBases: [],
        info: {}
      },
      staffNameList: '',
      customerSex: {
        0: '性别未知',
        1: '男',
        2: '女'
      },
      merchantModel: '',
      labelArray: [],
      detailObj: [
        {
          title: '添加时间',
          value: obj => {
            return obj.info.addTime
          }
        },
        {
          title: '来源',
          value: obj => {
            return obj.info.addWayName
          }
        },
        {
          title: '联系电话',
          type: 'tel',
          value: obj => {
            return obj.info.customerPhone
          },
          placeholder: '请输入',
          save_key: 'customerPhone',
          maxlength: 11,
          key: 'customerPhone'
        },
        {
          title: '车牌号',
          type: 'platNumber',
          value: obj => {
            return obj.vehicleInfo.vehicleNo
          },
          save_key: 'audi',
          placeholder: '请输入',
          // placeholder: '',
          key: 'vehicleTrain',
          maxlength: 10
        },
        {
          title: '购车日期',
          type: 'date',
          value: obj => {
            return obj.vehicleInfo.buyTime
          },
          save_key: 'buyDate',
          // placeholder: '请选择',
          placeholder: '',
          key: 'buyTime'
        },
        {
          title: '近期保养日期',
          type: 'date',
          value: obj => {
            return obj.vehicleInfo.maintRecTime
          },
          save_key: 'maintenanceDate',
          // placeholder: '请选择',
          key: 'maintRecTime'
        },
        {
          title: '近期到店日期',
          type: 'date',
          value: obj => {
            return obj.vehicleInfo.recReachTime
          },
          save_key: 'arrivalDate',
          // placeholder: '请选择',
          placeholder: '',
          key: 'recReachTime'
        },
        {
          title: '商业险到期日期',
          type: 'date',
          value: obj => {
            return obj.vehicleInfo.insEndTime
          },
          save_key: 'comInsuranceEndtime',
          // placeholder: '请选择',
          placeholder: '',
          key: 'insEndTime'
        },
        {
          title: '车架号',
          type: 'standNo',
          value: obj => {
            return obj.vehicleInfo.standNo
          },
          save_key: 'audi',
          // placeholder: '请输入',
          placeholder: '',
          key: 'vehicleTrain',
          maxlength: 17
        },
        {
          title: '品牌车型', //品牌 车系 车型
          type: 'text',
          special: 'special',
          value: obj => {
            return obj.vehicleInfo.vehicleBrand
          },
          valueTrain: obj => {
            return obj.vehicleInfo.vehicleTrain
          },
          valueType: obj => {
            return obj.vehicleInfo.vehicleType
          },
          save_key: 'audi',
          // placeholder: '请输入',
          placeholder: '',
          key: 'vehicleTrain',
          maxlength: 50
        }
      ],
      id: '',
      showDatePicker: false,
      maxDate: new Date(),
      selectDate: new Date(),
      minDate: new Date(2002, 1, 1),
      target: '',
      customerId: 0, //默认是客户显示打标签按钮
      userAgent: false,
      isTrue: false
    }
  },
  created() {
    this.merchantModel = this.getLocalStorage('dj_scrm_userInfo').merchantModel ? this.getLocalStorage('dj_scrm_userInfo').merchantModel : ''
  },
  activated() {
    this.watchPageBack().then(() => {
      this.showToast('更新成功', () => {
        this.showLoading()
        this.getCustomerDetail(this.id)
      })
    })
  },
  mounted() {
    this.userAgent = this.isMobile()
    this.showLoading()
    let { id, customerId, isTrue, sessionId } = this.getQuery()
    if (sessionId) id = window.localStorage.getItem('dj_scrm_id') && JSON.parse(window.localStorage.getItem('dj_scrm_id')).id
    // console.log(id,'测试测试')
    // id = 'wo_pmOEQAAr93aXGLTNtAjLGZZxpwXuQ'
    if (id || isTrue) {
      this.id = id
      this.isTrue = isTrue
      // this.customerId = customerId //用来判断。若员工尚未添加该客户为好友,则暂不允许在客户跟进中修改客户的信息,仅只读。
      this.getCustomerDetail(id)
    } else {
      wxConfig.init(['getCurExternalContact']).then(() => {
        wxConfig
          .getCurExternalContact()
          .then(userId => {
            this.id = userId
            this.getCustomerDetail(userId)
          })
          .catch(e => {
            this.hideLoading()
            // Dialog.alert({
            //   title: '提示',
            //   message: '该功能暂不支持在群侧边栏打开',
            //   confirmButtonText: '知道了',
            //   confirmButtonColor: '#3975c6'
            // }).then(() => {
            //   wx.closeWindow()
            // })
            this.$router.push({ name: 'customer.groupDetail' })
          })
      })
    }
  },
  methods: {
    isMobile() {
      if (window.navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i)) {
        return true // 移动端
      } else {
        return false // PC端
      }
    },
    goBack() {
      this.$router.back()
    },
    moreInfo() {
      let {
        info: { customerPhone },
        vehicleInfo: { vehicleNo }
      } = this.userInfo
      this.customerId = 0
      if (!customerPhone && !vehicleNo && this.customerId == 0) {
        this.showToast('请完善客户的联系电话或车牌号,系统将自动关联更多的客户信息')
        return
      }
      this.isMore = !this.isMore
    },
    moreInfoLabel(index) {
      this.labelArray[index].isShow = !this.labelArray[index].isShow
    },
    getCustomerDetail(userId) {
      setTimeout(() => {
        this.hideLoading()
        detailApi.getCustomerDetail({ userId }).then(res => {
          if (res) {
            this.flag = true
            let staffNameList = []
            if (res.staffFollows) {
              res.staffFollows.map(e => {
                staffNameList.push(e.staffName)
              })
            }
            if (res.vehicleInfoList && res.vehicleInfoList.length) res.vehicleInfo = res.vehicleInfoList[0]
            this.staffNameList = staffNameList.join('、')
            Object.keys(res).map(key => {
              if (res[key]) this.userInfo[key] = res[key]
            })
            this.initLabel()
          }
        })
      }, 3000)
    },
    //标签分组
    initLabel() {
      let labelArray = [
        {
          labelGroupType: '企业标签',
          children: [],
          isShow: false
        },
        {
          labelGroupType: '自店标签',
          children: [],
          isShow: false
        },
        {
          labelGroupType: '系统标签',
          children: [],
          isShow: false
        }
      ]

      this.userInfo.labelInfos &&
        this.userInfo.labelInfos.forEach(ele => {
          labelArray.forEach(label => {
            if (ele.labelGroupInfo.labelGroupType == label.labelGroupType) {
              label.children.push(ele)
            }
          })
        })
      // console.log(labelArray)
      this.labelArray = labelArray
    },
    setDetail({ type, title, save_key, maxlength }) {
      let {
        detailObj,
        userInfo: { vehicleInfo, info }
      } = this
      let userId = this.id
      if (this.customerId == -1) return
      if (type == 'tel' || type == 'platNumber') {
        if (info.customerPhone && save_key == 'customerPhone') return
        if (vehicleInfo.vehicleNo && save_key == 'audi') return
        let name = type == 'platNumber' ? 'customer.editPlat' : 'customer.editDetail'
        this.$router.push({
          name,
          params: {
            title,
            type,
            save_key,
            userId,
            maxlength,
            vehicleInfo,
            detailObj,
            info
          }
        })
      } else {
        Dialog.alert({
          title: '提示',
          message: '客户信息修改功能即将上线,敬请期待',
          confirmButtonText: '知道了',
          confirmButtonColor: '#3975c6'
        }).then(() => {
          // wx.closeWindow()
        })
      }
      // if (type) {
      //   if (type != 'date') {
      //     if (info.customerPhone && save_key == 'customerPhone') return
      //     this.$router.push({
      //       name: 'customer.editDetail',
      //       params: {
      //         title,
      //         type,
      //         save_key,
      //         userId,
      //         maxlength,
      //         vehicleInfo,
      //         detailObj,
      //         info
      //       }
      //     })
      //   } else {
      //     let now = new Date()
      //     this.maxDate = save_key == 'comInsuranceEndtime' ? new Date(now.getFullYear() + 2, now.getMonth() + 1, now.getDate()) : now
      //     this.showDatePicker = true
      //     this.target = save_key
      //   }
      // }
    },
    confirmDate(e) {
      let {
        target,
        id,
        detailObj,
        userInfo: { vehicleInfo, info }
      } = this
      let staffUserId = this.getLocalStorage('dj_scrm_userInfo').workUserId
      this.showDatePicker = false
      let obj = {
        customerPhone: info.customerPhone,
        customerSex: info.customerSex
      }
      if (vehicleInfo) {
        Object.keys(vehicleInfo).map(i => {
          if (vehicleInfo[i]) {
            detailObj.map(k => {
              if (k.key == i && target != k.save_key) {
                if (!obj[k.save_key]) obj[k.save_key] = k.type == 'date' ? vehicleInfo[i].replace(/-/g, '/') : vehicleInfo[i]
              }
            })
          }
        })
      }
      entmicroApi
        .editCustomer({
          staffUserId,
          userId: id,
          [target]: new Date(e).format('yyyy/MM/dd'),
          ...obj
        })
        .then(res => {
          this.showToast('更新成功', () => {
            this.showLoading()
            this.getCustomerDetail(id)
          })
        })
    },
    handleTag(labelType) {
      this.$refs.popRefs.labelType = labelType
      this.$refs.popRefs.clearData()
      this.$refs.popRefs.toggle()
    },
    successHandle() {
      let { id } = this
      this.showLoading()
      setTimeout(() => {
        this.$refs.popRefs.toggle()
        this.getCustomerDetail(id)
      }, 1000)
    }
  }
}
</script>

<style lang="scss" scope>
.layout {
  padding-bottom: 60px;
}
.detail-bg {
  background-color: #fff;
  border-radius: 4px;
  box-shadow: 0px 4px 8px 0px rgba(224, 224, 224, 0.5);
}
.detail-first {
  padding: 22px 10px 0;
  margin: 10px 16px;
  .detail-customer {
    display: flex;
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
    padding: 0 10px 21px;
    .avatar {
      width: 44px;
      height: 44px;
      flex-shrink: 0;
    }
    &-name {
      font-size: 16px;
      margin-left: 16px;
      color: #333;
      .name {
        font-weight: 600;
        margin-right: 6px;
      }
      .wechat {
        color: #3975c6;
      }
      div {
        font-size: 14px;
      }
    }
  }
  .detail-member {
    display: flex;
    align-items: center;
    font-size: 14px;
    min-height: 42px;
    color: #333;
    .name {
      color: #999;
      padding: 0 10px 0 0;
      margin-right: 10px;
      position: relative;
      flex-shrink: 0;
      &::after {
        content: '';
        display: block;
        width: 1px;
        height: 14px;
        position: absolute;
        right: 0;
        top: 50%;
        transform: translateY(-50%);
        background-color: #999;
      }
    }
    .name-list {
      width: calc(100% - 80px);
      word-break: break-all;
      padding: 10px 0;
    }
  }
}
.detail-second {
  box-shadow: 0px 4px 8px 0px rgba(224, 224, 224, 0.5);
  margin: 0 16px;
  background-color: #fff;
  .cell-title {
    width: 120px;
    flex: none;
  }
  .van-cell-group {
    transition: all 0.5s;
    // min-height: 540px;
    max-height: 1000px;
    overflow: hidden;
  }
  .van-cell {
    min-height: 60px !important;
    align-items: center;
    .van-cell__value {
      color: #333333;
    }
  }
  .more-hidden {
    max-height: 240px;
  }
  .placeholder {
    color: #ccc;
  }
  .detail-more {
    border-radius: 0 0 4px 4px;
    color: #999;
    font-size: 12px;
    text-align: center;
    line-height: 18px;
    padding: 6px 0 14px;
    position: relative;
    z-index: 2;
    background-color: #fff;
    top: -1px;
    .btn {
      width: 108px;
      height: 21px;
      border-radius: 12px;
      border: 1px solid #3975c6;
      color: #3975c6;
      font-size: 12px;
      .sprite-icon {
        margin-left: 4px;
        transition: all 0.5s;
      }
      .more {
        transform: rotate(-180deg);
      }
    }
  }
}
.detail-third {
  margin: 10px 16px;
  padding: 10px 16px 16px 16px;
  position: relative;
  .title {
    font-size: 16px;
    color: #333;
    font-weight: 600;
    line-height: 22px;
    .prompt-text {
      font-size: 12px;
      font-weight: 400;
      color: #666666;
      line-height: 17px;
      margin-left: 6px;
    }
  }
  .detail-label {
    .no-label {
      position: absolute;
      top: 10px;
      right: 16px;
      z-index: 99;
      // top: 50%;
      // left: 50%;
      // transform: translate(-50%, -50%);
    }
    .btn {
      width: 60px;
      height: 24px;
      background: #3975c6;
      box-shadow: 0px 2px 6px 2px rgba(57, 117, 198, 0.11);
      border-radius: 11px;
      border: 1px solid #3975c6;
      box-sizing: border-box;
      color: #fff;
      font-size: 12px;
      .plus {
        margin-right: 4px;
      }
    }
    .has-label {
      .btn-box {
        display: flex;
        justify-content: flex-end;
        padding-top: 20px;
      }
      .label-box {
        .label-title {
          font-size: 14px;
          color: #666666;
          margin: 16px 0 8px;
        }
      }
    }
    .label-text {
      display: inline-flex;
      margin: 0 6px 6px 0;
      border-radius: 14px;
      background-color: rgba(57, 117, 198, 0.15);
      font-size: 14px;
      color: #3975c6;
      padding: 4px 12px;
      box-sizing: border-box;
    }
  }
  .detail-more {
    border-radius: 0 0 4px 4px;
    color: #999;
    font-size: 12px;
    text-align: center;
    line-height: 18px;
    padding: 20px 0 0 0;
    position: relative;
    z-index: 2;
    background-color: #fff;
    top: -1px;
    .btn {
      width: 108px;
      height: 21px;
      border-radius: 12px;
      border: 1px solid #3975c6;
      color: #3975c6;
      font-size: 12px;
      .sprite-icon {
        margin-left: 4px;
        transition: all 0.5s;
      }
      .more {
        transform: rotate(-180deg);
      }
    }
  }
}
.detail-fourth {
  margin: 10px 16px 36px 10px;
  padding: 10px 16px 0;
  .title {
    font-weight: 700;
  }
  .detail-group {
    min-height: 81px;
    position: relative;
    margin-top: 4px;
    .no-data {
      position: absolute;
      left: 50%;
      top: 50%;
      transform: translate(-50%, -50%);
      font-size: 12px;
      color: #999;
    }
    .group-item {
      display: flex;
      align-items: center;
      padding: 17px 0;
      border-bottom: 1px solid rgba(0, 0, 0, 0.1);
      &:last-child {
        border-bottom: none;
      }
      .group-avatar {
        width: 44px;
        height: 44px;
        background-color: #e1e1e1;
        .sprite-icon {
          width: 100%;
          height: 100%;
        }
      }
      .name {
        font-size: 16px;
        color: #333;
        font-weight: 500;
        margin-left: 10px;
      }
    }
  }
}
</style>