function convertDate(date) {
  if (typeof date === "number") {
    return date;
  } else if (typeof date != "object" && new Date(date).getTime()) {
    return new Date(date).getTime();
  } else {
    return date;
  }
}

export function compareData(oldBillData, newBill) {
  let that = this;
  for (let i in oldBillData) {
    if (i.endsWith("RQ") || i.endsWith("Time") || i.endsWith("SJ")) {
      oldBillData[i] = convertDate(oldBillData[i]);
    }
    if (
      Object.prototype.toString.apply(oldBillData[i]) == "[object Object]" &&
      oldBillData[i].code
    ) {
      //处理基础数据类型
      let code = oldBillData[i].code;
      oldBillData[i] = {};
      oldBillData[i].code = code;
    }
    if (
      i.endsWith("ZB") &&
      Object.prototype.toString.apply(oldBillData[i]) == "[object Array]" &&
      oldBillData[i].length > 0
    ) {
      let dateArr = Object.keys(oldBillData[i][0]).filter(
        //处理子表中的日期
        (v) => v.endsWith("RQ") || v.endsWith("Time") || v.endsWith("SJ")
      );
      oldBillData[i].forEach((v) => {
        if (dateArr.length > 0) {
          dateArr.forEach((b) => {
            v[b] = convertDate(v[b]);
          });
        }
        Object.entries(v).forEach((k) => {
          if (
            Object.prototype.toString.apply(k[1]) == "[object Object]" &&
            k[1].code
          ) {
            let code = k[1].code;
            v[k[0]] = {};
            v[k[0]].code = code;
          }
        });
      });
    }
  }
  for (let i in newBill) {
    if (i.endsWith("RQ") || i.endsWith("Time") || i.endsWith("SJ")) {
      newBill[i] = convertDate(newBill[i]);
    }
    if (
      Object.prototype.toString.apply(newBill[i]) == "[object Object]" &&
      newBill[i].code
    ) {
      //处理基础数据类型
      let code = newBill[i].code;
      newBill[i] = {};
      newBill[i].code = code;
    }
    if (
      i.endsWith("ZB") &&
      Object.prototype.toString.apply(newBill[i]) == "[object Array]" &&
      newBill[i].length > 0
    ) {
      let dateArr = Object.keys(newBill[i][0]).filter(
        (v) => v.endsWith("RQ") || v.endsWith("Time") || v.endsWith("SJ")
      );
      //处理子表中的日期
      newBill[i].forEach((v) => {
        if (dateArr.length > 0) {
          dateArr.forEach((b) => {
            v[b] = convertDate(v[b]);
          });
        }
        Object.entries(v).forEach((k) => {
          if (
            Object.prototype.toString.apply(k[1]) == "[object Object]" &&
            k[1].code
          ) {
            let code = k[1].code;
            v[k[0]] = {};
            v[k[0]].code = code;
          }
        });
      });
    }
  }
  return JSON.stringify(oldBillData) == JSON.stringify(newBill);
}
