<template>
  <div style="width: 95%;margin:0 auto;margin-top: 30px;">
    <!--引用表格-->
    <BasicTable @register="registerTable">
      <!--插槽:table标题-->
      <template #tableTitle>
        <a-button type="primary" @click="router.back()" v-auth="'dkdc-tbz-zltb'">返回</a-button>
        <a-button type="primary" v-if="route.query.type === 'edit'" @click="handleAdd"
          v-auth="'dkdc-tbz-zltb'">新增</a-button>
      </template>
      <template #action="{ record }">
        <TableAction :actions="getTableAction(record)" />
      </template>
    </BasicTable>
  </div>
</template>
  
<script lang="ts" name="xcjd-Supervise-LookData" setup>
import { BasicTable, TableAction, TableActionType } from '/@/components/Table';
import { useListPage } from '/@/hooks/system/useListPage';
import { useRouter, useRoute } from 'vue-router';
import { useMessage } from '/@/hooks/web/useMessage';
import { lookDatacolumns, searchFormSchema, useSuspectsData, useCategoryData } from './data';
import { getXcjdList, SetDel,getImportUrl, getExportUrl } from './api';
// import { useModal } from '/@/components/Modal';
import { ref } from "vue";
//注册model
// const [registerModal, { openModal }] = useModal();
// let isEdit = ref(true)
let router = useRouter();
let route = useRoute();
const { createMessage } = useMessage();

//注册table数据
const { tableContext } = useListPage({
  tableProps: {
    title: '现场监督-现场监督-现场监督列表',
    api: getXcjdList,
    columns:lookDatacolumns,
    canResize: false,
    //定义rowSelection的类型，默认是checkbox多选，可以设置成radio单选
    rowKey: 'wrdkid',
    // rowSelection: { type: 'radio' },
    // clickToRowSelect: true,
    useSearchForm: false,
    showIndexColumn: true,
    //   formConfig: {
    //     labelWidth: 120,
    //     schemas: searchFormSchema,
    //     autoSubmitOnEnter: true,
    //     showAdvancedButton: false,
    //   },
    actionColumn: {
      width: 120,
      fixed: 'right'
    },
    beforeFetch(params) {
      if (route.query.wrdkid) {
        params.wrdkid = route.query.wrdkid;
      } else {
        createMessage.error('内容错误，请返回重试')
      }
    },
  },
});
const [registerTable, { reload }, { rowSelection, selectedRowKeys }] = tableContext;
//删除事件
async function handleDelete(record) {
  await SetDel({xcjdId:record.id})
  reload();
}
//编辑事件
function handleLook(record) {
  router.push(`/xcjd/Supervise/LookData/look?xcjdId=${record.id}`)
}
//编辑事件
function handleAdd() {
  router.push(`/xcjd/Supervise/LookData/form?wrdkid=${route.query.wrdkid}`)
}
/**
* 操作栏
*/
function getTableAction(record) {
  if (route.query.type === 'edit') {
    return [
      {
        label: '删除',
        popConfirm: {
          title: '是否确认删除',
          confirm: handleDelete.bind(null, record),
        },
      },
      {
        label: '查看',
        onClick: handleLook.bind(null, record),
      },
    ];
  } else if (route.query.type === 'look') {
    return [
      {
        label: '查看',
        onClick: handleLook.bind(null, record),
      },
    ];
  }

}
</script>
<style scoped></style>
  