<!-- 初调文件上传 --><!-- 表单布局 -->
<template>
  <!-- 自定义表单 -->
  <BasicForm @register="registerForm"> 
    <template #JUploadQyGd="{modal, field}">
      <div class="flex">
        <a-upload
          v-model:file-list="fileList"
          accept=".xls,.xlsx"
          :maxCount="1"
          name="file"
          action="/soil/dklc/importGd"
          :data="{'type':'2', 'pgtype': data.pgtype, 'scjdbm':data.scjdbm,'wrdkid':dkxx.wrdkid}"
          :headers="headers"
          :beforeUpload="gdBeforeUpload"
          :showUploadList="false"
          @change="handleChange"
        >
          <a-button v-if="visibleFlag">
            <Icon icon="ant-design:upload-outlined" />
            上传
          </a-button>
        </a-upload>
        <a-button v-if="fileList.length>0 || data.qygdFile" class="ml-2" @click="toBatchDownload((fileList[0]?.url || data.qygdFile),dkxx.wrdkmc+'-区域拐点')" type="primary">下载</a-button>
        <a-button type="primary" @click.prevent="onExportXls('/dklc/downloadGd','拐点模版', null)" style="margin-left:10px;">拐点模版下载</a-button>
      </div>
    </template>
    <template #JUploadBjGd="{modal, field}">
      <div class="flex">
        <a-upload
          v-model:file-list="fileListbjgd"
          accept=".xls,.xlsx"
          :maxCount="1"
          name="file"
          action="/soil/dklc/importGd"
          :data="{'type':'1', 'pgtype': data.pgtype, 'scjdbm':data.scjdbm,'wrdkid':dkxx.wrdkid}"
          :headers="headers"
          :beforeUpload="gdBeforeUpload"
          :showUploadList="false"
          @change="handleBjChange"
        >
          <a-button v-if="visibleFlag">
            <Icon icon="ant-design:upload-outlined" />
            上传
          </a-button>
        </a-upload>
        <a-button v-if="fileListbjgd.length>0 || data.gdFile" class="ml-2" @click="toBatchDownload((fileListbjgd[0]?.url || data.gdFile),dkxx.wrdkmc+'-边界拐点')" type="primary">下载</a-button>
        <a-button type="primary" @click.prevent="onExportXls('/dklc/downloadGd','拐点模版', null)" style="margin-left:10px;">拐点模版下载</a-button>
      </div>
    </template>
    <template #JUploadBjMap="{}">
      <div class="flex">
        <Mapbj :data="MapbjInfo" v-if="mapShow" style="height:500px;"/>
      </div>
    </template>
  </BasicForm>

  <a-modal v-model:visible="gdFlag" :footer="null" title="拐点生成图" width="70%">
    <Mapgd :data="MapgdInfo" v-if="gdFlag"/>
  </a-modal>
</template> 

