Browse Source

添加租户

zhangyu 5 years ago
parent
commit
26cf5dfc91

+ 50 - 1
src/api/scan/request.js

@@ -728,7 +728,7 @@ export function delBatchList(param, success) {
     http.postJson(url, data, success)
 }
 
-//台账获取竖井类型
+//获取竖井类型
 export function getCenoteType(param, success) {
     let url = `${baseUrl}/datacenter/shaft/queryShaftFuncType?projectId=${param.ProjId}&secret=${param.secret}`
     let data = param.data
@@ -749,6 +749,55 @@ export function getCenoteTableData(param, success) {
     http.postJson(url, data, success)
 }
 
+//修改竖井信息
+export function updataCenoteTableData(param, success) {
+    let url = `${baseUrl}/datacenter/shaft/update?projectId=${param.ProjId}&secret=${param.secret}`
+    let data = param.data
+    http.postJson(url, data, success)
+}
+
+//删除竖井信息
+export function deleteCenoteTableData(param, success) {
+    let url = `${baseUrl}/datacenter/shaft/delete?projectId=${param.ProjId}&secret=${param.secret}`
+    let data = param.data
+    http.postJson(url, data, success)
+}
+
+//竖井关联元空间
+export function saveCenoteRelateSpace(param, success) {
+    let url = `${baseUrl}/datacenter/shaft/relateSpace?projectId=${param.ProjId}&secret=${param.secret}`
+    let data = param.data
+    http.postJson(url, data, success)
+}
+
+//获取租户表头信息
+export function getRentTableHeader(param, success) {
+    let url = `${baseUrl}/datacenter/tenant/queryDic?projectId=${param.ProjId}&secret=${param.secret}`
+    let data = param.data
+    http.postJson(url, data, success)
+}
+
+//获取租户表格内容信息
+export function getRentTableData(param, success) {
+    let url = `${baseUrl}/datacenter/tenant/queryWithCount?projectId=${param.ProjId}&secret=${param.secret}`
+    let data = param.data
+    http.postJson(url, data, success)
+}
+
+//修改租户信息
+export function updataRentTableData(param, success) {
+    let url = `${baseUrl}/datacenter/tenant/update?projectId=${param.ProjId}&secret=${param.secret}`
+    let data = param.data
+    http.postJson(url, data, success)
+}
+
+//删除租户信息
+export function deleteRentTableData(param, success) {
+    let url = `${baseUrl}/datacenter/tenant/delete?projectId=${param.ProjId}&secret=${param.secret}`
+    let data = param.data
+    http.postJson(url, data, success)
+}
+
 //扫楼创建资产
 export function createFmList(param, success) {
     let url = `${api}/service/fm/create`

+ 5 - 2
src/components/ledger/lib/cenoteType.vue

@@ -26,11 +26,14 @@ export default {
     };
   },
   created() {
-    this.getData();
+    this.getData()
   },
   watch: {
     projectId() {
-      this.id = "";
+      this.getData()
+      if (this.options.length) {
+        this.changeVal(this.options[0].ID)
+      }
     }
   },
   methods: {

+ 126 - 5
src/utils/handsontable/notShow.js

@@ -58,7 +58,9 @@ let cantShow = [
     "InsurerFax",
     "InsuranceFile",
     "EquipID",
-    "EquipName"
+    "EquipName",
+    "SpaceCount",
+    "SpaceList"
 ]
 
 let cutArr = [{
@@ -509,9 +511,7 @@ const showTools = {
             if (item.InfoPointCode == "BIMLocation") {
                 return undefined
             }
-            if (
-                readArr.indexOf(item.InputMode) > -1
-            ) {
+            if (!!readArr && readArr.indexOf(item.InputMode) > -1 ) {
                 if (item.Visible || !allMess) {
                     if (!showTools.cantShow(item.InfoPointCode) && !onlyRead && !taizhang) {
                         return undefined
@@ -522,7 +522,7 @@ const showTools = {
                             return undefined
                         }
                     }
-                    if (item.Unit == "") {
+                    if (!item.Unit || item.Unit == "") {
                         return item.InfoPointName;
                     } else {
                         return item.InfoPointName + "(" + item.Unit + ")";
@@ -535,6 +535,127 @@ const showTools = {
             }
         }).filter(d => d);
         return data
+    },
+
+    showHeaderTypes(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.InfoPointCode == "BIMLocation") {
+                return undefined
+            }
+            if (!!typeArr && typeArr.indexOf(item.InputMode) > -1) {
+                return undefined
+            }
+            if (item.Visible || !allMess) {
+                //固定不显示的code
+                if (!showTools.cantShow(item.InfoPointCode) && !onlyRead) {
+                    return undefined
+                }
+
+                if (!showTools.isShow(item.InfoPointCode)) {
+                    if (isWatch && !onlyRead) {
+                        return undefined
+                    }
+                }
+
+                if (item.InfoPointCode == "EquipQRCode") {
+                    return {
+                        data: item.InfoPointCode,
+                        renderer: text.lookQRCode,
+                        readOnly: onlyRead
+                    }
+                }
+
+                //图片类型
+                if (
+                    item.InfoPointCode == "InstallPic" ||
+                    item.InfoPointCode == "InstallDrawing" ||
+                    item.InfoPointCode == "Nameplate" ||
+                    item.InfoPointCode == "Pic" ||
+                    item.InfoPointCode == "Drawing"
+                ) {
+                    return {
+                        data: item.InfoPointCode,
+                        renderer: text.picType,
+                        readOnly: onlyRead
+                    }
+                }
+
+                //文件类型
+                if (item.InfoPointCode == "InsuranceFile" ||
+                    item.InfoPointCode == "Archive" ||
+                    item.InfoPointCode == "CheckReport") {
+                    return {
+                        data: item.InfoPointCode,
+                        renderer: text.fileType,
+                        readOnly: onlyRead
+                    }
+                }
+
+                if (item.InputMode == "D1" || item.InputMode == "D2") {
+                    return {
+                        data: item.InfoPointCode,
+                        renderer: tools.customDropdownRenderer,
+                        editor: "chosen",
+                        readOnly: onlyRead,
+                        chosenOptions: {
+                            multiple: true, //多选
+                            data: item.optionList || ""
+                        }
+                    };
+                } else if (item.InputMode == "E1") {//单选
+                    return {
+                        data: item.InfoPointCode,
+                        renderer: tools.customDropdownRenderer,
+                        editor: "chosen",
+                        readOnly: onlyRead,
+                        chosenOptions: {
+                            data: item.optionList || ""
+                        }
+                    };
+                } else if (item.InputMode == "A1" || item.InputMode == "A2") {
+                    return {
+                        data: item.InfoPointCode,
+                        type: "numeric",
+                        readOnly: onlyRead,
+                        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: item.InfoPointCode,
+                        type: "date",
+                        dateFormat: "YYYY-MM-DD",
+                        readOnly: onlyRead,
+                        correctFormat: true
+                    };
+                } else if (item.InputMode == "Own" && !onlyRead) {
+                    return {
+                        data: item.InfoPointCode,
+                        renderer: text.idType,
+                        readOnly: onlyRead
+                    }
+                } else {
+                    return {
+                        data: item.InfoPointCode,
+                        readOnly: onlyRead
+                    };
+                }
+            } else {
+                return undefined
+            }
+
+        }).filter(item => item);
+        return data
     }
 }
 

+ 231 - 83
src/views/ledger/cenotelist/index.vue

@@ -16,10 +16,10 @@
       </el-select>
       <el-button>添加竖井</el-button>
       <el-button @click="getTableHeader">刷新</el-button>
-      <el-button v-show="!onlyRead">撤销</el-button>
+      <el-button v-show="!onlyRead" @click="undo">撤销</el-button>
     </el-row>
     <div class="tableBox">
-      <div class="center middle_sty" style="flex:1;" v-show="tableData && !tableData.length">
+      <div class="center middle_sty" style="flex:2;" v-show="tableData && !tableData.length">
         <p>
           <i class="iconwushuju iconfont"></i>
           暂无数据
@@ -28,21 +28,23 @@
       <div class="tableLeft" v-show="tableData && tableData.length">
         <handson-table ref="table"></handson-table>
       </div>
-      <div class="tableRight" v-show="tableData && tableData.length">
-        <div class="table_right_box"><span class="iconfont close_right">&#xe66b;</span></div>
-        <h5>管理需要关联的元空间</h5>
-        <p style="margin-bottom: 10px;">以下为关联的元空间id</p>
-        <el-input
-          type="textarea"
-          :autosize="{ minRows: 6, maxRows: 10}"
-          :disabled="onlyRead"
-          placeholder="请输入元空间id,以“,”分割"
-          v-model="relationids">
-        </el-input>
-        <el-row class="right" v-show="!onlyRead">
-          <el-button>取消</el-button>
-          <el-button type="primary">保存</el-button>
-        </el-row>
+      <div class="tableRight">
+        <div v-show="isTableRightShow">
+          <div class="table_right_box"><span class="iconfont close_right" @click="handleCloseRight">&#xe66b;</span></div>
+          <h5>管理需要关联的元空间</h5>
+          <p style="margin-bottom: 10px;">以下为关联的元空间id</p>
+          <el-input
+            type="textarea"
+            :autosize="{ minRows: 6, maxRows: 10}"
+            :disabled="onlyRead"
+            placeholder="请输入元空间id,以“,”分割"
+            v-model="spaceList">
+          </el-input>
+          <el-row class="right" v-show="!onlyRead">
+            <el-button @click="handleCloseRight">取消</el-button>
+            <el-button @click="saveSpaceList" type="primary">保存</el-button>
+          </el-row>
+        </div>
       </div>
     </div>
     <el-pagination
@@ -59,11 +61,14 @@
   </div>
 </template>
 <script>
-import tools from "@/utils/scan/tools";
+import tools from "@/utils/scan/tools"
+import handsonUtils from "@/utils/hasontableUtils"
+import showTools from "@/utils/handsontable/notShow"
+import text from "@/utils/handsontable/mainText"
 
 import cenoteType from "@/components/ledger/lib/cenoteType";
 import handsonTable from "@/components/common/handsontable";
-import { getCenoteType, getCenoteTableHeader, getCenoteTableData } from "@/api/scan/request"
+import { getCenoteType, getCenoteTableHeader, getCenoteTableData, updataCenoteTableData, deleteCenoteTableData, saveCenoteRelateSpace } from "@/api/scan/request"
 import { mapGetters, mapActions } from "vuex";
 export default {
   components: {
@@ -72,9 +77,11 @@ export default {
   },
   data() {
     return {
-      cenoteId: "",
+      cenoteId: "",//竖井类型id
+      shaftId: "",//要操作的竖井id
       cenoteTypeList: [],
-      relationids: "",
+      isTableRightShow: false,
+      spaceList: "",
       options: [{
         value: true,
         label: '只读模式'
@@ -92,13 +99,7 @@ export default {
         total: 0
       },
       tableData: [],
-      param: {
-        buildId: "",
-        floorId: "",
-        deviceId: "",
-        ProjId: "",
-        secret: ""
-      },
+      copyTableData: [],
       assetGroupList: [],
       graphyId: null
     };
@@ -111,20 +112,16 @@ export default {
     ])
   },
   created() {
-    this.param.ProjId = this.projectId
-    this.param.secret = this.secret
     this.getCenoteTypeData()
     this.getTableHeader()
-    // this.getProjName()
-  },
-  watch: {
-      projectId() {
-          this.param.ProjId = this.projectId;
-          // this.getProjName()
-      }
   },
+  // watch: {
+  //     projectId() {
+  //         this.param.ProjId = this.projectId;
+  //     }
+  // },
   methods: {
-    //获取竖井类型
+    // 获取竖井类型
     async getCenoteTypeData() {
       let param = {
         ProjId: this.projectId,
@@ -139,7 +136,7 @@ export default {
         })
       })
     },
-    //获取表头数据(初始化表格)
+    // 获取表头数据(初始化表格)
     async getTableHeader() {
       let param = {
         ProjId: this.projectId,
@@ -154,18 +151,10 @@ export default {
       })
     },
     async getTableData() {//获取表格数据
-      let data = {};
-      if(this.cenoteId){
-        data = {
-          Filters: `ID=${this.cenoteId}`,
-          PageNumber: this.page.pageNumber,
-          PageSize: this.page.pageSize
-        }
-      } else {
-        data = {
-          PageNumber: this.page.pageNumber,
-          PageSize: this.page.pageSize
-        }
+      let data = {
+        Filters: this.cenoteId? `ProjectId='${this.projectId}';ShaftFuncType='${this.cenoteId}'`: `ProjectId='${this.projectId}'`,
+        PageNumber: this.page.pageNumber,
+        PageSize: this.page.pageSize
       }
       const params = {
         ProjId: this.projectId,
@@ -174,6 +163,7 @@ export default {
       }
       await getCenoteTableData(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){
@@ -181,11 +171,111 @@ export default {
         }
       })
     },
+    // 修改表格内容
+    async updateTableData(data, change) {
+      let param = {
+        ProjId: this.projectId,
+        secret: this.secret,
+        data: {
+          Content: [],
+          Projection: data[0]? Object.keys(data[0]): []
+        }
+      };
+      //生成对应修改数据
+      data.map((item, index) => {
+        let key = change[index][1]
+        item[key] = item[key] != ""? item[key]: null
+        param.data.Content.push(item);
+      });
+
+      await updataCenoteTableData(param, (res) => {
+        
+      })
+    },
+    // 删除表格数据
+    async deleteTableData(params) {
+      await deleteCenoteTableData(params, (res) => {
+        this.$message.success("删除成功")
+        this.getTableHeader()
+      })
+    },
+    //保存元空间关联
+    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()
+      })
+    },
+    // 删除表格行
+    handleDeleteTableRow() {
+      let params = tools.differenceArr(this.tableData, this.copyTableData)
+      if (params.length < 1) {
+        return
+      }
+      let param = {
+        ProjId: this.projectId,
+        secret: this.secret,
+        data: []
+      }
+      params.map(item => {
+        param.data.push(item.ShaftID)
+      })
+      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].indexOf("/") > 0) {
+            changeData[0][1] = changeData[0][1].split("/").join(".")
+          }
+
+          // 存在data进行修改请求
+          if (data && data.length) {
+            this.updateTableData(data, changeData);
+          }
+        }
+      }
+    },
+    //撤回
+    undo() {
+      this.tableExample.undo();
+    },
     //切换竖井类型
     changeFloor(value) {
       this.cenoteId = value.ID
       this.getTableHeader()
     },
