let app = getApp()
Page({
    data: {
        currentTab: 0,
        repairList: []
    },

    onLoad(options) {
        // 页面初始化 options为页面跳转所带来的参数
        wx.setNavigationBarTitle({
            title: options.name
        })
    },

    onShow() {
        switch (this.data.currentTab) {
            case 0:
                this.getList()
                break
            case 1:
                this.getList('PENDING_ASSIGN')
                break
            case 2:
                this.getList('PENDING_PROCESS')
                break
            case 3:
                this.getList('COMPLETED')
                break
            case 4:
                this.getList('SCORE')
                break
            case 5:
                this.getList('CANCELED')
        }
    },

    getList(status) {
        let that = this
        let workCondition = ''
        that.data.repairList = []
        if (status) {
            workCondition = '/repair/list?status=' + status
        } else {
            workCondition = '/repair/list'
        }
        app.AjaxRequest('get', {
            'content-type': 'application/json',
            'Authorization': 'Bearer ' + app.Getopenid()
        }, workCondition, {}, function (res) {
            that.setData({
                repairList: res.rows
            })
        })
    },

    //滑动切换
    swiperTab: function (e) {
        var that = this
        that.setData({
            currentTab: e.detail.current
        })
        switch (e.detail.current) {
            case 0:
                this.getList()
                break
            case 1:
                this.getList('PENDING_ASSIGN')
                break
            case 2:
                this.getList('PENDING_PROCESS')
                break
            case 3:
                this.getList('COMPLETED')
                break
            case 4:
                this.getList('SCORE')
                break
            case 5:
                this.getList('CANCELED')
        }
    },

    //点击切换
    clickTab: function (e) {
        var that = this
        console.log(e.target.dataset.current)
        if (this.data.currentTab === e.target.dataset.current) {
            return false
        } else {
            that.setData({
                currentTab: e.target.dataset.current
            })
        }
    },

    scrollToLower() {

    },

    repairapply() {
        wx.navigateTo({
            url: '../parkRepair/repairInApply/repairInApply',
        })
    },
    repairDetail(e) {
        wx.navigateTo({
            url: '../parkRepair/repairDetail/repairDetail?id=' + e.currentTarget.dataset.id,
        })
    },
    navEvaluate(e) {
        wx.navigateTo({
            url: '../parkRepair/evaluate/evaluate?id=' + e.currentTarget.dataset.id,
        })
    }
})