<template>
  <view class="reservation-page">
    <view class="fixed-nav">
      <NavBar title="船只管理">
      </NavBar>
    </view>
    <view class="content-area">
      <view v-for="item in shipList" :key="item.id" class="ship-cell" @click="goDetail(item)">
        <view class="ship-title">
          船号: <text class="ship-no">{{ item.ship_number }}</text>
        </view>
        <view class="ship-row">所有人: {{ item.owner_name }}</view>
        <view class="ship-row">联系电话: {{ item.phone }}</view>
        <view class="ship-row">总吨位: {{ item.total_tonnage }} 吨</view>
      </view>
      <view class="add-cell-btn-bar">
        <button class="add-cell-btn" @click="goAdd">添加</button>
      </view>
    </view>
  </view>
</template>

<script>
import NavBar from '@/components/NavBar.vue'
import { API } from '@/config/index.js'
export default {
  name: 'ShipManagePage',
  components: { NavBar },
  data() {
    return {
      shipList: []
    }
  },
  onLoad() {
    this.fetchShipList();
  },
  methods: {
    async fetchShipList() {
      const token = uni.getStorageSync('token');
      if (!token) {
        uni.showToast({ title: '请先登录', icon: 'none' });
        return;
      }
      uni.showLoading({ title: '加载中...' });
      try {
        console.log(API.SHIP_INDEX)
        const res = await new Promise((resolve, reject) => {
          uni.request({
            url: API.SHIP_INDEX,
            method: 'GET',
            data: { token },
            success: resolve,
            fail: reject
          });
        });
        uni.hideLoading();
        if (res.data && res.data.errcode === 0) {
          this.shipList = res.data.data || [];
        } else {
          uni.showToast({ title: res.data.errmsg || '获取失败', icon: 'none' });
        }
      } catch (error) {
        uni.hideLoading();
        uni.showToast({ title: error.message || '网络错误', icon: 'none' });
      }
    },
    goAdd() {
      uni.navigateTo({ url: '/pages/index/ship_add' })
    },
    goDetail(item) {
      const itemStr = encodeURIComponent(JSON.stringify(item));
      uni.navigateTo({
        url: `/pages/index/ship_detail?id=${item.id}&item=${itemStr}`
      })
    }
  }
}
</script>

<style scoped>
.reservation-page {
  background: linear-gradient(180deg, #eaf3ff 0%, #f6faff 100%);
  min-height: 100vh;
  padding-bottom: 40rpx;
}
.fixed-nav {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  background: linear-gradient(180deg, #cbe6ff 0%, #f6faff 100%);
  box-shadow: 0 2px 8px rgba(0,0,0,0.04);
}
.content-area {
  padding: 220rpx 24rpx 24rpx 24rpx;
}
.ship-cell {
  background: #fff;
  border-radius: 16rpx;
  box-shadow: 0 2rpx 8rpx rgba(0,0,0,0.04);
  padding: 32rpx 28rpx;
  margin-bottom: 32rpx;
  border: 1rpx solid #e5e5e5;
}
.ship-title {
  font-size: 30rpx;
  font-weight: bold;
  margin-bottom: 18rpx;
}
.ship-no {
  color: #222;
  font-weight: bold;
  font-size: 32rpx;
}
.ship-row {
  font-size: 26rpx;
  color: #222;
  margin-bottom: 10rpx;
}
.add-btn {
  position: absolute;
  right: 32rpx;
  top: 50%;
  transform: translateY(-50%);
  z-index: 10;
  font-size: 44rpx;
  color: #217aff;
}
.add-cell-btn-bar {
  display: flex;
  justify-content: center;
  margin-top: 32rpx;
}
.add-cell-btn {
  min-width: 420rpx;
  height: 80rpx;
  border-radius: 40rpx;
  background: #217aff;
  color: #fff;
  font-size: 32rpx;
  font-weight: 500;
  border: none;
  outline: none;
  box-shadow: 0 4rpx 16rpx rgba(33,122,255,0.08);
  transition: background 0.2s;
}
</style> 