import service from "../utils/request";
import axios from "axios";
import {getToken} from "../utils/auth";

export function getInformationCollectionList(params) {
    let urls = new Url()
    let newurl = urls.getUrl('/InforForms/LoadList', params)
    return service({
        url: newurl,
        method: 'GET'
    })
}

export function postInformationCollection(data) {
    return service({
        url: "/InforForms/Add",
        method: 'POST',
        data
    })
}

export function postInformationVerify(data) {
    return service({
        url: "/InforForms/Verify",
        method: 'POST',
        data
    })
}

export function deleteInformationCollection(data) {
    return service({
        url: "/InforForms/Delete",
        method: 'POST',
        data
    })
}

export function updateInformationCollection(data) {
    return service({
        url: "/InforForms/Update",
        method: 'POST',
        data
    })
}

export const getInformationCollection = function (id) {
    return service({
        url: '/InforForms/Get?id=' + id,
        method: 'GET'
    })
}
export const getInformationExportExcel = function (page, key, limit) {
    let url = '/InforForms/ExportExcel?page=' + page + '&limit=' + limit
    if (key) {
        url = '/InforForms/ExportExcel?page=' + page + '&limit=' + limit + '&key=' + key
    }
    return axios.get(+url, {
        headers: {
            "X-Token": getToken(),
        },
        responseType: 'blob',
    })
}

export function getCompleteQueryList(params) {
    let urls = new Url()
    let newurl = urls.getUrl('/DroneCaseinfo/LoadCaseInfoList', params)
    return service({
        url: newurl,
        method: 'GET'
    })
}


export function getCaseInfo(params){
    let urls = new Url()
    let newurl = urls.getUrl('/DroneCaseinfo/GetCaseInfo', params)
    return service({
        url: newurl,
        method: 'GET'
    })
}

export function getCaseHandleInfo(params){
    let urls = new Url()
    let newurl = urls.getUrl('/DroneCaseinfo/GetDroneCaseDeal', params)
    return service({
        url: newurl,
        method: 'GET'
    })
}



export function DeleteDroneFiles(data) {
    return service({
        url: "/DroneCaseinfo/DeleteDroneFiles",
        method: 'POST',
        data
    })
}

export function ExportCaseWord(params){
    let urls = new Url()
    let newurl = urls.getUrl('/DroneCaseinfo/DroneCaseInfoExport', params)
    return service({
        url: newurl,
        method: 'GET'
    })
}


export function GetOrgAreaByPoint(params){
    let urls = new Url()
    let newurl = urls.getUrl('/DroneCaseinfo/GetOrgAreaByPoint', params)
    return service({
        url: newurl,
        method: 'GET'
    })
}



class Url {
    /**
     * 传入对象返回url参数
     * @param {Object} data {a:1}
     * @returns {string}
     */
    getParam(data) {
        let url = '';
        for (let k in data) {
            let value = data[k] !== undefined ? data[k] : '';
            if (value !== undefined && value !== "" && value !== null) {
                url += `&${k}=${encodeURIComponent(value)}`
            }
        }
        return url ? url.substring(1) : ''
    }

    /**
     * 将url和参数拼接成完整地址
     * @param {string} url url地址
     * @param {Json} data json对象
     * @returns {string}
     */
    getUrl(url, data) {
        //看原始url地址中开头是否带?，然后拼接处理好的参数
        return url += (url.indexOf('?') < 0 ? '?' : '') + this.getParam(data)
    }
}
