export const danxiangdinge_index = (data) => {
    let max = 0;
    for(let i = 0;  i< data.length; i++) {
        if (data[i].hasOwnProperty("children")) {
            let child = data[i]["children"];
            for (let j = 0; j < child.length; j++) {
                let de = child[j];
                if (de["清单编码"].startsWith("D")) {
                    let number = de["清单编码"].substring(1);
                    let n = Number(number);
                    if (n > max) {
                        max = n;
                    }
                }
            }
        }
    }
        let result =  (max + 1).toString();
        result = result.padStart(5, '0');
        return "D".concat(result);

    
  };
export const copy = (input) => {
    return JSON.parse(JSON.stringify(input));
};


export const renameDingE = (oldname, xuhao) => {
    let index = oldname.indexOf('附注', 0);
    let raw = oldname;
    if (index == -1) {

    } else {
        raw = oldname.substring(0, index);
    }
    for(let i = 0; i < xuhao.length; i++) {
        raw = raw.concat("附注");
        raw = raw.concat(xuhao[i].toString());
    }
    if (oldname.indexOf('换', 0) > -1) {
        raw = raw.concat('换');
    }
    return raw;
};

export const extractFuzhu = (debm) => {
    if (debm) {
        let start = 0;
        let result = [];
        while(start < debm.length) {
            let index = debm.indexOf('附注', start);
            if (index == -1) break;
            let i = index + 2;
            for(i = index+2; i < debm.length; i++) {
                if (debm[i] >= '0' && debm[i] <= '9') {

                } else {
                    break;
                }
            }
            let find = debm.substring(index+2, i);
            result.push(Number(find));
            start = i;


        }
        return result;
    } else {
        return [];
    }
};


