<!-- @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" :isMustChooseFlag="false"></BaseIndexButton>
        <BaseIndexButton ref="followTask" name="followTask" :isMustChooseFlag="false"></BaseIndexButton>
      </template>
      <template #right>
        <BaseIndexButton ref="add" name="add"></BaseIndexButton>
      </template>
    </BaseIndexButtonGroup>

    <!--  查询条件区域  -->
    <div id="search-cond-div" ref="search-cond-div" style="margin-top: 1px;padding: 0">
      <SearchCond ref="searchCond" v-model="searchCond"
                  @collapse-change="collapseChange" :setFlag="false"
                  :search-content="searchContent"></SearchCond>
    </div>
    <!--  table区域  -->
    <card style="padding: 0">
      <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-50" primaryKey="cusId"
               :page-size-opts="pageSizeOpts"
               :page-size="pageInfo.pageSize"
               :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="contactPhones"></DkTableColumn>
        <DkTableColumn field="orgName"></DkTableColumn>
        <DkTableColumn field="intentionTagsName"></DkTableColumn>
        <DkTableColumn field="customerClassifiedName" title="客户分类"></DkTableColumn>
        <DkTableColumn field="intentionQuantityTag"></DkTableColumn>
        <DkTableColumn field="saleStatusName"></DkTableColumn>
        <DkTableColumn field="customerTagNames"></DkTableColumn>
        <DkTableColumn field="opCreateTime"></DkTableColumn>
        <DkTableColumn field="nextFollowPlan"></DkTableColumn>
        <DkTableColumn field="nextFollowTime"></DkTableColumn>
        <DkTableColumn field="reportUserName"></DkTableColumn>
        <DkTableColumn field="followCount" :digits="0"></DkTableColumn>
        <DkTableColumn field="customerFromName"></DkTableColumn>
        <DkTableColumn field="toiletCountName"></DkTableColumn>
        <DkTableColumn field="fitupTypeName"></DkTableColumn>
        <DkTableColumn field="houseTypeName"></DkTableColumn>
        <DkTableColumn field="fitupStyleName"></DkTableColumn>
        <DkTableColumn field="ageCompositionName"></DkTableColumn>
        <DkTableColumn field="decisionMakerName"></DkTableColumn>
        <DkTableColumn field="remarks"></DkTableColumn>
      </DkTable>
    </card>

    <!--    跟进任务-->
    <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>


    <!--    导入-->
    <Upload v-show="false"
            :headers="{Authorization: 'Bearer ' + $store.state.user.token}"
            :action="this.$config.serviceUrl + '/customer-server/sale/customer/import'"
            accept=".xls, .xlsx" :on-success="uploadSuccess"
    >
      <Button ref="uploadButton">
      </Button>
    </Upload>

  </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: 'contactPhones'},
          valueKind: 'STR'
        },
        {
          itemName: 'opCreateTime',
          valueFormat: {
            code: 'opCreateTime',
            default: [new Date().addMonths(-1).format('yyyy-MM-dd'), new Date().format('yyyy-MM-dd')]
          },
          valueKind: 'DATE_RANGE'
        },
        {
          valueFormat: {code: 'reportUserName'},
          valueKind: 'STR'
        },
        {
          valueFormat: {code: 'followCount'},
          valueKind: 'STR'
        },
        {
          valueFormat: {
            code: 'customerFromList',
            data: [],
            valueKey: 'fromId',
            labelKey: 'fromName',
          },
          valueKind: 'M-CHOICE'
        },
        {
          valueFormat: {
            code: 'customerTags',
            data: [],
            valueKey: 'tagId',
            labelKey: 'tagName',
          },
          valueKind: 'M-CHOICE'
        },
        {
          valueFormat: {
            code: 'intentionTags',
            data: [],
            valueKey: 'dataCode',
            labelKey: 'dataName',
          },
          valueKind: 'M-CHOICE'
        },
        {
          itemName: self.$t('intentionQuantityTag'),
          valueFormat: {code: 'intentionQuantity'},
          valueKind: 'STR'
        },
        {
          valueFormat: {code: 'addressFull'},
          valueKind: 'STR'
        },
        {
          valueFormat: {
            code: 'channelList',
            data: [],
            valueKey: 'channelId',
            labelKey: 'channelName',
          },
          valueKind: 'M-CHOICE'
        },
        {
          valueFormat: {
            code: 'neverFollowFlag',
            data: [
              {label: self.$t('yes'), value: 'true'}, {label: self.$t('no'), value: 'false'}
            ],
          },
          valueKind: 'RADIO'
        },
        {
          valueFormat: {
            code: 'overFollowTimeFlag',
            data: [
              {label: self.$t('yes'), value: 'true'}, {label: self.$t('no'), value: 'false'}
            ],
          },
          valueKind: 'RADIO'
        },
      ],
      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
        }
      })
    },
  },
  created() {
    this.primaryKey = 'customerId'  // 设置主键Id
    this.routeObjName = 'customer'  // 设置路由名称
  }
}
</script>
