yyb
4 天以前 883ab99ab021be1adc6dc5689368f899ea436e54
完成
已添加1个文件
已修改2个文件
1097 ■■■■■ 文件已修改
src/pages/routingInspection/detail/indexJX.vue 147 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/pages/routingInspection/detail/indexLS.vue 591 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/pages/routingInspection/upload.vue 359 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/pages/routingInspection/detail/indexJX.vue
@@ -138,6 +138,7 @@
        style="padding-bottom: 10px"
      >
        <wd-form-item
          prop="structureItemsGroup"
          :label="formatValue(item.structureName)"
          label-width="400rpx"
          style="color: red"
@@ -184,6 +185,7 @@
          :label="formatValue(item.twistName)"
          label-width="400rpx"
          style="color: red"
          prop="inspectTwistGroup"
          required
        ></wd-form-item>
        <wd-form-item label="绞向" prop="direction" required>
@@ -290,40 +292,15 @@
      <view style="margin: 10rpx">
        <text class="title">{{ "附件" }}</text>
      </view>
      <view class="attachment-grid">
        <!-- å·²ä¸Šä¼ é™„件(包含新上传的) -->
        <wd-col v-for="(file, index) in allFiles" :key="file.id || index" class="attachment-item">
          <wd-img :width="80" :height="80" :src="file.url" @click="previewImage(file.url)">
            <template #error>
              <view class="error-wrap">加载失败</view>
            </template>
            <template #loading>
              <view class="loading-wrap">
                <wd-loading />
              </view>
            </template>
          </wd-img>
          <!-- ç¼–辑模式下显示删除按钮 -->
          <!-- <wd-icon
            v-if="isEdit"
            name="close-circle"
            class="delete-icon"
            @click.stop="deleteFile(file.id || index)"
          ></wd-icon> -->
        </wd-col>
        <!-- ä¸Šä¼ æŒ‰é’®ï¼ˆä»…编辑模式显示) -->
        <wd-col v-if="isEdit" class="attachment-item upload-btn">
          <wd-upload
            :multiple="true"
            :max-count="5"
            :before-upload="beforeUpload"
            @success="handleUploadSuccess"
            @fail="handleUploadFail"
          >
            <view class="upload-icon">+</view>
          </wd-upload>
        </wd-col>
      </view>
      <wd-col :span="24">
        <AttachmentUpload
          :detailData="detailData"
          :isEdit="isEdit"
          :deviceType="paramsType"
          ref="attachmentRef"
          v-if="detailDataLoaded"
        />
      </wd-col>
    </wd-row>
    <wd-popup v-model="show" custom-style="border-radius:32rpx;" @close="handleClose">
