index.vue 8.12 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" @syncClick="syncClick">
          <span class="inline-b" slot="form-slot">
            <el-button plain @click="resetTable">重置</el-button>
            <el-button type="primary" @click="searchTable">查询</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 } from '@/api/modules/clientGroupManage'
import url from '@/assets/clientDataOverview/nodata.png'
export default {
  name: 'clientManage',
  // 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: '请输入管理员'
        }
      ],
      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: 'totalCount',
            minWidth: 100
          },
          {
            label: '新增入群客户数',
            prop: 'newCustomerCount',
            minWidth: 140
          },
          {
            label: '新增退群客户数',
            prop: 'delCustomerCount',
            minWidth: 140
          },
          {
            label: '新增群聊成员数',
            prop: 'allMembers',
            minWidth: 140
          },
          {
            label: '群聊员工数',
            prop: 'staffs',
            minWidth: 140
          },
          {
            label: '创建方式',
            prop: 'creationMethod',
            minWidth: 140
          },
          {
            label: '群主',
            prop: 'groupHostName'
          },
          {
            label: '管理员',
            prop: 'groupAdminName'
          },
          {
            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()
  //       }
  //     }
  //   }
  // },
  mounted() {},
  methods: {
    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()
    },
    searchTable() {
      this.$refs.clientGroupManage.refreshTable()
    },
    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()
      })
    },

    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 {
    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: 20px;
    }
  }
}
</style>