gaoluyang
昨天 b64a0deae5b5d33f9e20671a68936b27f0b9b00b
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
<script lang="ts" setup>
import type { WmsCheckOrderApi } from '#/api/wms/order/check';
import type { WmsCheckOrderDetailApi } from '#/api/wms/order/check/detail';
 
import { computed, ref } from 'vue';
 
import { useVbenModal } from '@vben/common-ui';
 
import { VxeColumn, VxeTable } from '#/adapter/vxe-table';
import {
  getCheckOrder,
  getCheckOrderDetailListByOrderId,
} from '#/api/wms/order/check';
import { useDescription } from '#/components/description';
import {
  formatPrice,
  formatQuantity,
  getLossClass,
} from '#/views/wms/utils/format';
 
import {
  getCheckDetailFooter,
  getDetailActualPrice,
  getDetailDifferencePrice,
  getDetailDifferenceQuantity,
  useDetailSchema,
} from '../data';
 
interface DetailRow extends WmsCheckOrderDetailApi.CheckOrderDetail {
  actualPrice?: number;
  differencePrice?: number;
  differenceQuantity?: number;
}
 
defineOptions({ name: 'WmsCheckOrderDetail' });
 
const detailData = ref<WmsCheckOrderApi.CheckOrder>({});
 
/** 详情明细补齐实际金额和盈亏字段,便于表格与 footer 统一渲染 */
const detailRows = computed<DetailRow[]>(() =>
  (detailData.value.details || []).map((detail) => ({
    ...detail,
    actualPrice: getDetailActualPrice(detail),
    differencePrice: getDetailDifferencePrice(detail),
    differenceQuantity: getDetailDifferenceQuantity(detail),
  })),
);
 
const [Descriptions] = useDescription({
  bordered: true,
  column: 2,
  schema: useDetailSchema(),
  useCard: false,
});
 
const [Modal, modalApi] = useVbenModal({
  async onOpenChange(isOpen: boolean) {
    if (!isOpen) {
      detailData.value = {};
      return;
    }
    const data = modalApi.getData<{ id?: number }>();
    if (!data?.id) {
      return;
    }
    modalApi.lock();
    try {
      const order = await getCheckOrder(data.id);
      const details =
        order.details || (await getCheckOrderDetailListByOrderId(data.id));
      detailData.value = { ...order, details };
    } finally {
      modalApi.unlock();
    }
  },
});
</script>
 
<template>
  <Modal
    title="盘库单详情"
    class="w-2/3"
    :show-cancel-button="false"
    :show-confirm-button="false"
  >
    <div class="mx-4 space-y-4">
      <Descriptions :data="detailData" />
      <VxeTable
        :data="detailRows"
        border
        empty-text="暂无商品明细"
        :footer-method="getCheckDetailFooter"
        :show-overflow="true"
        show-footer
        size="small"
      >
        <VxeColumn title="商品信息" min-width="200">
          <template #default="{ row }">
            <div>{{ row.itemName || '-' }}</div>
            <div v-if="row.itemCode" class="text-xs text-gray-500">
              商品编号:{{ row.itemCode }}
            </div>
          </template>
        </VxeColumn>
        <VxeColumn title="规格信息" min-width="200">
          <template #default="{ row }">
            <div>{{ row.skuName || '-' }}</div>
            <div v-if="row.skuCode" class="text-xs text-gray-500">
              规格编号:{{ row.skuCode }}
            </div>
          </template>
        </VxeColumn>
        <VxeColumn field="quantity" title="账面数量" align="right" width="120">
          <template #default="{ row }">
            {{ formatQuantity(row.quantity) || '-' }}
          </template>
        </VxeColumn>
        <VxeColumn title="单价(元)" align="right" width="120">
          <template #default="{ row }">
            {{ formatPrice(row.price) || '-' }}
          </template>
        </VxeColumn>
        <VxeColumn
          field="checkQuantity"
          title="实盘数量"
          align="right"
          width="120"
        >
          <template #default="{ row }">
            {{ formatQuantity(row.checkQuantity) || '-' }}
          </template>
        </VxeColumn>
        <VxeColumn
          field="actualPrice"
          title="实际金额(元)"
          align="right"
          width="140"
        >
          <template #default="{ row }">
            {{ formatPrice(row.actualPrice) || '-' }}
          </template>
        </VxeColumn>
        <VxeColumn
          field="differenceQuantity"
          title="盈亏数量"
          align="right"
          width="120"
        >
          <template #default="{ row }">
            <span :class="getLossClass(row.differenceQuantity)">
              {{ formatQuantity(row.differenceQuantity) || '-' }}
            </span>
          </template>
        </VxeColumn>
        <VxeColumn
          field="differencePrice"
          title="实际盈亏金额(元)"
          align="right"
          width="160"
        >
          <template #default="{ row }">
            <span :class="getLossClass(row.differencePrice)">
              {{ formatPrice(row.differencePrice) || '-' }}
            </span>
          </template>
        </VxeColumn>
      </VxeTable>
    </div>
  </Modal>
</template>