<script setup name='addMeeting'>
import { reactive, ref, onMounted, getCurrentInstance } from 'vue'
import OrgTree from '@/components/orgTree/index.vue'
import AddExpertDialog from './components/addExpertDialog.vue'
import AddProjectDialog from './components/addProjectDialog.vue'
import { getDictionaryTree } from '@/http/apis/expertManage/expertStore'
import { createMeeting } from '@/http/apis/expertManage/reviewMeeting'
import { districtList, getBusinessstripLine } from '@/http/apis/commonApi'
import { storeToRefs } from 'pinia'
import store from '@/store'
import { useRouter } from 'vue-router'
import getTimeDiffer from '@/utils/getTimeDiffer.js'
const { dictList } = storeToRefs(store.dictStore), { meetingTypeOptions, projectTypeOptions } = store.dictStore.globalDicts || {}
const { proxy } = getCurrentInstance(),
  userInfo = storeToRefs(store.userStore).userInfo || {},
  router = useRouter(),
  ruleFormRef = ref(),
  ruleForm = reactive({
    expertInviteRule: {
      inviteType: 1,
      randomRules: [{ expertDicts: [], expertTags: [] }],
      appointRule: {},
      avoidRule: {
        avoidUnitIdList: [],
        avoidOrgIdList: [],
        expertIds: [],
        avoidType: userInfo.value.regionName === '市本级' ? 2 : 1
      }

    },
    meetingBasicInfo: {
      isInnerProject: true
    }
  }),
  // 处理抽取规则字典数据expertDicts
  handleRandomRulesDictionary = ($event, index) => {
    if (!$event) {
      ruleForm.expertInviteRule.randomRules[index].expertDicts = []
      return
    }
    const dictType = $event.split('##')[1]
    const dictObj = { dictCodes: [$event.split('##')[0]], expertDict: dictType }
    if (ruleForm.expertInviteRule.randomRules[index].expertDicts.length === 0) {
      ruleForm.expertInviteRule.randomRules[index].expertDicts.push(dictObj)
    } else {
      const order = ruleForm.expertInviteRule.randomRules[index].expertDicts.findIndex(i => i.expertDict === dictType)
      if (order !== -1) { ruleForm.expertInviteRule.randomRules[index].expertDicts.splice(order, 1, dictObj) } else {
        ruleForm.expertInviteRule.randomRules[index].expertDicts.push(dictObj)
      }
    }
  },
  // 处理抽取规则标签数据expertTags
  handleRandomRulesTags = ($event, index) => {
    let tagGeneralType // 级联选择器标签总类型
    let tagType // select选择器标签总类型
    let dictObj
    if (!$event) {
      dictObj = undefined
      ruleForm.expertInviteRule.randomRules[index].expertTags = []
      return
    } else if (Array.isArray($event)) { // 处理级联选择器，数组型数据
      tagGeneralType = $event[0].split('##')[0]
      tagType = $event[$event.length - 1].split('##')[0]
      dictObj = { tagGeneralType, tagCodes: [$event[$event.length - 1].split('##')[2]], expertTag: tagGeneralType }
    } else { // 处理select选择器，字符串型数据
      tagType = $event.split('##')[0]
      dictObj = { tagType, tagCodes: [$event.split('##')[2]], expertTag: tagType }
    }
    if (ruleForm.expertInviteRule.randomRules[index].expertTags.length === 0) {
      ruleForm.expertInviteRule.randomRules[index].expertTags.push(dictObj)
    } else {
      if (Array.isArray($event)) {
      // （级联选择器数组型）判断选择的数据是否已经存在，若存在替换之前的数据，否则直接添加当前数据
        const order = ruleForm.expertInviteRule.randomRules[index].expertTags.findIndex(i => i.tagGeneralType === tagGeneralType)
        if (order !== -1) { ruleForm.expertInviteRule.randomRules[index].expertTags.splice(order, 1, dictObj) } else {
          ruleForm.expertInviteRule.randomRules[index].expertTags.push(dictObj)
        }
      } else {
      // （select选择器字符串型）同理
        const order = ruleForm.expertInviteRule.randomRules[index].expertTags.findIndex(i => i.tagType === tagType)
        if (order !== -1) { ruleForm.expertInviteRule.randomRules[index].expertTags.splice(order, 1, dictObj) } else {
          ruleForm.expertInviteRule.randomRules[index].expertTags.push(dictObj)
        }
      }
    }
  },
  // 列表数据
  column = reactive([
    {
      label: '序号',
      type: 'index',
      width: '60'
    },
    {
      label: '项目名称',
      key: 'projectName',
      prop: 'projectName',
      minWidth: '150',
      showOverflowTooltip: true
    },
    {
      label: '申报单位',
      key: 'buildOrg',
      prop: 'buildOrg',
      minWidth: '150',
      showOverflowTooltip: true
    },
    {
      label: '项目类型',
      slot: 'projectTypeName',
      prop: 'projectTypeName',
      width: '100'
    },
    {
      label: '申报金额',
      key: 'declaredAmount',
      prop: 'declaredAmount',
      width: '130'
    },
    {
      label: '预算年度',
      key: 'projectYear',
      prop: 'projectYear',
      width: '100'
    },
    {
      label: '操作',
      slot: 'action',
      width: '60',
      fixed: 'right'
    }
  ]),
  validatorTime = (rule, value, callback) => {
    if (getTimeDiffer(new Date(value[0].replace(/-/g, '/')), new Date(), 'h') > 1) {
      return callback()
    } else {
      return callback(new Error('评审时间必须是当前时间的一小时之后'))
    }
  },
  rules = reactive({
    'meetingBasicInfo.name': [
      { required: true, message: '请输入会议名称', trigger: 'blur' }
    ],
    'meetingBasicInfo.isInnerProject': [
      { required: true, message: '请选择', trigger: 'blur' }
    ],
    'meetingBasicInfo.type': [
      { required: true, message: '请选择评审类型', trigger: 'blur' }
    ],
    'meetingBasicInfo.projectIdList': [
      { required: true, message: '请选择评审项目', trigger: 'blur' }
    ],
    'meetingBasicInfo.projects': [
      { required: true, message: '请填写评审项目', trigger: 'blur' }
    ],
    'meetingBasicInfo.times': [
      { required: true, message: '请选择评审时间', trigger: 'change' },
      { validator: validatorTime, trigger: 'change' }
    ],
    'meetingBasicInfo.meetingUsageTime': [
      { required: true, message: '请选择评审耗时', trigger: 'blur' }
    ],
    'meetingBasicInfo.meetingAddress': [
      { required: true, message: '请输入评审地点', trigger: 'blur' }
    ],
    'meetingBasicInfo.judgesAttendanceTime': [
      { required: true, message: '请选择评委到场时间', trigger: 'blur' }
    ],
    'meetingBasicInfo.connecter': [
      { required: true, message: '请输入联系人', trigger: 'blur' }
    ],
    'meetingBasicInfo.contact': [
      { required: true, message: '请输入联系方式', trigger: 'blur' }
    ],
    'expertInviteRule.inviteType': [
      { required: true, message: '请选择抽取方式', trigger: 'blur' }
    ],
    // extractionRule: [
    //   { required: true, message: '请定义抽取规则', trigger: 'blur' }
    // ],
    'expertInviteRule.appointRule.inviteDesc': [
      { required: true, message: '请输入抽取理由', trigger: 'blur' }
    ],
    'expertInviteRule.appointRule.expertIdList': [
      { required: true, message: '请指定专家', trigger: 'blur' }
    ],
    'expertInviteRule.avoidRule.avoidUnitIdList': [
      { required: true, message: '请添加回避单位', trigger: 'blur' }
    ],
    'expertInviteRule.avoidRule.expertIds': [
      { required: true, message: '请添加回避专家', trigger: 'blur' }
    ],
    'expertInviteRule.avoidRule.avoidOrgIdList': [
      { required: true, message: '请添加回避条线', trigger: 'blur' }
    ],
    'expertInviteRule.avoidRule.avoidType': [{ required: true, message: '请选择' }]
  }),
  loading = ref(false),
  submitForm = async (formEl) => {
    if (!formEl) return
    await formEl.validate(async (valid, fields) => {
      if (valid) {
        const ruleFormClone = JSON.parse(JSON.stringify(ruleForm))
        // 处理随机抽取规则数据
        if (ruleForm.expertInviteRule.inviteType === 1) {
          delete ruleFormClone.expertInviteRule.appointRule // 随机抽取，删除指定抽取空对象
          ruleFormClone.expertInviteRule.randomRules.forEach(element => {
            element['inviteType'] = ruleFormClone.expertInviteRule.inviteType
            Object.keys(element).forEach(item => {
              switch (item) {
                case 'expertSource':
                  delete element[item]
                  break
                case 'expertType':
                  delete element[item]
                  break
                case 'goodAt':
                  delete element[item]
                  break
                case 'otherTag':
                  delete element[item]
                  break
                case 'professionalLevel':
                  delete element[item]
                  break
                case 'expertRegionLists':
                  delete element[item]
                  break
                default:
                  break
              }
            })
          })
        } else { // 处理指定抽取规则数据
          delete ruleFormClone.expertInviteRule.randomRules // 指定抽取，删除随机抽取空对象
          ruleFormClone.expertInviteRule.appointRule['inviteType'] = ruleFormClone.expertInviteRule.inviteType
          // 处理指定抽取专家数据
          ruleFormClone.expertInviteRule.appointRule.expertIdList = ruleFormClone.expertInviteRule.appointRule.expertIdList.map(ele => {
            return ele.id
          })
          ruleFormClone.expertInviteRule.appointRule.count = ruleFormClone.expertInviteRule.appointRule?.expertIdList?.length
        }
        // 处理回避单位数据
        ruleFormClone.expertInviteRule.avoidRule.avoidUnitIdList = ruleFormClone.expertInviteRule.avoidRule.avoidUnitIdList.map(ele => {
          return ele.organizationCode
        })
        // // 处理回避条线数据
        // ruleFormClone.expertInviteRule.avoidRule.avoidOrgIdList = ruleFormClone.expertInviteRule.avoidRule.avoidOrgIdList.map(ele => {
        //   return ele.businessStripCode
        // })
        // 处理回避专家数据
        ruleFormClone.expertInviteRule.avoidRule.expertIds = ruleFormClone.expertInviteRule.avoidRule.expertIds.map(ele => {
          return ele.userId
        })
        if (!ruleForm.meetingBasicInfo.isInnerProject) {
          ruleFormClone.meetingBasicInfo.projects = []
          ruleFormClone.meetingBasicInfo.projects.push({ projectName: ruleForm.meetingBasicInfo.projects })
        } else {
        // 处理评审项目数据
          ruleFormClone.meetingBasicInfo.innerProjects = ruleFormClone.meetingBasicInfo.projectIdList.map(ele => {
            return {
              projectId: ele.id,
              projectCode: ele.projectCode
            }
          })
        }
        ruleFormClone.meetingBasicInfo.startTime = ruleFormClone.meetingBasicInfo.times?.[0] || undefined
        ruleFormClone.meetingBasicInfo.endTime = ruleFormClone.meetingBasicInfo.times?.[1] || undefined
        ruleFormClone.meetingBasicInfo.times = undefined
        loading.value = true
        try {
          await createMeeting(ruleFormClone)
          proxy.$message.success('提交成功！')
          loading.value = false
          router.go(-1)
        } catch (e) {
          loading.value = false
        }
      } else {
        console.log('error submit!', fields)
      }
    })
  },
  // 添加项目
  projectDialogData = reactive({
    visible: false,
    meetingType: ruleForm.meetingBasicInfo.type,
    data: []
  }),
  addProject = () => {
    projectDialogData.visible = true
    projectDialogData.meetingType = ruleForm.meetingBasicInfo.type
    projectDialogData.data = ruleForm.meetingBasicInfo.projectIdList
  },
  getProjectData = (data) => {
    ruleForm.meetingBasicInfo.projectIdList = JSON.parse(JSON.stringify(data))
    projectDialogData.visible = false
  },
  deleteProject = (row) => {
    const order = ruleForm.meetingBasicInfo.projectIdList.findIndex(i => i.id === row.id)
    ruleForm.meetingBasicInfo.projectIdList.splice(order, 1)
  },
  // 添加回避条线
  title = ref(),
  showLineTree = () => {
    title.value = '回避条线'
    orgProps.defaultProps = {
      children: 'records',
      label: 'businessStripName',
      value: 'businessStripCode',
      isLeaf: 'isLeaf'
    }
    orgProps.type = 'LINE'
    orgProps.unitVisible = true
    orgProps.showCheckbox = true
    orgProps.data = ruleForm.expertInviteRule.avoidRule.avoidOrgIdList && ruleForm.expertInviteRule.avoidRule.avoidOrgIdList.map(i => i) || []
  },
  closeTag3 = (index) => {
    ruleForm.expertInviteRule.avoidRule.avoidOrgIdList.splice(index, 1)
  },
  // 回避单位
  orgProps = reactive({
    unitVisible: false,
    showCheckbox: false,
    data: undefined
  }),
  showOrgTree = () => {
    orgProps.unitVisible = true
    orgProps.showCheckbox = true
    orgProps.defaultProps = {
      children: 'children',
      label: 'title',
      value: 'key',
      isLeaf: 'isLeaf'
    }
    orgProps.type = 'UNIT'
    orgProps.data = ruleForm.expertInviteRule.avoidRule.avoidUnitIdList && ruleForm.expertInviteRule.avoidRule.avoidUnitIdList.map(i => {
      return {
        key: i.organizationCode,
        title: i.name
      }
    }) || []
  },
  closeOrg = () => {
    title.value = undefined
    orgProps.unitVisible = false
  },
  getOrgData = (data) => {
    if (title.value === '回避条线') {
      ruleForm.expertInviteRule.avoidRule.avoidOrgIdList = data.map(i => i)
    } else {
      ruleForm.expertInviteRule.avoidRule.avoidUnitIdList = data.map(i => ({ organizationCode: i.key, name: i.title }))
    }
  },
  // 删除回避单位
  delTag = (index) => {
    ruleForm.expertInviteRule.avoidRule.avoidUnitIdList.splice(index, 1)
  },
  // 添加指定抽取专家弹窗
  selectExpertType = ref(),
  unitUserDialogData = reactive({
    visible: false,
    // orgCode: route.query.orgCode || userInfo.value.orgCode,
    data: []
  }),
  addExperts = () => {
    selectExpertType.value = 1
    unitUserDialogData.visible = true
    unitUserDialogData.data = ruleForm.expertInviteRule.appointRule?.expertIdList?.map(i => {
      return {
        userId: i.id,
        expertName: i.name
      }
    }) || []
  },
  getUserData = (data) => {
    if (selectExpertType.value === 1) {
      ruleForm.expertInviteRule.appointRule.expertIdList = data.map(i => {
        return {
          id: i.userId,
          name: i.expertName
        }
      })
    } else {
      ruleForm.expertInviteRule.avoidRule.expertIds = data
    }

    unitUserDialogData.visible = false
  },
  closeExpertTag = (tag) => {
    ruleForm.expertInviteRule.appointRule.expertIdList.splice(ruleForm.expertInviteRule.appointRule.expertIdList.indexOf(tag), 1)
  },
  // 添加回避专家弹窗
  closeTag2 = (tag) => {
    ruleForm.expertInviteRule.avoidRule.expertIds.splice(ruleForm.expertInviteRule.avoidRule.expertIds.indexOf(tag), 1)
  },
  addAvoidanceExpert = () => {
    selectExpertType.value = 2
    unitUserDialogData.visible = true
    unitUserDialogData.data = ruleForm.expertInviteRule.avoidRule?.expertIds || []
  },
  // 添加/删除抽取规则
  ExtractionRule = ref([0]),
  addExtractionRule = () => {
    if (ruleForm.expertInviteRule.randomRules.length >= 5) {
      proxy.$message.warning('最多添加5个规则')
      return
    }
    ExtractionRule.value.push(ExtractionRule.value.length)
    ruleForm.expertInviteRule.randomRules.push({ expertDicts: [], expertTags: [] })
  },
  delExtractionRule = (index) => {
    ruleForm.expertInviteRule.randomRules.splice(index, 1)
    ExtractionRule.value.splice(index, 1)
  }
