1
lxl
2022-09-16 2d9ddf8269640309f22053d3c92a38fd77e84358
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
<template>
  <div class="list">
    <div class="header_box">
      <span>模型属性绑定</span>
    </div>
    <div class="content">
      <div class="search">
        <el-form :inline="true" :model="formInline" class="demo-form-inline">
          <div class="form_box1">
            <el-form-item label="模型ID">
              <!-- <span>{{ formInline.modelId }}</span> -->
              <el-input disabled v-model="formInline.modelId"></el-input>
            </el-form-item>
            <el-form-item label="模型经度">
              <!-- <span>{{ formInline.lng }}</span> -->
              <el-input disabled v-model="formInline.lng"> </el-input>
            </el-form-item>
            <el-form-item label="模型纬度">
              <!-- <span>{{ formInline.lat }}</span> -->
              <el-input disabled v-model="formInline.lat"></el-input>
            </el-form-item>
            <el-form-item>
              <el-button
                type="primary"
                v-show="showtableList"
                plain
                @click="selectModel"
                >选择模型</el-button
              >
            </el-form-item>
            <el-form-item>
              <el-button
                type="primary"
                v-show="!showtableList"
                plain
                @click="finishSelect"
                >确定</el-button
              >
            </el-form-item>
          </div>
        </el-form>
      </div>
      <div
        class="table_box"
        v-if="this.itemInfomation[0].tabletype == 'busDeviceMain'"
      >
        <el-table border :data="itemInfomation" stripe style="width: 100%">
          <!-- <el-table-column prop="bdmId" label="设备ID"> </el-table-column> -->
          <el-table-column min-width="100" prop="deviceNo" label="设备编码">
          </el-table-column>
          <el-table-column
            min-width="100"
            prop="bdmSpecification"
            label="规格型号"
          >
          </el-table-column>
          <el-table-column
            min-width="160"
            prop="bdmDeviceName"
            label="设备名称"
          >
          </el-table-column>
          <el-table-column min-width="50" prop="bdmType" label="设备类别">
          </el-table-column>
        </el-table>
        <div class="btn_box">
          <el-button type="success" plain @click="updateBind"
            >绑定提交</el-button
          >
          <el-button type="info" plain @click="backList"
            >返回绑定查询</el-button
          >
        </div>
      </div>
      <div class="table_box" v-else>
        <el-table border :data="itemInfomation" stripe style="width: 100%">
          <!-- <el-table-column prop="id" label="设备ID"> </el-table-column> -->
          <el-table-column min-width="100" prop="deviceNo" label="设备编码">
          </el-table-column>
          <el-table-column min-width="100" prop="deviceName" label="设备名称">
          </el-table-column
          ><el-table-column min-width="100" prop="deviceModel" label="规格型号">
          </el-table-column>
          <el-table-column min-width="100" prop="deivceType" label="设备类别">
          </el-table-column>
        </el-table>
        <div class="pag" style="text-align: center; margin-top: 20px"></div>
        <div class="btn_box">
          <el-button type="success" plain @click="updateBind"
            >绑定提交</el-button
          >
          <el-button type="info" plain @click="backList"
            >返回绑定查询</el-button
          >
        </div>
      </div>
    </div>
  </div>
</template>
 
<script>
let handler;
let pickedFeature;
 
import {
  updatebusDeviceMainlist,
  updatebusProductionDevicelist,
} from "../../../api/api";
 
