index.vue 10.6 KB
<template>
  <div>
    <div class="scrm-sub-client-container">
      <!-- <p class="pageTitle">客户管理</p> -->
      <div class="pageContent">
        <search-form :ploading="sloading" :isHasSyncBtn="true" class="searchTop border-shadow" :formModel="searchForm" :formList="clientManageFormList" @setTableHeightEvent="setTableHeightEvent" @resetTable="resetTable" @searchTable="searchTable" @syncClick="syncClick">
          <span class="inline-b" slot="form-slot">
            <!-- :id="tableParams.btnId" -->
            <el-button plain @click="resetTable">重置</el-button>
            <el-button type="primary" @click="searchTable">查询</el-button>
            <el-button type="primary" @click="syncClick" :loading="sloading">同步数据</el-button>
          </span>
        </search-form>

        <GLTable ref="clientManage" :hasNum="true" :getListApi="getListApi" :beforeSearchFn="beforeSearchFn" :searchForm="searchFormTable" :noDataImg="url" :pageConf="pageConf" :tableParams="tableParams" :headerStyle="{ height: '54px', background: '#F4F6FC', color: '#333333', fontSize: '14px' }">
          <span slot="customerName" slot-scope="scope">
            <el-tooltip effect="dark" :content="scope.scope.customerName" placement="top">
              <span class="ellipsis-1" style="display: inline-block; max-width: 70px; text-align: left">{{ scope.scope.customerName }}</span>
            </el-tooltip>

            <span class="pure-blue-text">{{ scope.scope.type == 1 ? '@微信' : scope.scope.type == 2 ? '@企微' : '' }}</span>
          </span>
          <span slot="customerSex" slot-scope="scope">
            <span>{{ scope.scope.customerSex == 0 ? '未知' : scope.scope.customerSex == 1 ? '男' : '女' }}</span>
          </span>
          <span slot="customerPhone" slot-scope="scope">
            <span>{{ scope.scope.customerPhone == 'null' ? '' : scope.scope.customerPhone }}</span>
          </span>

          <span slot="addWay" slot-scope="scope">
            <el-tooltip effect="dark" :content="toLabel(scope.scope.addWay)" placement="top">
              <span style="display: inline-block; max-width: 120px; text-align: left">{{ toLabel(scope.scope.addWay) }}</span>
            </el-tooltip>
          </span>

          <span slot="isJoin" slot-scope="scope">
            <span>{{ scope.scope.isJoin ? '是' : '否' }}</span>
          </span>
          <span slot="status" slot-scope="scope">
            <!-- <span class="dot" :class="scope.scope.enableStatus ? DICTSTATUS[scope.scope.enableStatus].split(',')[1] : ''"></span> -->
            <span class="statusText" :class="{ 'red-text': scope.scope.status === -1, 'green-text': scope.scope.status == 0 }">{{ statusText(scope.scope.status) }}</span>
          </span>
          <template slot="auth-button" slot-scope="scope" :data="scope.scope">
            <!-- <auth-button :data="scope.scope"></auth-button> -->
            <span @click="goDetail(scope.scope.oneId)" class="blue-text">详情</span>
          </template>
        </GLTable>
      </div>
    </div>
  </div>
</template>

