<!-- 场景资源上传 -->
<template>
  <div style="height: 100%; width: 100%; margin-top: 0; padding: 0;">
    <!-- 使用搜索框和表格封装组件 -->
    <BasicTable
    :rowSelection="{ type: 'checkbox' }" 
    @register="registerTable"
    :clickToRowSelect="false"
    >
    <!-- 表格右上角按钮 -->
    <template #toolbar>
        <Authority  :value="authList.addAuth">
          <a-button type="primary" @click="addMethod" >新增接口</a-button>
        </Authority>
        <Authority :value="authList.deleteAuth">
          <Popconfirm
            title="您确定要批量删除数据"
            ok-text="确定"
            cancel-text="取消"
            @confirm="handleDeleteOrBatchDelete(null)"
          >
            <a-button type="primary" color="error" :disabled="hasBatchDelete"> 批量删除 </a-button>
          </Popconfirm>
        </Authority>
      </template>
      <!-- 表格操作栏 -->
      <template #action="{ record }">
        <TableAction
          :actions="[
                        {
              label: '浏览',
              auth: 'api:yt:role:saveOrUpdateRoleInfoWithMenu:update',
              icon: 'clarity:note-edit-line',//图标
              onClick: handleEdit.bind(null, record),
            },
            {
              label: '查看',
              auth: 'api:yt:role:saveOrUpdateRoleInfoWithMenu:update',
              icon: 'clarity:note-edit-line',
              onClick: handleEdit.bind(null, record),
            },
            {
              label: '编辑',
              auth: 'api:yt:role:saveOrUpdateRoleInfoWithMenu:update',
              icon: 'clarity:note-edit-line',
              onClick: handleEdit.bind(null, record),
            },
            {
              label: '删除',
              auth: 'api:yt:role:delete',
              icon: 'ant-design:delete-outlined',
              color: 'error',
              ifShow: true,
              popConfirm: {
                title: '是否确认删除',
                confirm: handleDeleteOrBatchDelete.bind(null, record),
              },
            },
          ]"
        />
      </template>
    </BasicTable>
    <!-- 新增和编辑 -->
    <!-- <RoleDrawer @register="registerDrawer" @success="handleSuccess" /> -->
    <addMethod @register="registerModal" @success="handleSuccess"></addMethod>
  </div>
</template>

<script>
import { defineComponent, nextTick } from 'vue';
import { BasicTable, TableAction, useTable } from '/@/components/Table';
import { Authority } from '/@/components/Authority';
import { useModal } from '/@/components/Modal';
import { Popconfirm } from 'ant-design-vue';
import { getInterfaceListByPage, delInterfaceResource  } from '../../api/interfaceUploadApi';
import { columns, searchFormSchema } from './interfaceUploadData';
// Interface
import { useBatchDelete } from '/@/hooks/web/useBatchDelete';

import AddMethod from './AddMethod.vue'

export default defineComponent({
  name: 'mapUpload',
  components: { BasicTable, Authority, Popconfirm, TableAction,  AddMethod},
  setup(){
    //按钮的权限控制标识
    const bottomAuthority = "api:dataresource:interfaceupload:";
    const authList = {
      addAuth: bottomAuthority + "interfaceuploadAdd",//新增权限控制
      deleteAuth: bottomAuthority + "interfaceuploadDelete",//删除权限控制
      editAuth: bottomAuthority + "interfaceuploadEdit",//编辑权限控制
    }
    // 新增和编辑界面
    // const [registerDrawer, { openDrawer }] = useDrawer();
    const [registerModal, { openModal: openModal }] = useModal();
    // 新增和编辑界面操作函数
    function handleSuccess() {
      reload();
    };
    // 配置下方表格
    const [registerTable, { setProps, reload, setSelectedRowKeys }] = useTable({
      // 表格题目
        title: '接口服务列表',
        // 分页查询请求函数
        api: getInterfaceListByPage,
        // 表头
        columns,
        // 查询条件框配置Interface
        formConfig: {
          labelWidth: 120,
          schemas: searchFormSchema,
        },
        useSearchForm: true,
        showTableSetting: true,
        bordered: true,
        // 表格控制序号显示
        showIndexColumn: true,
        // 表格操作栏
        actionColumn: {
          width: 200,
          title: '操作',
          dataIndex: 'action',
          slots: { customRender: 'action' },
          fixed: 'right',
        },
      });
      // 
      const { hasBatchDelete, handleDeleteOrBatchDelete, selectionOptions, resetSelectedRowKeys } = useBatchDelete(delInterfaceResource, handleSuccess, setProps);
      // 
      selectionOptions.rowSelection.getCheckboxProps = (record) => {
        // Demo:status为1的选择框禁用
        if (record.status === 1) {
          return { disabled: true };
        } else {
          return { disabled: false };
        }
      };
      // 
      nextTick(() => {
        setProps(selectionOptions);
      });
      // 新增
      // function handleCreate() {
      //   // openDrawer(true, {
      //   //   isUpdate: false,
      //   // });
      // };
      function addMethod(){
        openModal(true, {
          isUpdate: false,
        });
      };
      // 编辑
      function handleEdit(record) {
        // openDrawer(true, {
        //   record,
        //   isUpdate: true,
        // });
      };

      return {
        registerModal,
        authList,
        registerTable,
        // handleCreate,
        addMethod,
        handleEdit,
        handleSuccess,
        hasBatchDelete,
        handleDeleteOrBatchDelete,
      };

  },
})
</script>