| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271 |
- <template>
- <ele-modal
- :title="title"
- :visible.sync="visible"
- :before-close="handleClose"
- :close-on-click-modal="false"
- :close-on-press-escape="false"
- append-to-body
- width="70%"
- :maxable="true"
- >
- <el-card shadow="never">
- <ele-split-layout
- width="266px"
- allow-collapse
- :right-style="{ overflow: 'hidden' }"
- >
- <div>
- <div class="ele-border-lighter sys-organization-list">
- <el-tree
- :data="treeList"
- :props="{
- children: 'children',
- value: 'id',
- label: 'name'
- }"
- node-key="id"
- ref="tree"
- :highlight-current="true"
- :expand-on-click-node="false"
- @node-click="handleNodeClick"
- v-bind="$attrs"
- :default-expand-all="true"
- >
- </el-tree>
- </div>
- </div>
- <template v-slot:content>
- <ele-pro-table
- max-height="500px"
- ref="table"
- :columns="columns"
- :datasource="physicalList"
- @selection-change="handleSelectionChange"
- row-key="id"
- :initLoad="false"
- :needPage="false"
- >
- </ele-pro-table>
- </template>
- </ele-split-layout>
- </el-card>
- <div class="rx-sc">
- <el-button type="primary" size="small" @click="selected">选择</el-button>
- <el-button size="small" @click="handleClose">关闭</el-button>
- </div>
- </ele-modal>
- </template>
- <script>
- import {
- queryBindSubstanceList,
- getPhysicalModel,
- getDetailInfo
- } from '@/api/material/list';
- import { getAssetInfo } from '@/api/ledgerAssets/index.js';
- export default {
- components: {},
- props: {
- // 是否多选
- multiple: {
- type: Boolean,
- default: false
- }
- },
- computed: {
- seekList() {
- return [
- {
- label: '名称',
- value: 'name',
- type: 'input',
- placeholder: '请输入'
- }
- ];
- },
- // 表格列配置
- columns() {
- const list = [
- {
- columnKey: 'selection',
- type: 'selection',
- width: 45,
- align: 'center',
- reserveSelection: true,
- fixed: 'left'
- },
- {
- columnKey: 'index',
- type: 'index',
- label: '序号',
- width: 55,
- align: 'center',
- showOverflowTooltip: true,
- fixed: 'left'
- },
- {
- prop: 'name',
- label: '名称',
- showOverflowTooltip: true
- },
- {
- prop: 'identifier',
- label: '点位',
- showOverflowTooltip: true,
- minWidth: 180
- },
- {
- prop: 'dataType.specs.max',
- label: '最大值',
- showOverflowTooltip: true,
- minWidth: 180
- },
- {
- prop: 'dataType.specs.min',
- label: '最小值',
- showOverflowTooltip: true,
- minWidth: 180
- },
- {
- prop: 'dataType.specs.unitName',
- label: '单位',
- showOverflowTooltip: true,
- minWidth: 180
- }
- ];
- return list;
- }
- },
- data() {
- return {
- visible: false,
- title: '选择',
- type: null,
- // 表格选中数据
- selection: [],
- physicalList: [],
- cachingData: {},
- treeList: [],
- current: null
- };
- },
- watch: {},
- methods: {
- /* 表格数据源 */
- async queryBindSubstanceList(id) {
- let data = await queryBindSubstanceList({
- id,
- pageNum: 1,
- size: 1000
- });
- this.treeList[0].children = data.list;
- },
- getPhysicalModel(id) {
- getPhysicalModel(id).then((res) => {
- this.physicalList = [];
- if (res.code == 0) {
- this.physicalList = res.data.properties;
- if (this.cachingData[id]) {
- this.$refs.table.setSelectedRows(this.cachingData[id].list);
- }
- }
- });
- },
- handleNodeClick(data) {
- // if (data.id == this.treeList[0].id) {
- // this.physicalList = [];
- // return;
- // }
- this.current = data;
- this.$refs.table.clearSelection();
- this.getPhysicalModel(data.id);
- },
- async open(id) {
- const data = await getAssetInfo(id);
- console.log(data);
- this.visible = true;
- if (id) {
- this.treeList.push({
- ...data,
- children: []
- });
- this.$nextTick(() => {
- this.queryBindSubstanceList(id);
- });
- }
- },
- handleSelectionChange(data) {
- this.cachingData[this.current.id] = {
- substanceCode: this.current.code,
- substanceId: this.current.id,
- substanceName: this.current.name,
- iotId: this.current.iotId,
- list: data
- };
- },
- handleClose() {
- this.physicalList = [];
- this.cachingData = [];
- this.treeList = [];
- this.visible = false;
- },
- selected() {
- let cachingData = [];
- let list = [];
- for (let key in this.cachingData) {
- cachingData.push(this.cachingData[key]);
- }
- if (!cachingData.length) {
- this.$message.warning('请选择设备点位!');
- return;
- }
- cachingData.forEach((item) => {
- item.list.forEach((listItem) => {
- list.push({
- substanceCode: item.substanceCode,
- substanceId: item.substanceId,
- substanceName: item.substanceName,
- iotId: item.iotId,
- paramCode: listItem.identifier,
- paramValue: listItem.name,
- maxValue: listItem.dataType?.specs.max,
- minValue: listItem.dataType?.specs.min,
- unitName: listItem.dataType?.specs.unitName
- });
- });
- });
- this.$emit('bindSubstanceSuccess', list);
- this.handleClose();
- }
- }
- };
- </script>
- <style lang="scss" scoped>
- .rx-sc {
- display: flex;
- align-items: center;
- justify-content: center;
- }
- .ml60 {
- margin-left: 60px;
- }
- :deep(.radio) {
- .el-radio__label {
- padding: 0;
- }
- }
- </style>
|