<template>
  <div class="home">
    <van-nav-bar title="确认物资" fixed left-arrow @click-left="onClickLeft" />

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

    <div class="content" v-if="pendingConfirmList">
      <van-cell-group>
        <van-cell
          v-for="(item, index) in pendingConfirmList"
          :key="index"
          :title="item.wzmc"
          is-link
          :label="`余量：${item.ye}(${item.dw})`"
          :to="{
            name: 'MaterialDetail',
            params: {
              data: encodeURIComponent(
                JSON.stringify({
                  material: item,
                  yhzDetail: yhzInfo,
                  isConfirm: true,
                })
              ),
            },
          }"
        >
        </van-cell>
      </van-cell-group>
    </div>
  </div>
</template>

<script setup>
import { ref, onMounted, reactive, toRaw, watch } from "vue";
import { useRouter, useRoute } from "vue-router";
import { showToast, showLoadingToast } from "vant";

import { request } from "../../../../shared/utils/request";

const router = useRouter();
const route = useRoute();
const yhzInfo = ref({}); // 养护站详情数据
const pendingConfirmList = ref([]); // 待确认列表数据

// 获取养护站详情数据
onMounted(() => {
  yhzInfo.value = JSON.parse(decodeURIComponent(route.params.data));
  console.log("yhzInfo", toRaw(yhzInfo.value));
  getPendingConfirmList();
});

const getPendingConfirmList = async () => {
  try {
    const data = {
      yhzid: yhzInfo.value.id,
      pageNum: 1,
      pageSize: 9999,
    };
    const res = await request({
      url: "/snow-ops-platform/yjwz/pendingConfirmList",
      method: "get",
      params: data,
    });
    if (res.code === "00000") {
      pendingConfirmList.value = res.data.records;
    } else {
      throw new Error(res.message);
    }
  } catch (error) {
    showToast({
      type: "fail",
      message: error.message,
    });
    console.log("error", error);
  }
};

const onClickLeft = () => {
  router.push({
    name: "MaterialManage",
    params: { data: encodeURIComponent(JSON.stringify(yhzInfo.value)) },
  });
};
</script>

<style>
.home {
  padding-top: var(--van-nav-bar-height); /* 自动匹配导航栏高度 */
}
.content {
  padding: 16px 16px 80px 16px;
}
</style>