feiyu02
2025-09-17 b330e57051e54789eb83d10dc58c4d9d10c608e1
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<template>
  <el-card shadow="hover">
    <div>新设备</div>
    <div v-if="device">{{ device.name }}</div>
    <div v-else>未选择</div>
    <el-divider></el-divider>
    <div>监管场景</div>
    <div v-if="scene">{{ scene.name }}</div>
    <div v-else>未选择</div>
    <template #footer>
      <el-row justify="space-between">
        <div>
          <!-- <el-button type="primary" plain :disabled="!enabled">名称同步</el-button> -->
          <el-button type="primary" plain :disabled="!enabled" @click="setNewDevice"
            >录入设备信息</el-button
          >
        </div>
        <el-button type="danger" :disabled="!enabled" @click="uploadMatchScene"
          >上传匹配信息</el-button
        >
      </el-row>
      <div v-if="newDevice">
        <el-text>新增设备</el-text>
        <FormDevice :form-info="newDevice" :is-edit="true"></FormDevice>
      </div>
      <div v-if="deviceList.length > 0">
        <el-text>已有设备</el-text>
        <FormDevice v-for="item in deviceList" :key="item.diId" :form-info="item"></FormDevice>
      </div>
    </template>
  </el-card>
</template>
<script setup>
import { ref, computed, watch } from 'vue';
import deviceApi from '@/api/fysp/deviceApi';
import constructionApi from '@/api/additional-jingan/constructionApi';
import { useFetchData } from '@/composables/fetchData';
import { ElMessage } from 'element-plus';
 
import FormDevice from './FormDevice.vue';
 
const props = defineProps({
  device: Object,
  scene: Object
});
 
const emit = defineEmits(['success']);
 
// 新增设备信息
const newDevice = ref();
// 场景已有设备信息
const deviceList = ref([]);
 
const enabled = computed(() => {
  return props.device && props.scene;
});
 
watch(
  () => props.scene,
  (nV, oV) => {
    if (nV != oV) {
      // fetchDeviceInfo();
    }
  }
);
 
function fetchDeviceInfo() {
  deviceApi.fetchDevice(props.scene.guid).then((res) => {
    deviceList.value = res.data;
  });
}
 
function setNewDevice() {
  newDevice.value = {
    diName: props.device.name,
    diMnCode: props.device.code,
    diType: 1,
    diSupplier: null,
    diMaintainer: null,
    diRunningStatus: true,
    diRemoved: false
  };
}
 
const { loading, fetchData } = useFetchData();
/**
 * 上传设备关联工地
 */
function uploadMatchScene() {
  const param = {
    name: props.scene.name,
    address: props.scene.location,
    street: props.scene.townname,
    lon: props.scene.longitude,
    lat: props.scene.latitude,
    sbCode: props.device.code,
    sbName: props.device.name
  };
  
  fetchData(() => {
    return constructionApi.uploadConstructionDevice(param).then((res) => {
      ElMessage({
        message: res.message,
        type: 'success'
      });
      emit('success');
    });
  });
}
</script>