// component/faultItem/faultItem.ts
import { httpUtil } from '../../utils/restful';
import { TimeUtil } from '../../utils/TimeUtil'
Component({
    /**
     * 组件的属性列表
     */
    properties: {
        //0=待维修 1=维修中 2=已完成

        itemData: null
    },

    /**
     * 组件的初始数据
     */
    data: {
        status: 0,
        statusText: "",
        faultTime: '',
        myItemData: null,
    },
    lifetimes: {
        attached: function () {
            // 在组件实例被从页面节点树添加时执行
            let text = "";

            switch (Number(this.properties.itemData.processType)) {
                case 0:
                    text = "待维修";
                    break;
                case 1:
                    text = "维修中";
                    break;
                case 2:
                    text = "已完成";
                    break;
            }
            this.setData({
                status: this.properties.itemData.processType,
                statusText: text,
                faultTime: TimeUtil.dateFormat(parseInt(this.properties.itemData.reportTime), "yyyy-MM-dd HH:mm"),
                myItemData: this.properties.itemData
            })

        },
        detached: function () {
            // 在组件实例被从页面节点树移除时执行

        },
    },

    /**
     * 组件的方法列表
     */
    methods: {
        toFaultInfoPage: function () {
            console.log("去故障详情界面")
            httpUtil.wxGet(httpUtil.interfaces.getFaultInfoByDevId + this.data.itemData.id, null).then((res: any) => {
                console.log("获取故障详情成功:", res)

                let item = JSON.stringify(res.data.data)

                wx.navigateTo({
                    url: '../../faultInfo/faultInfo?item=' + item
                })

            }).catch((res: any) => {
                console.log("获取故障详情失败:", res)
            })

        }
    }
})