Commit 81238a41 by 岑成威

fix: 修复bug

1 parent cb4805c3
Pipeline #208 for 81238a41 failed in 0 seconds
...@@ -86,6 +86,72 @@ export interface InspectionScoreVO { ...@@ -86,6 +86,72 @@ export interface InspectionScoreVO {
skeletonLevel?: null | string; skeletonLevel?: null | string;
} }
const SCORE_RATING_LEVELS = new Set(["A", "B", "C", "D"]);
/** 从 `getInspectionChildren(-1)` 响应中解析 `inspectionScoreVO` */
export function extractInspectionScoreVO(raw: InspectionChildrenData): InspectionScoreVO | null {
if (!raw || typeof raw !== "object") {
return null;
}
if (Array.isArray(raw)) {
for (const item of raw) {
if (!item || typeof item !== "object") continue;
const vo = (item as { inspectionScoreVO?: unknown }).inspectionScoreVO;
if (vo && typeof vo === "object") {
return vo as InspectionScoreVO;
}
}
return null;
}
const vo = raw.inspectionScoreVO;
if (!vo || typeof vo !== "object") {
return null;
}
return vo;
}
/** 与 ScoreForm.validate 必填项一致:评分已保存且可回显时视为已填完 */
export function isInspectionScoreVOFilled(vo: InspectionScoreVO | null | undefined): boolean {
if (!vo) return false;
const appearanceBasis = String(vo.exteriorComment ?? "").trim();
const frameRating = String(vo.skeletonLevel ?? "")
.trim()
.toUpperCase();
const frameBasis = String(vo.skeletonComment ?? "").trim();
const interiorRating = String(vo.interiorLevel ?? "")
.trim()
.toUpperCase();
const interiorBasis = String(vo.interiorComment ?? "").trim();
const overallRating = String(vo.overallComment ?? "").trim();
return (
appearanceBasis.length > 0 &&
SCORE_RATING_LEVELS.has(frameRating) &&
frameBasis.length > 0 &&
SCORE_RATING_LEVELS.has(interiorRating) &&
interiorBasis.length > 0 &&
overallRating.length > 0
);
}
function isCompletedFlagFieldDone(flag: unknown): boolean {
return flag === 1 || String(flag ?? "") === "1";
}
function isInspectionVoCompleted(vo: InspectionResultVO | undefined): boolean {
return vo?.completedFlag === 1 || String(vo?.completedFlag ?? "") === "1";
}
/** 检测评分大项是否已完成:root.completedFlag / inspectionResultVO / 已保存的 inspectionScoreVO */
export function resolveScoreModuleCompletedFlag(
scoreRoot: InspectionNode | undefined,
scoreVo: InspectionScoreVO | null | undefined
): 0 | 1 {
if (isCompletedFlagFieldDone(scoreRoot?.completedFlag)) return 1;
if (isInspectionVoCompleted(scoreRoot?.inspectionResultVO)) return 1;
if (isInspectionScoreVOFilled(scoreVo)) return 1;
return 0;
}
/** /**
* `getInspectionChildren` 响应: * `getInspectionChildren` 响应:
* - 普通节点:节点数组; * - 普通节点:节点数组;
...@@ -160,7 +226,7 @@ function isKeyedSelectInteractionType(interactionType: string | undefined): bool ...@@ -160,7 +226,7 @@ function isKeyedSelectInteractionType(interactionType: string | undefined): bool
} }
/** 将模板默认值如 `2-私户` 按首个 `-` 拆成 key / 展示文案 */ /** 将模板默认值如 `2-私户` 按首个 `-` 拆成 key / 展示文案 */
function parseKeyedSelectDefault(raw: string): { valueKey: string; valueText: string } { export function parseKeyedSelectDefault(raw: string): { valueKey: string; valueText: string } {
const i = raw.indexOf("-"); const i = raw.indexOf("-");
if (i === -1) { if (i === -1) {
return { valueKey: "", valueText: raw }; return { valueKey: "", valueText: raw };
...@@ -183,7 +249,7 @@ export function resolveInspectionNodeInitialValueTexts( ...@@ -183,7 +249,7 @@ export function resolveInspectionNodeInitialValueTexts(
): string[] { ): string[] {
if (!hasDefaultValueFlag(node)) return []; if (!hasDefaultValueFlag(node)) return [];
const type = node.defaultType; const type = Number(node.defaultType);
if (type === 1) { if (type === 1) {
return [node.defaultValue ?? ""]; return [node.defaultValue ?? ""];
} }
...@@ -206,6 +272,71 @@ export function resolveInspectionNodeInitialValueTexts( ...@@ -206,6 +272,71 @@ export function resolveInspectionNodeInitialValueTexts(
return []; return [];
} }
/** 从 options 字符串(如 `["5-国五"]`)中按 key 或文案反查选项 */
function resolveSelectKeyFromOptions(
options: string | undefined,
valueKey: string,
valueText: string
): { valueKey: string; valueText: string } {
if (valueKey || !valueText || !options) {
return { valueKey, valueText };
}
try {
const opts = JSON.parse(options) as string[];
for (const opt of opts) {
const parts = String(opt ?? "").split("-");
const k = parts[0] ?? "";
const t = parts[1] ?? "";
if (t === valueText || k === valueText || String(opt) === valueText) {
return { valueKey: k, valueText: t || valueText };
}
}
} catch {
/* ignore invalid options */
}
return { valueKey, valueText };
}
/**
* 叶子节点下拉/单选类控件的初始 valueKey / valueText(检测结果、apply 写入字段、resolvedInitialValue)
*/
export function getInspectionLeafSelectInitial(node: InspectionNode): {
value: string;
valueKey: string;
valueText: string;
} {
const empty = { value: "", valueKey: "", valueText: "" };
const list = node.inspectionResultVO?.inspectionValueList;
if (list?.length) {
const first = list[0];
let valueKey = String(first?.valueKey ?? "");
let valueText = String(first?.valueText ?? "");
({ valueKey, valueText } = resolveSelectKeyFromOptions(node.options, valueKey, valueText));
if (valueKey || valueText) {
return { value: valueKey, valueKey, valueText };
}
}
let valueKey = String(node.valueKey ?? node.value ?? "");
let valueText = String(node.valueText ?? "");
({ valueKey, valueText } = resolveSelectKeyFromOptions(node.options, valueKey, valueText));
if (valueKey || valueText) {
return { value: valueKey, valueKey, valueText };
}
const raw = node.resolvedInitialValue;
if (raw) {
let parsed = parseKeyedSelectDefault(String(raw));
({ valueKey, valueText } = resolveSelectKeyFromOptions(
node.options,
parsed.valueKey,
parsed.valueText
));
if (valueKey || valueText) {
return { value: valueKey, valueKey, valueText };
}
}
return empty;
}
function buildInspectionResultVOFromDefaults(node: InspectionNode, valueTexts: string[]): InspectionResultVO { function buildInspectionResultVOFromDefaults(node: InspectionNode, valueTexts: string[]): InspectionResultVO {
const keyed = isKeyedSelectInteractionType(node.interactionType); const keyed = isKeyedSelectInteractionType(node.interactionType);
const inspectionValueList: InspectionValueItem[] = valueTexts.map((raw, index) => { const inspectionValueList: InspectionValueItem[] = valueTexts.map((raw, index) => {
......
<script setup lang="ts"> <script setup lang="ts">
import type { CustomizeFormValidateResult } from "@/types/views/car-detail"; import type { CustomizeFormValidateResult } from "@/types/views/car-detail";
import type { InspectionNode, InspectionTemplateDefaultData } from "@api"; import {
getInspectionLeafSelectInitial,
type InspectionNode,
type InspectionTemplateDefaultData,
} from "@api";
import { ref, watch } from "vue"; import { ref, watch } from "vue";
...@@ -43,13 +47,42 @@ const rules = ref({}); ...@@ -43,13 +47,42 @@ const rules = ref({});
// 加载中 // 加载中
const pageLoading = ref(false); const pageLoading = ref(false);
watch(() => props.leafNodes, (nodes) => { const SELECT_INTERACTION_TYPES = new Set(["dropdown", "radio_button_select"]);
pageLoading.value = true;
columnsList.value = (nodes || []).map((item) => ({ function getValueText(item: InspectionNode) {
let valueText = "";
if (item?.inspectionResultVO) {
const inspectionValueList = item?.inspectionResultVO?.inspectionValueList || [];
if (inspectionValueList && inspectionValueList.length > 0) {
const inputList = ["text_input", "textarea_input", "number_input", "date_picker"];
if (inputList.includes(String(item.interactionType ?? ""))) {
valueText = inspectionValueList[0]?.valueText || "";
}
}
}
return valueText;
}
function mapLeafNodeToColumnRow(item: InspectionNode): InspectionColumnRow {
const row: InspectionColumnRow = {
...item, ...item,
resultStatus: item?.inspectionResultVO?.resultStatus == 3 ? true : false, resultStatus: item?.inspectionResultVO?.resultStatus == 3 ? true : false,
value: getValueText(item), value: "",
})) as InspectionColumnRow[]; };
if (SELECT_INTERACTION_TYPES.has(String(item.interactionType ?? ""))) {
const { value, valueKey, valueText } = getInspectionLeafSelectInitial(item);
row.value = value;
row.valueKey = valueKey;
row.valueText = valueText;
return row;
}
row.value = getValueText(item);
return row;
}
watch(() => props.leafNodes, (nodes) => {
pageLoading.value = true;
columnsList.value = (nodes || []).map((item) => mapLeafNodeToColumnRow(item)) as InspectionColumnRow[];
console.log('leafNodes', columnsList.value); console.log('leafNodes', columnsList.value);
...@@ -65,20 +98,6 @@ onMounted(() => { ...@@ -65,20 +98,6 @@ onMounted(() => {
}, 1200); }, 1200);
}); });
function getValueText(item: any) {
let valueText = "";
if (item?.inspectionResultVO) {
const inspectionValueList = item?.inspectionResultVO?.inspectionValueList || [];
if (inspectionValueList && inspectionValueList.length > 0) {
const inputList = ["text_input", "textarea_input", "number_input", "date_picker"];
if (inputList.includes(item.interactionType)) {
valueText = inspectionValueList[0].valueText || "";
}
}
}
return valueText;
}
// 提交数据 // 提交数据
function setSubmitData() { function setSubmitData() {
const returnData: { const returnData: {
...@@ -283,7 +302,7 @@ defineExpose({ ...@@ -283,7 +302,7 @@ defineExpose({
<van-form ref="customizeFormRef" :model="form" :rules="rules"> <van-form ref="customizeFormRef" :model="form" :rules="rules">
<div v-for="(item, index) in columnsList" :key="index" class="customizeList" :class="{ <div v-for="(item, index) in columnsList" :key="item.id ?? index" class="customizeList" :class="{
'border-bottom': (index < columnsList.length - 1 && item.interactionType != 'image_upload') || item.interactionType == 'textarea_input', 'border-bottom': (index < columnsList.length - 1 && item.interactionType != 'image_upload') || item.interactionType == 'textarea_input',
'customizeList50': setImgWidth(item) 'customizeList50': setImgWidth(item)
}"> }">
......
<script setup lang="ts"> <script setup lang="ts">
import { getInspectionLeafSelectInitial } from "@api";
import { computed, onMounted, ref } from "vue"; import { computed, onMounted, ref } from "vue";
const props = defineProps({ const props = defineProps({
...@@ -16,15 +17,9 @@ onMounted(() => { ...@@ -16,15 +17,9 @@ onMounted(() => {
initData(); initData();
}); });
// 初始化数据
function initData() { function initData() {
pickerValue.value = ""; const { valueKey } = getInspectionLeafSelectInitial(props.item);
if (props?.item?.inspectionResultVO) { pickerValue.value = valueKey;
const inspectionValueList = props?.item?.inspectionResultVO?.inspectionValueList || [];
if (inspectionValueList && inspectionValueList.length > 0) {
pickerValue.value = inspectionValueList[0].valueKey || "";
}
}
} }
// 计算属性 // 计算属性
......
...@@ -10,6 +10,9 @@ const props = defineProps({ ...@@ -10,6 +10,9 @@ const props = defineProps({
const emit = defineEmits(["update"]); const emit = defineEmits(["update"]);
/** 日期选择最早可选:1990-01-01(年月模式为 1990-01) */
const MIN_PICKER_DATE = new Date(1990, 0, 1);
const displayValue = computed({ const displayValue = computed({
get: () => String(props.item.value ?? ""), get: () => String(props.item.value ?? ""),
set: (v: string) => emit("update", v), set: (v: string) => emit("update", v),
...@@ -33,29 +36,47 @@ function initData() { ...@@ -33,29 +36,47 @@ function initData() {
} }
} }
function clampPickerParts(parts: (number | string)[]): (number | string)[] {
const year = Number(parts[0]);
const month = Number(parts[1] ?? 1);
const day = Number(parts[2] ?? 1);
const clampedYear = Math.max(year, MIN_PICKER_DATE.getFullYear());
const clampedMonth =
clampedYear === MIN_PICKER_DATE.getFullYear()
? Math.max(month, MIN_PICKER_DATE.getMonth() + 1)
: month;
if (columnsType.value.length === 2) {
return [clampedYear, clampedMonth];
}
const clampedDay =
clampedYear === MIN_PICKER_DATE.getFullYear() &&
clampedMonth === MIN_PICKER_DATE.getMonth() + 1
? Math.max(day, MIN_PICKER_DATE.getDate())
: day;
return [clampedYear, clampedMonth, clampedDay];
}
function handleShowPicker() { function handleShowPicker() {
showPicker.value = true; showPicker.value = true;
if (!props.item.value) { if (!props.item.value) {
const date = new Date(); const date = new Date();
if (columnsType.value.length === 2) { const parts =
pickerValue.value = [date.getFullYear(), date.getMonth() + 1]; columnsType.value.length === 2
} else { ? [date.getFullYear(), date.getMonth() + 1]
pickerValue.value = [date.getFullYear(), date.getMonth() + 1, date.getDate()]; : [date.getFullYear(), date.getMonth() + 1, date.getDate()];
} pickerValue.value = clampPickerParts(parts);
} else { } else {
const dateArr = props.item.value.split("-"); const dateArr = props.item.value.split("-").map((v) => Number(v) || v);
if (columnsType.value.length === 2) { pickerValue.value = clampPickerParts(dateArr);
pickerValue.value = [dateArr[0], dateArr[1]];
} else {
pickerValue.value = dateArr;
}
} }
} }
function onConfirm() { function onConfirm() {
let picker = ""; let picker = "";
if (pickerValue.value.length > 0) { if (pickerValue.value.length > 0) {
picker = pickerValue.value.join("-"); const clamped = clampPickerParts(pickerValue.value);
pickerValue.value = clamped;
picker = clamped.join("-");
} }
showPicker.value = false; showPicker.value = false;
emit("update", picker); emit("update", picker);
...@@ -77,8 +98,14 @@ function getLabelWidth(nodeName: string) { ...@@ -77,8 +98,14 @@ function getLabelWidth(nodeName: string) {
:placeholder="item.placeholder" readonly :required="item.required === 1" @click="handleShowPicker" :placeholder="item.placeholder" readonly :required="item.required === 1" @click="handleShowPicker"
input-align="right" :label-width="getLabelWidth(item.nodeName) + 'px'" /> input-align="right" :label-width="getLabelWidth(item.nodeName) + 'px'" />
<van-popup v-model:show="showPicker" destroy-on-close position="bottom" teleport="#vant-portal-host"> <van-popup v-model:show="showPicker" destroy-on-close position="bottom" teleport="#vant-portal-host">
<van-date-picker v-model="pickerValue" :columns-type="columnsType" :title="item.nodeName" <van-date-picker
@cancel="showPicker = false" @confirm="onConfirm" /> v-model="pickerValue"
:columns-type="columnsType"
:min-date="MIN_PICKER_DATE"
:title="item.nodeName"
@cancel="showPicker = false"
@confirm="onConfirm"
/>
</van-popup> </van-popup>
</div> </div>
</template> </template>
......
<script setup lang="ts"> <script setup lang="ts">
import { computed, onMounted, ref } from "vue"; import { getInspectionLeafSelectInitial } from "@api";
import { computed, onMounted, ref, watch } from "vue";
const props = defineProps({ const props = defineProps({
item: { item: {
...@@ -8,13 +9,13 @@ const props = defineProps({ ...@@ -8,13 +9,13 @@ const props = defineProps({
}, },
carTypeList: { carTypeList: {
type: Array, type: Array,
default: () => {}, default: () => [],
}, },
}); });
const emit = defineEmits(["update"]); const emit = defineEmits(["update"]);
const showPicker = ref(false); const showPicker = ref(false);
const pickerValue = ref([]); const pickerValue = ref<string[]>([]);
const displayValueText = computed({ const displayValueText = computed({
get: () => String(props.item.valueText ?? ""), get: () => String(props.item.valueText ?? ""),
...@@ -31,27 +32,8 @@ const displayValueText = computed({ ...@@ -31,27 +32,8 @@ const displayValueText = computed({
}, },
}); });
// 页面加载时初始化数据
onMounted(() => {
initData();
});
// 初始化数据
function initData() {
pickerValue.value = [];
if (props?.item?.inspectionResultVO) {
const inspectionValueList = props?.item?.inspectionResultVO?.inspectionValueList || [];
if (inspectionValueList && inspectionValueList.length > 0 && inspectionValueList[0].valueKey) {
pickerValue.value = [inspectionValueList[0].valueKey];
}
}
onConfirm();
}
// 计算属性
const columnsList = computed(() => { const columnsList = computed(() => {
const optionsList = JSON.parse(props.item.options || "[]").map(item => { const optionsList = JSON.parse(props.item.options || "[]").map((item: string) => {
const valueList = (item || "").split("-"); const valueList = (item || "").split("-");
return { return {
text: valueList[1] || "", text: valueList[1] || "",
...@@ -61,50 +43,119 @@ const columnsList = computed(() => { ...@@ -61,50 +43,119 @@ const columnsList = computed(() => {
return props.item.nodeName === "车型" ? props.carTypeList : optionsList; return props.item.nodeName === "车型" ? props.carTypeList : optionsList;
}); });
function emitSelection(value: string, valueText: string, valueKey: string) {
const item = props.item as { value?: string; valueKey?: string; valueText?: string };
if (
String(item?.value ?? "") === value &&
String(item?.valueText ?? "") === valueText &&
String(item?.valueKey ?? "") === valueKey
) {
return;
}
emit("update", { value, valueText, valueKey });
}
function findColumn(valueKey: string, valueText: string) {
const cols = columnsList.value as { text?: string; value?: string }[];
if (valueKey) {
const byKey = cols.find((col) => col.value === valueKey);
if (byKey) return byKey;
}
if (valueText) {
return cols.find((col) => col.text === valueText || col.value === valueText);
}
return undefined;
}
/** 从 VO / 节点字段 / resolvedInitialValue 回显,无有效选中时不 emit 空值 */
function initData() {
const { valueKey, valueText } = getInspectionLeafSelectInitial(props.item);
if (!valueKey && !valueText) {
pickerValue.value = [];
return;
}
const selected = findColumn(valueKey, valueText);
if (selected?.value !== undefined && selected.value !== "") {
pickerValue.value = [String(selected.value)];
emitSelection(String(selected.value), String(selected.text ?? ""), String(selected.value));
return;
}
pickerValue.value = valueKey ? [valueKey] : [];
emitSelection(valueKey, valueText, valueKey || valueText);
}
onMounted(() => {
initData();
});
watch(
() => props.carTypeList,
() => {
if (props.item?.nodeName === "车型") {
initData();
}
}
);
function onConfirm() { function onConfirm() {
const picker = pickerValue.value && pickerValue.value.length > 0 ? pickerValue.value[0] : ""; const picker =
pickerValue.value && pickerValue.value.length > 0 ? pickerValue.value[0] : "";
showPicker.value = false; showPicker.value = false;
const selected = columnsList.value.find((col) => col.value === picker) || {}; if (!picker) {
emit("update", { const { valueKey, valueText } = getInspectionLeafSelectInitial(props.item);
value: selected.value || "", if (valueKey || valueText) {
valueText: selected.text || "", return;
valueKey: selected.value || "", }
}); emitSelection("", "", "");
return;
}
const selected =
(columnsList.value as { text?: string; value?: string }[]).find((col) => col.value === picker) ||
{};
emitSelection(String(selected.value ?? ""), String(selected.text ?? ""), String(selected.value ?? ""));
} }
function getLabelWidth(nodeName: string) { function getLabelWidth(nodeName: string) {
let widtPx = 76; let widtPx = 76;
if (nodeName.length > 4) { if (nodeName.length > 4) {
widtPx = widtPx + ((nodeName.length - 4) * 12); widtPx = widtPx + (nodeName.length - 4) * 12;
} }
return widtPx; return widtPx;
} }
</script> </script>
<template> <template>
<div> <div>
<van-field v-model="displayValueText" <van-field
clearable v-model="displayValueText"
is-link clearable
:label="item.nodeName" is-link
name="datePicker" :label="item.nodeName"
:placeholder="item.placeholder" name="datePicker"
readonly :placeholder="item.placeholder"
:required="item.required === 1" readonly
@click="showPicker = true" input-align="right" :label-width="getLabelWidth(item.nodeName) + 'px'" /> :required="item.required === 1"
<van-popup v-model:show="showPicker" input-align="right"
destroy-on-close :label-width="getLabelWidth(item.nodeName) + 'px'"
position="bottom" @click="showPicker = true"
teleport="#vant-portal-host"> />
<van-picker v-model="pickerValue" <van-popup
:columns="columnsList" v-model:show="showPicker"
:title="item.nodeName" destroy-on-close
@cancel="showPicker = false" position="bottom"
@confirm="onConfirm" /> teleport="#vant-portal-host"
</van-popup> >
</div> <van-picker
v-model="pickerValue"
:columns="columnsList"
:title="item.nodeName"
@cancel="showPicker = false"
@confirm="onConfirm"
/>
</van-popup>
</div>
</template> </template>
<style lang="scss" scoped></style> <style lang="scss" scoped></style>
...@@ -184,11 +184,7 @@ ...@@ -184,11 +184,7 @@
<script setup lang="ts"> <script setup lang="ts">
import type { ScoreRatingOption } from "@/types/views/car-detail"; import type { ScoreRatingOption } from "@/types/views/car-detail";
import type { import type { CompleteInspectionParams, InspectionScoreVO } from "@api";
CompleteInspectionParams,
InspectionChildrenData,
InspectionScoreVO,
} from "@api";
import type { RatingGuideConfig } from "./rating-guide-content"; import type { RatingGuideConfig } from "./rating-guide-content";
...@@ -197,7 +193,7 @@ import { reactive, ref, watch } from "vue"; ...@@ -197,7 +193,7 @@ import { reactive, ref, watch } from "vue";
import ratingSelectedCheckImg from "@/assets/image/rating-selected-check.png"; import ratingSelectedCheckImg from "@/assets/image/rating-selected-check.png";
import systemTipImg from "@/assets/image/system-tip.png"; import systemTipImg from "@/assets/image/system-tip.png";
import { SCORE_RATING_OPTIONS as RATING_OPTIONS } from "@/types/views/car-detail"; import { SCORE_RATING_OPTIONS as RATING_OPTIONS } from "@/types/views/car-detail";
import { getInspectionChildren } from "@api"; import { extractInspectionScoreVO, getInspectionChildren } from "@api";
import { isRequestFailureAlreadyHandled } from "@utils/request"; import { isRequestFailureAlreadyHandled } from "@utils/request";
import { showToast } from "vant"; import { showToast } from "vant";
...@@ -242,28 +238,6 @@ function onRatingGuideShow(v: boolean) { ...@@ -242,28 +238,6 @@ function onRatingGuideShow(v: boolean) {
ratingGuideOpen.value = v; ratingGuideOpen.value = v;
} }
function extractInspectionScoreVO(raw: InspectionChildrenData): InspectionScoreVO | null {
if (!raw || typeof raw !== "object") {
return null;
}
/** `rootNodeId === -1` 时接口常返回 `[{ id: -1, inspectionScoreVO: {...}, ... }]`,与单对象两种形态 */
if (Array.isArray(raw)) {
for (const item of raw) {
if (!item || typeof item !== "object") continue;
const vo = (item as { inspectionScoreVO?: unknown }).inspectionScoreVO;
if (vo && typeof vo === "object") {
return vo as InspectionScoreVO;
}
}
return null;
}
const vo = raw.inspectionScoreVO;
if (!vo || typeof vo !== "object") {
return null;
}
return vo;
}
function scoreFieldToNumber(value: unknown, fallback = 0): number { function scoreFieldToNumber(value: unknown, fallback = 0): number {
if (value === null || value === undefined || value === "") { if (value === null || value === undefined || value === "") {
return fallback; return fallback;
......
...@@ -7,9 +7,11 @@ import { computed, ref } from "vue"; ...@@ -7,9 +7,11 @@ import { computed, ref } from "vue";
import { import {
applyResolvedInitialValuesToLeafNodes, applyResolvedInitialValuesToLeafNodes,
extractInspectionScoreVO,
getInspectionChildren, getInspectionChildren,
getInspectionRootNodes, getInspectionRootNodes,
getInspectionTemplateDefault, getInspectionTemplateDefault,
resolveScoreModuleCompletedFlag,
} from "@api"; } from "@api";
import { isRequestFailureAlreadyHandled } from "@utils/request"; import { isRequestFailureAlreadyHandled } from "@utils/request";
import { showToast } from "vant"; import { showToast } from "vant";
...@@ -146,6 +148,15 @@ export function useInspectModules(route: RouteLocationNormalizedLoaded) { ...@@ -146,6 +148,15 @@ export function useInspectModules(route: RouteLocationNormalizedLoaded) {
const scoreRoot = rootNodes.find((root) => String(root.id) === "-1"); const scoreRoot = rootNodes.find((root) => String(root.id) === "-1");
const inspectionRoots = rootNodes.filter((root) => String(root.id) !== "-1"); const inspectionRoots = rootNodes.filter((root) => String(root.id) !== "-1");
let scoreVo = null;
try {
const scoreRaw = await getInspectionChildren(-1, taskId.value);
scoreVo = extractInspectionScoreVO(scoreRaw);
} catch (error) {
console.error("刷新检测评分完成状态失败:", error);
}
const scoreCompletedFlag = resolveScoreModuleCompletedFlag(scoreRoot, scoreVo);
const refreshedInspectionModules: BigModule[] = inspectionRoots.map((root) => { const refreshedInspectionModules: BigModule[] = inspectionRoots.map((root) => {
const prev = oldByKey.get(String(root.id)); const prev = oldByKey.get(String(root.id));
return { return {
...@@ -162,7 +173,7 @@ export function useInspectModules(route: RouteLocationNormalizedLoaded) { ...@@ -162,7 +173,7 @@ export function useInspectModules(route: RouteLocationNormalizedLoaded) {
const scoreModule: BigModule = { const scoreModule: BigModule = {
key: SCORE_BIG_KEY, key: SCORE_BIG_KEY,
label: "检测评分", label: "检测评分",
completedFlag: scoreRoot?.completedFlag as 0 | 1 | string | undefined, completedFlag: scoreCompletedFlag,
subTabs: prevScore?.subTabs ?? [], subTabs: prevScore?.subTabs ?? [],
hasSecondaryTabs: prevScore?.hasSecondaryTabs, hasSecondaryTabs: prevScore?.hasSecondaryTabs,
secondaryProgress: prevScore?.secondaryProgress, secondaryProgress: prevScore?.secondaryProgress,
...@@ -386,6 +397,7 @@ export function useInspectModules(route: RouteLocationNormalizedLoaded) { ...@@ -386,6 +397,7 @@ export function useInspectModules(route: RouteLocationNormalizedLoaded) {
switchToUncompletedInspectionNode, switchToUncompletedInspectionNode,
advanceInspectionStep, advanceInspectionStep,
onOpenModulePicker, onOpenModulePicker,
refreshBigModulesFromRootNodes,
}; };
} }
......
...@@ -212,6 +212,7 @@ export function useInspectSubmit( ...@@ -212,6 +212,7 @@ export function useInspectSubmit(
inspectionScoreFormRef.value.getCompleteInspectionPayload(modules.taskId.value) inspectionScoreFormRef.value.getCompleteInspectionPayload(modules.taskId.value)
); );
if (result && hasCompleteInspectionUncompletedHint(result)) { if (result && hasCompleteInspectionUncompletedHint(result)) {
await modules.refreshBigModulesFromRootNodes();
const target = getCompleteInspectionUncompletedNavigateTarget(result); const target = getCompleteInspectionUncompletedNavigateTarget(result);
const name = target?.toastName; const name = target?.toastName;
const nid = target?.nodeId; const nid = target?.nodeId;
......
<script setup lang="ts"> <script setup lang="ts">
import type { ReportItem } from "@/types/views/car-list"; import type { ReportItem } from "@/types/views/car-list";
import { computed, onActivated, ref, watch } from "vue"; import { computed, onActivated, ref } from "vue";
import { useRouter } from "vue-router"; import { useRouter } from "vue-router";
import { getInspectReportPage } from "@/api/modules/inspect-report"; import { getInspectReportPage } from "@/api/modules/inspect-report";
...@@ -9,7 +9,9 @@ import PageTop from "@/components/PageTop.vue"; ...@@ -9,7 +9,9 @@ import PageTop from "@/components/PageTop.vue";
const router = useRouter(); const router = useRouter();
const keyword = ref(""); const keywordInput = ref("");
/** 点击「搜索」后生效的查询词 */
const searchKeyword = ref("");
const refreshing = ref(false); const refreshing = ref(false);
const loading = ref(false); const loading = ref(false);
const finished = ref(false); const finished = ref(false);
...@@ -85,7 +87,7 @@ async function fillMore() { ...@@ -85,7 +87,7 @@ async function fillMore() {
const res = await getInspectReportPage({ const res = await getInspectReportPage({
size: pageSize, size: pageSize,
page: currentPage.value, page: currentPage.value,
keyword: keyword.value.trim() || undefined, keyword: searchKeyword.value || undefined,
}); });
const next = (res.content ?? []).map((x: unknown) => mapReportItem(x as Record<string, unknown>)); const next = (res.content ?? []).map((x: unknown) => mapReportItem(x as Record<string, unknown>));
...@@ -112,6 +114,15 @@ async function onRefresh() { ...@@ -112,6 +114,15 @@ async function onRefresh() {
} }
} }
function onSearch() {
searchKeyword.value = keywordInput.value.trim();
void onRefresh();
}
function onClearKeyword() {
keywordInput.value = "";
}
/** 检测报告列表:查看报告优先使用行内 h5Url,否则进站内报告页 */ /** 检测报告列表:查看报告优先使用行内 h5Url,否则进站内报告页 */
function onViewReport(item: ReportItem) { function onViewReport(item: ReportItem) {
const url = item.h5Url?.trim(); const url = item.h5Url?.trim();
...@@ -124,9 +135,6 @@ function onViewReport(item: ReportItem) { ...@@ -124,9 +135,6 @@ function onViewReport(item: ReportItem) {
} }
} }
watch([keyword], () => {
void onRefresh();
});
onActivated(() => { onActivated(() => {
// keepAlive: true 下首次进入与从子页返回都会触发;勿再在 setup 末尾调用 onRefresh,否则会并发两次 fillMore、第一页重复追加 // keepAlive: true 下首次进入与从子页返回都会触发;勿再在 setup 末尾调用 onRefresh,否则会并发两次 fillMore、第一页重复追加
...@@ -144,22 +152,26 @@ onActivated(() => { ...@@ -144,22 +152,26 @@ onActivated(() => {
color="#969799" color="#969799"
name="search" name="search"
size="16" /> size="16" />
<input v-model="keyword" <input v-model="keywordInput"
autocomplete="off" autocomplete="off"
class="round-search__input" class="round-search__input"
enterkeyhint="search"
placeholder="搜索报告号、车牌号、车型名称" placeholder="搜索报告号、车牌号、车型名称"
type="search" /> type="search" />
<button v-show="keyword" <button v-show="keywordInput"
aria-label="清除" aria-label="清除"
class="round-search__clear" class="round-search__clear"
type="button" type="button"
@click="keyword = ''"> @click="onClearKeyword">
<van-icon color="#c8c9cc" <van-icon color="#c8c9cc"
name="clear" name="clear"
size="18" /> size="18" />
</button> </button>
</div> </div>
<button class="round-search__submit"
type="button"
@click="onSearch">
搜索
</button>
</div> </div>
</div> </div>
</PageTop> </PageTop>
...@@ -246,6 +258,7 @@ onActivated(() => { ...@@ -246,6 +258,7 @@ onActivated(() => {
.round-search { .round-search {
display: flex; display: flex;
gap: 8px;
align-items: center; align-items: center;
box-sizing: border-box; box-sizing: border-box;
padding: 0; padding: 0;
...@@ -308,6 +321,20 @@ onActivated(() => { ...@@ -308,6 +321,20 @@ onActivated(() => {
border: 0; border: 0;
} }
.round-search__submit {
flex-shrink: 0;
height: 34px;
padding: 0 14px;
font-size: 14px;
font-weight: 500;
line-height: 34px;
color: #fff;
cursor: pointer;
background: #185efe;
border: 0;
border-radius: 999px;
}
.list-wrap { .list-wrap {
flex: 1; flex: 1;
padding: 12px 12px calc(12px + env(safe-area-inset-bottom)); padding: 12px 12px calc(12px + env(safe-area-inset-bottom));
......
...@@ -10,7 +10,9 @@ import PageTop from "@/components/PageTop.vue"; ...@@ -10,7 +10,9 @@ import PageTop from "@/components/PageTop.vue";
import WorkOrderStatusTags from "@/components/WorkOrderStatusTags.vue"; import WorkOrderStatusTags from "@/components/WorkOrderStatusTags.vue";
import searchIcon from "@assets/image/searchIcon.png"; import searchIcon from "@assets/image/searchIcon.png";
const keyword = ref(""); const keywordInput = ref("");
/** 点击「搜索」后生效的查询词 */
const searchKeyword = ref("");
const activeStatus = ref<WorkOrderStatus>(1); const activeStatus = ref<WorkOrderStatus>(1);
const refreshing = ref(false); const refreshing = ref(false);
const loading = ref(false); const loading = ref(false);
...@@ -111,7 +113,7 @@ async function fillMore() { ...@@ -111,7 +113,7 @@ async function fillMore() {
size: pageSize, size: pageSize,
page: currentPage.value, page: currentPage.value,
status: activeStatus.value, status: activeStatus.value,
keyword: keyword.value.trim(), keyword: searchKeyword.value,
}); });
const next = (res.content ?? []).map((item: unknown) => const next = (res.content ?? []).map((item: unknown) =>
mapWorkOrderItem(item as unknown as Record<string, unknown>) mapWorkOrderItem(item as unknown as Record<string, unknown>)
...@@ -147,9 +149,19 @@ async function onRefresh() { ...@@ -147,9 +149,19 @@ async function onRefresh() {
} }
} }
function onSearch() {
searchKeyword.value = keywordInput.value.trim();
void onRefresh();
}
function onClearKeyword() {
keywordInput.value = "";
}
function onStatusChange(status: WorkOrderStatus) { function onStatusChange(status: WorkOrderStatus) {
activeStatus.value = status; activeStatus.value = status;
keyword.value = ""; keywordInput.value = "";
searchKeyword.value = "";
} }
function startCheck(item: WorkOrderItem) { function startCheck(item: WorkOrderItem) {
...@@ -260,7 +272,7 @@ function getCardActions(item: WorkOrderItem): CardAction[] { ...@@ -260,7 +272,7 @@ function getCardActions(item: WorkOrderItem): CardAction[] {
/** 底部操作区统一拦冒泡,避免点到按钮与卡片间隙时仍触发整张卡的 viewWorkOrder */ /** 底部操作区统一拦冒泡,避免点到按钮与卡片间隙时仍触发整张卡的 viewWorkOrder */
function stopCardFooterBubbling() {} function stopCardFooterBubbling() {}
watch([keyword, activeStatus], () => { watch(activeStatus, () => {
void onRefresh(); void onRefresh();
}); });
...@@ -289,22 +301,26 @@ void onRefresh(); ...@@ -289,22 +301,26 @@ void onRefresh();
aria-hidden="true" aria-hidden="true"
class="round-search__icon" class="round-search__icon"
:src="searchIcon" /> :src="searchIcon" />
<input v-model="keyword" <input v-model="keywordInput"
autocomplete="off" autocomplete="off"
class="round-search__input" class="round-search__input"
enterkeyhint="search"
placeholder="搜索车牌号、VIN码、车型名称" placeholder="搜索车牌号、VIN码、车型名称"
type="search" /> type="search" />
<button v-show="keyword" <button v-show="keywordInput"
aria-label="清除" aria-label="清除"
class="round-search__clear" class="round-search__clear"
type="button" type="button"
@click="keyword = ''"> @click="onClearKeyword">
<van-icon color="#c8c9cc" <van-icon color="#c8c9cc"
name="clear" name="clear"
size="18" /> size="18" />
</button> </button>
</div> </div>
<button class="round-search__submit"
type="button"
@click="onSearch">
搜索
</button>
</div> </div>
</div> </div>
</PageTop> </PageTop>
...@@ -464,6 +480,7 @@ void onRefresh(); ...@@ -464,6 +480,7 @@ void onRefresh();
.round-search { .round-search {
display: flex; display: flex;
gap: 8px;
align-items: center; align-items: center;
box-sizing: border-box; box-sizing: border-box;
padding: 0; padding: 0;
...@@ -528,6 +545,20 @@ void onRefresh(); ...@@ -528,6 +545,20 @@ void onRefresh();
border: 0; border: 0;
} }
.round-search__submit {
flex-shrink: 0;
height: 34px;
padding: 0 14px;
font-size: 14px;
font-weight: 500;
line-height: 34px;
color: #fff;
cursor: pointer;
background: #185efe;
border: 0;
border-radius: 999px;
}
.list-wrap { .list-wrap {
flex: 1; flex: 1;
padding: 12px; padding: 12px;
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!