index.vue 11 KB
<template>
  <div>
    <div class="scrm-sub-client-container">
      <!-- <p class="pageTitle">客户群管理</p> -->
      <div class="pageContent">
        <search-form class="searchTop border-shadow" :isHasSyncBtn="true" :showDefaultTime="false" :merchantModel="merchantModel" :accountLevel="accountLevel" :formModel="searchForm" :formList="clientGroupFormList" @setTableHeightEvent="setTableHeightEvent" @resetTable="resetTable" @searchTable="searchTable" @handleExport="handleExport" @syncClick="syncClick">
          <span class="inline-b" slot="form-slot">
            <el-button plain @click="resetTable">重置</el-button>
            <el-button type="primary" @click="searchTable">查询</el-button>
            <el-button type="primary" @click="handleExport">导出</el-button>
            <!-- v-if="(merchantModel == 1 && accountLevel == 1) || (merchantModel == 2 && accountLevel == 4)"允许所有人同步 -->
            <!-- <el-button type="primary" @click="syncClick" :loading="sloading">同步数据</el-button> -->
          </span>
        </search-form>

        <GLTable @setTableFinishFun="setTableFinishFun" v-if="isReload" ref="clientGroupManage" :hasNum="true" :getListApi="getListApi" :beforeSearchFn="beforeSearchFn" :noDataImg="url" :pageConf="pageConf" :searchForm="searchFormTable" :tableParams="tableParams">
          <span slot="status" slot-scope="scope">
            <!-- <span class="dot" :class="scope.scope.enableStatus ? DICTSTATUS[scope.scope.enableStatus].split(',')[1] : ''"></span> -->
            <span class="statusText" :class="scope.scope.status ? CLIENTSTATUS[scope.scope.status].split(',')[1] : ''">{{ scope.scope.status ? CLIENTSTATUS[scope.scope.status].split(',')[0] : '--' }}</span>
          </span>
          <template slot="auth-button" slot-scope="scope" :data="scope.scope">
            <!-- <auth-button :data="scope.scope"></auth-button> -->
            <span @click="goDetail(scope.scope.id, scope.scope.custGroupName)" class="blue-text">详情</span>
            <!-- <GLButton  @click="goDetail(scope.scope.id, scope.scope.custGroupName)" fn="客户群详情" type="text">详情</GLButton>   -->
          </template>
        </GLTable>
      </div>
    </div>
  </div>
</template>

