gaoluyang
3 天以前 7a5c5250b66cc6faffbcac9e192073473c50f79f
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
<script lang="ts" setup>
import type { ErpSaleOrderApi } from '#/api/erp/sale/order';
import type { DescriptionItemSchema } from '#/components/description';
 
import { h, onMounted, ref } from 'vue';
 
import { ContentWrap } from '@vben/common-ui';
import { DICT_TYPE } from '@vben/constants';
import {
  erpCountInputFormatter,
  erpPriceInputFormatter,
  formatDateTime,
} from '@vben/utils';
 
import { Spin, Tag } from 'ant-design-vue';
 
import { getSaleOrder } from '#/api/erp/sale/order';
import { DictTag } from '#/components/dict-tag';
import { useDescription } from '#/components/description';
 
import ItemForm from '../modules/item-form.vue';
 
defineOptions({ name: 'ErpSaleOrderDetail' });
 
const props = defineProps<{ id: string }>();
 
const loading = ref(false);
const formData = ref<ErpSaleOrderApi.SaleOrder>();
 
/** 文本字段空值占位 */
function textRender(val: unknown) {
  return val === 0 || val ? String(val) : '-';
}
 
/** 出库状态渲染 */
function renderOutStatus(val?: number) {
  const map: Record<number, { text: string; color: string }> = {
    0: { text: '未出库', color: 'default' },
    1: { text: '已预留', color: 'processing' },
    2: { text: '部分出库', color: 'warning' },
    3: { text: '全部出库', color: 'success' },
  };
  const item = map[val ?? 0]!;
  return h(Tag, { color: item.color }, () => item.text);
}
 
/** 生产状态渲染 */
function renderProductionStatus(val?: number) {
  if (formData.value?.needProduction !== 1) {
    return h(Tag, { color: 'default' }, () => '无需生产');
  }
  const map: Record<number, { text: string; color: string }> = {
    0: { text: '未完成', color: 'warning' },
    1: { text: '已完成', color: 'success' },
  };
  const item = map[val ?? 0]!;
  return h(Tag, { color: item.color }, () => item.text);
}
 
const [Descriptions] = useDescription({
  bordered: true,
  column: 2,
  schema: [
    { label: '订单单号', field: 'no', render: textRender },
    { label: '客户名称', field: 'customerName', render: textRender },
    { label: '关联合同', field: 'contractNo', render: textRender },
    {
      label: '订单时间',
      field: 'orderTime',
      render: (val) => formatDateTime(val) as string,
    },
    {
      label: '合计数量',
      field: 'totalCount',
      render: (val) => erpCountInputFormatter(val) || '-',
    },
    {
      label: '合计金额',
      field: 'totalPrice',
      render: (val) => erpPriceInputFormatter(val) || '-',
    },
    {
      label: '优惠金额',
      field: 'discountPrice',
      render: (val) => erpPriceInputFormatter(val) || '-',
    },
    {
      label: '定金金额',
      field: 'depositPrice',
      render: (val) => erpPriceInputFormatter(val) || '-',
    },
    {
      label: '审批状态',
      field: 'status',
      render: (val) =>
        h(DictTag, { type: DICT_TYPE.ERP_AUDIT_STATUS, value: val }),
    },
    {
      label: '出库状态',
      field: 'outStatus',
      render: (val) => renderOutStatus(val as number),
    },
    {
      label: '生产状态',
      field: 'productionStatus',
      render: (val) => renderProductionStatus(val as number),
    },
    { label: '创建人', field: 'creatorName', render: textRender },
    {
      label: '创建时间',
      field: 'createTime',
      render: (val) => formatDateTime(val) as string,
    },
    { label: '备注', field: 'remark', render: textRender },
  ] as DescriptionItemSchema[],
});
 
onMounted(async () => {
  try {
    loading.value = true;
    formData.value = await getSaleOrder(Number(props.id));
  } finally {
    loading.value = false;
  }
});
</script>
 
<template>
  <ContentWrap class="m-2">
    <Spin :spinning="loading" tip="加载中...">
      <div class="space-y-4">
        <!-- 基本信息 -->
        <div class="rounded-lg border border-border bg-background p-4">
          <div class="mb-4 flex items-center gap-2">
            <span class="inline-block h-4 w-1 rounded bg-primary" />
            <span class="text-base font-semibold">基本信息</span>
          </div>
          <Descriptions :data="formData" />
        </div>
        <!-- 销售明细 -->
        <div
          v-if="formData?.items?.length"
          class="rounded-lg border border-border bg-background p-4"
        >
          <div class="mb-4 flex items-center gap-2">
            <span class="inline-block h-4 w-1 rounded bg-primary" />
            <span class="text-base font-semibold">销售明细</span>
          </div>
          <ItemForm :items="formData.items" :disabled="true" />
        </div>
      </div>
    </Spin>
  </ContentWrap>
</template>