<script setup name="formConfiguration">
import { ref, getCurrentInstance, watch, nextTick } from 'vue'
import ElTree from '@/components/elTree/index.vue'
import {
  saveFormConfig,
  getFormConfig
} from '@/http/apis/systemManage/formConfiguration'
import store from '@/store'
import { getIsShowRegionTree, getTreeParams } from '@/utils/getIsShowRegionTree'
const { proxy } = getCurrentInstance(),
  {
    fourSystem,
    businessTerritory,
    constructionLevel,
    projectBasisMaterials,
    coreBusiness, projectTypeOptions
  } = store.dictStore.globalDicts || {},
  column1 = [
    {
      label: '依据项',
      key: 'yjx',
      prop: 'yjx'
    },
    {
      label: '依据文件名',
      key: 'yjwjm',
      prop: 'yjwjm',
      width: 250
    },
    {
      label: '文件',
      slot: 'action',
      width: 100
    }
  ],
  column2 = [
    {
      label: '序号',
      type: 'index',
      width: 100
    },
    {
      label: '业务编号',
      key: 'ywbh',
      prop: 'ywbh'
    },
    {
      label: '业务名称',
      key: 'ywmc',
      prop: 'ywmc',
      width: 250
    },
    {
      label: '所属单位',
      key: 'shdw',
      prop: 'shdw',
      width: 100
    }
  ],
  pagination = false,
  collapseModal = ref('1'),
  collapseModal1 = ref('1'),
  collapseModal2 = ref('1'),
  collapseModal3 = ref('1'),
  collapseModal4 = ref('1'),
  collapseModal5 = ref('1'),
  collapseModal6 = ref('1'),
  collapseModal7 = ref('1'),
  collapseModal8 = ref('1'),
  collapseModal9 = ref(['1']),
  baseForm = ref({}),
  capitalForm = ref({}),
  totalMoneyForm = ref({}),
  annualPlanForm = ref({}),
  safetyInvestmentForm = ref({}),
  moduleActiveList = ref([0]),
  safetyInputModular = ref([]),
  addModuleFn = () => {
    if (safetyInputModular.value && safetyInputModular.value.length >= 10) {
      proxy.$message.error('模块最多可增加10个！')
      return
    }
    if (safetyInputModular.value && moduleActiveList.value) moduleActiveList.value.push(safetyInputModular.value.length)
    safetyInputModular.value.push({
      // id: safetyInputModular.value.length
    })
  },
  visible = ref(false),
  addIndx = ref(),
  addField = (index) => {
    if (safetyInputModular.value[index].formList?.length >= 10) {
      proxy.$message.warning('最多加10个字段')
      return
    }
    addIndx.value = index
    visible.value = true
  },
  addForm = ref({
    optionList: [{}],
    type: '输入'
  }),
  formNameValidator = (rule, value, callback) => {
    if (
      safetyInputModular.value[addIndx.value].formList &&
      safetyInputModular.value[addIndx.value].formList.length > 0
    ) {
      if (
        safetyInputModular.value[addIndx.value].formList.findIndex(
          (item) => item.formName === value
        ) !== -1
      ) {
        callback('重复字段名称!')
      } else {
        callback()
      }
    } else {
      callback()
    }
  },
  optionListNameValidator = (rule, value, callback) => {
    const newArr = addForm.value.optionList.filter(
      (item) => item.name === value
    )
    if (newArr && newArr.length > 1) {
      callback('重复选项!')
    } else {
      callback()
    }
  },
  addFormRules = {
    formName: [
      { required: true, message: '登录名不能为空', trigger: 'blur' },
      { validator: formNameValidator, trigger: 'blur' }
    ],
    type: [{ required: true, message: '请选择字段类型', trigger: 'change' }],
    maxLength: [{ required: true, message: '请输入最大长度', trigger: 'blur' }],
    minNumber: [{ required: true, message: '请输入最小数值', trigger: 'blur' }],
    maxNumber: [{ required: true, message: '请输入最大数值', trigger: 'blur' }],
    fileNumber: [
      { required: true, message: '请输入文件个数', trigger: 'blur' }
    ],
    isRequired: [
      { required: true, message: '请选择是否必填', trigger: 'blur' }
    ],
    formSort: [{ required: true, message: '请输入排序', trigger: 'blur' }]
  },
  addFormRef = ref(),
  confirmFn = (formEl) => {
    if (!formEl) {
      return
    }
    formEl.validate((valid) => {
      if (valid) {
        if (
          safetyInputModular.value[addIndx.value].formList &&
          safetyInputModular.value[addIndx.value].formList.length > 0
        ) {
          console.log(123)
        } else {
          safetyInputModular.value[addIndx.value].formList = []
        }
        const params = {
          name: addForm.value.formName,
          props: {
            required: addForm.value.isRequired,
            sort: Number(addForm.value.formSort),
            type: addForm.value.type
          }
        }
        switch (addForm.value.type) {
          case '输入':
            params.props.maxLength = addForm.value.maxLength
            params.valueType = 'String'
            break
          case '数值输入':
            if (addForm.value.minNumber > addForm.value.maxNumber) {
              proxy.$message.error('最小数值不能大于最大数值！')
              return
            }
            params.props.minNumber = addForm.value.minNumber
            params.props.maxNumber = addForm.value.maxNumber
            params.valueType = 'Number'
            break
          case '单选':
            params.valueType = 'String'
            params.props.options = addForm.value.optionList
            params.props.optionName = addForm.value.optionList
              .map((item) => {
                return item.name
              })
              .join(',')
            break
          case '多选':
            params.valueType = 'Array'
            params.props.options = addForm.value.optionList
            params.props.optionName = addForm.value.optionList
              .map((item) => {
                return item.name
              })
              .join(',')
            break
          case '文件上传':
            params.valueType = 'Array'
            params.props.fileNumber = addForm.value.fileNumber
            break

          default:
            break
        }
        safetyInputModular.value[addIndx.value].formList.push(params)
        visible.value = false
        proxy.$message.success('成功！')
        addForm.value = {
          optionList: [{}],
          type: '输入'
        }
      }
    })
  },
  isCoreBusiness = ref(false),
  isSafetyInput = ref(false),
  isProjectImageProgress = ref(false),
  isAccessory = ref(true),
  isRemark = ref(false),
  isAnnualPaymentPlan = ref(true),
  moduleFormRef = ref(),
  loading = ref(false),
  saveConfigurationFn = async () => {
    let flag = false
    safetyInputModular.value.forEach(data => {
      if (!data.formList || !data.formList.length) {
        flag = true
      }
    })
    if (flag) {
      proxy.$message.warning('请勿增加空模块')
      return false
    }
    const params = {
      id: id.value ? id.value : undefined,
      isCoreBusiness: isCoreBusiness.value,
      isSafetyInput: isSafetyInput.value,
      isProjectImageProgress: isProjectImageProgress.value,
      isAccessory: isAccessory.value,
      isRemark: isRemark.value,
      isAnnualPaymentPlan: isAnnualPaymentPlan.value,
      isReviewChecklist: isReviewChecklist.value,
      reviewChecklist: reviewInfoForm?.value.reviewChecklist || []
    }
    loading.value = true
    var results = []
    if (safetyInputModular.value && safetyInputModular.value.length > 0) {
      results = moduleFormRef.value?.map(formRef => {
        return new Promise((resolve, reject) => {
          formRef.validate((valid) => {
            if (valid) {
              resolve(valid)
            } else {
              reject(valid)
            }
          })
        })
      })
    }
    results.push(new Promise((resolve, reject) => {
      reviewInfoFormRef.value?.validate(valid => {
        if (valid) {
          resolve(valid)
        } else {
          reject(valid)
        }
      })
    }))
    Promise.all(results)
      .then(async (info) => {
        const postData = {
          ...params,
          safetyInputModular: safetyInputModular.value?.length ? safetyInputModular.value.map((i, index) => {
            return {
              ...i,
              id: index
            }
          }) : []
        }
        await saveFormConfig(postData)
        proxy.$message.success('保存成功！')
        loading.value = false
      })
      .catch((err) => {
        loading.value = false
        console.log(err)
        return false
      })
  },
  delOption = (index) => {
    addForm.value.optionList.splice(index, 1)
  },
  addOption = () => {
    if (addForm.value.optionList?.length >= 10) {
      proxy.$message.warning('最多加10个选项')
      return
    }
    addForm.value.optionList.push({})
  },
  delModule = (index) => {
    safetyInputModular.value.splice(index, 1)
    moduleActiveList.value.splice(index, 1)
  },
  selectFn = () => {},
  id = ref(),
  formId = ref(),
  formName = ref(),
  initForm = () => {
    formId.value = ''
    isCoreBusiness.value = false
    isSafetyInput.value = false
    isProjectImageProgress.value = false
    isAccessory.value = true
    isRemark.value = false
    isAnnualPaymentPlan.value = true
    moduleFormRef.value = undefined
    safetyInputModular.value = []
  },
  getConfigFn = async () => {
    initForm()
    const res = await getFormConfig({
      regionCode: treeForm.value
    })
    id.value = res.data.id
    formId.value = res.data.formId
    formName.value = res.data.formName
    isCoreBusiness.value = res.data.isCoreBusiness
    isSafetyInput.value = res.data.isSafetyInput
    isProjectImageProgress.value = res.data.isProjectImageProgress
    isAccessory.value = res.data.isAccessory
    isRemark.value = res.data.isRemark
    isAnnualPaymentPlan.value = res.data.isAnnualPaymentPlan
    isReviewChecklist.value = res.data.isReviewChecklist
    reviewInfoForm.value = {
      reviewChecklist: res.data.reviewChecklist ? JSON.parse(res.data.reviewChecklist) : [{
        modules: [{}]
      }]
    }
    if (res.data.safetyInputModular && res.data.safetyInputModular.length > 0) {
      safetyInputModular.value = res.data.safetyInputModular
      moduleActiveList.value = res.data.safetyInputModular.map((item, index) => {
        return index
      })
    }
  },
  treeForm = ref({}),
  getTree = (value) => {
    treeForm.value = value.regionLevel === 3 ? value.regionCode : undefined
    getConfigFn()
  },
  // 审查清单
  isReviewChecklist = ref(false),
  reviewInfoFormRef = ref(),
  reviewInfoForm = ref({
    reviewChecklist: [{
      modules: [{}]
    }]
  }),
  addList = () => {
    reviewInfoForm.value.reviewChecklist.push({ modules: [{}] })
  },
  addChild = (index) => {
    reviewInfoForm.value.reviewChecklist[index].modules.push({})
  },
  delChild = (index, key) => {
    reviewInfoForm.value.reviewChecklist[index].modules.splice(key, 1)
  },
  delList = (index) => {
    reviewInfoForm.value.reviewChecklist.splice(index, 1)
  }
