<!-- 联系人信息维护 -->
<template>
  <div>
    <dialog-edit :visible.sync="dialogVisible" :form="contactForm" :editModel="editModel" :api="api" :formRules="formRules"
                 :title="$t('enterpriseInfoManage.supplierInfoManage.contactInfoMaintain')" labelWidth="150px"
                 :autoSave="false" @onSaved="onSaved" ref="dialog"
                 :menuCode="menuId" savePerms="contactSave" :loading="form.loading">
      <div class="contactTitle">
        <span class="account-title">{{$t('enterpriseInfoManage.supplierInfoManage.accountInfos')}}</span>
      </div>
      <div class="account-info">
        <el-divider></el-divider>
      </div>
      <dym-form :componentList="accountList" :formValue="contactForm" @selectChanged="templateAllEvent"></dym-form>
      <div v-if="loadingDiv" class="zhuanquanquan" v-loading="loadingDiv"></div>
      <div>
        <employee-item ref="employeeItem" :menu-id="menuId" :edit-model="editModel" @delSuccess="delSuccess" :form="form"
                       :employeeShow="employeeShow"
                       :optionList="optionList" :regMsg="regMsg" @createSuccess="createSuccess" :surplusCount="surplusCount"
                       :contact-form.sync="contactForm" :formRules="formRules" :enterpriseType="form.tagCode"></employee-item>
        <history-info v-if="historyFlag" :historyForm="historyForm" :sourceHistoryData="sourceHistoryData"></history-info>
      </div>
    </dialog-edit>
  </div>
</template>