+    //关闭右侧关联元空间输入按钮
+    handleCloseRight() {
+      this.isTableRightShow = false
+      this.spaceList = ""
+    },
     //切换每页显示多少条数据
     handleSizeChange(val) {
       this.page.pageSize = val
@@ -198,41 +288,29 @@ export default {
     },
     formatHeaderData(list) {//格式化表头显示的数据
       let arr = tools.copyArr(list)
-      let data = arr.map((item) => {
-        if (item.Field == "SpaceCount" || item.Field == "SpaceList"){
-          return undefined
-        } else {
-          return item.Name
-        }
-      }).filter(d => d)
+      arr.map((item) => {
+        item.Visible = true
+      })
+      let readArr = ["A1", "A2", "B1", "C5", "D1", "D2", "E1", "F1", "F2", "L", "L1", "L2", "N2", "X"]
+      if (!this.onlyRead) {
+        readArr.push("Own")
+      }
+      let data = showTools.changeHeader(arr, readArr, this.onlyRead, false, this.allMess)
       data.unshift("关联的元空间");
       return data;
     },
     formatHeaderType(list) {//格式化表头头映射的数据
-      let arr = tools.copyArr(list)
-      let data = arr.map(item => {
-        if (item.Field == "SpaceCount" || item.Field == "SpaceList") {
-          return undefined
-        } else if(item.Field == "ShaftFuncType") {
-          return {
-            data: item.Field,
-            readOnly: this.onlyRead,
-            renderer: tools.customDropdownRenderer,
-            editor: "chosen",
-            chosenOptions: {
-                data: this.cenoteTypeList
-            }
-          }
-        } else {
-          return {
-            data: item.Field,
-            readOnly: this.onlyRead
-          }
+      let arr = tools.copyArr(list);
+      arr.map((item) => { //缺少信息点
+        item.Visible = true
+        if (item.InputMode == "E1") {
+          item.optionList = this.cenoteTypeList
         }
-      }).filter(d => d)
+      })
+      let data = showTools.showHeaderTypes(arr, this.onlyRead, false, this.allMess)
       data.unshift({
         data: "SpaceCount",
-        readOnly: true
+        readOnly: this.onlyRead
       })
       return data;
     },
@@ -251,9 +329,9 @@ export default {
           }
         },
         // 事件
-        afterChange: this.tdChange, //修改后
+        afterChange: this.handleUpdataTable, //修改后
         afterFilter: this.trimmedRows, //排序前
-        afterRemoveRow: this.romoveFm, //右键删除
+        afterRemoveRow: this.handleDeleteTableRow, //右键删除
         afterOnCellMouseDown: this.handleTdClick //鼠标点击
       };
       this.$nextTick(() => {
@@ -261,8 +339,78 @@ export default {
         this.tableExample = this.$refs.table.init(settings);
       });
     },
