<template>
  <div>
    <div class="hanson-bar">
      <span>当前筛选条件下共{{page.total || '--'}}系统</span>
      <div style="width:300px;float:right;overflow:hidden;">
        <el-button size="small" @click="addDevice" icon="iconfont icon-tianjia">添加系统</el-button>
        <el-button size="small" @click="reset" icon="iconfont icon-shuaxin">刷新</el-button>
        <el-button size="small" @click="undo" icon="iconfont icon-undo">撤销</el-button>
      </div>
      <div style="width:200px;color:gray;float:right;padding-top:7px;font-size:10px;">
        <span v-if="!onlyRead">隐藏自动填充的信息点:</span>
        <el-tooltip v-if="!onlyRead" :content="'' + (isWatch ? '隐藏' : '不隐藏')" placement="top">
          <el-switch
            @change="changeWatch"
            v-model="isWatch"
            active-color="#13ce66"
            inactive-color="gray"
          ></el-switch>
        </el-tooltip>
        <span v-if="onlyRead">只看要采集的信息:</span>
        <el-tooltip v-if="onlyRead" :content="'' + (allMess ? '部分' : '全集')" placement="top">
          <el-switch
            @change="changeWatch"
            v-model="allMess"
            active-color="#13ce66"
            inactive-color="gray"
          ></el-switch>
        </el-tooltip>
      </div>
      <div
        style="width:90px;cursor: pointer;color:gray;float:right; font-size:10px;padding-top:7px;"
      >
        <p v-if="onlyRead" @click="changeRead">
          <i class="iconfont icon-yulan"></i>
          <span>只读模式</span>
        </p>
        <p v-else @click="changeRead">
          <i class="iconfont icon-yulan"></i>
          <span>编辑模式</span>
        </p>
      </div>
    </div>
    <qrcode :dialog="dialog" :addBody="true" ref="qrcode"></qrcode>
    <firm ref="firm" :dialog="dialog"></firm>
    <supply-dialog ref="supply" :dialog="dialog"></supply-dialog>
    <supplier-dialog ref="supplier" @changeSupplier="supplierChange" :dialog="dialog"></supplier-dialog>
    <guarantee-dialog ref="guarantee" :dialog="dialog"></guarantee-dialog>
    <upload-files-dialog ref="upload" @changeFile="fileChange" :keysArr="filesArr" :dialog="dialog"></upload-files-dialog>
    <upload-img-dialog @changeFile="imgChange" :keysArr="imgsArr" :dialog="dialog"></upload-img-dialog>
    <maintainer-dialog @changeMaintainer="changeMaintainer" ref="maintainer" :dialog="dialog"></maintainer-dialog>
    <insurer-dialog @changeInsurer="changeInsurer" ref="insurer" :dialog="dialog"></insurer-dialog>
    <pic-dialog :dialog="dialog" :keysArr="picsArr" @change="changePics"></pic-dialog>
    <div
      v-show="!main || !main.length"
      style="width:100%;text-align:center;font-size:30px;color:gray;"
    >请选择系统类型</div>
    <div v-show="main && main.length" v-loading="loading" id="handsontable" ref="handsontable"></div>
    <my-pagination v-show="main && main.length" @change="getMain" :page="page"></my-pagination>
    <dialog-assets
      :assetType="[this.mess.deviceId]"
      @close="getClose"
      v-if="dialog.addDevice"
      ref="assets"
      :dialog="dialog"
    ></dialog-assets>
    <details-dialog :iframeSrc="iframeSrc" v-if="dialog.details" :dialog="dialog"></details-dialog>
    <system-relevance @close="reset" :id="systemId" :dialog="dialog"></system-relevance>
  </div>
</template>
<script>
import { getTableHeader, getBillSystemList, updateBusiness, BeatchQueryParam, delBatchList } from "@/api/request";


import tools from "@/assets/js/tools";
import handsonUtils from "@/utils/hasontableUtils"
import showTools from "@/utils/hansontable/notShow"


