<template>
  <div id="deviceList">
    <el-row>
      <el-tabs @tab-click="tabsClick" v-model="tabVal">
        <el-tab-pane v-for="t in partsTypeList" :key="t.Id" :name="t.Code" :label="t.Name+'('+t.Count+')'"></el-tab-pane>
      </el-tabs>
    </el-row>
    <el-row class="left">
      <!-- <div style="width:200px;display:inline-block;text-align:left;color:gray;">
        <span>隐藏自动填充的信息</span>
        <el-checkbox v-model="allMess" @change="getTableHeader"></el-checkbox>
      </div> -->
      <el-button size="small" type="default" icon="el-icon-back" @click="goback" style="margin-right:10px;"></el-button>
      <el-select v-model="showType" @change="initTable" style="width:100px;margin-right:10px;vertical-align:bottom;">
        <el-option v-for="item in showTypes" :key="item.value" :label="item.label" :value="item.value">
        </el-option>
      </el-select>
      <el-button @click="handleCreateTableData">添加部件</el-button>
      <el-button @click="getTableHeader">刷新</el-button>
      <el-button v-show="!onlyRead" @click="undo">撤销</el-button>
      <div style="float:right;overflow:hidden;">
        <span style="width:20px;float:left;display:block;height:20px;cursor: pointer;" @click="changeAssetsFalg">
          <i v-show="!onlyRead" class="el-icon-fa  el-icon-fa-compass"></i>
        </span>
        <span>当前筛选条件下共{{page.total || '--'}}部件</span>
      </div>
    </el-row>
    <div class="tableBox">
      <div class="center middle_sty" v-show="tableData && !tableData.length">
        <p>
          <i class="icon-wushuju iconfont"></i>
          暂无数据
        </p>
      </div>
      <div class="tableLeft" v-show="tableData && tableData.length">
        <handson-table ref="table"></handson-table>
      </div>
    </div>
    <el-pagination class="right" v-show="tableData && tableData.length" @size-change="handleSizeChange" @current-change="handleCurrentChange"
      :current-page="page.pageNumber" :page-sizes="page.pageSizes" :page-size="page.pageSize" layout="total, sizes, prev, pager, next, jumper"
      :total="page.total"></el-pagination>
    <!-- 二维码弹窗 -->
    <qrcode :dialog="myDialog" :qrcodeUrl="qrcodeUrl" :addBody="true" ref="qrcode"></qrcode>
    <!-- 型号弹窗 -->
    <firm :mess="{deviceId: firmId}" ref="firm" @changeFirm="firmChange" :dialog="myDialog"></firm>
    <!-- 供应商合同弹窗 -->
    <supply-dialog ref="supply" @change="supplyChange" :id="id" :dialog="myDialog"></supply-dialog>
    <!-- 供应商弹窗 -->
    <supplier-dialog ref="supplier" @changeSupplier="supplierChange" :dialog="myDialog"></supplier-dialog>
    <guarantee-dialog :id="id" ref="guarantee" @change="guaranteeChange" :dialog="myDialog"></guarantee-dialog>
    <upload-files-dialog :read="onlyRead ? true : false" ref="upload" @changeFile="fileChange" :keysArr="filesArr" :dialog="myDialog">
    </upload-files-dialog>
    <upload-img-dialog :read="onlyRead ? true : false" @changeFile="imgChange" :keysArr="imgsArr" :dialog="myDialog"></upload-img-dialog>
    <maintainer-dialog @changeMaintainer="changeMaintainer" ref="maintainer" :dialog="myDialog"></maintainer-dialog>
    <insurer-dialog @changeInsurer="changeInsurer" ref="insurer" :dialog="myDialog"></insurer-dialog>
    <pic-dialog :read="onlyRead ? true : false" :dialog="myDialog" :keysArr="picsArr" @change="changePics"></pic-dialog>
    <details-dialog :iframeSrc="iframeSrc" v-if="myDialog.details" :dialog="myDialog"></details-dialog>
    <!-- 关联资产 -->
    <change-rea @changeProperty="changeProperty" :dialog="myDialog" :category="deviceType"></change-rea>
    <!-- 不支持的输入方式 -->
    <el-dialog title="临时维护信息点" :visible.sync="myDialog.update" @close="handleCloseUpdate" width="670px">
      <el-row>
        该信息点未定义对应组件，现在维护数据不确定后续是否可用。如确实需要维护，请点击
        <el-link @click="updateInputShow = true" type="primary" :underline="false">继续维护</el-link>
        。
      </el-row>
      <el-row style="margin-top:20px;" v-show="updateInputShow">
        <el-input type="textarea" :autosize="{ minRows: 4, maxRows: 8}" placeholder="请输入内容"
                  v-model="updateInput"></el-input>
      </el-row>
      <span slot="footer" class="dialog-footer">
        <el-button @click="myDialog.update = false">取 消</el-button>
        <el-button type="primary" @click="handleClickUpdate">确 认</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import tools from "@/utils/scan/tools";
