123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590 |
- <template>
- <div id="deviceList">
- <!-- <div class="search-header">
- <floor-cascader @change="changeFloor"></floor-cascader>
- </div> -->
- <el-row class="left">
- <span style="float:right;">当前筛选条件下共{{page.total || '--'}}租户</span>
- <el-select v-model="onlyRead" @change="getTableHeader" style="width:100px;margin-right:10px;vertical-align:bottom;">
- <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
- </el-option>
- </el-select>
- <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>
- <!-- <div v-show="onlyRead" style="width:200px;display:inline-block;text-align:left;color:gray;font-size:12px;">
- <span>只看要采集的信息</span>
- <el-checkbox v-model="allMess" @change="getTableHeader"></el-checkbox>
- </div> -->
- <el-button @click="handleCreateTableData">添加租户</el-button>
- <el-button @click="getTableHeader">刷新</el-button>
- <el-button @click="mangeTenantZone">管理租赁空间</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">
- <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>
- <!-- 不支持的输入方式 -->
- <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>
- <!-- 右侧关联的业务空间抽屉 -->
- <roomCountDrawer ref="roomCountDrawer" :readonly="onlyRead" @refresh="getTableData"></roomCountDrawer>
- </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 roomCountDrawer from "@/components/ledger/rentList/roomCountDrawer"
- import floorCascader from "@/components/ledger/lib/floorCascader"
- import handsonTable from "@/components/common/handsontable"
- import { getDataDictionary, getRentTableHeader, queryRentTableData, updataRentTableData, deleteRentTableData, saveRentRelateSpace, BeatchQueryParam } from "@/api/scan/request"
- import { mapGetters, mapActions } from "vuex";
- export default {
- components: {
- floorCascader,
- handsonTable,
- roomCountDrawer
- },
- data() {
- return {
- buildId: null,//建筑id
- floorId: null,//楼层id
- tenantID: "",//要操作的租户id
- isTableRightShow: false,
- roomId: "",//关联的空间id
- options: [{
- value: true,
- label: '只读模式'
- }, {
- value: false,
- label: '编辑模式'
- }],
- onlyRead: true,
- showType: "",
- // allMess: true,
- tableHeader: [],
- page: {
- pageSize: 50,
- pageSizes: [10, 20, 50, 100],
- pageNumber: 1,
- total: 0
- },
- tableData: [],
- copyTableData: [],
- myDialog: {
- update: false,//临时维护信息点
- },
- inputMap: {
- FloorId: 'B1'
- }, //信息点和输入方式映射表
- updateInputShow: false, //是否显示临时维护输入框
- updateInfoPoint: '',//临时维护信息点
- updateInput: '', //临时维护信息点值
- };
- },
- computed: {
- ...mapGetters("layout", ["projectId", "secret", "userId"]),
- showTypes() {
- return this.onlyRead ?
- [{ value: "Visible", label: '只看采集信息' }, { value: "all", label: '全部' }] :
- [{ value: "partInfo", label: '隐藏信息点' }, { value: "all", label: '全部' }, { value: "Visible", label: '只看采集信息' }]
- }
- },
- created() {
- this.getTableHeader()
- },
- watch: {
- projectId() {
- this.getTableHeader()
- },
- showTypes: {
- handler(newName, oldName) {
- if (newName && newName[0] && newName[0].value) {
- this.showType = newName[0].value
- } else {
- this.showType = ""
- }
- },
- immediate: true,
- deep: true
- }
- },
- methods: {
- // 获取表头数据(初始化表格)
- async getTableHeader() {
- let param = {
- data: {
- Orders: "sort asc",
- PageNumber: 1,
- PageSize: 500
- },
- type: 'Tenant'
- }
- await getDataDictionary(param, res => {
- this.tableHeader = res.Content;
- this.tableHeader.forEach(item => {
- if (item.Path && item.InputMode) {
- this.inputMap[item.Path] = item.InputMode
- }
- })
- this.getTableData()
- })
- },
- async getTableData() {//获取表格数据
- let params = {
- Cascade: [
- { Name: 'zoneTenantList', Cascade: [{ Name: 'building' }, { Name: 'floor' }] },
- { Name: 'zoneGeneraltList', Cascade: [{ Name: 'building' }, { Name: 'floor' }] }
- ],
- Orders: "createTime desc, TenantID asc",
- PageNumber: this.page.pageNumber,
- PageSize: this.page.pageSize
- }
- await queryRentTableData(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) {
- if (this.onlyRead) {
- this.getBatch(res.Content)
- }
- this.initTable()
- }
- })
- },
- // 修改表格内容
- async updateTableData(data, change) {
- let param = {
- 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.Projection.indexOf(key) == -1) {
- param.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.Content.push(item);
- });
- await updataRentTableData(param, (res) => {
- })
- },
- //保存元空间关联
- async saveSpaceList() {
- let params = {
- Tenant: this.tenantID,
- RoomID: this.roomId
- }
- await saveRentRelateSpace(params, (res) => {
- this.$message.success("关联成功!")
- this.getTableHeader()
- })
- },
- // 删除表格数据
- async deleteTableData(params) {
- await deleteRentTableData(params, (res) => {
- this.$message.success("删除成功")
- this.getTableHeader()
- })
- },
- // 添加租户数据
- handleCreateTableData() {
- this.$router.push({ name: 'rentadd' })
- },
- // 删除表格行
- handleDeleteTableRow() {
- let params = tools.differenceArr(this.tableData, this.copyTableData)
- if (params.length < 1) {
- return
- }
- let param = []
- params.map(item => {
- param.push({ TenantID: item.TenantID })
- })
- 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)
- let data = showTools.headerTextFilter(arr, "tenant", this.onlyRead, this.showType)
- data.unshift("操作", "所属楼层", "租赁空间");
- return data;
- },
- formatHeaderType(list) {//格式化表头头映射的数据
- let arr = tools.copyArr(list);
- let data = showTools.headerTypeFilter(arr, "tenant", this.onlyRead, this.showType)
- data.unshift({
- data: "caozuo",
- renderer: tools.lookDetails,
- readOnly: true
- }, {
- data: "FloorId",
- readOnly: true
- }, {
- data: "RoomCount",
- renderer: (instance, td, row, col, prop, value, cellProperties) => {
- td.style.color = "#409EFF";
- td.style.cursor = "pointer";
- let num = 0;
- let a = instance.getDataAtRowProp(row, 'ZoneGeneraltList')
- let b = instance.getDataAtRowProp(row, 'ZoneTenantList')
- if (a && a.length) {
- num += a.length
- }
- if (b && b.length) {
- num += b.length
- }
- td.innerHTML = num;
- return td;
- },
- 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, //修改后
- 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)
- let inputMode = this.inputMap[val]
- this.row = row.row //要操作的列号
- this.messKey = val //要操作的列类型
- this.tenantID = infos.TenantID //要操作的数据id
- //点击操作跳转详情
- if (val === "caozuo") {
- this.$message("开发中!")
- // window.open(`${process.env.BASE_URL}:8889/#/details?perjectId=${this.projectId}&secret=${this.secret}&FmId=${this.tenantID}&type=0&code=VOTn`,"_blank")
- return false
- }
- //点击关联的元空间
- if (val === "RoomCount") {
- // if (infos && infos.RoomID) {
- // this.roomId = infos.RoomID
- // } else {
- // this.roomId = ""
- // }
- // this.isTableRightShow = true;
- this.$refs.roomCountDrawer.showDrawer(infos)
- return false
- }
- if (!this.onlyRead && showTools.InputModeArr.indexOf(inputMode) == '-1') {
- this.updateInfoPoint = val
- this.updateInput = tools.dataForKey(this.tableData[row.row], val)
- this.myDialog.update = true
- }
- },
- //关闭临时维护弹窗回调
- handleCloseUpdate() {
- this.updateInputShow = false
- this.updateInfoPoint = ''
- this.updateInput = ''
- },
- //更新临时维护信息点
- handleClickUpdate() {
- 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 = ''
- },
- //表格点击事件
- 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;
- },
- //获取动态参数
- getBatch(data) {
- let param = {
- secret: this.secret,
- ProjId: this.projectId,
- data: {
- criterias: []
- }
- };
- this.tableHeader.map(head => {
- if (
- head.InputMode == "L" ||
- head.InputMode == "L1" ||
- head.InputMode == "L2" ||
- head.InputMode == "M"
- ) {
- data.map(item => {
- let cur = tools.dataForKey(item, head.Path);
- if (cur) {
- param.data.criterias.push({
- id: item.TenantID,
- code: head.InfoPointCode
- });
- }
- });
- }
- });
- if (param.data.criterias.length) {
- BeatchQueryParam(param, res => {
- this.tableData = data.map(item => {
- res.Content.map(child => {
- if (item.TenantID == child.id) {
- if (child.data || child.data == 0) {
- this.tableHeader.map(head => {
- if (head.InfoPointCode == child.code) {
- tools.setDataForKey(item, head.Path, child.data);
- }
- });
- } else {
- this.tableHeader.map(head => {
- if (head.InfoPointCode == child.code) {
- tools.setDataForKey(
- item,
- head.Path,
- // child.error ? "表号功能号格式错误" : "表号功能号不存在"
- child.error ? child.value ? "表号功能号格式错误" : "表号功能号不存在" : "暂未采集到实时数据"
- );
- }
- });
- }
- }
- });
- return item;
- });
- this.tableExample.loadData(this.tableData);
- });
- }
- },
- // 跳转至管理租赁空间
- mangeTenantZone() {
- this.$router.push({ name: 'manageTenantZone', query: { onlyRead: this.onlyRead } })
- }
- }
- };
- </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% - 95px);
- 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;
- }
- }
- }
- }
- .el-pagination button,
- .el-pagination span:not([class*="suffix"]) {
- vertical-align: middle;
- }
- </style>
|