
let util = require('../../../utils/util')
let apiArr = require('../../../api/water_filter')

// packages/master/device/index.js
Page({

    /**
     * 页面的初始数据
     */
    data: {
        deviceList: [],

        page_num: 1,
        page_size: 10,
        flag: false,

        option1: [
            { text: '全部', value: 0 },
            { text: '在用', value: 1 },
            { text: '已拆机', value: 4 },
            { text: '已报废 ', value: 7 },
            { text: '已在库', value: 9 },
        ],
        active: 0,

    },

    desc(e){
        console.log(e);
        wx.navigateTo({
          url: '/packages/master/deviceInfo/index?id=' + e.currentTarget.dataset.id,
        })
    },

    changeActive(e){
        let that = this
        that.setData({
            active:e.currentTarget.dataset.item.value,
            page_num: 1,
            deviceList:[]
        })
        that.getDeviceList()
    },
    getDeviceList() {
        let that = this
        wx.showLoading({
            title: '加载中...',
        })
        util.postUrl(apiArr.masterDeviceList, {
            page_num: that.data.page_num,
            page_size: that.data.page_size,
            info_id: wx.getStorageSync('info_id'),
            status:that.data.active
        }, res => {
            let flag = false
            wx.hideLoading()
            if (res.rows) {
                if (res.rows.length == that.data.page_size) {
                    flag = true
                } else {
                    flag = false
                }
                that.setData({
                    page_num: that.data.page_num + 1,
                    flag,
                    deviceList: that.data.deviceList.concat(res.rows || [])
                })
            }
        })

    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        let that = this
        that.getDeviceList()
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {
        let that = this
        if (that.data.flag) {
            that.getDeviceList()
        }
    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})