@@ -342,8 +319,9 @@
import RoutingInspectionApi from "@/api/routingInspection/routingInspection";
import Scan from "@/components/scan/index.vue";
import { useToast } from "wot-design-uni";
import AttachmentUpload from "../upload.vue";
// æ ¸å¿ƒçŠ¶æ€
const paramsType = ref("");
const paramsId = ref("");
const recordData = ref<any>({ structureInfo: { files: [], structureRecordResult: {} } });
const show = ref(false);
@@ -353,8 +331,10 @@
const deviceUid = ref("");
const scanRef = ref();
const toast = useToast();
const attachmentRef = ref<any>(null);
const detailData = reactive<any>({});
const detailDataLoaded = ref(false);
// è¡¨å•临时数据(编辑模式绑定)
const formData = reactive({
  twistDiameter: "", // ç»žåˆ¶å¤–径
  structureFormula: "", // æˆå“ç»“æž„
@@ -365,7 +345,6 @@
  sampleComplete: "", // æ ·å“æ˜¯å¦é½å…¨
});
// é€‰é¡¹æ•°æ®
const twistDirectionOptions = [
  { label: "左向", value: "左向" },
  { label: "右向", value: "右向" },
@@ -387,47 +366,40 @@
  { label: "否", value: "否" },
];
// åˆå¹¶åŽŸæœ‰é™„ä»¶å’Œæ–°ä¸Šä¼ é™„ä»¶
const allFiles = computed(() => {
  return [...(recordData.value.structureInfo?.files || []), ...tempFiles.value];
});
// åˆå§‹åŒ–表单数据(接口数据同步到表单)
const initFormData = () => {
  const structureResult = recordData.value.structureInfo?.structureRecordResult || {};
  const inspectionResult = recordData.value.inspectionResult || {};
  // åŸºç¡€å¯ç¼–辑字段
  formData.twistDiameter = inspectionResult.twistDiameter || "";
  formData.structureFormula = structureResult.inspectStructure?.structureFormula || "";
  formData.sampleComplete = inspectionResult.sampleComplete || "";
  formData.conclusion = structureResult.conclusion || "";
  // ä¿®å¤äº§å“å¤–观和结论的数据格式
  formData.productAppearance = Array.isArray(structureResult.productAppearance)
    ? structureResult.productAppearance
    : structureResult.productAppearance
    ? [structureResult.productAppearance]
    : [];
  // å¾ªçŽ¯ç±»å­—æ®µï¼ˆæ·±æ‹·è´é¿å…åŽŸæ•°æ®æ±¡æŸ“ï¼‰
  formData.structureItems = JSON.parse(
    JSON.stringify(structureResult.inspectStructure?.structureItems || [])
  );
  formData.inspectTwist = JSON.parse(JSON.stringify(structureResult.inspectTwist || []));
  // åˆå§‹åŒ–绞向数据(确保有值)
  formData.inspectTwist.forEach((item: any) => {
    if (!item.direction) item.direction = "";
  });
};
// èŽ·å–è¯¦æƒ…æ•°æ®
const getDetailData = async (id: string, deviceType: string) => {
  try {
    const response = await RoutingInspectionApi.getStrandedInspectionStructureInfoById({ id });
    recordData.value = response.data;
    detailData.value = response.data.structureInfo;
    console.log("detailData.value", detailData.value);
    tempFiles.value = []; // æ¸…空临时文件
    initFormData(); // æ•°æ®è¿”回后初始化表单
    detailDataLoaded.value = true; // æ•°æ®åŠ è½½å®ŒæˆåŽï¼Œæ¸²æŸ“å­ç»„ä»¶
    console.log("父组件-数据就绪后打印");
  } catch (error) {
    console.error("获取详情失败:", error);
    uni.showToast({ title: "加载失败", icon: "error" });
@@ -436,8 +408,14 @@
// é¡µé¢åŠ è½½
onLoad((options: any) => {
  paramsId.value = options.id;
  getDetailData(options.id, options.deviceType);
  try {
    paramsId.value = options.id;
    paramsType.value = options.deviceType;
    getDetailData(options.id, options.deviceType);
  } catch (error) {
    console.error("获取详情失败:", error);
    uni.showToast({ title: "加载失败", icon: "error" });
  }
});
// ç¼–辑模式切换
@@ -448,8 +426,8 @@
// å–消编辑(重置表单)
const close = () => {
  isEdit.value = false;
  tempFiles.value = []; // å–消时清空临时上传的文件
  initFormData(); // æ¢å¤åŽŸå§‹æ•°æ®
  tempFiles.value = [];
  initFormData();
};
// ä¿å­˜ç¼–辑(含必填项校验)
@@ -482,7 +460,9 @@
  }
  console.log("1111", deviceUid.value);
  if (!deviceUid.value) return uni.showToast({ title: "请扫描二维码", icon: "none" });
  // 4. æäº¤æ•°æ®åˆ°æŽ¥å£
  const { newFiles } = attachmentRef.value.getSubmitFiles();
  console.log("newFiles", newFiles);
  const allFileIds = [...newFiles];
  try {
    const res = await RoutingInspectionApi.strandedPatrolCheckInspection({
      deviceUid: deviceUid.value,
@@ -499,13 +479,13 @@
      inspectionResult: {
        sampleComplete: formData.sampleComplete,
      },
      processInspectionAttachmentList: tempFiles.value.map((f) => f.url), // æ–°ä¸Šä¼ çš„附件
      processInspectionAttachmentList: allFileIds,
    });
    if (res.code === 200) {
      uni.showToast({ title: "保存成功", icon: "success" });
      isEdit.value = false;
      getDetailData(paramsId.value, recordData.value.deviceType); // åˆ·æ–°æ•°æ®
      getDetailData(paramsId.value, paramsType.value);
    } else {
      uni.showModal({ title: res.msg || "保存失败", icon: "error" });
    }
@@ -513,61 +493,6 @@
    console.error("保存失败:", e);
    uni.showModal({ title: e.message || "保存失败", icon: "error" });
  }
};
// é™„件上传前置校验
const beforeUpload = (file: any) => {
  // é™åˆ¶å›¾ç‰‡å¤§å°ä¸è¶…过2M
  const maxSize = 2 * 1024 * 1024;
  if (file.size > maxSize) {
    uni.showToast({ title: "图片大小不能超过2M", icon: "none" });
    return false;
  }
  return true;
};
// é™„件上传成功回调
const handleUploadSuccess = (res: any) => {
  // å‡è®¾æŽ¥å£è¿”回格式: { url: 'xxx', id: 'xxx' }
  if (Array.isArray(res)) {
    tempFiles.value = [
      ...tempFiles.value,
      ...res.map((file) => ({
        ...file,
        id: `temp-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`, // ç”Ÿæˆä¸´æ—¶ID
      })),
    ];
  } else {
    tempFiles.value.push({
      ...res,
      id: `temp-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`,
    });
  }
};
// é™„件上传失败回调
const handleUploadFail = (err: any) => {
  uni.showToast({ title: "附件上传失败", icon: "error" });
};
// åˆ é™¤é™„ä»¶
const deleteFile = (id: string | number) => {
  // åˆ é™¤ä¸´æ—¶æ–‡ä»¶
  tempFiles.value = tempFiles.value.filter((file) => file.id !== id);
  // å¦‚果是原有文件,需要标记删除(实际项目中可能需要接口交互)
  if (typeof id !== "string" || !id.startsWith("temp-")) {
    // è¿™é‡Œå¯ä»¥å®žçŽ°åˆ é™¤åŽŸæœ‰æ–‡ä»¶çš„é€»è¾‘
    recordData.value.structureInfo.files = recordData.value.structureInfo.files.filter(
      (file: any, index: number) => index !== id
    );
  }
};
// å›¾ç‰‡é¢„览
const previewImage = (url: string) => {
  previewImageUrl.value = url;
  show.value = true;
};
const handleClose = () => {
@@ -639,7 +564,7 @@
  } catch (err) {
    console.error("JSON解析失败:", err);
    toast.error("扫码数据异常");
    return; // è§£æžå¤±è´¥ç›´æŽ¥è¿”回,避免后续错误
    return;
  }
  deviceUid.value = codeObj?.uid;
  toast.success("扫码成功");
