spring
2 天以前 6e763136fdf4469143ebbae0b717eb8e9b0ca954
src/pages/routingInspection/detail/indexLS.vue
@@ -34,326 +34,311 @@
        保存
      </wd-button>
      <view class="placeholder"></view>
      <view class="scan-info">
        <text class="scan-device-text">当前扫码机台: {{ scannedDeviceModel || "未扫码" }}</text>
      </view>
      <view class="scan-wrapper" @click="openScan">
        <wd-icon name="scan" size="24px" color="#0D867F"></wd-icon>
      </view>
    </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
        <wd-form-item label="外观" prop="appearance" required>
          <template v-if="isEdit">
            <view style="display: flex; flex-wrap: wrap; gap: 10px">
              <wd-checkbox
                v-for="(opt, idx) in appearanceOptions"
                :key="idx"
                style="text-align: justify"
                :value="opt.value"
                :modelValue="formData.appearance?.includes(opt.value) || false"
                @click="handleAppearanceClick(opt.value)"
                style="width: 100px"
              >
                <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>
                {{ opt.label }}
              </wd-checkbox>
            </view>
          </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>
        <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="windingTightness" required>
          <template v-if="isEdit">
            <wd-radio-group
              v-model="formData.windingTightness"
              inline
              class="conclusion-radio-group"
            >
              <view class="upload-icon">+</view>
            </wd-upload>
          </wd-col>
        </view>
      </wd-row>
    </div>
              <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" />
      </div>
    </wd-popup>
    <Scan ref="scanRef" emitName="scan" />
    <wd-toast />
  </view>
