<template>
  <div>
    <el-row :gutter="10">
      <el-col :xs="24" :sm="24" :md="24" :lg="8">
        <!-- 是否合作方 (表单验证prop) -->
        <el-form-item v-if="enterpriseType === 'projectCompany'" :label="$t('enterpriseInfoManage.projCompanyInfoManage.partnerOrNot')" :prop="proplabel + '.partnerFlag'"
                      :label-width="labelWidthLeft"
                      :rules="item.forbiddenStatus ? { required: false } : formRules.partnerFlag">
          <select-dictionary :disabled="item.forbiddenStatus" v-model="item.partnerFlag" :dictTypeCode="'ZD0003'"
                             :placeholder="editModel === 'V' ? '' : $t('common.pleaseSelect')" class="item-width">
          </select-dictionary>
        </el-form-item>
        <!-- 是否挂靠(表单验证prop) -->
        <el-form-item v-else :label="$t('enterpriseInfoManage.supplierInfoManage.isAttached')" :prop="proplabel + '.anchoredFlag'"
                      :label-width="labelWidthLeft"
                      :rules="item.forbiddenStatus ? { required: false } : formRules.isAttached">
          <select-dictionary :disabled="item.forbiddenStatus" v-model="item.anchoredFlag" :dictTypeCode="'ZD0003'"
                             :placeholder="editModel === 'V' ? '' : $t('common.pleaseSelect')" class="item-width">
          </select-dictionary>
        </el-form-item>
      </el-col>
      <!-- 上班时间(字典)(表单验证prop) -->
      <el-col :xs="24" :sm="24" :md="24" :lg="8">
        <el-form-item :label="$t('enterpriseInfoManage.supplierInfoManage.officeHours')" :prop="proplabel + '.workTimeId'"
                      :label-width="labelWidthCenter"
                      :rules="item.forbiddenStatus ? { required: false } : formRules.officeHours">
          <select-work-shift :disabled="item.forbiddenStatus" v-model="item.workTimeId"
                             :placeholder="editModel === 'V' ? '' : $t('common.pleaseSelect')" class="item-width">
          </select-work-shift>
        </el-form-item>
      </el-col>
      <!-- 周末是否操作(字典)(表单验证prop) -->
      <el-col :xs="24" :sm="24" :md="24" :lg="8">
        <el-form-item :label="$t('enterpriseInfoManage.supplierInfoManage.operateWeek')" :prop="proplabel + '.weekendOperation'"
                      :label-width="labelWidthRight"
                      :rules="item.forbiddenStatus ? { required: false } : formRules.operateWeek">
          <select-dictionary :disabled="item.forbiddenStatus" v-model="item.weekendOperation" :dictTypeCode="'ZD0003'"
                             :placeholder="editModel === 'V' ? '' : $t('common.pleaseSelect')" class="item-width">
          </select-dictionary>
        </el-form-item>
      </el-col>
    </el-row>
    <el-row :gutter="10">
      <!-- 保理负责事项(表单验证prop) -->
      <el-col :xs="24" :sm="24" :md="24" :lg="8">
        <el-form-item :label="$t('enterpriseInfoManage.supplierInfoManage.responsibleMatter')" :prop="proplabel + '.factoringResponsibility'"
                      :label-width="labelWidthLeft"
                      :rules="item.forbiddenStatus ? { required: false } : formRules.responsibleMatter">
          <select-dict-dis :ref="'dictDis' + index" :disabled="item.forbiddenStatus" v-model="item.factoringResponsibility" :disabledOptions="disabledOptions"
                             :dictTypeCode="'factor_responsibility'" name="forbiddenStatusDict"
                             :multiple="true" :placeholder="editModel === 'V' ? '' : $t('common.pleaseSelect')"
                             class="item-width" @selectChanged="forbiddenStatusChange">
          </select-dict-dis>
        </el-form-item>
      </el-col>
      <!-- 对保理熟悉程度(表单验证prop) -->
      <el-col :xs="24" :sm="24" :md="24" :lg="8">
        <el-form-item :label="$t('enterpriseInfoManage.supplierInfoManage.familiarity')" :prop="proplabel + '.factoringDegree'"
                      :label-width="labelWidthCenter"
                      :rules="item.forbiddenStatus ? { required: false } : formRules.familiarity">
          <select-dictionary :disabled="item.forbiddenStatus" v-model="item.factoringDegree" :dictTypeCode="'factor_degree'"
                             :placeholder="editModel === 'V' ? '' : $t('common.pleaseSelect')" class="item-width">
          </select-dictionary>
        </el-form-item>
      </el-col>
      <!-- 保理操作配合程度(表单验证prop) -->
      <el-col :xs="24" :sm="24" :md="24" :lg="8">
        <el-form-item :label="$t('enterpriseInfoManage.supplierInfoManage.coordination')" :prop="proplabel + '.coordinationDegree'"
                      :label-width="labelWidthRight"
                      :rules="item.forbiddenStatus ? { required: false } : formRules.coordination">
          <select-dictionary :disabled="item.forbiddenStatus" v-model="item.coordinationDegree" :dictTypeCode="'coordination_degree'"
                             :placeholder="editModel === 'V' ? '' : $t('common.pleaseSelect')" class="item-width">
          </select-dictionary>
        </el-form-item>
      </el-col>
    </el-row>
    <el-row :gutter="10">
      <!-- 盖章方式(表单验证prop) -->
      <el-col :xs="24" :sm="24" :md="24" :lg="8">
        <el-form-item :label="$t('enterpriseInfoManage.supplierInfoManage.sealWay')" :prop="proplabel + '.stampWay'"
                      :label-width="labelWidthLeft"
                      :rules="item.forbiddenStatus ? { required: false } : formRules.sealWay">
          <select-dictionary :disabled="item.forbiddenStatus" v-model="item.stampWay" :multiple="true"
                             :dictTypeCode="'sealing_method'" :bufferParams="{ 'index': index }"
                             @selectChanged="selectChanged"
                             name="stampWayInfo"
                             :placeholder="editModel === 'V' ? '' : $t('common.pleaseSelect')" class="item-width">
          </select-dictionary>
        </el-form-item>
      </el-col>
      <!-- 电子章盖章流程(表单验证prop) -->
      <el-col :xs="24" :sm="24" :md="24" :lg="8">
        <el-form-item :label="$t('enterpriseInfoManage.supplierInfoManage.sealFlow')" :prop="proplabel + '.stampingProcess'"
                      :label-width="labelWidthCenter"
                      :rules="item.stampingFlag && !item.forbiddenStatus ? formRules.sealFlow : { required: false }">
          <select-dictionary v-model="item.stampingProcess" :disabled="!item.stampingFlag || item.forbiddenStatus" :dictTypeCode="'stamp_process'"
                             :placeholder="(editModel === 'V' || !item.stampingFlag || item.forbiddenStatus) ? '' : $t('common.pleaseSelect')" class="item-width">
          </select-dictionary>
        </el-form-item>
      </el-col>
      <!-- 电子章盖章天数(表单验证prop) -->
      <el-col :xs="24" :sm="24" :md="24" :lg="8">
        <el-form-item :label="$t('enterpriseInfoManage.supplierInfoManage.sealDay')" :prop="proplabel + '.stampedDays'"
                      :label-width="labelWidthRight"
                      :rules="item.stampingFlag && !item.forbiddenStatus ? formRules.sealDay : { required: false }">
          <el-input v-model="item.stampedDays" :disabled="!item.stampingFlag || item.forbiddenStatus"
                    :placeholder="(editModel === 'V' || !item.stampingFlag || item.forbiddenStatus) ? '' : $t('common.pleaseInput')" class="item-width dymForm"></el-input>
        </el-form-item>
      </el-col>
    </el-row>
    <el-row :gutter="10">
      <!-- 鲜章盖章流程(表单验证prop) -->
      <el-col :xs="24" :sm="24" :md="24" :lg="8">
        <el-form-item :label="$t('enterpriseInfoManage.supplierInfoManage.chapterStampingProcess')" :prop="proplabel + '.chapterStampingProcess'"
                      :label-width="labelWidthLeft"
                      :rules="item.stampingFlag1 && !item.forbiddenStatus ? formRules.chapterStampingProcess : { required: false }">
          <select-dictionary v-model="item.chapterStampingProcess" :disabled="!item.stampingFlag1 || item.forbiddenStatus"
                             :dictTypeCode="'chapter_stamping_process'"
                             :placeholder="(editModel === 'V' || !item.stampingFlag1 || item.forbiddenStatus) ? '' : $t('common.pleaseSelect')" class="item-width">
          </select-dictionary>
        </el-form-item>
      </el-col>
      <!-- 鲜章盖章天数(表单验证prop) -->
      <el-col :xs="24" :sm="24" :md="24" :lg="8">
        <el-form-item :label="$t('enterpriseInfoManage.supplierInfoManage.chapterStampedDays')" :prop="proplabel + '.chapterStampedDays'"
                      :label-width="labelWidthCenter"
                      :rules="item.stampingFlag1 && !item.forbiddenStatus ? formRules.chapterStampedDays : { required: false }">
          <el-input v-model="item.chapterStampedDays" :disabled="!item.stampingFlag1 || item.forbiddenStatus"
                    :placeholder="(editModel === 'V' || !item.stampingFlag1 || item.forbiddenStatus) ? '' : $t('common.pleaseInput')" class="item-width dymForm"></el-input>
        </el-form-item>
      </el-col>
      <!-- 工作负责板块(表单验证prop) -->
      <el-col :xs="24" :sm="24" :md="24" :lg="8">
        <el-form-item :label="$t('enterpriseInfoManage.supplierInfoManage.workResTemplate')" :prop="proplabel + '.workResTemplate'"
                      :label-width="labelWidthRight"
                      :rules="!item.forbiddenStatus ? [{ required: true, message: $t('regMsg.enterpriseInfoManage.workResTemplate'), trigger: 'change' }] : { required: false }">
