export function getDyn(col, arr, comp) {
  let str = comp
  let is = true
  let type = ''
  for (let item of arr) {
    for (let itemChild of item.hrChildren) {
      for (let colItem of col) {
        if (itemChild.columnValue) {
          is = false
        }
        if (colItem == itemChild.columnName) {
          if (itemChild.htmlType == "input") {
            type = 1
            str = str.replace(itemChild.columnName, itemChild.columnValue)
          } else if (itemChild.htmlType == "datetime") {
            type = 2
            if(getTime(itemChild.columnValue)){
              str = str.replace(itemChild.columnName, getTime(itemChild.columnValue))
            }else{
              is=true
            }
          }else if(itemChild.htmlType == "datetime-date") {
            type = 3
            if (getTime(itemChild.columnValue)) {
              str = str.replace(itemChild.columnName, getTime(itemChild.columnValue))
            } else {
              is = true
            }
          }
        }
      }
    }
  }
  if (is) {
    return
  }
  if (type == 2) {
    return setTimeH(evals(str))
  }
  if(type==3){
    return setTime(evals(str))
  }
  return evals(str)
}

function evals(code) {
  let fun = new Function(`return ${code}`)();
  return fun
}
// 时间戳转成天
function setTime(val) {
  return Math.round(Number(val) / (1000 * 3600 * 24))
}
// 时间戳转成小时
function setTimeH(val) {
  return Math.round(Number(val) / (1000 * 3600))
}
// 转化成时间戳
function getTime(val) {
  var date = new Date(val);
  return date.getTime()
}
export function setDyn(col, arr, comp) {
  let str = comp
  for (let item of arr) {
    for (let itemChild of item.hrChildren) {
      for (let colItem of col) {
        if (colItem == itemChild.columnName) {
          str = str.replace(itemChild.columnName, itemChild.columnValue)
        }
      }
    }
  }
  return str
}
