// pages/production/production.js - 生产管理页面
Page({
  data: {
    productionList: [],
    stats: {
      total: 0,
      today: 0,
      thisMonth: 0
    },
    loading: false
  },

  onLoad() {
    console.log('生产管理页加载')
    this.loadProductionData()
  },

  onShow() {
    console.log('生产管理页显示')
    this.loadProductionData()
  },

  onPullDownRefresh() {
    this.loadProductionData()
    setTimeout(() => {
      wx.stopPullDownRefresh()
    }, 1000)
  },

  // 加载生产数据
  loadProductionData() {
    this.setData({ loading: true })
    
    // TODO: 从API加载生产数据
    // 模拟数据
    setTimeout(() => {
      this.setData({
        stats: {
          total: 120,
          today: 5,
          thisMonth: 42
        },
        productionList: [
          { id: 1, cattleId: 'C001', earTag: 'ET001', type: '产奶', amount: 25, unit: 'L', date: '2024-01-15' },
          { id: 2, cattleId: 'C002', earTag: 'ET002', type: '产奶', amount: 28, unit: 'L', date: '2024-01-15' },
          { id: 3, cattleId: 'C003', earTag: 'ET003', type: '产奶', amount: 22, unit: 'L', date: '2024-01-14' }
        ],
        loading: false
      })
    }, 500)
  },

  // 添加生产记录
  addProduction() {
    wx.showToast({
      title: '功能开发中',
      icon: 'none'
    })
  },

  // 查看生产详情
  viewProductionDetail(e) {
    const id = e.currentTarget.dataset.id
    wx.showToast({
      title: '功能开发中',
      icon: 'none'
    })
  }
})

