<!-- 文件型资源上传 -->
<template>
  <div style="height: 100%; width: 100%; margin-top: 0; padding: 0">
    <!-- 使用搜索框和表格封装组件 -->
    <BasicTable :rowSelection="{ type: 'checkbox' }" @register="registerTable" :clickToRowSelect="true">
      <!-- 表格右上角按钮 -->
      <template #toolbar>
        <Authority>
          <a-button type="primary" @click="addMethod">新增流程</a-button>
        </Authority>
        <!-- :value="authList.deleteAuth" -->
        <Authority>
          <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: '查看',
            onClick: handleView.bind(null, record),
          },
          {
            label: '编辑',
            onClick: handleEdit.bind(null, record),
          },
          {
            label: '删除',
            color: 'error',
            ifShow: true,
            popConfirm: {
              title: '是否确认删除',
              confirm: handleDeleteOrBatchDelete.bind(null, record),
            },
          },
        ]" />
      </template>
      <!-- <template #pdate="{ record }">
        <Tag :color="'red'">
          {{ record.publishdate ? moment(record.publishdate).format('YYYY-MM-DD HH:mm:ss') : '' }}
        </Tag>
      </template> -->
      <template #status="{ record }">
        <!-- <a-switch checked-children="启用" un-checked-children="停用" :checked="record.STATUS === 0 ? true : false"
          @change="changeCheck(record)" /> -->
        {{ record.STATUS === 0 ? "使用中" : "" }}
      </template>
    </BasicTable>
    <!-- 新增和编辑 -->
    <!-- <RoleDrawer @register="registerDrawer" @success="handleSuccess" /> -->
    <AddProcess @register="registerModal" @success="handleSuccess"></AddProcess>
  </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 { getFileListByPage, delFileResource } from '../../api/fileUploadApi';
import { columns, searchFormSchema } from './configData';
import { list } from '/@/api/resource/files';
import { useBatchDelete } from '/@/hooks/web/useBatchDelete';
import AddProcess from './AddProcess.vue';
import { useMessage } from '/@/hooks/web/useMessage';
import Moment from 'moment';
import {
  queryFlowInfoPage,
  queryFlowInfoById,
  queryFlowInfo,
  delFlowInfo,
} from '/@/api/resource/examine';

export default defineComponent({
  name: 'configProcess',
  components: { BasicTable, Authority, Popconfirm, TableAction, AddProcess },
  setup() {
    //按钮的权限控制标识
    const bottomAuthority = 'sys:process:config:';
    const authList = {
      addAuth: bottomAuthority + 'processAdd', //新增权限控制
      deleteAuth: bottomAuthority + 'processDelete', //删除权限控制
      editAuth: bottomAuthority + 'processEdit', //编辑权限控制
    };
    const moment = Moment;
    const { createMessage } = useMessage();
    // 新增和编辑界面
    const [registerModal, { openModal: openModal }] = useModal();
    // 新增和编辑界面操作函数
    function handleSuccess() {
      reload();
    }
    // 配置下方表格
    const [registerTable, { setProps, reload, setSelectedRowKeys }] = useTable({
      // 表格题目
      title: '流程配置列表',
      // 分页查询请求函数
      api: queryFlowInfoPage, //list,
      // 表头
      columns,
      // 查询条件框配置
      // formConfig: {
      //   labelWidth: 120,
      //   schemas: searchFormSchema,
      // },
      useSearchForm: false,
      showTableSetting: true,
      bordered: true,
      // 表格控制序号显示
      showIndexColumn: true,
      // 表格操作栏
      actionColumn: {
        width: 200,
        title: '操作',
        dataIndex: 'action',
        slots: { customRender: 'action' },
        fixed: 'right',
      },
      tableSetting: {
        redo: true,
        size: true,
        setting: false,
        fullScreen: false
      },
      pagination: {
        hideOnSinglePage: false,
        page: 1,
        pageSize: 10,
      },
    });
    //
    const { hasBatchDelete, handleDeleteOrBatchDelete, selectionOptions, resetSelectedRowKeys } =
      useBatchDelete(delFlowInfo, handleSuccess, setProps);
    selectionOptions.rowSelection.getCheckboxProps = (record) => {
      // Demo:status为1的选择框禁用 控制选择框勾选状态
      // if (record.status === 1) {
      //   return { disabled: true };
      // } else {
      //   return { disabled: false };
      // }
    };
    nextTick(() => {
      setProps(selectionOptions);
    });

    /**
     * 新增
     */
    function addMethod() {
      openModal(true, {
        isUpdate: false,
      });
    }

    /**
     * 查看
     */
    const handleView = async (record) => {
      const result = await queryFlowInfo({
        flowInfo: {
          id: record.id,
        },
      });
      if (result) {
        openModal(true, {
          record: result,
          isUpdate: false,
        });
      } else {
        createMessage.error('查询流程明细异常！请联系管理员处理');
      }
    };

    /**
     * 编辑
     */
    const handleEdit = async (record) => {
      const result = await queryFlowInfo({
        flowInfo: {
          id: record.id,
        },
      });
      if (result) {
        openModal(true, {
          record: result,
          isUpdate: true,
        });
      } else {
        createMessage.error('查询流程明细异常！请联系管理员处理');
      }
    };

    function changeCheck(row) {
      //console.log(row);
    }

    return {
      moment,
      registerModal,
      authList,
      createMessage,
      registerTable,
      addMethod,
      handleView,
      handleEdit,
      handleSuccess,
      hasBatchDelete,
      handleDeleteOrBatchDelete,
      changeCheck,
    };
  },
});
</script>
<style scoped lang="less">
:deep(.vben-basic-table) {
  height: 100% !important;

  .ant-table-wrapper {
    height: 100% !important;
  }
}
</style>
