<template>
  <div>
    <el-button size="small" type="primary" @click="show">新 建</el-button>
    <el-drawer
        :show-close="false"
        :visible.sync="dialogFormVisible"
        append-to-body
        direction="rtl"
        size="600px"
        title="新建客户"
        @close="onClose">
      <div class="drawer__panel">
        <el-row :gutter="20">
          <el-form ref="form" :model="form" :rules="rules" label-position="right" label-width="100px" size="mini">
            <el-col :span="20">
              <el-form-item label="客户名称:" prop="enterprisename">
                <el-input v-model="form.enterprisename" placeholder="请输入客户名称" style="width: 100%"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <businessInquiry ref="businessRef" :keyword="form.enterprisename"
                               @businessData="businessSelect"></businessInquiry>
            </el-col>
            <el-col :span="24">
              <el-form-item label="企业简称:" prop="abbreviation">
                <el-input v-model="form.abbreviation" placeholder="请输入企业简称" style="width: 100%"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="客户类型:" prop="type">
                <el-select v-model="form.type" placeholder="请选择客户类型" style="width: 100%">
                  <el-option
                      v-for="item in options.type"
                      :key="item.value"
                      :label="item.value"
                      :value="item.value">
                    <span style="float: left">{{ item.value }}</span>
                    <span style="float: right; color: #8492a6; font-size: 12px">{{
                        item.remarks ? item.remarks : '暂无描述'
                      }}</span>
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="客户等级:" prop="grade">
                <el-select v-model="form.grade" placeholder="请选择客户等级" style="width: 100%">
                  <el-option
                      v-for="item in options.customerGrade"
                      :key="item.rowindex"
                      :label="item.value "
                      :value="item.value">
                    <span style="float: left">{{ item.value }}</span>
                    <span style="float: right; color: #8492a6; font-size: 12px">{{
                        item.remarks ? item.remarks : '暂无描述'
                      }}</span>
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="客户分类:" prop="customergrade">
                <el-select v-model="form.customergrade" placeholder="请选择客户分类" style="width: 100%">
                  <el-option
                      v-for="item in options.customerClassification"
                      :key="item.rowindex"
                      :label="item.value "
                      :value="item.value">
                    <span style="float: left">{{ item.value }}</span>
                    <span style="float: right; color: #8492a6; font-size: 12px">{{
                        item.remarks ? item.remarks : '暂无描述'
                      }}</span>
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="客户行业:" prop="industry">
                <el-select
                    ref="sle"
                    v-model="form.industry"
                    multiple
                    placeholder="请选择所属行业"
                    size="mini"
                    style="width:100%;"
                >
                  <el-option
                      v-for="item in options.industryData"
                      :key="item.value"
                      :label="item.value"
                      :value="item.value"
                  >
                    <span style="float: left">{{ item.value }}</span>
                    <span style="float: right; color: #8492a6; font-size: 12px">{{
                        item.remarks ? item.remarks : '暂无描述'
                      }}</span>
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="联系人:" prop="contactsinfo.name">
                <contactsNewTemplate :name="form.contactsinfo.name" :ownerid="0" ownertable="sys_enterprise"
                                     placement="left-start" @contactData="contactData"
                                     @inputChange="inputChange"></contactsNewTemplate>
              </el-form-item>
            </el-col>

            <el-col v-if="isPhone" :span="24">
              <el-form-item label="联系方式:" prop="contactsinfo.phonenumber">
                <el-button-group>
                  <el-radio v-model="isPhone" :label="true" @change="phoneChang('手机')">手机号</el-radio>
                  <el-radio v-model="isPhone" :label="false" @change="phoneChang('座机')">座机电话</el-radio>
                </el-button-group>
                <el-input v-model="form.contactsinfo.phonenumber" placeholder="请输入手机号"
                          style="width: 100%;margin-top: 10px" @input="telephoneChange('手机')"></el-input>
              </el-form-item>
            </el-col>
            <el-col v-if="!isPhone" :span="24">
              <el-form-item label="联系方式:" prop="contactsinfo.telephone">
                <el-button-group>
                  <el-radio v-model="isPhone" :label="true" @change="phoneChang('手机')">手机号</el-radio>
                  <el-radio v-model="isPhone" :label="false" @change="phoneChang('座机')">座机电话</el-radio>
                </el-button-group>
                <div style="width: 100%">
                  <el-input v-model="areaCode" placeholder="请输入区号" style="width:25%;margin-top: 10px"
                            @input="telephoneChange('座机')"></el-input>
                  <span style="color: #999999">——</span>
                  <el-input v-model="telephone" placeholder="请输入座机电话" style="width:68%;margin-top: 10px"
                            @input="telephoneChange('座机')"></el-input>
                </div>
              </el-form-item>
            </el-col>

            <el-col :span="24">
              <el-form-item label="税号:" prop="taxno">
                <el-input v-model="form.taxno" placeholder="请输入企业税号" style="width: 100%"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="法人:" prop="contact">
                <el-input v-model="form.contact" placeholder="请输入法人信息" style="width: 100%"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="联系电话:" prop="telephone">
                <el-input v-model="form.telephone" placeholder="请输入联系电话" style="width: 100%"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="省市县:" prop="province">
                <el-cascader
                    v-model="value"
                    :options="basicData.data().areaData"
                    clearable
                    style="width: 100%" @change="cascaderChange">
                </el-cascader>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="详细地址:" prop="address">
                <el-input v-model="form.address" placeholder="请输入详细地址" style="width: 100%"></el-input>
              </el-form-item>
            </el-col>

            <el-col :span="24">
              <el-form-item label="上级企业:" prop="superiorenterprisename">
                <el-popover
                    v-model="customerShow"
                    placement="bottom"
                    trigger="click"
                    width="700"
                    @show="customerList">
                  <el-input
                      v-model="customerParam.content.where.condition"
                      clearable
                      placeholder="请输入内容"
                      size="mini"
                      style="width:300px;margin-bottom: 10px"
                      @clear="customerList(customerParam.content.pageNumber = 1)"
                      @keyup.enter.native="customerList(customerParam.content.pageNumber = 1)">
                    <i slot="prefix" class="el-icon-search"
                       @click="customerList(customerParam.content.pageNumber = 1)"></i>
                  </el-input>
                  <el-table :data="customer.customerData" :header-cell-style="{background:'#EEEEEE',color:'#333'}"
                            height="396px"
                            size="mini" @row-click="customerData">
                    <el-table-column
                        label="客户编号"
                        width="100">
                      <template slot-scope="scope">
                        <span style="margin-left: 10px">{{
                            scope.row.sa_customersid ? scope.row.sa_customersid : '--'
                          }}</span>
                      </template>
                    </el-table-column>
                    <el-table-column
                        label="客户名称"
                        width="260">
                      <template slot-scope="scope">
                        <span
                            style="margin-left: 10px">{{
                            scope.row.enterprisename ? scope.row.enterprisename : '--'
                          }}</span>
                      </template>
                    </el-table-column>
                    <el-table-column
                        label="地址"
                    >
                      <template slot-scope="scope">
                        <span style="margin-left: 10px">{{ scope.row.address ? scope.row.address : '--' }}</span>
                      </template>
                    </el-table-column>
                  </el-table>
                  <div class="container normal-panel" style="text-align:right">
                    <el-pagination
                        :current-page="customer.currentPage"
                        :page-sizes="[20,50,100,]"
                        :total="customer.total"
                        background
                        layout="total,sizes, prev, pager, next, jumper"
                        small
                        @size-change="handleSizeChangeCustomer"
                        @current-change="handleCurrentChangeCustomer">
                    </el-pagination>
                  </div>
                  <el-input slot="reference" v-model="form.superiorenterprisename" :readonly="true" autocomplete="off"
                            placeholder="请选择客户" @input="selectCustomer"></el-input>
                </el-popover>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="客户来源:" prop="source">
                <selectTemp ref="sourceRef" placeholder="请选择来源" payload="cluesource" @selectChange="selectSource"></selectTemp>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="归属经销商:" prop="sa_agentsid">
                <el-popover
                    v-model="agentsShow"
                    placement="bottom"
                    trigger="click"
                    width="700"
                    @show="queryAgents">
                  <el-input
                      v-model="agentsParam.content.where.condition"
                      clearable
                      placeholder="请输入内容"
                      size="mini"
                      style="width:300px;margin-bottom: 10px"
                      @clear="queryAgents(agentsParam.content.pageNumber = 1)"
                      @keyup.enter.native="queryAgents(agentsParam.content.pageNumber = 1)">
                    <i slot="prefix" class="el-icon-search"
                       @click="queryAgents(agentsParam.content.pageNumber = 1)"></i>
                  </el-input>
                  <el-table :data="agents.agentsData" :header-cell-style="{background:'#EEEEEE',color:'#333'}"
                            height="396px"
                            size="mini" @row-click="agentsData">
                    <el-table-column
                        label="经销商编码"
                        width="100">
                      <template slot-scope="scope">
                        <span style="margin-left: 10px">{{ scope.row.agentnum ? scope.row.agentnum : '--' }}</span>
                      </template>
                    </el-table-column>
                    <el-table-column
                        label="经销商名称"
                        width="260">
                      <template slot-scope="scope">
                        <span
                            style="margin-left: 10px">{{
                            scope.row.enterprisename ? scope.row.enterprisename : '--'
                          }}</span>
                      </template>
                    </el-table-column>
                    <el-table-column
                        label="地址"
                    >
                      <template slot-scope="scope">
                        <span style="margin-left: 10px">{{ scope.row.address ? scope.row.address : '--' }}</span>
                      </template>
                    </el-table-column>
                  </el-table>
                  <div class="container normal-panel" style="text-align:right">
                    <el-pagination
                        :current-page="agents.currentPage"
                        :page-sizes="[20,50,100,]"
                        :total="agents.total"
                        background
                        layout="total,sizes, prev, pager, next, jumper"
                        small
                        @size-change="handleSizeChangeAgent"
                        @current-change="handleCurrentChangeAgent">
                    </el-pagination>
                  </div>
                  <el-input slot="reference" v-model="form.agentname" :readonly="true" autocomplete="off"
                            placeholder="请选择经销商" @input="selectAgents"></el-input>
                </el-popover>
              </el-form-item>
            </el-col>
          </el-form>
        </el-row>
      </div>
      <div class="fixed__btn__panel">
        <el-button class="normal-btn-width inline-16" size="small" @click="onClose">取 消</el-button>
        <duplicateCheck ref="check" :data="form" @onCheck="onCheck" @onSuccess="onClose"></duplicateCheck>
        <el-button :loading="loading" class="normal-btn-width" size="small" type="primary" @click="onSave">确 定
        </el-button>
      </div>
    </el-drawer>
    <enterprise
        v-if="visibleEnterprise"
        :index="index"
        :sa_projectid="form.sa_projectid"
        :visible="visibleEnterprise"
        @onEnterprise="onEnterprise">
    </enterprise>
  </div>