<!--          <select-work-template v-model="item.workResTemplate" :optionList="optionList" :disabled="enableWorkResTemplate(item)" :filterable="true"-->
<!--                                :index="index" @selectChanged="templateEvent"-->
<!--                                :placeholder="(editModel === 'V' || enableWorkResTemplate(item)) ? '' : $t('common.pleaseSelect')"-->
<!--                                class="item-width"></select-work-template>-->
          <select-work-template-core-plat-modify v-model="item.workResTemplate" :optionList="optionList" name="child"
                                                 :disabled="enableWorkResTemplate(item)" :filterable="true"
                                                 :index="index" @selectChanged="coreTemplateEvent" v-if="enterpriseType === '60'"
                                                 :placeholder="(editModel === 'V' || enableWorkResTemplate(item)) ? '' : $t('common.pleaseSelect')"
                                                 class="item-width"></select-work-template-core-plat-modify>
          <select-work-template-pro-plat-modify v-model="item.workResTemplate" :optionList="optionList"
                                                :disabled="enableWorkResTemplate(item)" :filterable="true"
                                                :index="index" @selectChanged="proTemplateEvent" v-if="enterpriseType === '150'"
                                                :placeholder="(editModel === 'V' || enableWorkResTemplate(item)) ? '' : $t('common.pleaseSelect')"
                                                class="item-width"></select-work-template-pro-plat-modify>
          <select-work-template-plat-modify v-model="item.workResTemplate" :optionList="optionList"
                                                :disabled="enableWorkResTemplate(item)" :filterable="true"
                                                :index="index" @selectChanged="templateEvent" v-if="enterpriseType === '140'"
                                                :placeholder="(editModel === 'V' || enableWorkResTemplate(item)) ? '' : $t('common.pleaseSelect')"
                                                class="item-width"></select-work-template-plat-modify>
        </el-form-item>
      </el-col>
    </el-row>
    <el-row :gutter="10">
      <!-- 特殊事项 -->
      <el-col :xs="24" :sm="24" :md="24" :lg="24">
        <el-form-item :label-width="labelWidthLeft"
                      :label="$t('enterpriseInfoManage.supplierInfoManage.specialIssue')">
          <el-input :disabled="item.forbiddenStatus" type="textarea" v-model="item.specialMatter" maxlength="500" :placeholder="editModel === 'V' ? '' : $t('common.pleaseInput')" class="item-width dymForm"></el-input>
        </el-form-item>
      </el-col>
    </el-row>
    <el-row :gutter="10">
      <!-- 备注 -->
      <el-col :xs="24" :sm="24" :md="24" :lg="24">
        <el-form-item :label-width="labelWidthLeft"
                      :label="$t('enterpriseInfoManage.supplierInfoManage.remark')">
          <el-input :disabled="item.forbiddenStatus" type="textarea" v-model="item.memo" maxlength="500" :placeholder="editModel === 'V' ? '' : $t('common.pleaseInput')" class="item-width dymForm"></el-input>
        </el-form-item>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import { SelectDictionary } from 'newepoch-components'