</template>
<script setup lang="ts">
import { ref, reactive } from "vue";
import { onLoad } from "@dcloudio/uni-app";
import { ref, reactive, computed, onUnmounted } from "vue";
import { onLoad, onShow, onHide } from "@dcloudio/uni-app";
import RoutingInspectionApi from "@/api/routingInspection/routingInspection";
import Scan from "@/components/scan/index.vue";
import { useToast } from "wot-design-uni";
import AttachmentUpload from "../upload.vue";
import { useUserStore } from "@/store/modules/user";
import { useScanCode } from "@/composables/useScanCode";
// 核心状态
const paramsId = ref("");
const paramsType = ref("");
const detailData = ref<any>({});
const show = ref(false);
const previewImageUrl = ref("");
const isEdit = ref(false);
const tempFiles = ref<any[]>([]);
const deviceUid = ref("");
const scanRef = ref();
const toast = useToast();
const attachmentRef = ref<any>(null);
// 获取当前登录用户信息
const userStore = useUserStore();
const userInfo: any = computed(() => userStore.userInfo);
// 使用扫码管理 composable(全局监听器,不随页面切换关闭)
const {
  deviceUid,
  deviceModel: scannedDeviceModel,
  loadFromCache,
  enableListener,
} = useScanCode("scanLS");
// 表单数据
const formData = reactive({
  dia: "",
  maxDia: "",
  minDia: "",
  appearance: "",
  appearance: [] as string[],
  windingTightness: "",
  arrangementNeatness: "",
  aluminumWireDistance: "",
@@ -389,11 +374,11 @@
    case 1:
      return "danger";
    case 2:
      return "info";
      return "primary";
    case 3:
      return "success";
    default:
      return "info";
      return "default";
  }
};
@@ -413,8 +398,46 @@
};
// 格式化工具
const formatProductAppearance = (productAppearance: string) => {
  return !productAppearance ? "-" : productAppearance;
const formatProductAppearance = (productAppearance: string[]) => {
  if (!productAppearance || !Array.isArray(productAppearance) || !productAppearance.length) {
    return "-";
  }
  return productAppearance.join("、");
};
// 处理外观选择的互斥逻辑
const handleAppearanceClick = (value: string) => {
  // 确保 appearance 是数组
  if (!Array.isArray(formData.appearance)) {
    formData.appearance = [];
  }
  const currentValues = [...formData.appearance];
  const isCurrentlyChecked = currentValues.includes(value);
  let newSelection: string[] = [];
  if (value === "无外观问题") {
    if (isCurrentlyChecked) {
      // 取消选中"无外观问题"
      newSelection = [];
    } else {
      // 选中"无外观问题",清空其他选项
      newSelection = ["无外观问题"];
    }
  } else {
    // 点击其他选项
    if (isCurrentlyChecked) {
      // 取消选中该选项
      newSelection = currentValues.filter((v) => v !== value);
    } else {
      // 选中该选项,移除"无外观问题"
      const filteredValues = currentValues.filter((v) => v !== "无外观问题");
      newSelection = [...filteredValues, value];
    }
  }
  formData.appearance = newSelection;
};
const formatValue = (value: any, unit?: string) => {
@@ -438,7 +461,12 @@
  formData.dia = inspectionResult.dia || "";
  formData.maxDia = inspectionResult.maxDia || "";
  formData.minDia = inspectionResult.minDia || "";
  formData.appearance = inspectionResult.appearance || "";
  // 确保 appearance 是数组
  formData.appearance = Array.isArray(inspectionResult.appearance)
    ? inspectionResult.appearance
    : inspectionResult.appearance
      ? [inspectionResult.appearance]
      : [];
  formData.windingTightness = inspectionResult.windingTightness || "";
  formData.arrangementNeatness = inspectionResult.arrangementNeatness || "";
  formData.aluminumWireDistance = inspectionResult.aluminumWireDistance || "";
@@ -452,6 +480,13 @@
  try {
    const response = await RoutingInspectionApi.getDrawInspectInfoById({ id });
    detailData.value = response.data;
    // 如果巡检员为空,默认设置为当前登录用户
    if (!detailData.value.processInspectionUserName) {
      detailData.value.processInspectionUserName =
        userInfo.value?.nickName || userInfo.value?.userName || "";
    }
    tempFiles.value = [];
    initFormData();
  } catch (error) {
@@ -462,6 +497,7 @@
// 页面加载
onLoad((options: any) => {
  paramsId.value = options.id;
  paramsType.value = options.deviceType;
  getDetailData(options.id, options.deviceType);
});
@@ -482,7 +518,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" });
@@ -492,7 +528,19 @@
    return uni.showToast({ title: "成品模后接头情况为必填项", icon: "none" });
  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" });
  // 验证扫码数据(从缓存或新扫码获取)
  console.log("保存前检查 deviceUid:", deviceUid.value);
  if (!deviceUid.value) {
    return uni.showToast({
      title: "请先扫描设备二维码",
      icon: "none",
      duration: 2000,
    });
  }
  const { newFiles } = attachmentRef.value.getSubmitFiles();
  console.log("newFiles", newFiles);
  const allFileIds = [...newFiles];
  // 提交
  try {
    const res = await RoutingInspectionApi.drawPatrolCheckInspection({
@@ -510,12 +558,23 @@
        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);
      // 设置刷新标记,告诉列表页需要刷新
      uni.setStorageSync("needRefreshInspectionList", true);
      uni.showToast({
        title: "保存成功",
        icon: "success",
        duration: 1500,
      });
      // 延迟返回列表页,让用户看到成功提示
      setTimeout(() => {
        uni.navigateBack({
          delta: 1,
        });
      }, 1500);
    } else {
      uni.showModal({ title: res.msg || "保存失败", icon: "error" });
    }
@@ -525,90 +584,41 @@
  }
};
// 附件上传校验
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 = () => {
  show.value = false;
};
const openScan = () => {
  scanRef.value.triggerScan();
  console.log("indexLS - 点击扫码按钮(全局扫码模式,无需手动触发)");
  // 全局扫码模式下,硬件扫码会自动触发,无需手动调用
  uni.showToast({
    title: "请使用扫码枪扫描",
    icon: "none",
  });
};
const getScanCode = (params: any) => {
  console.log("完整参数:", params);
  let codeObj = {};
  try {
    codeObj = JSON.parse(params.code);
  } catch (err) {
    console.error("JSON解析失败:", err);
    toast.error("扫码数据异常");
    return; // 解析失败直接返回,避免后续错误
// 页面显示时的处理
onShow(() => {
  console.log("========== indexLS - onShow 触发 ==========");
  // 重新启用监听器(确保监听器有效)
  enableListener();
  // 加载缓存(更新UI显示)
  const cachedData = loadFromCache();
  // 如果没有缓存数据,提示用户需要扫码
  if (!cachedData || !cachedData.uid) {
    console.log("⚠️ 未检测到扫码缓存,用户需要扫描设备二维码");
    // 在编辑模式下才提示
    if (isEdit.value) {
      setTimeout(() => {
        uni.showToast({
          title: "请扫描设备二维码后再保存",
          icon: "none",
          duration: 2000,
        });
      }, 500);
    }
  }
  deviceUid.value = codeObj?.uid;
  toast.success("扫码成功");
};
// 确保先移除再添加监听
const setupScanListener = () => {
  uni.$off("scan", getScanCode); // 先移除旧的
  uni.$on("scan", getScanCode); // 再添加新的
};
onUnmounted(() => {
  // 开启广播监听事件
  uni.$off("scan", getScanCode);
  console.log("离开1");
});
onMounted(() => {
  // 开启广播监听事件
  setupScanListener();
  console.log("显示1");
});
</script>
@@ -636,6 +646,18 @@
.placeholder {
  flex: 1;
}
.scan-info {
  display: flex;
  align-items: center;
  margin-right: 10px;
  .scan-device-text {
    font-size: 14px;
    color: #0d867f;
    font-weight: 500;
  }
}
.scan-wrapper {
@@ -758,4 +780,4 @@
  align-items: flex-start; // 垂直方向顶部对齐(上移关键)
  gap: 20rpx; // 选项之间的间距
}
</style>
</style>