<script>
import { getTableList, syncCustomerBase, getStatus, clientGroupExportApi } from '@/api/modules/clientGroupManage'
import url from '@/assets/clientDataOverview/nodata.png'
export default {
  name: 'clientGroupManage',
  // inject: ['reload'],
  data() {
    return {
      isReload: true,
      url: url,
      sloading: false,
      searchForm: {},
      searchFormTable: {},
      clientGroupFormList: [
        {
          type: 'daterange',
          prop: 'daterange',
          label: '创建时间',
          pickerOptions: {
            disabledDate(time) {
              return time.getTime() > Date.now() || time.getTime() < new Date('2017-12-31').getTime()
            }
          }
        },
        {
          type: 'input',
          inputType: 'text',
          prop: 'custGroupName',
          label: '群聊名称',
          placeholder: '请输入群聊名称'
        },
        {
          type: 'input',
          inputType: 'text',
          prop: 'groupHostName',
          label: '群主',
          placeholder: '请输入群主'
        },
        {
          type: 'input',
          inputType: 'text',
          prop: 'groupAdminName',
          label: '管理员',
          placeholder: '请输入管理员'
        },
        {
          type: 'select',
          prop: 'creationMethod',
          label: '创建方式',
          placeholder: '请选择',
          options: [
            {
              label: '全部',
              value: null
            },
            {
              label: '手动拉群',
              value: 1
            },
            {
              label: '一客一群',
              value: 2
            }
          ]
        }
      ],
      pageConf: { pageSize: 'pageSize', pageNum: 'pageNum', totalCount: 'count' },
      tableParams: {
        btnId: new Date().getTime() + parseInt(Math.random() * 1000),
        listName: 'data',
        tableColumns: [
          {
            label: '群聊名称',
            prop: 'custGroupName',
            minWidth: 160
          },
          {
            label: '当前成员总数',
            prop: 'allMembers',
            minWidth: 140
          },
          {
            label: '当前客户数',
            prop: 'totalCount',
            minWidth: 100
          },
          {
            label: '当日新增入群客户数',
            prop: 'newCustomerCount',
            minWidth: 160
          },
          {
            label: '当日新增退群客户数',
            prop: 'delCustomerCount',
            minWidth: 160
          },
          {
            label: '当前跟进员工数',
            prop: 'staffs',
            minWidth: 140
          },
          {
            label: '群主',
            prop: 'groupHostName'
          },
          {
            label: '管理员',
            prop: 'groupAdminName'
          },
          {
            label: '创建方式',
            prop: 'creationMethod',
            formatter: cellValue => {
              return cellValue.creationMethod == 1 ? '手动拉群' : cellValue.creationMethod == 2 ? '一客一群' : ''
            },
            minWidth: 140
          },
          {
            label: '创建时间',
            prop: 'addTime',
            width: 95
          }
        ],
        tableOption: {
          width: 170
          // btnList: [
          //   {
          //     name: '详情',
          //     // pType: 'detail'
          //   }
          // ]
        }
      },
      getListApi: getTableList,

      merchantModel: 1,
      accountLevel: 0, //1,2,3,4工厂,省代,市代,门店
      flushTime: false
    }
  },
  // activated() {
  //   this.searchTable()
  // },
  created() {
    if (window.__POWERED_BY_QIANKUN__) {
      //运行在qiankun容器中
      this.merchantModel = this.$globalState.session.merchantModel
      this.accountLevel = this.$globalState.session.accountLevel
    }
  },
  // watch: {
  //   'searchForm.daterange':{
  //     deep: true,
  //     handler(val) {
  //       console.log('val值:',val)
  //       if(val){
  //         this.searchTable()
  //       }
  //     }
  //   }
  // },
  beforeDestroy() {
    this.$message.closeAll()
  },
  mounted() {
    this.wxTips()
  },
  methods: {
    jumpWx() {
      this.$history.push('/settings/enterpriseWechat/index')
    },
    wxTips() {
      const menu = JSON.parse(sessionStorage['SCRM_BASE_MENULIST'])
      menu.forEach(item => {
        if (!item.children) {
          return
        }
        item.children.forEach(itm => {
          if (itm.path == '/enterpriseWechat/index') {
            getStatus({}).then(res => {
              if (res.status != 'SUCCESS') {
                const h = this.$createElement
                this.$message({
                  showClose: true,
                  duration: 0,
                  message: h('p', null, [h('span', null, '此功能需完成【企业微信授权】后方可使用! '), h('span', { on: { click: this.jumpWx }, style: { marginRight: '150px', cursor: 'pointer', color: '#5850ff' } }, ['企业微信授权 ', h('i', { class: 'el-icon-d-arrow-right' }, '')])])
                })
              }
            })
          }
        })
      })
    },
    syncClick() {
      let _this = this
      _this.sloading = true
      syncCustomerBase({})
        .then(res => {
          if (!res) {
            return
          }
          _this.sloading = false
          this.$message.success('已同步客户群')
          this.$refs.clientGroupManage.refreshTable()
        })
        .catch(err => {
          _this.sloading = false
        })
        .finally(() => {
          _this.sloading = false
        })
    },
    setTableHeightEvent() {
      this.$refs.clientGroupManage.setTableHeightFun()
    },
    setTableFinishFun(content) {
      console.log(content, this.$refs.clientGroupManage.data.length, '获取数据')
      // if (!this.flushTime) {
      //   this.flushTime = true
      //   this.searchTable()
      // }

      //接收到的数据为空
      // if (!this.$refs.clientGroupManage.data.length) {
      //   this.$refs.clientGroupManage.setTableHeightFun()
      // }
      this.$refs.clientGroupManage.data.length ? (this.$refs.clientGroupManage.tableHeightValues = '') : this.$refs.clientGroupManage.setTableHeightFun()
    },
    //导出
    handleExport() {
      var params = this.getParams()
      clientGroupExportApi(params).then(res => {
        this.$Utils.exportFn(res)
      })
    },
    searchTable() {
      this.$refs.clientGroupManage.refreshTable()
    },
    getParams() {
      var params = JSON.parse(JSON.stringify(this.searchForm))
      if (params.daterange) {
        params.beginTime = this.searchForm.daterange[0]
        params.endTime = this.searchForm.daterange[1]
      } else {
        if (params.beginTime) delete params.beginTime && delete params.endTime
      }
      delete params.daterange
      return params
    },
    beforeSearchFn() {
      // return new Promise((resolve, reject) => {
      //   this.searchFormTable = JSON.parse(JSON.stringify(this.searchForm))
      //   if (this.searchFormTable.daterange) {
      //     this.searchFormTable.beginTime = this.searchForm.daterange[0]
      //     this.searchFormTable.endTime = this.searchForm.daterange[1]
      //     delete this.searchFormTable.daterange
      //   } else {
      //     if (this.searchFormTable.beginTime) delete this.searchFormTable.beginTime && delete this.searchFormTable.endTime
      //   }
      //   resolve()
      // })
      return new Promise((resolve, reject) => {
        this.searchFormTable = this.getParams()
        resolve()
      })
    },

    resetTable() {
      this.isReload = false
      this.searchForm = {}
      this.$nextTick(() => {
        this.isReload = true
      })
    },
    goDetail(id, name) {
      this.$router.push({
        path: '/clientGroupManage/clientGroupDetail',
        query: {
          id: id,
          groupName: name
        }
      })
    }
  }
}
</script>
<style lang="scss" scoped>
@import '@/styles/variables.scss';
@import '@/styles/resetelement.scss';
.scrm-sub-client-container {
  .pageTitle {
    position: relative;
    margin-bottom: 20px;
    height: 20px;
    font-size: 20px;
    font-weight: 700;
    color: #333333;
    line-height: 20px;
    letter-spacing: 1px;
  }
  .pageContent {
    .glsx-table {
      /deep/ .el-table__fixed,
      /deep/ .el-table__fixed-right {
        height: 100% !important; //设置高优先,以覆盖内联样式
      }
    }
    padding: 6px 20px 30px;
    box-shadow: 0 10px 20px 0 rgba(88, 80, 255, 0.1);
    // min-width: 1300px;
    background-color: #fff;
    .el-button + .el-button {
      margin-left: 10px;
    }
  }
  .el-message--info {
    height: 40px;
    background: #e6e9ff;
    border: 1px solid $btnBlue;
    border-radius: 4px;
    font-size: 14px;
    color: rgba(0, 0, 0, 0.65);
  }
  .el-message .el-icon-info {
    color: $btnBlue;
    font-size: 16px;
  }
}
</style>