import request from '@/utils/request';

//修改设备维修记录
function updateRepair(data) {
    return request({
        url: '/equipment/repairRecords',
        method: 'put',
        data:data
        // data: {
        //     "recordId": data.recordId,
        //     "deviceId": data.deviceId,
        //     "createTime": data.createTime,
        //     "updateTime": data.updateTime,
        //     "repairTime": data.repairTime,
        //     "repairPart": data.repairPart,
        //     "repairReason": data.repairReason,
        //     "repairPerson": data.repairPerson,
        //     // "beforeFile": data.beforeFile,
        //     // "afterFile": data.afterFile
        // }
    });

}



//新增设备维修记录
function addRepir(data) {
    return request({
        url: '/equipment/repairRecords',
        method: 'post',
        data:data
        // data: {
        //     "recordId": data.recordId,
        //     "deviceId": data.deviceId,
        //     "createTime": data.createTime,
        //     "updateTime": data.updateTime,
        //     "repairTime": data.repairTime,
        //     "repairPart": data.repairPart,
        //     "repairReason": data.repairReason,
        //     "repairPerson": data.repairPerson,
        //     // "beforeFile": data.beforeFile,
        //     // "afterFile": data.afterFile
        // }
    });

}


//导出设备维修记录
function exportRepir(data) {
    return request({
        url: '/equipment/repairRecords/export',
        method: 'post',
        data: {
            "recordId": data.recordId,
            "deviceId": data.deviceId,
            "createTime": data.createTime,
            "updateTime": data.updateTime,
            "repairTime": data.repairTime,
            "repairPart": data.repairPart,
            "repairReason": data.repairReason,
            "repairPerson": data.repairPerson
        }
    });

}


//获取明细设备维修记录
function getRepirDetail(id) {
    return request({
        url: '/equipment/repairRecords/' + id,
        method: 'get'
    });

}



//获取列表 
function getRepairList(data) {
    return request({
        url: '/equipment/repairRecords/list',
        method: 'get',
        params: {   
            "recordId": data.recordId,
            "deviceId": data.deviceId,            
            "repairPart": data.repairPart,
            "repairReason": data.repairReason,
            "repairPerson": data.repairPerson,
            "repairBeginTime":data.Date?data.Date[0]:'',
            "repairEndTime": data.Date?data.Date[1]:'',
            "searchValue":data.searchValue,
            "pageNum": data.pageNum,
            "pageSize": data.pageSize
        }
    });

}

//删除记录
function dropRepir(id) {
    if (Array.isArray(id)) {
        id = id.join(",");
    }
    return request({
        url: '/equipment/repairRecords/' + id,
        method: 'delete'
    });

}


//获取设备类型
function getDeviceTypeAll() {
    return new Promise((resolve, reject) => {
        request({
            url: '/api/deviceType/all',
            method: 'get',

        }).then((res) => {
            resolve(res);
        }).catch((ex) => {
            reject(ex);
        });
    });
}

function getDeviceAll(){
    return request({
        url:'api/device?pageNum=1&pageSize=99999',
        method:'get'}
    );
}

export default {
    updateRepair: updateRepair,
    addRepir: addRepir,
    exportRepir: exportRepir,
    getRepirDetail: getRepirDetail,
    getRepairList: getRepairList,
    dropRepir: dropRepir,
    getDeviceTypeAll: getDeviceTypeAll,
    getDeviceAll:getDeviceAll
}