import qrcode from "@/components/lib/qrcode";
import firm from "@/components/dialogs/list/firm";
import supplyDialog from "@/components/dialogs/list/supplyDialog";
import supplierDialog from "@/components/dialogs/list/supplierDialog";
import maintainerDialog from "@/components/dialogs/list/maintainerDialog";
import insurerDialog from "@/components/dialogs/list/insurerDialog";
import guaranteeDialog from "@/components/dialogs/list/guaranteeDialog";
import uploadFilesDialog from "@/components/dialogs/list/filesDialog";
import uploadImgDialog from "@/components/dialogs/list/uploadImgDialog";
import picDialog from "@/components/dialogs/list/picDialog"
import myPagination from "@/components/lib/myPagination";
import dialogAssets from "@/components/dialogs/addDialog/dialogSystem";
import detailsDialog from "@/components/lib/detailsDia"
import systemRelevance from "@/components/transfers/tableTransfers"

//下拉插件
import "@/assets/js/chosen.jquery.min";
import "@/assets/js/handsontable-chosen-editor";

export default {
  components: {
    qrcode, //二维码页面
    firm, //
    supplyDialog,
    supplierDialog,
    guaranteeDialog,
    uploadFilesDialog,
    maintainerDialog,
    insurerDialog,
    uploadImgDialog,
    picDialog,
    myPagination,
    dialogAssets,
    detailsDialog,
    systemRelevance
  },
  data() {
    return {
      main: [],
      mess: {},
      headers: null,
      page: {
        size: 50,
        sizes: [10, 30, 50, 100, 150, 200],
        total: 0,
        currentPage: 1
      },
      dialog: {
        qrcode: false, //二维码弹窗
        firm: false, //厂商弹窗
        supply: false, //选择供应合同
        supplier: false, //供应商选择
        guarantee: false, //选择保单
        maintainer: false, //选择维修商
        insurer: false, //选择保险公司
        uploadFiles: false,//上传文件
        uploadImgs: false,//上传单个图片
        pic: false, //多个图片
        addDevice: false,
        details: false,//详情页
        relevance: false,//关联设备
      },
      row: null,//被修改的row
      filesArr: [],//保存临时的文件key
      messKey: null,
      imgsArr: [],//临时保存的图片key数组
      picsArr: [],//临时设备图片keys数组
      noShowList: ["SysID", "SysName"],
      projId: this.$route.query.projId,
      copyMain: null,
      iframeSrc: "",
      systemId: "",
      onlyRead: true,
      allMess: true,
      linkNameFalg: false,
      qrcodeUrl: "",//二维码图片地址
      isWatch: true,
      loading: false,
    };
  },
  created() {
  },
  mounted() { },
  methods: {

    //触发父组件change
    getClose(val) {
      this.$emit("close", val)
    },
    //获取表头
    getHeaderData(code) {
      this.mess = code
      getTableHeader({
        code: this.mess.deviceId,
        ProjId: this.projId
      }).then(res => {
        this.headers = res.data.Content;
        this.getMain()
      });
    },
    changeRead() {
      this.onlyRead = !this.onlyRead
      this.getMain()
    },
    changeWatch() {
      this.reset()
    },

    //获取主体数据
    getMain() {
      let _this = this
      let param = {
        data: {
          customInfo: true,
          "limit": {        // 分页查询, 选填.
            "skip": this.page.size * (this.page.currentPage - 1),  // 跳过多少数据
            "count": this.page.size   // 查询跳过300条数据之后的50条 (默认按照创建时间从大-->小排序)
          },
          criteria: {
            id: "",
            type: [this.mess.deviceId]
          }
        },
        secret: this.$route.query.secret,
        ProjId: this.$route.query.projId
      }
      if (this.mess.buildId == "all") {
        param.data.criteria.id = this.mess.ProjId
      } else if (!this.mess.floorId && !this.mess.buildId) {
        param.data.criteria.id = this.mess.ProjId
      } else {
        param.data.criteria.id = this.mess.buildId
      }

      this.loading = true

      getBillSystemList(param, res => {
        if (_this.onlyRead) {
          this.getBatch(res.Content)
        }
        this.loading = false
        this.main = res.Content
        this.copyMain = tools.deepCopy(res.Content)
        this.page.total = res.Count
        if (!!this.hot) {
          this.hot.destroy();
          this.hot = null;
        }
        if (!!res.Content && res.Content.length) {
          this.initHot();
        }
      })
    },

    //撤回
    undo() {
      this.hot.undo();
    },

    //刷新
    reset() {
      this.getMain();
    },

    //添加设备
    addDevice() {
      this.dialog.addDevice = true
      this.$nextTick(() => {
        this.$refs.assets.step(0)
      })
    },

    /**
     * 表头文案处理函数
     * @param list header数组数据
     *
     * @return 处理好的文案
     */
    delHeader(list) {
      let arr = tools.copyArr(list)
      // 如果不是只读状态，添加四大厂商选择
      //   if (!this.onlyRead) {
      //     arr = showTools.assetToArr(arr)
      //   }
      //   console.log(arr)
      let readArr = ["A1", "A2", "B1", "C5", "D1", "D2", "X", "L", "L1", "L2", "F1", "F2", "M"]
      let data = showTools.changeHeader(arr, readArr, this.onlyRead, this.isWatch, this.allMess)
      data.unshift("操作", "关联设备数量");
      return data;
    },

    /**
     * 表头数据处理函数
     * @param list header数组数据
     *
     * @return 处理好的数据格式
     */
    getType(list) {
      let arr = tools.copyArr(list)
      let data = showTools.showTypes(arr, this.onlyRead, this.isWatch, this.allMess)

      data.unshift(
        {
          data: "caozuo",
          renderer: tools.lookDetails,
          readOnly: true
        },
        {
          data: "count",
          renderer: tools.num,
          readOnly: true
        }
      );
      data = data.filter(item => item);
      if (this.onlyRead) {
        data.map(item => {
          item.readOnly = true
        })
      }
      return data;
    },

    changeItem(item) {
      //二维码
      if (item.infopoint_code == "EquipQRCode" && item.visible) {
        return {
          data: "infos." + item.infopoint_code,
          renderer: text.lookQRCode,
          readOnly: true
        }
      }
      //厂商选择
      //   if ((item.infopoint_code == "Brand" || item.infopoint_code == "Specification") && item.visible) {
      //     return {
      //       data: "infos." + item.infopoint_code,
      //       renderer: tools.lookDetails,
      //       readOnly: true
      //     }
      //   }

      //   if (item.infopoint_code == "SupplierContractID" && item.visible) {
      //     return {
      //       data: "infos." + item.infopoint_code,
      //       renderer: tools.lookDetails,
      //       readOnly: true
      //     }
      //   }

      if (item.infopoint_code == "InsuranceNum" && item.visible) {
        //选择保单
        return {
          data: "infos." + item.infopoint_code,
          renderer: tools.lookDetails,
          readOnly: true
        }
      }

      if ((item.infopoint_code == "InsuranceFile" || item.infopoint_code == "Archive") && item.visible) {
        return {
          data: "infos." + item.infopoint_code,
          renderer: tools.lookDetails,
          readOnly: true
        }
      }

      if (
        (
          item.infopoint_code == "InstallPic" ||
          item.infopoint_code == "InstallDrawing" ||
          item.infopoint_code == "Nameplate" ||
          item.infopoint_code == "Pic" ||
          item.infopoint_code == "Drawing"
        ) && item.visible
      ) {
        return {
          data: "infos." + item.infopoint_code,
          renderer: tools.lookDetails,
          readOnly: true
        }
      }

      if (
        (
          item.infopoint_code == "Maintainer" ||
          item.infopoint_code == "Supplier" ||
          item.infopoint_code == "Insurer" ||
          item.infopoint_code == "InsurerContactor"
        )
        && item.visible
      ) {
        return {
          data: "infos." + item.infopoint_code,
        }
      }

      if (item.collection_cmpt_code == "Enum" && item.visible) {
        return {
          data: "infos." + item.infopoint_code,
          renderer: this.customDropdownRenderer,
          editor: "chosen",
          chosenOptions: {
            // multiple: true,//多选
            data: item.dataSource || ""
          }
        };
      } else if (item.collection_cmpt_code == "Num" && item.visible) {
        return {
          data: "infos." + item.infopoint_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.collection_cmpt_code == "Time" && item.visible) {
        return {
          data: "infos." + item.infopoint_code,
          type: "date",
          dateFormat: "YYYY-MM-DD",
          correctFormat: true
        };
      } else if (item.collection_cmpt_code == "text" && item.visible) {
        return {
          data: "infos." + item.infopoint_code
        };
      } else if (
        (item.info_point_code == "设备ID" ||
          item.info_point_code == "设备名称") && item.visible
      ) {
        return {
          data: "infos." + item.infopoint_code,
          readOnly: true
        };
      } else if (item.collection_cmpt_code == "checkBox" && item.visible) {
        return {
          data: "infos." + item.infopoint_code,
          renderer: this.customDropdownRenderer,
          editor: "chosen",
          chosenOptions: {
            multiple: true,//多选
            data: item.dataSource || ""
          }
        };
      } else if (item.collection_cmpt_code == "Own" && item.visible) {
        return {
          data: "infos." + item.infopoint_code,
          renderer: text.idType,
        }
      } else {
        return undefined
      }
    },
    //插件修改
    customDropdownRenderer(
      instance,
      td,
      row,
      col,
      prop,
      value,
      cellProperties
    ) {
      var selectedId;
      var optionsList = cellProperties.chosenOptions.data;
      if (
        typeof optionsList === "undefined" ||
        typeof optionsList.length === "undefined" ||
        !optionsList.length
      ) {
        Handsontable.renderers.TextRenderer(
          instance,
          td,
          row,
          col,
          prop,
          value,
          cellProperties
        );
        return td;
      }
      var values = (value + "").split(",");
      value = [];
      for (var index = 0; index < optionsList.length; index++) {
        if (values.indexOf(optionsList[index].code + "") > -1) {
          selectedId = optionsList[index].code;
          value.push(optionsList[index].name);
        }
      }
      value = value.join(", ");
      Handsontable.renderers.TextRenderer(
        instance,
        td,
        row,
        col,
        prop,
        value,
        cellProperties
      );
      return td;
    },

    messShow(item) {
      if (item.collection_cmpt_code == "Enum") {
        return {
          data: "infos." + item.infopoint_code,
          renderer: this.customDropdownRenderer,
          editor: "chosen",
          chosenOptions: {
            // multiple: true,//多选
            data: item.dataSource || ""
          }
        };
      } else if (item.collection_cmpt_code == "Num") {
        return {
          data: "infos." + item.infopoint_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.collection_cmpt_code == "Time") {
        return {
          data: "infos." + item.infopoint_code,
          type: "date",
          dateFormat: "YYYY-MM-DD",
          correctFormat: true
        };
      } else if (item.collection_cmpt_code == "text") {
        return {
          data: "infos." + item.infopoint_code
        };
      } else if (
        (item.info_point_code == "设备ID" ||
          item.info_point_code == "设备名称")
      ) {
        return {
          data: "infos." + item.infopoint_code,
          readOnly: true
        };
      } else if (item.collection_cmpt_code == "checkBox") {
        return {
          data: "infos." + item.infopoint_code,
          renderer: this.customDropdownRenderer,
          editor: "chosen",
          chosenOptions: {
            multiple: true,//多选
            data: item.dataSource || ""
          }
        };
      } else {
        return {
          data: "infos." + item.infopoint_code,
        }
      }
    },

    //获取动态参数
    getBatch(data) {
      console.log(this.headers, data, "data22222")
      let param = {
        secret: this.$route.query.secret,
        ProjId: this.$route.query.projId,
        data: {
          criterias: []
        }
      }
      if (!!data && data.length) {
        //一级遍历list
        data.map(item => {
          if (!!item.infos) {
            //二级遍历对象infos
            for (let key in item.infos) {
              //判断是否是设定参数和动态参数
              if (!!item.infos[key]) {
                this.headers.map(child => {
                  //如果一级标签为动态参数或者设定参数放入数据等待请求
                  if (key == child.InfoPointCode && (child.InputMode == "L" || child.InputMode == "L1" || child.InputMode == "L2")) {
                    param.data.criterias.push({
                      id: item.id,
                      code: key
                    })
                  }
                })
              }
            }
          }
        })
        if (param.data.criterias.length) {
          BeatchQueryParam(param, res => {
            if (!this.onlyRead) {
              return false
            }
            this.main = data.map(item => {
              res.Content.map(child => {
                if (item.id == child.id) {
                  if (!!child.data || child.data == 0) {
                    item.infos[child.code] = child.data
                  } else {
                    item.infos[child.code] = child.error ? "表号功能号格式错误" : "表号功能号不存在"
                  }
                }
              })
              return item
            })
            console.log(this.main)
            this.hot.loadData(this.main)
          })
        }
      }
    },

    //初始化插件
    initHot() {
      var container = document.getElementById("handsontable");
      let winHeight = document.documentElement.clientHeight;
      this.hot = new Handsontable(container, {
        data: this.main,
        fixedColumnsLeft: 5,
        colHeaders: this.delHeader(this.headers), //表头文案
        columns: this.getType(this.headers), //数据显示格式
        filters: true,
        maxRows: this.main.length,
        height: winHeight - 100 - 50 - 150,
        columnSorting: true, //添加排序
        sortIndicator: true, //添加排序
        renderAllRows: true,
        // colWidths: 200,
        autoColumnSize: true,
        language: "zh-CN",
        manualColumnResize: true,
        manualColumnMove: true,
        dropdownMenu: [
          "filter_by_condition",
          "filter_by_value",
          "filter_action_bar"
        ],
        contextMenu: {
          items: {
            remove_row: {
              name: "删除该系统"
            }
          }
        },
        // 事件
        afterChange: this.tdChange, //修改后
        afterFilter: this.trimmedRows, //排序前
        afterRemoveRow: this.romoveFm, //右键删除
        afterOnCellMouseDown: this.eventClick //鼠标点击
      });
      let pro = document.getElementById("hot-display-license-info");
      if (!!pro) {
        pro.parentNode.removeChild(pro);
      }
      this.isLoading = false;
    },

    //表格中的点击
    eventClick(el, rowArr) {
      //点击的是表头
      if (rowArr.row < 0) {
        return;
      }
      //被筛选过后的数组
      let trimmedArr = this.trimmedRows();
      //是否启用了排序
      let isSort = this.hot.getPlugin("columnSorting").isSorted();
      if (trimmedArr.length && isSort) {
        let sortArr = this.myHotArr.getPlugin("columnSorting").rowsMapper
          .__arrayMap;
        let infos = this.main[trimmedArr[sortArr[rowArr.row]]];
        this.getInfors(infos, { row: sortArr[rowArr.row], col: rowArr.col });
      } else if (isSort) {
        //排序后的数组
        let sortArr = this.hot.getPlugin("columnSorting").rowsMapper.__arrayMap;
        let infos = this.main[sortArr[rowArr.row]];
        this.getInfors(infos, { row: sortArr[rowArr.row], col: rowArr.col });
      } else if (trimmedArr.length) {
        let infos = this.main[trimmedArr[rowArr.row]];
        this.getInfors(infos, { row: trimmedArr[rowArr.row], col: rowArr.col });
      } else {
        let infos = this.main[rowArr.row];
        this.getInfors(infos, rowArr);
      }
    },

    tdChange(changeData, source) {
      if (!this.onlyRead) {
        if (changeData) {
          let trimmedArr = this.trimmedRows();
          let param = handsonUtils.getParam(changeData, source, this.hot, trimmedArr);
          let data = [];
          for (let i = 0; i < param.length; i++) {
            data.push(param[i]);
          }
          //如果data中包含/且data长度为1,将其转换成.
          if (changeData.length == 1 && changeData[0][1].indexOf("/") > 0) {
            changeData[0][1] = changeData[0][1].split("/").join(".")
          }

          //存在data进行修改请求
          if (data && data.length) {
            this.updateBusiness(data, changeData);
          }
        }
      }
    },

    //删除资产
    async romoveFm() {
      this.$confirm('此操作将删除该系统, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        let params = tools.differenceArr(this.main, this.copyMain)
        console.log(params, "params")

        let param = {
          secret: this.$route.query.secret,
          ProjId: this.$route.query.projId,
          data: {
            criterias: []
          }
        }
        for (let i = 0; i < params.length; i++) {
          param.data.criterias.push({ id: params[i].id })
        }
        this.removeSys(param)
        this.getMain()

      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },

    async removeSys(param) {
      await delBatchList(param, res => {
        this.$message.success("删除成功")
      })
    },

    // 修改
    updateBusiness(data, change) {
      let param = {
        ProjId: this.mess.ProjId,
        secret: this.mess.secret,
        data: {
          criterias: []
        }
      };

      //生成对应修改数据
      data.map((item, index) => {
        let arr = change[index][1].split(".");
        let info = {};
        info[arr[1]] = [{ value: change[index][3] != "" ? change[index][3] : null }];
        param.data.criterias.push({
          id: item.id,
          infos: info
        });
      });
      console.log(param)
      param.data.criterias.map(item => {
        for (let k in item.infos) {
          if (item.infos[k] == "") {
            item.infos[k] = null
          }
        }
      })
      updateBusiness(param).then(res => {
        console.log(res);
      });
    },

    //获取到了正确的信息
    getInfors(infos, row) {
      //其他的开始判断
      let val = this.hot.colToProp(row.col);
      this.systemId = infos.id
      if (val == "count") {
        this.dialog.relevance = true
      }
      if (val == "caozuo") {
        this.iframeSrc =
          process.env.BASE_URL +
          ":8889/#/details?perjectId=" +
          this.$route.query.projId +
          "&secret=" +
          this.$route.query.secret +
          "&FmId=" +
          infos.id +
          "&type=1&code=" +
          infos.category.substring(2, 4);
        this.dialog.details = true
      }

      if (val == "infos.EquipQRCode") {
        this.dialog.qrcode = true;
        this.$refs.qrcode.getCanvas(1111);
      }

      //   if (val == "infos.Brand" || val == "infos.Specification") {
      //     this.dialog.firm = true;
      //   }

      //   if (val == "infos.SupplierContractID") {
      //     this.dialog.supply = true;
      //   }

      //   if (val == "infos.InsuranceNum") {
      //     //选择保单
      //     this.dialog.guarantee = true;
      //   }

      if (val == "infos.InsuranceFile" || val == "infos.Archive") {
        this.filesArr = this.main[row.row].infos ? (this.main[row.row].infos[val.split(".")[1]] ? [this.main[row.row].infos[val.split(".")[1]]] : []) : []
        this.dialog.uploadFiles = true
      }

      if (
        val == "infos.InstallLocation" ||
        val == "infos.InstallPic" ||
        val == "infos.InstallDrawing" ||
        val == "infos.Nameplate" ||
        val == "infos.Drawing"
      ) {
        if (val == "infos.Nameplate") {
          this.imgsArr = this.main[row.row].infos ? (this.main[row.row].infos[val.split(".")[1]] ? [this.main[row.row].infos[val.split(".")[1]].key] : []) : []
        } else {
          this.imgsArr = this.main[row.row].infos ? (this.main[row.row].infos[val.split(".")[1]] ? [this.main[row.row].infos[val.split(".")[1]]] : []) : []
        }
        this.dialog.uploadImgs = true
      }

      if (val == "infos.Pic") {
        // console.log(this.main[row.row].infos[val.split(".")[1]], "this.main[row.row].infos[val.split")
        this.picsArr = this.main[row.row].infos ? (this.main[row.row].infos[val.split(".")[1]] ? this.main[row.row].infos[val.split(".")[1]] : []) : []
        this.dialog.pic = true
      }

      //   if (
      //     val == "infos.Supplier"
      //   ) {
      //     this.dialog.supplier = true;
      //   }

      //   if (val == "infos.Maintainer") {
      //     this.dialog.maintainer = true;
      //   }

      //   if (
      //     val == "infos.Insurer" ||
      //     val == "infos.InsurerContactor") {
      //     this.dialog.insurer = true;
      //   }
      this.row = row.row
      this.messKey = val
      console.log(val, row);
    },

    //获取被筛选掉的行号
    trimmedRows() {
      // var plugin = hot.getPlugin('trimRows').trimmedRows;//获取被筛选掉的行号
      var plugin = this.hot.getPlugin("trimRows").trimmedRows;
      let dataLength = this.main.length;
      let dataArr = new Array();
      for (let i = 0; i < dataLength; i++) {
        dataArr.push(i);
      }
      if (plugin.length <= 0) {
        dataArr = undefined;
      } else {
        dataArr = this.array_diff(dataArr, plugin);
      }
      return dataArr || [];
      // var DataArray = new Array();

      // for (var i = 0; i < plugin.length; i++) {
      //     // 通过行号获取数据
      //     DataArray.push(this.hot.getSourceDataAtRow(plugin[i]));
      // }
    },
    //如果选择供应商之后
    supplierChange(data) {
      for (let key in data) {
        if (key == 'name') {
          this.setDataToMain(data[key], "Supplier", this.row)
        }
        if (key == 'email') {
          this.setDataToMain(data[key], "SupplierEmail", this.row)
        }
        if (key == 'website') {
          this.setDataToMain(data[key], "SupplierWeb", this.row)
        }
        if (key == 'phone') {
          this.setDataToMain(data[key], "SupplierPhone", this.row)
        }
        if (key == 'fox') {
          this.setDataToMain(data[key], "SupplierFax", this.row)
        }
        if (key == 'man') {
          this.setDataToMain(data[key], "SupplierContactor", this.row)
        }
      }
      //   tools.setItem(this.deviceType.code, this.main)
    },

    //保险商变更
    changeInsurer(data) {
      for (let key in data) {
        if (key == 'name') {
          this.setDataToMain(data[key], "Insurer", this.row)
        }
        if (key == 'email') {
          this.setDataToMain(data[key], "InsurerEmail", this.row)
        }
        if (key == 'website') {
          this.setDataToMain(data[key], "InsurerWeb", this.row)
        }
        if (key == 'phone') {
          this.setDataToMain(data[key], "InsurerPhone", this.row)
        }
        if (key == 'fox') {
          this.setDataToMain(data[key], "InsurerFax", this.row)
        }
        if (key == 'man') {
          this.setDataToMain(data[key], "InsurerContactor", this.row)
        }
      }
      //   tools.setItem(this.deviceType.code, this.main)
    },

    //维修商变更
    changeMaintainer(data) {
      for (let key in data) {
        if (key == 'name') {
          this.setDataToMain(data[key], "Maintainer", this.row)
        }
        if (key == 'email') {
          this.setDataToMain(data[key], "MaintainerEmail", this.row)
        }
        if (key == 'website') {
          this.setDataToMain(data[key], "MaintainerWeb", this.row)
        }
        if (key == 'phone') {
          this.setDataToMain(data[key], "MaintainerPhone", this.row)
        }
        if (key == 'fox') {
          this.setDataToMain(data[key], "MaintainerFax", this.row)
        }
        if (key == 'man') {
          this.setDataToMain(data[key], "MaintainerContactor", this.row)
        }
      }
      //   tools.setItem(this.deviceType.code, this.main)
    },

    //上传文件弹窗触发事件
    fileChange(keys) {
      this.setDataToMain(keys[0], this.messKey.split(".")[1], this.row)
      //   tools.setItem(this.deviceType.code, this.main)
    },

    //上传图片弹窗触发事件
    imgChange(keys) {
      this.setDataToMain(keys[0], this.messKey.split(".")[1], this.row)
      //   tools.setItem(this.deviceType.code, this.main)
    },

    //设备图片弹窗改变事件
    changePics(keys) {
      this.setDataToMain(keys, this.messKey.split(".")[1], this.row)
      //   tools.setItem(this.deviceType.code, this.main)
    },

    //判断是否有值，有值赋值
    setDataToMain(data, key, row) {
      if (!!data && data != '--') {
        if (!!this.main[row].infos) {
          //falg确定每个的是否有值
          let falg = false
          if (!this.main[row].infos[key]) {
            falg = true
          }
          //铭牌照片特殊处理
          if (key == 'Nameplate') {
            this.main[row].infos[key] = {
              "systemId": "dataPlatform",
              "name": "铭牌照片",
              "type": "image",
              "key": data
            }
          } else {
            this.main[row].infos[key] = data
          }
          if (falg) {
            this.updateBusiness([this.main[row]], [[0, "infos." + key, null, data]])
          }
        } else {
          this.main[row].infos = {}
          if (key == 'Nameplate') {
            this.main[row].infos[key] = {
              "systemId": "dataPlatform",
              "name": "铭牌照片",
              "type": "image",
              "key": data
            }
          } else {
            this.main[row].infos[key] = data
          }
        }
      } else {
        this.main[row].infos[key] = ''
      }
    }
  },
  watch: {
    dialog: {
      deep: true,
      handler: function () {
        // if (!this.dialog.relevance) {
        //   this.reset()
        // }
      }
    }
  }
};
</script>
<style lang="less">
.hanson-bar {
  height: 40px;
  padding: 5px;
  font-size: 16px;
  overflow: hidden;
  .iconfont {
    font-size: 12px;
  }
  .el-button {
    margin-right: 10px;
  }
}
</style>
