// 不显示的信息点数组
import text from "@/utils/handsontable/mainText"
import tools from "@/utils/scan/tools"
import fieldData from "@/utils/handsontable/fillterField"
import dataTypeMap from "./dataTypeMap"

let inputModeArr = ["A1", "A2", "B1", "C5", "D1", "D2", "E1", "L", "L1", "L2", "F1", "F2", "M", "Own"]
//在编辑模式下并且勾选隐藏自动填充的信息点不显示的字段
let noShowArr = [
  "specification",
  "serviceLife"
]
//在编辑模式下不显示的字段
let cantShow = [
  "EquipQRCode",
  "EquipID",
  "EquipName",
  "BIMLocation",
  "Brand",
  "Specification",
  "Manufacturer",
  "Supplier",
  "SupplierContactor",
  "SupplierPhone",
  "SupplierEmail",
  "SupplierWeb",
  "SupplierFax",
  "Maintainer",
  "MaintainerContactor",
  "MaintainerPhone",
  "MaintainerEmail",
  "MaintainerWeb",
  "Principal",
  "MaintainerFax",
  "Insurer",
  "InsurerContactor",
  "InsurerPhone",
  "InsurerEmail",
  "InsurerWeb",
  "InsurerFax",
  "InsuranceFile",
  "EquipID",
  "EquipName",
  "SpaceCount",
  "SpaceList",
  "TenantID",
  "ShaftID"
]

//台账编辑页面不显示的厂商信息
let firmArr = [
  "brand", //品牌
  "specification", //设备型号
  "manufacturer", //生产厂家
  "supplier", //供应商单位名称
  "supplierContactor", //供应商联系人
  "supplierPhone", //供应商联系电话
  "supplierEmail", //供应商电子邮件
  "supplierWeb", //供应商网址
  "supplierFax", //供应商传真
  "maintainer", //维修商单位名称
  "maintainerContactor", //维修商联系人
  "maintainerPhone", //维修商联系电话
  "maintainerEmail", //维修商电子邮件
  "maintainerWeb", //维修商网址
  "maintainerFax", //维修商传真
  "insurer", //保险公司名称
  "insurerContactor", //保险公司联系人
  "insurerPhone", //保险公司联系电话
  'insurerEmail', //保险公司电子邮件
  "insurerWeb", //保险公司网址
  "insurerFax", //保险公司传真
  // "dpManufacturerId",//品牌型号Id
  // "dpSupplierId",//供应商信息Id
  // "dpMaintainerId",//维修商信息Id
  // "dpInsurerId"//保险公司信息Id
]

let cutArr = [{
  name: "品牌型号",
  code: "dpManufacturerId",
  num: 2,
}, {
  name: "供应商信息",
  code: "dpSupplierId",
  num: 5
}, {
  name: "维修商信息",
  code: "dpMaintainerId",
  num: 19
}, {
  name: "保险公司信息",
  code: "dpInsurerId",
  num: 25
}]