-    handleTdClick() {
-      
+    //获取到了正确的信息
+    getInfors(infos, row) {
+      //其他的开始判断
+      let val = this.tableExample.colToProp(row.col)
+      this.shaftId = infos.ShaftID //要操作的数据id
+      //点击关联的元空间
+      if (val === "SpaceCount") {
+        this.spaceList = infos.SpaceList
+        this.isTableRightShow = true
+      }
+    },
+    //表格点击事件
+    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 = hot.getPlugin('trimRows').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 || [];
+      // var DataArray = new Array();
+
+      // for (var i = 0; i < plugin.length; i++) {
+      //     // 通过行号获取数据
+      //     DataArray.push(this.tableExample.getSourceDataAtRow(plugin[i]));
+      // }
+    },
+    //去除数组中相同的元素
+    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;
     },
     // getProjName() {
     //   let param = {

+ 548 - 11
src/views/rent/rentlist/index.vue

@@ -1,18 +1,555 @@
 <template>
-    <div>
-        租户清单
+  <div id="deviceList">
+    <div class="search-header">
+      <floor-cascader @change="changeFloor"></floor-cascader>
+      <!-- <cenote-type @change="changeFloor"></cenote-type> -->
     </div>
+    <el-row class="right">
+      <span style="float:left;">当前筛选条件下共{{page.total || '--'}}租户</span>
+      <el-checkbox v-show="onlyRead" v-model="allMess" @change="getTableHeader">只看要采集的信息</el-checkbox>
+      <el-select v-model="onlyRead" @change="getTableHeader">
+        <el-option
+          v-for="item in options"
+          :key="item.value"
+          :label="item.label"
+          :value="item.value">
+        </el-option>
+      </el-select>
+      <el-button>添加租户</el-button>
+      <el-button @click="getTableHeader">刷新</el-button>
+      <el-button v-show="!onlyRead" @click="undo">撤销</el-button>
+    </el-row>
+    <div class="tableBox">
+      <div class="center middle_sty" style="flex:2;" v-show="tableData && !tableData.length">
+        <p>
+          <i class="iconwushuju iconfont"></i>
+          暂无数据
+        </p>
+      </div>
+      <div class="tableLeft" v-show="tableData && tableData.length">
+        <handson-table ref="table"></handson-table>
+      </div>
+      <div class="tableRight">
+        <div v-show="isTableRightShow">
+          <div class="table_right_box"><span class="iconfont close_right" @click="handleCloseRight">&#xe66b;</span></div>
+          <h5>管理租赁空间</h5>
+          <p style="margin-bottom: 10px;">以下为关联的元空间id</p>
+          <el-input
+            type="textarea"
+            :autosize="{ minRows: 6, maxRows: 10}"
+            :disabled="onlyRead"
+            placeholder="请输入元空间id,以“,”分割"
+            v-model="relationids">
+          </el-input>
+          <el-row class="right" v-show="!onlyRead">
+            <el-button>取消</el-button>
+            <el-button type="primary">保存</el-button>
+          </el-row>
+        </div>
+      </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>
+  </div>
 </template>
 <script>
