<template>
  <div>
    <!--引用表格-->
    <BasicTable @register="registerTable" :rowSelection="rowSelection">
      <!-- 行业分类 -->
      <template #form-suspect="{ model, field }">
        <a-select
          v-model:value="model[field]"
          placeholder="请选择行业分类"
          :fieldNames="{ label: 'text', value: 'value' }"
          :options="isSuspectOptions"
          @change="changeSuspect"
        ></a-select>
      </template>
      <template #form-category="{ model, field }">
        <a-tree-select
          v-model:value="model[field]"
          show-search
          placeholder="请选择二级"
          allow-clear
          tree-default-expand-all
          :field-names="{ label: 'name', value: 'id', children: 'children' }"
          :tree-data="treeData"
          tree-node-filter-prop="label"
        >
          <template #suffixIcon>
            <SmileOutlined />
          </template>
        </a-tree-select>
      </template>
      <!--插槽:table标题-->
      <template #tableTitle>
        <a-button type="primary" @click="getMdb" v-auth="'qdml-gzml-ckxx'">下载mdb文件</a-button>
        <a-button type="primary" @click="getGdb" v-auth="'qdml-gzml-ckxx'">下载gdb文件</a-button>
        <div style="color:red;text-align:right;flex:1;line-height:32px;">注：本次数据为全量数据，生成的结果为前一天数据结果！</div>
      </template>
    </BasicTable>
  </div>
  <!--查看详情前置 -->
  <a-modal v-model:visible="open" :centered="true" title="信息">
    <template #footer>
      <a-button key="submit" type="primary" @click="open = false">确定</a-button>
    </template>
    <div class="py-10 ml-6">该地块还未进行填报，没有详情可以查看</div>
  </a-modal>
</template>

<script lang="ts" name="directory-gzml-gzml" setup>
  import { ref, h } from 'vue';
  import { BasicTable } from '/@/components/Table';
  import { useModal } from '/@/components/Modal';
  import { useListPage } from '/@/hooks/system/useListPage';
  import { columns, searchFormSchema } from './data';
  import { DsrwGeoList, getDownloadMdb, getDownloadGdb } from './api';
  import { existDclx, updateDclx, downloadFile } from '/@/api/common/api';
  import { useMessage } from '/@/hooks/web/useMessage';
  import { useRouter } from 'vue-router';
  import { Modal } from 'ant-design-vue';
  const { createMessage } = useMessage();
  let router = useRouter();
  //注册model
  const [registerMoveModal, { openModal: openMoveModal }] = useModal();
  //注册table数据
  const { tableContext } = useListPage({
    tableProps: {
      title: '清单名录-定时任务地图数据',
      api: DsrwGeoList,
      columns,
      canResize: false,
      clickToRowSelect: true,
      //定义rowSelection的类型，默认是checkbox多选，可以设置成radio单选
      rowKey: 'dkdm',
      rowSelection: { type: 'radio' },
      showActionColumn: false,
      formConfig: {
        labelWidth: 120,
        schemas: searchFormSchema,
        autoSubmitOnEnter: true,
        showAdvancedButton: false,
      },
      showIndexColumn: true,
      actionColumn: {
        width: 120,
      },
    },
  });
  const open = ref(false);
  const noChange = ref<boolean>(false);
  const selectdclx = ref<number>(1);
  const flg = ref(1);
  const visible = ref<boolean>(false);
  const bgvisible = ref<boolean>(false);
  const [registerTable, { reload }, { rowSelection, selectedRows, selectedRowKeys }] = tableContext;

  //查看基本信息
  function handleView() {
    if (selectedRowKeys.value.length == 0) {
      createMessage.info('请选择需要处理的内容，每次只能选中一条');
      return;
    }
    const record: any = selectedRows.value[0];
    if (!record.dclx) {
      open.value = true;
      return;
    }
    router.push(`/dkgl/investigate/modal/ViewData?wrdkid=${selectedRowKeys.value[0]}`);
  }
  //成功回调
  function handleSuccess() {
    selectedRows.value = [];
    selectedRowKeys.value = [];
    reload();
  }
  const handleOk = async () => {
    if (flg.value != 2) {
      visible.value = false;
      await updateDclx({ wrdkid: selectedRowKeys.value[0], dclx: selectdclx.value });
      router.push(`/dkgl/investigate/modal/DataFilling?wrdkid=${selectedRowKeys.value[0]}`);
    } else {
      bgvisible.value = true;
    }
  };

  const getMdb = ()=>{
    getDownloadMdb(null).then((res)=>{
      // console.log(res);
      if (res) {
        downloadFile('/sys/common/static'+res, res.split("/")[res.split("/").length-1]);
      } else {
        createMessage.error('文件下载失败');
      }
    });
  }

  const getGdb = ()=>{
    getDownloadGdb(null).then((res)=>{
      // console.log(res);
      if (res) {
        downloadFile('/sys/common/static'+res, res.split("/")[res.split("/").length-1]);
      } else {
        createMessage.error('文件下载失败');
      }
    });
  }
  
</script>
<style scoped></style>
