order-detail.vue 6.24 KB
<template>
  <view class="page-container">
    <!-- 页面级加载组件 -->
    <up-loading-page
        v-if="loading"
        :loading="true"
        title="加载中..."
        color="#2563EB"
    ></up-loading-page>

    <!-- 内容容器 -->
    <view v-else class="content-wrap">
      <!-- 空状态 -->
      <view v-if="!Object.keys(orderDetail).length" >
        <empty-view />
      </view>

      <!-- 工单详情内容 -->
      <view class="page-body" v-else>
        <!-- 工单名称 -->
        <view class="form-card form-card--title">
          <view class="card-title">{{ orderDetail.orderName || '无工单名称' }}</view>
        </view>

        <!-- 工单信息 -->
        <view class="form-card">
          <view class="sec-head">
            <view class="sec-bar"></view>
            <view class="sec-title">工单信息</view>
          </view>

          <view class="u-body-item u-flex">
            <view class="u-body-item-title">工单编号:</view>
            <view class="u-line-1 u-body-value">{{ orderDetail.orderNo || '--' }}</view>
          </view>
          <view class="u-body-item u-flex">
            <view class="u-body-item-title">工单道路:</view>
            <view class="u-line-1 u-body-value">{{ orderDetail.roadName || '--' }}</view>
          </view>
          <view class="u-body-item u-flex">
            <view class="u-body-item-title">工单位置:</view>
            <view class="u-line-1 u-body-value">{{ orderDetail.lonLatAddress || '--' }}</view>
          </view>
          <view class="u-body-item u-flex">
            <view class="u-body-item-title">问题类型:</view>
            <view class="u-line-1 u-body-value">{{ orderDetail.orderName || '--' }}</view>
          </view>
        </view>

        <!-- 情况描述 -->
        <view class="form-card">
          <view class="sec-head">
            <view class="sec-bar"></view>
            <view class="sec-title">情况描述</view>
          </view>
          <view class="desc-text">{{ orderDetail.remark || '--' }}</view>
        </view>

        <!-- 问题照片 -->
        <view class="form-card">
          <view class="sec-head">
            <view class="sec-bar"></view>
            <view class="sec-title">问题照片</view>
          </view>
          <view class="cell-content-wrap">
            <up-album
                :urls="orderDetail.problemsImgs"
                singleSize="70"
                multipleSize="70"
                :preview-full-image="true"
            ></up-album>
          </view>
        </view>

        <!-- 完成照片 -->
        <view class="form-card">
          <view class="sec-head">
            <view class="sec-bar"></view>
            <view class="sec-title">完成照片</view>
          </view>
          <view class="cell-content-wrap">
            <up-album
                :urls="orderDetail.endImgs"
                singleSize="70"
                multipleSize="70"
                :preview-full-image="true"
            ></up-album>
          </view>
        </view>

        <!-- 处理结果 -->
        <view class="form-card">
          <view class="sec-head">
            <view class="sec-bar"></view>
            <view class="sec-title">处理结果</view>
          </view>
          <view class="desc-text">{{ orderDetail.handleResult || '--' }}</view>
        </view>
      </view>
    </view>
  </view>
</template>

<script setup lang="ts">
import { ref } from 'vue';
import { inspectionPlanDetail } from "@/api/quick-order/quick-order";
import { onLoad } from '@dcloudio/uni-app';

// 给orderDetail指定类型,明确图片数组的类型
interface OrderDetail {
  problemsImgs?: string[];
  endImgs?: string[];
  [key: string]: any; // 兼容其他属性
}

// 初始化时给图片数组赋空数组,避免模板解析时访问undefined
const orderDetail = ref<OrderDetail>({
  problemsImgs: [],
  endImgs: []
});
const loading = ref(true);

/**
 * 获取工单详情
 */
const getOrderDetail = async (id: string) => {
  try {
    loading.value = true;
    const res = await inspectionPlanDetail({ id });
    console.log('接口返回problemsImgs:', res.problemsImgs); // 确认数据存在
    // 修复3:解构赋值时,强制保证图片数组为数组类型
    orderDetail.value = {
      ...res,
      problemsImgs: Array.isArray(res.problemsImgs) ? res.problemsImgs : [],
      endImgs: Array.isArray(res.endImgs) ? res.endImgs : []
    };
  } catch (error) {
    console.error('获取工单详情失败:', error);
    uni.showToast({ title: '加载失败,请重试', icon: 'none' });
  } finally {
    loading.value = false;
  }
};

onLoad((options) => {
  const { id } = options;
  if (id) {
    getOrderDetail(id);
  } else {
    loading.value = false;
    uni.showToast({ title: '缺少工单ID', icon: 'none' });
  }
});
</script>

<style scoped lang="scss">
/* 统一卡片样式(与工单/巡查详情页一致) */
.page-container {
  min-height: 100vh;
  padding-bottom: 40rpx;
  background-color: #F4F6FA;
  box-sizing: border-box;
}

// 内容容器
.content-wrap {
  width: 100%;
  box-sizing: border-box;
}
.page-body {
  padding: 0 24rpx;
}

// 白色卡片:8px 圆角 + 卡片阴影(设计稿 .card)
.form-card {
  margin-top: 24rpx;
  padding: 8rpx 24rpx 24rpx;
  background-color: #ffffff;
  border-radius: 16rpx;
  box-shadow: 0 4rpx 16rpx rgba(17, 24, 39, 0.06);
}

// 区块标题:蓝色竖条 + 标题文字
.sec-head {
  display: flex;
  align-items: center;
  gap: 12rpx;
  padding: 20rpx 0 8rpx;
}
.sec-bar {
  width: 6rpx;
  height: 28rpx;
  background-color: #2563EB;
  border-radius: 3rpx;
}
.sec-title {
  font-size: 30rpx;
  font-weight: 500;
  color: #1F2937;
}

/* 工单名称卡片 */
.form-card--title {
  padding: 28rpx 24rpx;
}
.card-title {
  font-size: 32rpx;
  font-weight: 500;
  color: #1F2937;
  line-height: 1.4;
}

/* 信息行 */
.form-card .u-body-item {
  margin-bottom: 12rpx;

  &:last-of-type {
    margin-bottom: 0;
  }
}

/* 长文本(情况描述 / 处理结果) */
.desc-text {
  padding-top: 12rpx;
  font-size: 28rpx;
  color: #1F2937;
  line-height: 1.6;
  word-break: break-all;
}

.cell-content-wrap {
  padding-top: 12rpx;
  :deep(image) { // 小程序中图片标签是image,且需要穿透样式隔离
    width: 70px !important;
    height: 70px !important;
  }
}
</style>