<script>
import { getTableList, getDictionaryFun, syncCustomer } from '@/api/modules/clientManage'
import url from '@/assets/clientDataOverview/nodata.png'
export default {
  name: 'clientManage',
  data() {
    return {
      url: url,
      sloading: false,
      CLIENTSTATUS: this.$Constants.CLIENT_STATUS,
      searchForm: {},
      searchFormTable: {},
      clientManageFormList: [
        {
          type: 'daterange',
          prop: 'daterange',
          label: '添加时间',
          pickerOptions: {
            disabledDate(time) {
              return time.getTime() > Date.now() || time.getTime() < new Date('2017-12-31').getTime()
            }
          }
        },
        {
          type: 'select',
          prop: 'status',
          label: '当前状态',
          placeholder: '请选择当前状态',
          options: [
            {
              label: '全部',
              value: null
            },
            {
              label: '正常',
              value: 0
            },
            {
              label: '删除好友',
              value: -1
            }
          ]
        },
        {
          type: 'select',
          prop: 'isJoin',
          label: '是否已加企微',
          placeholder: '请选择',
          options: [
            {
              label: '全部',
              value: null
            },
            {
              label: '是',
              value: 1
            },
            {
              label: '否',
              value: 0
            }
          ]
        },
        {
          type: 'select',
          prop: 'addWay',
          label: '来源',
          placeholder: '请选择当前来源',
          options: [] //this.$Constants.SOURCE_OPTION
        },
        {
          type: 'select',
          prop: 'customerSex',
          label: '性别',
          placeholder: '请选择性别',
          options: this.$Constants.GENDER_OPTION
        },
        {
          type: 'input',
          inputType: 'text',
          prop: 'customerPhone',
          label: '手机号',
          placeholder: '请输入手机号'
        },
        {
          type: 'input',
          inputType: 'text',
          prop: 'customerName',
          label: '客户名称',
          placeholder: '请输入客户名称'
        },
        {
          type: 'input',
          inputType: 'text',
          prop: 'followStaff',
          label: '跟进员工',
          placeholder: '请输入跟进员工'
        }
      ],
      pageConf: { pageSize: 'pageSize', pageNum: 'pageNum', totalCount: 'count' },
      tableParams: {
        // btnId: new Date().getTime() + parseInt(Math.random() * 1000),
        listName: 'data',
        // tableOption: true,
        tableColumns: [
          {
            label: 'User_id',
            prop: 'oneId',
            width: 180
          },
          {
            label: '客户名称',
            prop: 'customerName',
            addHtml: 'customerName',
            width: 180
          },
          {
            label: '手机号',
            prop: 'customerPhone',
            addHtml: 'customerPhone'
          },
          {
            label: '性别',
            prop: 'customerSex',
            addHtml: 'customerSex',
            width: 80
          },
          {
            label: '跟进员工',
            prop: 'followStaff'
          },
          {
            label: '来源',
            prop: 'addWay',
            addHtml: 'addWay'
          },
          {
            label: '是否加企微', //1. 加入,0.未加入
            prop: 'isJoin',
            addHtml: 'isJoin',
            width: 95
          },
          {
            label: '当前状态',
            prop: 'status',
            addHtml: 'status',
            width: 80
          },
          {
            label: '添加时间',
            prop: 'addTime',
            width: 188
          }
        ],
        tableOption: {
          width: 80,
          btnList: [
            {
              name: '详情',
              pType: 'detail'
            }
          ]
        }
      },
      getListApi: getTableList,
      sourceList: []
    }
  },
  created() {
    this.getDictionaryFun()
  },

  methods: {
    statusText(text) {
      return text === -1 ? '删除好友' : text === 0 ? '正常' : ''
    },
    setTableHeightEvent() {
      this.$refs.clientManage.setTableHeightFun()
    },
    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]
        } else {
          if (this.searchFormTable.beginTime) delete this.searchFormTable.beginTime && delete this.searchFormTable.endTime
        }
        delete this.searchFormTable.daterange
        resolve()
      })
    },
    getDictionaryFun() {
      getDictionaryFun({ dictType: 'add_way' }).then(res => {
        if (!res) {
          return
        }
        let data = res.map(item => {
          return {
            ...item,
            label: item.dictLabel,
            value: item.dictValue
          }
        })
        data.unshift({ label: '全部', value: '' })

        this.sourceList = data || []
        if (data && data.length > 0) {
          window.localStorage.setItem('sourceList', JSON.stringify(data))
        }
        this.$set(this.clientManageFormList[3], 'options', data)
        // if (res.code == 0) {
        //   console.log('shuju', res)
        // } else {
        //   this.$meesage({
        //     type: 'error',
        //     message: res.data.message
        //   })
        // }
      })
    },
    //来源 value值转为对应label
    toLabel(value) {
      if (value !== 0 && !value) {
        return
      }
      let curElement = this.sourceList.find(item => {
        return item.value === value
      })

      return curElement.label
    },
    //搜索表格
    searchTable() {
      this.$refs.clientManage.refreshTable()
    },
    syncClick() {
      let _this = this
      _this.sloading = true
      syncCustomer({})
        .then(res => {
          if (!res) {
            return false
          }
          _this.sloading = false
          _this.$message.success('已同步客户')
          _this.$refs.clientManage.refreshTable()
        })
        .catch(err => {
          _this.sloading = false
        })
    },
    //重置表格
    resetTable() {
      this.searchForm = {}
      this.$refs.clientManage.refreshTable()
    },
    goDetail(id) {
      this.$router.push({
        path: '/clientManage/clientDetail',
        query: {
          id: id
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
@import '@/styles/variables.scss';
@import '@/styles/resetelement.scss';
.scrm-sub-client-container {
  .pageTitle {
    margin-bottom: 20px;
    position: relative;
    height: 20px;
    font-size: 20px;
    font-weight: 700;
    color: #333333;
    line-height: 20px;
    letter-spacing: 1px;
  }
  .pageContent {
    padding: 6px 20px 30px;
    // min-width: 1300px;
    background-color: #fff;
    .el-button + .el-button {
      margin-left: 20px;
    }
    // .el-button {
    //   font-size: 14px;
    //   font-weight: 400;
    //   padding: 9px 21px;
    //   background: $btnBlue;
    //   border-radius: 4px;
    //   border: none;
    // }
    // .el-button:first-child {
    //   background: #ffffff;
    //   border-radius: 4px;
    //   border: 1px solid #999999;
    //   font-weight: 400;
    //   color: #666666;
    // }
    // .glsx-table {
    //   margin-top: 20px;
    // }
  }
}
</style>