let newData = [{
  name: "品牌型号",
  code: "dpManufacturerId",
  num: 2,
}, {
  name: "供应商信息",
  code: "dpSupplierId",
  num: 8
}, {
  name: "维修商信息",
  code: "dpMaintainerId",
  num: 35
}, {
  name: "保险公司信息",
  code: "dpInsurerId",
  num: 42
}]
//创建部件固定不显示-管理部件固定不显示(即编辑模式)
let partsAddNoShow = [
  'EquipID',
  'EquipName',
  'EquipQRCode',
  'BIMID',
  'BIMLocation',
  'Brand',
  'Specification',
  'Manufacturer',
  'Supplier',
  'SupplierContactor',
  'SupplierPhone',
  'SupplierEmail',
  'SupplierWeb',
  'SupplierFax',
  'maintainer',
  'MaintainerContactor',
  'MaintainerPhone',
  'MaintainerEmail',
  'MaintainerWeb',
  'MaintainerFax',
  'Insurer',
  "InsurerContactor",
  "InsurerPhone",
  "InsurerEmail",
  "InsurerWeb",
  "InsurerFax",
]
const showTools = {
  inputModeArr: ["A1", "A2", "B1", "B2", "C5", "D1", "D1L", "D2", "E1", "E2", "L", "L1", "L2", "F1", "F2", "M"],
             // ["A1", "A2", "B1",       "C5", "D1",        "D2", "E1",       "L", "L1", "L2", "F1", "F2", "M", "Own"]
  addArr: () => {
    return cutArr
  },
  cantShow: (code) => {
    let falg = true
    cantShow.map(item => {
      if (item == code) {
        falg = false
      }
    })
    return falg
  },
  fixedNoShowField: (noShowList, code) => {
    let flag = true
    noShowList.map(item => {
      if (item == code) {
        flag = false
      }
    })
    return flag
  },
  //几种类型不显示
  technologyParam: (item) => {
    if (
      item.firstTag == "控制参数" &&
      item.firstTag == "设定参数" &&
      item.firstTag == "运行参数"
    ) {
      return undefined
    }
  },
  isShow: (code) => {
    let falg = true
    noShowArr.map(item => {
      if (item == code) {
        falg = false
      }
    })
    return falg
  },
  // 将映射表枚举值转为数组
  mapToArr: () => {
    const arr = []
    for(let key in dataTypeMap) {
      arr.push(dataTypeMap[key])
    }
    return arr;
  },
  //插入需要的关系
  insertionRea: (data) => {
    cutArr.map(item => {
      data.splice(item.num, 0, item.name)
    })
    return data
  },

  insertionRea2: (data) => {
    newData.map(item => {
      data.splice(item.num, 0, item.name)
    })
    return data
  },

  insertionType: (data, callback) => {
    cutArr.map(item => {
      data.splice(item.num, 0, {
        data: "infos." + item.code,
        renderer: callback,
        readOnly: false
      })
    })
    return data
  },
  insertionType2: (data, callback) => {
    newData.map(item => {
      data.splice(item.num, 0, {
        data: "infos." + item.code,
        renderer: callback,
        readOnly: false
      })
    })
    return data
  },
  arrToArr(arr, showType) {
    let first = 0,
      scound = 0,
      three = 0,
      four = 0
    arr.find(function (value, index, arr) {
      let flag = (showType != "Visible" || value.visible)
      if (
        ((value.code == "brand" && flag) ||
          (value.code == "specification" && flag) ||
          (value.code == "manufacturer" && flag)) && !first
      ) {
        first = index
      }
      if (
        ((value.code == "supplier" && flag) ||
          (value.code == "supplierContactor" && flag) ||
          (value.code == "supplierEmail" && flag) ||
          (value.code == "supplierWeb" && flag) ||
          (value.code == "supplierFax" && flag) ||
          (value.code == "supplierPhone" && flag)) && !scound
      ) {
        scound = index
      }
      if (
        ((value.code == "maintainer" && flag) ||
          (value.code == "maintainerContactor" && flag) ||
          (value.code == "maintainerPhone" && flag) ||
          (value.code == "maintainerEmail" && flag) ||
          (value.code == "maintainerWeb" && flag) ||
          (value.code == "maintainerFax" && flag)) && !three
      ) {
        three = index
      }
      if (
        ((value.code == "insurer" && flag) ||
          (value.code == "insurerContactor" && flag) ||
          (value.code == "insurerPhone" && flag) ||
          (value.code == "insurerEmail" && flag) ||
          (value.code == "insurerWeb" && flag) ||
          (value.code == "insurerFax" && flag)) && !four
      ) {
        four = index
      }
    })
    let numList = [first, scound, three, four]
    numList.reverse().map((item, index) => {
      if (item) {
        if (index == 0) {
          arr.splice(item, 0, {
            dataType: "STR",
            firstName: "基本信息",
            aliasCode: "dpInsurerId",
            aliasName: "保险公司信息",
            name: "保险公司信息",
            code: "dpInsurerId",
            origCode: "dpInsurerId",
            origDataType: "Str",
            inputMode: "X",
            path: "dpInsurerId",
            priority: "S",
            editable: true,
            visible: true
          })
        } else if (index == 1) {
          arr.splice(item, 0, {
            dataType: "STR",
            firstName: "基本信息",
            aliasCode: "dpMaintainerId",
            aliasName: "维修商信息",
            name: "维修商信息",
            code: "dpMaintainerId",
            origCode: "dpMaintainerId",
            origDataType: "Str",
            inputMode: "X",
            path: "dpMaintainerId",
            priority: "S",
            editable: true,
            visible: true
          })
        } else if (index == 2) {
          arr.splice(item, 0, {
            dataType: "STR",
            firstName: "基本信息",
            aliasCode: "dpSupplierId",
            aliasName: "供应商信息",
            name: "供应商信息",
            code: "dpSupplierId",
            origCode: "dpSupplierId",
            origDataType: "Str",
            inputMode: "X",
            path: "dpSupplierId",
            priority: "S",
            editable: true,
            visible: true
          })
        } else if (index == 3) {
          arr.splice(item, 0, {
            dataType: "STR",
            firstName: "基本信息",
            aliasCode: "dpManufacturerId",
            aliasName: "生产厂家/品牌/型号",
            name: "生产厂家/品牌/型号",
            code: "dpManufacturerId",
            origCode: "dpManufacturerId",
            origDataType: "Str",
            inputMode: "X",
            path: "dpManufacturerId",
            priority: "S",
            editable: true,
            visible: true
          })
        }
      }
    })
    return arr
  },
  // 弃用
  // changeTypes(arr, onlyRead, isWatch, allMess, falg = false, taizhang = false) {
  //   let data = arr.map(item => {
  //     if (falg) {
  //       if (item.firstTag == "控制参数" ||
  //         item.firstTag == "设定参数" ||
  //         item.firstTag == "运行参数") {
  //         return undefined
  //       }
  //     }
  //     if (item.code == "BIMLocation") {
  //       return undefined
  //     }
  //     if (onlyRead || inputModeArr.indexOf(item.inputMode) > -1) {
  //       if (item.Visible || !allMess) {
  //         //固定不显示的code
  //         if (!showTools.cantShow(item.code) && !onlyRead && !taizhang) {
  //           return undefined
  //         }

  //         if (!showTools.isShow(item.code) && !taizhang && !taizhang) {
  //           if (isWatch && !onlyRead) {
  //             return undefined
  //           }
  //         }

  //         if (item.code == "EquipQRCode") {
  //           return {
  //             data: "Infos." + item.code,
  //             renderer: text.lookQRCode,
  //             readOnly: true
  //           }
  //         }

  //         if (item.inputMode == "D1") {
  //           return {
  //             data: "Infos." + item.code,
  //             renderer: tools.customDropdownRenderer,
  //             editor: "chosen",
  //             chosenOptions: {
  //               // multiple: true,//多选
  //               data: item.dataSource || ""
  //             }
  //           };
  //         } else if (item.inputMode == "A1" || item.inputMode == "A2") {
  //           return {
  //             data: "Infos." + item.code,
  //             type: "numeric",
  //             numericFormat: {
  //               pattern: "0,0.00"
  //               // culture: 'de-DE' // use this for EUR (German),
  //               // more cultures available on http://numbrojs.com/languages.html
  //             }
  //           };
  //         } else if (item.inputMode == "C5") {
  //           return {
  //             data: "Infos." + item.code,
  //             type: "date",
  //             dateFormat: "YYYY-MM-DD",
  //             correctFormat: true
  //           };
  //         } else if (
  //           item.inputMode == "B1" ||
  //           item.inputMode == "L" ||
  //           item.inputMode == "L1" ||
  //           item.inputMode == "L2" ||
  //           item.inputMode == "M"
  //         ) {
  //           return {
  //             data: "Infos." + item.code
  //           };
  //         } else if (
  //           item.inputMode == "X"
  //           // item.inputMode == "L1" ||
  //           // item.inputMode == "L2"
  //         ) {
  //           //   return undefined
  //           return {
  //             data: "Infos." + item.code,
  //             readOnly: true
  //           };
  //         } else if (item.inputMode == "D2") {
  //           return {
  //             data: "Infos." + item.code,
  //             renderer: tools.customDropdownRenderer,
  //             editor: "chosen",
  //             chosenOptions: {
  //               multiple: true, //多选
  //               data: item.dataSource || ""
  //             }
  //           };
  //         } else if (item.inputMode == "Own" && !onlyRead) {
  //           return {
  //             data: "Infos." + item.code,
  //             renderer: text.idType,
  //           }
  //         } else {
  //           return {
  //             data: "infos." + item.code
  //           }
  //         }
  //       } else {
  //         return undefined
  //       }
  //     } else {
  //       return false
  //     }


  //   }).filter(item => item);
  //   return data
  // },

  showTypes(arr, onlyRead, isWatch, allMess, falg = false, typeArr = false) {
    let data = arr.map(item => {
      if (falg) {
        if (item.firstTag == "控制参数" ||
          item.firstTag == "设定参数" ||
          item.firstTag == "运行参数") {
          return undefined
        }
      }
      if (item.code == "BIMLocation") {
        return undefined
      }
      if (onlyRead || inputModeArr.indexOf(item.inputMode) > -1) {
        if (item.Visible || !allMess) {
          //固定不显示的code
          if (!showTools.cantShow(item.code) && !onlyRead) {
            return undefined
          }

          if (!showTools.isShow(item.code) && !onlyRead) {
            if (isWatch && !onlyRead) {
              return undefined
            }
          }

          if (item.code == "EquipQRCode" || item.code == "RoomQRCode") {
            return {
              data: "infos." + item.code,
              renderer: text.lookQRCode,
              readOnly: true
            }
          }
          //图片类型
          if (
            item.code == "InstallPic" ||
            item.code == "Nameplate" ||
            item.code == "Pic"
          ) {
            return {
              data: "infos." + item.code,
              renderer: text.picType,
              readOnly: true
            }
          }

          //文件类型
          if (item.code == "InsuranceFile" ||
            item.code == "Archive" ||
            item.code == "CheckReport" ||
            item.code == "MaintainManual" ||
            item.code == "ApproachingAcceptance" ||
            item.code == "AcceptanceReport" ||
            item.code == "OperationManual" ||
            item.code == "OriginalCertificate" ||
            item.code == "TestReport" ||
            item.code == "ProductCertification" ||
            item.code == "InstallInstruction" ||
            item.code == "SupplierContract" ||
            item.code == "Drawing" ||
            item.code == "InstallDrawing"

          ) {
            return {
              data: "infos." + item.code,
              renderer: text.fileType,
              readOnly: true
            }
          }

          if (item.inputMode == "D1") {
            return {
              data: "infos." + item.code,
              renderer: tools.customDropdownRenderer,
              editor: "chosen",
              chosenOptions: {
                // multiple: true,//多选
                data: item.dataSource || ""
              }
            };
          } else if (item.inputMode == "A1" || item.inputMode == "A2") {
            return {
              data: "infos." + item.code,
              type: "numeric",
              numericFormat: {
                pattern: "0,0.00"
                // culture: 'de-DE' // use this for EUR (German),
                // more cultures available on http://numbrojs.com/languages.html
              }
            };
          } else if (item.inputMode == "C5") {
            return {
              data: "infos." + item.code,
              type: "date",
              dateFormat: "YYYY-MM-DD",
              correctFormat: true
            };
          } else if (
            item.inputMode == "B1" ||
            item.inputMode == "L" ||
            item.inputMode == "L1" ||
            item.inputMode == "L2" ||
            item.inputMode == "M"
          ) {
            return {
              data: "infos." + item.code
            }
          } else if (
            item.inputMode == "X" ||
            item.inputMode == "F2"
          ) {
            return {
              data: "infos." + item.code,
              readOnly: true
            };
          } else if (item.inputMode == "D2") {
            return {
              data: "infos." + item.code,
              renderer: tools.customDropdownRenderer,
              editor: "chosen",
              chosenOptions: {
                multiple: true, //多选
                data: item.dataSource || ""
              }
            };
          } else if (item.inputMode == "Own" && !onlyRead) {
            return {
              data: "infos." + item.code,
              renderer: text.idType,
            }
          } else {
            return {
              data: "infos." + item.code
            }
          }
        } else {
          return undefined
        }
      } else {
        return undefined
      }
    }).filter(item => item);
    return data
  },

  changeHeader(arr, readArr, onlyRead, isWatch, allMess, falg = false, taizhang = false) {
    let data = arr.map(item => {
      if (falg) {
        if (item.firstTag == "控制参数" ||
          item.firstTag == "设定参数" ||
          item.firstTag == "运行参数") {
          return undefined
        }
      }

      if (item.code == "BIMLocation") {
        return undefined
      }
      if (onlyRead || inputModeArr.indexOf(item.inputMode) > -1) {
        if (item.Visible || !allMess) {
          if (!showTools.cantShow(item.code) && !onlyRead && !taizhang) {
            return undefined
          }

          if (!showTools.isShow(item.code) && !taizhang) {
            if (isWatch && !onlyRead) {
              return undefined
            }
          }
          if (!item.Unit || item.Unit == "") {
            return item.InfoPointName;
          } else {
            return item.InfoPointName + "(" + item.Unit + ")";
          }
        } else {
          return undefined
        }
      } else {
        return undefined
      }
    }).filter(d => d);
    return data
  },

  showHeaderTypes(arr, typeArr, onlyRead, isWatch, allMess, falg = false) {
    let data = arr.map(item => {
      if (falg) {
        if (item.firstTag == "控制参数" ||
          item.firstTag == "设定参数" ||
          item.firstTag == "运行参数") {
          return undefined
        }
      }
      if (item.code == "BIMLocation") {
        return undefined
      }
      if (onlyRead || inputModeArr.indexOf(item.inputMode) > -1) {
        if (item.Visible || !allMess) {
          //固定不显示的code
          if (!showTools.cantShow(item.code) && !onlyRead) {
            return undefined
          }

          if (!showTools.isShow(item.code)) {
            if (isWatch && !onlyRead) {
              return undefined
            }
          }

          if (item.code == "EquipQRCode") {
            return {
              data: item.Path,
              renderer: text.lookQRCode,
              readOnly: onlyRead
            }
          }

          //图片类型
          if (
            item.code == "InstallPic" ||
            item.code == "Nameplate" ||
            item.code == "Pic"
          ) {
            return {
              data: item.Path,
              renderer: text.picType,
              readOnly: onlyRead
            }
          }

          //文件类型
          if (item.code == "InsuranceFile" ||
            item.code == "Archive" ||
            item.code == "CheckReport" ||
            item.code == "MaintainManual" ||
            item.code == "ApproachingAcceptance" ||
            item.code == "AcceptanceReport" ||
            item.code == "OperationManual" ||
            item.code == "OriginalCertificate" ||
            item.code == "TestReport" ||
            item.code == "ProductCertification" ||
            item.code == "InstallInstruction" ||
            item.code == "SupplierContract" ||
            item.code == "Drawing" ||
            item.code == "InstallDrawing"
          ) {
            return {
              data: item.Path,
              renderer: text.fileType,
              readOnly: onlyRead
            }
          }

          if (item.inputMode == "D1" || item.inputMode == "E1") { //单选
            return {
              data: item.Path,
              renderer: tools.customDropdownRenderer,
              editor: "chosen",
              readOnly: onlyRead,
              chosenOptions: {
                data: item.dataSource ? tools.formatDataSource(item.dataSource) : ""
              }
            };
          } else if (item.inputMode == "D2") {
            return {
              data: item.Path,
              renderer: tools.customDropdownRenderer,
              editor: "chosen",
              readOnly: onlyRead,
              chosenOptions: {
                multiple: true, //多选
                data: item.dataSource ? tools.formatDataSource(item.dataSource) : ""
              }
            };
          } else if (item.inputMode == "A1" || item.inputMode == "A2") {
            return {
              data: item.Path,
              type: "numeric",
              readOnly: onlyRead,
              numericFormat: {
                pattern: "0,0.00"
              }
            };
          } else if (item.inputMode == "C5") {
            return {
              data: item.Path,
              type: "date",
              dateFormat: "YYYY-MM-DD",
              readOnly: onlyRead,
              correctFormat: true
            };
          } else if (item.inputMode == "Own" && !onlyRead) {
            return {
              data: item.Path,
              renderer: text.idType,
              readOnly: onlyRead
            }
          } else {
            return {
              data: item.Path,
              readOnly: onlyRead
            };
          }
        } else {
          return undefined
        }
      } else {
        return undefined
      }
    }).filter(item => item);
    return data
  },

  tableHeadFilter(arr, readArr, onlyRead, isWatch, allMess, falg = false, taizhang = false) {
    if (!taizhang) {
      arr = showTools.arrToArr(arr)
    }
    let data = arr.map(item => {
      if (falg) {
        if (item.firstTag == "控制参数" ||
          item.firstTag == "设定参数" ||
          item.firstTag == "运行参数") {
          return undefined
        }
      }

      if (item.code == "BIMLocation") {
        return undefined
      }
      if (onlyRead || inputModeArr.indexOf(item.inputMode) > -1) {
        if (item.Visible || !allMess) {
          if (!showTools.fixedNoShowField(partsAddNoShow, item.code) && !onlyRead && !taizhang) {
            return undefined
          }
          if (!showTools.isShow(item.code) && !taizhang) {
            if (isWatch && !onlyRead) {
              return undefined
            }
          }
          if (!item.Unit || item.Unit == "") {
            return item.InfoPointName;
          } else {
            return item.InfoPointName + "(" + item.Unit + ")";
          }
        } else {
          return undefined
        }
      } else {
        return undefined;
      }
    }).filter(d => d);
    return data
  },
  tableHeaderTypes(arr, typeArr, onlyRead, isWatch, allMess, falg = false, taizhang = false) {
    if (!taizhang) {
      arr = showTools.arrToArr(arr)
    }
    let data = arr.map(item => {
      if (falg) {
        if (item.firstTag == "控制参数" ||
          item.firstTag == "设定参数" ||
          item.firstTag == "运行参数") {
          return undefined
        }
      }
      if (item.Path == "BIMLocation") {
        return undefined
      }
      if (onlyRead || inputModeArr.indexOf(item.inputMode) > -1) {
        if (item.Visible || !allMess) {
          //固定不显示的code
          if (!showTools.fixedNoShowField(partsAddNoShow, item.code) && !onlyRead && !taizhang) {
            return undefined
          }
          if (!showTools.isShow(item.code) && !taizhang) {
            if (isWatch && !onlyRead) {
              return undefined
            }
          }
          if (item.code == "EquipQRCode") {
            return {
              data: item.Path,
              renderer: text.lookQRCode,
              readOnly: onlyRead
            }
          }
          //图片类型
          if (
            item.code == "InstallPic" ||
            item.code == "Nameplate" ||
            item.code == "Pic"
          ) {
            return {
              data: item.Path,
              renderer: text.picType,
              readOnly: onlyRead
            }
          }

          //文件类型
          if (item.code == "InsuranceFile" ||
            item.code == "Archive" ||
            item.code == "CheckReport" ||
            item.code == "MaintainManual" ||
            item.code == "ApproachingAcceptance" ||
            item.code == "AcceptanceReport" ||
            item.code == "OperationManual" ||
            item.code == "OriginalCertificate" ||
            item.code == "TestReport" ||
            item.code == "ProductCertification" ||
            item.code == "InstallInstruction" ||
            item.code == "SupplierContract" ||
            item.code == "Drawing" ||
            item.code == "InstallDrawing"
          ) {
            return {
              data: item.Path,
              renderer: text.fileType,
              readOnly: onlyRead
            }
          }

          if (item.inputMode == "D1" || item.inputMode == "E1") { //单选
            return {
              data: item.Path,
              renderer: tools.customDropdownRenderer,
              editor: "chosen",
              readOnly: onlyRead,
              chosenOptions: {
                data: item.dataSource ? tools.formatDataSource(item.dataSource) : ""
              }
            };
          } else if (item.inputMode == "D2") {
            return {
              data: item.Path,
              renderer: tools.customDropdownRenderer,
              editor: "chosen",
              readOnly: onlyRead,
              chosenOptions: {
                multiple: true, //多选
                data: item.dataSource ? tools.formatDataSource(item.dataSource) : ""
              }
            };
          } else if (item.inputMode == "A1" || item.inputMode == "A2") {
            return {
              data: item.Path,
              type: "numeric",
              readOnly: onlyRead,
              numericFormat: {
                pattern: "0,0.00"
              }
            };
          } else if (item.inputMode == "C5") {
            return {
              data: item.Path,
              type: "date",
              dateFormat: "YYYY-MM-DD",
              readOnly: onlyRead,
              correctFormat: true
            };
          } else {
            return {
              data: item.Path,
              readOnly: onlyRead
            };
          }
        } else {
          return undefined
        }
      } else {
        return undefined
      }
    }).filter(item => item);
    return data
  },
  /**
   *
   * @param {*} arr 原始表头数组
   * @param {*} type 对应表格的模块类型
   * @param {*} onlyRead 是否只读
   * @param {*} showType 查看类型(全部;只看要采集的信息;隐藏部分信息)
   * @param {*} taizhang 是否是台账类型(默认为false)
   *
   */
  headerTextFilter(arr, type, onlyRead, showType, taizhang = false) {
    if (taizhang && !onlyRead) {
      arr = this.arrToArr(arr, showType)
    }
    let data = arr.map(item => {
      // if (type == "property" && item.firstTag == "RunParam") { //资产台账不显示运行参数
      //     return undefined
      // }
      if (onlyRead) { //只读模式
        if (!this.filterUnshow(onlyRead, type, item.code)) { //过滤固定不显示字段
          return undefined
        }
        if (showType == "Visible" && item.visible) { //只看要采集的信息
          return this.isUnit(item)
        } else if (showType == "all") { //显示全部
          return this.isUnit(item)
        } else {
          return undefined
        }
      } else { //编辑模式
        if (taizhang && !this.filterFirm(item.code)) {
          return undefined
        }
        if (!this.filterUnshow(onlyRead, type, item.code)) { //过滤固定不显示字段
          return undefined
        }
        if (showType == "Visible" && item.visible) { //只看要采集的信息
          return this.isUnit(item)
        } else if (showType == "all") { //显示全部
          return this.isUnit(item)
        } else if (showType == "partInfo" && item.visible && this.isShow(item.code)) { //隐藏部分厂家信息(***需维护不显示列表***)
          // if (item.FirstName == "控制参数" || item.FirstName == "设定参数" || item.FirstName == "运行参数") {
          if (item.firstTag == "techParam") { //技术参数
            return undefined
          } else {
            return this.isUnit(item)
          }
        } else {
          return undefined
        }

      }
    }).filter(d => d)
    return data
  },
  headerTypeFilter(arr, type, onlyRead, showType, taizhang = false) {
    if (taizhang && !onlyRead) {
      arr = this.arrToArr(arr, showType)
    }
    text.readOnly = onlyRead;
    let data = arr.map(item => {
      // if (type == "property" && item.firstTag == "runParam") { //资产台账不显示运行参数
      //     return undefined
      // }
      if (onlyRead) { //只读模式
        if (!this.filterUnshow(onlyRead, type, item.code)) { //过滤固定不显示字段
          return undefined
        }
        if (showType == "Visible" && item.visible) { //只看要采集的信息
          return this.textFormat(item, onlyRead)
        } else if (showType == "all") { //显示全部
          return this.textFormat(item, onlyRead)
        } else {
          return undefined
        }
      } else { //编辑模式
        if (taizhang && !this.filterFirm(item.code)) {
          return undefined
        }
        if (!this.filterUnshow(onlyRead, type, item.code)) { //过滤固定不显示字段
          return undefined
        }
        if (showType == "Visible" && item.visible) { //只看要采集的信息
          return this.inputModeFilter(item, onlyRead)
        } else if (showType == "all") { //显示全部
          return this.inputModeFilter(item, onlyRead)
        } else if (showType == "partInfo" && item.visible && this.isShow(item.code)) { //隐藏部分厂家信息(***需维护不显示列表***)
          // if (item.FirstName == "控制参数" || item.FirstName == "设定参数" || item.FirstName == "运行参数") {
          if (item.firstTag == "techParam") { //技术参数
            return undefined
          } else {
            return this.inputModeFilter(item, onlyRead)
          }
        } else {
          return undefined
        }
      }
    }).filter(d => d)
    return data
  },
  isUnit(item) {
    if (!item.unit || item.unit == "") {
      return item.name;
    } else {
      return item.name + "(" + item.unit + ")";
    }
  },
  textFormat(item, onlyRead) {
    console.log(item.path);
    if (
      // item.code == "EquipQRCode" ||
      // item.code == "RoomQRCode"
      item.code == "defaultQRCode"
    ) {
      return {
        data: item.path,
        renderer: text.lookQRCode,
        readOnly: onlyRead
      }
    }

    //图片类型
    if (
      item.code == "installPic" ||
      item.code == "nameplate" ||
      item.code == "pic"
    ) {
      return {
        data: item.path,
        renderer: text.picType,
        readOnly: onlyRead
      }
    }
    //文件类型
    if (item.code == "insuranceFile" ||
      item.code == "archive" ||
      item.code == "checkReport" ||
      item.code == "maintainManual" ||
      item.code == "approachingAcceptance" ||
      item.code == "acceptanceReport" ||
      item.code == "operationManual" ||
      item.code == "originalCertificate" ||
      item.code == "testReport" ||
      item.code == "productCertification" ||
      item.code == "installInstruction" ||
      item.code == "supplierContract" ||
      item.code == "drawing" ||
      item.code == "installDrawing"
    ) {
      return {
        data: item.path,
        renderer: text.fileType,
        readOnly: onlyRead
      }
    }

    if (item.inputMode == "D1" || item.inputMode == "E1" || item.inputMode == "D1L") { //单选输入
      return {
        data: item.path,
        renderer: tools.customDropdownRenderer,
        editor: "chosen",
        readOnly: onlyRead,
        chosenOptions: {
          data: item.dataSource ? tools.formatDataSource(item.dataSource) : ""
        }
      };
    } else if (item.inputMode == "D2" || item.inputMode == "E2") { //多选输入
      return {
        data: item.path,
        renderer: tools.customDropdownRenderer,
        editor: "chosen",
        readOnly: onlyRead,
        chosenOptions: {
          multiple: true, //多选
          data: item.dataSource ? tools.formatDataSource(item.dataSource) : ""
        }
      };
    } else if (item.inputMode == "A1" || item.inputMode == "A2") { //数字输入
      return {
        data: item.path,
        type: "numeric",
        readOnly: onlyRead,
        numericFormat: {
          pattern: "0,0.00"
        }
      };
    } else if (item.inputMode == "C5") { //日期输入
      return {
        data: item.path,
        type: "date",
        dateFormat: "YYYYMMDDHHmmss",
        readOnly: onlyRead,
        correctFormat: true
      };
    } else if (item.inputMode == "B1" ||
      item.inputMode == "B2" ||
      item.inputMode == "F1" ||
      item.inputMode == "F2" ||
      item.inputMode == "L1" ||
      item.inputMode == "L2" ||
      item.inputMode == "L" ||
      item.inputMode == "M") { //文本输入
      return {
        data: item.path,
        readOnly: onlyRead
      }
    } else { //(未支持的输入方式)暂不支持编辑
      return {
        data: item.path,
        readOnly: onlyRead
      }
    }
  },
  inputModeFilter(item, onlyRead) {
    if (
      // item.code == "EquipQRCode" ||
      // item.code == "RoomQRCode"
      item.code == "defaultQRCode"
    ) {
      return {
        data: item.path,
        renderer: text.lookQRCode,
        readOnly: !item.editable
      }
    }

    //图片类型
    if (
      item.code == "installPic" ||
      item.code == "nameplate" ||
      item.code == "pic"
    ) {
      return {
        data: item.path,
        renderer: text.picType,
        readOnly: !item.editable
      }
    }

    //文件类型
    if (item.code == "insuranceFile" ||
      item.code == "archive" ||
      item.code == "checkReport" ||
      item.code == "maintainManual" ||
      item.code == "approachingAcceptance" ||
      item.code == "acceptanceReport" ||
      item.code == "operationManual" ||
      item.code == "originalCertificate" ||
      item.code == "testReport" ||
      item.code == "productCertification" ||
      item.code == "installInstruction" ||
      item.code == "supplierContract" ||
      item.code == "drawing" ||
      item.code == "installDrawing"
    ) {
      return {
        data: item.path,
        renderer: text.fileType,
        readOnly: !item.editable
      }
    }

    //四大厂商
    if (
      item.code == "dpSupplierId" ||
      item.code == "dpMaintainerId" ||
      item.code == "dpInsurerId" ||
      item.code == "dpManufacturerId"
    ) {
      return {
        data: item.path,
        renderer: text.idType,
        readOnly: !item.editable
      }
    }
    if (!item.inputMode) {
      console.log('新版字典无输入类型', item)
    }
    if (item.category == 'STATIC') {
      if (item.dataType == dataTypeMap.ENUM || item.dataType == dataTypeMap.BOOLEAN) { //单选输入
        return {
          data: item.path,
          renderer: tools.customDropdownRenderer,
          editor: "chosen",
          readOnly: !item.editable,
          chosenOptions: {
            data: item.dataSource ? tools.formatDataSource(item.dataSource) : ""
          }
        };
      } else if (item.dataType == dataTypeMap.MENUM) { //多选输入
        return {
          data: item.path,
          renderer: tools.customDropdownRenderer,
          editor: "chosen",
          readOnly: !item.editable,
          chosenOptions: {
            multiple: true, //多选
            data: item.dataSource ? tools.formatDataSource(item.dataSource) : ""
          }
        };
      } else if (item.dataType == dataTypeMap.DOUBLE || item.dataType == dataTypeMap.INTEGER) { // 数字输入
        return {
          data: item.path,
          type: "numeric",
          readOnly: !item.editable,
          numericFormat: {
            pattern: "0,0.00"
          }
        };
      } else if (item.dataType == dataTypeMap.DATETIME) { // 日期输入
        return {
          data: item.path,
          type: "date",
          dateFormat: item.formater || "YYYYMMDDHHmmss",
          readOnly: !item.editable,
          correctFormat: true
        };
      } else if (item.dataType == dataTypeMap.STRING) { // 文本输入
        return {
          data: item.path,
          readOnly: !item.editable
        }
      } else { // (未支持的输入方式)暂不支持编辑
        return {
          data: item.path,
          readOnly: !item.editable
        }
      }
    } else { // 动态信息点
      console.log(`%c${item.category}-${item.dataType}`,`color:#c215e1;font-size: 20px;background:#434101`);
      return {
        data: item.path,
        readOnly: !item.editable
      }
    }
  },
  filterUnshow: (onlyRead, type, code) => {
    let falg = true,
      data = fieldData[type]
    if (onlyRead) {
      data.onlyRead.map(item => {
        if (item == code) {
          falg = false
        }
      })
      return falg
    } else {
      data.edit.map(item => {
        if (item == code) {
          falg = false
        }
      })
      return falg
    }
  },
  filterFirm: (code) => {
    let falg = true
    firmArr.map(item => {
      if (item == code) {
        falg = false
      }
    })
    return falg
  }
}

export default showTools
