<template>
  <div class="p-4">
    <BasicTable @register="registerTable">
      <template #createTime="{ record }">
        <Time :value="record.createTime" mode="datetime" />
      </template>
      <template #action="{ record }">
        <TableAction
          :actions="[
            {
              label: t('common.edit'),
              onClick: handleOpenModal.bind(null, record),
            },
          ]"
        />
      </template>
    </BasicTable>
    <SetpaswordModal @register="register" @reload="reload" />
    <!-- <addDetailsModal @register="registerAddDetail" @ok="reload" /> -->
  </div>
</template>
<script lang="ts">
  import { defineComponent, computed, ref } from 'vue';
  import { BasicTable, useTable, BasicColumn, TableAction } from '/@/components/Table';
  import { useMessage } from '/@/hooks/web/useMessage';
  import { useModal } from '/@/components/Modal';
  import { uploadApi } from '/@/api/sys/upload';
  import SetpaswordModal from './setconfigModal.vue';
  import { staffListApi, delApi, preDelApi, updateApi, getNumByStaff } from '/@/api/staff/list';
  import { useI18n } from '/@/hooks/web/useI18n';
  // import { useCopyToClipboard } from '/@/hooks/web/useCopyToClipboard';
  import { useGo } from '/@/hooks/web/usePage';
  import { Time } from '/@/components/Time';
  import { useUserStore } from '/@/store/modules/user';
  export default defineComponent({
    components: {
      BasicTable,
      TableAction,
      Time,
      SetpaswordModal,
      // addDetailsModal,
      // Alert,
    },
    setup() {
      const [register, { openModal }] = useModal();
      const surplusSubNum = ref({
        lookNum: 0,
        shotNum: 0,
      });
      const { createConfirm, createMessage } = useMessage();
      const userStore = useUserStore();
      const roleList = computed(() => userStore.getRoleList);
      console.log('getRoleList', roleList);
      const go = useGo();
      const { t } = useI18n();
      const columns: BasicColumn[] = [
        {
          title: t('routes.config.serial'),
          dataIndex: 'serial',
          width: 120,
        },
        {
          title: t('routes.config.account'),
          dataIndex: 'account',
          width: 150,
        },
        {
          title: t('routes.config.password'),
          dataIndex: 'password',
          width: 150,
        },
        {
          title: t('common.operation'),
          dataIndex: '',
          // ifShow: !getCheckRole('tourist'),
          slots: { customRender: 'action' },
          align: 'center',
          width: 40,
        },
      ];

      const [registerTable, { reload }] = useTable({
        title: t('routes.system.config'),
        api: staffListApi,
        columns: columns,
        useSearchForm: false,
        showTableSetting: true,
        tableSetting: { fullScreen: true },
        showIndexColumn: false,
        canResize: false,
        rowKey: 'id',
        fetchSetting: {
          pageField: 'pageNum',
          sizeField: 'pageSize',
          listField: 'list',
          totalField: 'total',
        },
        pagination: false,
        afterFetch: (T) => {
          return T;
        },
        bordered: true,
        sortFn: (sortInfo) => {
          let order = sortInfo.order && sortInfo.order.replace('end', '');
          return { ...sortInfo, sidx: sortInfo.field, order: order };
        },
      });
      function handleOpenModal(record) {
        openModal(true, record);
      }

      function handDelconfirm(record) {
        createConfirm({
          iconType: 'warning',
          title: '警告',
          content: `此操作将对${record.userName}进行删除, 是否继续?`,
          onOk: async () => {
            await delApi({ userId: record.id });
            reload();
          },
        });
      }
      return {
        registerTable,
        createMessage,
        handDelconfirm,
        t,
        reload,
        go,
        handleOpenModal,
        register,
        uploadApi: uploadApi as any,
        surplusSubNum,
      };
    },
  });
</script>
