<!-- @desc:客户管理  @auth:付斌  @time:2024/1/30 15:15 -->
<template>
  <div class="main-div">

    <!--  按钮区域  -->
    <BaseIndexButtonGroup id="BaseIndexButtonGroup">
      <template #left>
        <BaseIndexButton ref="search" name="search"></BaseIndexButton>
        <BaseIndexButton ref="clear" name="clear"></BaseIndexButton>
        <BaseIndexButton ref="edit" name="edit"></BaseIndexButton>
        <BaseIndexButton ref="check" name="check"></BaseIndexButton>
      </template>
      <template #right>
        <BaseIndexButton ref="add" name="add"></BaseIndexButton>
      </template>
    </BaseIndexButtonGroup>

    <!--  卡片区  -->
    <div class="index-card">
      <!--  查询条件区域  -->
      <div id="search-cond-div" ref="search-cond-div" class="search-cond-class">
        <SearchCond ref="searchCond" v-model="searchCond"
                    @collapse-change="collapseChange" :setFlag="false"
                    :search-content="searchContent"></SearchCond>
      </div>
      <!--  table区域  -->
      <DkTabs ref="tab" v-model="tabsModel" :options="tabsOptions" @on-click="clickTab"></DkTabs>
      <DkTable :id="'table-'+$options.name" ref="table-select" :data="tableData"
               :height="this.tableHeight-60" primaryKey="cusId"
               @pageChange="pageSizeChange"
               :page-total="pageInfo.total"
               :page-size="pageInfo.pageSize"
               :page-size-opts="pageSizeOpts"
               :current-page="pageInfo.currentPage"
               :choose-flag="false"
               name="table">
        <DkTableColumn field="cusCode"></DkTableColumn>
        <DkTableColumn field="cusName"></DkTableColumn>
        <DkTableColumn field="cusPhone"></DkTableColumn>
        <DkTableColumn field="channelName"></DkTableColumn>
        <DkTableColumn field="addressFull"></DkTableColumn>
        <DkTableColumn field="contactName"></DkTableColumn>
        <DkTableColumn field="contactPhone"></DkTableColumn>
        <DkTableColumn field="orgName"></DkTableColumn>
        <DkTableColumn field="remarks"></DkTableColumn>
      </DkTable>
    </div>

    <!--    跟进任务-->
    <FollowTask v-model="followTaskModal" :customer-names="customerInfo6.cusNames"
                :customer-ids="customerInfo6.customerIds" @ok="initData(1)"
                ref="modal_follow_task"
    />

    <!--    跟进-->
    <Follow v-model="followModal" :goods-specs="goodsSpecsList" :customer-data="customerInfo"
            :goods-specs-list-back-up="goodsSpecsListBackUp"
            :intention-list="intentionList" :invite-result-list="inviteResultList" :follow-type-list="followTypeList"
            ref="modal_follow"
    ></Follow>
  </div>
</template>

<script>
import {indexMixin} from '@/mixins'

export default {
  name: 'customer',
  mixins: [indexMixin],
  data() {
    let self = this
    return {
      pullCondModal: false,
      ibossCustomersShow: false,//iboss客户资料弹窗
      //页面初始化标识
      created: false,
      // 客户信息
      customerInfo: {},
      // 客户信息 跟进任务
      customerInfo6: {
        customerIds: [],
        cusNames: [],
        followUsers: []
      },
      // 错误信息
      errMessage: {},
      // 跟进弹窗
      followModal: false,
      // 跟进任务弹窗
      followTaskModal: false,
      // 跟进方式list
      followTypeList: [],
      //  商品规格品类
      goodsSpecsList: [],
      //  商品规格品类备份
      goodsSpecsListBackUp: [],
      // 邀约结果list
      inviteResultList: [],
      // 意向list
      intentionList: [],
      // 合并弹窗
      mergeModal: false,
      // 合并目标
      mergeTarget: null,
      // 合并来源
      mergeSource: null,
      // 接待弹窗
      receptionModal: false,
      // 客成状态list
      saleStatusList: [],
      // 查询条件
      searchCond: {},
      searchContent: [
        {
          valueFormat: {code: 'cusName'},
          valueKind: 'STR'
        },
        {
          valueFormat: {code: 'cusPhone'},
          valueKind: 'STR'
        },
        {
          valueFormat: {code: 'contactName'},
          valueKind: 'STR'
        },
        {
          valueFormat: {code: 'contactPhone'},
          valueKind: 'STR'
        },
      ],
      tableData: [],
      tabsModel: self.$t('potentialCus'),
      tabsOptions: [
        {label: self.$t('potentialCus'), name: self.$t('potentialCus'), index: 0},
        {label: self.$t('seasCus'), name: self.$t('seasCus'), index: 1},
        {label: self.$t('dealCus'), name: self.$t('dealCus'), index: 2},
        {label: self.$t('allCustomers'), name: self.$t('allCustomers'), index: 3},
      ],
      //业务部门list
      orgList: [],
      ruleInline: {
        erpOrgCode: [
          {required: true, trigger: 'none', type: 'array'}
        ],
      },
      ibossCustomersFormData: {
        orgId: null,
        orgCode: null,
        orgName: null,
        erpOrgCode: null,
      },
      pageInfo: {
        total: 0,
        pageSize: 20,
        currentPage: 1
      },
    }
  },
  methods: {
    /**
     * @desc   : 点击tab
     * @author : 付斌
     * @date   : 2024-02-01 14:20
     */
    clickTab(val) {
      this.$nextTick(() => {
        //查询条件
        this.loading = true
        this.tableData = []
        this.pageInfo.currentPage = 1
        this.searchData()
      })
    },
    /**
     * @desc   : 打开跟进弹窗
     * @author : 付斌
     * @date   : 2024-02-01 14:20
     */
    follow(e) {
      this.followModal = true

    },
    /**
     * @desc   : 跟进任务
     * @author : 付斌
     * @date   : 2024-02-01 14:21
     */
    followTask() {
      this.followTaskModal = true
    },
    /**
     * @desc   : 查询参数设定
     * @author : 常皓宁
     * @date   : 2024/4/7 11:22
     */
    setSearchParams(params) {
      params.flgValid = true
      if (this.tabsModel === this.$t('allReceipt')) {
        params.saleStatus = ''
      } else if (this.tabsModel === this.$t('potentialCus')) {
        params.saleStatus = '销售状态-潜客'
      } else if (this.tabsModel === this.$t('seasCus')) {
        params.saleStatus = '销售状态-公海'
      } else if (this.tabsModel === this.$t('dealCus')) {
        params.saleStatus = '销售状态-成交'
      }
      return params
    },
    /**
     * @desc   : 查询数据
     * @author : 付斌
     * @date   : 2024-02-01 14:22
     */
    getData(params) {
      // 查询数据
      this.excute(this.$service.customerService, this.$service.customerService.selectByCond, params).then(res => {
        if (res.code === this.$config.SUCCESS_CODE) {
          this.tableData = res.data.list
          this.pageInfo.total = res.data.total
        }
      })
    },
  },
  created() {
    this.primaryKey = 'customerId'  // 设置主键Id
    this.routeObjName = 'customer'  // 设置路由名称
  }
}
</script>
