<script name="basicInfo" setup>
import { nextTick, reactive, ref, onMounted, watch } from 'vue'
import store from '@/store'
import { fileFormatVerification, handleFileSuccess, handleFilePreview, handleFileError, reviewFileParam, fileTypes } from '@/utils/uploadAction.js'
import { storeToRefs } from 'pinia'
import { useRoute } from 'vue-router'
import { govStripList } from '@/http/apis/declareMange'
import OrgTree from '@/components/orgTree/index.vue'
import UserDialog from '@/pages/projectCollection/projectCollectionEnter/components/userDialog.vue'
import RelatedProjectDialog from '@/pages/projectCollection/projectCollectionEnter/components/relatedProjectDialog.vue'
import ProjectContentDialog from '@/pages/projectCollection/projectCollectionEnter/components/projectContentDialog.vue'
import { getOrganizationByCode } from '@/http/apis/commonApi'
import { templateTypePage } from '@/http/apis/performanceEvaluation/indicatorTemplate'
const props = defineProps({
  detailData: {
    type: Object,
    default: () => {
      return {}
    }
  },
  dictionaryList: {
    type: Array,
    default: () => []
  },
  declareAmount: {
    type: Number
  }
})
const {
    fourSystem,
    businessTerritory
    // projectConTypeOptions
  } = store.dictStore.globalDicts || {},
  route = useRoute(),
  uploadUrl = store.dictStore.uploadUrl,
  userInfo = storeToRefs(store.userStore).userInfo || {},
  formData = ref({
    baseProjIsConfidentiality: '01',
    buildOrgName: userInfo.value.empPosUnitName,
    beseExpectedResults: []
  }),
  formRef = ref(),
  // 手机号码校验
  checkTelPhone = (rule, value, callback) => {
    if (value === '') {
      return callback(new Error('请输入正确的手机号'))
    } else {
      const regIdCard =
            /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/
      if (regIdCard.test(value)) {
        callback()
      } else {
        return callback(new Error('请输入正确的手机号'))
      }
    }
  },
  userValidator = (rule, value, callback) => {
    if (!value) callback()
    if (formData.value.responsibleMan === formData.value.contactName && formData.value.responsibleManMobile === formData.value.contactPhone) {
      callback('项目负责人与项目联系人不能相同')
    } else {
      callback()
    }
  },
  moneyValidator = (rule, value, callback) => {
    if (!value) callback()
    if (!/^\d+(\.\d{1,6})?$/.test(value)) {
      callback('请输入正确格式，最多保留六位小数')
    } else if (value * 1 >= 100000000) {
      callback('请输入正确格式，小于100000000')
    } else {
      callback()
    }
  },
  rules = {
    baseProjIsConfidentiality: [{ required: true, message: '请选择是否涉密', trigger: 'change' }],
    projectName: [{ required: true, message: '请输入项目名称', trigger: 'blur' }],
    baseConstructionType: [{ required: true, message: '请选择内容类别', trigger: 'change' }],
    projectType: [{ required: true, message: '请选择项目类型', trigger: 'change' }],
    isFirst: [
      { required: true, message: '请选择是否首次新建', trigger: 'change' }
    ],

    isInnovateWholeProvinceShare: [
      { required: true, message: '请选择是否为一地创新全省共享项目', trigger: 'change' }
    ],
    isTemporaryAugment: [
      { required: true, message: '请选择是否为临时增补', trigger: 'change' }
    ],
    responsibleMan: [{ required: true, message: '请选择项目负责人', trigger: 'blur' }, { validator: userValidator }],
    responsibleManMobile: [
      { required: true, message: '请输入项目负责人手机号', trigger: 'blur' },
      { validator: checkTelPhone, trigger: 'blur' }
    ],
    contactName: [{ required: true, message: '请选择项目联系人', trigger: 'blur' }, { validator: userValidator }],
    contactPhone: [
      { required: true, message: '请输入项目联系人手机号', trigger: 'blur' },
      { validator: checkTelPhone, trigger: 'blur' }
    ],
    buildOrgName: [{ required: true, message: '请输入建设单位', trigger: 'blur' }],
    orgCreditCode: [
      {
        required: true,
        message: '请输入建设单位统一信用代码',
        trigger: 'blur'
      }
    ],
    superOrg: [
      { required: true, message: '请选择主管单位:', trigger: 'change' }
    ],
    superOrgCode: [{ required: true, message: '请选择主管单位:', trigger: 'change' }],
    superOrgCreditCode: [{ required: true, message: '请选择主管单位:' }],
    baseProvManDeprtType: [
      { required: true, message: '请选择上级主管单位类型:', trigger: 'change' }
    ],
    higherSuperOrg: [
      { required: true, message: '请选择上级主管单位', trigger: 'change' }
    ],
    higherSuperOrgCode: [
      { required: true, message: '请选择上级主管单位', trigger: 'change' }
    ],
    buildDuration: [{ required: true, message: '请选择建设起止年限', trigger: 'change' }],
    fourSystems: [{ required: true, message: '请选择四大体系', trigger: 'change' }],
    templateType: [{ required: true, message: '请选择绩效评价类型', trigger: 'change' }],
    isDigitalReform: [
      {
        required: true,
        message: '请选择是否数字化改革项目',
        trigger: 'change'
      }
    ],
    bizDomain: [
      { required: true, message: '请选择综合业务领域', trigger: 'change' }
    ],
    buildLevel: [{ required: true, message: '请选择建设层级', trigger: 'change' }],
    lowestLevel: [{ required: true, message: '请选择贯通层级', trigger: 'change' }],
    baseProjBasis: [{ required: true, message: '请选择立项依据', trigger: 'change' }],
    baseBasisEstablish: [{ required: true, message: '请输入立项依据说明' }],
    developCode: [{ required: true, message: '请填写发改编码', trigger: 'blur' }],
    financialCode: [{ required: true, message: '请填写财政编码', trigger: 'blur' }],
    isCloud: [{ required: true, message: '请选择是否上云', trigger: 'change' }],
    cloudType: [{ required: true, message: '请选择云类型', trigger: 'change' }],
    systemPosition: [{ required: true, message: '请输入系统定位', trigger: 'blur' }],
    projectIntroduction: [{ required: true, message: '请输入项目简介', trigger: 'blur' }],
    baseHistorProjs: [{ required: true, message: '请至少关联一个历年项目' }],
    beseExpectedResults: [{ required: true, message: '请至少添加一个项目内容与预期成效' }],
    projectYear: [{ required: true, message: '请选择预算年度' }],
    declareAmount: [{ required: true, message: '请输入申报金额', trigger: 'blur' }, { validator: moneyValidator, trigger: 'blur' }],
    annualPlanAmount: [
      { required: true, message: '请输入年度支付金额', trigger: 'blur' },
      { validator: moneyValidator, trigger: 'blur' }
    ]
  },

  // 立项依据
  buildBasisTableData = ref([
    {
      id: 1,
      title: '国家部委及省市下达任务、相关文件明确建设时间',
      fileName: '',
      fileList: []
    },
    {
      id: 2,
      title: '本级及上级领导批示',
      fileName: '',
      fileList: []
    },
    {
      id: 3,
      title: '重大任务',
      fileName: '',
      fileList: []
    },
    {
      id: 4,
      title: '重大共性问题',
      fileName: '',
      fileList: []
    },
    {
      id: 5,
      title: '重大决策',
      fileName: '',
      fileList: []
    },
    {
      id: 6,
      title: '普惠性惠企利民',
      fileName: '',
      fileList: []
    },
    {
      id: 7,
      title: '其他',
      fileName: '',
      fileList: []
    }
  ]),
  buildBasisColumn = [
    {
      type: 'selection'
    },
    {
      label: '依据项',
      key: 'title',
      prop: 'title'
    },
    {
      label: '依据文件名',
      slot: 'fileName'
    },
    {
      label: '文件（支持pdf、word）',
      slot: 'action',
      width: 300
    }
  ],
  tableListRef = ref(),
  selectionChange = (val) => {
    formData.value.baseProjBasis = val.map(i => i)
  },
  // 校验
  validForm = (callback) => {
    formRef.value.validate(valid => {
      callback(valid)
    })
  },
  // 回显
  setFormData = (data) => {
    formData.value = {
      baseProjIsConfidentiality: data.baseProjIsConfidentiality || '01',
      projectName: data.projectName,
      projectType: data.projectType,
      isFirst: data.isFirst,
      baseConstructionType: data?.baseConstructionType?.split('；') || undefined,
      isInnovateWholeProvinceShare: data.isInnovateWholeProvinceShare,
      isTemporaryAugment: data.isTemporaryAugment,
      responsibleMan: data.responsibleMan,
      responsibleManMobile: data.responsibleManMobile,
      contactName: data.contactName,
      contactPhone: data.contactPhone,
      buildOrgName: data.buildOrgName,
      orgCreditCode: data.orgCreditCode,
      superOrgCode: data.superOrgCode,
      superOrg: data.superOrg,
      superOrgCreditCode: data.superOrgCreditCode || '',
      baseProvManDeprtType: data?.baseProvManDeprtType + '' || '',
      higherSuperOrgCode: data.higherSuperOrgCode,
      higherSuperOrg: data.higherSuperOrg,
      buildDuration: data.beginTime && data.endTime ? [data.beginTime, data.endTime] : [],
      fourSystems: data.fourSystems,
      templateType: data.templateType,
      isDigitalReform: data.isDigitalReform,
      bizDomain: data.bizDomain && data.isDigitalReform === 1 ? data.bizDomain.split(',') : undefined,
      buildLevel: data.buildLevel,
      lowestLevel: data.lowestLevel,
      buildBasis: undefined,
      // buildBasis: data.buildBasis ? json.parse(data.buildBasis) : [],
      baseProjBasis: data?.baseProjBasis?.split('；')?.map((i, index) => {
        const file = `[${data.baseProjBasisFile?.replace(/}]；/g, '}],')}]`
        return {
          title: buildBasisTableData.value?.find(j => j.value === i)?.title,
          fileList: data?.baseProjBasisFile ? reviewFileParam(JSON.parse(file)[index]) : [],
          value: i
        }
      }) || [],
      baseBasisEstablish: data.baseBasisEstablish || '',
      developCode: data.developCode,
      financialCode: data.financialCode,
      isCloud: data.isCloud,
      cloudType: data.cloudType && data.cloudType.split(',') || [],
      systemPosition: data.systemPosition,
      projectIntroduction: data.projectIntroduction,
      baseHistorProjs: data?.baseHistorProjId?.split('；').map((i, k) => {
        return {
          baseProjId: i,
          baseProjName: data?.baseHistorProjName.split('；')[k],
          baseProjSetYear: data?.baseHistorProjYear.split('；')[k]
        }
      }) || [],
      beseExpectedResults: data?.beseExpectedResults && JSON.parse(data?.beseExpectedResults) || [],
      projectYear: data.projectYear ? data.projectYear + '' : null,
      declareAmount: data.declareAmount,
      annualPlanAmount: data.annualPlanAmount
    }
    const baseProjBasis = formData.value.baseProjBasis ? JSON.parse(JSON.stringify(formData.value.baseProjBasis)) : []
    if (data?.baseProjBasis?.split('；')?.length) {
      const dataIds = data?.baseProjBasis?.split('；')
      buildBasisTableData.value && buildBasisTableData.value.forEach(item => {
        if (dataIds.includes(item.value)) {
          item.fileList = baseProjBasis.find(i => i.value === item.value)?.fileList
          item.fileName = baseProjBasis.find(i => i.value === item.value)?.fileName
          tableListRef.value.toggleRowSelect(item, true)
        }
      })
    }
  },
  emits = defineEmits(['changeIsFirst', 'getBasicInfoData']),
  changeIsFirst = (val) => {
    emits('changeIsFirst', val)
  },
  // 主管单位
  orgProps = reactive({
    unitVisible: false,
    data: undefined,
    title: undefined,
    type: undefined,
    params: undefined
  }),
  showOrgTree = () => {
    orgProps.unitVisible = true
    orgProps.title = '主管单位'
    orgProps.type = 'UNIT'
    orgProps.showCheckbox = true
    orgProps.defaultProps = {
      children: 'children',
      label: 'title',
      value: 'key',
      isLeaf: 'isLeaf'
    }
    orgProps.params = {
      onlyUnit: true
    }
    orgProps.data = formData.value.superOrgCode ? [{
      key: formData.value.superOrgCode,
      title: formData.value.superOrg
    }] : []
  },
  closeOrg = () => {
    orgProps.unitVisible = false
  },
  getOrgData = (data) => {
    if (orgProps.title === '主管单位') {
      formData.value.superOrgCode = data?.[0].key || undefined
      formData.value.superOrg = data?.[0].title || undefined
      getCode('superOrgCreditCode', data?.[0].key)
    } else {
      formData.value.higherSuperOrgCode = data?.[0].key || undefined
      formData.value.higherSuperOrg = data?.[0].title || undefined
    }
  },
  // 选择条线，非市本级用户市
  showLineOrgTree = () => {
    orgProps.title = '上级条线主管单位'
    orgProps.type = 'UNIT'
    orgProps.defaultProps = {
      children: 'children',
      label: 'title',
      value: 'key',
      isLeaf: 'isLeaf'
    }
    orgProps.unitVisible = true
    orgProps.data = formData.value.higherSuperOrgCode ? [{
      key: formData.value.higherSuperOrgCode,
      title: formData.value.higherSuperOrg
    }] : []
  },
  // 市本级用户展示省级条线列表
  dialogVisible = ref(false),
  searchForm = reactive({
    businessStripName: undefined
  }),
  showDialog = async () => {
    getTableData()
    dialogVisible.value = true
    await nextTick()
    tableListRef.value.setRadio(formData.value.higherSuperOrgCode || '')
  },
  column = [
    {
      type: 'radio',
      key: 'businessStripCode',
      width: '60'
    },
    {
      label: '单位名称',
      key: 'businessStripName',
      prop: 'businessStripName',
      minWidth: '150',
      showOverflowTooltip: true
    },
    {
      label: '单位编码',
      key: 'businessStripCode',
      prop: 'businessStripCode',
      minWidth: '150',
      showOverflowTooltip: true
    }
  ],
  tableData = ref(),
  getTableData = async () => {
    const res = await govStripList({ ...searchForm })
    tableData.value = res.data
  },
  reset = () => {
    searchForm.businessStripName = undefined
    getTableData()
  },
  businessStripData = ref(),
  radioChange = (val) => {
    businessStripData.value = val
  },
  submit = () => {
    dialogVisible.value = false
    formData.value.higherSuperOrgCode = businessStripData.value.businessStripCode
    formData.value.higherSuperOrg = businessStripData.value.businessStripName
  },
  isDisabledCreditCode = ref({}),
  getCode = async (name, code) => {
    const res = await getOrganizationByCode(code || userInfo.value.empPosUnitCode)
    isDisabledCreditCode.value[name] = !!res.data.unifiedSocialCreditCode
    formData.value[name] = res.data.unifiedSocialCreditCode || formData.value[name]
  },
  // 选择负责人、联系人
  userDialogData = reactive({
    visible: false,
    params: {}
  }),
  filedName = ref(),
  filedPhone = ref(),
  showUserDialog = (name, phone) => {
    userDialogData.visible = true
    filedName.value = name
    filedPhone.value = phone
  },
  getUserData = (data) => {
    formData.value[filedName.value] = data.name
    formData.value[filedPhone.value] = data.phoneNo
  },
  // 上级主管单位类型
  changeBaseProvManDeprtType = (val, data) => {
    formData.value.higherSuperOrgCode = ''
    formData.value.higherSuperOrg = ''
  },
  // 关联项目
  columnPro = [
    {
      label: '序号',
      type: 'index',
      width: 60
    },
    {
      label: '项目名称',
      prop: 'baseProjName',
      key: 'baseProjName'
    },
    {
      label: '预算年度',
      prop: 'baseProjSetYear',
      key: 'baseProjSetYear'
    },
    {
      label: '操作',
      slot: 'action',
      key: 'action'
    }
  ],
  relatedProjectDialogData = reactive({
    visible: false
  }),
  showRelatedProjectDialog = () => {
    relatedProjectDialogData.visible = true
    relatedProjectDialogData.data = formData.value.baseHistorProjs
  },
  getProjectList = (data) => {
    formData.value.baseHistorProjs = data.map(i => {
      return {
        baseProjName: i.projectName,
        baseProjSetYear: i.projectYear,
        baseProjId: i.id
      }
    })
  },
  delPro = (index) => {
    formData.value.baseHistorProjs.splice(index, 1)
  },
  // 项目内容与预期成效
  columnContent = [
    {
      label: '项目主要内容',
      prop: 'mainContent',
      key: 'mainContent'
    },
    {
      label: '业务对象',
      prop: 'businessObject',
      key: 'businessObject'
    },
    {
      label: '操作',
      slot: 'action',
      key: 'action'
    }
  ],
  projectContentDialogData = reactive({
    visible: false,
    data: undefined
  }),
  projectContentIndex = ref(),
  showProjectContentDialog = (data, index) => {
    projectContentDialogData.data = data
    projectContentDialogData.visible = true
    projectContentIndex.value = index
  },
  setContent = (data) => {
    if (projectContentIndex.value === undefined) {
      formData.value.beseExpectedResults.push(data)
    } else {
      formData.value.beseExpectedResults[projectContentIndex.value] = data
    }
  },
  delProjectContent = (index) => {
    formData.value.beseExpectedResults.splice(index, 1)
  },
  templateTypeListData = ref(),
  getTemplateTypeList = async () => {
    const res = await templateTypePage({
      pageNumber: 1,
      pageSize: 10000
    })
    templateTypeListData.value = res?.data?.records || []
  }