</template>

<script>
import {mapGetters} from 'vuex'
import enterprise from '@/SDrpManagement/salerPrivatecustomer/components/enterprise'
// import duplicateCheck from "@/SDrpManagement/salerPrivatecustomer/components/duplicateCheck";
import duplicateCheck from "@/components/duplicatesCheck/customerCheck";
import contactsNewTemplate from '@/template/contactsNewTemplate/index'
import businessInquiry from '@/template/businessInquiry/index'

export default {
  name: "add",
  components: {enterprise, duplicateCheck, contactsNewTemplate, businessInquiry},
  data() {
    return {
      activeName: 'first',
      dialogFormVisible: false,
      visibleEnterprise: false,
      customerShow: false,
      checkResults: '',
      index: '',
      businessData: [],
      businessParam: {
        "id": 20221208103601,
        "content": {
          "pageNumber": 1,
          "pageSize": 5,
          "keyword": ''
        },
      },

      businessShow: false,
      total: 0,
      currentPage: 0,
      form: {
        sa_customersid: 0,//新增是传0
        parentid: 0, //上级客户ID,默认或没有上级的时候传0
        sys_enterpriseid: 0, //合作企业档案ID，新增是传0，更新
        enterprisename: "",//客户名称（企业名称）
        type: "", //客户类型
        source: "", //客户来源
        province: "",//非必填，可选
        city: "",//非必填，可选
        county: "",//非必填，可选
        address: "",//非必填，可选
        abbreviation: "",//非必填，可选
        taxno: "",//税号,非必填，可选
        grade: '',// 客户等级（商户等级）
        industry: [],//非必填，可选，所属行业
        contact: "",//非必填，可选
        phonenumber: "",//非必填，可选
        customergrade: "",
        ispublic: 0,//1:公海客户，0：私域客户，自己新建的
        telephone: "",
        sa_agentsid: "",
        erpagentnum: "",
        agentname: '',
        contactsinfo: {
          name: "",
          telephone: "",
          phonenumber: "",
          sys_phonebookid: 0
        },
      },
      value: [],
      options: {
        type: [],
        parentCustomers: [],
        /*  gradeData:[],*/
        customerGrade: [],
        industryData: [],
        customerClassification: [],
        distributor: []
      },
      rules: {
        enterprisename: [
          {required: true, message: '请输入客户名称', trigger: 'change,blur'},
        ],
        type: [
          {required: true, message: '还未选择客户类型', trigger: 'change'},
        ],
        contact: [
          {required: false, message: '请输入法人', trigger: 'change'},
        ],
        telephone: [
          {required: false, message: '请输入联系电话', trigger: 'change'},
          /*{ pattern:/^1[3-9]\d{9}$/, message: '请输入正确手机号码',trigger: 'change' }*/
        ],
        province: [
          {required: true, message: '请选择省市县', trigger: 'blur'},
        ],
        source: [
          { required: true, message: '请选择客户来源', trigger: 'change' },
        ],
        'contactsinfo.name': [
          {required: true, message: '请输入联系人姓名', trigger: 'change,blur'}
        ],
        'contactsinfo.phonenumber': [
          {required: true, message: '请输入联系电话', trigger: 'change'},
          {pattern: /^1[3-9]\d{9}$/, message: '请输入正确手机号码', trigger: 'change'}
        ],
        'contactsinfo.telephone': [
          {required: true, message: '请输入座机电话', trigger: 'change'},
          {pattern: /^0\d{2,3}-\d{7,8}$/, message: '请输入正确座机电话', trigger: 'change'}
        ],
      },
      customerParam: {
        "id": 20220920083901,
        "content": {
          "pageNumber": 1,
          "pageSize": 20,
          "where": {
            "condition": "",
            "type": 2,
            "sa_projectid": ""
          }
        }
      },
      customer: {
        customerData: [],
        total: 0,
        currentPage: 0,
      },
      agentsShow: false,
      agentsParam: {
        "id": 20230214162602,
        "content": {
          "hrid": '',
          "pageNumber": 1,
          "pageSize": 20,
          "where": {
            "condition": ""
          }
        }
      },
      agents: {
        agentsData: [],
        total: 0,
        currentPage: 0,
      },
      isPhone: true,
      enterpriseContact: {
        param: {
          "content": {
            "sys_enterpriseid": '',
            "pageNumber": 1,
            "pageSize": 9999,
            "where": {
              "condition": ""
            }
          },
          "id": 20221219193002,
        },
        listData: [],
        total: 0,
        currentPage: 0,
        show: false
      },
      myContacts: {
        param: {
          "id": 20221219161202,
          "content": {
            "pageNumber": 1,
            "pageSize": 9999,
            "ownertable": 'sa_customers',
            "ownerid": '',
            "where": {
              "condition": ""
            }
          }
        },
        listData: [],
        total: 0,
        currentPage: 0,
        show: false
      },
      areaCode: '',
      telephone: ''
    }
  },
  computed: {
    ...mapGetters({
      dataToForm: 'dataToForm',
      loading: 'loading'
    })
  },
  methods: {
    show() {
      this.form.agentname = ''
      this.form.sa_agentsid = ''
      this.dialogFormVisible = true
      this.typeList()
      /*this.parentCustomer()*/
      this.gradeList()
      this.industryList()
      this.queryCustomerGrade()
      this.enterpriseContactList()
    },
    /*选择工商信息*/
    businessSelect(val, regProvince) {
      this.$confirm('是否以查询的工商信息更新客户信息?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$refs.businessRef.businessShow = false
        this.form.enterprisename = val.companyName
        this.form.address = val.address === "-" ? '' : val.address
        this.form.taxno = val.taxNum
        this.value = [regProvince, val.regCity, val.regArea]
        this.form.province = regProvince
        this.form.city = val.regCity
        this.form.county = val.regArea
        this.form.contact = val.legalPerson
        this.form.telephone = val.phone
      }).catch(() => {
        this.$refs.businessRef.businessShow = false
        this.$message({
          type: 'info',
          message: '已取消更新'
        });
      })
    },
    /*查重检查*/
    onCheck() {
      this.$refs.form.validate((valid) => {
        if (!valid) return false
        this.$refs.check.creatShow = false
        this.$refs.check.queryRule()
      })
    },
    /*自动查重判断*/
    duplicateCheck() {
      this.$refs.form.validate(async (valid) => {
        if (!valid) return false
        const res = await this.$api.requested({
          "id": 20221208172002,
          "content": {
            "sa_customersid": this.form.sa_customersid,
            "enterprisename": this.form.enterprisename,
            "taxno": this.form.taxno,
            "address": this.form.address
          },
        })
        console.log(res, "查重结果")
        if (res.data.length !== 0) {
          console.log("重复")
        }
        this.checkResults = res.data.length
        this.onSave()
      })
    },
    onSave() {
      this.$refs.form.validate((valid) => {
        if (!valid) return false
        this.$refs.check.creatShow = true
        this.$store.commit('setLoading', true)
        this.$refs.check.queryRule(() => {
          this.$store.commit('setLoading', false)
        })
      })
    },
    onClose() {
      this.form.contactsinfo.telephone = ''
      this.form.contactsinfo.phonenumber = ''
      this.form.contactsinfo.sys_phonebookid = 0
      this.form.agentname = ''
      this.form.sa_agentsid = ''
      this.isPhone = true
      this.$refs['form'].resetFields();
      this.dialogFormVisible = false
      this.checkResults = ''
      this.value = ''
      this.businessShow = false
      this.areaCode = ''
      this.telephone = ''
      this.$refs.sourceRef.value = ''
      this.$emit('onSuccess')
    },
    /*客户类型列表*/
    async typeList() {
      const siteid = JSON.parse(sessionStorage.getItem('active_account')).siteid
      const res = await this.$api.requested({
        "classname": "sysmanage.develop.optiontype.optiontype",
        "method": "optiontypeselect",
        "content": {
          "pageNumber": 1,
          "pageSize": 20,
          "typename": "customertypemx",
          "parameter": {
            "siteid": siteid
          }
        }
      })
      this.options.type = res.data
    },
    async customerList() {
      const res = await this.$api.requested(this.customerParam)
      this.customer.customerData = res.data
      this.customer.total = res.total
      this.customer.currentPage = res.pageNumber
    },
    selectCustomer() {
      this.customerParam.content.where.condition = this.form.enterprisename
      this.customerList()
    },
    /*客户选择信息*/
    customerData(val) {
      this.form.parentid = val.sa_customersid
      this.form.superiorenterprisename = val.enterprisename
      this.customerShow = false
    },
    /*客户分页*/
    handleSizeChangeCustomer(val) {
      // console.log(`每页 ${val} 条`);
      this.customerParam.content.pageSize = val
      this.customerList()
    },
    handleCurrentChangeCustomer(val) {
      // console.log(`当前页: ${val}`);
      this.customerParam.content.pageNumber = val
      this.customerList()
    },
    enterpriseList() {

      this.visibleEnterprise = true
    },
    /*上级客户列表*/
    onEnterprise(data) {
      this.visibleEnterprise = false
      this.form.parentid = data.sa_customersid
      this.form.superiorenterprisename = data.enterprisename

    },
    /*省市县*/
    cascaderChange(val) {
      this.form.province = val[0]
      if (val.length === 1)
        return this.form = Object.assign({}, this.form, {province: val[0], city: '', county: ''})

      this.form = Object.assign({}, this.form, {province: val[0], city: val[1], county: val[2]})
      this.$refs.form.validateField('province')
    },
    /*客户分类*/
    async gradeList() {
      const siteid = JSON.parse(sessionStorage.getItem('active_account')).siteid
      const res = await this.$api.requested({
        "classname": "sysmanage.develop.optiontype.optiontype",
        "method": "optiontypeselect",
        "content": {
          "pageNumber": 1,
          "pageSize": 20,
          "typename": "customergrade",
          "parameter": {
            "siteid": siteid
          }
        }
      })
      this.options.customerClassification = res.data
    },
    /*客户等级*/
    queryCustomerGrade() {
      this.$store.dispatch('optiontypeselect', 'agentgrade').then(res => {
        this.options.customerGrade = res.data
      })
    },
    /*行业列表*/
    async industryList() {
      const siteid = JSON.parse(sessionStorage.getItem('active_account')).siteid
      const res = await this.$api.requested({
        "classname": "sysmanage.develop.optiontype.optiontype",
        "method": "optiontypeselect",
        "content": {
          "pageNumber": 1,
          "pageSize": 20,
          "typename": "industry",
          "parameter": {
            "siteid": siteid
          }
        }
      })
      this.options.industryData = res.data
    },
    /*所属经销商*/
    async queryAgents() {
      var sessionData = sessionStorage.getItem('active_account')
      this.agentsParam.content.hrid = JSON.parse(sessionData).hrid
      const res = await this.$api.requested(this.agentsParam)
      this.agents.agentsData = res.data
      this.agents.total = res.total
      this.agents.currentPage = res.pageNumber
    },
    selectAgents() {
      this.agentsParam.content.where.condition = this.form.agentname
      this.queryAgents()
    },
    /*客户选择信息*/
    agentsData(val) {
      this.form.sa_agentsid = val.sa_agentsid
      this.form.agentname = val.enterprisename
      this.agentsShow = false
    },
    /*客户分页*/
    handleSizeChangeAgent(val) {
      // console.log(`每页 ${val} 条`);
      this.agentsParam.content.pageSize = val
      this.queryAgents()
    },
    handleCurrentChangeAgent(val) {
      // console.log(`当前页: ${val}`);
      this.agentsParam.content.pageNumber = val
      this.queryAgents()
    },
    phoneChang(val) {
      if (val === '座机') {
        this.isPhone = false
      } else {
        this.isPhone = true
      }
    },
    searchData() {
      this.changeTab()
    },
    changeTab() {
      this.enterpriseContactList()
      this.myContactList()
    },
    /*企业联系人*/
    async enterpriseContactList() {
      this.enterpriseContact.param.content.where.condition = this.form.contactsinfo.name
      this.enterpriseContact.param.content.sys_enterpriseid = 0
      const res = await this.$api.requested(this.enterpriseContact.param)
      this.enterpriseContact.listData = res.data
      this.enterpriseContact.total = res.total
      this.enterpriseContact.currentPage = res.pageNumber
    },
    /*选择企业联系人*/
    enterpriseContactSelect(val) {
      this.form.contactsinfo.oldcontactsid = val.contactsid
      this.form.contactsinfo.name = val.name
      if (val.phonenumber.indexOf('-') != '-1') {
        this.isPhone = false
        this.areaCode = val.phonenumber.substring(0, val.phonenumber.indexOf('-'))
        this.telephone = val.phonenumber.substring(this.areaCode.length + 1)
        this.form.contactsinfo.telephone = this.areaCode + '-' + this.telephone
        this.form.contactsinfo.phonenumber = ''
      } else {
        this.isPhone = true
        this.form.contactsinfo.phonenumber = val.phonenumber
        this.form.contactsinfo.telephone = ''
        this.areaCode = ''
        this.telephone = ''
      }
      this.enterpriseContact.show = false
    },
    handleSizeChangeEnterprise(val) {
      // console.log(`每页 ${val} 条`);
      this.enterpriseContact.param.content.pageSize = val
      this.enterpriseContactList()
    },
    handleCurrentChangeEnterprise(val) {
      // console.log(`当前页: ${val}`);
      this.enterpriseContact.param.content.pageNumber = val
      this.enterpriseContactList()
    },
    /*我的联系人*/
    async myContactList() {
      this.myContacts.param.content.where.condition = this.form.contactsinfo.name
      this.myContacts.param.content.sys_enterpriseid = 0
      this.myContacts.param.content.ownerid = 0
      const res = await this.$api.requested(this.myContacts.param)

      this.myContacts.listData = res.data
      this.myContacts.total = res.total
      this.myContacts.currentPage = res.pageNumber
    },
    /*选择我的联系人*/
    myContactSelect(val) {
      this.form.contactsinfo.oldcontactsid = 0
      this.form.contactsinfo.name = val.name
      if (val.phonenumber.indexOf('-') != '-1') {
        this.isPhone = false
        this.areaCode = val.phonenumber.substring(0, val.phonenumber.indexOf('-'))
        this.telephone = val.phonenumber.substring(this.areaCode.length + 1)
        this.form.contactsinfo.telephone = this.areaCode + '-' + this.telephone
        this.form.contactsinfo.phonenumber = ''
      } else {
        this.isPhone = true
        this.form.contactsinfo.phonenumber = val.phonenumber
        this.form.contactsinfo.telephone = ''
      }
      this.enterpriseContact.show = false
    },
    handleSizeChangeMy(val) {
      // console.log(`每页 ${val} 条`);
      this.myContacts.param.content.pageSize = val
      this.myContactList()
    },
    handleCurrentChangeMy(val) {
      // console.log(`当前页: ${val}`);
      this.myContacts.param.content.pageNumber = val
      this.myContactList()
    },
    telephoneChange(val) {
      if (val === '座机') {
        this.form.contactsinfo.phonenumber = ''
        this.form.contactsinfo.telephone = this.areaCode + '-' + this.telephone
      } else {
        this.form.contactsinfo.telephone = ''
        this.areaCode = ''
        this.telephone = ''
      }
    },
    inputChange(val) {
      this.form.contactsinfo.name = val
    },
    contactData(val) {
      this.form.contactsinfo.name = val.name
      this.form.contactsinfo.sys_phonebookid = val.sys_phonebookid
      if (val.phonenumber.indexOf('-') != '-1') {
        this.isPhone = false
        this.areaCode = val.phonenumber.substring(0, val.phonenumber.indexOf('-'))
        this.telephone = val.phonenumber.substring(this.areaCode.length + 1)
        this.form.contactsinfo.telephone = this.areaCode + '-' + this.telephone
        this.form.contactsinfo.phonenumber = ''
      } else {
        this.isPhone = true
        this.form.contactsinfo.phonenumber = val.phonenumber
        this.form.contactsinfo.telephone = ''
      }
    },
    selectSource(data){
      this.form.source = data
    }
  }
}
</script>

<style scoped>
/deep/ .el-input__prefix {
  display: flex;
  align-items: center;
}
</style>