<script>
import { DialogEdit, dymForm, validate, regExp } from 'newepoch-components'
import BaseEdit from '@/pages/baseEditPage'
import supplierInfoManageApi from '@/api/enterpriseInfoManage/supplierInfoManageApi.js'
// import SelectWorkTemplate from '@/components/element/enterpriseInfoManage/SelectWorkTemplateModify.vue'
import SelectWorkTemplateCorePlatModify from '@/components/element/enterpriseInfoManage/platElement/SelectWorkTemplateCorePlatModify.vue'
import SelectWorkTemplateProPlatModify from '@/components/element/enterpriseInfoManage/platElement/SelectWorkTemplateProPlatModify'
import SelectWorkTemplatePlatModify from '@/components/element/enterpriseInfoManage/platElement/SelectWorkTemplatePlatModify.vue'
import * as format from '@/filters/index.js'
import employeeItem from './employeeItem.vue'
import historyInfo from './historyInfo.vue'
export default {
  extends: new BaseEdit(),
  name: 'contactInfoEdit',
  provide () {
    return {
      formClearFiled: this
    }
  },
  components: {
    DialogEdit,
    dymForm,
    employeeItem,
    historyInfo,
    SelectWorkTemplateCorePlatModify,
    SelectWorkTemplateProPlatModify,
    SelectWorkTemplatePlatModify
  },
  props: {
    enterpriseType: {
      type: String,
      default: function () {
        return null
      }
    }
  },
  data () {
    const labelWidth = '150px' // formitem文字宽度
    return {
      // 主页面真正模式
      employeeShow: false,
      surplusCount: 0,
      // 加载转圈圈
      reflash: true,
      loadingDiv: false,
      historyForm: {},
      sourceHistoryData: [],
      historyFlag: false,
      optionList: [],
      templateInfo: [],
      formRules: {
        // 负责板块
        resTemplate: [
          {
            tyep: Array,
            required: true,
            message: this.regMsg.enterpriseInfoManage.resTemplate,
            trigger: 'change',
            validator: this.resTemplateCheck
          }
        ],
        // 保理负责事项
        responsibleMatter: [{ required: true, message: this.regMsg.enterpriseInfoManage.responsibleMatter, trigger: 'change' }],
        // 对保理熟悉程度
        familiarity: [{ required: true, message: this.regMsg.enterpriseInfoManage.familiarity, trigger: 'change' }],
        // 保理操作配合程度
        coordination: [{ required: true, message: this.regMsg.enterpriseInfoManage.coordination, trigger: 'change' }],
        // 盖章方式
        sealWay: [{ required: true, message: this.regMsg.enterpriseInfoManage.sealWay, trigger: 'change' }],
        // 电子章盖章流程
        sealFlow: [{ required: true, message: this.regMsg.enterpriseInfoManage.sealFlow, trigger: 'change' }],
        // 电子章盖章天数
        sealDay: [{ required: true, message: this.regMsg.enterpriseInfoManage.sealDay, trigger: 'change' },
          { validator: this.chapterStampedDaysCheck, trigger: 'change' }],
        // 鲜章盖章流程
        chapterStampingProcess: [{ required: true, message: this.regMsg.enterpriseInfoManage.sealFlow, trigger: 'change' }],
        // 鲜章盖章天数
        chapterStampedDays: [{ required: true, message: this.regMsg.enterpriseInfoManage.sealDay, trigger: 'change' },
          { validator: this.chapterStampedDaysCheck, trigger: 'change' }],
        // 保理资料模板
        absDataTemplate: [{ required: true, message: this.regMsg.enterpriseInfoManage.absDataTemplate, trigger: 'blur' }],
        // 是否合作方
        partnerFlag: [{ required: true, message: this.regMsg.enterpriseInfoManage.partnerFlag, trigger: 'blur' }],
        // 是否挂靠
        isAttached: [{ required: true, message: this.regMsg.enterpriseInfoManage.isAttached, trigger: 'blur' }],
        // 上班时间
        officeHours: [{ required: true, message: this.regMsg.enterpriseInfoManage.officeHours, trigger: 'blur' }],
        // 周末是否操作
        operateWeek: [{ required: true, message: this.regMsg.enterpriseInfoManage.operateWeek, trigger: 'blur' }],
        // 联系人
        contact: [{ required: true, message: this.regMsg.enterpriseInfoManage.contact }, { validator: validate.nameValidate, trigger: 'blur' }],
        // 性别
        sex: [{ required: true, message: this.regMsg.enterpriseInfoManage.sex, trigger: 'change' }],
        email: [{ validator: validate.emailValidate, trigger: 'blur' }],
        // 座机
        telephone2: [{ validator: validate.telephoneValidate, trigger: 'blur' }],
        // 爱好
        hobby: [{ validator: validate.legalPersonValidate, trigger: 'blur' }]
      },
      contactForm: {
        existingAccount: {},
        contactList: []
      },
      resTemplate: [],
      queryParas: {},
      preAccountList: [],
      accountList: [
        // 企业名称
        {
          value: 'enterpriseName',
          disabled: false,
          componentName: 'el-input',
          label: this.$i18n.messages[this.$i18n.locale].enterpriseInfoManage.supplierInfoManage.enterpriseName,
          placeholder: this.$i18n.messages[this.$i18n.locale].common.pleaseInput,
          cols: [24, 24, 24, 8],
          labelWidth: labelWidth,
          prop: 'enterpriseName'
        },
        // 账号类型(字典处理)
        {
          value: 'employeeAccountType',
          disabled: false,
          componentName: 'SelectDictionary',
          dictTypeCode: 'create_account_type',
          labelWidth: labelWidth,
          label: this.$i18n.messages[this.$i18n.locale].enterpriseInfoManage.supplierInfoManage.accountType,
          placeholder: this.$i18n.messages[this.$i18n.locale].common.pleaseInput,
          cols: [24, 24, 24, 8],
          prop: 'employeeAccountType'
        },
        // 登录账号
        {
          value: 'account',
          disabled: false,
          componentName: 'el-input',
          labelWidth: labelWidth,
          label: this.$i18n.messages[this.$i18n.locale].enterpriseInfoManage.supplierInfoManage.loginAccount,
          placeholder: this.$i18n.messages[this.$i18n.locale].common.pleaseInput,
          cols: [24, 24, 24, 8],
          prop: 'account'
        },
        // 是否做业务(表单验证)
        {
          value: 'businessStatus',
          disabled: false,
          componentName: 'SelectDictionary',
          dictTypeCode: 'ZD0003',
          labelWidth: labelWidth,
          label: this.$i18n.messages[this.$i18n.locale].enterpriseInfoManage.supplierInfoManage.doBusiness,
          placeholder: this.$i18n.messages[this.$i18n.locale].common.pleaseSelect,
          cols: [24, 24, 24, 8],
          prop: 'businessStatus'
        },
        // 负责板块 (级联多选组件)(表单验证)
        {
          value: 'resTemplate',
          disabled: false,
          name: 'resTemplate',
          labelWidth: labelWidth,
          componentName: SelectWorkTemplatePlatModify,
          filterable: true,
          label: this.$i18n.messages[this.$i18n.locale].enterpriseInfoManage.supplierInfoManage.resTemplate,
          placeholder: this.$i18n.messages[this.$i18n.locale].common.pleaseSelect,
          cols: [24, 24, 24, 8],
          prop: 'resTemplate',
          reload: false,
          attrs: {
            attrsQueryParas: ''
          }
        }
      ]
    }
  },
  computed: {
    api () {
      return supplierInfoManageApi.employee
    }
  },
  methods: {
    resTemplateCheck (rule, value, callback) {
      if (!this.contactForm || !this.contactForm.resTemplate || this.contactForm.resTemplate.length === 0) {
        return callback(new Error(this.regMsg.enterpriseInfoManage.resTemplate))
      } else {
        return callback()
      }
    },
    // 盖章天数校验
    chapterStampedDaysCheck: function (rule, value, callback) {
      if (!this.UtilJs.isEmpty(value)) {
        if (regExp.dayNum.test(value)) {
          if (value > 30) {
            callback(new Error(this.regMsg.enterpriseInfoManage.sealDayInfoCheck))
          } else {
            callback()
          }
        } else {
          callback(new Error(this.regMsg.enterpriseInfoManage.sealDayInfo))
        }
      } else {
        callback()
      }
    },
    // 获取历史记录
    historyFilter () {
      let that = this
      let data = {}
      // 企业Id
      data.enterpriseId = that.form.enterpriseId
      // 企业类型
      data.enterpriseType = that.form.tagCode
      supplierInfoManageApi.historyInfo.getHistoryList(data).then(res => {
        if (res && res.data) {
          if (res.data.length > 0) {
            that.historyFlag = true
            // 提单次数
            that.$set(that.historyForm, 'billAmount', res.data[0].ladingSum)
            // 提单频率
            that.$set(that.historyForm, 'billTimes', res.data[0].ladingFrequency)
            that.sourceHistoryData = res.data
          } else {
            that.historyFlag = false
          }
        } else {
          that.historyFlag = false
        }
      })
    },
    // 当前数据
    handleFilter () {
      let that = this
      that.queryParas.keyId = that.form.keyId
      that.queryParas.tagCode = this.form.tagCode
      that.loadingDiv = true
      supplierInfoManageApi.employeeContact.getList(this.queryParas).then(res => {
        that.loadingDiv = false
        if (res && res.data) {
          // 企业名称
          that.$set(that.contactForm, 'enterpriseName', res.data.enterpriseName)
          // 账号类型
          that.contactForm.employeeAccountType = format.formatFindDefoult(res.data.employeeAccountType)
          // 登录账号
          that.$set(that.contactForm, 'account', res.data.account)
          // 账号keyId
          that.contactForm.keyId = res.data.keyId
          // 账号ID
          that.contactForm.accountId = res.data.accountId
          // 企业ID
          that.contactForm.enterpriseId = res.data.enterpriseId
          // 是否做业务
          that.$set(that.contactForm, 'businessStatus', res.data.businessStatus)
          // 负责板块
          if (this.form.tagCode === '60' && res.data.accountCorePlateAreaRelDTOList) {
            this.$set(this.contactForm, 'resTemplate', this.templateToIdCore(res.data.accountCorePlateAreaRelDTOList))
          } else if (this.form.tagCode === '150' && res.data.accountProjectPlateContractRelDTOList) {
            this.$set(this.contactForm, 'resTemplate', this.templateToIdProj(res.data.accountProjectPlateContractRelDTOList))
          } else if (this.form.tagCode === '140' && res.data.accountTerritoryDtoList) {
            this.$set(this.contactForm, 'resTemplate', this.templateToId(res.data.accountTerritoryDtoList))
          }
          that.accountList[4].reload = !that.accountList[4].reload
          let newDataList = that.sortByKey(res.data.fincrmEmployeeAccountRelDTOList, 'contactLevel')
          that.InitList(newDataList)
        }
      })
    },
    // 获取值
    InitList (newDataList) {
      let that = this
      let data = []
      let count = 0
      newDataList.forEach((it) => {
        let info = {}
        // 联系人等级keyId
        info.employeeLeavelId = it.keyId
        // 联系人信息keyId
        info.employeeKeyId = it.fincrmEmployeeDTO.keyId
        // 联系人详细信息keyId
        info.employeeInfoKeyId = it.fincrmEmployeeInfoDTO.keyId
        if (it.fincrmEmployeeBusinessDTO) {
          // 联系人业务相关信息keyId
          info.employeeBusinessKeyId = it.fincrmEmployeeBusinessDTO.keyId
          // 是否合作方
          info.partnerFlag = format.formatFindDefoult(it.fincrmEmployeeBusinessDTO.partnerFlag)
          // 上班时间
          if (it.fincrmEmployeeBusinessDTO.workTimeId === '0' || it.fincrmEmployeeBusinessDTO.workTimeId === 0) {
            info.workTimeId = ''
          } else {
            info.workTimeId = it.fincrmEmployeeBusinessDTO.workTimeId
          }
          // 周末是否操作
          info.weekendOperation = it.fincrmEmployeeBusinessDTO.weekendOperation !== undefined ? it.fincrmEmployeeBusinessDTO.weekendOperation.toString() : ''
          // 保理负责事项
          // let factoringResponsibility = it.fincrmEmployeeBusinessDTO.factoringResponsibility.toString()
          // // factoringResponsibility = factoringResponsibility === '0' ? '' : factoringResponsibility
          // info.factoringResponsibility = format.formatFindDefoult(factoringResponsibility)
          info.factoringResponsibility = []
          it.attributeDTOList.forEach(s => {
            if (s.attributeType.toString() === '3') {
              let factoringResponsibility = s.attributeValue.toString()
              info.factoringResponsibility.push(format.formatFindDefoult(factoringResponsibility))
            }
          })
          // 对保理熟悉程度
          let factoringDegree = it.fincrmEmployeeBusinessDTO.factoringDegree !== undefined ? it.fincrmEmployeeBusinessDTO.factoringDegree.toString() : ''
          factoringDegree = factoringDegree === '0' ? '' : factoringDegree
          info.factoringDegree = format.formatFindDefoult(factoringDegree)
          // 保理操作配合程度
          let coordinationDegree = it.fincrmEmployeeBusinessDTO.coordinationDegree !== undefined ? it.fincrmEmployeeBusinessDTO.coordinationDegree.toString() : ''
          coordinationDegree = coordinationDegree === '0' ? '' : coordinationDegree
          info.coordinationDegree = format.formatFindDefoult(coordinationDegree)
          // 特殊事项
          info.specialMatter = it.fincrmEmployeeBusinessDTO.specialMatter
          // 备注
          info.memo = it.fincrmEmployeeBusinessDTO.memo
        }
        // 联系人角色
        info.contactLevel1 = '第' + format.numberToChinese(parseInt(it.contactLevel)) + '联系人'
        info.contactLevel = it.contactLevel
        // that.level.push(info.contactLevel1)
        // info.contactLevel = '第一联系人'
        // 联系人
        info.reload = true
        info.employeeName = it.fincrmEmployeeDTO.employeeName
        // 性别
        info.gender = format.formatFindDefoult(it.fincrmEmployeeDTO.gender)
        // 手机号
        info.telephone = it.fincrmEmployeeDTO.telephone
        // 微信号
        info.weixin = it.fincrmEmployeeDTO.weixin
        // qq
        info.qq = it.fincrmEmployeeDTO.qq
        // 座机
        info.telephone2 = it.fincrmEmployeeInfoDTO.officePhone
        // 邮箱地址
        info.email = it.fincrmEmployeeDTO.email
        // 做事风格
        info.characterStyle = it.fincrmEmployeeDTO.characterStyle
        // 部门
        info.enterpriseDepartment = format.formatDictDefoult(it.fincrmEmployeeInfoDTO.enterpriseDeptId)
        // 职务
        info.position = it.fincrmEmployeeInfoDTO.position
        // 性格
        info.character = it.fincrmEmployeeDTO.character
        // 生日
        if (it.fincrmEmployeeDTO.birthday === '1900-01-01' || it.fincrmEmployeeDTO.birthday === -2209017600000) {
          info.birthday = ''
        } else {
          if (it.fincrmEmployeeDTO.calendarType === '0') {
            info.birthday = format.formatCheckDatetime(it.fincrmEmployeeDTO.birthday)
            // info.birthday = '1970-01-01'
          } else if (it.fincrmEmployeeDTO.calendarType === '1') {
            info.birthday = 'L' + format.formatCheckDatetime(it.fincrmEmployeeDTO.birthday)
          }
        }
        // 日期类型
        if (it.fincrmEmployeeDTO.calendarType) {
          info.calendarType = parseInt(it.fincrmEmployeeDTO.calendarType)
        } else {
          info.calendarType = 1
        }
        // 年龄
        let age = it.fincrmEmployeeDTO.age
        age = age === '0' || age === 0 ? '' : age
        info.age = format.formatFindDefoult(age)
        // 星座
        info.constellation = format.formatFindDefoult(it.fincrmEmployeeDTO.constellation)
        // 籍贯
        info.nativePlace = it.fincrmEmployeeDTO.nativePlace
        // 婚否
        let maritalStatus = it.fincrmEmployeeDTO.maritalStatus
        maritalStatus = maritalStatus === '-1' ? '' : maritalStatus
        info.maritalStatus = format.formatFindDefoult(maritalStatus)
        // 爱好
        info.hobby = it.fincrmEmployeeDTO.hobby
        // 关联已有账号
        info.associateExistingAccount = it.accountId
        /* 业务相关操作信息 */
        // 是否挂靠
        info.anchoredFlag = format.formatFindDefoult(it.fincrmEmployeeInfoDTO.anchoredFlag)
        // 盖章方式 attributeDTOList
        let stampWay = []
        it.attributeDTOList.forEach(s => {
          if (s.attributeType.toString() === '1') {
            stampWay.push(s.attributeValue)
            // 1电子章
            if (s.attributeValue === '1') {
              info.stampingFlag = true
              // 电子章盖章流程
              info.stampingProcess = s.stampProcess
              // 电子章盖章天数
              info.stampedDays = s.stampedDays
            }
            // 2鲜章
            if (s.attributeValue === '2') {
              info.stampingFlag1 = true
              // 鲜章盖章流程
              info.chapterStampingProcess = s.stampProcess
              // 鲜章盖章天数
              info.chapterStampedDays = s.stampedDays
            }
          }
        })
        if (stampWay.length > 0) {
          info.stampWay = stampWay
        } else {
          info.stampWay = ''
        }
        // 保理资料模板
        // info.factoringTemplate = it
        // 工作负责板块 fincrmPlateAreaRelDTOList
        // if (it.fincrmPlateAreaRelDTOList.length > 0) {
        //   info.workResTemplate = that.templateToId(it.fincrmPlateAreaRelDTOList)
        // }
        if (this.form.tagCode === '60' && it.corePlateAreaRelDTOList) {
          info.workResTemplate = that.templateToIdCore(it.corePlateAreaRelDTOList)
        } else if (this.form.tagCode === '150' && it.projectPlateContractRelDTOList) {
          info.workResTemplate = that.templateToIdProj(it.projectPlateContractRelDTOList)
        } else if (this.form.tagCode === '140' && it.fincrmPlateAreaRelDTOList) {
          info.workResTemplate = that.templateToId(it.fincrmPlateAreaRelDTOList)
        }
        // 是否禁用
        // info.forbiddenStatus = true
        if (it.fincrmEmployeeDTO.forbiddenStatus && it.fincrmEmployeeDTO.forbiddenStatus === '1') {
          info.forbiddenStatus = true
          count++
        } else {
          info.forbiddenStatus = false
        }
        // 删除原因
        info.deleteReason = it.fincrmEmployeeDTO.deleteReason
        data.push(info)
      })
      that.contactForm.contactList = data
      this.surplusCount = data.length - count
      if (that.editModel === 'V') {
        that.contactForm.contactList.forEach(item => {
          that.$set(item, 'forbiddenStatus', true)
          // that.$set(item, '')
        })
      }
    },
    // 数组对象排序
    sortByKey (array, key) {
      return array.sort(function (a, b) {
        let x = a[key]
        let y = b[key]
        return ((x < y) ? -1 : ((x > y) ? 1 : 0))
      })
    },
    // 保存
    onSaved () {
      let $this = this
      // $this.loading = true
      this.$set($this.form, 'loading', true)
      // let fincrmEmployeeBusinessDTO = {}
      // let fincrmEmployeeDTO = {}
      // let fincrmEmployeeInfoDTO = {}
      let infoList = []
      // let fincrmPlateContractRelDTOList = {}
      $this.contactForm.contactList.forEach(it => {
        if (it.forbiddenStatus) return
        let data = {
          fincrmEmployeeBusinessDTO: {
            fincrmPlateContractRelDTOList: []
          },
          fincrmEmployeeDTO: {},
          fincrmEmployeeInfoDTO: {}
        }
        // let stamp = {}
        data.keyId = it.employeeLeavelId
        // 联系人信息keyId
        data.fincrmEmployeeDTO.keyId = it.employeeKeyId
        // 联系人详细信息keyId
        data.fincrmEmployeeInfoDTO.keyId = it.employeeInfoKeyId
        // 联系人业务相关信息keyId
        data.fincrmEmployeeBusinessDTO.keyId = it.employeeBusinessKeyId
        // 联系人角色 组件处理
        data.contactLevel = it.contactLevel
        // 联系人
        data.fincrmEmployeeDTO.employeeName = it.employeeName
        // 性别
        data.fincrmEmployeeDTO.gender = it.gender
        // 手机号
        data.fincrmEmployeeDTO.telephone = it.telephone
        // 微信号
        data.fincrmEmployeeDTO.weixin = it.weixin
        // qq
        data.fincrmEmployeeDTO.qq = it.qq
        // 座机
        data.fincrmEmployeeDTO.telephone2 = it.telephone2
        // 邮箱地址
        data.fincrmEmployeeDTO.email = it.email
        // 备注
        data.fincrmEmployeeDTO.memo = it.memo
        // 做事风格
        data.fincrmEmployeeDTO.characterStyle = it.characterStyle
        // 部门
        data.fincrmEmployeeInfoDTO.enterpriseDeptId = it.deptId
        // 部门名称
        data.fincrmEmployeeInfoDTO.enterpriseDepartment = it.deptName
        // 职务
        data.fincrmEmployeeInfoDTO.position = it.position
        // 性格
        data.fincrmEmployeeDTO.character = it.character
        // 生日
        data.fincrmEmployeeDTO.birthday = it.newDate
        // data.fincrmEmployeeDTO.birthday = '2009-01-01'
        // 日期类型
        data.fincrmEmployeeDTO.calendarType = it.calendarType
        // 年龄
        data.fincrmEmployeeDTO.age = it.age
        // 星座
        if (it.constellation === '' || it.constellation === undefined) {
          data.fincrmEmployeeDTO.constellation = -1
        } else {
          data.fincrmEmployeeDTO.constellation = it.constellation
        }
        // 籍贯
        data.fincrmEmployeeDTO.nativePlace = it.nativePlace
        // 婚否
        data.fincrmEmployeeDTO.maritalStatus = !it.maritalStatus || it.maritalStatus.length === 0 ? '-1' : it.maritalStatus
        // 爱好
        data.fincrmEmployeeDTO.hobby = it.hobby
        // 关联已有账号
        // data.associateExistingAccount = it.accountId
        data.accountId = it.associateExistingAccount
        /* 业务相关操作信息 */
        // 是否挂靠
        data.fincrmEmployeeInfoDTO.anchoredFlag = it.anchoredFlag
        // 是否合作方
        // data.fincrmEmployeeInfoDTO.partnerFlag = it.partnerFlag
        // 上班时间
        data.fincrmEmployeeBusinessDTO.workTimeId = it.workTimeId
        // 周末是否操作
        data.fincrmEmployeeBusinessDTO.weekendOperation = it.weekendOperation
        // 保理负责事项
        // data.fincrmEmployeeBusinessDTO.factoringResponsibility = it.factoringResponsibility
        data.attributeDTOList = []
        if (it.factoringResponsibility.length > 0) {
          it.factoringResponsibility.forEach(s => {
            let attribute = {}
            attribute.attributeType = '3'
            attribute.attributeValue = s
            data.attributeDTOList.push(attribute)
          })
        }
        // 是否合作方
        data.fincrmEmployeeBusinessDTO.partnerFlag = it.partnerFlag
        // 对保理熟悉程度
        data.fincrmEmployeeBusinessDTO.factoringDegree = it.factoringDegree
        // 保理操作配合程度
        data.fincrmEmployeeBusinessDTO.coordinationDegree = it.coordinationDegree
        // 盖章方式 attributeDTOList
        // data.stampWay = ''
        if (it.stampWay.length > 0) {
          it.stampWay.forEach(s => {
            let attribute = {}
            attribute.attributeType = '1'
            attribute.attributeValue = s
            data.attributeDTOList.push(attribute)
          })
        }
        // 盖章流程
        data.stampProcessZero = it.stampingProcess
        // 电子章盖章天数
        data.stampedAayZero = it.stampedDays
        // 鲜章盖章流程
        data.stampProcessOne = it.chapterStampingProcess
        // 鲜章盖章天数
        data.stampedAayOne = it.chapterStampedDays
        // 保理资料模板
        // info.factoringTemplate = it
        // 工作负责板块 fincrmPlateAreaRelDTOList
        if (this.form.tagCode === '60') {
          data.corePlateAreaRelDTOList = it.fincrmPlateAreaRelDTOList
        } else if (this.form.tagCode === '150') {
          data.projectPlateContractRelDTOList = it.fincrmPlateAreaRelDTOList
        } else if (this.form.tagCode === '140') {
          data.fincrmPlateAreaRelDTOList = it.fincrmPlateAreaRelDTOList
        }
        // 特殊事项
        data.fincrmEmployeeBusinessDTO.specialMatter = it.specialMatter
        // 备注
        data.fincrmEmployeeBusinessDTO.memo = it.memo
        infoList.push(data)
      })
      let dataList = {}
      // 企业名称
      // dataList.enterpriseName = $this.contactForm.enterpriseName
      // 账号类型
      // dataList.employeeAccountType = $this.contactForm.employeeAccountType
      // 登录账号
      // dataList.account = $this.contactForm.account
      // 账号Id
      dataList.accountId = $this.contactForm.accountId
      // 企业keyId
      dataList.enterpriseId = $this.contactForm.enterpriseId
      // 是否做业务
      dataList.businessStatus = $this.contactForm.businessStatus
      // 账号keyId
      dataList.keyId = $this.contactForm.keyId
      // 企业负责板块
      if (this.form.tagCode === '60') {
        dataList.accountCorePlateAreaRelDTOList = $this.templateInfo
      } else if (this.form.tagCode === '150') {
        dataList.accountProjectPlateContractRelDTOList = $this.templateInfo
      } else if (this.form.tagCode === '140') {
        dataList.accountTerritoryDtoList = $this.templateInfo
      }
      dataList.fincrmEmployeeAccountRelDTOList = infoList
      // 企业标签
      dataList.enterpriseType = $this.form.tagCode
      // 登录用户名
      dataList.userName = this.$store.getters.nikeName
      supplierInfoManageApi.employeeUpdate.update(dataList).then(res => {
        if (res && res.data) {
          $this.success(this.$i18n.messages[this.$i18n.locale].common.updateSuccess)
          $this.dialogVisible = false
          this.$set($this.form, 'loading', false)
          $this.$emit('createSuccess')
        } else {
          $this.error(this.$i18n.messages[this.$i18n.locale].common.updateError)
        }
      }).catch(() => {
        this.$set($this.form, 'loading', false)
      })
    },
    // dymformchange事件
    templateAllEvent (data, index) {
      if (data.resTemplateInfo) {
        this.optionList = data.resTemplateInfo
        if (this.form.tagCode === '60') {
          this.coreWorkInfoFun(data.resTemplateInfo)
        } else if (this.form.tagCode === '150') {
          this.proWorkInfoFun(data.resTemplateInfo)
        } else if (this.form.tagCode === '140') {
          this.workInfoFun(data.resTemplateInfo)
        }
      }
    },
    // 供应商
    workInfoFun (data1) {
      let list = []
      data1.some(item => {
        let data = {
          children: []
        }
        if (item.value === '-1') {
          data.coreEnterpriseId = item.value
          data.coreEnterpriseName = item.label
          list.push(data)
          return true
        } else {
          if (item.children && item.children.length > 0) {
            item.children.some(it => {
              if (it.value === '-1') {
                data.children.push({
                  areaId: it.value,
                  areaName: it.label,
                  children: []
                })
                return true
              } else {
                let child = {
                  children: []
                }
                if (it.children && it.children.length > 0) {
                  it.children.some(it2 => {
                    let child2 = {}
                    child2.contractId = it2.value
                    child2.contractName = it2.label
                    child.children.push(child2)
                  })
                }
                child.areaId = it.value
                child.areaName = it.label
                data.children.push(child)
              }
            })
          }
          data.coreEnterpriseId = item.value
          data.coreEnterpriseName = item.label
          list.push(data)
        }
      })
      this.templateInfo = list
    },
    // 项目公司
    proWorkInfoFun (data) {
      let list = []
      if (data.some(it => it.value === '-1')) {
        list.push({
          contractId: '-1',
          contractName: '全部'
        })
      } else {
        data.forEach(it => {
          list.push({
            contractId: it.value,
            contractName: it.label
          })
        })
      }
      this.templateInfo = list
    },
    // 核心企业
    coreWorkInfoFun (data) {
      let list = []
      data.some(it => {
        if (it.value === '-1') {
          list.push({
            areaName: it.label,
            areaId: it.value,
            fincrmCorePlateProjectRelDTOList: []
          })
          return true
        } else {
          list.push({
            bigAreaId: it.areaParent,
            bigAreaName: it.areaParentName,
            areaName: it.areaName,
            areaId: it.keyId,
            fincrmCorePlateProjectRelDTOList: []
          })
          if (it.children) {
            it.children.forEach(it1 => {
              var a = it1.companyId
              var b = it1.companyName
              if (it1.value === '-1') {
                a = it1.value
                b = it1.label
              }
              list[list.length - 1].fincrmCorePlateProjectRelDTOList.push({
                projectEnterpriseId: a,
                projectEnterpriseName: b
              })
            })
          }
        }
      })
      this.templateInfo = list
    },
    // 核心企业转ID
    templateToIdCore (data) {
      var a = []
      data.some(it => {
        if (it.areaId === '-1') {
          a.push(['-1'])
          return true
        } else {
          var b = [it.bigAreaId + '-' + it.areaId]
          if (it.fincrmCorePlateProjectRelDTOList) {
            if (it.fincrmCorePlateProjectRelDTOList.length === 0) {
              a.push(b)
            } else {
              it.fincrmCorePlateProjectRelDTOList.forEach(it1 => {
                var c = [...b, it1.projectEnterpriseId]
                a.push(c)
              })
            }
          } else {
            a.push(b)
          }
        }
      })
      return a
    },
    // 项目公司
    templateToIdProj (data = []) {
      var a = []
      data.forEach(it => {
        a.push([it.contractId])
      })
      return a
    },
    // 负责模块数据转换去id
    templateToId (data) {
      let ids = []
      if (data.length > 0) {
        data.forEach(item => {
          if (item.children && item.children.length > 0) {
            item.children.forEach(it => {
              if (it.children) {
                if (it.children.length > 0) {
                  it.children.forEach(it2 => {
                    let list = []
                    if (!ids.some(it12 => it12.indexOf(it.coreEnterpriseId) >= 0 && it12.indexOf(it.areaId) >= 0 && it12.indexOf(it.contractId) >= 0)) {
                      list.push(item.coreEnterpriseId)
                      list.push(it.areaId)
                      list.push(it2.contractId)
                      ids.push(list)
                    }
                  })
                } else {
                  let list1 = []
                  if (!ids.some(it12 => it12.indexOf(it.coreEnterpriseId) >= 0 && it12.indexOf(it.areaId) >= 0)) {
                    list1.push(item.coreEnterpriseId)
                    list1.push(it.areaId)
                    ids.push(list1)
                  }
                }
              }
            })
          } else {
            var list1 = [item.coreEnterpriseId]
            ids.push(list1)
          }
        })
      }
      return ids
    },
    // 新建联系人成功
    createSuccess (contactItem) {
      // this.contactForm.contactList.push(contactItem)
      this.loadData()
      this.reflash = false
      // this.historyFilter()
    },
    // 删除联系人成功
    delSuccess () {
      this.loadData()
    },
    // 加载数据
    loadData () {
      this.optionList = []
      this.contactForm = Object.create(null)
      this.$set(this.contactForm, 'contactList', [])
      this.$set(this.contactForm, 'existingAccount', {})
      this.contactForm.existingAccount.enterpriseId = this.form.enterpriseId
      if (this.UtilJs.isEmpty(this.form.keyId)) {
        this.dialogVisible = false
        return this.warning('账号ID不存在，请检查')
      }
      if (this.UtilJs.isEmpty(this.form.enterpriseId) || this.UtilJs.isEmpty(this.form.tagCode)) {
        this.dialogVisible = false
        return this.warning('企业ID和企业类型不能为空')
      }
      this.handleFilter()
      this.historyFilter()
    }
  },
  watch: {
    visible (value) {
      let that = this
      if (value) {
        if (this.form.tagCode === '60') {
          that.accountList[that.accountList.length - 1].componentName = SelectWorkTemplateCorePlatModify
          this.accountList[this.accountList.length - 1].attrs.attrsQueryParas = { coreCompanyId: this.form.enterpriseId }
        } else if (this.form.tagCode === '150') {
          that.accountList[that.accountList.length - 1].componentName = SelectWorkTemplateProPlatModify
          this.accountList[this.accountList.length - 1].attrs.attrsQueryParas = { enterpriseId: this.form.enterpriseId }
        } else if (this.form.tagCode === '140') {
          that.accountList[that.accountList.length - 1].componentName = SelectWorkTemplatePlatModify
        }
        that.$nextTick(() => {
          if (this.$attrs.employeeShow) {
            this.employeeShow = this.$attrs.employeeShow
          }
          if (this.editModel === 'V') {
            that.accountList.forEach((item, index) => {
              if (this.employeeShow && item.value === 'resTemplate') {
                that.$set(item, 'disabled', false)
              } else {
                that.$set(item, 'disabled', true)
                that.$set(item, 'pleaceholder', '')
              }
            })
          } else {
            that.$set(that.accountList[0], 'disabled', true)
            that.$set(that.accountList[0], 'pleaceholder', '')
            that.$set(that.accountList[1], 'disabled', true)
            that.$set(that.accountList[1], 'pleaceholder', '')
            that.$set(that.accountList[2], 'disabled', true)
            that.$set(that.accountList[2], 'pleaceholder', '')
          }
        })
        this.loadData()
      } else {
        that.historyFlag = false
        that.contactForm = Object.create(null)
        that.$set(that.contactForm, 'contactList', [])
        that.$set(that.contactForm, 'existingAccount', {})
        if (!that.reflash) {
          that.$emit('createSuccess')
        }
        that.reflash = true
      }
    }
  }
}
</script>

<style scoped lang="scss">
  @import '~@/styles/enterpriseInfoManage/supplierInfoManage/contactInfoEdit.scss';
</style>
