/* 图片类型 */
function imageType(data, type) {
    for (let i = 0; i < data.length; i++) {
        let attinfos = [];
        for (let k = 0; k < data[i].attinfos.length; k++) {
            if (data[i].attinfos[k].ftype == type) attinfos.push(data[i].attinfos[k])
        }
        data[i].attinfos = attinfos;
    }
    return data;
}

/* 二维数组 */
function twoDimensionalArr(data, nub, max = 3) {
    let list = data,
        arrList = [];
    for (let i = 0; max > i && list.length >= 1; i++) {
        arrList.push(list.splice(0, nub))
    };
    return arrList;
}

/* 格式化时间 */
function checkdate(data) {
    for (let i = 0; i < data.length; i++) {
        let checkdate = data[i].checkdate;
        if (checkdate != null && checkdate != undefined) data[i].checkdate = checkdate.slice(0, checkdate.lastIndexOf('.'));
    }
    return data;
}

/* 通告格式化时间 */
function annunciateCheckdate(list) {
    for (let k = 0; k < list.length; k++) {
        let data = list[k];
        if (data.checkdate != null && data.checkdate != undefined && data.checkdate != '') {
            let arr = data.checkdate.split(" "),
                y = arr[0].split('-'),
                d = arr[1].split(':');
            data.checkdate = y[1] + '-' + y[2] + " " + d[0] + ':' + d[1]
        }
    }
    return list
}

/* 截取时间 只取年月日 */
function getYTD(data) {
    for (let i = 0; i < data.length; i++) {
        if (data[i].checkdate) {
            let checkdate = data[i].checkdate;
            const YTD = checkdate.split(' ');
            data[i].checkdate = YTD[0];
        } else {
            data[i].checkdate = '';
        }
    }
    return data;
}

module.exports = {
    checkdate,
    getYTD,
    twoDimensionalArr,
    imageType,
    annunciateCheckdate
}