// pages/warning/warning.js
const auth = require('../../utils/auth.js');

Page({
  data: {
    farms: [
      {
        id: '13847540178',
        name: '13847540178_养殖场',
        warnings: {
          notInventoried: 0,
          abnormalSteps: 0,
          collarCut: 0,
          hostDisconnected: 0
        }
      },
      {
        id: '15848532959',
        name: '15848532959_养殖场',
        warnings: {
          notInventoried: 0,
          abnormalSteps: 0,
          collarCut: 0,
          hostDisconnected: 0
        }
      },
      {
        id: '15848525265',
        name: '15848525265_养殖场',
        warnings: {
          notInventoried: 0,
          abnormalSteps: 0,
          collarCut: 0,
          hostDisconnected: 0
        }
      },
      {
        id: '15849585844',
        name: '15849585844_养殖场',
        warnings: {
          notInventoried: 0,
          abnormalSteps: 0,
          collarCut: 0,
          hostDisconnected: 0
        }
      }
    ]
  },

  onLoad() {
    // 检查认证状态
    if (!auth.isAuthenticated()) {
      wx.reLaunch({
        url: '/pages/login/login'
      });
      return;
    }
    
    console.log('日检预警页面加载');
  },

  onShow() {
    // 检查认证状态
    if (!auth.isAuthenticated()) {
      wx.reLaunch({
        url: '/pages/login/login'
      });
      return;
    }
    
    console.log('日检预警页面显示');
  },

  // 查看今日预警详情
  viewTodayWarnings() {
    wx.showToast({
      title: '今日预警详情',
      icon: 'none'
    });
  },

  // 查看养殖场详情
  viewFarmDetail(e) {
    const farmId = e.currentTarget.dataset.farmId;
    wx.showToast({
      title: `查看养殖场 ${farmId}`,
      icon: 'none'
    });
  }
});