import moment from "moment"
import axios from "axios";
import {listAllUrl} from "@/api/ecology/atmosphere/acid-rain-plcae"
export default {
    toCountyObjData(excelData){
        return excelData.map(item => {

            const row = {
                regionCode: item[0],
                city: (typeof item[1] == "string" && item[1].includes("市"))?item[1].sub(0,item[1].lastIndexOf("市")): "南宁市",
                county: (typeof item[1] == "string" && item[1].includes("县"))?item[1].sub(0,item[1].lastIndexOf("县")): "",
                area: (typeof item[1] == "string" && item[1].includes("区"))?item[1].sub(0,item[1].lastIndexOf("区")): "南宁区",
                place: item[2],
                placeType: item[3],
                monitorStartTime: moment(`${item[4]}-${item[5]}-${item[6]} ${item[7]}:${item[8]}:00`).valueOf(),
                monitorEndTime: moment(`${item[9]}-${item[10]}-${item[11]} ${item[12]}:${item[13]}:00`).valueOf(),
                monitorTime: moment(`${item[4]}-${item[5]}-${item[6]} ${item[7]}:${item[8]}:00`).valueOf(),
                precipitationType: item[14],
                precipitation: item[15],
                ph: item[16],
                conductivity: item[17],
                so42: item[18],
                no3: item[19],
                f: item[20],
                cl: item[21],
                nh4: item[22],
                ca: item[23],
                mg: item[24],
                na: item[25],
                k: item[26],
                systemCode: item[27],

            }

            return row;
        })
    },
    async toObjData(excelData,monitorYear) {
        const res  = await axios.get(listAllUrl,{params:{year:monitorYear}})
        if(res.data.code !=0 && res.data.data.length === 0){
            return Promise.reject(monitorYear +"点位字典未设置");
        }
        const dict = res.data.data;
        return excelData.map(item => {
            const monitorTime = moment(monitorYear + "."+item[1],"Y.M.D");
            const monitorStartTime  = moment(`${monitorYear}.${item[2]}.${item[3]} ${item[4]}:${item[5]}`,"Y.M.D H:m");
            const monitorEndTime  = moment(`${monitorYear}.${item[6]}.${item[7]} ${item[8]}:${item[9]}`,"Y.M.D H:m");
            const row = {
                city: "南宁市",
                place: dict.find(p=>p.placeCode == item[0].split("~")[0]).place,
                placeType:dict.find(p=>p.placeCode == item[0].split("~")[0]).attribute,
                code: item[0],
                precipitationType:item[10],
                precipitation:item[11],
                ph:item[12],
                conductivity:item[13],
                f:item[14],
                cl:item[15],
                so42:item[16],
                no3:item[17],
                na:item[18],
                nh4:item[19],
                k:item[20],
                mg:item[21],
                ca:item[22],
                monitorStartTime: monitorStartTime.valueOf(),
                monitorEndTime: monitorEndTime.valueOf(),
                monitorTime: monitorTime.valueOf(),
            }

            return row;
        })

    },

}
