/**
 * 对item进行从左向右排版
 * @param itemArr 
 * @param col 列
 * @param pW 父宽度
 * @param pH 父高度
 * @param h item的高度
 * @param dw 间隔宽度
 * @param dh 间隔高度
 * @returns 
 */
export function typesetting(itemArr = [], col = 1, pW = 1280, pH = 720, h = 70, dw = 20, dh = 20) {

    if (!itemArr || itemArr.length == 0 || col == 0) {
        return;
    }

    let len = itemArr.length;

    let row = Math.ceil(len / col);

    let tH = row * h + (row - 1) * dh;

    //计处纵向坐标
    let y = (pH - tH) / 2;

    for (let i = 0; i < row; ++i) {

        let tCol = col;

        if ((i + 1) * col > len) {

            tCol = len - i * col;
        }

        let tW = 0;

        //计算总宽度
        for (let j = 0; j < tCol; ++j) {
            tW += itemArr[i * col + j].width;
        }

        tW += dw * (tCol - 1);

        //计算横向开始坐标
        let x = (pW - tW) / 2;

        let tempX = x;

        for (let j = 0; j < tCol; ++j) {
            let item = itemArr[i * col + j];
            item.x = tempX;

            item.y = y+ (h + dh) * i;

            tempX += item.width + dw;
        }
    }
}