<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="handle('ckxx')" v-auth="'hqgl-jgdk-ckxx'">查看详情</a-button>
        <a-button type="primary" @click="handle('jcxx')" v-auth="'hqgl-jgdk-jcxx'">添加监测信息</a-button>
        <a-button type="primary" @click="handle('ckjcxx')" v-auth="'hqgl-jgdk-ckjcxx'">查看监测信息</a-button>
        <a-button type="primary" @click="handle('fjxz')" v-auth="'zdjg-fjxz'">附件下载</a-button>
        <a-button type="primary" @click="onExportXls" v-auth="'hqgl-jgdk-dc'">导出</a-button>
      </template>
      <!--操作栏-->
    </BasicTable>
    <!--查看详情 -->
    <viewInfor @register="registerModal" @success="handleSuccess" />
  </div>
</template>

<script lang="ts" name="dkgl-investigate-Acceptance" setup>
  import { BasicTable } from '/@/components/Table';
  import { useListPage } from '/@/hooks/system/useListPage';
  import { columnJG, searchFormSchemajg, useSuspectsData, useCategoryData } from './data';
  import viewInfor from './modal/viewInfor.vue';

  import { useRouter } from 'vue-router';

  import { zdjgList, zdjgExport } from './api';
  import { useMessage } from '/@/hooks/web/useMessage';
  import { useModal } from '/@/components/Modal';
  import { downloadFile } from '/@/api/common/api';

  const { createMessage } = useMessage();
  let router = useRouter();
  const [registerModal, { openModal }] = useModal();

  //注册table数据
  const { tableContext, onExportXls } = useListPage({
    tableProps: {
      title: '重点监管地块',
      api: zdjgList,
      columns: columnJG,
      canResize: false,
      //定义rowSelection的类型，默认是checkbox多选，可以设置成radio单选
      rowKey: 'wrdkid',
      clickToRowSelect: true,
      showActionColumn: false,
      rowSelection: { type: 'checkbox' },
      // useSearchForm: false,
      formConfig: {
        labelWidth: 120,
        schemas: searchFormSchemajg,
        autoSubmitOnEnter: true,
        showAdvancedButton: false,
      },
      actionColumn: {
        width: 120,
      },
    },
    exportConfig: {
      name: '重点监管地块',
      url: zdjgExport,
    },
  });
  const isSuspectOptions = useSuspectsData().data; // 行业分类
  const useCategory = useCategoryData();
  const treeData = useCategory.data; // 行业类别-数据
  const changeSuspect = useCategory.changeIsSuspect; // 行业类别-方法
  const [registerTable, { reload }, { rowSelection, selectedRowKeys, selectedRows }] = tableContext;

  function handle(v) {
    if(v == 'fjxz'){
      if (selectedRowKeys.value.length == 0) {
        createMessage.info('请选择需要处理的内容，至少选中一条');
        return;
      }
      downloadFile('/qdgl/zdjgBatchDownLoad', `地块管理-重点监管地块附件.zip`, {wrdkids:selectedRowKeys.value.join(',') });
      return
    }
    if (selectedRowKeys.value.length == 0 || selectedRowKeys.value.length > 1) {
      createMessage.info('请选择需要处理的内容，每次只能选中一条');
      return;
    }
    const obj = { ...selectedRows.value[0] };
    if (v == 'ckxx') {
      // 跳查看管理列表
      openModal(true, {
        record: obj,
        isUpdate: true,
        showFooter: true,
      });
    } else if (v == 'jcxx') {
      router.push(`/dkgl/hqgl/jgInfor?wrdkid=${selectedRowKeys.value[0]}&type=edit`);
    } else if(v == 'ckjcxx'){
      router.push(
        `/dkgl/hqgl/jgList?wrdkid=${selectedRowKeys.value[0]}&wrdkmc=${selectedRows.value[0].wrdkmc}&wrdkbm=${selectedRows.value[0].wrdkbm}`
      );
    }
  }
  function handleSuccess() {
    reload();
  }
</script>
<style scoped></style>
