From 8850c6df45d9db593652e43617820e07c114e027 Mon Sep 17 00:00:00 2001 From: lh Date: Mon, 5 Jan 2026 09:34:16 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=9C=BA=E7=A5=A8=E9=A2=84?= =?UTF-8?q?=E8=AE=A2=E7=95=8C=E9=9D=A2=EF=BC=8C=E5=AE=9E=E7=8E=B0=E6=9C=BA?= =?UTF-8?q?=E7=A5=A8=E9=A2=84=E8=AE=A2=E6=B5=81=E7=A8=8B=E7=94=B3=E8=AF=B7?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=EF=BC=8C=E4=BC=98=E5=8C=96=E6=9C=BA=E7=A5=A8?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E3=80=81=E5=AF=BC=E5=87=BA=E9=80=BB=E8=BE=91?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/oa/crm/flightBooking/edit.vue | 158 ++++++++++++++++++----- src/views/oa/crm/flightBooking/index.vue | 12 +- 2 files changed, 130 insertions(+), 40 deletions(-) diff --git a/src/views/oa/crm/flightBooking/edit.vue b/src/views/oa/crm/flightBooking/edit.vue index c9204d4..574daa5 100644 --- a/src/views/oa/crm/flightBooking/edit.vue +++ b/src/views/oa/crm/flightBooking/edit.vue @@ -14,11 +14,11 @@ /> - + - + @@ -37,7 +37,7 @@ - + @@ -113,7 +113,7 @@ import { getUserList } from '@/api/system/user'; import { CodeRuleEnum, FlowCodeEnum } from '@/enums/OAEnum'; import { getInfo } from '@/api/login'; import FileUpload from '@/components/FileUpload/index.vue'; -import { getFlightBooking, delFlightBooking, addFlightBooking, updateFlightBooking, submitAndFlowStart } from '@/api/oa/crm/flightBooking'; +import { getFlightBooking, addFlightBooking, updateFlightBooking, submitAndFlowStart } from '@/api/oa/crm/flightBooking'; import { FlightBookingVO, FlightBookingQuery, FlightBookingForm } from '@/api/oa/crm/flightBooking/types'; const { proxy } = getCurrentInstance() as ComponentInternalInstance; @@ -144,13 +144,94 @@ const flowInstanceBizExtBo = ref>({}); const type = ref(0); +// 添加自定义验证函数 +const validateAmount = (rule: any, value: any, callback: any) => { + if (!value) { + callback(new Error('机票金额不能为空')); + return; + } + + // 检查是否为数字(包括整数、小数、负数) + const numValue = Number(value); + if (isNaN(numValue)) { + callback(new Error('请输入有效的数字')); + return; + } + + // 检查是否为负数(如果需要) + if (numValue < 0) { + callback(new Error('机票金额不能为负数')); + return; + } + + // 检查小数位数(最多2位小数) + const strValue = String(value); + const decimalPart = strValue.split('.')[1]; + if (decimalPart && decimalPart.length > 2) { + callback(new Error('最多支持两位小数')); + return; + } + + callback(); +}; + // 机票编号生成状态 const isCodeGenerated = ref(false); /** 查询用户信息下拉框结构 */ const userInfoList = ref([]); +// 存储当前登录用户信息 +const currentUser = ref(null); + +// 获取当前登录用户信息 +const getCurrentUserInfo = async () => { + try { + const userInfo = await getInfo(); + currentUser.value = userInfo.data.user; + return currentUser.value; + } catch (error) { + console.error('获取当前登录用户信息失败:', error); + return null; + } +}; + +// 查询所有用户列表 const getUserInfoListSelect = async () => { - const res = await getUserList({ pageNum: 1, pageSize: 1000 }); - userInfoList.value = res.data; + try { + const res = await getUserList({ pageNum: 1, pageSize: 1000 }); + userInfoList.value = res.data; + // 将当前用户添加到用户列表中(如果不在列表中) + if (currentUser.value && currentUser.value.userId) { + const userExists = userInfoList.value.some((user: any) => user.userId === currentUser.value.userId); + if (!userExists) { + // 将当前用户添加到列表开头 + userInfoList.value.unshift({ + userId: currentUser.value.userId, + nickName: currentUser.value.nickName + // 可以添加其他需要的字段 + }); + } + } + } catch (error) { + proxy?.$modal.msgError('获取用户列表失败'); + } +}; + +// 初始化用户数据(获取当前用户并查询用户列表) +const initUserData = async () => { + // 1. 先获取当前登录用户 + await getCurrentUserInfo(); + // 2. 再查询所有用户列表 + await getUserInfoListSelect(); + // 3. 如果是新增模式,设置当前用户为默认乘机人 + const id = routeParams.value.id as string | number; + if (!id && routeParams.value.type !== 'update' && routeParams.value.type !== 'view' && routeParams.value.type !== 'approval') { + // 新增模式,设置当前用户为默认乘机人 + if (currentUser.value && currentUser.value.userId) { + form.value.passengerId = currentUser.value.userId; + form.value.passengerName = currentUser.value.nickName; + console.log('已设置当前登录用户为默认乘机人:', currentUser.value.nickName); + } + } }; // 判断表单是否禁用(查看或审批模式) @@ -209,14 +290,17 @@ const data = reactive>({ departureLocation: [{ required: true, message: '出发地点不能为空', trigger: 'blur' }], arrivalLocation: [{ required: true, message: '到达地点不能为空', trigger: 'blur' }], flightDiscount: [{ required: true, message: '机票折扣不能为空', trigger: 'blur' }], - flightAmount: [{ required: true, message: '机票金额不能为空', trigger: 'blur' }] + flightAmount: [ + { required: true, message: '机票金额不能为空', trigger: 'blur' }, + { validator: validateAmount, trigger: ['blur', 'change'] } // 添加自定义验证 + ] } }); const { queryParams, form, rules } = toRefs(data); const flightBookingFormRef = ref(); -// 生成合同编号 +// 生成机票编号 const generateContractCode = async () => { if (isCodeGenerated.value) return; // 如果已经生成过,直接返回 try { @@ -240,19 +324,15 @@ watch( // 自动设置 passengerName form.value.passengerName = selectedUser.nickName; } - } else { - // 如果 passengerId 为空,清空 passengerName - form.value.passengerName = ''; } }, { immediate: true } // 立即执行一次,用于编辑模式的数据回显 ); -/** 提交按钮 */ const submitForm = (status: string, mode: boolean) => { - try { - buttonLoading.value = true; - flightBookingFormRef.value?.validate(async (valid: boolean) => { - if (valid) { + buttonLoading.value = true; + flightBookingFormRef.value?.validate(async (valid: boolean) => { + if (valid) { + try { // 设置后端发起和不等于草稿状态 直接走流程发起 if (status != 'draft') { // 后端发起流程模式 @@ -268,7 +348,7 @@ const submitForm = (status: string, mode: boolean) => { }; form.value.flowStatus = 'waiting'; form.value.bookingStatus = '2'; - const res = await submitAndFlowStart(form.value).finally(() => (buttonLoading.value = false)); + const res = await submitAndFlowStart(form.value); form.value = res.data; proxy?.$modal.msgSuccess('操作成功'); proxy?.$tab.closePage(); @@ -278,33 +358,40 @@ const submitForm = (status: string, mode: boolean) => { form.value.bookingStatus = '1'; if (form.value.bookingId) { - await updateFlightBooking(form.value).finally(() => (buttonLoading.value = false)); + await updateFlightBooking(form.value); } else { - await addFlightBooking(form.value).finally(() => (buttonLoading.value = false)); + await addFlightBooking(form.value); } proxy?.$modal.msgSuccess('暂存成功'); proxy?.$tab.closePage(); router.go(-1); } + } catch (error) { + // 错误处理 + console.error('提交失败:', error); + proxy?.$modal.msgError('操作失败'); + } finally { + // 只在验证通过且有请求操作时才设置加载状态为 false + buttonLoading.value = false; } - }); - } finally { - buttonLoading.value = false; - } + } else { + // 验证不通过时,立即恢复按钮状态 + buttonLoading.value = false; + proxy?.$modal.msgWarning('s请检查表单填写是否正确'); + } + }); }; - onMounted(async () => { nextTick(async () => { - // 获取路由参数 - getUserInfoListSelect(); + // 初始化用户数据(获取当前用户和用户列表) + proxy?.$modal.loading('正在加载数据,请稍后...'); + await initUserData(); routeParams.value = route.query; const id = routeParams.value.id as string | number; if (id && (routeParams.value.type === 'update' || routeParams.value.type === 'view' || routeParams.value.type === 'approval')) { - proxy?.$modal.loading('正在加载数据,请稍后...'); const res = await getFlightBooking(id); Object.assign(form.value, res.data); - proxy?.$modal.closeLoading(); // 编辑模式:如果已有合同编号,禁用生成按钮 if (form.value.applyCode) { @@ -323,13 +410,14 @@ onMounted(async () => { // } catch (error) { // console.error('获取用户信息失败:', error); // } - // // 新增模式:如果已有合同编号,禁用生成按钮 - // if (form.value.contractCode) { - // isCodeGenerated.value = true;`` - // } else if (form.value.contractFlag === '1') { - // // 如果有合同但没有编号,允许生成 - // isCodeGenerated.value = false; - // } + // 新增模式:如果已有机票编号,禁用生成按钮 + if (form.value.applyCode) { + isCodeGenerated.value = true; + } else { + // 如果有合同但没有编号,允许生成 + isCodeGenerated.value = false; + } + proxy?.$modal.closeLoading(); } }); }); diff --git a/src/views/oa/crm/flightBooking/index.vue b/src/views/oa/crm/flightBooking/index.vue index 04e4eec..61169fa 100644 --- a/src/views/oa/crm/flightBooking/index.vue +++ b/src/views/oa/crm/flightBooking/index.vue @@ -97,6 +97,8 @@ + +