-    export default {
-        data() {
-            return {}
+import tools from "@/utils/scan/tools"
+import handsonUtils from "@/utils/hasontableUtils"
+import showTools from "@/utils/handsontable/notShow"
+import text from "@/utils/handsontable/mainText"
+
+import floorCascader from "@/components/ledger/lib/floorCascader"
+import handsonTable from "@/components/common/handsontable"
+import { getCenoteType, getRentTableHeader, getRentTableData, updataRentTableData, deleteRentTableData } from "@/api/scan/request"
+import { mapGetters, mapActions } from "vuex";
+export default {
+  components: {
+    floorCascader,
+    handsonTable
+  },
+  data() {
+    return {
+      buildId: null,//建筑id
+      floorId: null,//楼层id
+      cenoteId: "",//租户类型id
+      shaftId: "",//要操作的租户id
+      cenoteTypeList: [],
+      isTableRightShow: false,
+      relationids: "",
+      options: [{
+        value: true,
+        label: '只读模式'
+      }, {
+        value: false,
+        label: '编辑模式'
+      }],
+      onlyRead: true,
+      allMess: true,
+      tableHeader: [],
+      page: {
+        pageSize: 20,
+        pageSizes: [10, 20, 50, 100],
+        pageNumber: 1,
+        total: 0
+      },
+      tableData: [],
+      copyTableData: [],
+      assetGroupList: [],
+      graphyId: null
+    };
+  },
+  computed: {
+    ...mapGetters("layout", [
+        "projectId",
+        "secret",
+        "userId"
+    ])
+  },
+  created() {
+    this.getCenoteTypeData()
+    this.getTableHeader()
+  },
+  // watch: {
+  //     projectId() {
+  //         this.param.ProjId = this.projectId;
+  //     }
+  // },
+  methods: {
+    // 获取租户类型
+    async getCenoteTypeData() {
+      let param = {
+        ProjId: this.projectId,
+        secret: this.secret,
+        data: {}
+      }
+      await getCenoteType (param, res => {
+        let data = res.Content
+        this.cenoteTypeList = data.map((item) => {
+          item.Code = item.ID
+          return item
+        })
+      })
+    },
+    // 获取表头数据(初始化表格)
+    async getTableHeader() {
+      let param = {
+        ProjId: this.projectId,
+        secret: this.secret,
+        data: {
+          "CollectFlag": this.allMess
+        }
+      }
+      await getRentTableHeader(param, res => {
+        this.tableHeader = res.Content;
+        this.getTableData()
+      })
+    },
+    async getTableData() {//获取表格数据
+      let Filters
+      if (this.buildId == "all") {
+        Filters = `ProjectId='${this.projectId}'`
+      } else if (this.buildId == "noKnow") {
+        Filters = `ProjectId='${this.projectId}';BuildingId isNull`
+      } else if (this.floorId == "noKnow") {
+        Filters = `ProjectId='${this.projectId}';BuildingId='${this.buildId}';FloorId isNull`
+      } else if (this.floorId && this.floorId != "all") {
+        Filters = `ProjectId='${this.projectId}';BuildingId='${this.buildId}';FloorId='${this.floorId}'`
+      } else if (this.floorId == 'all') {
+        Filters = `ProjectId='${this.projectId}';BuildingId='${this.buildId}'`
+      } else {
+        Filters = `ProjectId='${this.projectId}'`
+      }
+      let data = {
+        Filters: Filters,
+        PageNumber: this.page.pageNumber,
+        PageSize: this.page.pageSize
+      }
+      const params = {
+        ProjId: this.projectId,
+        secret: this.secret,
+        data: data
+      }
+      await getRentTableData(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 = {
+        ProjId: this.projectId,
+        secret: this.secret,
+        data: {
+          Content: [],
+          Projection: data[0]? Object.keys(data[0]): []
+        }
+      };
+      //生成对应修改数据
+      data.map((item, index) => {
+        let key = change[index][1]
+        item[key] = item[key] != ""? item[key]: null
+        param.data.Content.push(item);
+      });
+
+      await updataRentTableData(param, (res) => {
+        
+      })
+    },
+    // 删除表格数据
+    async deleteTableData(params) {
+      await deleteRentTableData(params, (res) => {
+        this.$message.success("删除成功")
+        this.getTableHeader()
+      })
+    },
+    // 删除表格行
+    handleDeleteTableRow() {
+      let params = tools.differenceArr(this.tableData, this.copyTableData)
+      if (params.length < 1) {
+        return
+      }
+      let param = {
+        ProjId: this.projectId,
+        secret: this.secret,
+        data: {
+          idList: []
+        }
+      }
+      params.map(item => {
+        param.data.idList.push(item.ShaftID)
+      })
+      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].indexOf("/") > 0) {
+            changeData[0][1] = changeData[0][1].split("/").join(".")
+          }
+
+          // 存在data进行修改请求
+          if (data && data.length) {
+            this.updateTableData(data, changeData);
+          }
+        }
+      }
+    },
+    //撤回
+    undo() {
+      this.tableExample.undo();
+    },
+    //切换租户类型
+    changeFloor(value) {
+      if (value[0]) {
+        this.buildId = value[0]
+      }
+      if (value[1]) {
+        this.floorId = value[1]
+      } else {
+        this.floorId = null
+      }
+      this.getTableHeader()
+    },
+    //关闭右侧关联元空间输入按钮
+    handleCloseRight() {
+      this.isTableRightShow = false
+    },
+    //切换每页显示多少条数据
+    handleSizeChange(val) {
+      this.page.pageSize = val
+      this.getTableHeader()
+    },
+    //切换页数
+    handleCurrentChange(val) {
+      this.page.pageNumber = val
+      this.getTableHeader()
+    },
+    formatHeaderData(list) {//格式化表头显示的数据
+      let arr = tools.copyArr(list)
+      arr.map((item) => {
+        item.Visible = true
+      })
+      let readArr = ["A1", "A2", "B1", "C5", "D1", "D2", "E1", "F1", "F2", "L", "L1", "L2", "N2", "X"]
+      if (!this.onlyRead) {
+        readArr.push("Own")
+      }
+      let data = showTools.changeHeader(arr, readArr, this.onlyRead, false, this.allMess)
+      data.unshift("关联的元空间");
+      return data;
+    },
+    formatHeaderType(list) {//格式化表头头映射的数据
+      let arr = tools.copyArr(list);
+      arr.map((item) => { //缺少信息点
+        item.Visible = true
+        if (item.InputMode == "E1") {
+          item.optionList = this.cenoteTypeList
+        }
+      })
+      let data = showTools.showHeaderTypes(arr, this.onlyRead, false, this.allMess)
+      data.unshift({
+        data: "SpaceCount",
+        readOnly: this.onlyRead
+      })
+      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: {
+          items: {
+            remove_row: {
+              name: "删除租户"
+            }
+          }
         },
-        created() {},
-        mounted() {},
-        methods: {}
-    }
-</script>
-<style>
+        // 事件
+        afterChange: this.handleUpdataTable, //修改后
+        afterFilter: this.trimmedRows, //排序前
+        afterRemoveRow: this.handleDeleteTableRow, //右键删除
+        afterOnCellMouseDown: this.handleTdClick //鼠标点击
+      };
+      this.$nextTick(() => {
+        console.log(this.$refs.table);
+        this.tableExample = this.$refs.table.init(settings);
+      });
+    },
+    //获取到了正确的信息
+    getInfors(infos, row) {
+      //其他的开始判断
+      let val = this.tableExample.colToProp(row.col);
+      this.row = row.row //要操作的列号
+      this.messKey = val //要操作的列类型
+      this.shaftId = infos.ShaftID //要操作的数据id
+      //点击关联的元空间
+      if (val === "SpaceCount") {
+        this.isTableRightShow = true;
+      }
+    },
+    //表格点击事件
+    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 = hot.getPlugin('trimRows').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 || [];
+      // var DataArray = new Array();
 
