123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567 |
- <template>
- <div id="partsList">
- <el-row>
- <el-tabs @tab-click="getTableHeader" v-model="tabVal">
- <el-tab-pane
- v-for="t in partsTypeList"
- :key="t.category"
- :name="t.category"
- :label="`${t.categoryName}(${t.count ? t.count : 0})`"
- ></el-tab-pane>
- </el-tabs>
- </el-row>
- <el-row class="left">
- <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: 140px; 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="getTableHeader">刷新</el-button>
- </el-row>
- <div class="tableBox">
- <div
- class="center middle_sty"
- v-show="tableData && !tableData.length"
- style="flex: 2"
- >
- <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>
- <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>
- <pic-dialog
- :read="onlyRead ? true : false"
- :dialog="myDialog"
- :keysArr="picsArr"
- @change="changePics"
- ></pic-dialog>
- </div>
- </template>
- <script>
- import tools from "@/utils/old-adm/scan/tools";
- import showTools from "@/utils/handsontable/notShow";
- import qrcode from "@/components/old-adm/ledger/lib/qrcode";
- import uploadFilesDialog from "@/components/old-adm/dialogs/list/filesDialog";
- import uploadImgDialog from "@/components/old-adm/dialogs/list/uploadImgDialog";
- import picDialog from "@/components/old-adm/dialogs/list/picDialog";
- import systemType from "@/components/old-adm/dialogs/list/systemType";
- import handsonTable from "@/components/old-adm/common/handsontable";
- import {
- BeatchQueryParam,
- deleteParts,
- getEquipPartsCon,
- getEquipPartsType,
- } from "@/api/scan/request";
- import { getDataDictionary } from "@/api/dict";
- import { mapGetters } from "vuex";
- export default {
- components: {
- qrcode, //二维码页面
- uploadFilesDialog,
- uploadImgDialog,
- picDialog,
- systemType,
- handsonTable,
- },
- data() {
- return {
- deviceId: "", //设备id
- isTableRightShow: false,
- spaceList: "",
- onlyRead: true,
- tableHeader: [],
- page: {
- pageSize: 50,
- pageSizes: [10, 20, 50, 100],
- pageNumber: 1,
- total: 0,
- },
- showTypes: [
- { value: "Visible", label: "只看需交付的" },
- { value: "all", label: "全部" },
- ],
- showType: "Visible",
- tableData: [],
- copyTableData: [],
- tableExample: null,
- tabVal: "",
- partsTypeList: [], //tabs
- myDialog: {
- qrcode: false, //二维码弹窗
- uploadFiles: false, //上传文件
- uploadImgs: false, //上传单个图片
- pic: false, //多个图片
- addDevice: false,
- systemType: false,
- details: false, //详情页
- changeRea: false,
- lookPic: false, //图片查看
- },
- inputMap: {},
- qrcodeUrl: "", //二维码图片地址
- filesArr: [], //保存临时的文件key
- imgsArr: [], //临时保存的图片key数组
- picsArr: [], //临时设备图片keys数组
- systemId: null,
- graphyId: null,
- mess: {},
- id: 0,
- EquipmentList: [],
- firmId: "", //品牌型号所需字段
- queryParam: {}, //返回到指定位置
- };
- },
- computed: {
- ...mapGetters("layout", ["projectId", "secret", "userId", "group_code"]),
- },
- created() {
- this.queryParam = this.$route.query;
- this.deviceId = this.$route.query.deviceId;
- this.getTypes();
- },
- methods: {
- //获取当前设备下的部件类
- async getTypes() {
- let params = {
- filters: `id='${this.deviceId}'`,
- pageNumber: 1,
- pageSize: 50,
- };
- await getEquipPartsType(params, (res) => {
- this.partsTypeList = res.content;
- if (this.partsTypeList.length) {
- this.tabVal = this.partsTypeList[0].category;
- this.getTableHeader();
- }
- });
- },
- // 获取表头数据(初始化表格)
- async getTableHeader() {
- let params = {
- orders: "sort asc, name desc",
- pageNumber: 1,
- pageSize: 1000,
- type: this.tabVal,
- };
- await getDataDictionary(params, (res) => {
- this.tableHeader = res.content;
- this.codeToDataSource = {};
- this.tableHeader.forEach((item) => {
- if (item.path) {
- this.inputMap[item.path] = item;
- }
- if (item.dataSource) {
- try {
- this.codeToDataSource[item.code] = {};
- item.dataSource.forEach((dic) => {
- this.codeToDataSource[item.code][dic.code] = dic.name;
- });
- } catch (e) {
- console.log(e);
- }
- }
- });
- this.getTableData();
- });
- },
- //获取表格数据
- async getTableData() {
- let params = {
- pageNumber: this.page.pageNumber,
- pageSize: this.page.PageSize,
- orders: "createTime desc, localName desc, localId desc, id desc",
- filters: `classCode='${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.getBatch(res.content);
- this.initTable();
- }
- });
- },
- //切换每页显示多少条数据
- 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("查看详情", "当前关联的资产");
- 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,
- fillHandle: "vertical", //允许纵向填充
- maxRows: this.tableData.length,
- contextMenu: this.onlyRead
- ? false
- : {
- items: {
- remove_row: {
- name: "删除部件",
- },
- },
- },
- // 事件
- afterRemoveRow: this.handleDeleteTableRow, //右键删除
- afterOnCellMouseDown: this.handleTdClick, //鼠标点击
- };
- this.$nextTick(() => {
- this.tableExample = this.$refs.table.init(settings);
- });
- },
- //表格点击事件
- 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) {
- //其他的开始判断
- let val = this.tableExample.colToProp(row.col);
- if (val == "caozuo") {
- // window.open(`http://adm.sagacloud.cn:8058/spread?id=${infos.EquipID}&pid=${this.projectId}&secret=${this.secret}`,"_blank")
- this.$message("开发中...");
- }
- //设备二维码图片
- if (val == "defaultQRCode") {
- this.qrcodeUrl = this.tableData[row.row].defaultQRCode;
- if (!!this.qrcodeUrl) {
- this.myDialog.qrcode = true;
- } else {
- this.$message("此设备没有设备二维码");
- }
- }
- //关联系统
- if (val == "linkSystem") {
- // this.systemList = this.tableData[row.row].linkSystem || [];
- this.myDialog.systemType = true;
- }
- //保险文件--设备文档--安装质检报告
- if (
- val == "infos.insuranceFile" || //保险文件
- val == "infos.archive" || //设备文档
- val == "infos.checkReport" || //安装质检报告
- val == "infos.maintainManual" || //维修保养手册
- val == "infos.approachingAcceptance" || //进场验收单
- val == "infos.acceptanceReport" || //验收报告
- val == "infos.operationManual" || //操作说明书
- val == "infos.originalCertificate" || //原厂证明
- val == "infos.testReport" || //检测报告
- val == "infos.productCertification" || //产品合格证
- val == "infos.installInstruction" || //
- val == "infos.supplierContract" || //供应合同
- val == "infos.drawing" || //设备图纸
- val == "infos.installDrawing" //安装图纸
- ) {
- let data = tools.dataForKey(this.tableData[row.row], val);
- this.filesArr = data ? data : [];
- this.myDialog.uploadFiles = true;
- }
- //安装照片--设备铭牌照片
- if (val == "infos.installPic" || val == "infos.nameplate") {
- let data = tools.dataForKey(this.tableData[row.row], val);
- this.imgsArr = data ? data : [];
- this.myDialog.uploadImgs = true;
- }
- //设备照片
- if (val == "infos.pic") {
- let data = tools.dataForKey(this.tableData[row.row], val);
- this.picsArr = data ? data : [];
- this.myDialog.pic = true;
- }
- this.row = row.row;
- this.messKey = val;
- },
- //去除数组中相同的元素
- 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;
- },
- // 删除表格行
- 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("取消删除");
- });
- },
- // 删除表格数据
- async deleteTableData(params) {
- await deleteParts(params, (res) => {
- this.$message.success("删除成功!");
- this.getTypes();
- });
- },
- //上传文件弹窗触发事件
- 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);
- },
- //获取动态参数
- getBatch(data) {
- let param = {
- groupCode: this.group_code,
- appId: "datacenter",
- projectId: this.projectId,
- data: [],
- };
- this.tableHeader.map((head) => {
- if (head.category != "STATIC") {
- data.map((item) => {
- let cur = tools.dataForKey(item, head.path);
- if (cur) {
- param.data.push({
- objectId: item.id,
- infoCode: head.code,
- });
- }
- });
- }
- });
- if (param.data.length) {
- BeatchQueryParam(param, (res) => {
- this.tableData = data.map((item) => {
- res.data.map((child) => {
- if (item.id == child.objectId) {
- if (child.data || child.data == 0) {
- this.tableHeader.map((head) => {
- if (head.code == child.infoCode) {
- let contentVal = child.data;
- if (this.codeToDataSource[child.infoCode]) {
- contentVal =
- this.codeToDataSource[child.infoCode][child.data];
- }
- tools.setDataForKey(item, head.path, contentVal);
- }
- });
- } else {
- this.tableHeader.map((head) => {
- if (head.code == child.infoCode) {
- tools.setDataForKey(
- item,
- head.path,
- child.error
- // child.error ? child.value ? "表号功能号格式错误" : "表号功能号不存在" : "暂未采集到实时数据"
- );
- }
- });
- }
- }
- });
- return item;
- });
- this.tableExample.loadData(this.tableData);
- });
- }
- },
- // 返回
- goback() {
- this.$router.push({ path: "/ledger/facility" });
- },
- },
- };
- </script>
- <style lang="less" scoped>
- #partsList {
- 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 {
- flex: 1;
- }
- }
- }
- .el-pagination button,
- .el-pagination span:not([class*="suffix"]) {
- vertical-align: middle;
- }
- </style>
|