zmc
2023-08-08 dbfdc1166172e3cdc45b7093376cef83bea75fb9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<!-- 获取店铺名 设备编号的级联下拉框组件  
    将选择的设备编号返回给父组件
 -->
<script>
import axiosInstanceInstance from '../utils/request.js'
export default {
  // 默认选择一个
  // props:{
  //   devId:{
  //     type: Array,
  //     default: ['全部','全部'],
  //   }
     
  // }
  props:['devId'],
  emits: ['submitId'],
  data() {
    return {
      // 选择店铺名
      deviceId: [],
      // 店铺名 级联选择器
      optionsShop: [],
      // 保存设备信息表所有信息
      deviceInfo: []
    };
  },
  watch:{
    // 保证页面切换回来时,店铺组件还是保持默认选中的一家
    devId(){
      this.deviceId = this.devId
    }
  },
  mounted(){
    this.getDeviceInfo()
  },
  methods: {
    getDeviceInfo() {
      // 级联下拉框数据 从接口中动态获取
        axiosInstanceInstance.get('/fume/device').then((result) => {
          this.deviceInfo = result.data.data;
          this.deviceInfo.forEach((item) => {
            this.optionsShop[this.optionsShop.length] = {
              value: item.diName,
              label: item.diName,
              children: [
                {
                  value: item.diCode,
                  label: item.diCode
                }
              ]
            };
          });
          console.log(this.optionsShop);
        });
        
        // 打开时默认展示一个店铺
      this.deviceId = this.devId
    }
  }
};
</script>
 
<template>
  <div>
    <span>
      <el-cascader
        v-model="deviceId"
        :options="optionsShop"
        :props="{ expandTrigger: 'hover' }"
      
        @change="$emit('submitId', deviceId[1])"
        placeholder="全部"
      />
      <!--   @visible-change="getDeviceInfo" -->
    </span>
  </div>
</template>