src/pages/routingInspection/detail/indexLS.vue
@@ -40,287 +40,254 @@
    </view>
  </view>
  <view class="list">
    <div class="inspection-report">
      <!-- åŸºæœ¬ä¿¡æ¯æ¨¡å— -->
      <wd-row>
        <view style="margin: 10rpx">
          <text class="title">{{ "基本信息" }}</text>
        </view>
        <wd-col :span="24">
          <wd-form-item label="日期" prop="recordDate">
            {{ formatDate(detailData.fixedInfo?.recordDate) }}
          </wd-form-item>
          <wd-form-item label="机台" prop="deviceModel">
            {{ formatValue(detailData.fixedInfo?.deviceModel) }}
          </wd-form-item>
          <wd-form-item label="班次" prop="workShift">
            {{ formatValue(detailData.fixedInfo?.workShift) }}
          </wd-form-item>
          <wd-form-item label="班组" prop="teamName">
            {{ formatValue(detailData.fixedInfo?.teamName) }}
          </wd-form-item>
          <wd-form-item label="单丝规格" prop="model">
            {{ formatValue(detailData.fixedInfo?.model) }}
          </wd-form-item>
          <wd-form-item label="生产轴数" prop="outputNumber">
            {{ formatValue(detailData.fixedInfo?.outputNumber, "è½´") }}
          </wd-form-item>
          <wd-form-item label="型号" prop="poleModel">
            {{ formatValue(detailData.fixedInfo?.poleModel) }}
          </wd-form-item>
          <wd-form-item label="批次" prop="poleNumber">
            {{ formatValue(detailData.fixedInfo?.poleNumber) }}
          </wd-form-item>
          <wd-form-item label="记录人" prop="createUserName">
            {{ formatValue(detailData.fixedInfo?.createUserName) }}
          </wd-form-item>
          <wd-form-item label="首检盘号" prop="firstNo">
            {{ formatValue(detailData.fixedInfo?.firstNo) }}
          </wd-form-item>
        </wd-col>
      </wd-row>
    <!-- åŸºæœ¬ä¿¡æ¯æ¨¡å— -->
    <wd-row>
      <view style="margin: 10rpx">
        <text class="title">{{ "基本信息" }}</text>
      </view>
      <wd-col :span="24">
        <wd-form-item label="日期" prop="recordDate">
          {{ formatDate(detailData.fixedInfo?.recordDate) }}
        </wd-form-item>
        <wd-form-item label="机台" prop="deviceModel">
          {{ formatValue(detailData.fixedInfo?.deviceModel) }}
        </wd-form-item>
        <wd-form-item label="班次" prop="workShift">
          {{ formatValue(detailData.fixedInfo?.workShift) }}
        </wd-form-item>
        <wd-form-item label="班组" prop="teamName">
          {{ formatValue(detailData.fixedInfo?.teamName) }}
        </wd-form-item>
        <wd-form-item label="单丝规格" prop="model">
          {{ formatValue(detailData.fixedInfo?.model) }}
        </wd-form-item>
        <wd-form-item label="生产轴数" prop="outputNumber">
          {{ formatValue(detailData.fixedInfo?.outputNumber, "è½´") }}
        </wd-form-item>
        <wd-form-item label="型号" prop="poleModel">
          {{ formatValue(detailData.fixedInfo?.poleModel) }}
        </wd-form-item>
        <wd-form-item label="批次" prop="poleNumber">
          {{ formatValue(detailData.fixedInfo?.poleNumber) }}
        </wd-form-item>
        <wd-form-item label="记录人" prop="createUserName">
          {{ formatValue(detailData.fixedInfo?.createUserName) }}
        </wd-form-item>
        <wd-form-item label="首检盘号" prop="firstNo">
          {{ formatValue(detailData.fixedInfo?.firstNo) }}
        </wd-form-item>
      </wd-col>
    </wd-row>
      <!-- è‡ªæ£€è®°å½•详情模块 -->
      <wd-row>
        <view style="margin: 10rpx">
          <text class="title">{{ "自检记录详情" }}</text>
        </view>
        <wd-col :span="24">
          <wd-form-item label="巡检员" prop="processInspectionUserName">
            {{ detailData.processInspectionUserName || "-" }}
          </wd-form-item>
          <wd-form-item label="状态" prop="status">
            <wd-tag custom-class="space" :type="getStatusType(detailData.status)">
              {{ getStatusText(detailData.status) }}
            </wd-tag>
          </wd-form-item>
        </wd-col>
      </wd-row>
    <!-- è‡ªæ£€è®°å½•详情模块 -->
    <wd-row>
      <view style="margin: 10rpx">
        <text class="title">{{ "自检记录详情" }}</text>
      </view>
      <wd-col :span="24">
        <wd-form-item label="巡检员" prop="processInspectionUserName">
          {{ detailData.processInspectionUserName || "-" }}
        </wd-form-item>
        <wd-form-item label="状态" prop="status">
          <wd-tag custom-class="space" :type="getStatusType(detailData.status)">
            {{ getStatusText(detailData.status) }}
          </wd-tag>
        </wd-form-item>
      </wd-col>
    </wd-row>
      <!-- æ£€éªŒç»“æžœ -->
      <wd-row>
        <view style="margin: 10rpx">
          <text class="title">{{ "检验结果" }}</text>
        </view>
        <wd-col :span="24">
          <wd-form-item label="单丝直径" prop="dia">
            {{ formatValue(detailData.inspectionResult?.dia, "mm") || "-" }}
          </wd-form-item>
    <!-- æ£€éªŒç»“æžœ -->
    <wd-row>
      <view style="margin: 10rpx">
        <text class="title">{{ "检验结果" }}</text>
      </view>
      <wd-col :span="24">
        <wd-form-item label="单丝直径" prop="dia">
          {{ formatValue(detailData.inspectionResult?.dia, "mm") || "-" }}
        </wd-form-item>
          <wd-form-item label="最大直径" prop="maxDia" required>
            <template v-if="isEdit">
              <wd-input v-model="formData.maxDia" placeholder="请输入最大直径(mm)" type="number" />
            </template>
            <template v-else>
              {{ formatValue(detailData.inspectionResult?.maxDia, "mm") || "-" }}
            </template>
          </wd-form-item>
        <wd-form-item label="最大直径" prop="maxDia" required>
          <template v-if="isEdit">
            <wd-input v-model="formData.maxDia" placeholder="请输入最大直径(mm)" type="number" />
          </template>
          <template v-else>
            {{ formatValue(detailData.inspectionResult?.maxDia, "mm") || "-" }}
          </template>
        </wd-form-item>
          <wd-form-item label="最小直径" prop="minDia" required>
            <template v-if="isEdit">
              <wd-input v-model="formData.minDia" placeholder="请输入最小直径(mm)" type="number" />
            </template>
            <template v-else>
              {{ formatValue(detailData.inspectionResult?.minDia, "mm") || "-" }}
            </template>
          </wd-form-item>
        <wd-form-item label="最小直径" prop="minDia" required>
          <template v-if="isEdit">
            <wd-input v-model="formData.minDia" placeholder="请输入最小直径(mm)" type="number" />
          </template>
          <template v-else>
            {{ formatValue(detailData.inspectionResult?.minDia, "mm") || "-" }}
          </template>
        </wd-form-item>
          <wd-form-item label="外观" prop="appearance" required>
            <template v-if="isEdit">
              <wd-checkbox-group
                v-model="formData.appearance"
                inline
                v-for="(opt, idx) in appearanceOptions"
                :key="idx"
                style="text-align: justify"
              >
                <wd-checkbox :modelValue="opt.value" style="width: 100px">
                  {{ opt.label }}
                </wd-checkbox>
              </wd-checkbox-group>
            </template>
            <template v-else>
              {{
                formatProductAppearance(detailData.inspectionResult?.appearance).join("、") || "-"
              }}
            </template>
          </wd-form-item>
          <wd-form-item label="卷绕紧密" prop="windingTightness" required>
            <template v-if="isEdit">
              <wd-radio-group
                v-model="formData.windingTightness"
                inline
                class="conclusion-radio-group"
              >
                <wd-radio
                  v-for="(opt, idx) in sampleCompleteOptions"
                  :key="idx"
                  :value="opt.value"
                  shape="dot"
                >
                  {{ opt.label }}
                </wd-radio>
              </wd-radio-group>
            </template>
            <template v-else>
              {{ formatValue(detailData.inspectionResult?.windingTightness) }}
            </template>
          </wd-form-item>
          <wd-form-item label="排列整齐" prop="arrangementNeatness" required>
            <template v-if="isEdit">
              <wd-radio-group
                v-model="formData.arrangementNeatness"
                inline
                class="conclusion-radio-group"
              >
                <wd-radio
                  v-for="(opt, idx) in sampleCompleteOptions"
                  :key="idx"
                  :value="opt.value"
                  shape="dot"
                >
                  {{ opt.label }}
                </wd-radio>
              </wd-radio-group>
            </template>
            <template v-else>
              {{ formatValue(detailData.inspectionResult?.arrangementNeatness) }}
            </template>
          </wd-form-item>
          <wd-form-item
            label="外层铝线离侧板边缘距离"
            prop="aluminumWireDistance"
            label-width="360rpx"
            required
          >
            <template v-if="isEdit">
              <wd-input
                v-model="formData.aluminumWireDistance"
                placeholder="请输入距离(mm)"
                type="number"
              />
            </template>
            <template v-else>
              {{ formatValue(detailData.inspectionResult?.aluminumWireDistance, "mm") || "-" }}
            </template>
          </wd-form-item>
          <wd-form-item
            label="成品模后接头情况"
            prop="jointCondition"
            label-width="280rpx"
            required
          >
            <template v-if="isEdit">
              <wd-radio-group
                v-model="formData.jointCondition"
                inline
                class="conclusion-radio-group"
              >
                <wd-radio
                  v-for="(opt, idx) in jointConditionOptions"
                  :key="idx"
                  :value="opt.value"
                  shape="dot"
                >
                  {{ opt.label }}
                </wd-radio>
              </wd-radio-group>
            </template>
            <template v-else>
              {{ formatValue(detailData.inspectionResult?.jointCondition) || "-" }}
            </template>
          </wd-form-item>
          <wd-form-item label="结论" prop="conclusion" required>
            <template v-if="isEdit">
              <wd-radio-group v-model="formData.conclusion" inline class="conclusion-radio-group">
                <wd-radio
                  v-for="(opt, idx) in conclusionOptions"
                  :key="idx"
                  :value="opt.value"
                  shape="dot"
                >
                  {{ opt.label }}
                </wd-radio>
              </wd-radio-group>
            </template>
            <template v-else>
              {{ formatValue(detailData.inspectionResult?.conclusion) || "-" }}
            </template>
          </wd-form-item>
        </wd-col>
      </wd-row>
      <!-- å·¡æ£€ç»“æžœ -->
      <wd-row v-if="detailData.processInspectionResult?.isFully">
        <view style="margin: 10rpx">
          <text class="title">{{ "巡检结果" }}</text>
        </view>
        <wd-col :span="24">
          <wd-form-item label="铝杆前、中、尾样品是否齐全" prop="isFully" required>
            <template v-if="isEdit">
              <wd-radio-group v-model="formData.isFully" inline class="conclusion-radio-group">
                <wd-radio
                  v-for="(opt, idx) in sampleCompleteOptions"
                  :key="idx"
                  :value="opt.value"
                  shape="dot"
                >
                  {{ opt.label }}
                </wd-radio>
              </wd-radio-group>
            </template>
            <template v-else>
              <wd-tag
                custom-class="space"
                :type="detailData.processInspectionResult?.isFully ? 'success' : 'danger'"
              >
                {{ detailData.processInspectionResult?.isFully ? "是" : "否" }}
              </wd-tag>
            </template>
          </wd-form-item>
        </wd-col>
      </wd-row>
      <!-- é™„件模块 -->
      <wd-row class="attachment-section" v-if="detailData.files && detailData.files.length > 0">
        <view style="margin: 10rpx">
          <text class="title">{{ "附件" }}</text>
        </view>
        <view class="attachment-grid">
          <wd-col v-for="(file, index) in detailData.files" :key="index" class="attachment-item">
            <wd-img :width="80" :height="80" :src="file.url" @click="previewImage(file.url)">
              <template #error><view class="error-wrap">加载失败</view></template>
              <template #loading>
                <view class="loading-wrap"><wd-loading /></view>
              </template>
            </wd-img>
            <!-- <wd-icon
              v-if="isEdit"
              name="close-circle"
              class="delete-icon"
              @click.stop="deleteFile(index)"
            ></wd-icon> -->
          </wd-col>
          <wd-col v-if="isEdit" class="attachment-item upload-btn">
            <wd-upload
              :multiple="true"
              :max-count="5"
              :before-upload="beforeUpload"
              @success="handleUploadSuccess"
              @fail="handleUploadFail"
              accept="all"
        <wd-form-item label="外观" prop="appearance" required>
          <template v-if="isEdit">
            <wd-checkbox-group
              v-model="formData.appearance"
              inline
              v-for="(opt, idx) in appearanceOptions"
              :key="idx"
              style="text-align: justify"
            >
              <view class="upload-icon">+</view>
            </wd-upload>
          </wd-col>
        </view>
      </wd-row>
    </div>
              <wd-checkbox :modelValue="opt.value" style="width: 100px">
                {{ opt.label }}
              </wd-checkbox>
            </wd-checkbox-group>
          </template>
          <template v-else>
            {{ formatProductAppearance(formData.appearance) }}
          </template>
        </wd-form-item>
        <wd-form-item label="卷绕紧密" prop="windingTightness" required>
          <template v-if="isEdit">
            <wd-radio-group
              v-model="formData.windingTightness"
              inline
              class="conclusion-radio-group"
            >
              <wd-radio
                v-for="(opt, idx) in sampleCompleteOptions"
                :key="idx"
                :value="opt.value"
                shape="dot"
              >
                {{ opt.label }}
              </wd-radio>
            </wd-radio-group>
          </template>
          <template v-else>
            {{ formatValue(detailData.inspectionResult?.windingTightness) }}
          </template>
        </wd-form-item>
        <wd-form-item label="排列整齐" prop="arrangementNeatness" required>
          <template v-if="isEdit">
            <wd-radio-group
              v-model="formData.arrangementNeatness"
              inline
              class="conclusion-radio-group"
            >
              <wd-radio
                v-for="(opt, idx) in sampleCompleteOptions"
                :key="idx"
                :value="opt.value"
                shape="dot"
              >
                {{ opt.label }}
              </wd-radio>
            </wd-radio-group>
          </template>
          <template v-else>
            {{ formatValue(detailData.inspectionResult?.arrangementNeatness) }}
          </template>
        </wd-form-item>
        <wd-form-item
          label="外层铝线离侧板边缘距离"
          prop="aluminumWireDistance"
          label-width="360rpx"
          required
        >
          <template v-if="isEdit">
            <wd-input
              v-model="formData.aluminumWireDistance"
              placeholder="请输入距离(mm)"
              type="number"
            />
          </template>
          <template v-else>
            {{ formatValue(detailData.inspectionResult?.aluminumWireDistance, "mm") || "-" }}
          </template>
        </wd-form-item>
        <wd-form-item label="成品模后接头情况" prop="jointCondition" label-width="280rpx" required>
          <template v-if="isEdit">
            <wd-radio-group v-model="formData.jointCondition" inline class="conclusion-radio-group">
              <wd-radio
                v-for="(opt, idx) in jointConditionOptions"
                :key="idx"
                :value="opt.value"
                shape="dot"
              >
                {{ opt.label }}
              </wd-radio>
            </wd-radio-group>
          </template>
          <template v-else>
            {{ formatValue(detailData.inspectionResult?.jointCondition) || "-" }}
          </template>
        </wd-form-item>
        <wd-form-item label="结论" prop="conclusion" required>
          <template v-if="isEdit">
            <wd-radio-group v-model="formData.conclusion" inline class="conclusion-radio-group">
              <wd-radio
                v-for="(opt, idx) in conclusionOptions"
                :key="idx"
                :value="opt.value"
                shape="dot"
              >
                {{ opt.label }}
              </wd-radio>
            </wd-radio-group>
          </template>
          <template v-else>
            {{ formatValue(detailData.inspectionResult?.conclusion) || "-" }}
          </template>
        </wd-form-item>
      </wd-col>
    </wd-row>
    <!-- å·¡æ£€ç»“æžœ -->
    <wd-row v-if="detailData.processInspectionResult?.isFully">
      <view style="margin: 10rpx">
        <text class="title">{{ "巡检结果" }}</text>
      </view>
      <wd-col :span="24">
        <wd-form-item label="铝杆前、中、尾样品是否齐全" prop="isFully" required>
          <template v-if="isEdit">
            <wd-radio-group v-model="formData.isFully" inline class="conclusion-radio-group">
              <wd-radio
                v-for="(opt, idx) in sampleCompleteOptions"
                :key="idx"
                :value="opt.value"
                shape="dot"
              >
                {{ opt.label }}
              </wd-radio>
            </wd-radio-group>
          </template>
          <template v-else>
            <wd-tag
              custom-class="space"
              :type="detailData.processInspectionResult?.isFully ? 'success' : 'danger'"
            >
              {{ detailData.processInspectionResult?.isFully ? "是" : "否" }}
            </wd-tag>
          </template>
        </wd-form-item>
      </wd-col>
    </wd-row>
    <!-- é™„件模块 -->
    <wd-row class="attachment-section" v-if="detailData.files && detailData.files.length > 0">
      <view style="margin: 10rpx">
        <text class="title">{{ "附件" }}</text>
      </view>
      <wd-col :span="24">
        <AttachmentUpload
          :detailData="detailData"
          :isEdit="isEdit"
          :deviceType="paramsType"
          ref="attachmentRef"
        />
      </wd-col>
    </wd-row>
    <wd-popup v-model="show" custom-style="border-radius:32rpx;" @close="handleClose">
      <div class="image-preview">
        <img :src="previewImageUrl" alt="预览图片" style="width: 100%; height: auto" />