onMounted(() => {
  getTemplateTypeList()
  getCode('orgCreditCode')
})
watch(() => props.declareAmount, val => {
  if (val >= 1000) {
    formData.value.isDigitalReform = 1
  }
})

defineExpose({ validForm, formData, setFormData })
watch(() => props.dictionaryList, val => {
  if (val) {
    buildBasisTableData.value = []
    props.dictionaryList?.filter(i => i.type === 'PROJECT_BASIS').forEach(i => {
      buildBasisTableData.value.push({
        title: i.label,
        fileName: '',
        fileList: [],
        value: i.value
      })
    })
  }
})
watch(() => formData.value, val => {
  emits('getBasicInfoData', formData.value)
}, { deep: true })
</script>

<template>
  <el-form
    ref="formRef"
    :model="formData"
    :rules="rules"
    label-position="right"
    label-width="180px"
    label-suffix=":"
    scroll-to-error
    :validate-on-rule-change="false"
  >
    <el-row :gutter="40">
      <el-col :span="24">
        <el-form-item label="是否涉密" prop="baseProjIsConfidentiality">
          <el-radio-group v-model="formData.baseProjIsConfidentiality">
            <el-radio label="01">否</el-radio>
            <el-radio label="02">是</el-radio>
          </el-radio-group>
        </el-form-item>
      </el-col>
      <el-col :span="24">
        <el-form-item label="项目名称" prop="projectName">
          <el-input v-model="formData.projectName" maxlength="50" placeholder="请输入" />
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="项目类型" prop="projectType">
          <el-radio-group v-model="formData.projectType" :disabled="$route.name==='declarePlan'||[10012,10013,10016].includes(detailData?.status)">
            <el-radio label="01">首次建设</el-radio>
            <el-radio label="02">迭代升级</el-radio>
          </el-radio-group>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="内容类别" prop="baseConstructionType">
          <el-checkbox-group v-model="formData.baseConstructionType">
            <el-checkbox v-for="(item,index) in dictionaryList?.filter(i => i.type === 'CONTENT_TYPE')" :key="index" :label="item.value">{{ item.label }}</el-checkbox>
          </el-checkbox-group>
        </el-form-item>
      </el-col>
      <template v-if="formData.baseProjIsConfidentiality==='01'">
        <el-col :span="12">
          <el-form-item label="是否首次新建" prop="isFirst">
            <el-radio-group v-model="formData.isFirst" :disabled="$route.name==='declarePlan'||[10012,10013,10016].includes(detailData?.status)" @change="changeIsFirst">
              <el-radio :label="1">是</el-radio>
              <el-radio :label="0">否</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="是否一地创新全省共享项目" label-width="auto" prop="isInnovateWholeProvinceShare">
            <el-radio-group v-model="formData.isInnovateWholeProvinceShare" :disabled="$route.name==='declarePlan'||[10012,10013,10016].includes(detailData?.status)">
              <el-radio :label="true">是</el-radio>
              <el-radio :label="false">否</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col v-if="route.name!='planEdit'" :span="12">
          <el-form-item label="是否临时增补" prop="isTemporaryAugment">
            <el-radio-group v-model="formData.isTemporaryAugment" :disabled="$route.name==='declarePlan'||[10012,10013,10016].includes(detailData?.status)">
              <el-radio :label="1">是</el-radio>
              <el-radio :label="0">否</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
      </template>
      <el-col :span="12">
        <el-form-item label="项目负责人" prop="responsibleMan">
          <el-input
            v-model="formData.responsibleMan"
            maxlength="50"
            readonly
            placeholder="请选择，温馨提示：项目负责人请填写领导信息"
            @click="showUserDialog('responsibleMan','responsibleManMobile')"
          />
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="项目负责人手机号" prop="responsibleManMobile">
          <el-input
            v-model="formData.responsibleManMobile"
            maxlength="11"
            placeholder="请选择"
            readonly
            @click="showUserDialog('responsibleMan','responsibleManMobile')"
          />
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="项目联系人" prop="contactName">
          <el-input
            v-model="formData.contactName"
            maxlength="50"
            placeholder="请选择"
            readonly
            @click="showUserDialog('contactName','contactPhone')"
          />
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="项目联系人手机号" prop="contactPhone">
          <el-input
            v-model="formData.contactPhone"
            maxlength="11"
            placeholder="请选择"
            readonly
            @click="showUserDialog('contactName','contactPhone')"
          />
        </el-form-item>
      </el-col>
      <el-col v-if="formData.baseProjIsConfidentiality==='01'" :span="12">
        <el-form-item label="建设起止年限" prop="buildDuration">
          <el-date-picker
            v-model="formData.buildDuration"
            type="daterange"
            range-separator="-"
            start-placeholder="开始时间"
            end-placeholder="结束时间"
            format="YYYY-MM-DD"
            value-format="YYYY-MM-DD"
          />
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="建设单位" prop="buildOrgName">
          <el-input v-model="formData.buildOrgName" placeholder="请输入" :disabled="true" />
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="建设单位统一信用代码" prop="orgCreditCode">
          <el-input
            v-model="formData.orgCreditCode"
            maxlength="18"
            placeholder="请输入"
            :disabled="isDisabledCreditCode['orgCreditCode']"
          />
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="上级主管单位类型" prop="baseProvManDeprtType">
          <el-radio-group v-model="formData.baseProvManDeprtType" :disabled="$route.name==='declarePlan'||[10012,10013,10016].includes(detailData?.status)" @change="changeBaseProvManDeprtType">
            <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="higherSuperOrg">
          <el-input v-if="$route.name==='declarePlan'||[10012,10013,10016].includes(detailData?.status)" v-model="formData.higherSuperOrg" disabled />
          <el-input
            v-else-if="formData.baseProvManDeprtType==='1'"
            v-model="formData.higherSuperOrg"
            placeholder="请选择"
            readonly
            @click="showDialog"
          />
          <el-input
            v-else
            v-model="formData.higherSuperOrg"
            placeholder="请选择"
            readonly
            @click="showLineOrgTree"
          />
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="本级主管单位" prop="superOrg">
          <el-input v-if="$route.name==='declarePlan'||[10012,10013,10016].includes(detailData?.status)" v-model="formData.superOrg" disabled />
          <el-input
            v-else
            v-model="formData.superOrg"
            placeholder="请选择"
            readonly
            :disabled="$route.name==='declarePlan'||[10012,10013,10016].includes(detailData?.status)"
            @click="showOrgTree"
          />

        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="本级主管单位统一社会信用代码" prop="superOrgCreditCode">
          <el-input v-model="formData.superOrgCreditCode" placeholder="请填写" :disabled="isDisabledCreditCode['superOrgCreditCode']||$route.name==='declarePlan'||[10012,10013,10016].includes(detailData?.status)" />
        </el-form-item>
      </el-col>
      <template v-if="formData.baseProjIsConfidentiality==='01'">
        <el-col :span="24">
          <el-form-item label="四大体系" prop="fourSystems">
            <el-radio-group v-model="formData.fourSystems" :disabled="$route.name==='declarePlan'||[10012,10013,10016].includes(detailData?.status)">
              <el-radio v-for="(v,k) in fourSystem" :key="k" :label="k*1">{{ v }}</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="绩效评价类型" prop="templateType">
            <el-radio-group v-model="formData.templateType" :disabled="$route.name==='declarePlan'||[10012,10013,10016].includes(detailData?.status)">
              <el-radio
                v-for="(v,k) in templateTypeListData"
                :key="k"
                :label="v.id"
              >
                {{ v.name }}
              </el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="是否数字化改革项目" prop="isDigitalReform">
            <el-radio-group v-model="formData.isDigitalReform" :disabled="$route.name==='declarePlan'||[10012,10013,10016].includes(detailData?.status)">
              <el-radio :label="1">是</el-radio>
              <el-radio :label="0">否</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item v-if="formData.isDigitalReform === 1" label="综合业务领域" prop="bizDomain">
            <el-select
              v-model="formData.bizDomain"
              placeholder="请选择"
              class="w-full"
              multiple
              :disabled="$route.name==='declarePlan'||[10012,10013,10016].includes(detailData?.status)"
            >
              <el-option
                v-for="(v, k) in businessTerritory"
                :key="k"
                :label="v"
                :value="k"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="建设层级" prop="buildLevel">
            <el-radio-group v-model="formData.buildLevel">
              <el-radio
                v-for="(item,index) in dictionaryList?.filter(i => i.type === 'BUILD_LEVEL')"
                :key="index"
                :label="item.value"
              >{{ item.label }}
              </el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col v-if="!(formData?.baseConstructionType?.includes('03')&&!formData?.baseConstructionType?.includes('01'))" :span="24">
          <el-form-item v-if="formData?.baseConstructionType?.includes('01')" label="贯通层级" prop="lowestLevel">
            <el-radio-group v-model="formData.lowestLevel">
              <el-radio
                v-for="(item,index) in dictionaryList?.filter(i => i.type === 'BUILD_LEVEL')"
                :key="index"
                :label="item.value"
              >{{ item.label }}
              </el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item v-else label="贯通层级">
            <el-radio-group v-model="formData.lowestLevel">
              <el-radio
                v-for="(item,index) in dictionaryList?.filter(i => i.type === 'BUILD_LEVEL')"
                :key="index"
                :label="item.value"
              >{{ item.label }}
              </el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="立项依据材料" prop="baseProjBasis">
            <table-list
              ref="tableListRef"
              :pagination="false"
              style="width: 100%"
              :column="buildBasisColumn"
              :data="buildBasisTableData"
              @selection-change="selectionChange"
            >
              <template #fileName="{scope}">
                <el-form-item v-if="formData.baseProjBasis&&formData.baseProjBasis.map(i=>i.value).includes(scope.row.value)">
                  <el-input
                    :value="formData.baseProjBasis[formData.baseProjBasis.findIndex(i=>i.value===scope.row.value)]?.fileList?.[0]?.name"
                    placeholder="请输入"
                    :maxlength="50"
                    :disabled="true"
                  />
                </el-form-item>
                <el-input v-else :disabled="true" />
              </template>
              <template #action="{scope}">
                <el-form-item
                  v-if="formData.baseProjBasis&&formData.baseProjBasis.map(i=>i.value).includes(scope.row.value)"
                  class="basicUploadItem"
                  :rules="{required: true,message:'请上传'}"
                  :prop="`baseProjBasis[${formData.baseProjBasis.findIndex(i=>i.value===scope.row.value)}].fileList`"
                >
                  <el-upload
                    ref="materialUploadRef"
                    v-model:file-list="formData.baseProjBasis[formData.baseProjBasis.findIndex(i=>i.value===scope.row.value)].fileList"
                    class="flex items-center flex-col w-full"
                    :action="uploadUrl"
                    :on-success="res => handleFileSuccess(res, formData.baseProjBasis[formData.baseProjBasis.findIndex(i=>i.value===scope.row.value)].fileList, true)"
                    :on-error="handleFileError"
                    :before-upload="file=>fileFormatVerification(file, {
                      types: fileTypes
                    })"
                    :limit="1"
                    :accept="fileTypes.map(i=>`.${i}`).join(',')"
                    :on-preview="handleFilePreview"
                  >
                    <template #trigger>
                      <div>
                        <a>上传</a>
                      </div>
                    </template>
                  </el-upload>
                </el-form-item>
                <span v-else class="text-info cursor-not-allowed">上传</span>
              </template>
            </table-list>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="立项依据说明" prop="baseBasisEstablish">
            <el-input
              v-model="formData.baseBasisEstablish"
              type="textarea"
              show-word-limit
              placeholder="请填写"
              :maxlength="150"
            />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item v-if="declareAmount>=1000&&false" label="发改编码" prop="developCode">
            <el-input
              v-model="formData.developCode"
              maxlength="50"
              placeholder="请填写"
              :disabled="$route.name==='declarePlan'||[10012,10013,10016].includes(detailData?.status)"
            />
          </el-form-item>
          <el-form-item v-else label="发改编码">
            <el-input
              v-model="formData.developCode"
              maxlength="50"
              placeholder="请填写"
              :disabled="$route.name==='declarePlan'||[10012,10013,10016].includes(detailData?.status)"
            />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item v-if="declareAmount>=1000&&false" label="财政编码" prop="financialCode">
            <el-input
              v-model="formData.financialCode"
              maxlength="50"
              placeholder="请填写"
              :disabled="$route.name==='declarePlan'||[10012,10013,10016].includes(detailData?.status)"
            />
          </el-form-item>
          <el-form-item v-else label="财政编码">
            <el-input
              v-model="formData.financialCode"
              maxlength="50"
              placeholder="请填写"
              :disabled="$route.name==='declarePlan'||[10012,10013,10016].includes(detailData?.status)"
            />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="是否上云" prop="isCloud">
            <el-radio-group v-model="formData.isCloud">
              <el-radio :label="1">是</el-radio>
              <el-radio :label="0">否</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col v-if="formData.isCloud===1" :span="24">
          <el-form-item label="云类型" prop="cloudType">
            <el-checkbox-group v-model="formData.cloudType">
              <el-checkbox label="1">政务云（非信创）</el-checkbox>
              <el-checkbox label="2">政务云（信创）</el-checkbox>
              <el-checkbox label="3">其他</el-checkbox>
            </el-checkbox-group>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="系统定位" prop="systemPosition">
            <el-input
              v-model="formData.systemPosition"
              :rows="4"
              type="textarea"
              placeholder="请输入"
              show-word-limit
              maxlength="2000"
            />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="项目简介" prop="projectIntroduction">
            <el-input
              v-model="formData.projectIntroduction"
              :rows="4"
              type="textarea"
              placeholder="请输入"
              show-word-limit
              maxlength="2000"
            />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item v-if="formData.projectType!=='01'" label="历年项目名称" prop="baseHistorProjs">
            <p class="text-right w-full mb-8">
              <el-button type="primary" @click="showRelatedProjectDialog">关联历年项目</el-button>
            </p>
            <table-list
              :pagination="false"
              style="width: 100%"
              :column="columnPro"
              :data="formData.baseHistorProjs"
              :empty-temp="false"
            >
              <template #action="{scope}">
                <a class="text-danger" @click="delPro(scope.$index)">删除</a>
              </template>
            </table-list>
          </el-form-item>
          <el-form-item v-else label="历年项目名称">
            <p class="text-right w-full mb-8">
              <el-button type="primary" @click="showRelatedProjectDialog">关联历年项目</el-button>
            </p>
            <table-list
              :pagination="false"
              style="width: 100%"
              :column="columnPro"
              :data="formData.baseHistorProjs"
              :empty-temp="false"
            >
              <template #action="{scope}">
                <a class="text-danger" @click="delPro(scope.$index)">删除</a>
              </template>
            </table-list>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="项目内容与预期成效" prop="beseExpectedResults">
            <table-list
              :pagination="false"
              style="width: 100%"
              :column="columnContent"
              :data="formData.beseExpectedResults"
              :empty-temp="false"
            >
              <template #action="{scope}">
                <a @click="showProjectContentDialog(scope.row,scope.$index)">编辑</a>
                <a class="text-danger" @click="delProjectContent(scope.$index)">删除</a>
              </template>
            </table-list>
            <p class="text-right w-full mt-8">
              <el-button
                type="primary"
                class="w-full"
                plain
                icon="Plus"
                @click="()=>showProjectContentDialog()"
              >添加</el-button>
            </p>
          </el-form-item>
        </el-col>
      </template>
      <template v-if="formData.baseProjIsConfidentiality==='02'">
        <el-col :span="12">
          <el-form-item label="预算年度" prop="projectYear">
            <el-date-picker
              v-model="formData.projectYear"
              :disabled="$route.name==='declarePlan'||[10012,10013,10016].includes(detailData?.status)"
              type="year"
              placeholder="请选择"
              format="YYYY"
              value-format="YYYY"
            />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="申报金额" prop="declareAmount">
            <el-input-number
              v-model="formData.declareAmount"
              placeholder="请填写"
              :min="0.000001"
              :controls="false"
              @mousewheel.prevent
            />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="年度支付金额" prop="annualPlanAmount">
            <el-input-number
              v-model="formData.annualPlanAmount"
              placeholder="请填写"
              :min="0"
              :controls="false"
              @mousewheel.prevent
            />
          </el-form-item>
        </el-col>
      </template>
    </el-row>
  </el-form>
  <org-tree
    :visible="orgProps.unitVisible"
    :show-checkbox="false"
    :default-data="orgProps.data"
    :title="orgProps.title"
    :type="orgProps.type"
    :default-props="orgProps.defaultProps"
    :params="orgProps.params"
    @close="closeOrg"
    @get-select-unit="getOrgData"
  />
  <el-dialog
    :model-value="dialogVisible"
    title="上级条线主管单位"
    width="60%"
    @close="dialogVisible = false"
  >
    <el-form
      :model="searchForm"
      size="small"
      label-suffix=":"
    >
      <el-row
        :gutter="16"
        class="mb-16"
      >
        <el-col :span="8">
          <el-form-item label="单位名称">
            <el-input
              v-model="searchForm.businessStripName"
              placeholder="请输入"
            />
          </el-form-item>
        </el-col>
        <el-col :span="16">
          <el-form-item class="btn">
            <div class="flex">
              <el-button
                type="primary"
                @click="getTableData"
              >查询</el-button>
              <el-button
                @click="reset"
              >重置</el-button>
            </div>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <table-list
      ref="tableListRef"
      :column="column"
      :data="tableData"
      :pagination="false"
      style="height: 600px;overflow: auto"
      @get-table-data="getTableData"
      @radio-change="radioChange"
    />
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="dialogVisible = false">关闭</el-button>
        <el-button
          type="primary"
          @click="submit"
        >
          提交
        </el-button>
      </span>
    </template>
  </el-dialog>
  <user-dialog
    :visible="userDialogData.visible"
    :params="userDialogData.params"
    @close="userDialogData.visible=false"
    @get-user-data="getUserData"
  />
  <related-project-dialog
    :visible="relatedProjectDialogData.visible"
    :data="relatedProjectDialogData.data"
    @get-project-list="getProjectList"
    @close="relatedProjectDialogData.visible=false"
  />
  <project-content-dialog
    :visible="projectContentDialogData.visible"
    :data="projectContentDialogData.data"
    @set-content="setContent"
    @close="projectContentDialogData.visible=false"
  />
</template>

<style lang="less">
.el-upload-list{
  width: 100%;
}
.basicUploadItem{
  .el-upload-list__item-file-name{
    white-space: pre-wrap;
  }
  .el-form-item__error{
    top: 60%;
    width: 100%;
    text-align: center;
  }
}
</style>
