feat: 工单服务数据回显

This commit is contained in:
duanshuwen
2025-11-13 18:40:15 +08:00
parent 9749e20971
commit 48932e3851
2 changed files with 64 additions and 10 deletions

View File

@@ -27,7 +27,11 @@
class="bg-F5F7FA border-box flex flex-items-center p-12 rounded-10 font-size-14 color-171717 mb-12" class="bg-F5F7FA border-box flex flex-items-center p-12 rounded-10 font-size-14 color-171717 mb-12"
> >
<text class="font-500 line-height-22 mr-20">联系电话</text> <text class="font-500 line-height-22 mr-20">联系电话</text>
<input placeholder="请填写联系电话" v-model="contactPhone" /> <input
placeholder="请填写联系电话"
v-model="contactPhone"
@input="handleContactPhoneInput"
/>
</view> </view>
<view <view
@@ -115,19 +119,57 @@
</template> </template>
<script setup> <script setup>
import { ref, onMounted, nextTick } from "vue"; import { ref, computed, onMounted, nextTick, defineProps, watch } from "vue";
import { SCROLL_TO_BOTTOM } from "@/constant/constant"; import { SCROLL_TO_BOTTOM } from "@/constant/constant";
import { createWorkOrder } from "@/request/api/WorkOrderApi"; import { createWorkOrder } from "@/request/api/WorkOrderApi";
import { updateImageFile } from "@/request/api/UpdateFile"; import { updateImageFile } from "@/request/api/UpdateFile";
import { zniconsMap } from "@/static/fonts/znicons.js"; import { zniconsMap } from "@/static/fonts/znicons.js";
const props = defineProps({
toolCall: {
type: Object,
default: () => ({}),
},
});
const workOrderTypeId = ref(""); const workOrderTypeId = ref("");
const roomId = ref(""); const roomId = ref("");
const contactPhone = ref("");
const contactText = ref("");
const contentImgUrl = ref(""); const contentImgUrl = ref("");
const isCallSuccess = ref(false); // 呼叫成功状态 const isCallSuccess = ref(false); // 呼叫成功状态
const workOrderId = ref(0); // 工单ID const workOrderId = ref(0); // 工单ID
const toolResult = computed(() => {
if (props.toolCall?.toolResult) {
return JSON.parse(props.toolCall?.toolResult);
} else {
return {};
}
});
// 原始手机号(未脱敏)
const originalPhone = ref("");
// 展示与输入绑定的手机号(初始为脱敏)
const contactPhone = ref("");
// 是否用户已编辑过手机号(一旦编辑则不再脱敏)
const hasEditedPhone = ref(false);
// 手机号脱敏138****1234仅对11位数字进行处理
const maskPhone = (phone) => {
if (!phone) return "";
return String(phone).replace(/(\d{3})\d{4}(\d{4})/, "$1****$2");
};
// 监听工具返回结果,初始化原始与脱敏显示
watch(
toolResult,
(val) => {
originalPhone.value = val?.userPhone || "";
hasEditedPhone.value = false;
contactPhone.value = maskPhone(originalPhone.value);
},
{ immediate: true }
);
const contactText = computed({
get: () => toolResult.value?.callServiceContent || "",
set: (val) => (contactText.value = val),
});
// 处理图片上传 // 处理图片上传
const handleChooseImage = () => { const handleChooseImage = () => {
@@ -143,6 +185,11 @@ const handleChooseImage = () => {
}); });
}; };
// 标记用户已编辑手机号
const handleContactPhoneInput = () => {
hasEditedPhone.value = true;
};
const handleDeleteImage = () => { const handleDeleteImage = () => {
contentImgUrl.value = ""; contentImgUrl.value = "";
}; };
@@ -168,7 +215,10 @@ const handleCall = async () => {
return; return;
} }
if (!contactPhone.value.trim()) { const phoneToSubmit = hasEditedPhone.value
? contactPhone.value
: originalPhone.value;
if (!phoneToSubmit.trim()) {
uni.showToast({ title: "请填写联系电话", icon: "none" }); uni.showToast({ title: "请填写联系电话", icon: "none" });
return; return;
} }
@@ -178,19 +228,22 @@ const handleCall = async () => {
return; return;
} }
sendCreateWorkOrder(); sendCreateWorkOrder(phoneToSubmit);
}; };
/// 创建工单 /// 创建工单
const sendCreateWorkOrder = async () => { const sendCreateWorkOrder = async (phoneToSubmit) => {
try { try {
const res = await createWorkOrder({ const params = {
workOrderTypeId: workOrderTypeId.value, workOrderTypeId: workOrderTypeId.value,
roomNo: roomId.value, roomNo: roomId.value,
userPhone: contactPhone.value, userPhone: phoneToSubmit,
content: contactText.value, content: contactText.value,
contentImgUrl: contentImgUrl.value, contentImgUrl: contentImgUrl.value,
}); };
console.log("🚀 ~ sendCreateWorkOrder ~ params:", params);
const res = await createWorkOrder(params);
if (res.code === 0) { if (res.code === 0) {
// 保存工单ID // 保存工单ID

View File

@@ -46,6 +46,7 @@
v-else-if=" v-else-if="
item.toolCall.componentName === CompName.callServiceCard item.toolCall.componentName === CompName.callServiceCard
" "
:toolCall="item.toolCall"
/> />
<Feedback <Feedback
v-else-if=" v-else-if="