// 各种字典数据
const technicalExpertiseTree = ref([])// 技术专长
const industrySectorTree = ref([])// 行业领域
const expertSource = ref([])// 专家来源
const goodAtTree = ref([])// 擅长
const otherTree = ref([])// 其他标签
const copeDictionaryData = (val) => { // 处理字典数据的方法
  const data = val?.map((item) => {
    const deptData = {}
    deptData.value = item.parentCode + '##' + item.unionCode
    deptData.label = item.tagName
    // deptData.isLeaf = false
    if (item.children && item.children.length) {
      deptData.children = item.children.map((v) => ({ value: v.parentCode + '##' + v.unionCode, label: v.tagName }))
      const childrenData = copeDictionaryData(item.children)
      deptData.children = [...childrenData]
    }
    return deptData
  })
  return data
}
// 处理专家层级数据
const handleExpertRegion = ($event, index) => {
  console.log(ruleForm.expertInviteRule.randomRules[index].expertRegionLists)
  ruleForm.expertInviteRule.randomRules[index].expertRegionList = ruleForm.expertInviteRule.randomRules[index].expertRegionLists?.map(i => {
    return {
      regionCode: i[i.length - 1]?.split('##')[0],
      regionLevel: i[i.length - 1]?.split('##')[2] * 1
    }
  }) || []
  // let regionArr = []
  // if (!$event) {
  //   regionArr = []
  // } else {
  //   regionArr = $event.pop().split('##')
  // }
  // const regionCode = regionArr?.[0]
  // const regionLevel = regionArr?.[2]
  // ruleForm.expertInviteRule.randomRules[index].expertRegionCode = regionCode
  // ruleForm.expertInviteRule.randomRules[index].expertRegionLevel = regionLevel
}
// 处理履职意向数据
const handleExpertIntentionWorkRegions = ($event, index) => {
  let regionArr = []
  if (!$event) {
    regionArr = []
  } else {
    regionArr = $event.pop().split('##')
  }
  const regionCode = regionArr?.[0]
  const regionLevel = regionArr?.[2]
  ruleForm.expertInviteRule.randomRules[index].intentionRegionCode = regionCode
  ruleForm.expertInviteRule.randomRules[index].intentionRegionLevel = regionLevel
}
// 获取各种字典数据
const getDictionaryData = async (params) => {
  if (params === 'technical_expertise' && technicalExpertiseTree.value.length === 0) {
    const technicalExpertiseRes = await getDictionaryTree({ rootTagCodeList: [params] })
    technicalExpertiseTree.value = copeDictionaryData(technicalExpertiseRes)[0].children
  } else if (params === 'industry_sector' && industrySectorTree.value.length === 0) {
    const industrySectorRes = await getDictionaryTree({ rootTagCodeList: [params] })
    industrySectorTree.value = copeDictionaryData(industrySectorRes)[0].children
  } else if (params === 'expert_source' && expertSource.value.length === 0) {
    const expertSourceRes = await getDictionaryTree({ rootTagCodeList: [params] })
    expertSource.value = copeDictionaryData(expertSourceRes)[0].children
  } else if (params === 'good_at' && goodAtTree.value.length === 0) {
    const goodAtRes = await getDictionaryTree({ rootTagCodeList: [params] })
    goodAtTree.value = copeDictionaryData(goodAtRes)[0].children
  } else if (params === 'other' && otherTree.value.length === 0) {
    const otherRes = await getDictionaryTree({ rootTagCodeList: [params] })
    otherTree.value = copeDictionaryData(otherRes)[0].children
  }
}
const regionTree = ref([])
const copeData = (val) => {
  const data = val.map((item) => {
    const deptData = {}
    deptData.value = item.unionCode
    deptData.label = item.name
    if (item.children && item.children.length) {
      deptData.children = item.children.map((v) => ({ value: v.unionCode, label: v.name }))
      const childrenData = copeData(item.children)
      deptData.children = [...childrenData]
    }
    return deptData
  })
  return data
}
// 切换是否为系统内项目重置数据
const isInnerProjectChange = (val) => {
    if (val) {
      ruleForm.meetingBasicInfo.projects = undefined
    } else {
      ruleForm.meetingBasicInfo.projectIdList = undefined
    }
  },
  // 修改评审类型
  changeType = () => {
    ruleForm.meetingBasicInfo.projectIdList = []
  },
  regionProps = ref({ multiple: true }),
  lineListData = ref([]),
  getLineList = async () => {
    const res = await getBusinessstripLine()
    lineListData.value = res.data
  }
