// pages/gate/index.js
import HTTP from "../../../requestFn/Api"
const app = getApp()
Page({

  data: {
    garden_id: null,
    gate_list: [],
    tabbar: {},
  },
  onLoad() {
    const {unreadCountGate} = app.globalData;
    this.setData({unreadCountGate});
    getApp().watch('unreadCountGate', this.watchBack);
    app.editTabbar();
  },
  watchBack(name, value) {
    let data = {};
    data[name] = value;
    this.setData(data);
  },
  onShow(options) {
    const that = this;
    const {
      garden_id
    } = app.globalData;
    if (garden_id) {
      that.setData({
        garden_id
      })
    }
    that.getGate(garden_id)
  },
  //获取门禁列表
  getGate(garden_id) {
    const that = this;
    HTTP.GetGate({
      garden_id
    }).then(res => {
      that.setData({
        gate_list: res.list
      })
    })
  },
  async openDoor(e) {
    const {
      garden_id
    } = this.data;
    const {
      device_id
    } = e.currentTarget.dataset;
    wx.navigateTo({
      url: `/page/gate/pages/door/index?device_id=${device_id}&garden_id=${garden_id}&type=1`,
    })
  },

})