@@ -337,8 +304,11 @@
import RoutingInspectionApi from "@/api/routingInspection/routingInspection";
import Scan from "@/components/scan/index.vue";
import { useToast } from "wot-design-uni";
import AttachmentUpload from "../upload.vue";
// æ ¸å¿ƒçŠ¶æ€
const paramsId = ref("");
const paramsType = ref("");
const detailData = ref<any>({});
const show = ref(false);
const previewImageUrl = ref("");
@@ -347,13 +317,14 @@
const deviceUid = ref("");
const scanRef = ref();
const toast = useToast();
const attachmentRef = ref<any>(null);
// è¡¨å•数据
const formData = reactive({
  dia: "",
  maxDia: "",
  minDia: "",
  appearance: "",
  appearance: [],
  windingTightness: "",
  arrangementNeatness: "",
  aluminumWireDistance: "",
@@ -413,8 +384,8 @@
};
// æ ¼å¼åŒ–工具
const formatProductAppearance = (productAppearance: string) => {
  return !productAppearance ? "-" : productAppearance;
const formatProductAppearance = (productAppearance: string[]) => {
  return !productAppearance.length ? "-" : productAppearance.join("、");
};
const formatValue = (value: any, unit?: string) => {
@@ -438,7 +409,7 @@
  formData.dia = inspectionResult.dia || "";
  formData.maxDia = inspectionResult.maxDia || "";
  formData.minDia = inspectionResult.minDia || "";
  formData.appearance = inspectionResult.appearance || "";
  formData.appearance = inspectionResult.appearance || [];
  formData.windingTightness = inspectionResult.windingTightness || "";
  formData.arrangementNeatness = inspectionResult.arrangementNeatness || "";
  formData.aluminumWireDistance = inspectionResult.aluminumWireDistance || "";
@@ -462,6 +433,7 @@
// é¡µé¢åŠ è½½
onLoad((options: any) => {
  paramsId.value = options.id;
  paramsType.value = options.deviceType;
  getDetailData(options.id, options.deviceType);
});
@@ -482,7 +454,7 @@
  // æ ¡éªŒ
  if (!formData.maxDia) return uni.showToast({ title: "最大直径为必填项", icon: "none" });
  if (!formData.minDia) return uni.showToast({ title: "最小直径为必填项", icon: "none" });
  if (!formData.appearance) return uni.showToast({ title: "外观为必填项", icon: "none" });
  if (!formData.appearance.length) return uni.showToast({ title: "外观为必填项", icon: "none" });
  if (!formData.windingTightness) return uni.showToast({ title: "卷绕紧密为必填项", icon: "none" });
  if (!formData.arrangementNeatness)
    return uni.showToast({ title: "排列整齐为必填项", icon: "none" });
@@ -493,6 +465,9 @@
  if (!formData.conclusion) return uni.showToast({ title: "结论为必填项", icon: "none" });
  if (!formData.isFully) return uni.showToast({ title: "铝杆样品是否齐全为必填项", icon: "none" });
  if (!deviceUid.value) return uni.showToast({ title: "请扫描二维码", icon: "none" });
  const { newFiles } = attachmentRef.value.getSubmitFiles();
  console.log("newFiles", newFiles);
  const allFileIds = [...newFiles];
  // æäº¤
  try {
    const res = await RoutingInspectionApi.drawPatrolCheckInspection({
@@ -510,12 +485,12 @@
        conclusion: formData.conclusion,
      },
      inspectionResult: { isFully: formData.isFully },
      processInspectionAttachmentList: tempFiles.value.map((f) => f.url),
      processInspectionAttachmentList: allFileIds,
    });
    if (res.code === 200) {
      uni.showToast({ title: "保存成功", icon: "success" });
      isEdit.value = false;
      getDetailData(paramsId.value, detailData.value.deviceType);
      getDetailData(paramsId.value, paramsType.value);
    } else {
      uni.showModal({ title: res.msg || "保存失败", icon: "error" });
    }
@@ -523,56 +498,6 @@
    console.error("保存失败:", e);
    uni.showModal({ title: e.message || "保存失败", icon: "error" });
  }
};
// é™„件上传校验
const beforeUpload = (file: any) => {
  const maxSize = 2 * 1024 * 1024;
  if (file.size > maxSize) {
    uni.showToast({ title: "图片大小不能超过2M", icon: "none" });
    return false;
  }
  return true;
};
// é™„件上传成功
const handleUploadSuccess = (res: any) => {
  if (Array.isArray(res)) {
    tempFiles.value = [
      ...tempFiles.value,
      ...res.map((file) => ({
        ...file,
        id: `temp-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`,
      })),
    ];
  } else {
    tempFiles.value.push({
      ...res,
      id: `temp-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`,
    });
  }
};
// é™„件上传失败
const handleUploadFail = (err: any) => {
  uni.showToast({ title: "附件上传失败", icon: "error" });
};
// åˆ é™¤é™„ä»¶
const deleteFile = (index: number) => {
  if (index >= detailData.value.files.length) {
    tempFiles.value = tempFiles.value.filter(
      (_, idx) => idx !== index - detailData.value.files.length
    );
  } else {
    detailData.value.files = detailData.value.files.filter((_, idx) => idx !== index);
  }
};
// å›¾ç‰‡é¢„览
const previewImage = (url: string) => {
  previewImageUrl.value = url;
  show.value = true;
};
const handleClose = () => {
@@ -583,12 +508,10 @@
  scanRef.value.triggerScan();
};
const getScanCode = (params: any) => {
  console.log("完整参数:", params);
  let codeObj = {};
  try {
    codeObj = JSON.parse(params.code);
  } catch (err) {
    console.error("JSON解析失败:", err);
    toast.error("扫码数据异常");
    return; // è§£æžå¤±è´¥ç›´æŽ¥è¿”回,避免后续错误
  }
src/pages/routingInspection/upload.vue
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,359 @@
<template>
  <view class="attachment-container">
    <!-- å¤´éƒ¨æ“ä½œåŒº -->
    <view class="header-actions">
      <wd-button
        icon="file-add"
        :round="false"
        size="small"
        custom-class="add_btn"
        @click="addAttachment"
        v-if="isEdit"
      >
        æ–°å¢ž
      </wd-button>
    </view>
    <!-- é™„件列表 -->
    <view class="attachment-list">
      <wd-status-tip v-if="attachmentList.length === 0" image="content" tip="暂无附件" />
      <wd-card
        v-for="item in attachmentList"
        :key="item.id"
        type="rectangle"
        custom-class="attachment-card"
        :border="false"
      >
        <view class="attachment-item" @click="previewAttachment(item)">
          <view class="attachment-info">
            <view class="attachment-name">{{ item.bucketFileName || item.name }}</view>
            <view class="attachment-meta">
              <text class="file-type">{{ getFileType(item.bucketFileName) }}</text>
              <text class="upload-time">{{ formatTime(item.createTime) }}</text>
            </view>
          </view>
          <view class="attachment-actions" @click.stop v-if="isEdit">
            <wd-icon name="delete" color="#ff4757" @click="deleteAttachment(item.id)" />
          </view>
        </view>
      </wd-card>
    </view>
    <wd-toast />
  </view>
</template>
<script setup lang="ts">
import { ref, onMounted } from "vue";
import { useToast } from "wot-design-uni";
import AttachmentAPI from "@/api/product/attachment";
// å¤–部参数
const props = defineProps({
  detailData: { type: Object, default: () => ({}) },
  isEdit: { type: Boolean, default: false },
  deviceType: { type: String, default: "" },
});
const toast = useToast();
const attachmentList =
  props.deviceType == "1"
    ? ref<any[]>(props.detailData.value.files || [])
    : ref<any[]>(props.detailData.files || []);
const attachmentIds =
  props.deviceType == "1"
    ? ref<string[]>(props.detailData.value.attachmentId || [])
    : ref<string[]>(props.detailData.attachmentId || []);
// æ–°å¢žé™„ä»¶
const addAttachment = () => {
  // æ˜¾ç¤ºé€‰æ‹©æ–‡ä»¶ç±»åž‹çš„弹窗
  uni.showActionSheet({
    itemList: ["选择图片", "选择视频", "拍照", "录像"],
    success: (res) => {
      switch (res.tapIndex) {
        case 0: // é€‰æ‹©å›¾ç‰‡
          chooseImages();
          break;
        case 1: // é€‰æ‹©è§†é¢‘
          chooseVideos();
          break;
        case 2: // æ‹ç…§
          takePhoto();
          break;
        case 3: // å½•像
          recordVideo();
          break;
      }
    },
    fail: (error) => {
      console.error("选择文件类型失败:", error);
      toast.show("选择文件类型失败");
    },
  });
};
// é€‰æ‹©å›¾ç‰‡
const chooseImages = () => {
  uni.chooseImage({
    count: 9,
    sizeType: ["original", "compressed"],
    sourceType: ["album"],
    success: async (res) => {
      const filePaths = Array.isArray(res.tempFilePaths) ? res.tempFilePaths : [res.tempFilePaths];
      await handleFileUpload(filePaths);
    },
    fail: (error) => {
      console.error("选择图片失败:", error);
      toast.show("选择图片失败");
    },
  });
};
// é€‰æ‹©è§†é¢‘
const chooseVideos = () => {
  uni.chooseVideo({
    sourceType: ["album"],
    maxDuration: 60,
    camera: "back",
    success: async (res) => {
      await handleFileUpload([res.tempFilePath]);
    },
    fail: (error) => {
      console.error("选择视频失败:", error);
      toast.show("选择视频失败");
    },
  });
};
// æ‹ç…§
const takePhoto = () => {
  uni.chooseImage({
    count: 1,
    sizeType: ["original", "compressed"],
    sourceType: ["camera"],
    success: async (res) => {
      const filePaths = Array.isArray(res.tempFilePaths) ? res.tempFilePaths : [res.tempFilePaths];
      await handleFileUpload(filePaths);
    },
    fail: (error) => {
      console.error("拍照失败:", error);
      toast.show("拍照失败");
    },
  });
};
// å½•像
const recordVideo = () => {
  uni.chooseVideo({
    sourceType: ["camera"],
    maxDuration: 60,
    camera: "back",
    success: async (res) => {
      await handleFileUpload([res.tempFilePath]);
    },
    fail: (error) => {
      console.error("录像失败:", error);
      toast.show("录像失败");
    },
  });
};
// å¤„理文件上传
const handleFileUpload = async (filePaths: string[]) => {
  try {
    toast.show("正在上传...");
    // ä¸Šä¼ æ–‡ä»¶
    const uploadResults: any = await AttachmentAPI.uploadAttachmentFiles(filePaths);
    const result = uploadResults.map((it: any) => {
      return it.data;
    });
    console.log("result", result);
    // æ›´æ–°é™„件列表
    const flattenedResult = result.flat();
    attachmentList.value.push(...flattenedResult);
    console.log(attachmentList.value);
    // æå–附件ID
    attachmentIds.value = attachmentList.value.map((item: any) => item.id);
    toast.show("上传成功");
    console.log("111", attachmentIds.value.attachmentId);
  } catch (error) {
    console.error("上传失败:", error);
    toast.show("上传失败");
  }
};
// åˆ é™¤é™„ä»¶
const deleteAttachment = async (aid: number) => {
  try {
    uni.showModal({
      title: "确认删除",
      content: "确定要删除这个附件吗?",
      success: async (res) => {
        if (res.confirm) {
          // å‰ç«¯æ‰‹åŠ¨åˆ é™¤ï¼šç›´æŽ¥ä»Žåˆ—è¡¨ä¸­ç§»é™¤è¿™æ¡æ•°æ®
          attachmentList.value = attachmentList.value.filter((item) => item.id !== aid);
          // èŽ·å–å‰©ä½™çš„é™„ä»¶ID组合
          attachmentIds.value = attachmentList.value.map((item) => item.id).join(",");
          toast.show("删除成功");
        }
      },
    });
    console.log("111", attachmentIds.value.attachmentId);
  } catch (error) {
    console.error("删除失败:", error);
    toast.show("删除失败");
  }
};
// é¢„览附件
const previewAttachment = (item: any) => {
  // æ ¹æ®æ–‡ä»¶ç±»åž‹è¿›è¡Œé¢„览
  const fileName = item.bucketFileName || item.name;
  const fileType = getFileType(fileName);
  if (fileType.startsWith("image")) {
    // å›¾ç‰‡é¢„览
    uni.previewImage({
      urls: [item.url],
      current: item.url,
    });
  } else {
    // å…¶ä»–文件类型,可以下载或打开
    uni.downloadFile({
      url: item.url,
      success: (res) => {
        uni.openDocument({
          filePath: res.tempFilePath,
          success: () => {
            console.log("打开文档成功");
          },
          fail: (error) => {
            console.error("打开文档失败:", error);
            toast.show("无法预览此文件类型");
          },
        });
      },
      fail: (error) => {
        console.error("下载文件失败:", error);
        toast.show("下载文件失败");
      },
    });
  }
};
// èŽ·å–æ–‡ä»¶ç±»åž‹
const getFileType = (fileName: string) => {
  if (!fileName) return "unknown";
  const extension = fileName.split(".").pop()?.toLowerCase();
  switch (extension) {
    case "jpg":
    case "jpeg":
    case "png":
    case "gif":
    case "bmp":
    case "webp":
      return "image";
    case "pdf":
      return "pdf";
    case "doc":
    case "docx":
      return "word";
    case "xls":
    case "xlsx":
      return "excel";
    case "ppt":
    case "pptx":
      return "powerpoint";
    case "txt":
      return "text";
    case "zip":
    case "rar":
      return "archive";
    default:
      return "file";
  }
};
// æ ¼å¼åŒ–文件大小
const formatFileSize = (size: number) => {
  if (size < 1024) return size + " B";
  if (size < 1024 * 1024) return (size / 1024).toFixed(1) + " KB";
  return (size / (1024 * 1024)).toFixed(1) + " MB";
};
// æ ¼å¼åŒ–æ—¶é—´
const formatTime = (time: string) => {
  const date = new Date(time);
  return date.toLocaleString();
};
// å¯¹å¤–暴露方法:获取所有需提交的文件
const getSubmitFiles = () => ({
  newFiles: attachmentIds.value || [],
});
defineExpose({ getSubmitFiles });
</script>
<style lang="scss" scoped>
.attachment-container {
  padding: 12px;
  background: #f3f9f8;
  min-height: 100vh;
}
.header-actions {
  margin-bottom: 12px;
  :deep(.add_btn) {
    background: #0d867f;
    color: white;
    border: none;
  }
}
.attachment-list {
  .attachment-card {
    margin-bottom: 12px;
    border-radius: 4px;
  }
}
.attachment-item {
  display: flex;
  align-items: center;
  padding: 12px;
  .attachment-info {
    flex: 1;
    .attachment-name {
      font-size: 16px;
      font-weight: 500;
      color: #333;
      margin-bottom: 4px;
      word-break: break-all;
    }
    .attachment-meta {
      display: flex;
      gap: 12px;
      font-size: 12px;
      color: #999;
    }
  }
  .attachment-actions {
    margin-left: 12px;
    :deep(.wd-icon) {
      font-size: 20px;
      cursor: pointer;
    }
  }
}
</style>