|
@@ -2,34 +2,26 @@
|
|
|
import type { ExtendedFormApi } from '@vben/common-ui';
|
|
import type { ExtendedFormApi } from '@vben/common-ui';
|
|
|
import type { OrdersEntity } from '@vben/types';
|
|
import type { OrdersEntity } from '@vben/types';
|
|
|
|
|
|
|
|
-import { computed, h, ref } from 'vue';
|
|
|
|
|
|
|
+import { computed, ref } from 'vue';
|
|
|
|
|
|
|
|
import { useVbenModal } from '@vben/common-ui';
|
|
import { useVbenModal } from '@vben/common-ui';
|
|
|
|
|
|
|
|
-import { ElImage, ElMessage } from 'element-plus';
|
|
|
|
|
|
|
+import { 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']);
|
|
|
const data = ref();
|
|
const data = ref();
|
|
|
-const formType = ref<'create' | 'detail' | 'edit'>('create');
|
|
|
|
|
|
|
+const formType = ref<'create' | 'edit'>('create');
|
|
|
|
|
|
|
|
const titleMap = {
|
|
const titleMap = {
|
|
|
create: '新增订单',
|
|
create: '新增订单',
|
|
|
- detail: '订单详情',
|
|
|
|
|
edit: '编辑订单',
|
|
edit: '编辑订单',
|
|
|
} as const;
|
|
} as const;
|
|
|
|
|
|
|
|
const getTitle = computed(() => titleMap[formType.value]);
|
|
const getTitle = computed(() => titleMap[formType.value]);
|
|
|
|
|
|
|
|
-const invoiceDataList = ref<any[]>([{}]);
|
|
|
|
|
-const certificateDataList = ref<any[]>([]);
|
|
|
|
|
-const buyerPhotoDataList = ref<any[]>([]);
|
|
|
|
|
-const coupon2sid = ref(''); // 优惠券id
|
|
|
|
|
-
|
|
|
|
|
const [BaseForm, baseFormApi] = useVbenForm({
|
|
const [BaseForm, baseFormApi] = useVbenForm({
|
|
|
showDefaultActions: false,
|
|
showDefaultActions: false,
|
|
|
// 所有表单项共用,可单独在表单内覆盖
|
|
// 所有表单项共用,可单独在表单内覆盖
|
|
@@ -42,16 +34,6 @@ const [BaseForm, baseFormApi] = useVbenForm({
|
|
|
},
|
|
},
|
|
|
wrapperClass: 'grid-cols-1 lg:grid-cols-2',
|
|
wrapperClass: 'grid-cols-1 lg:grid-cols-2',
|
|
|
schema: [
|
|
schema: [
|
|
|
- // { title: '订单号', field: 'ordersnumber' },
|
|
|
|
|
- // { title: '订单关联用户id', field: 'ordersuserid' },
|
|
|
|
|
- // { title: '订单关联产品id', field: 'ordersproductid' },
|
|
|
|
|
- // { title: '产品名称', field: 'ordersproductname' },
|
|
|
|
|
- // { title: '产品sn', field: 'ordersproductsn' },
|
|
|
|
|
- // { title: '订单总金额', field: 'orderstotalprice' },
|
|
|
|
|
- // { title: '订单优惠后金额', field: 'ordersdiscountprice' },
|
|
|
|
|
- // { title: '优惠金额', field: 'ordersyhprice' },
|
|
|
|
|
- // { title: '优惠卷id', field: 'orderscouponid' },
|
|
|
|
|
- // { title: '订单状态', field: 'ordersorderstatus' },
|
|
|
|
|
{
|
|
{
|
|
|
component: 'Input',
|
|
component: 'Input',
|
|
|
fieldName: 'ordersnumber',
|
|
fieldName: 'ordersnumber',
|
|
@@ -202,11 +184,6 @@ const [Modal, modalApi] = useVbenModal({
|
|
|
} as any),
|
|
} as any),
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
- if (formType.value === 'detail') {
|
|
|
|
|
- modalApi.close();
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
await apiMap[formType.value]();
|
|
await apiMap[formType.value]();
|
|
|
ElMessage.success('操作成功');
|
|
ElMessage.success('操作成功');
|
|
|
|
|
|
|
@@ -217,272 +194,20 @@ const [Modal, modalApi] = useVbenModal({
|
|
|
async onOpenChange(isOpen) {
|
|
async onOpenChange(isOpen) {
|
|
|
if (isOpen) {
|
|
if (isOpen) {
|
|
|
data.value = modalApi.getData();
|
|
data.value = modalApi.getData();
|
|
|
-
|
|
|
|
|
formType.value = data.value.formType;
|
|
formType.value = data.value.formType;
|
|
|
|
|
|
|
|
- baseFormApi.setState({
|
|
|
|
|
- commonConfig: { disabled: formType.value === 'detail' },
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
if (data.value.formType === 'create') {
|
|
if (data.value.formType === 'create') {
|
|
|
|
|
+ // 新增模式,重置表单
|
|
|
|
|
+ baseFormApi.resetForm();
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ // 编辑模式,加载订单详情
|
|
|
try {
|
|
try {
|
|
|
modalApi.setState({ loading: true });
|
|
modalApi.setState({ loading: true });
|
|
|
-
|
|
|
|
|
- invoiceDataList.value = [];
|
|
|
|
|
- certificateDataList.value = [];
|
|
|
|
|
- buyerPhotoDataList.value = [];
|
|
|
|
|
-
|
|
|
|
|
- // 去掉schema中invoiceAttachments和certificateAttachments字段,避免页面不更新
|
|
|
|
|
- baseFormApi.setState({
|
|
|
|
|
- schema: baseFormApi
|
|
|
|
|
- .getState()
|
|
|
|
|
- ?.schema?.filter(
|
|
|
|
|
- (item) =>
|
|
|
|
|
- item.fieldName !== 'invoiceAttachments' &&
|
|
|
|
|
- item.fieldName !== 'certificateAttachments' &&
|
|
|
|
|
- item.fieldName !== 'buyerPhotoAttachments',
|
|
|
|
|
- ),
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- const filePrefix = await getFilePrefix();
|
|
|
|
|
-
|
|
|
|
|
- // 先执行获取订单详情
|
|
|
|
|
await getOrderDetail(data.value.row.ordersid, baseFormApi);
|
|
await getOrderDetail(data.value.row.ordersid, baseFormApi);
|
|
|
-
|
|
|
|
|
- // 订单详情获取完成后,再并行执行剩余3个函数
|
|
|
|
|
- const results = await Promise.allSettled([
|
|
|
|
|
- getOrderInvoice(data.value.row.ordersid, filePrefix),
|
|
|
|
|
- getOrderCertificate(coupon2sid.value, filePrefix),
|
|
|
|
|
- getOrderBuyerPhoto(coupon2sid.value, filePrefix),
|
|
|
|
|
- ]);
|
|
|
|
|
-
|
|
|
|
|
- // 更新schema
|
|
|
|
|
- const schema = baseFormApi.getState()?.schema ?? [];
|
|
|
|
|
-
|
|
|
|
|
- // 检查schema中是否已存在invoiceAttachments字段
|
|
|
|
|
- const hasInvoiceAttachments = schema.some(
|
|
|
|
|
- (item) => item.fieldName === 'invoiceAttachments',
|
|
|
|
|
- );
|
|
|
|
|
-
|
|
|
|
|
- // 检查schema中是否已存在certificateAttachments字段
|
|
|
|
|
- const hasCertificateAttachments = schema.some(
|
|
|
|
|
- (item) => item.fieldName === 'certificateAttachments',
|
|
|
|
|
- );
|
|
|
|
|
-
|
|
|
|
|
- // 检查schema中是否已存在buyerPhotoAttachments字段
|
|
|
|
|
- const hasBuyerPhotoAttachments = schema.some(
|
|
|
|
|
- (item) => item.fieldName === 'buyerPhotoAttachments',
|
|
|
|
|
- );
|
|
|
|
|
-
|
|
|
|
|
- // 首先添加购机者照片
|
|
|
|
|
- // 如果不存在,则添加购买人自拍附件字段
|
|
|
|
|
- if (!hasBuyerPhotoAttachments && buyerPhotoDataList.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' },
|
|
|
|
|
- buyerPhotoDataList.value.map((item) => {
|
|
|
|
|
- return h(ElImage, {
|
|
|
|
|
- src: item.url,
|
|
|
|
|
- previewSrcList: buyerPhotoDataList.value.map(
|
|
|
|
|
- (i) => i.url,
|
|
|
|
|
- ),
|
|
|
|
|
- fit: 'cover',
|
|
|
|
|
- style: 'width: 100px; height: 100px;',
|
|
|
|
|
- class: 'border rounded',
|
|
|
|
|
- previewTeleported: true,
|
|
|
|
|
- });
|
|
|
|
|
- }),
|
|
|
|
|
- ),
|
|
|
|
|
- fieldName: 'buyerPhotoAttachments',
|
|
|
|
|
- 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: 'buyerPhotoAttachments',
|
|
|
|
|
- label: '购机者照片',
|
|
|
|
|
- // formItemClass: 'lg:col-span-2',
|
|
|
|
|
- },
|
|
|
|
|
- ],
|
|
|
|
|
- });
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // 然后添加证件附件
|
|
|
|
|
- // 如果不存在,则添加证件附件字段
|
|
|
|
|
- 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',
|
|
|
|
|
- },
|
|
|
|
|
- ],
|
|
|
|
|
- });
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // 最后添加发票附件展示
|
|
|
|
|
- // 如果不存在,则添加发票附件字段
|
|
|
|
|
- if (!hasInvoiceAttachments) {
|
|
|
|
|
- baseFormApi.setState({
|
|
|
|
|
- schema: [
|
|
|
|
|
- ...(baseFormApi.getState()?.schema ?? []),
|
|
|
|
|
- {
|
|
|
|
|
- component: h(
|
|
|
|
|
- 'div',
|
|
|
|
|
- { class: 'flex flex-wrap gap-3' },
|
|
|
|
|
- invoiceDataList.value.length > 0
|
|
|
|
|
- ? invoiceDataList.value.map((item) => {
|
|
|
|
|
- // 判断文件类型,根据atttype进行不同展示
|
|
|
|
|
- if (item.atttype === 'pdf') {
|
|
|
|
|
- // PDF文件显示为链接
|
|
|
|
|
- return h(
|
|
|
|
|
- 'a',
|
|
|
|
|
- {
|
|
|
|
|
- href: item.url,
|
|
|
|
|
- target: '_blank',
|
|
|
|
|
- class:
|
|
|
|
|
- 'inline-flex items-center px-3 py-2 text-sm font-medium text-blue-600 bg-blue-50 border border-blue-200 rounded-lg hover:bg-blue-100 hover:text-blue-700 transition-colors',
|
|
|
|
|
- title: item.attorginname || item.attname,
|
|
|
|
|
- },
|
|
|
|
|
- [
|
|
|
|
|
- h('i', {
|
|
|
|
|
- class: 'fas fa-file-pdf mr-2 text-red-500',
|
|
|
|
|
- }),
|
|
|
|
|
- item.attorginname ||
|
|
|
|
|
- `${item.attname}.${item.atttype}`,
|
|
|
|
|
- ],
|
|
|
|
|
- );
|
|
|
|
|
- } else {
|
|
|
|
|
- // 图片文件使用ElImage展示
|
|
|
|
|
- const imageExtensions = new Set([
|
|
|
|
|
- 'bmp',
|
|
|
|
|
- 'gif',
|
|
|
|
|
- 'jpeg',
|
|
|
|
|
- 'jpg',
|
|
|
|
|
- 'png',
|
|
|
|
|
- 'webp',
|
|
|
|
|
- ]);
|
|
|
|
|
- return imageExtensions.has(item.atttype.toLowerCase())
|
|
|
|
|
- ? h(ElImage, {
|
|
|
|
|
- src: item.url,
|
|
|
|
|
- previewSrcList: invoiceDataList.value
|
|
|
|
|
- .filter((i) =>
|
|
|
|
|
- imageExtensions.has(
|
|
|
|
|
- i.atttype.toLowerCase(),
|
|
|
|
|
- ),
|
|
|
|
|
- )
|
|
|
|
|
- .map((i) => i.url),
|
|
|
|
|
- fit: 'cover',
|
|
|
|
|
- style: 'width: 100px; height: 100px;',
|
|
|
|
|
- class: 'border rounded',
|
|
|
|
|
- previewTeleported: true,
|
|
|
|
|
- })
|
|
|
|
|
- : // 其他文件类型显示为普通链接
|
|
|
|
|
- h(
|
|
|
|
|
- 'a',
|
|
|
|
|
- {
|
|
|
|
|
- href: item.url,
|
|
|
|
|
- target: '_blank',
|
|
|
|
|
- class:
|
|
|
|
|
- 'inline-flex items-center px-3 py-2 text-sm font-medium text-gray-600 bg-gray-50 border border-gray-200 rounded-lg hover:bg-gray-100 hover:text-gray-700 transition-colors',
|
|
|
|
|
- title: item.attorginname || item.attname,
|
|
|
|
|
- },
|
|
|
|
|
- [
|
|
|
|
|
- h('i', {
|
|
|
|
|
- class: 'fas fa-file mr-2 text-gray-500',
|
|
|
|
|
- }),
|
|
|
|
|
- item.attorginname ||
|
|
|
|
|
- `${item.attname}.${item.atttype}`,
|
|
|
|
|
- ],
|
|
|
|
|
- );
|
|
|
|
|
- }
|
|
|
|
|
- })
|
|
|
|
|
- : [
|
|
|
|
|
- h(
|
|
|
|
|
- 'span',
|
|
|
|
|
- {
|
|
|
|
|
- class: 'text-sm text-gray-500',
|
|
|
|
|
- },
|
|
|
|
|
- '暂无发票附件',
|
|
|
|
|
- ),
|
|
|
|
|
- ],
|
|
|
|
|
- ),
|
|
|
|
|
- fieldName: 'invoiceAttachments',
|
|
|
|
|
- label: '发票附件',
|
|
|
|
|
- // formItemClass: 'lg:col-span-2',
|
|
|
|
|
- },
|
|
|
|
|
- ],
|
|
|
|
|
- });
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // 可以选择处理失败的请求
|
|
|
|
|
- results.forEach((result, index) => {
|
|
|
|
|
- if (result.status === 'rejected') {
|
|
|
|
|
- console.warn(`请求 ${index} 失败:`, result.reason);
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
} catch (error) {
|
|
} catch (error) {
|
|
|
- console.error(error);
|
|
|
|
|
|
|
+ console.error('加载订单详情失败:', error);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
modalApi.setState({ loading: false });
|
|
modalApi.setState({ loading: false });
|
|
@@ -497,77 +222,6 @@ const getOrderDetail = async (ordersid: string, formApi: ExtendedFormApi) => {
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
formApi.setValues(detailData);
|
|
formApi.setValues(detailData);
|
|
|
-
|
|
|
|
|
- coupon2sid.value = detailData.coupon2sid;
|
|
|
|
|
-};
|
|
|
|
|
-
|
|
|
|
|
-// 获取发票附件
|
|
|
|
|
-const getOrderInvoice = async (ordersid: string, filePrefix: string) => {
|
|
|
|
|
- const invoiceData = await getAttachmentListApi({
|
|
|
|
|
- attlsh: ordersid,
|
|
|
|
|
- attmodel: 'coupon_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 (coupon2sid: string, filePrefix: string) => {
|
|
|
|
|
- const certificateData = await getAttachmentListApi({
|
|
|
|
|
- attlsh: coupon2sid,
|
|
|
|
|
- attmodel: 'coupon_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 getOrderBuyerPhoto = async (coupon2sid: string, filePrefix: string) => {
|
|
|
|
|
- const buyerPhotoData = await getAttachmentListApi({
|
|
|
|
|
- attlsh: coupon2sid,
|
|
|
|
|
- attmodel: 'coupon_buyer',
|
|
|
|
|
- pageindex: 1,
|
|
|
|
|
- rows: 10,
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- if (buyerPhotoData.Data.length > 0) {
|
|
|
|
|
- buyerPhotoData.Data.forEach((item: any) => {
|
|
|
|
|
- item.url = `${filePrefix}${item.attpath}${item.attname}.${item.atttype}`;
|
|
|
|
|
- });
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- buyerPhotoDataList.value = buyerPhotoData.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>
|
|
|
|
|
|