<script lang="ts" setup>
  //引入依赖
  import { ref, reactive, unref } from 'vue';
  import { nextTick, watch, toRaw, createVNode, h } from 'vue';
  import { updateCbdc, updateXxdc, saveGFxpg, saveGkxf, saveXgpg, checkShp, saveBjxx, checkCountBjxx, downloadFile } from '/@/api/common/api';
  import { useForm, BasicForm, FormSchema } from '/@/components/Form';
  import { useMessage } from '/@/hooks/web/useMessage';
  import { transformation } from '@/utils/EPSG';
  import { Modal } from 'ant-design-vue';
  import { CheckOutlined } from '@ant-design/icons-vue';
  import { getToken } from '/@/utils/auth';
  import { Icon } from '/@/components/Icon';
  import { filterObj } from '/@/utils/common/compUtils';
  import { useMethods } from '/@/hooks/system/useMethods';
  import Mapbj from '@/components/customComponent/mapbj.vue';
  import Mapgd from '@/components/customComponent/mapgd.vue';
  const { handleExportXls } = useMethods();
  const { createMessage } = useMessage();
  const fileListbjgd = ref<any>([]);
  const fileList = ref<any>([]);
  const headers = reactive({
    'X-Access-Token': getToken(),
  });
  const gdFlag = ref(false);
  const mapShow = ref(false);
  const MapbjInfo = ref<any>({});
  const MapgdInfo = ref<any>([]);
  // Emits声明
  const emit = defineEmits(['upsuccess']);
  
  function toBatchDownload(url, name) {
    console.log(url, name)
    let fileExtension = url.split('.').pop();
    downloadFile('/sys/common/static' + url.replace("/mnt/data/files", ''), `${name}.${fileExtension}`);
  }
  const handleChange = async (info) => {
    if (info.file.status === 'done') {
      if (info.file.response.success && info.file.response.result.code==200) {
        createMessage.success(`${info.file.name} 成功`);
        const arry = info.file.response.result;
        fileList.value = [{name: info.file.name, url: arry['result'].url}];
        uploadGkBjGdFlag.value = true;
        let fieldsValue = await getFieldsValue();
        nextTick(async () => {
          const obj = toRaw(fieldsValue);
          fieldsValue.qygdFile = arry['result'].url
          await setFieldsValue({
            ...obj,
          });
        });
      } else {
        fileList.value = [];
        if (info.file.response.message && info.file.response.message.indexOf('拐点生成gis数据错误')>-1) {
          let res = transformation('CGCS2000_3_Degree_GK_Zone_38', [info.file.response.result]);
          let zxdw = {"type":"Point","coordinates":[Number(props.dkxx.wrdkzxjd),Number(props.dkxx.wrdkzxwd)]}
          gdFlag.value = true;
          createMessage.error(`${info.file.response.message || info.file.response.result.message}`);
          MapgdInfo.value.push(zxdw)
          MapgdInfo.value.push(JSON.parse(JSON.parse(res)[0]))
        } else {
          createMessage.error(`${info.file.response.message || info.file.response.result.message}`);
        }
      }
    } else if (info.file.status === 'error') {
      fileList.value = [];
      createMessage.error(`${info.file.name} 失败`);
    }
  };
  const handleBjChange = async (info) => {
    if (info.file.status === 'done') {
      if (info.file.response.success && info.file.response.result.code==200) {

        createMessage.success(`${info.file.name} 成功`);
        const arry = info.file.response.result;
        fileListbjgd.value = [{name: info.file.name, url: arry['result'].url}];
        uploadBjGdFlag.value = true;
        let fieldsValue = await getFieldsValue();
        nextTick(async () => {
          const obj = toRaw(fieldsValue);
          fieldsValue.gdFile = arry['result'].url
          await setFieldsValue({
            ...obj,
          });
        });
      } else {
        fileListbjgd.value = [];
        if (info.file.response.message && info.file.response.message.indexOf('拐点生成gis数据错误')>-1) {
          let res = transformation('CGCS2000_3_Degree_GK_Zone_38', [info.file.response.result]);
          let zxdw = {"type":"Point","coordinates":[Number(props.dkxx.wrdkzxjd),Number(props.dkxx.wrdkzxwd)]}
          gdFlag.value = true;
          createMessage.error(`${info.file.response.message || info.file.response.result.message}`);
          MapgdInfo.value.push(zxdw)
          MapgdInfo.value.push(JSON.parse(JSON.parse(res)[0]))
        } else {
          createMessage.error(`${info.file.response.message || info.file.response.result.message}`);
        }
      }
    } else if (info.file.status === 'error') {
      fileListbjgd.value = [];
      createMessage.error(`${info.file.name} 失败`);
    }
  }
  const gdBeforeUpload = (file) => {
    let isshow = false;
    const isFile = file.name.split('.')[file.name.split('.').length - 1];
   
    if (isFile == 'xls' || isFile == 'xlsx') {
      isshow = true;
    } else {
      createMessage.error('只能上传.xls/.xlsx格式的文件');
      isshow = false;
    }
    return isshow;
  }
  const uploadBjGdFlag = ref(false);  //边界拐点上传标识
  const uploadGkBjGdFlag = ref(false);  //管控区域边界拐点上传标识
  const props = defineProps({
    labelFirst: {
      type: String,
      default: '初步调查',
    },
    objec: {
      type: Array,
      default: [
        {
          name: '',
        },
      ],
    },
    visibleFlag: {
      type: Boolean,
      default: true,
    },
    data: {
      type: Object,
      default: {},
    },
    dksdzt: {
      type: String,
      default: null,
    },
    dkxx: {
      type: Object,
      default: {
        wrdkmc: '',
        wrdkbm: '',
      },
    },
  });
  //自定义表单字段
  const formSchemas: FormSchema[] = [
    {
      label: '污染地块id',
      field: 'wrdkid',
      component: 'Input',
      show: false,
    },
    {
      label: 'id',
      field: 'id',
      component: 'Input',
      show: false,
    },
    {
      label: `${props?.objec ? props?.objec[0]?.name : '公示照片'}`,
      field: 'gspic',
      component: 'JUpload',
      dynamicDisabled: () => {
        return props.dksdzt == '1';
      },
      required: true,
      componentProps: () => {
        return {
          buttonVisible: props.visibleFlag,
          showUploadList: false,
          maxCount: 1,
          fileName: `${
            props?.objec
              ? (props?.dkxx?.wrdkmc ? props?.dkxx?.wrdkmc + '-' : '') + props?.objec[0]?.name
              : (props?.dkxx?.wrdkmc ? props?.dkxx?.wrdkmc + '-' : '') + '公示照片'
          }`,
          accept: '.png,.jpg,.jpeg',
          beforeUpload: (file) => {
            if (file.type != 'image/jpeg' && file.type != 'image/png') {
              createMessage.error('只能上传png、jpg格式的图片');
              return false;
            }
            // return file.type == 'image/jpeg';
          },
          onChange: async (v) => {
            if (!v || v == props.data.gspic) {
              return
            }
            const arry = v.split(',');
            props.data.gspic = arry[arry.length - 1]
            await upLoad({
              wrdkid: props.data.wrdkid,
              id: props.data.id,
              gspic: arry[arry.length - 1],
            });
            // Modal.success({
            //   title: () => '上传提示',
            //   content: () => h('div', {}, [h('p', '上传成功')]),
            // });
          },
        };
      },
    },
    {
      label: `${props?.objec ? props?.objec[1]?.name : '初步调查报告'}`,
      field: 'dcbglj',
      component: 'JUpload',
      required: true,
      dynamicDisabled: () => {
        return props.dksdzt == '1';
      },
      componentProps: () => {
        return {
          buttonVisible: props.visibleFlag,
          showUploadList: false,
          maxCount: 1,
          fileName: `${
            props?.objec
              ? (props?.dkxx?.wrdkmc ? props?.dkxx?.wrdkmc + '-' : '') + props?.objec[1]?.name
              : (props?.dkxx?.wrdkmc ? props?.dkxx?.wrdkmc + '-' : '') + '初步调查报告'
          }`,
          accept: '.pdf,.zip',
          beforeUpload: (file) => {
            let isshow = false;
            const isFile = file.name.split('.')[file.name.split('.').length - 1];
            if (isFile == 'pdf' || isFile == 'zip' || isFile == 'PDF') {
              isshow = true;
            } else {
              createMessage.error('只能上传.pdf/.zip格式的文件');
              isshow = false;
            }

            return isshow;
          },
          onChange: async (v) => {
            if (!v || v == props.data.dcbglj) {
              return
            }
            const arry = v.split(',');
            props.data.dcbglj = arry[arry.length - 1]
            if (props.labelFirst == '风险评估') {
              upLoad({
                wrdkid: props.data.wrdkid,
                id: props.data.id,
                fxpgbglj: arry[arry.length - 1],
              });
            } else if (props.labelFirst == '风险管控' || props.labelFirst == '修复' || props.labelFirst == '风险管控及修复') {
              upLoad({
                wrdkid: props.data.wrdkid,
                id: props.data.id,
                falj: arry[arry.length - 1],
              });
            } else if (props.labelFirst == '风险管控效果评估' || props.labelFirst == '修复效果评估' || props.labelFirst == '风险管控及修复效果评估') {
              upLoad({
                wrdkid: props.data.wrdkid,
                id: props.data.id,
                zlyxfxgpgbglj: arry[arry.length - 1],
              });
            } else {
              await upLoad({
                wrdkid: props.data.wrdkid,
                id: props.data.id,
                dcbglj: arry[arry.length - 1],
              });
              // Modal.success({
              //   title: () => '上传提示',
              //   content: () => h('div', {}, [h('p', '上传成功')]),
              // });
            }
          },
        };
      },
    },
    {
      label: '边界拐点文件',
      field: 'gdFile',
      // required: true,
      component: 'JUpload',
      dynamicDisabled: () => {
        return props.dksdzt == '1';
      },
      slot: 'JUploadBjGd',
      componentProps: () => {
        return {
          buttonVisible: props.visibleFlag,
          showUploadList: false,
          maxCount: 1,
          fileName: (props?.dkxx?.wrdkmc ? props?.dkxx?.wrdkmc + '-' : '') + '边界拐点文件',
          accept: '.xls,.xlsx',
          beforeUpload: (file) => {

            let isshow = false;
            const isFile = file.name.split('.')[file.name.split('.').length - 1];
            console.log(file, 'file');

            if (isFile == 'xls' || isFile == 'xlsx') {
              isshow = true;
            } else {
              createMessage.error('只能上传.xls/.xlsx格式的文件');
              isshow = false;
            }
            return isshow;
          },
          onChange: async (v) => {
            if (!v || v == props.data.gd) {
              return
            }
            const arry = v.split(',');
            props.data.gd = arry[arry.length - 1]
            const param = {
              wrdkid: props.data.wrdkid,
              scjdbm: props.data.scjdbm,
              pgtype: props.data.pgtype,
              url: arry[arry.length - 1],
            };
            const res = await checkShp(param);
            let ss = transformation(res.zbx, JSON.parse(res.geomtry));
            res.geo = ss;

            await upLoad({
              wrdkid: props.data.wrdkid,
              id: props.data.id,
              gd: arry[arry.length - 1],
            });
          },
        };
      },
    },
    {
      label: '边界文件',
      field: 'dkshp',
      required: true,
      component: 'JUpload',
      dynamicDisabled: () => {
        return props.dksdzt == '1';
      },
      componentProps: ({ formModel }) => {
        return {
          tipHtml: {
            preContent: '(',
            downloadLinkText: '<span class="red">下载边界文件要求说明',
            nextContent: ')，填报前必读)',
            fileUrl: '/upload/static/边界文件要求说明20200514.pdf',
            fileName: '边界说明文件.pdf',
            fieldName: (props.dkxx.dclx==3 && props.labelFirst == '详细调查')?'矢量边界':'',
            params: { wrdkid: props.data.wrdkid, scjdbm: props.data.scjdbm, pgtype: props.data.pgtype },
          },
          buttonVisible: props.visibleFlag,
          showUploadList: false,
          maxCount: 1,
          fileName: (props?.labelFirst ? props?.labelFirst:'') + '边界文件'+(props?.dkxx?.wrdkbm ? '-' + props?.dkxx?.wrdkbm: ''),
          accept: '.zip',
          beforeUpload: (file) => {
            if (!uploadBjGdFlag.value) {
              createMessage.error('请先上传拐点信息');
              return false
            }
            let isshow = false;
            const isFile = file.name.split('.')[file.name.split('.').length - 1];
            console.log(file, 'file');
            if (isFile == 'zip') {
              isshow = true;
            } else {
              createMessage.error('只能上传.zip格式的文件');
              isshow = false;
            }
            // if (file.type == 'application/x-zip-compressed') {
            //   isshow = true;
            // } else {
            //   createMessage.error('只能上传zip格式的文件');
            //   isshow = false;
            // }
            return isshow;
          },
          onChange: async (v) => {
            if (!v || v == props.data.dkshp) {
              return
            }
            const arry = v.split(',');
            props.data.dkshp = arry[arry.length - 1]
            const param = {
              wrdkid: props.data.wrdkid,
              scjdbm: props.data.scjdbm,
              pgtype: props.data.pgtype,
              url: arry[arry.length - 1],
              type: 1,
            };
            const res = await checkShp(param);
            let ss = transformation(res.zbx, JSON.parse(res.geomtry));
            res.geo = ss;
            //边界校验 
            await checkCountBjxx(res);
            await saveBjxx(res);
            await upLoad({
              wrdkid: props.data.wrdkid,
              id: props.data.id,
              dkshp: arry[arry.length - 1],
            });
            mapShow.value = true;
            MapbjInfo.value = { wrdkid: props.data.wrdkid, scjdbm: props.data.scjdbm, pgtype: props.data.pgtype };
            // Modal.success({
            //   title: () => '上传提示',
            //   content: () => h('div', {}, [h('p', '上传成功')]),
            // });
          },
        };
      },
    },
    {
      label: '',
      field: 'gdFiles',
      component: 'Input',
      dynamicDisabled: () => {
        return props.dksdzt == '1';
      },
      colProps: { span: 24 },
      slot: 'JUploadBjMap',
      show: (props.dkxx.dclx==3 && props.labelFirst == '详细调查')?false:true,
    },
    {
      label: '边界图片',
      helpMessage: '最多上传4张图片',
      field: 'dkpic',
      component: 'JImageUpload',
      required: true,
      dynamicDisabled: () => {
        return props.dksdzt == '1';
      },
      componentProps: () => {
        return {
          fileType: 'image',
          showPreviewBtn: true,
          showUploadList: false,
          buttonVisible: props.visibleFlag,
          fileMax: 4,
          fileName: (props?.dkxx?.wrdkbm ? props?.dkxx?.wrdkbm + '-' : '') + '边界图片',
          accept: '.png,.jpg,.jpeg',
          beforeUpload: (file) => {
            if (file.type != 'image/jpeg' && file.type != 'image/png') {
              createMessage.error('只能上传png、jpg格式的图片');
              return false;
            }
          },
          onChange: async (v) => {
            if (!v || v == props.data.dkpic) {
              return
            }
            console.log(v, '图片')
            // let fieldsValue = await getFieldsValue();
            // nextTick(async () => {
            //   const obj = toRaw(fieldsValue);
            //   fieldsValue.dkpic = v
            //   await setFieldsValue({
            //     ...obj,
            //   });
            // });
            await upLoad({
              wrdkid: props.data.wrdkid,
              id: props.data.id,
              dkpic: v,
            });
          },
        };
      },
    },
    {
      label: '盖章红线图',
      field: 'gzhxt',
      component: 'JUpload',
      required: true,
      dynamicDisabled: () => {
        return props.dksdzt == '1';
      },
      componentProps: () => {
        return {
          showUploadList: false,
          buttonVisible: props.visibleFlag,
          maxCount: 1,
          fileName: (props?.dkxx?.wrdkbm ? props?.dkxx?.wrdkbm + '-' : '') + '盖章红线图',
          accept: '.pdf,.zip',
          beforeUpload: (file) => {
            let isshow = false;
            const isFile = file.name.split('.')[file.name.split('.').length - 1];
            if (isFile == 'pdf' || isFile == 'zip' || isFile == 'PDF') {
              isshow = true;
            } else {
              createMessage.error('只能上传.pdf/.zip格式的文件');
              isshow = false;
            }

            return isshow;
          },
          onChange: async (v) => {
            if (!v || v == props.data.gzhxt) {
              return
            }
            const arry = v.split(',');
            props.data.gzhxt = arry[arry.length - 1]
            await upLoad({
              wrdkid: props.data.wrdkid,
              id: props.data.id,
              gzhxt: arry[arry.length - 1],
            });
          },
        };
      },
    },
    {
      label: '现场施工佐证材料',
      field: 'xcsgzzcl',
      // required: true,
      component: 'JUpload',
      dynamicDisabled: () => {
        return props.dksdzt == '1';
      },
      show: () => {
        return props.labelFirst == '风险管控' || props.labelFirst == '修复' || props.labelFirst == '风险管控及修复' ? true : false;
      },
      componentProps: () => {
        return {
          tipHtml: {
            preContent: '(',
            downloadLinkText: '<span class="red">优先监管地块管理使用',
            nextContent: ')',
          },
          buttonVisible: props.visibleFlag,
          showUploadList: false,
          maxCount: 1,
          fileName: (props?.dkxx?.wrdkmc ? props?.dkxx?.wrdkmc + '-' : '') + '现场施工佐证材料',
          accept: '.zip',
          beforeUpload: (file) => {
            let isshow = false;
            const isFile = file.name.split('.')[file.name.split('.').length - 1];
            console.log(file, 'file');
            if (isFile == 'zip') {
              isshow = true;
            } else {
              createMessage.error('只能上传.zip格式的文件');
              isshow = false;
            }
            return isshow;
          },
          onChange: async (v) => {
            if (!v || v == props.data.xcsgzzcl) {
              return
            }
            const arry = v.split(',');
            props.data.xcsgzzcl = arry[arry.length - 1]
            await upLoad({
              wrdkid: props.data.wrdkid,
              id: props.data.id,
              xcsgzzcl: arry[arry.length - 1],
            });
            // Modal.success({
            //   title: () => '上传提示',
            //   content: () => h('div', {}, [h('p', '上传成功')]),
            // });
          },
        };
      },
    },
    {
      label: '管控区域拐点文件',
      field: 'qygdFile',
      // required: true,
      component: 'JUpload',
      dynamicDisabled: () => {
        return props.dksdzt == '1';
      },
      show: () => {
       return ((props.labelFirst == '风险管控' && props.data.gkcsQt=='阻隔') || (props.labelFirst == '修复' && props.data.gkcsQt=='阻隔') || (props.labelFirst == '风险管控及修复' && props.data?.gkcsQt?.indexOf('阻隔')>-1))? true : false;
      },
      slot: 'JUploadQyGd',
      componentProps: () => {
        return {
          buttonVisible: props.visibleFlag,
          showUploadList: false,
          maxCount: 1,
          fileName: (props?.dkxx?.wrdkmc ? props?.dkxx?.wrdkmc + '-' : '') + '管控区域拐点文件',
          accept: '.xls,.xlsx',
          beforeUpload: (file) => {
            let isshow = false;
            const isFile = file.name.split('.')[file.name.split('.').length - 1];
            console.log(file, 'file');
            if (isFile == 'xls' || isFile == 'xlsx') {
              isshow = true;
            } else {
              createMessage.error('只能上传.xls/.xlsx格式的文件');
              isshow = false;
            }
            return isshow;
          },
          onChange: async (v) => {
            if (!v || v == props.data.qygd) {
              return
            }
            const arry = v.split(',');
            props.data.gygd = arry[arry.length - 1]
            const param = {
              wrdkid: props.data.wrdkid,
              scjdbm: props.data.scjdbm,
              pgtype: props.data.pgtype,
              url: arry[arry.length - 1],
            };
            const res = await checkShp(param);
            let ss = transformation(res.zbx, JSON.parse(res.geomtry));
            res.geo = ss;

            await upLoad({
              wrdkid: props.data.wrdkid,
              id: props.data.id,
              qygd: arry[arry.length - 1],
            });
          },
        };
      },
    },
    {
      label: '管控区域矢量边界',
      field: 'qyshp',
      // required: true,
      component: 'JUpload',
      dynamicDisabled: () => {
        return props.dksdzt == '1';
      },
      show: () => {
        return ((props.labelFirst == '风险管控' && props.data.gkcsQt=='阻隔') || (props.labelFirst == '修复' && props.data.gkcsQt=='阻隔') || (props.labelFirst == '风险管控及修复' && props.data?.gkcsQt?.indexOf('阻隔')>-1))? true : false;
      },
      componentProps: () => {
        return {
          tipHtml: {
            preContent: '(',
            downloadLinkText: '<span class="red">下载边界文件要求说明',
            nextContent: ')，填报前必读)',
            fileUrl: '/upload/static/边界文件要求说明20200514.pdf',
            fileName: '边界说明文件.pdf',
            fieldName: '矢量边界',
            params: { wrdkid: props.data.wrdkid, scjdbm: props.data.scjdbm, pgtype: props.data.pgtype },
          },
          buttonVisible: props.visibleFlag,
          showUploadList: false,
          maxCount: 1,
          fileName: (props?.dkxx?.wrdkmc ? props?.dkxx?.wrdkmc + '-' : '') + '管控区域矢量边界',
          accept: '.zip',
          beforeUpload: (file) => {
            if (!uploadGkBjGdFlag.value) {
              createMessage.error('请先上传拐点信息');
              return false
            }
            let isshow = false;
            const isFile = file.name.split('.')[file.name.split('.').length - 1];
            console.log(file, 'file');
            if (isFile == 'zip') {
              isshow = true;
            } else {
              createMessage.error('只能上传.zip格式的文件');
              isshow = false;
            }
            return isshow;
          },
          onChange: async (v) => {
            if (!v || v == props.data.qyshp) {
              return
            }
            const arry = v.split(',');
            props.data.qyshp = arry[arry.length - 1];
            const param = {
              wrdkid: props.data.wrdkid,
              scjdbm: props.data.scjdbm,
              pgtype: props.data.pgtype,
              url: arry[arry.length - 1],
              type: 2,
            };
            const res = await checkShp(param);
            let ss = transformation(res.zbx, JSON.parse(res.geomtry));
            res.geo = ss;
            res.type = 2;
            //边界校验 
            await checkCountBjxx(res);
            await upLoad({
              wrdkid: props.data.wrdkid,
              id: props.data.id,
              qyshp: arry[arry.length - 1],
              qyshpgeo:ss
            });
          },
        };
      },
    },
    {
      label: '详细调查检测数据表格',
      field: 'xxdcjcsjbg',
      required: true,
      dynamicDisabled: () => {
        return props.dksdzt == '1';
      },
      show: () => {
        return props.labelFirst == '详细调查' ? true : false;
      },
      component: 'JUpload',
      componentProps: () => {
        return {
          tipHtml: {
            downloadLinkText: '<button class="ant-btn ant-btn-primary">下载模板</button>',
            fileUrl: '/upload/static/详细调查检测数据表格模板.xlsx',
            fileName: '详细调查检测数据表格模板.xlsx',
          },
          buttonVisible: props.visibleFlag,
          showUploadList: false,
          maxCount: 1,
          fileName: (props?.dkxx?.wrdkmc ? props?.dkxx?.wrdkmc + '-' : '') + '详细调查检测数据表格',
          accept: '.xls,.xlsx',
          beforeUpload: (file) => {
            let isshow = false;
            if (file.type == 'application/vnd.ms-excel' || file.type == 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet') {
              isshow = true;
            } else {
              createMessage.error('只能上传.xls/.xlsx格式的文件');
              isshow = false;
            }
            return isshow;
          },
          onChange: async (v) => {
            if (!v || v == props.data.xxdcjcsjbg) {
              return
            }
            const arry = v.split(',');
            props.data.xxdcjcsjbg = arry[arry.length - 1]
            await upLoad({
              wrdkid: props.data.wrdkid,
              id: props.data.id,
              xxdcjcsjbg: arry[arry.length - 1],
            });
            // Modal.success({
            //   title: () => '上传提示',
            //   content: () => h('div', {}, [h('p', '上传成功')]),
            // });
          },
        };
      },
    },
  ];

  const [registerForm, { validate, getFieldsValue, setFieldsValue }] = useForm({
    //注册表单列
    schemas: formSchemas,
    //不显示查询和重置按钮
    showActionButtonGroup: false,
    //默认row行配置,当 layout 为 horizontal 生效
    rowProps: { gutter: 24, justify: 'start', align: 'middle' },
    //全局col列占比(每列显示多少位)，和schemas中的colProps属性一致
    baseColProps: { span: 12 },
    //使用labelCol的样式参数来控制标题宽度
    labelCol: { style: { width: '150px' } },
    //row行的样式
    baseRowStyle: { width: '100%' },
    //表单布局属性，支持（vertical,horizontal），默认为horizontal
    layout: 'horizontal',
  });

  watch(
    () => props.data,
    async (newVal: any, oldVal: any) => {
      (newVal?.id != oldVal?.id ||
        newVal?.wrdkid != oldVal?.wrdkid ||
        newVal?.gspic != oldVal?.gspic ||
        newVal?.dcbglj != oldVal?.dcbglj ||
        newVal?.dkshp != oldVal?.dkshp ||
        newVal?.dkpic != oldVal?.dkpic ||
        newVal?.xcsgzzcl != oldVal?.xcsgzzcl ||
        newVal?.xxdcjcsjbg != oldVal?.xxdcjcsjbg ||
        newVal?.fxpgbglj != oldVal?.fxpgbglj ||
        newVal?.falj != oldVal?.falj ||
        newVal?.gdFile != oldVal?.gdFile ||
        newVal?.qygdFile != oldVal?.qygdFile ||
        newVal?.zlyxfxgpgbglj != oldVal?.zlyxfxgpgbglj) &&
        nextTick(async () => {
          if (newVal?.dkshp) {
            mapShow.value = true;
            MapbjInfo.value = { wrdkid:newVal.wrdkid, scjdbm: newVal.scjdbm, pgtype: newVal.pgtype };
          }
          if (newVal.qygdFile) {
            uploadGkBjGdFlag.value = true;
          }
          if (newVal.gdFile) {
            uploadBjGdFlag.value = true;
          }
          const obj = toRaw(newVal);
          if (props.labelFirst == '风险评估') {
            obj.dcbglj = obj.fxpgbglj;
          } else if (props.labelFirst == '风险管控' || props.labelFirst == '修复' || props.labelFirst == '风险管控及修复') {
            obj.dcbglj = obj.falj;
          } else if (props.labelFirst == '风险管控效果评估' || props.labelFirst == '修复效果评估' || props.labelFirst == '风险管控及修复效果评估') {
            obj.dcbglj = obj.zlyxfxgpgbglj;
          }
          console.log('obj:::', obj);
          await setFieldsValue({
            ...obj,
          });
        });
    },
    { deep: true, immediate: true }
  );
  // 点击上传图片接口
  async function upLoad(param) {
    if (props.labelFirst == '初步调查') {
      const setup = await updateCbdc(param);
      if (setup=='成功') {
        emit("upsuccess")
      }
    } else if (props.labelFirst == '风险评估') {
      const setup = await saveGFxpg(param);
      if (setup=='成功') {
        emit("upsuccess")
      }
    } else if (props.labelFirst == '风险管控' || props.labelFirst == '修复' || props.labelFirst == '风险管控及修复') {
      const setup = await saveGkxf(param);
      if (setup=='成功') {
        emit("upsuccess")
      }
    } else if (props.labelFirst == '风险管控效果评估' || props.labelFirst == '修复效果评估' || props.labelFirst == '风险管控及修复效果评估') {
      const setup = await saveXgpg(param);
      if (setup=='成功') {
        emit("upsuccess")
      }
    } else {
      const setup = await updateXxdc(param);
      if (setup=='成功') {
        emit("upsuccess")
      }
    }
  }

  // 导出 excel
  async function onExportXls(url, name, params) {
    let realUrl = typeof url === 'function' ? url() : url;
    if (realUrl) {
      let title = typeof name === 'function' ? name() : name;
      let paramsForm: any = {};
      let paramsFormDefault: any = {};
      try {
        // 单独处理的开始日期结束日期，data自定义的参数
        if (paramsForm.data) {
          const arry = paramsForm.data.split(',');
          paramsForm.startTime = arry[0];
          paramsForm.endTime = arry[1];
        }
        if (paramsFormDefault.data) {
          const arry = paramsFormDefault.data.split(',');
          paramsFormDefault.startTime = arry[0];
          paramsFormDefault.endTime = arry[1];
        }
      } catch (e) {
        console.error(e);
      }
      if (!paramsForm?.column) {
        Object.assign(paramsForm, { column: 'createTime', order: 'desc' });
      }
      if (params) {
        Object.keys(params).map((k) => {
          let temp = (params as object)[k];
          if (temp) {
            paramsForm[k] = unref(temp);
          }
        });
      }
      return handleExportXls(title as string, realUrl, filterObj(paramsForm));
    } else {
      createMessage.warn('没有传递 exportConfig.url 参数');
      return Promise.reject();
    }
  }
  
</script>

<style scoped>
  /** 时间和数字输入框样式 */
  :deep(.ant-input-number) {
    width: 100%;
  }

  :deep(.ant-picker) {
    width: 100%;
  }
</style>

