<template>
  <div>
    <BasicTable @register="registerTimeTable">
      <template #action="{ record }">
        <TableAction
          :actions="[
            {
              label: record.sceneCount || '-',
              onClick: handleCreate.bind(null, record),
            },
          ]"
        />
      </template>
    </BasicTable>
    <sceneListModal @register="register" />
  </div>
</template>
<script lang="ts">
  import { defineComponent } from 'vue';
  import { BasicTable, useTable, FormProps, TableAction } from '/@/components/Table';
  import { userShareList } from '/@/api/account';
  import { userListSchema } from './data';
  import { useI18n } from '/@/hooks/web/useI18n';
  import { usePermissionStore } from '/@/store/modules/permission';
  import sceneListModal from './sceneListModal.vue';
  import { useModal } from '/@/components/Modal';

  export default defineComponent({
    components: {
      BasicTable,
      sceneListModal,
      TableAction,
    },
    setup() {
      const { t } = useI18n();
      const permissionStore = usePermissionStore();
      const [register, { openModal }] = useModal();
      const { getCheckPerm } = permissionStore;
      const searchForm: Partial<FormProps> = {
        labelWidth: 100,
        schemas: [
          {
            field: 'ryNickName',
            label: '姓名',
            component: 'Input',
            componentProps: {
              maxLength: 100,
            },
            colProps: {
              xl: 6,
              xxl: 6,
            },
          },
          {
            field: 'ryNo',
            label: '人员编号',
            component: 'Input',
            componentProps: {
              maxLength: 100,
            },
            colProps: {
              xl: 8,
              xxl: 8,
            },
          },
        ],
      };
      const [registerTimeTable, { reload }] = useTable({
        api: userShareList,
        columns: userListSchema,
        useSearchForm: true,
        formConfig: searchForm,
        showTableSetting: true,
        showIndexColumn: false,
        searchInfo: { type: 1 },
        rowKey: 'id',
        fetchSetting: {
          pageField: 'pageNum',
          sizeField: 'pageSize',
          listField: 'list',
          totalField: 'total',
        },
        actionColumn: {
          width: 100,
          title: '场景',
          dataIndex: 'action',
          slots: { customRender: 'action' },
        },
        canResize: true,
      });
      function handleCreate(record) {
        openModal(true, record);
      }
      function tabChange(val: string) {
        console.log('tabChange', val);
        reload();
      }
      function handleOpen(record) {
        console.log('点击了启用', record);
      }
      return {
        registerTimeTable,
        handleOpen,
        tabChange,
        reload,
        register,
        getCheckPerm,
        handleCreate,
        t,
      };
    },
  });
</script>
<style lang="less" scoped>
  .desc-wrap-BasicTable {
    background-color: #f0f2f5;
    .vben-basic-table-form-container {
      padding: 0;
    }
  }
</style>