onMounted(async () => {
  // 获取履职意向数据
  const res = await districtList({ regionCode: 330500, regionLevel: 2 })
  const regionRes = []
  regionRes.push(res.data)
  regionTree.value = copeData(regionRes)
  getLineList()
})
</script>

<template>
  <el-form
    ref="ruleFormRef"
    :model="ruleForm"
    :rules="rules"
    label-width="auto"
    class="demo-ruleForm footerPage"
    label-suffix="："
    scroll-to-error
  >
    <el-card class="mb-16" shadow="never">
      <template #header>
        <div class="card-header">
          <span>基本信息</span>
        </div>
      </template>
      <el-row :gutter="20">
        <el-col :span="24">
          <el-form-item
            label="会议名称"
            prop="meetingBasicInfo.name"
          >
            <el-input
              v-model="ruleForm.meetingBasicInfo.name"
              placeholder="请输入"
              :maxlength="50"
            />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="24">
          <el-form-item
            label="是否系统内项目"
            prop="meetingBasicInfo.isInnerProject"
          >
            <el-radio-group
              v-model="ruleForm.meetingBasicInfo.isInnerProject"
              class="ml-4"
              @change="isInnerProjectChange"
            >
              <el-radio :label="true">是</el-radio>
              <el-radio :label="false">否</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="24">
          <el-form-item
            label="评审类型"
            prop="meetingBasicInfo.type"
          >
            <el-radio-group v-model="ruleForm.meetingBasicInfo.type" @change="changeType">
              <el-radio v-for="(v,k) in meetingTypeOptions" :key="k" :label="k">{{ v }}</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="ruleForm.meetingBasicInfo.isInnerProject?24:12">
          <el-form-item
            v-if="ruleForm.meetingBasicInfo.isInnerProject"
            label="评审项目"
            prop="meetingBasicInfo.projectIdList"
          >
            <table-list
              class="w-full"
              :column="column"
              :pagination="false"
              :height="200"
              :data="ruleForm.meetingBasicInfo.projectIdList"
            >
              <template #projectTypeName="{scope}">
                {{ projectTypeOptions[scope.row?.projectType] }}
              </template>
              <template #action="{ scope }">
                <a @click="deleteProject(scope.row)">删除</a>
              </template>
            </table-list>
          </el-form-item>
          <el-form-item
            v-else
            label="评审项目"
            prop="meetingBasicInfo.projects"
          >
            <el-input
              v-model="ruleForm.meetingBasicInfo.projects"
              placeholder="请输入"
              :maxlength="50"
            />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-button
            v-if="ruleForm.meetingBasicInfo.isInnerProject"
            class="ml-40"
            type="primary"
            :disabled="!ruleForm.meetingBasicInfo.type"
            @click="addProject()"
          >添加项目</el-button>
        </el-col>
      </el-row>
      <el-row
        :gutter="20"
        class="mt-30"
      >
        <el-col :span="15">
          <el-form-item
            label="评审时间"
            prop="meetingBasicInfo.times"
          >
            <el-date-picker
              v-model="ruleForm.meetingBasicInfo.times"
              type="datetimerange"
              placeholder="请选择"
              format="YYYY-MM-DD HH:mm"
              value-format="YYYY-MM-DD HH:mm"
            />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item
            label="评审耗时"
            prop="meetingBasicInfo.meetingUsageTime"
          >
            <el-radio-group
              v-model="ruleForm.meetingBasicInfo.meetingUsageTime"
              class="ml-4"
            >
              <el-radio :label="1">半天</el-radio>
              <el-radio :label="2">一天</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item
            label="评委到场时间"
            prop="meetingBasicInfo.judgesAttendanceTime"
          >
            <el-date-picker
              v-model="ruleForm.meetingBasicInfo.judgesAttendanceTime"
              type="datetime"
              placeholder="请选择"
              format="YYYY-MM-DD HH:mm"
              value-format="YYYY-MM-DD HH:mm"
            />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="24">
          <el-form-item
            label="评审地点"
            prop="meetingBasicInfo.meetingAddress"
          >
            <el-input
              v-model="ruleForm.meetingBasicInfo.meetingAddress"
              placeholder="请输入"
              :maxlength="50"
            />
          </el-form-item>
        </el-col>

      </el-row>
      <el-row :gutter="20">
        <el-col :span="12">
          <el-form-item
            label="联系人"
            prop="meetingBasicInfo.connecter"
          >
            <el-input
              v-model="ruleForm.meetingBasicInfo.connecter"
              placeholder="请输入"
              :maxlength="20"
            />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item
            label="联系方式"
            prop="meetingBasicInfo.contact"
          >
            <el-input
              v-model="ruleForm.meetingBasicInfo.contact"
              placeholder="请输入"
              :maxlength="11"
            />
          </el-form-item>
        </el-col>
      </el-row>
    </el-card>
    <el-card class="mb-16" shadow="never">
      <template #header>
        <div class="card-header">
          <span>抽取信息</span>
        </div>
      </template>
      <el-row :gutter="20">
        <el-col :span="12">
          <el-form-item
            label="抽取方式"
            prop="expertInviteRule.inviteType"
          >
            <el-radio-group
              v-model="ruleForm.expertInviteRule.inviteType"
              class="ml-4"
            >
              <el-radio :label="1">随机抽取</el-radio>
              <el-radio :label="2">指定抽取</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row
        v-if="ruleForm.expertInviteRule.inviteType == 1"
        :gutter="20"
      >
        <el-col :span="24">
          <el-form-item
            label="抽取规则"
          >
            <el-card
              v-for="(ele,index) in ExtractionRule"
              :key="index"
              class="box-card w-full mb-8"
            >
              <template #header>
                <div class="card-header flex justify-between">
                  <span>规则{{ index+1 }}</span>
                  <el-button
                    type="danger"
                    plain
                    icon="Delete"
                    :disabled="ExtractionRule.length === 1"
                    @click="delExtractionRule(index)"
                  >
                    删除规则
                  </el-button>
                </div>
              </template>
              <el-row class="mt-8" :gutter="10">
                <el-col :span="8">
                  <el-form-item
                    label="邀请数量"
                    :label-width="100"
                    :prop="`expertInviteRule.randomRules[${index}].count`"
                    :rules=" [
                      { required: true, message: ' ', trigger: 'blur' }
                    ]"
                  >
                    <el-input-number
                      v-model="ruleForm.expertInviteRule.randomRules[index].count"
                      placeholder="请输入"
                      :min="1"
                      :controls="false"
                      :step="1"
                      step-strictly
                    />
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row :gutter="10" class="mt-8">
                <el-col :span="8">
                  <el-form-item label="其他标签" :label-width="100">
                    <el-select
                      v-model="ruleForm.expertInviteRule.randomRules[index].otherTag"
                      class="w-full"
                      clearable
                      placeholder="请选择"
                      @change="handleRandomRulesTags($event, index)"
                      @visible-change="getDictionaryData('other')"
                    >
                      <el-option
                        v-for="item in otherTree"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value"
                      />
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="专家级别" :label-width="100">
                    <el-cascader
                      v-model="ruleForm.expertInviteRule.randomRules[index].expertRegionLists"
                      clearable
                      :options="regionTree"
                      placeholder="请选择"
                      class="w-full"
                      :props="regionProps"
                      @change="handleExpertRegion($event, index)"
                    />
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="内外围" :label-width="100">
                    <el-select
                      v-model="ruleForm.expertInviteRule.randomRules[index].expertType"
                      placeholder="请选择"
                      class="w-full"
                      clearable
                      @change="handleRandomRulesDictionary($event, index)"
                    >
                      <el-option
                        v-for="(item,order) in dictList &&
                          dictList.length &&
                          dictList.find(i => i.dictionaryName === 'expert_type')
                            .dictionaryList"
                        :key="order"
                        :label="item.describe"
                        :value="item.dictionaryCode+'##'+item.dictionaryType"
                      />
                    </el-select>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row :gutter="10" class="mt-8">
                <el-col :span="8">
                  <el-form-item label="履职意向" :label-width="100">
                    <el-cascader
                      :options="regionTree"
                      class="w-full"
                      clearable
                      @change="handleExpertIntentionWorkRegions($event,index)"
                    />
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="专家来源" :label-width="100">
                    <el-select
                      v-model="ruleForm.expertInviteRule.randomRules[index].expertSource"
                      class="w-full"
                      placeholder="请选择"
                      clearable
                      @change="handleRandomRulesTags($event, index)"
                      @visible-change="getDictionaryData('expert_source')"
                    >
                      <el-option
                        v-for="(item,order) in expertSource"
                        :key="order"
                        :label="item.label"
                        :value="item.value"
                      />
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="职称级别" :label-width="100">
                    <el-select
                      v-model="ruleForm.expertInviteRule.randomRules[index].professionalLevel"
                      class="w-full"
                      placeholder="请选择"
                      clearable
                      @change="handleRandomRulesDictionary($event, index)"
                    >
                      <el-option
                        v-for="(item,order) in dictList &&
                          dictList.length &&
                          dictList.find(i => i.dictionaryName === 'title_level')
                            .dictionaryList"
                        :key="order"
                        :label="item.describe"
                        :value="item.dictionaryCode+'##'+item.dictionaryType"
                      />
                    </el-select>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row :gutter="10" class="mt-8">
                <el-col :span="8">
                  <el-form-item label="擅长方向" :label-width="100">
                    <el-select
                      v-model="ruleForm.expertInviteRule.randomRules[index].goodAt"
                      class="w-full"
                      placeholder="请选择"
                      clearable
                      @change="handleRandomRulesTags($event, index)"
                      @visible-change="getDictionaryData('good_at')"
                    >
                      <el-option
                        v-for="(item,order) in goodAtTree"
                        :key="order"
                        :label="item.label"
                        :value="item.value"
                      />
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="技术专长" :label-width="100">
                    <el-cascader
                      :options="technicalExpertiseTree"
                      placeholder="请选择"
                      class="w-full"
                      clearable
                      @change="handleRandomRulesTags($event, index)"
                      @visible-change="getDictionaryData('technical_expertise')"
                    />
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="行业领域" :label-width="100">
                    <el-cascader
                      :options="industrySectorTree"
                      placeholder="请选择"
                      class="w-full"
                      clearable
                      @change="handleRandomRulesTags($event, index)"
                      @visible-change="getDictionaryData('industry_sector')"
                    />
                  </el-form-item>
                </el-col>
              </el-row>
            </el-card>
            <el-button
              class="w-full"
              type="primary"
              icon="plus"
              plain
              @click="addExtractionRule"
            >添加规则</el-button>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row
        v-else
        :gutter="20"
      >
        <el-col :span="24">
          <el-form-item
            label="指定抽取理由"
            prop="expertInviteRule.appointRule.inviteDesc"
          >
            <el-input
              v-model="ruleForm.expertInviteRule.appointRule.inviteDesc"
              placeholder="请输入"
              type="textarea"
              maxlength="1000"
              :show-word-limit="true"
            />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item
            label="指定专家"
            prop="expertInviteRule.appointRule.expertIdList"
          >
            <div class="flex flex-col items-start">
              <el-button
                type="primary"
                class="button-new-tag ml-1"
                size="small"
                @click="addExperts"
              >
                <el-icon>
                  <Plus />
                </el-icon>添加专家
              </el-button>
              <p>
                <el-tag
                  v-for="tag in ruleForm.expertInviteRule.appointRule.expertIdList"
                  :key="tag"
                  class="mx-1"
                  closable
                  :disable-transitions="false"
                  @close="closeExpertTag(tag)"
                >
                  {{ tag.name }}
                </el-tag>
              </p>

            </div>
          </el-form-item>
        </el-col>
      </el-row>
    </el-card>
    <el-card v-if="ruleForm.expertInviteRule.inviteType == 1" shadow="never">
      <template #header>
        <div class="card-header">
          <span>回避信息</span>
        </div>
      </template>
      <el-row>
        <el-col>
          <el-form-item label="部门、条线回避规则" prop="expertInviteRule.avoidRule.avoidType">
            <el-select v-model="ruleForm.expertInviteRule.avoidRule.avoidType">
              <el-option :value="1" label="回避单位" />
              <el-option :value="2" label="回避条线" />
              <el-option :value="3" label="不回避" />
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="12">
          <el-form-item
            label="回避单位"
          >
            <div class="flex flex-col items-start">
              <el-button
                type="primary"
                size="small"
                icon="Plus"
                @click="showOrgTree"
              >
                添加回避单位
              </el-button>
              <p>
                <el-tag
                  v-for="(item,index) in ruleForm.expertInviteRule.avoidRule.avoidUnitIdList"
                  :key="index"
                  class="mr-8"
                  closable
                  @close="delTag(index)"
                >
                  {{ item.name }}
                </el-tag>
              </p>
            </div>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="12">
          <el-form-item
            label="回避专家"
          >
            <div class="flex flex-col items-start">
              <el-button
                type="primary"
                class="button-new-tag ml-1"
                size="small"
                icon="Plus"
                @click="addAvoidanceExpert"
              >
                添加回避专家
              </el-button>
              <p>
                <el-tag
                  v-for="tag in ruleForm.expertInviteRule.avoidRule.expertIds"
                  :key="tag"
                  class="mx-1"
                  closable
                  :disable-transitions="false"
                  @close="closeTag2(tag)"
                >
                  {{ tag.expertName }}
                </el-tag>
              </p>
            </div>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="12">
          <el-form-item
            v-if="false"
            label="回避条线"
          >
            <div class="flex flex-col items-start">
              <el-button
                type="primary"
                class="button-new-tag ml-1"
                size="small"
                icon="Plus"
                @click="showLineTree"
              >
                添加回避条线
              </el-button>
              <p>
                <el-tag
                  v-for="(tag,index) in ruleForm.expertInviteRule.avoidRule.avoidOrgIdList"
                  :key="tag"
                  class="mx-1"
                  closable
                  :disable-transitions="false"
                  @close="closeTag3(index)"
                >
                  {{ tag.businessStripName }}
                </el-tag>
              </p>

            </div>
          </el-form-item>
          <el-form-item label="回避条线">
            <el-select v-model="ruleForm.expertInviteRule.avoidRule.avoidOrgIdList" multiple>
              <el-option
                v-for="(item,index) in lineListData"
                :key="index"
                :label="item.businessStripName"
                :value="item.businessStripCode"
              />
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="24">
          <el-form-item label="一周内参与">
            <el-input-number
              v-model="ruleForm.expertInviteRule.avoidRule.weekInviteCount"
              placeholder="请输入"
              :min="0"
              :controls="false"
              style="width: 100px !important;"
            />
            <div style="fontSize:14px; color:#666666; lineHeight:2em">次的专家不再抽取</div>
          </el-form-item>
        </el-col>
      </el-row>
    </el-card>
    <div class="footer">
      <el-button
        type="primary"
        :loading="loading"
        @click="submitForm(ruleFormRef)"
      >
        提交
      </el-button>
      <el-button @click="router.go(-1)">返回</el-button>
    </div>
  </el-form>
  <org-tree
    :visible="orgProps.unitVisible"
    :show-checkbox="orgProps.showCheckbox"
    :default-data="orgProps.data"
    :title="title"
    :type="orgProps.type"
    :default-props="orgProps.defaultProps"
    @close="closeOrg"
    @get-select-unit="getOrgData"
  />
  <add-expert-dialog
    :visible="unitUserDialogData.visible"
    :org-code="unitUserDialogData.orgCode"
    :data="unitUserDialogData.data"
    :select-expert-type="selectExpertType"
    @get-user-data="getUserData"
    @close="unitUserDialogData.visible = false"
  />
  <add-project-dialog
    :visible="projectDialogData.visible"
    :data="projectDialogData.data"
    :meeting-type="projectDialogData.meetingType"
    :dictionary-list="dictionaryList"
    @get-project-data="getProjectData"
    @close="projectDialogData.visible = false"
  />
</template>