watch(visible, (val) => {
  nextTick(() => {
    if (!val) {
      console.log(val)
    }
  })
})
</script>

<template>
  <div class="mainBox">
    <el-row>
      <el-col v-if="getIsShowRegionTree(['SUPER_ADMIN','REGION_MANAGER'])" style="padding-right: 16px" :span="4">
        <elTree :params="getTreeParams({'SUPER_ADMIN':false,'REGION_MANAGER':false})" @get-tree="getTree" />
      </el-col>
      <el-col :span="getIsShowRegionTree(['SUPER_ADMIN','REGION_MANAGER'])?20:24" class="leftCol">
        <el-collapse v-model="collapseModal">
          <el-collapse-item name="1">
            <template #title>
              <div class="collapse-title">基本信息（字段不可修改）</div>
            </template>
            <el-form
              :model="baseForm"
              label-position="right"
              label-width="180px"
              label-suffix=":"
            >
              <el-row :gutter="40">
                <el-col :span="12">
                  <el-form-item label="项目名称" prop="num1">
                    <el-input
                      v-model="baseForm.num1"
                      disabled
                      placeholder="请输入"
                    />
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="是否一地创新全省共享项目" label-width="auto" required>
                    <el-radio-group disabled>
                      <el-radio :label="true">是</el-radio>
                      <el-radio :label="false">否</el-radio>
                    </el-radio-group>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="是否临时增补" prop="num2">
                    <el-radio-group v-model="baseForm.num2" disabled>
                      <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="num3">
                    <el-input
                      v-model="baseForm.num3"
                      disabled
                      placeholder="请输入"
                    />
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="项目负责人手机号" prop="num4">
                    <el-input
                      v-model="baseForm.num4"
                      disabled
                      placeholder="请输入"
                    />
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="项目联系人" prop="num5">
                    <el-input
                      v-model="baseForm.num5"
                      disabled
                      placeholder="请输入"
                    />
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="项目联系人手机号" prop="num6">
                    <el-input
                      v-model="baseForm.num6"
                      disabled
                      placeholder="请输入"
                    />
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="建设单位" prop="num7">
                    <el-input
                      v-model="baseForm.num7"
                      disabled
                      placeholder="请输入"
                    />
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="建设单位统一信用代码" prop="num8">
                    <el-input
                      v-model="baseForm.num8"
                      disabled
                      placeholder="请输入"
                    />
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="项目类型" prop="num9">
                    <el-radio-group v-model="baseForm.num9" disabled>
                      <el-radio
                        v-for="(v,k) in projectTypeOptions"
                        :key="k"
                        :label="k"
                      >{{ v }}</el-radio>
                    </el-radio-group>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="是否首次新建" prop="num10">
                    <el-radio-group v-model="baseForm.num10" disabled>
                      <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="建设起止年限" required>
                    <el-date-picker
                      disabled
                      type="datetimerange"
                      range-separator="-"
                      start-placeholder="开始时间"
                      end-placeholder="结束时间"
                      format="YYYY-MM"
                      value-format="YYYY-MM"
                    />
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="预算年度" prop="num11">
                    <el-date-picker
                      v-model="baseForm.num11"
                      disabled
                      type="year"
                      placeholder="请选择"
                    />
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="四大体系" prop="num12">
                    <el-select
                      v-model="baseForm.num12"
                      disabled
                      placeholder="请选择"
                    >
                      <el-option
                        v-for="(item, index) in fourSystem"
                        :key="index"
                        :label="item"
                        :value="index"
                      />
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="是否数字化改革项目" prop="num13">
                    <el-radio-group v-model="baseForm.num13" disabled>
                      <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="num14">
                    <el-select
                      v-model="baseForm.num14"
                      disabled
                      placeholder="请选择"
                    >
                      <el-option
                        v-for="(item, index) in businessTerritory"
                        :key="index"
                        :label="item"
                        :value="index"
                      />
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="24">
                  <el-form-item label="建设层级" prop="num15">
                    <el-radio-group v-model="baseForm.num15" disabled>
                      <el-radio
                        v-for="(item, index) in constructionLevel"
                        :key="index"
                        :label="index"
                      >{{ item }}
                      </el-radio>
                    </el-radio-group>
                  </el-form-item>
                </el-col>
                <el-col :span="24">
                  <el-form-item label="立项依据材料" prop="num16">
                    <table-list
                      :pagination="pagination"
                      style="width: 100%"
                      :column="column1"
                      :data="projectBasisMaterials"
                    >
                      <template #action>
                        <span>上传</span>
                      </template>
                    </table-list>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="发改编码" prop="num17">
                    <el-input
                      v-model="baseForm.num17"
                      disabled
                      placeholder="请输入"
                    />
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="财政编码" prop="num18">
                    <el-input
                      v-model="baseForm.num18"
                      disabled
                      placeholder="请输入"
                    />
                  </el-form-item>
                </el-col>
                <el-col :span="24">
                  <el-form-item label="是否上云" prop="num19">
                    <el-radio-group v-model="baseForm.num19" disabled>
                      <el-radio :label="1">是</el-radio>
                      <el-radio :label="2">否</el-radio>
                    </el-radio-group>
                  </el-form-item>
                </el-col>
                <el-col :span="24">
                  <el-form-item label="云类型" prop="num20">
                    <el-checkbox-group v-model="baseForm.num20" disabled>
                      <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="num21">-->
                <!--                    <el-radio-group v-model="baseForm.num21" disabled>-->
                <!--                      <el-radio-->
                <!--                        v-for="(item, index) in insuranceLevel"-->
                <!--                        :key="index"-->
                <!--                        :label="index"-->
                <!--                      >{{ item }}</el-radio>-->
                <!--                    </el-radio-group>-->
                <!--                  </el-form-item>-->
                <!--                </el-col>-->
                <!--                <el-col :span="24">-->
                <!--                  <el-form-item label="是否密评" prop="num22">-->
                <!--                    <el-radio-group v-model="baseForm.num22" disabled>-->
                <!--                      <el-radio :label="1">是</el-radio>-->
                <!--                      <el-radio :label="2">否</el-radio>-->
                <!--                    </el-radio-group>-->
                <!--                  </el-form-item>-->
                <!--                </el-col>-->
                <el-col :span="24">
                  <el-form-item label="项目简介" prop="num23">
                    <el-input
                      v-model="baseForm.num23"
                      disabled
                      :rows="4"
                      type="textarea"
                      placeholder="请输入"
                    />
                  </el-form-item>
                </el-col>
              </el-row>
            </el-form>
          </el-collapse-item>
        </el-collapse>
        <el-collapse v-model="collapseModal1" class="marginTop">
          <el-collapse-item name="1">
            <template #title>
              <div class="collapse-title">资金申报情况（字段不可修改）</div>
            </template>
            <el-form
              :model="capitalForm"
              label-position="right"
              label-width="180px"
              label-suffix=":"
            >
              <el-row>
                <el-col :span="12">
                  <el-form-item label="申报金额" prop="sum1">
                    <el-input-number
                      v-model="capitalForm.sum1"
                      disabled
                      placeholder="请填写"
                      :min="0"
                      :controls="false"
                    />
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="12">
                  <el-form-item label="自有资金" prop="sum2">
                    <el-input-number
                      v-model="capitalForm.sum2"
                      disabled
                      placeholder="请填写"
                      :min="0"
                      :controls="false"
                    />
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="政府投资-本级财政资金" prop="sum3">
                    <el-input-number
                      v-model="capitalForm.sum3"
                      disabled
                      placeholder="请填写"
                      :min="0"
                      :controls="false"
                    />
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="政府投资-上级补助资金" prop="sum4">
                    <el-input-number
                      v-model="capitalForm.sum4"
                      disabled
                      placeholder="请填写"
                      :min="0"
                      :controls="false"
                    />
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="银行贷款" prop="sum5">
                    <el-input-number
                      v-model="capitalForm.sum5"
                      disabled
                      placeholder="请填写"
                      :min="0"
                      :controls="false"
                    />
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="其他资金" prop="sum6">
                    <el-input-number
                      v-model="capitalForm.sum6"
                      disabled
                      placeholder="请填写"
                      :min="0"
                      :controls="false"
                    />
                  </el-form-item>
                </el-col>
              </el-row>
            </el-form>
          </el-collapse-item>
        </el-collapse>
        <el-collapse v-model="collapseModal2" class="marginTop">
          <el-collapse-item name="1">
            <template #title>
              <div class="collapse-title">总投资分配情况（字段不可修改）</div>
            </template>
            <el-form
              style="padding-left: 16px"
              :model="totalMoneyForm"
              label-suffix=":"
            >
              <el-row :gutter="10">
                <el-col :span="8">
                  <el-form-item label="软件开发" prop="money1">
                    <el-input-number
                      v-model="totalMoneyForm.money1"
                      placeholder="请填写"
                      :min="0"
                      disabled
                      :controls="false"
                    />
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="云资源、硬件配置" prop="money2">
                    <el-input-number
                      v-model="totalMoneyForm.money2"
                      disabled
                      placeholder="请填写"
                      :min="0"
                      :controls="false"
                    />
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="第三方服务" prop="money3">
                    <el-input-number
                      v-model="totalMoneyForm.money3"
                      disabled
                      placeholder="请填写"
                      :min="0"
                      :controls="false"
                    />
                  </el-form-item>
                </el-col>
              </el-row>
            </el-form>
          </el-collapse-item>
        </el-collapse>
        <el-collapse v-model="collapseModal3" class="marginTop">
          <el-collapse-item name="1">
            <template #title>
              <div class="collapse-title">
                年度支付计划（字段不可修改）
              </div>
              <!--              <div class="elSwitch" @click.stop>-->
              <!--                <el-switch v-model="isAnnualPaymentPlan" />-->
              <!--              </div>-->
            </template>
            <el-form
              style="padding-left: 16px"
              :model="annualPlanForm"
              label-position="right"
              label-width="180px"
              label-suffix=":"
            >
              <el-row>
                <el-col :span="12">
                  <el-form-item label="年度支付金额" prop="annualPlan1">
                    <el-input-number
                      v-model="annualPlanForm.annualPlan1"
                      placeholder="请填写"
                      disabled
                      :min="0"
                      :controls="false"
                    />
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row :gutter="10">
                <el-col :span="12">
                  <el-form-item label="自有资金" prop="annualPlan2">
                    <el-input-number
                      v-model="annualPlanForm.annualPlan2"
                      disabled
                      placeholder="请填写"
                      :min="0"
                      :controls="false"
                    />
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item
                    label="政府投资-本级财政资金"
                    prop="annualPlan3"
                  >
                    <el-input-number
                      v-model="annualPlanForm.annualPlan3"
                      disabled
                      placeholder="请填写"
                      :min="0"
                      :controls="false"
                    />
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item
                    label="政府投资-上级补助资金"
                    prop="annualPlan4"
                  >
                    <el-input-number
                      v-model="annualPlanForm.annualPlan4"
                      disabled
                      placeholder="请填写"
                      :min="0"
                      :controls="false"
                    />
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="银行贷款" prop="annualPlan5">
                    <el-input-number
                      v-model="annualPlanForm.annualPlan5"
                      disabled
                      placeholder="请填写"
                      :min="0"
                      :controls="false"
                    />
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="其他" prop="annualPlan6">
                    <el-input-number
                      v-model="annualPlanForm.annualPlan6"
                      disabled
                      placeholder="请填写"
                      :min="0"
                      :controls="false"
                    />
                  </el-form-item>
                </el-col>
              </el-row>
            </el-form>
          </el-collapse-item>
        </el-collapse>
        <el-collapse v-model="collapseModal4" class="marginTop">
          <el-collapse-item name="1">
            <template #title>
              <div class="collapse-title">
                核心业务（字段不可修改，可选择是否启用该模块）
              </div>
              <div class="elSwitch" @click.stop>
                <el-switch v-model="isCoreBusiness" />
              </div>
            </template>
            <div style="padding-left: 16px">
              <div class="flexRight" style="margin-bottom: 16px">
                <el-button type="primary" disabled @click="selectFn">
                  选择核心业务
                </el-button>
              </div>
              <table-list
                :pagination="pagination"
                style="width: 100%"
                :column="column2"
                :data="coreBusiness"
              />
            </div>
          </el-collapse-item>
        </el-collapse>
        <el-collapse v-model="collapseModal5" class="marginTop">
          <el-collapse-item name="1">
            <template #title>
              <div class="collapse-title">
                安全投入（字段不可修改，可选择是否启用该模块）
              </div>
              <div class="elSwitch" @click.stop>
                <el-switch v-model="isSafetyInput" />
              </div>
            </template>
            <el-form
              style="padding-left: 16px"
              :model="safetyInvestmentForm"
              label-position="right"
              label-width="100px"
              label-suffix=":"
            >
              <el-row>
                <el-col :span="12">
                  <el-form-item label="投入项" prop="safetyInvestment1">
                    <el-input
                      v-model="safetyInvestmentForm.safetyInvestment1"
                      disabled
                      placeholder="请输入"
                    />
                  </el-form-item>
                </el-col>
                <el-col :span="24">
                  <el-form-item label="内容描述" prop="safetyInvestment2">
                    <el-input
                      v-model="safetyInvestmentForm.safetyInvestment2"
                      :rows="4"
                      disabled
                      type="textarea"
                      placeholder="请输入"
                    />
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="12">
                  <el-form-item label="金额" prop="safetyInvestment3">
                    <el-input-number
                      v-model="safetyInvestmentForm.safetyInvestment3"
                      placeholder="请填写"
                      disabled
                      :min="0"
                      :controls="false"
                    />
                  </el-form-item>
                </el-col>
              </el-row>
            </el-form>
          </el-collapse-item>
        </el-collapse>
        <el-collapse v-model="collapseModal6" class="marginTop">
          <el-collapse-item name="1">
            <template #title>
              <div class="collapse-title">
                工程形象进度（字段不可修改，可选择是否启用该模块）
              </div>
              <div class="elSwitch" @click.stop>
                <el-switch v-model="isProjectImageProgress" />
              </div>
            </template>
            <el-form
              label-position="right"
              label-width="100px"
              label-suffix=":"
              class="pl-16"
            >
              <el-row>
                <el-col :span="12">
                  <el-form-item label="第一季度" required>
                    <el-input disabled />
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="第二季度" required>
                    <el-input disabled />
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="第三季度" required>
                    <el-input disabled />
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="第四季度" required>
                    <el-input disabled />
                  </el-form-item>
                </el-col>
              </el-row>
            </el-form>
          </el-collapse-item>
        </el-collapse>
        <el-collapse v-model="collapseModal7" class="marginTop">
          <el-collapse-item name="1">
            <template #title>
              <div class="collapse-title">
                附件（字段不可修改）
              </div>
              <!--              <div class="elSwitch" @click.stop>-->
              <!--                <el-switch v-model="isAccessory" />-->
              <!--              </div>-->
            </template>
            <el-form
              label-position="right"
              label-width="260px"
              label-suffix=":"
            >
              <el-row>
                <el-col :span="12">
                  <el-form-item label="初步方案" required>
                    <el-upload
                      ref="preliminaryPlanRef"
                      class="upload-demo"
                      disabled
                    >
                      <el-button plain type="primary" disabled>选择文件</el-button>
                      <template #tip>
                        <div class="el-upload__tip">
                          支持PDF文件
                        </div>
                      </template>
                    </el-upload>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item
                    label="佐证材料"
                    required
                  >
                    <el-upload
                      class="upload-demo"
                      multiple
                      disabled
                    >
                      <el-button plain type="primary" disabled>选择文件</el-button>
                      <template #tip>
                        <div class="el-upload__tip">
                          支持PDF文件
                        </div>
                      </template>
                    </el-upload>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item
                    label="项目总投资测算明细"
                    required
                  >
                    <el-upload
                      class="upload-demo"
                      multiple
                      disabled
                    >
                      <el-button plain type="primary" disabled>选择文件</el-button>
                      <template #tip>
                        <div class="el-upload__tip">
                          支持PDF文件
                        </div>
                      </template>
                    </el-upload>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item
                    label="申报单位主要职责（单位三定方案）"
                    required
                  >
                    <el-upload
                      class="upload-demo"
                      multiple
                      disabled
                    >
                      <el-button plain type="primary" disabled>选择文件</el-button>
                      <template #tip>
                        <div class="el-upload__tip">
                          支持PDF文件
                        </div>
                      </template>
                    </el-upload>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item
                    label="项目申报书"
                    required
                  >
                    <el-upload
                      class="upload-demo"
                      multiple
                      disabled
                    >
                      <el-button plain type="primary" disabled>选择文件</el-button>
                      <template #tip>
                        <div class="el-upload__tip">
                          支持PDF文件
                        </div>
                      </template>
                    </el-upload>
                  </el-form-item>
                </el-col>
              </el-row>
            </el-form>
          </el-collapse-item>
        </el-collapse>
        <el-collapse v-if="treeForm==='330500'" v-model="collapseModal9" class="marginTop">
          <el-collapse-item name="1">
            <template #title>
              <div class="collapse-title">
                审查清单
              </div>
              <div class="elSwitch" @click.stop>
                <el-switch v-model="isReviewChecklist" />
              </div>
            </template>
            <el-form
              ref="reviewInfoFormRef"
              label-position="right"
              label-width="90px"
              label-suffix=":"
              :model="reviewInfoForm"
              scroll-to-error
            >
              <div>
                <div
                  v-for="(item,index) in reviewInfoForm.reviewChecklist"
                  :key="index"
                  class="relative ml-16 pb-16 mb-16"
                  style="border: 1px solid #eee;"
                >
                  <el-row class="mt-16">
                    <el-col :span="12">
                      <el-form-item label="标题" :prop="`reviewChecklist[${index}].title`" :rules="[{required:true,message:'请输入'}]">
                        <el-input v-model="item.title" />
                      </el-form-item>
                    </el-col>
                  </el-row>
                  <div class="p-16 mx-24">
                    <div v-for="(child,key) in item.modules" :key="key" class="relative">
                      <el-row>
                        <el-col :span="12">
                          <el-form-item label="子标题" :prop="`reviewChecklist[${index}].modules[${key}].subTitle`" :rules="[{required:true,message:'请输入'}]">
                            <el-input v-model="child.subTitle" />
                          </el-form-item>
                        </el-col>
                      </el-row>
                      <el-row>
                        <el-col :span="12">
                          <el-form-item label="审查内容" :prop="`reviewChecklist[${index}].modules[${key}].content`" :rules="[{required:true,message:'请输入'}]">
                            <el-input v-model="child.content" type="textarea" />
                          </el-form-item>
                        </el-col>
                        <el-col :span="12">
                          <el-form-item label="否决情形" :prop="`reviewChecklist[${index}].modules[${key}].rejectionSituation`" :rules="[{required:true,message:'请输入'}]">
                            <el-input v-model="child.rejectionSituation" type="textarea" />
                          </el-form-item>
                        </el-col>
                        <el-col :span="6">
                          <el-form-item label="响应情况">
                            <el-input v-model="child.resCondition" disabled />
                          </el-form-item>
                        </el-col>
                        <el-col :span="6">
                          <el-form-item label="对应页码">
                            <el-input v-model="child.corrPageNum" disabled />
                          </el-form-item>
                        </el-col>
                        <el-col :span="12">
                          <el-form-item label="审核意见">
                            <el-input v-model="child.reviewComments" type="textarea" disabled />
                            <el-radio-group v-model="child.reviewResult">
                              <el-radio :label="1">通过</el-radio>
                              <el-radio :label="2">不通过</el-radio>
                              <el-radio :label="3">一票否决</el-radio>
                            </el-radio-group>
                          </el-form-item>
                        </el-col>
                      </el-row>
                      <el-divider v-if="key<item.modules?.length-1" />
                      <el-button
                        v-if="item.modules?.length>1"
                        icon="Delete"
                        type="danger"
                        link
                        class="absolute right-4 top-1"
                        @click="delChild(index,key)"
                      >删除</el-button>
                    </div>
                    <el-button
                      icon="Plus"
                      type="primary"
                      plain
                      @click="addChild(index)"
                    >增加子模块</el-button>
                  </div>
                  <el-button
                    icon="Delete"
                    type="danger"
                    link
                    class="absolute right-4 top-4"
                    @click="delList(index)"
                  >删除</el-button>
                </div>
              </div>
              <div class="w-full px-16 mt-16">
                <el-button
                  icon="Plus"
                  type="primary"
                  plain
                  class="w-full"
                  @click="addList"
                >增加模块</el-button>
              </div>
            </el-form>
          </el-collapse-item>
        </el-collapse>
        <el-collapse v-model="collapseModal8" class="marginTop">
          <el-collapse-item name="1">
            <template #title>
              <div class="collapse-title">
                备注（字段不可修改，可选择是否启用该模块）
              </div>
              <div class="elSwitch" @click.stop>
                <el-switch v-model="isRemark" />
              </div>
            </template>
            <el-form
              style="padding-left: 16px"
              label-position="right"
              label-width="100px"
              label-suffix=":"
            >
              <el-form-item
                label="备注"
                prop="notes"
              ><el-input
                :autosize="{ minRows: 2, maxRows: 4 }"
                maxlength="2000"
                type="textarea"
                placeholder="请填写"
              /> </el-form-item>
            </el-form>
          </el-collapse-item>
        </el-collapse>
        <div
          v-if="safetyInputModular && safetyInputModular.length > 0"
          class="marginTop"
        >
          <el-collapse
            v-for="(item, index) in safetyInputModular"
            :key="index"
            v-model="moduleActiveList"
            class="marginTop"
          >
            <el-collapse-item :name="item.id">
              <template #title>
                <div class="flexbetween collapse-title">
                  <div class="flexItem formClass" @click.stop>
                    <el-form ref="moduleFormRef" :model="item">
                      <el-form-item
                        :rules="{
                          required: true,
                          message: '请输入',
                          trigger: 'blur',
                        }"
                        prop="moduleName"
                      >
                        <el-input
                          v-model="safetyInputModular[index].moduleName"
                          style="width: 400px"
                          :maxlength="50"
                          placeholder="请填写模块名称。例如市级有进度计划模块，可如下定义"
                        />
                      </el-form-item>
                      &nbsp;&nbsp;
                      <el-form-item
                        :rules="{
                          required: true,
                          message: '请输入',
                          trigger: 'blur',
                        }"
                        prop="sort"
                      >
                        <el-input-number
                          v-model="safetyInputModular[index].sort"
                          placeholder="请填写"
                          :min="1"
                        />
                      </el-form-item>
                    </el-form>
                  </div>
                  <a
                    class="delClass"
                    @click.stop="delModule(index)"
                  >删除模块</a>
                </div>
              </template>
              <el-form
                style="padding-left: 16px"
                :model="item.formList"
                label-position="right"
                :label-width="
                  item.formList && item.formList.length > 0 ? '100px' : '0px'
                "
                label-suffix=":"
              >
                <el-row>
                  <el-col
                    v-for="(childItem,k) in item.formList"
                    :key="k"
                    :span="12"
                  >
                    <el-form-item
                      :label="childItem.name"
                      :prop="childItem.name"
                      :rules="{
                        required: childItem.props?.required,
                      }"
                    >
                      <el-input
                        v-if="childItem.props?.type === '输入'"
                        disabled
                        placeholder="请输入"
                      />
                      <el-input-number
                        v-else-if="childItem.props?.type === '数值输入'"
                        disabled
                        style="width: 100%"
                        placeholder="请填写"
                        :min="0"
                        :controls="false"
                      />
                      <el-radio-group
                        v-else-if="childItem.props?.type === '单选'"
                        disabled
                      >
                        <el-radio
                          v-for="(i, inx) in childItem.props?.options"
                          :key="inx"
                          :label="inx"
                        >{{ i.name }}</el-radio>
                      </el-radio-group>
                      <el-checkbox-group
                        v-else-if="childItem.props?.type === '多选'"
                        disabled
                      >
                        <el-checkbox
                          v-for="(i, inx) in childItem.props.options"
                          :key="inx"
                          :label="inx"
                        >{{ i.name }}</el-checkbox>
                      </el-checkbox-group>
                      <el-button v-else disabled>文件上传</el-button>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item class="btnClass">
                      <el-button
                        class="w-full"
                        type="primary"
                        plain
                        icon="Plus"
                        @click="addField(index)"
                      >增加字段</el-button>
                    </el-form-item>
                  </el-col>
                </el-row>
              </el-form>
            </el-collapse-item>
          </el-collapse>
        </div>
        <el-button
          plain
          type="primary"
          icon="Plus"
          class="w-full mt-16"
          @click="addModuleFn"
        >增加模块</el-button>
      </el-col>
    </el-row>
  </div>
  <div class="footer justify-center">
    <el-button type="primary" :loading="loading" @click="saveConfigurationFn">
      保存配置
    </el-button>
  </div>
  <el-dialog title="字段属性" :model-value="visible" @close="visible=false">
    <el-form
      ref="addFormRef"
      :model="addForm"
      :rules="addFormRules"
      label-width="90px"
      label-suffix=":"
    >
      <el-row :gutter="20">
        <el-col :span="12">
          <el-form-item label="字段名称" prop="formName">
            <el-input v-model="addForm.formName" placeholder="请输入" :maxlength="50" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="字段类型" prop="type">
            <el-select
              v-model="addForm.type"
              style="width: 100%"
              placeholder="请选择"
            >
              <el-option value="输入">输入</el-option>
              <el-option value="数值输入">数值输入</el-option>
              <el-option value="单选">单选</el-option>
              <el-option value="多选">多选</el-option>
              <el-option value="文件上传">文件上传</el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col v-if="addForm.type === '输入' || !addForm.type" :span="12">
          <el-form-item label="最大长度" prop="maxLength">
            <el-input-number
              v-model="addForm.maxLength"
              style="width: 100%"
              placeholder="请填写"
              :min="0"
              :max="10000"
              :controls="false"
            />
          </el-form-item>
        </el-col>
        <el-col
          v-if="addForm.type === '多选' || addForm.type === '单选'"
          :span="24"
        >
          <el-form-item
            v-for="(item, index) in addForm.optionList"
            :key="item"
            :label="'选项' + (index + 1)"
            :prop="`optionList[${index}].name`"
            :rules="[
              {
                required: true,
                message: '请输入',
                trigger: 'blur',
              },
              { validator: optionListNameValidator },
            ]"
          >
            <el-row style="width: 86%" :gutter="10">
              <el-col :span="12">
                <el-input
                  v-model="addForm.optionList[index].name"
                  placeholder="请输入"
                />
              </el-col>
              <el-col v-if="addForm.optionList.length !== 1" :span="12">
                <el-button type="primary" @click="delOption">
                  删除选项
                </el-button>
              </el-col>
            </el-row>
          </el-form-item>
        </el-col>
        <el-col
          v-if="addForm.type === '多选' || addForm.type === '单选'"
          :span="24"
        >
          <el-form-item>
            <el-button type="primary" @click="addOption">
              增加选项
            </el-button>
          </el-form-item>
        </el-col>
        <el-col v-if="addForm.type === '数值输入'" :span="12">
          <el-form-item label="最小数值" prop="minNumber">
            <el-input-number
              v-model="addForm.minNumber"
              style="width: 100%"
              placeholder="请填写"
              :min="0"
              :controls="false"
            />
          </el-form-item>
        </el-col>
        <el-col v-if="addForm.type === '数值输入'" :span="12">
          <el-form-item label="最大数值" prop="maxNumber">
            <el-input-number
              v-model="addForm.maxNumber"
              style="width: 100%"
              placeholder="请填写"
              :min="0"
              :controls="false"
            />
          </el-form-item>
        </el-col>
        <el-col v-if="addForm.type === '文件上传'" :span="12">
          <el-form-item label="文件个数" prop="fileNumber">
            <el-input-number
              v-model="addForm.fileNumber"
              style="width: 100%"
              placeholder="请填写"
              :min="0"
              :max="10"
              :controls="false"
            />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="是否必填" prop="isRequired">
            <el-select
              v-model="addForm.isRequired"
              style="width: 100%"
              placeholder="请选择"
            >
              <el-option label="是" :value="true" />
              <el-option label="否" :value="false" />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="排序" prop="formSort">
            <el-input-number
              v-model="addForm.formSort"
              style="width: 100%"
              placeholder="请输入"
              :min="0"
              :max="100"
              :controls="false"
            />
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <template #footer>
      <el-button type="primary" @click="confirmFn(addFormRef)"> 提交 </el-button>
      <el-button @click="visible = false"> 关闭 </el-button>
    </template>
  </el-dialog>
