|
@@ -1,13 +1,16 @@
|
|
|
<script lang="ts" setup>
|
|
<script lang="ts" setup>
|
|
|
|
|
+import type { ExtendedFormApi } from '@vben/common-ui';
|
|
|
import type { OrdersEntity } from '@vben/types';
|
|
import type { OrdersEntity } from '@vben/types';
|
|
|
|
|
|
|
|
-import { computed, ref } from 'vue';
|
|
|
|
|
|
|
+import { computed, h, ref } from 'vue';
|
|
|
|
|
|
|
|
import { useVbenModal } from '@vben/common-ui';
|
|
import { useVbenModal } from '@vben/common-ui';
|
|
|
|
|
|
|
|
-import { ElMessage } from 'element-plus';
|
|
|
|
|
|
|
+import { ElImage, ElMessage } from 'element-plus';
|
|
|
|
|
|
|
|
import { useVbenForm, z } from '#/adapter/form';
|
|
import { useVbenForm, z } from '#/adapter/form';
|
|
|
|
|
+import { getDictListApi } from '#/api/dict';
|
|
|
|
|
+import { getAttachmentListApi } from '#/api/file';
|
|
|
import { addOrdersApi, editOrdersApi, getOrdersDetailApi } from '#/api/orders';
|
|
import { addOrdersApi, editOrdersApi, getOrdersDetailApi } from '#/api/orders';
|
|
|
|
|
|
|
|
const emit = defineEmits(['finish']);
|
|
const emit = defineEmits(['finish']);
|
|
@@ -22,6 +25,9 @@ const titleMap = {
|
|
|
|
|
|
|
|
const getTitle = computed(() => titleMap[formType.value]);
|
|
const getTitle = computed(() => titleMap[formType.value]);
|
|
|
|
|
|
|
|
|
|
+const invoiceDataList = ref<any[]>([{}]);
|
|
|
|
|
+const certificateDataList = ref<any[]>([]);
|
|
|
|
|
+
|
|
|
const [BaseForm, baseFormApi] = useVbenForm({
|
|
const [BaseForm, baseFormApi] = useVbenForm({
|
|
|
showDefaultActions: false,
|
|
showDefaultActions: false,
|
|
|
// 所有表单项共用,可单独在表单内覆盖
|
|
// 所有表单项共用,可单独在表单内覆盖
|
|
@@ -202,19 +208,215 @@ const [Modal, modalApi] = useVbenModal({
|
|
|
|
|
|
|
|
try {
|
|
try {
|
|
|
modalApi.setState({ loading: true });
|
|
modalApi.setState({ loading: true });
|
|
|
- const detailData = await getOrdersDetailApi({
|
|
|
|
|
- ordersid: data.value.row.ordersid,
|
|
|
|
|
|
|
+
|
|
|
|
|
+ invoiceDataList.value = [];
|
|
|
|
|
+ certificateDataList.value = [];
|
|
|
|
|
+
|
|
|
|
|
+ // 去掉schema中invoiceAttachments和certificateAttachments字段,避免页面不更新
|
|
|
|
|
+ baseFormApi.setState({
|
|
|
|
|
+ schema: baseFormApi
|
|
|
|
|
+ .getState()
|
|
|
|
|
+ ?.schema?.filter(
|
|
|
|
|
+ (item) =>
|
|
|
|
|
+ item.fieldName !== 'invoiceAttachments' &&
|
|
|
|
|
+ item.fieldName !== 'certificateAttachments',
|
|
|
|
|
+ ),
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- baseFormApi.setValues(detailData);
|
|
|
|
|
- } catch {
|
|
|
|
|
- // console.log(error);
|
|
|
|
|
|
|
+ const filePrefix = await getFilePrefix();
|
|
|
|
|
+ const results = await Promise.allSettled([
|
|
|
|
|
+ getOrderDetail(data.value.row.ordersid, baseFormApi),
|
|
|
|
|
+ getOrderInvoice(data.value.row.ordersid, filePrefix),
|
|
|
|
|
+ getOrderCertificate(data.value.row.ordersid, filePrefix),
|
|
|
|
|
+ ]);
|
|
|
|
|
+
|
|
|
|
|
+ // 更新schema
|
|
|
|
|
+ const schema = baseFormApi.getState()?.schema ?? [];
|
|
|
|
|
+
|
|
|
|
|
+ // 检查schema中是否已存在invoiceAttachments字段
|
|
|
|
|
+ const hasInvoiceAttachments = schema.some(
|
|
|
|
|
+ (item) => item.fieldName === 'invoiceAttachments',
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
|
|
+ // 如果不存在,则添加发票附件字段
|
|
|
|
|
+ if (!hasInvoiceAttachments && invoiceDataList.value.length > 0) {
|
|
|
|
|
+ baseFormApi.setState({
|
|
|
|
|
+ schema: [
|
|
|
|
|
+ ...schema,
|
|
|
|
|
+ {
|
|
|
|
|
+ component: h(
|
|
|
|
|
+ 'div',
|
|
|
|
|
+ { class: 'grid-cols-1 lg:grid-cols-2 flex flex-wrap gap-3' },
|
|
|
|
|
+ invoiceDataList.value.map((item) => {
|
|
|
|
|
+ return h(ElImage, {
|
|
|
|
|
+ src: item.url,
|
|
|
|
|
+ previewSrcList: invoiceDataList.value.map((i) => i.url),
|
|
|
|
|
+ fit: 'cover',
|
|
|
|
|
+ style: 'width: 100px; height: 100px;',
|
|
|
|
|
+ class: 'border rounded',
|
|
|
|
|
+ previewTeleported: true,
|
|
|
|
|
+ });
|
|
|
|
|
+ }),
|
|
|
|
|
+ ),
|
|
|
|
|
+ fieldName: 'invoiceAttachments',
|
|
|
|
|
+ label: '发票附件',
|
|
|
|
|
+ // formItemClass: 'lg:col-span-2',
|
|
|
|
|
+ },
|
|
|
|
|
+ ],
|
|
|
|
|
+ });
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // 设置空数据提示
|
|
|
|
|
+ baseFormApi.setState({
|
|
|
|
|
+ schema: [
|
|
|
|
|
+ ...schema,
|
|
|
|
|
+ {
|
|
|
|
|
+ component: h(
|
|
|
|
|
+ 'div',
|
|
|
|
|
+ {
|
|
|
|
|
+ class:
|
|
|
|
|
+ 'grid-cols-1 lg:grid-cols-2 flex flex-wrap gap-3 text-sm',
|
|
|
|
|
+ },
|
|
|
|
|
+ '暂无',
|
|
|
|
|
+ ),
|
|
|
|
|
+ fieldName: 'invoiceAttachments',
|
|
|
|
|
+ label: '发票附件',
|
|
|
|
|
+ // formItemClass: 'lg:col-span-2',
|
|
|
|
|
+ },
|
|
|
|
|
+ ],
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 检查schema中是否已存在certificateAttachments字段
|
|
|
|
|
+ const hasCertificateAttachments = schema.some(
|
|
|
|
|
+ (item) => item.fieldName === 'certificateAttachments',
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
|
|
+ // 如果不存在,则添加证书附件字段
|
|
|
|
|
+ if (
|
|
|
|
|
+ !hasCertificateAttachments &&
|
|
|
|
|
+ certificateDataList.value.length > 0
|
|
|
|
|
+ ) {
|
|
|
|
|
+ baseFormApi.setState({
|
|
|
|
|
+ schema: [
|
|
|
|
|
+ ...(baseFormApi.getState()?.schema ?? []),
|
|
|
|
|
+ {
|
|
|
|
|
+ component: h(
|
|
|
|
|
+ 'div',
|
|
|
|
|
+ { class: 'grid-cols-1 lg:grid-cols-2 flex flex-wrap gap-3' },
|
|
|
|
|
+ certificateDataList.value.map((item) => {
|
|
|
|
|
+ return h(ElImage, {
|
|
|
|
|
+ src: item.url,
|
|
|
|
|
+ previewSrcList: certificateDataList.value.map(
|
|
|
|
|
+ (i) => i.url,
|
|
|
|
|
+ ),
|
|
|
|
|
+ fit: 'cover',
|
|
|
|
|
+ style: 'width: 100px; height: 100px;',
|
|
|
|
|
+ class: 'border rounded',
|
|
|
|
|
+ previewTeleported: true,
|
|
|
|
|
+ });
|
|
|
|
|
+ }),
|
|
|
|
|
+ ),
|
|
|
|
|
+ fieldName: 'certificateAttachments',
|
|
|
|
|
+ label: '证书附件',
|
|
|
|
|
+ // formItemClass: 'lg:col-span-2',
|
|
|
|
|
+ },
|
|
|
|
|
+ ],
|
|
|
|
|
+ });
|
|
|
|
|
+ } else {
|
|
|
|
|
+ baseFormApi.setState({
|
|
|
|
|
+ schema: [
|
|
|
|
|
+ ...(baseFormApi.getState()?.schema ?? []),
|
|
|
|
|
+ {
|
|
|
|
|
+ component: h(
|
|
|
|
|
+ 'div',
|
|
|
|
|
+ {
|
|
|
|
|
+ class:
|
|
|
|
|
+ 'grid-cols-1 lg:grid-cols-2 flex flex-wrap gap-3 text-sm',
|
|
|
|
|
+ },
|
|
|
|
|
+ '暂无',
|
|
|
|
|
+ ),
|
|
|
|
|
+ fieldName: 'certificateAttachments',
|
|
|
|
|
+ label: '证书附件',
|
|
|
|
|
+ // formItemClass: 'lg:col-span-2',
|
|
|
|
|
+ },
|
|
|
|
|
+ ],
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 可以选择处理失败的请求
|
|
|
|
|
+ results.forEach((result, index) => {
|
|
|
|
|
+ if (result.status === 'rejected') {
|
|
|
|
|
+ console.warn(`请求 ${index} 失败:`, result.reason);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ } catch (error) {
|
|
|
|
|
+ console.error(error);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
modalApi.setState({ loading: false });
|
|
modalApi.setState({ loading: false });
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
});
|
|
});
|
|
|
|
|
+
|
|
|
|
|
+// 获取订单详情
|
|
|
|
|
+const getOrderDetail = async (ordersid: string, formApi: ExtendedFormApi) => {
|
|
|
|
|
+ const detailData = await getOrdersDetailApi({
|
|
|
|
|
+ ordersid,
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ formApi.setValues(detailData);
|
|
|
|
|
+};
|
|
|
|
|
+
|
|
|
|
|
+// 获取订单发票附件
|
|
|
|
|
+const getOrderInvoice = async (ordersid: string, filePrefix: string) => {
|
|
|
|
|
+ const invoiceData = await getAttachmentListApi({
|
|
|
|
|
+ attlsh: ordersid,
|
|
|
|
|
+ attmodel: 'orders_invoice',
|
|
|
|
|
+ pageindex: 1,
|
|
|
|
|
+ rows: 10,
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ if (invoiceData.Data.length > 0) {
|
|
|
|
|
+ invoiceData.Data.forEach((item: any) => {
|
|
|
|
|
+ item.url = `${filePrefix}${item.attpath}${item.attname}.${item.atttype}`;
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ invoiceDataList.value = invoiceData.Data;
|
|
|
|
|
+};
|
|
|
|
|
+
|
|
|
|
|
+// 获取订单证件附件
|
|
|
|
|
+const getOrderCertificate = async (ordersid: string, filePrefix: string) => {
|
|
|
|
|
+ const certificateData = await getAttachmentListApi({
|
|
|
|
|
+ attlsh: ordersid,
|
|
|
|
|
+ attmodel: 'orders_identity',
|
|
|
|
|
+ pageindex: 1,
|
|
|
|
|
+ rows: 10,
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ if (certificateData.Data.length > 0) {
|
|
|
|
|
+ certificateData.Data.forEach((item: any) => {
|
|
|
|
|
+ item.url = `${filePrefix}${item.attpath}${item.attname}.${item.atttype}`;
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ certificateDataList.value = certificateData.Data;
|
|
|
|
|
+};
|
|
|
|
|
+
|
|
|
|
|
+// 获取文件前缀地址
|
|
|
|
|
+const getFilePrefix = async () => {
|
|
|
|
|
+ const filePrefixData = await getDictListApi({
|
|
|
|
|
+ groupname: 'fileheadurl',
|
|
|
|
|
+ pageindex: 1,
|
|
|
|
|
+ rows: 999,
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ if (filePrefixData.Data.length > 0) {
|
|
|
|
|
+ return filePrefixData.Data[0].substance;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return '';
|
|
|
|
|
+};
|
|
|
</script>
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
|
<template>
|