| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173 |
- <template>
- <div id="cascaderMap">
- <span class="buildFloor" style="padding-right: 12px;">设备族</span>
- <el-select v-model="value" placeholder="请选择" clearable :props="props" filterable
- :style="isWidth ? '' : 'width:160px;'" size="small" @change="changeVal">
- <el-option v-for="item in options" :key="item.code" :label="item.facility" :value="item.code"></el-option>
- </el-select>
- <!-- <el-cascader
- placeholder="请选择"
- :options="options"
- v-model="value"
- :props="props"
- filterable
- :style="isWidth ? '' : 'width:160px;'"
- size="small"
- @change="changeVal"
- change-on-select
- ></el-cascader> -->
- </div>
- </template>
- <script>
- import { mapGetters } from 'vuex';
- import { getEquipBelongs, queryProperty } from "@/api/scan/request";
- export default {
- name: "getCode",
- props: {
- isWidth: {
- type: Boolean,
- default: true
- },
- all: {
- type: Boolean,
- default: false,
- }
- },
- computed: {
- ...mapGetters("layout", [
- "projectId",
- ])
- },
- data() {
- return {
- value: [],
- options: [],
- props: {
- value: "code",
- label: "facility"
- },
- falg: true,
- content: []
- };
- },
- created() {
- this.getData();
- },
- watch: {
- projectId() {
- this.value = ['']
- }
- },
- methods: {
- setValue(val) {
- this.value = val
- },
- //修改val
- changeVal(val) {
- let value = {}
- this.options.map(item => {
- if (item.code == val) {
- value = item
- }
- })
- this.value = val
- this.$emit("change", value)
- },
- getData() {
- let _this = this
- let param1 = {
- data: {
- distinct: true,
- pageNumber: 1,
- pageSize: 500,
- projection: ["family", "familyName"]
- }
- }, param2 = {
- distinct: true,
- pageNumber: 1,
- pageSize: 500,
- projection: [
- "family"
- ]
- }
- let promise1 = new Promise((resolve, reject) => {
- getEquipBelongs(param1, res => {
- resolve(res)
- })
- })
- let promise2 = new Promise((resolve, reject) => {
- queryProperty(param2, res => {
- resolve(res)
- })
- })
- Promise.all([promise1, promise2]).then((res) => {
- let allData = res[0], data = res[1]
- _this.options = _this.changeArr(allData.content)
- if (_this.value) {
- _this.changeVal(this.value)
- }
- if (!_this.all) {
- _this.content = data.content.map(item => {
- return item.family
- });
- _this.changeList();
- if (_this.value) {
- _this.changeVal(this.value)
- }
- }
- })
- // getEquipBelongs(params, res => {
- // this.options = this.changeArr(res.Content)
- // if (!!this.value && this.value.length) {
- // let value = {}
- // this.options.map(item => {
- // if (item.code == this.value[0]) {
- // value = item
- // }
- // })
- // this.$emit("change", value)
- // }
- // if (!this.falg) {
- // this.changeList()
- // }
- // })
- console.log(this.options,'=========================')
- },
- changeArr(arr) {
- let data = [];
- arr.map(item => {
- data.push({ code: item.family, facility: item.familyName, disabled: false })
- });
- return data;
- },
- pushData(content) {
- this.content = content
- if (this.options.length) {
- this.falg = true
- this.changeList()
- } else {
- this.falg = false
- }
- },
- changeList() {
- this.options = this.options.filter(item => {
- if (this.content.indexOf(item.code) > -1) {
- return item
- }
- })
- }
- }
- };
- </script>
- <style lang="less" scoped>
- #cascaderMap {
- float: left;
- margin-left: 10px;
- .buildFloor {
- color: #999999;
- font-size: 14px;
- }
- }
- </style>
|