<template>
  <div class="home">
    <van-nav-bar title="冰雪灾害" fixed left-arrow @click-left="onClickLeft" />

    <van-cell-group>
      <van-cell title="当前站点" :value="yhzDetail.mc" />
    </van-cell-group>

    <div class="content">
      <van-cell-group>
        <van-cell
          title="基本信息"
          style="font-size: 18px; font-weight: bold; line-height: inherit"
        >
        </van-cell>
        <van-cell :title="'发生时间： ' + eventDetailData?.event?.occurTime">
        </van-cell>
        <van-cell
          :title="'发生地点： ' + eventDetailData?.event?.occurLocation"
        >
        </van-cell>
        <van-cell :title="'起点桩号： ' + eventDetailData?.event?.startStakeNo">
        </van-cell>
        <van-cell :title="'止点桩号： ' + eventDetailData?.event?.endStakeNo">
        </van-cell>
        <van-cell
          :title="'受灾里程： ' + eventDetailData?.event?.disasterMileage"
        >
        </van-cell>
        <van-cell :title="'填报人： ' + eventDetailData?.event?.reporterName">
        </van-cell>
        <van-cell :title="'填报时间： ' + eventDetailData?.event?.reportTime">
        </van-cell>
      </van-cell-group>
      <van-cell-group>
        <van-cell
          title="处置情况"
          style="font-size: 18px; font-weight: bold; line-height: inherit"
        >
        </van-cell>
        <van-cell
          :title="'处置措施： ' + eventDetailData?.event?.disposalMeasures"
        >
        </van-cell>
        <van-cell
          :title="'预计恢复时间： ' + eventDetailData?.event?.expectRecoverTime"
        >
        </van-cell>
      </van-cell-group>
      <van-cell-group>
        <van-cell
          title="实施情况"
          style="font-size: 18px; font-weight: bold; line-height: inherit"
        >
        </van-cell>
        <van-cell
          :title="
            '投入人力： ' + eventDetailData?.material?.inputManpower + ' 人次'
          "
        >
        </van-cell>
        <van-cell
          :title="
            '投入资金： ' + eventDetailData?.material?.inputFunds + ' 万元'
          "
        >
        </van-cell>
        <van-cell
          :title="
            '投入设备： ' + eventDetailData?.material?.inputEquipment + ' 台班'
          "
        >
        </van-cell>
        <van-cell
          v-for="(item, index) in eventDetailData?.materialUsageList"
          :key="index"
          :title="`${item.materialName}：${item.usageAmount} ${item.materialUnit}`"
        >
        </van-cell>
        <van-cell
          :title="`当前通行状况：${
            { 1: '正常通行', 2: '限速通行', 3: '封闭交通' }[
              eventDetailData?.traffic?.currentStatus
            ] || '未知状态'
          }`"
        >
        </van-cell>
        <van-cell
          :title="`有无车辆滞留：${
            { 0: '无', 1: '有' }[
              eventDetailData?.traffic?.hasStrandedVehicles
            ] || '未知状态'
          }`"
        >
        </van-cell>
        <van-cell
          v-if = 'eventDetailData?.traffic?.hasStrandedVehicles === 1'
          :title="
            '滞留车辆数：' + eventDetailData?.traffic?.strandedVehicleCount + ' 辆'
          "
        >
        </van-cell>
        <van-cell
          :title="
            '实际恢复时间： ' + eventDetailData?.traffic?.actualRecoverTime
          "
        >
        </van-cell>
        <van-cell
          :title="
            '附件： '
          "
        >
          <template #label>
            <van-image
              v-for="(item, index) in eventDetailData?.photos"
              :key="index"
              :src="item.photoUrl"
              fit="cover"
              width="100px"
              @click="showImage(item.photoUrl)"
            ></van-image>
          </template>
        </van-cell>
      </van-cell-group>
    </div>
  </div>
</template>
    
    <script setup>
import { ref, onMounted, toRaw, reactive } from "vue";
import { useRouter, useRoute } from "vue-router";
import { showToast, showLoadingToast, showImagePreview } from "vant";
import { request } from "../../../../shared/utils/request";

const router = useRouter();
const route = useRoute();

const yhzDetail = ref({});
const event = ref();
const eventDetailData = ref({}); // 冰雪事件详情数据

// 获取冰雪事件详情数据
const getEventDetailData = async () => {
  try {
    const res = await request({
      url: `/snow-ops-platform/event/getById?id=${event.value.id}`,
      method: "GET",
    });
    if (res.code === "00000") {
      eventDetailData.value = res.data;
    } else {
      throw new Error(res.message);
    }
  } catch (error) {
    showToast({
      message: error.message,
      type: "fail",
    });
  }
};

onMounted(() => {
  const data = JSON.parse(decodeURIComponent(route.params.data));
  yhzDetail.value = data.yhzDetail;
  event.value = data.event;
  getEventDetailData();
});

const onClickLeft = () => {
  router.push({
    name: "IceEventManage",
    params: { data: encodeURIComponent(JSON.stringify(yhzDetail.value)) },
  });
};

const showImage = (url) => {
  showImagePreview([url]);
};
</script>
    
    <style scoped>
.home {
  padding-top: var(--van-nav-bar-height); /* 自动匹配导航栏高度 */
}

.content {
  padding: 16px;
}

.grid {
  margin-top: 16px;
}

.btn {
  margin-top: 24px;
}

.status-tag {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 4px;
  color: white;
  font-size: 12px;
}
.status-good {
  background-color: #07c160;
}
.status-warning {
  background-color: #ff976a;
}
.status-danger {
  background-color: #ee0a24;
}
</style>
    