import SelectWorkShift from '@/components/element/enterpriseInfoManage/SelectWorkShift.vue'
import SelectWorkTemplate from '@/components/element/enterpriseInfoManage/SelectWorkTemplateModifyNo.vue'
import SelectWorkTemplateCorePlatModify from '@/components/element/enterpriseInfoManage/platElement/SelectWorkTemplateCorePlatModify.vue'
import SelectWorkTemplateProPlatModify from '@/components/element/enterpriseInfoManage/platElement/SelectWorkTemplateProPlatModify.vue'
import SelectWorkTemplatePlatModify from '@/components/element/enterpriseInfoManage/platElement/SelectWorkTemplatePlatModify.vue'
import selectDictDis from '@/components/element/enterpriseInfoManage/selectDictDis.vue'
export default {
  name: 'contactBusInfo',
  components: {
    SelectDictionary,
    SelectWorkTemplate,
    SelectWorkShift,
    selectDictDis,
    SelectWorkTemplateCorePlatModify,
    SelectWorkTemplateProPlatModify,
    SelectWorkTemplatePlatModify
  },
  props: {
    index: {
      type: [Number, String],
      required: true
    },
    editModel: {
      type: [Number, String],
      required: true
    },
    item: {
      type: Object,
      required: true,
      default: () => {
        return {}
      }
    },
    formRules: {
      type: [Array, Object],
      default: () => {
        return {}
      }
    },
    proplabel: {
      type: String,
      default: () => {
        return ''
      }
    },
    enterpriseType: {
      type: String,
      default: function () {
        return null
      }
    },
    reloadWork: {
      type: Boolean,
      default: function () {
        return false
      }
    },
    optionList: {
      type: Array,
      default: function () {
        return []
      }
    }
  },
  data () {
    return {
      // disabledOptions: [],
      reload: false,
      // formitem文字宽度
      labelWidthLeft: '150px',
      labelWidthCenter: '150px',
      labelWidthRight: '150px'
    }
  },
  computed: {
    disabledOptions: function () {
      if (this.item.factoringResponsibility && this.item.factoringResponsibility.some(it => it === '1')) {
        return [{ dictId: '1' }]
      } else {
        return []
      }
    }
  },
  methods: {
    forbiddenStatusChange (a, b, c, d) {
      if (a) {
        if (a.some(it => it === '1')) {
          this.item.factoringResponsibility = ['1']
          // this.disabledOptions = [{ dictId: '1' }]
        } else {
          // this.disabledOptions = []
        }
        this.$nextTick(() => {
          // this.reload = !this.reload
          this.$refs['dictDis' + this.index].loadOptions()
        })
      }
    },
    // 板块使能
    enableWorkResTemplate (item) {
      if (this.$attrs.employeeShow) {
        return false
      }
      return item.forbiddenStatus
    },
    // 盖章方式返回 盖章流程禁用
    selectChanged (key, name, data, bufferParams) {
      // dictId
      if (name === 'stampWayInfo') {
        if (data.length > 0) {
          if (data.length === 1) {
            data.forEach(it => {
              // 1电子章 2鲜章
              if (it.dictId === '1') {
                this.$set(this.item, 'chapterStampingProcess', '')
                this.$set(this.item, 'chapterStampedDays', '')
                this.$set(this.item, 'stampingFlag', true)
              } else {
                this.$set(this.item, 'stampingFlag', false)
              }
              if (it.dictId === '2') {
                this.$set(this.item, 'stampingProcess', '')
                this.$set(this.item, 'stampedDays', '')
                this.$set(this.item, 'stampingFlag1', true)
              } else {
                this.$set(this.item, 'stampingFlag1', false)
              }
            })
          }
          if (data.length === 2) {
            // data.forEach(it => {
            //   if (it.dictId === '2') {
            //     this.$set(this.contactForm.contactList[bufferParams.index], 'stampingFlag', true)
            //   }
            //   if (it.dictId === '1') {
            //     this.$set(this.contactForm.contactList[bufferParams.index], 'stampingFlag1', true)
            //   }
            // })
            this.$set(this.item, 'stampingFlag', true)
            this.$set(this.item, 'stampingFlag1', true)
          }
        } else {
          this.$set(this.item, 'stampingFlag', false)
          this.$set(this.item, 'stampingFlag1', false)
          this.$set(this.item, 'stampingProcess', '')
          this.$set(this.item, 'stampedDays', '')
          this.$set(this.item, 'chapterStampingProcess', '')
          this.$set(this.item, 'chapterStampedDays', '')
        }
      }
    },
    proTemplateEvent (index, name, dataLists, val) {
      let list = []
      if (dataLists.some(it => it.value === '-1')) {
        list.push({
          contractId: '-1',
          contractName: '全部'
        })
      } else {
        dataLists.forEach(it => {
          list.push({
            contractId: it.value,
            contractName: it.label
          })
        })
      }
      this.item.fincrmPlateAreaRelDTOList = list
    },
    // 工作模块数据处理
    coreTemplateEvent (index, name, dataLists, val) {
      let list = []
      dataLists.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.item.fincrmPlateAreaRelDTOList = list
    },
    templateEvent (index, name, dataLists, val) {
      let $this = this
      $this.item.fincrmPlateAreaRelDTOList = []
      if (dataLists.length > 0) {
        let list = []
        dataLists.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.item.fincrmPlateAreaRelDTOList = list
      }
    }
  }
}
</script>

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