+      // for (var i = 0; i < plugin.length; i++) {
+      //     // 通过行号获取数据
+      //     DataArray.push(this.tableExample.getSourceDataAtRow(plugin[i]));
+      // }
+    },
+    //去除数组中相同的元素
+    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;
+    },
+    // getProjName() {
+    //   let param = {
+    //     list: [{ id: this.param.ProjId }],
+    //     perjectId: this.param.ProjId,
+    //     secret: this.param.secret,
+    //   }
+      // getSpaceName(param).then(res => {
+      //   if (res.data.Result == "success") {
+      //     this.mess.perjectName = res.data.Content[0].infos.ProjLocalName
+      //     this.getEqCode()
+      //   } else {
+      //     this.$message.error("请求失败:" + res.data.ResultMsg)
+      //   }
+      // }).catch(_ => {
+      //   this.$message.error("请求失败")
+      // })
+    // },
+    close(val) {
+      this.getEqCode()
+      console.log(val)
+      if(this.$refs.cascader)
+      this.$refs.cascader.changeVal([val.code])
+      //   this.$refs.tableMain.getHeaderData(this.param);
+    },
+    getEqCode() {
+      getEquipmentFamily(res => {
+        this.assetGroupList = res.Content
+        this.getGraphyId()
+      })
+    },
+    getFamilyList() {
+      let param = {
+        ProjId: this.param.ProjId,
+        secret: this.param.secret,
+        data: { type: "Eq" }
+      }
+      getFamilyList(param, res => {
+          if (this.$refs.cascader) {
+              this.$refs.cascader.pushData(res.Content)
+          }
+        
+      })
+    },
+    //获取header的list
+    // getNumber() {
+    //   let param = {
+    //     ProjId: this.param.ProjId,
+    //     secret: this.param.secret,
+    //     data: { type: "Eq" }
+    //   }
+    //   getNumber(param, res => {
+    //     console.log(res)
+    //     this.mess.name[0].num = res.content.count
+    //     this.mess.name[1].num = res.content.bindingCount
+    //     this.getFamilyList()
+    //   })
+    // },
+
+    getGraphyId() {
+      let param = {
+        ProjId: this.param.ProjId,
+        secret: this.param.secret,
+        type: "SystemEquip"
+      }
+      getGraphyId(param).then(res => {
+        if (res.data.Result == "success") {
+          this.graphyId = res.data.graph_id
+          if(this.$refs.tableMain)
+          this.$refs.tableMain.setGraphyId(this.graphyId, this.assetGroupList);
+          // this.getNumber()
+        } else {
+          this.$message.error("请求错误:" + res.data.ResultMsg)
+        }
+      }).catch(_ => {
+        this.$message.error("请求错误")
+      })
+    },
+
+    //修改设备族
+    changeDevice(value) {
+      this.param.deviceId = value.code
+      this.param.name = value.facility
+      if (!!value) {
+          if(this.$refs.tableMain)
+        this.$refs.tableMain.getHeaderData(this.param);
+      } else {
+        return;
+      }
+    },
+  }
+};
+</script>
+<style lang="less" scoped>
+#deviceList {
+  overflow: hidden;
+  height: 100%;
+  background-color: #f6f6f6;
+  position: relative;
+  .search-header {
+    overflow: hidden;
+    padding:0 10px 10px 10px;
+    border-bottom: 1px solid #bcbcbc;
+  }
+  .tableBox {
+    display: flex;
+    height: calc(100% - 140px);
+    margin-top: 10px;
+    .tableLeft {
+      flex: 2;
+      margin-right: 20px;
+    }
+    .tableRight {
+      flex: 1;
+      // display: none;
+      border-left: 1px solid #dadada;
+      padding: 5px 15px;
+      margin-right: 5px;
+      box-shadow: 0px 1px 5px 0px rgba(59, 66, 84, 0.15);
+      .table_right_box::after{
+        display: block;
+        content: "";
+        clear: both;
+      }
+      .close_right {
+        float: right;
+        cursor: pointer;
+      }
+    }
+  }
+}
 </style>