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

// packages/WaterPurifier/pages/upKeep/upKeep.js
Page({

    /**
     * 页面的初始数据
     */
    data: {
        statusType: {
            1: '待分配',
            2: '安装中',
            3: '待激活',
            4: '已安装',
            5: '忽略',
        },
       
        value1: 0,
        value2: 'a',
        show: false,
        MasterList: [

        ],

        searchText: "",//搜索文字
        page_num: 1,
        page_size: 10,
        total: '',
        deviceList: [],
        sendOrders: {}, // 派单订单
        flag: false
    },
    desc(e) {
        let that = this
        wx.navigateTo({
          url: `../newOrderListDesc/index?id=${e.currentTarget.dataset.id}`,
        })
    },
    addWorkOrder() {
        wx.navigateTo({
            url: '../newWorkOrder/newWorkOrder',
        })
    },

    onClose() {
        let that = this
        that.setData({
            show: false
        })
    },
    dispatch(e) {
        let that = this
        that.setData({
            show: true,
            sendOrders: e.currentTarget.dataset.item
        })
    },

    // 下拉列表选择工单状态
    headerDropdownClick(e) {
        this.setData({
            value1: e.detail,
            orderList: [],
            page_num: 1,
        })
        this.getNewOrderList();
    },


    ipt1(e) {
        let that = this
        that.setData({
            searchText: e.detail.value,
            page_num: 1,
            flag: false,
            deviceList: []
        })
        that.getNewOrderList()
    },

    search() {
        let that = this
        that.setData({
            page_num: 1,
            flag: false,
            deviceList: []
        })
        that.getNewOrderList()
    },


    //工单列表
    getNewOrderList() {
        let that = this
        wx.showLoading({
            title: '加载中...',
            mask: true,
        })
        //设置加载状态
        util.postUrl(apiArr.userNewOrderList, {
            page_size: that.data.page_size,
            page_num: that.data.page_num,
            status: that.data.value1,
            search: that.data.searchText
        }, res => {
            wx.hideLoading()
            if (res.rows) {
                let flag = false
                if (res.rows.length == that.data.page_size) {
                    flag = true
                } else {
                    flag = false
                }
                that.setData({
                    flag,
                    deviceList: that.data.deviceList.concat(res.rows || []),
                    page_num: that.data.page_num + 1
                })

            }
        })
    },

    onLineSupport(){
        wx.navigateTo({
          url: '/pages/onLineSupport/onLineSupport',
        })
    },

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

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

    },

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

    },

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

    },

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

    },

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

    },

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

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

    }
})