CZT
2023-10-21 3e7773504d6bd15e6ed20ecf5c6236b163ba0fe8
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
var viewAB = "01";// 默认正面
 
/**
 * 根据设备列表渲染设备示意图,要求被渲染的divID = device_view
 *
 * @param listDevice
 */
renderDevice = function (listDevice) {
    // 首先清空div中的内容
    $("#device_view").empty();
    // 根据设备列表添加原型信息
    addDevice(listDevice, viewAB);
};
 
// 切换图片a=正面,b=背面
function cutImg(depotId, target) {
    // 首先清空div中的内容
    $("#device_view").empty();
 
    var verbImg = imgMap[depotId];
    // console.log(verbImg);
    var imgPath = "../../static/img/areation/" + verbImg.file + "/" + verbImg.a;
    if (target == "02") {
        imgPath = "../../static/img/areation/" +  verbImg.file + "/" + verbImg.b;
    }
 
    $("#device_view").css("background", "url(" + imgPath + ") no-repeat");
    viewAB = target;
};
 
// 动态添加设备信息
function addDevice(list) {
    if (!list || list.length == 0) return;
    var container = $("#device_view");
    var parentLeft = container.offset().left, parentTop = container.offset().top;
    // var parentWidth = container.width(), parentHeight = container.height();
 
    var temp;
    var left = 0, top = 0;
    var imgResult;
    $.each(list, function (index, item) {
        // 获取PC的位置
        left = parentLeft + item.posX - 20;
        top = parentTop + item.posY - 10;
        temp = "";
        if (viewAB == "01" && item.location == "02") {
            return true;// 跳过
        }
        if (viewAB == "02" && item.location == "01") {
            return true;// 跳过
        }
        imgResult = getStatusImg(item);
 
        temp += "<div id='" + item.id + "' class='device' " + "depotid='"
            + item.depotId + "' name='" + item.name + "' type='"
            + item.type + "' passcode='" + item.passCode + "' serid='"
            + item.serId
            + "' status='" + item.status
            + "' link='" + item.link
            + "' select='false"
            + "' onclick=showControl('" + item.id + "') style='left:"
            + left + "px;top:" + top + "px;'>";
 
        if (DeviceType.TYPE_03 == item.type) {
            temp += "<img class='img_device40' src='" + imgResult.statusImg + "' />";
        } else if (DeviceType.TYPE_04 == item.type) {
            temp += "<img class='img_device25' src='" + imgResult.statusImg + "' />";
        } else if (viewAB == "02") {
            temp += "<img class='img_device50' src='" + imgResult.statusImg + "' />";
        } else {
            temp += "<img class='img_device30' src='" + imgResult.statusImg + "' />";
        }
        //表示有故障
        if (imgResult.errorTag) {
            temp += "<i class='err-img'></i>";
        }
        temp += "</div>";
 
        container.append(temp);
    });
};
 
