gaoluyang
2026-06-24 712aa51536236d43e87273e4ce45ac5691dffad8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<script lang="ts" setup>
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { ErpPurchaseInApi } from '#/api/erp/purchase/in';
 
import { ref } from 'vue';
 
import { message, Modal } from 'ant-design-vue';
 
import { useVbenVxeGrid } from '#/adapter/vxe-table';
import { getPurchaseInPage } from '#/api/erp/purchase/in';
 
import { usePurchaseInGridColumns, usePurchaseInGridFormSchema } from '../data';
 
const emit = defineEmits<{
  success: [rows: ErpPurchaseInApi.PurchaseIn[]];
}>();
 
const supplierId = ref<number>(); // 供应商 ID
const open = ref<boolean>(false); // 弹窗是否打开
const selectedRows = ref<ErpPurchaseInApi.PurchaseIn[]>([]); // 选中的行
 
/** 表格配置 */
const [Grid, gridApi] = useVbenVxeGrid({
  formOptions: {
    schema: usePurchaseInGridFormSchema(),
  },
  gridOptions: {
    columns: usePurchaseInGridColumns(),
    height: 520,
    keepSource: true,
    proxyConfig: {
      ajax: {
        query: async ({ page }, formValues) => {
          return await getPurchaseInPage({
            pageNo: page.currentPage,
            pageSize: page.pageSize,
            supplierId: supplierId.value,
            paymentEnable: true, // 只查询可付款的
            ...formValues,
          });
        },
      },
    },
    rowConfig: {
      keyField: 'id',
      isHover: true,
    },
    checkboxConfig: {
      highlight: true,
      range: true,
    },
    toolbarConfig: {
      refresh: true,
      search: true,
    },
  } as VxeTableGridOptions<ErpPurchaseInApi.PurchaseIn>,
  gridEvents: {
    checkboxChange: ({
      records,
    }: {
      records: ErpPurchaseInApi.PurchaseIn[];
    }) => {
      selectedRows.value = records;
    },
    checkboxAll: ({ records }: { records: ErpPurchaseInApi.PurchaseIn[] }) => {
      selectedRows.value = records;
    },
  },
});
 
/** 打开弹窗 */
function openModal(id: number) {
  // 重置数据
  supplierId.value = id;
  open.value = true;
  selectedRows.value = [];
  // 查询列表
  gridApi.formApi?.resetForm();
  gridApi.formApi?.setValues({ supplierId: id });
  gridApi.query();
}
 
/** 确认选择采购入库单 */
function handleOk() {
  if (selectedRows.value.length === 0) {
    message.warning('请选择要添加的采购入库单');
    return;
  }
  emit('success', selectedRows.value);
  open.value = false;
}
 
defineExpose({ open: openModal });
</script>
 
<template>
  <Modal
    v-model:open="open"
    title="选择采购入库单"
    width="80%"
    @cancel.stop="open = false"
    @ok.stop="handleOk"
  >
    <Grid table-title="采购入库单列表(仅展示可付款的单据)" />
  </Modal>
</template>