import handsonUtils from "@/utils/hasontableUtils";
import showTools from "@/utils/handsontable/notShow";
import text from "@/utils/handsontable/mainText";

import handsonTable from "@/components/common/handsontable";
import {
  getPartsAllType,
  getDataDictionary,
  getEquipPartsCon,
  updateParts,
  deleteParts,
  getEquipBelongs
} from "@/api/scan/request";
import { mapGetters, mapActions } from "vuex";

import qrcode from "@/components/ledger/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 changeRea from "@/components/dialogs/changeRea"
export default {
  components: {
    qrcode, //二维码页面
    firm, //品牌型号弹窗
    supplyDialog,
    supplierDialog,
    maintainerDialog,
    insurerDialog,
    guaranteeDialog,
    uploadFilesDialog,
    uploadImgDialog,
    picDialog,
    handsonTable,
    changeRea
  },
  data() {
    return {
      shaftId: "", //要操作的部件id
      isTableRightShow: false,
      spaceList: "",
      onlyRead: false,
      showTypes: [
        { value: "partInfo", label: '隐藏信息点' },
        { value: "all", label: '全部' },
        { value: "Visible", label: '只看采集信息' }
      ],
      showType: "partInfo",
      tableHeader: [],
      page: {
        pageSize: 50,
        pageSizes: [10, 20, 50, 100],
        pageNumber: 1,
        total: 0
      },
      tableData: [],
      copyTableData: [],
      inputMap: {
        flowBuild: {
          InputMode: 'D1',
          Editable:true,
          InfoPointCode:"flowBuild",
          InfoPointName:"建筑楼层",
          Path:"flowBuild"
        }
      }, //信息点和输入方式映射表
      updateInputShow: false, //是否显示临时维护输入框
      updateInfoPoint: '',//临时维护信息点
      updateInput: '', //临时维护信息点值
      tableExample: null,
      tabVal: "",
      activeTab: {}, //当前tab页index
      partsTypeList: [], //tabs
      myDialog: {
        qrcode: false, //二维码弹窗
        firm: false, //厂商弹窗
        supply: false, //选择供应合同
        supplier: false, //供应商选择
        guarantee: false, //选择保单
        maintainer: false, //选择维修商
        insurer: false, //选择保险公司
        uploadFiles: false, //上传文件
        uploadImgs: false, //上传单个图片
        pic: false, //多个图片
        addDevice: false,
        systemType: false,
        details: false, //详情页
        lookPic: false, //图片查看
        changeRea: false, //关联的资产
        update: false,//临时维护信息点
      },
      qrcodeUrl: "", //二维码图片地址
      filesArr: [], //保存临时的文件key
      imgsArr: [], //临时保存的图片key数组
      picsArr: [], //临时设备图片keys数组
      systemId: null,
      graphyId: null,
      mess: {},
      id: 0,
      EquipmentList: [],
      firmId: "", //品牌型号所需字段--族id三位编码(传设备类id或部件类id)
      deviceType: {},
      queryParam: {}, //返回到指定位置
    };
  },
  computed: {
    ...mapGetters("layout", ["projectId", "secret", "userId"])
  },
  created() {
    this.queryParam = this.$route.query;
    this.deviceId = this.$route.query.deviceId; //设备id
    this.typeId = this.$route.query.typeId; //设备类id
    this.mess.deviceId = this.typeId;
    this.getTypes();
  },
  methods: {
    getBelongs() {
      let params = {
        data: {
          Filters: `EquipCode='${this.tabVal}'`,
          PageNumber: 1,
          PageSize: 50
        }
      }
      getEquipBelongs(params, res => {
        if (res.Content.length) {
          this.firmId = res.Content[0].Family;
          this.deviceType.assetType = res.Content[0].Family
          this.deviceType.assetName = res.Content[0].FamilyName
        }
      })
    },
    //tab页点击事件
    tabsClick(tab) {
      this.activeTab = this.partsTypeList[tab.index];
      this.getTableHeader();
    },
    //获取当前设备类下的所有部件类
    async getTypes() {
      let params = {
        category: this.typeId, //设备类型
        id: this.deviceId //设备id
      };
      await getPartsAllType(params, res => {
        this.partsTypeList = res.Content;
        this.tabVal = this.partsTypeList[0].Code;
        this.activeTab = this.partsTypeList[0];
        this.getTableHeader();
        this.getBelongs();
      });
    },
    // 获取表头数据(初始化表格)
    async getTableHeader() {
      let params = {
        data: {
          Orders: "sort asc, InfoPointName desc",
          PageNumber: 1,
          PageSize: 1000
        },
        type: this.tabVal
      };
      await getDataDictionary(params, res => {
        this.tableHeader = res.Content;
        this.tableHeader.forEach(item => {
          if (item.Path) {
            this.inputMap[item.Path] = item
          }
        })
        this.getTableData();
      });
    },
    //获取表格数据
    async getTableData() {
      let params = {
        PageNumber: this.page.pageNumber,
        PageSize: this.page.pageSize,
        Orders: "createTime desc, EquipLocalName desc, EquipLocalID desc, EquipID desc",
        Filters: `category='${this.tabVal}';parentId='${this.deviceId}'`
      };
      await getEquipPartsCon(params, res => {
        this.tableData = res.Content;
        this.copyTableData = tools.deepCopy(res.Content);
        this.page.pageNumber = res.PageNumber;
        this.page.total = res.Total;
        if (this.tableData && this.tableData.length) {
          this.initTable();
        }
      });
    },
    // 修改表格内容
    async updateTableData(data, change) {
      let param = {
        projectId: this.projectId,
        data: {
          Content: [],
          Projection: []
        }
      }, keyList = [];
      //生成要修改字段列表
      change.map((item) => {
        let key = item[1].split(".")[0]
        if (item[1] && keyList.indexOf(key) == -1) {
          keyList.push(key)
        }
        if (item[1] && item[3] == "" && param.data.Projection.indexOf(key) == -1) {
          param.data.Projection.push(key)
        }
      })
      //生成对应修改数据
      data.map((item, index) => {
        keyList.map(value => {
          let itemData = tools.dataForKey(item, value);
          tools.setDataForKey(item, value, itemData == "" ? null : itemData);
        });
        // let keyarr = change[index][1].split(".");
        // if (keyarr && keyarr.length > 1) {
        //   item[keyarr[0]][keyarr[1]] =
        //     item[keyarr[0]][keyarr[1]] != ""
        //       ? item[keyarr[0]][keyarr[1]]
        //       : null;
        // } else {
        //   item[keyarr[0]] = item[keyarr[0]] != "" ? item[keyarr[0]] : null;
        // }
        param.data.Content.push(item);
      });
      param.Projection = []
      await updateParts(param, res => { });
    },
    // 删除表格数据
    async deleteTableData(params) {
      await deleteParts(params, res => {
        this.$message.success("删除成功!");
        this.getTypes();
      });
    },
    //保存元空间关联
    async saveSpaceList() {
      let data = {
        ShaftId: this.shaftId,
        SpaceId: this.spaceList
      };
      const params = {
        ProjId: this.projectId,
        secret: this.secret,
        data: data
      };
      await saveCenoteRelateSpace(params, res => {
        this.$message.success("关联成功!");
        this.getTableHeader();
      });
    },
    // 添加部件
    handleCreateTableData() {
      this.activeTab.deviceId = this.deviceId;
      this.$router.push({
        name: "partsadd",
        query: {
          ...this.activeTab,
          pageNo: this.queryParam.pageNo,
          pageSize: this.queryParam.pageSize,
          showType: this.showType
        }
      });
    },
    // 删除表格行
    handleDeleteTableRow() {
      let params = tools.differenceArr(this.tableData, this.copyTableData);
      if (params.length < 1 || this.tableData > this.copyTableData) {
        return;
      }
      let param = {
        projectId: this.projectId,
        data: []
      };
      params.map(item => {
        param.data.push({ EquipID: item.EquipID });
      });
      this.$confirm("此操作将删除部件，是否继续？", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          this.deleteTableData(param);
        })
        .catch(() => {
          this.getTableHeader();
          this.$message("取消删除");
        });
    },
    //修改
    handleUpdataTable(changeData, source) {
      if (!this.onlyRead) {
        if (changeData) {
          let trimmedArr = this.trimmedRows();
          let param = handsonUtils.getParam(
            changeData,
            source,
            this.tableExample,
            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] &&
            changeData[0][1].indexOf("/") > 0
          ) {
            changeData[0][1] = changeData[0][1].split("/").join(".");
          }

          // 存在data进行修改请求
          if (data && data.length) {
            this.updateTableData(data, changeData);
          }
        }
      }
    },
    //撤回
    undo() {
      this.tableExample.undo();
    },
    //切换每页显示多少条数据
    handleSizeChange(val) {
      this.page.pageSize = val;
      this.getTableHeader();
    },
    //切换页数
    handleCurrentChange(val) {
      this.page.pageNumber = val;
      this.getTableHeader();
    },
    formatHeaderData(list) {
      //格式化表头显示的数据
      let arr = tools.copyArr(list)
      let data = showTools.headerTextFilter(arr, "parts", this.onlyRead, this.showType, true)
      data.unshift("查看详情", "当前关联的资产")
      return data
    },
    formatHeaderType(list) {
      //格式化表头头映射的数据
      let arr = tools.copyArr(list);
      let data = showTools.headerTypeFilter(arr, "parts", this.onlyRead, this.showType, true)
      data.unshift(
        {
          data: "caozuo",
          renderer: tools.lookDetails,
          readOnly: true
        },
        {
          data: "PropertyLocalName",
          readOnly: true
        }
      );
      return data;
    },
    initTable() {
      //实例化表格
      let settings = {
        data: this.tableData,
        colHeaders: this.formatHeaderData(this.tableHeader),
        columns: this.formatHeaderType(this.tableHeader),
        rowHeights: 30,
        maxRows: this.tableData.length,
        contextMenu: this.onlyRead ? false : {
          items: {
            remove_row: {
              name: "删除部件"
            }
          }
        },
        // 事件
        afterChange: this.handleUpdataTable, //修改后
        afterRemoveRow: this.handleDeleteTableRow, //右键删除
        afterOnCellMouseDown: this.handleTdClick //鼠标点击
      };
      this.$nextTick(() => {
        this.tableExample = this.$refs.table.init(settings);
      });
    },
    //去除数组中相同的元素
    array_diff(a, b) {
      for (var i = 0; i < b.length; i++) {
        for (var j = 0; j < a.length; j++) {
          if (a[j] == b[i]) {
            a.splice(j, 1);
            j = j - 1;
          }
        }
      }
      return a;
    },
    //选择型号修改
    firmChange(data) {
      tools.setDataForKey(this.tableData[this.row], "DPManufacturerID", data.venderId)//生产商ID
      tools.setDataForKey(this.tableData[this.row], "DPBrandID", data.brandId)//品牌ID
      tools.setDataForKey(this.tableData[this.row], "DPSpecificationID", data.specificationId)//型号ID
      tools.setDataForKey(this.tableData[this.row], "LedgerParam.EquipManufactor.Manufacturer", data.venderName)
      tools.setDataForKey(this.tableData[this.row], "LedgerParam.EquipManufactor.Brand", data.brandName)
      tools.setDataForKey(this.tableData[this.row], "LedgerParam.EquipManufactor.Specification", data.name)
      this.handleUpdataTable(
        [
          [this.row, "DPManufacturerID", null, data.venderId],
          [this.row, "DPBrandID", null, data.brandId],
          [this.row, "DPSpecificationID", null, data.specificationId],
          [this.row, "LedgerParam.EquipManufactor.Manufacturer", null, data.venderName],
          [this.row, "LedgerParam.EquipManufactor.Brand", null, data.brandName],
          [this.row, "LedgerParam.EquipManufactor.Specification", null, data.name]
        ],
        "edit"
      )
      // this.handleUpdataTable([[this.row, "LedgerParam.EquipManufactor.Brand", null, data.brand]], "edit")
      // this.handleUpdataTable([[this.row, "LedgerParam.EquipManufactor.Specification", null, data.name]], "edit")
    },
    //供应商变更
    supplierChange(data) {
      tools.setDataForKey(this.tableData[this.row], 'DPSupplierID', data.venderId)
      tools.setDataForKey(this.tableData[this.row], 'LedgerParam.SupplyPurchase.Supplier', data.name)
      tools.setDataForKey(this.tableData[this.row], 'LedgerParam.SupplyPurchase.SupplierPhone', data.contacts[0]?data.contacts[0].phone:null)
      tools.setDataForKey(this.tableData[this.row], 'LedgerParam.SupplyPurchase.SupplierContactor', data.contacts[0]?data.contacts[0].name:null)
      tools.setDataForKey(this.tableData[this.row], 'LedgerParam.SupplyPurchase.SupplierWeb', data.website?data.website:null)
      tools.setDataForKey(this.tableData[this.row], 'LedgerParam.SupplyPurchase.SupplierEmail', data.contacts[0]?data.contacts[0].email:null)
      tools.setDataForKey(this.tableData[this.row], 'LedgerParam.SupplyPurchase.SupplierFax', data.contacts[0]?data.contacts[0].fax:null)
      this.handleUpdataTable(
          [
              [this.row, 'DPSupplierID', null, data.venderId],
              [this.row, 'LedgerParam.SupplyPurchase.Supplier', null, data.name],
              [this.row, 'LedgerParam.SupplyPurchase.SupplierPhone', null, data.contacts[0]?data.contacts[0].phone:null],
              [this.row, 'LedgerParam.SupplyPurchase.SupplierContactor', null, data.contacts[0]?data.contacts[0].name:null],
              [this.row, 'LedgerParam.SupplyPurchase.SupplierWeb', null, data.website?data.website:null],
              [this.row, 'LedgerParam.SupplyPurchase.SupplierEmail', null, data.contacts[0]?data.contacts[0].email:null],
              [this.row, 'LedgerParam.SupplyPurchase.SupplierFax', null, data.contacts[0]?data.contacts[0].fax:null],
          ],
          'edit'
      )
      // this.handleUpdataTable([[this.row, "LedgerParam.SupplyPurchase.Supplier", null, data.name]], "edit")
    },
    //保险商变更
    changeInsurer(data) {
      tools.setDataForKey(this.tableData[this.row], 'DPInsurerID', data.venderId)
      tools.setDataForKey(this.tableData[this.row], 'LedgerParam.InsuranceDoc.Insurer', data.name?data.name:null)
      tools.setDataForKey(this.tableData[this.row], 'LedgerParam.InsuranceDoc.InsurerWeb', data.website?data.website:null)
      tools.setDataForKey(this.tableData[this.row], 'LedgerParam.InsuranceDoc.InsurerEmail', data.contacts[0]?data.contacts[0].email:null)
      tools.setDataForKey(this.tableData[this.row], 'LedgerParam.InsuranceDoc.InsurerFax', data.contacts[0]?data.contacts[0].fax:null)
      tools.setDataForKey(this.tableData[this.row], 'LedgerParam.InsuranceDoc.InsurerPhone', data.contacts[0]?data.contacts[0].phone:null)
      tools.setDataForKey(this.tableData[this.row], 'LedgerParam.InsuranceDoc.InsurerContactor', data.contacts[0]?data.contacts[0].name:null)
      this.handleUpdataTable(
          [
              [this.row, 'DPInsurerID', null, data.venderId],
              [this.row, 'LedgerParam.InsuranceDoc.Insurer', null, data.name?data.name:null],
              [this.row, 'LedgerParam.InsuranceDoc.InsurerWeb', null, data.website?data.website:null],
              [this.row, 'LedgerParam.InsuranceDoc.InsurerEmail', null, data.contacts[0]?data.contacts[0].email:null],
              [this.row, 'LedgerParam.InsuranceDoc.InsurerFax', null, data.contacts[0]?data.contacts[0].fax:null],
              [this.row, 'LedgerParam.InsuranceDoc.InsurerPhone', null, data.contacts[0]?data.contacts[0].phone:null],
              [this.row, 'LedgerParam.InsuranceDoc.InsurerContactor', null, data.contacts[0]?data.contacts[0].name:null],
          ],
          'edit'
      )
      // this.handleUpdataTable([[this.row, "LedgerParam.InsuranceDoc.Insurer", null, data.name]], "edit")
    },
    //维修商变更
    changeMaintainer(data) {
      tools.setDataForKey(this.tableData[this.row], 'DPMaintainerID', data.venderId)
      tools.setDataForKey(this.tableData[this.row], 'LedgerParam.OperationMainte.Maintainer', data.name)
      tools.setDataForKey(this.tableData[this.row], 'LedgerParam.OperationMainte.MaintainerWeb', data.website?data.website:null)
      tools.setDataForKey(this.tableData[this.row], 'LedgerParam.OperationMainte.MaintainerContactor', data.contacts[0]?data.contacts[0].name:null)
      tools.setDataForKey(this.tableData[this.row], 'LedgerParam.OperationMainte.MaintainerPhone', data.contacts[0]?data.contacts[0].phone:null)
      tools.setDataForKey(this.tableData[this.row], 'LedgerParam.OperationMainte.MaintainerEmail', data.contacts[0]?data.contacts[0].email:null)
      tools.setDataForKey(this.tableData[this.row], 'LedgerParam.OperationMainte.MaintainerFax', data.contacts[0]?data.contacts[0].fax:null)
      this.handleUpdataTable(
          [
              [this.row, 'DPMaintainerID', null, data.venderId],
              [this.row, 'LedgerParam.OperationMainte.Maintainer', null, data.name],
              [this.row, 'LedgerParam.OperationMainte.MaintainerWeb', null, data.website?data.website:null],
              [this.row, 'LedgerParam.OperationMainte.MaintainerContactor', null, data.contacts[0]?data.contacts[0].name:null],
              [this.row, 'LedgerParam.OperationMainte.MaintainerPhone', null, data.contacts[0]?data.contacts[0].phone:null],
              [this.row, 'LedgerParam.OperationMainte.MaintainerEmail', null, data.contacts[0]?data.contacts[0].email:null],
              [this.row, 'LedgerParam.OperationMainte.MaintainerFax', null, data.contacts[0]?data.contacts[0].fax:null],
          ],
          'edit'
      )
      // this.handleUpdataTable([[this.row, "LedgerParam.OperationMainte.Maintainer", null, data.name]], "edit")
    },
    supplyChange(data) {
      tools.setDataForKey(this.tableData[this.row], "LedgerParam.SupplyPurchase.SupplierContractID", { id: data });
    },
    //保险合同
    guaranteeChange(data) {
      for (let key in data) {
        this.utilToKey(key, "insuranceNo", data, "InsuranceNum");
        if (key == "contractFile") {
          if (!!data[key]) {
            data[key] = [data[key]];
          }
        }
        this.utilToKey(key, "contractFile", data, "InsuranceFile");
      }
    },
    //修改关联的资产
    changeProperty(val) {
      this.setDataToMain(val.PropertyId, 'PropertyId', this.row);
      this.setDataToMain(val.LinkEquipLocalName, 'LinkEquipLocalName', this.row);
    },
    //上传文件弹窗触发事件
    fileChange(keys) {
      this.setDataToMain(keys, this.messKey, this.row);
    },
    //上传图片弹窗触发事件
    imgChange(keys) {
      this.setDataToMain(keys, this.messKey, this.row);
    },
    //设备图片弹窗改变事件
    changePics(keys) {
      this.setDataToMain(keys, this.messKey, this.row);
    },
    //表格点击事件
    handleTdClick(el, rowArr) {
      //点击的是表头
      if (rowArr.row < 0) {
        return;
      }
      //被筛选过后的数组
      let trimmedArr = this.trimmedRows();
      //是否启用了排序
      let isSort = this.tableExample.getPlugin("columnSorting").isSorted();
      if (trimmedArr.length && isSort) {
        let sortArr = this.myHotArr.getPlugin("columnSorting").rowsMapper
          .__arrayMap;
        let infos = this.tableData[trimmedArr[sortArr[rowArr.row]]];
        this.getInfors(infos, { row: sortArr[rowArr.row], col: rowArr.col });
      } else if (isSort) {
        //排序后的数组
        let sortArr = this.tableExample.getPlugin("columnSorting").rowsMapper
          .__arrayMap;
        let infos = this.tableData[sortArr[rowArr.row]];
        this.getInfors(infos, { row: sortArr[rowArr.row], col: rowArr.col });
      } else if (trimmedArr.length) {
        let infos = this.tableData[trimmedArr[rowArr.row]];
        this.getInfors(infos, { row: trimmedArr[rowArr.row], col: rowArr.col });
      } else {
        let infos = this.tableData[rowArr.row];
        this.getInfors(infos, rowArr);
      }
    },
    //获取被筛选掉的行号
    trimmedRows() {
      var plugin = this.tableExample.getPlugin("trimRows").trimmedRows;
      let dataLength = this.tableData.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 || [];
    },
    getInfors(infos, row) {
      this.row = row.row;
      let val = this.tableExample.colToProp(row.col);
      let inputData = this.inputMap[val];
      this.messKey = val;
      switch (val) {
        //操作
        case 'caozuo':
          // window.open(`http://adm.sagacloud.cn:8058/spread?id=${infos.EquipID}&pid=${this.projectId}&secret=${this.secret}`,"_blank")
          this.$message("开发中...")
          break;
        //设备二维码图片
        case 'EquipQRCode':
          this.qrcodeUrl = this.tableData[row.row].EquipQRCode;
          if (!!this.qrcodeUrl) {
            this.myDialog.qrcode = true;
          } else {
            this.$message("此设备没有设备二维码");
          }
          break;
        //关联系统
        case 'LinkSystem':
          if (!this.onlyRead) {
            this.curDevice = infos.EquipID;
            this.systemList = this.tableData[row.row].LinkSystem || [];
            this.myDialog.systemType = true;
          }
          break;
        //关联资产
        case 'PropertyLocalName':
          if (this.linkNameFalg) {
            this.myDialog.changeRea = true;
          }
          break;
        //品牌型号弹窗
        case 'DPManufacturerID':
          if (!this.onlyRead) {
            this.myDialog.firm = true;
          }
          break;
        //供应商信息弹窗
        case 'DPSupplierID':
          if (!this.onlyRead) {
            this.myDialog.supplier = true;
          }
          break;
        //维修商信息弹窗
        case 'DPMaintainerID':
          if (!this.onlyRead) {
            this.myDialog.maintainer = true;
          }
          break;
        //保险公司信息
        case 'DPInsurerID':
          if (!this.onlyRead) {
            this.myDialog.insurer = true;
          }
          break;
        //供应合同编号
        case 'LedgerParam.SupplyPurchase.SupplierContractID':
          if (!this.onlyRead) {
            let ContractIDflag = null;
            let DPSdata = this.tableData[row.row].DPSupplierID;
            if (DPSdata) {
              ContractIDflag = DPSdata.split("-")[0];
            }
            if (!!ContractIDflag) {
              this.id = ContractIDflag;
              this.myDialog.supply = true;
            } else {
              this.$message("请先选择供应商");
            }
          }
          break;
        //保险单号
        case 'LedgerParam.InsuranceDoc.InsuranceNum':
          if (!this.onlyRead) {
            let DPInsurerIDflag = null;
            let DPIdata = this.tableData[row.row].DPInsurerID;
            if (DPIdata) {
              DPInsurerIDflag = DPIdata.split("-")[0];
            }
            if (!!DPInsurerIDflag) {
              this.id = DPInsurerIDflag;
              this.myDialog.guarantee = true;
            } else {
              this.$message("请先选择保险商");
            }
          }
          break;
        //保险文件--设备文档--安装质检报告
        case 'LedgerParam.InsuranceDoc.InsuranceFile': //保险文件
        case 'LedgerParam.PhotoDoc.Archive': //设备文档
        case 'LedgerParam.Siteinstall.CheckReport': //安装质检报告
        case 'LedgerParam.OperationMainte.MaintainManual': //维修保养手册
        case 'LedgerParam.SupplyPurchase.ApproachingAcceptance': //进场验收单
        case 'LedgerParam.SupplyPurchase.AcceptanceReport': //验收报告
        case 'LedgerParam.PhotoDoc.OperationManual': //操作说明书
        case 'LedgerParam.EquipManufactor.OriginalCertificate': //原厂证明
        case 'LedgerParam.EquipManufactor.TestReport': //检测报告
        case 'LedgerParam.PhotoDoc.ProductCertification': //产品合格证
        case 'LedgerParam.Siteinstall.InstallInstruction': //安装说明书
        case 'LedgerParam.SupplyPurchase.SupplierContract': //供应合同
        case 'LedgerParam.PhotoDoc.Drawing': //设备图纸
        case 'LedgerParam.Siteinstall.InstallDrawing': //安装图纸
          let IPSdata = tools.dataForKey(this.tableData[row.row], val);
          this.filesArr = IPSdata ? IPSdata : [];
          this.myDialog.uploadFiles = true;
          break;
        //安装照片--设备铭牌照片
        case 'LedgerParam.Siteinstall.InstallPic':
        case 'LedgerParam.PhotoDoc.Nameplate':
          let SSPPdata = tools.dataForKey(this.tableData[row.row], val);
          this.imgsArr = SSPPdata ? SSPPdata : [];
          this.myDialog.uploadImgs = true;
          break;
        //设备照片
        case 'LedgerParam.PhotoDoc.Pic':
          let Pdata = tools.dataForKey(this.tableData[row.row], val);
          this.picsArr = Pdata ? Pdata : [];
          this.myDialog.pic = true;
          break;
        //包含的部件字段
        case 'Count':
          if (this.onlyRead) {
            this.$router.push({ path: '/ledger/parts', query: { deviceId: infos.EquipID } });
          } else {
            this.$router.push({ path: '/ledger/partsmanage', query: { deviceId: infos.EquipID, typeId: this.mess.deviceId } });
          }
          break;
        default:
          break;
      }
      if (!this.onlyRead && !inputData.Editable) {
        this.$message("该信息点的值为自动生成，不可人工维护！");
        return false;
      }
      if (!this.onlyRead && showTools.InputModeArr.indexOf(inputData.inputMode) == '-1') {
        this.updateInfoPoint = val;
        this.updateInput = tools.dataForKey(this.tableData[row.row], val);
        this.myDialog.update = true;
        return false;
      }
    },
    //关闭临时维护弹窗回调
    handleCloseUpdate() {
      this.updateInputShow = false
      this.updateInfoPoint = ''
      this.updateInput = ''
    },
    //更新临时维护信息点
    handleClickUpdate() {
      // this.$message("更新成功");
      tools.setDataForKey(this.tableData[this.row], this.updateInfoPoint, this.updateInput)
      this.handleUpdataTable([[this.row, this.updateInfoPoint, null, this.updateInput]], "edit")
      this.updateInputShow = false
      this.myDialog.update = false
      this.updateInput = ''
    },
    utilToKey(key, name, data, messName) {
      if (key == name) {
        this.setDataToMain(data[key], messName, this.row);
      }
    },
    //判断是否有值，有值赋值
    setDataToMain(data, key, row) {
      if (!!data && data != "--") {
        if (!!this.tableData[row]) {
          tools.setDataForKey(this.tableData[row], key, data);
          this.handleUpdataTable([[row, key, null, data]], "edit");
        } else {
          this.tableData[row] = {};
          tools.setDataForKey(this.tableData[row], key, data);
        }
      } else {
        tools.setDataForKey(this.tableData[row], key, "");
      }
    },
    //修改资产
    changeAssetsFalg() {
      if (this.linkNameFalg) {
        this.linkNameFalg = false
      } else {
        this.$confirm('<p>真的要在这里修改部件关联的资产么?</p><p>真的能通过列表信息找到想关联的资产么？</p><p>在这里修改关联的资产一定是因为之前关联错了要修改么？</p>', '提示', {
          dangerouslyUseHTMLString: true,
          confirmButtonText: '没错！我要改关联的资产',
          cancelButtonText: '我就点开看看',
          confirmButtonClass: 'cancelButtonClass',
          cancelButtonClass: 'cancelButtonClass'
        }).then(_ => {
          this.linkNameFalg = true
        }).catch(_ => {
          this.$message("取消")
        })
      }
    },
    // 返回
    goback() {
      this.$router.push({
        name: 'facilityLedger',
        params: {
          deviceId: this.queryParam.typeId,
          pageNo: this.queryParam.pageNo,
          pageSize: this.queryParam.pageSize,
          readOnly: false
        }
      })
    }
  }
};
</script>
<style lang="less" scoped>
#deviceList {
  overflow: hidden;
  height: 100%;
  background-color: #fff;
  padding: 10px;
  position: relative;
  .right {
    background: #fff;
  }
  .search-header {
    overflow: hidden;
    padding: 0 10px 10px 10px;
    border-bottom: 1px solid #bcbcbc;
  }
  .tableBox {
    display: flex;
    height: calc(100% - 150px);
    margin-top: 10px;
    .tableLeft,
    .middle_sty {
      flex: 1;
    }
  }
}
.el-pagination button,
.el-pagination span:not([class*="suffix"]) {
  vertical-align: middle;
}
</style>
