<script setup lang="ts">
import {Page, useVbenModal, type VbenFormProps} from '@vben/common-ui';
import {Space} from 'ant-design-vue';
import {
  useVbenVxeGrid,
  type VxeGridProps
} from '#/adapter/vxe-table';
import {
  workOrdersList,
} from '#/api/property/businessManagement/workOrders';
import workOrdersDetail from './work-orders-detail.vue';
import {columns, querySchema} from './data';

const formOptions: VbenFormProps = {
  commonConfig: {
    labelWidth: 80,
    componentProps: {
      allowClear: true,
    },
  },
  schema: querySchema(),
  wrapperClass: 'grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4',
};

const gridOptions: VxeGridProps = {
  checkboxConfig: {
    // 高亮
    highlight: true,
    // 翻页时保留选中状态
    reserve: true,
    // 点击行选中
    // trigger: 'row',
  },
  columns,
  height: 'auto',
  keepSource: true,
  pagerConfig: {},
  proxyConfig: {
    ajax: {
      query: async ({page}, formValues = {}) => {
        return await workOrdersList({
          pageNum: page.currentPage,
          pageSize: page.pageSize,
          status:'0',
          ...formValues,
        });
      },
    },
  },
  rowConfig: {
    keyField: 'id',
  },
  // 表格全局唯一表示 保存列配置需要用到
  id: 'property-workOrders-index'
};

const [BasicTable, tableApi] = useVbenVxeGrid({
  formOptions,
  gridOptions,
});

const [WorkOrdersDetail, detailApi] = useVbenModal({
  connectedComponent: workOrdersDetail,
});

function handleInfo(row:any) {
  detailApi.setData({id:row.id});
  detailApi.open();
}
</script>

<template>
  <Page :auto-content-height="true">
    <BasicTable table-title="工单待办列表" class="order-work-left-radio">
      <template #action="{ row }">
        <Space>
          <ghost-button
            v-access:code="['property:workOrders:info']"
            @click.stop="handleInfo(row)"
          >
            {{ $t('pages.common.info') }}
          </ghost-button>
        </Space>
      </template>
    </BasicTable>
    <WorkOrdersDetail/>
  </Page>
</template>

<style lang="scss" scoped>
</style>

