//获取文书的所有url
export const getWriterUrl = (val, callback) => {
    // this.extUrlList = val.extUrl ? val.extUrl.split(",") : [];
    let url = ''
    if(val.subCategory === "medical_record_homepage" || val.category === "medical_record_homepage"){
      url = val.data.filePath || ''
    } else if(val.subCategory === "outpatients_emergency_case" || val.subCategory =='in_hospital_process' || val.subCategory == 'informed_consent') {
      url = val.data ? val.data.url : '';
    } else if(val.subCategory === "nursing_record") {
      url = val.data.url || '';
    }else {
      url = val.other.filePath || '';
    }
    let urlArr = url.split(',')
    const list = urlArr.map(item => {
      let str = item.substring(0,item.lastIndexOf('.'))
      return {
          title: val.title,
          label: str.substring(0,str.indexOf('_')),
          type: item.substring(item.lastIndexOf('.') + 1),
          subCategory: val.subCategory || val.category,
          url: item,
        };
    })
    callback ? callback(list) : null;
    // this.handleUrlList(list)
}

export const setWriterBtn = (row) => {
    if((row.subCategory =='outpatients_emergency_case' ||
      row.subCategory == 'nursing_record' ||
      row.subCategory == 'in_hospital_process' ||
      row.subCategory == 'informed_consent') && row.data.url) {
      return true
    } else if(row.subCategory == 'medical_record_homepage' && row.data.filePath) {
      return true
    }
}

// 处理报告的url数据

// 时间格式处理
export const handleDataFormat = (date) => {
    let year = new Date(date).getFullYear();
    let month = new Date(date).getMonth() + 1;
    let day = new Date(date).getDate();
    if (month < 10) month = "0" + String(month);
    if (day < 10) day = "0" + String(day);
    return String(year) + String(month) + String(day);
  }

export const getObjectURL = (file) => {
    const bolb = new Blob([file], { type:'application/pdf'});
    let url = "";
    if (window.createObjectURL != undefined) {
      url = window.createObjectURL(bolb);
    } else if (window.webkitURL != undefined) {
      try {
        url = window.URL.createObjectURL(bolb);
      } catch (error) {}
    } else if (window.URL != undefined) {
      try {
        url = window.webkitURL.createObjectURL(bolb);
      } catch (error) {}
    }
    return url;
  }
//获取地址里的参数
export const getQueryObject = (url) => {
  const search = url.substring(url.lastIndexOf("?") + 1);
  const obj = {};
  const reg = /([^?&=]+)=([^?&=]*)/g;
  search.replace(reg, (rs, $1, $2) => {
    const name = decodeURIComponent($1);
    let val = decodeURIComponent($2);
    val = String(val);
    obj[name] = val;
    return rs;
  });
  return obj;
}

export const setMarkLineList = (itemRef, panLow, panHigh, list) => {
    let itemrefList = [];
    let warnRangeList = [];
    let max = 0;
    let min = 0;
    if (itemRef) {
      let symbol1 = "－";
      let symbol2 = "-";
      if (itemRef.indexOf(symbol1) && itemRef.split(symbol1).length === 2) {
        itemrefList = itemRef.split(symbol1).map((item, index) => {
          return {
            yAxis: item,
            name: item,
            label: { show: true, position: "end", formatter: index === 0 ? "低值：" + item : "高值：" + item},
            lineStyle: { color: "#06AF67"}
          };
        });
      } else if (itemRef.indexOf(symbol2) && itemRef.split(symbol2).length === 2) {
        itemrefList = itemRef.split(symbol2).map((item, index) => {
          return {
            yAxis: item,
            name: item,
            label: { show: true,  position: "end",  formatter: index === 0 ? "低值：" + item : "高值：" + item },
            lineStyle: { color: "#06AF67"}
          };
        });
      }
    }
    if (panLow) {
      warnRangeList.push({
        yAxis: panLow,
        name: panLow,
        label: { show: true,  position: "end",  formatter: "低限：" + panLow },
        lineStyle: {  color: "red"}
      });
    }
    if (panHigh) {
      warnRangeList.push({
        yAxis: panHigh,
        name: panHigh,
        label: { show: true,  position: "end", formatter: "高限：" + panHigh },
        lineStyle: { color: "red"}
      });
    }
    let List = itemrefList.concat(warnRangeList);
    let arr = cloneDeep(list);
    List.forEach(item => arr.push(item.yAxis));
    max = Math.max(...arr);
    min = Math.min(...arr);
    let info = {
      maxNum: max,
      minNum: min,
      markLineList: List
    };
    return info;
  }