// 根据设备类型和状态,获取当前设备的显示状态图片
function getStatusImg(item) {
    var result = {
        statusImg: null,
        errorTag: false
    };
 
    //轴流风窗
    if (DeviceType.TYPE_02 == item.type) {
        if (!item.status || DeviceStatus.ERROR == item.status) {
            result.statusImg = "../../static/img/device/CIR_02_W_CLOSE.png";
            result.errorTag = true;
            return result;
        }
        if (DeviceStatus.W_CLOSE == item.status) {
            result.statusImg = "../../static/img/device/CIR_02_W_CLOSE.png";
            return result;
        }
        if (DeviceStatus.W_OPEN == item.status) {
            result.statusImg = "../../static/img/device/CIR_02_F_CLOSE.png";
            return result;
        }
        if (DeviceStatus.F_CLOSE == item.status) {
            result.statusImg = "../../static/img/device/CIR_02_F_CLOSE.png";
            return result;
        }
        if (DeviceStatus.F_OPEN == item.status) {
            result.statusImg = "../../static/img/device/CIR_02_F_OPEN.gif";
            return result;
        }
        if (DeviceStatus.F_OPEN_F == item.status) {
            result.statusImg = "../../static/img/device/CIR_02_F_OPEN_F.gif";
            return result;
        }
    }
    //离心风机
    if (DeviceType.TYPE_03 == item.type) {
        if (!item.status || DeviceStatus.ERROR == item.status) {
            result.statusImg = "../../static/img/device/CIR_03_CLOSE.png";
            result.errorTag = true;
            return result;
        }
        if (DeviceStatus.CLOSE == item.status || DeviceStatus.F_CLOSE == item.status) {
            result.statusImg = "../../static/img/device/CIR_03_CLOSE.png";
            return result;
        }
        if (DeviceStatus.OPEN == item.status || DeviceStatus.F_OPEN == item.status) {
            result.statusImg = "../../static/img/device/CIR_03_OPEN.gif";
            return result;
        }
    }
 
    //环流风机
    if (DeviceType.TYPE_04 == item.type) {
        if (!item.status || DeviceStatus.ERROR == item.status) {
            result.statusImg = "../../static/img/device/CIR_04_CLOSE.png";
            result.errorTag = true;
            return result;
        }
        if (DeviceStatus.CLOSE == item.status || DeviceStatus.F_CLOSE == item.status) {
            result.statusImg = "../../static/img/device/CIR_04_CLOSE.png";
            return result;
        }
        if (DeviceStatus.OPEN == item.status || DeviceStatus.F_OPEN == item.status) {
            result.statusImg = "../../static/img/device/CIR_04_OPEN.gif";
            return result;
        }
    }
    //阀门
    if (DeviceType.TYPE_07 == item.type || DeviceType.TYPE_09 == item.type) {
        if (!item.status || DeviceStatus.ERROR == item.status) {
            result.statusImg = "../../static/img/device/CIR_07_CLOSE.png";
            result.errorTag = true;
            return result;
        }
        if (DeviceStatus.CLOSE == item.status) {
            result.statusImg = "../../static/img/device/CIR_07_CLOSE.png";
            return result;
        }
        if (DeviceStatus.OPEN == item.status) {
            result.statusImg = "../../static/img/device/CIR_07_OPEN.png";
            return result;
        }
    }
 
    //通风口
    if (DeviceType.TYPE_0B == item.type) {
        if (!item.status || DeviceStatus.ERROR == item.status) {
            result.statusImg = "../../static/img/device/CIR_0B_CLOSE.png";
            result.errorTag = true;
            return result;
        }
        if (DeviceStatus.CLOSE == item.status) {
            result.statusImg = "../../static/img/device/CIR_0B_CLOSE.png";
            return result;
        }
        if (DeviceStatus.OPEN == item.status) {
            result.statusImg = "../../static/img/device/CIR_0B_OPEN.png";
            return result;
        }
    }
    return result;
};
 
// 根据CSS标签控制那些组件支持拖拽.device
function dragDevice() {
    var tips = $(".device");
    if (tips.length == 0) {
        return;
    }
    // var container = $("#device_view");
    // var parentLeft = container.offset().left, parentTop = container.offset().top;
    //console.log("-----------parentLeft----" + parentLeft);
    // console.log("-----------parentTop----" + parentTop);
    //var parentWidth = container.width(), parentHeight = container.height();
    var maxX = 1300, maxY = 750;
    $.each(tips, function (index, item) {
        var dd = new Dragdrop({
            target: item,
            area: [0, maxX, 0, maxY],
            callback: function (obj) {
                // console.log('x:' + (obj.moveX - parentLeft) + ' y:' + (obj.moveY - parentTop));
            }
        });
        dd.dragAll();
    });
};
 
// 保存设备位置信息
function updatePos() {
    var tips = $(".device");
    if (tips.length == 0) {
        return;
    }
    var container = $("#device_view");
    var parentLeft = container.offset().left, parentTop = container.offset().top;
    //var parentWidth = container.width(), parentHeight = container.height();
    // 封装数据进行保存
    var data = new Array();
    var id, curDepotId = null, offset;
    $.each(tips, function (index, item) {
        id = item.id;
        curDepotId = item.getAttribute("depotid");
        offset = $('#' + id).offset();
        //调整为相对位置
        posX = offset.left - parentLeft;
        posY = offset.top - parentTop;
 
        data[index] = {
            bizId: id,
            depotId: curDepotId,
            selfTag: viewAB,
            posX: posX,
            posY: posY
        };
    });
 
    $.ajax({
        type: 'POST',
        url: "../../basic/common/update-verb-pos",
        dataType: 'JSON',
        contentType: "application/json;charset=UTF-8",
        data: JSON.stringify(data),
        success: function (result) {
            layer.msg(result.msg);
        },
        error: function (result) {
            layer.msg(result.msg);
        }
    });
}