<template>
  <view class="page">
    <view class="borrow-list">
      <view v-for="item in detailList" :key="item.assetId" class="borrow-item card">
        <view class="item-header"><text class="asset-name">{{ item.assetName }}</text></view>
        <view class="content">
          <view class="row">📅 盘点日期：<text class="value">{{ item.inventoryDate }}</text></view>
          <view class="row">👤 盘点人：<text class="value">{{ item.inventoryManName }}</text></view>
          <view class="row">📝 备注：<text class="value">{{ item.note || '无' }}</text></view>
        </view>
        <view class="result-row">
          <text class="label">盘点结果：</text>
          <text class="result normal" v-if="item.inventoryResult==0">正常</text>
          <text class="result damaged" v-else-if="item.inventoryResult==1">损坏</text>
          <text class="result lost" v-else-if="item.inventoryResult==2">丢失</text>
          <text class="result unknown" v-else>未知</text>
        </view>
      </view>
    </view>
    <view class="none" v-if="detailList.length===0">没有更多数据了</view>
  </view>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import { onLoad } from '@dcloudio/uni-app'
// @ts-ignore JS模块无类型声明
import { getInventoryDetailEnd } from '@/pages/api/fixedAssets.js'

const planId = ref<string | number | null>(null)
const detailList = ref<any[]>([])

onLoad(async (options?: Record<string, any>) => {
  planId.value = options?.planId || null
  if (!planId.value) return
  await loadDetail()
})

async function loadDetail() {
  try {
    const res: any = await getInventoryDetailEnd(planId.value)
    detailList.value = res?.data || []
  } catch (e) {
    console.error(e)
    uni.showToast({ title: '加载失败', icon: 'none' })
  }
}
</script>

<style scoped>
.page { min-height: 100vh; background: #f5f7fb; padding: 24rpx; }
.card { background: #fff; border-radius: 20rpx; box-shadow: 0 8rpx 24rpx rgba(0,0,0,0.06); padding: 20rpx; margin-bottom: 16rpx; }
.asset-name { font-size: 30rpx; color: #222; font-weight: 600; }
.row { font-size: 24rpx; color: #666; margin-top: 6rpx; }
.result-row { margin-top: 8rpx; }
.label { font-size: 24rpx; color: #666; margin-right: 8rpx; }
.result { font-size: 24rpx; }
.result.normal { color: #38b000; }
.result.damaged { color: #ff6b6b; }
.result.lost { color: #f39c12; }
.result.unknown { color: #999; }
.none { text-align: center; color: #9a9aa0; margin-top: 20rpx; }
.value { color: #333; }
</style>