export default {
  //import引入的组件需要注入到对象中才能使用
  components: {},
  data() {
    //这里存放数据
    return {
      showtableList: true,
      currentPage3: 5,
      itemInfomation: [],
      options: [],
      tabletype: "",
      formInline: {
        lng: "",
        lat: "",
        modelId: "",
      },
    };
  },
  //方法集合
  methods: {
    selectModel() {
      this.showtableList = !this.showtableList;
      handler && handler.destroy();
      handler = new Cesium.ScreenSpaceEventHandler(Viewer.scene.canvas);
      handler.setInputAction((event) => {
        pickedFeature && (pickedFeature.color = Cesium.Color.WHITE);
        pickedFeature = sgworld.Viewer.scene.pick(event.position);
        if (Cesium.defined(pickedFeature)) {
          if (pickedFeature.primitive instanceof Cesium.Cesium3DTileset) {
            if (pickedFeature && pickedFeature.getProperty) {
              pickedFeature.color = Cesium.Color.RED.withAlpha(0.8);
              let value = pickedFeature.getProperty("name");
              let cartographic =
                window.Viewer.scene.globe.ellipsoid.cartesianToCartographic(
                  pickedFeature.content.tile.boundingSphere.center
                );
              let lng = Cesium.Math.toDegrees(cartographic.longitude);
              let lat = Cesium.Math.toDegrees(cartographic.latitude);
              this.formInline.modelId = value;
              this.formInline.lng = lng;
              this.formInline.lat = lat;
            }
          }
        }
      }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
    },
    finishSelect() {
      this.showtableList = !this.showtableList;
      pickedFeature && (pickedFeature.color = Cesium.Color.WHITE);
      handler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_CLICK);
    },
    updateBind() {
      // console.log(this.itemInfomation[0].tabletype);
      if (this.itemInfomation[0].tabletype == "busDeviceMain") {
        let obj = {
          bdmId: this.itemInfomation[0].bdmId,
          bdmLocation: `${this.formInline.lng}, ${this.formInline.lat}`,
          modelId: this.formInline.modelId,
          status: 1,
        };
        updatebusDeviceMainlist(obj).then((res) => {
          if (res.data.code === 200) {
            this.$message({
              type: "success",
              message: "成功!",
            });
            this.backList();
          }
        });
        handler && handler.destroy();
        handler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_CLICK);
      } else if (this.itemInfomation[0].tabletype == "busProductionDevice") {
        let obj = {
          id: this.itemInfomation[0].id,
          bindLocation: `${this.formInline.lng}, ${this.formInline.lat}`,
          modelId: this.formInline.modelId,
          status: 1,
        };
        updatebusProductionDevicelist(obj).then((res) => {
          if (res.data.code === 200) {
            this.$message({
              type: "success",
              message: "成功!",
            });
            this.backList();
          }
        });
        handler && handler.destroy();
        handler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_CLICK);
      }
    },
 
    backList() {
      pickedFeature && (pickedFeature.color = Cesium.Color.WHITE);
      handler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_CLICK);
      handler && handler.destroy();
      this.$store.commit("showBindBox", true);
      this.$store.commit("showBindInfoBox", false);
    },
    initData() {
      //是否绑定过模型
      if (
        this.$store.state.binditemInfo.modelId !== null &&
        this.$store.state.binditemInfo.modelId !== ""
      ) {
        let arr = this.$store.state.binditemInfo.bdmLocation.split(",");
        let lng = parseFloat(arr[0]);
        let lat = parseFloat(arr[1]);
        this.formInline.modelId = this.$store.state.binditemInfo.modelId;
        this.formInline.lng = lng;
        this.formInline.lat = lat;
      } else {
        return;
      }
    },
  },
 
  created() {
    this.initData();
    this.itemInfomation[0] = this.$store.state.binditemInfo;
    if (this.$store.state.binditemInfo.bdmId) {
      this.itemInfomation[0].tabletype = "busDeviceMain";
    } else if (this.$store.state.binditemInfo.id) {
      this.itemInfomation[0].tabletype = "busProductionDevice";
    }
  },
};
</script>
<style lang="less" scoped>
.list {
  width: 1200px;
  background: rgba(255, 255, 255, 0.8);
  .header_box {
    padding: 8px;
    background: rgba(0, 0, 0, 0.9);
    color: #fff;
    span {
      font-size: 15px;
    }
  }
  .content {
    padding: 10px 20px;
    .search {
      display: flex;
      /deep/ .el-form-item {
        margin-bottom: 8px;
      }
      .table_box {
        background-color: #bfa;
      }
      // .demo-form-inline {
      //   // display: flex;
      //   // justify-content: space-between;
      //   // flex-wrap: wrap;
      //   .form_box1 {
      //     display: flex;
      //     justify-content: space-between;
      //     flex-wrap: wrap;
      //   }
      //   .form_box2 {
      //     display: flex;
      //     justify-content: space-between;
      //     flex-wrap: wrap;
      //   }
      // }
    }
    .btn_box {
      margin-top: 20px;
      display: flex;
      justify-content: space-around;
    }
  }
}
</style>