</template>
<style lang="less" scoped>
.mainBox {
  position: relative;
  padding-bottom: 53px;
}
:deep(.el-collapse) {
  .el-collapse-item__header {
    position: relative;
    padding: 0px 16px;
    font-size: 14px;
  }
  .el-collapse-item__content {
    padding: 16px 16px 16px 0px;
  }
  .el-collapse-item__header.is-active {
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
  }
  .collapse-title {
    flex: 1 0 90%;
    order: 1;
    .el-collapse-item__header {
      flex: 1 0 auto;
      order: -1;
    }
    .el-input-number {
      width: 150px !important;
    }
  }
}
.btnClass {
  :deep(.el-form-item__content) {
    line-height: 24px;
  }
}

.marginTop {
  margin-top: 16px;
}
.delClass {
  color: #e65151;
}
.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(0, 100, 235, 1);
  width: 100%;
  padding: 2px 0px;
  border-radius: 4px;
  border: 1px solid rgba(0, 100, 235, 1);
  cursor: pointer;
}
.fontSize {
  font-size: 14px;
}
.elSwitch {
  position: absolute;
  right: 16px;
  top: 0px;
}
.formClass {
  :deep(.el-form) {
    display: flex;
    align-items: center;
    .el-form-item {
      margin-bottom: 0px;
    }
  }
}
.bottomBtn {
  width: calc(100% - 201px);
  position: fixed;
  z-index: 999;
  right: 0px;
  bottom: 0px;
  background: #fff;
  padding: 10px 0px;
  border-top: 1px solid rgba(0, 0, 0, 0.1);
}
</style>
