<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 {
  paymentReviewList,
} from '#/api/property/costManagement/paymentReview';
import type { PaymentReviewForm } from '#/api/property/costManagement/paymentReview/model';
import paymentReviewModal from './paymentReview-modal.vue';
import paymentReviewDetail from './paymentReview-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 paymentReviewList({
          pageNum: page.currentPage,
          pageSize: page.pageSize,
          ...formValues,
        });
      },
    },
  },
  rowConfig: {
    keyField: 'id',
  },
  id: 'property-paymentReview-index'
};

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

const [PaymentReviewModal, modalApi] = useVbenModal({
  connectedComponent: paymentReviewModal,
});

const [paymentReviewDetailModal, paymentReviewDetailApi] = useVbenModal({
  connectedComponent: paymentReviewDetail,
});

async function handleInfo(row: Required<PaymentReviewForm>) {
  paymentReviewDetailApi.setData({ id: row.id });
  paymentReviewDetailApi.open();
}

async function handleEdit(row: Required<PaymentReviewForm>) {
  modalApi.setData({ id: row.id });
  modalApi.open();
}
</script>

<template>
  <Page :auto-content-height="true">
    <BasicTable table-title="缴费审核列表">
      <template #action="{ row }">
        <Space>
          <ghost-button
              @click.stop="handleInfo(row)"
              v-access:code="['property:payFeeAudit:query']"
          >
            {{ $t('pages.common.info') }}
          </ghost-button>
          <ghost-button
              :disabled="row.state!=='0'"
              @click.stop="handleEdit(row)"
              v-access:code="['property:payFeeAudit:edit']"
          >
            {{ '审核' }}
          </ghost-button>
        </Space>
      </template>
    </BasicTable>
    <PaymentReviewModal @reload="tableApi.query()" />
    <paymentReviewDetailModal/>
  </Page>
</template>
