jiazx0107@163.com
2023-07-04 785ce007ce4b7b2119a99aacc95cefe9da09e32e
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
284
285
286
287
288
289
var layer;
var depotId;
var view_tag = "A";//A-仓外 B-仓内
var windowWidth = 1920;
var windowHeight = 1080;
 
$(function () {
    layui.use(['layer'], function () {
        layer = layui.layer;
        renderDevice();
    });
});
 
 
window.onload = function () {
    $("#m-container").css("background-image", "url(" + backgroundImg + ")");
    windowWidth = document.body.offsetWidth;
    windowHeight = document.body.offsetHeight;
};
 
function shoControl(id) {
    $.each(listDevice, function (index, item) {
        if (item.id == id) {
            depotId = item.depotId;
            return true;
        }
    });
 
    layer.open({
        type: 1,
        title: '当前仓操作',
        area: ['450px', '210px'],
        shade: 0,
        content: $('#control-FK'),
        btn: 0,
        closeBtn: 2
    });
};
 
function showTips(msg) {
    $("#fire_info").text("信息:" + msg);
};
 
//添加设备信息
function renderDevice() {
    if (!listDevice || listDevice.length == 0) {
        showTips("没有获取到照明配置信息!");
        return;
    }
 
    //删除之前的渲染
    $("div").remove(".device");
 
    var container = $("#m-container");
    var parentWidth = container.width();
    var parentHeight = container.height();
    var temp;
    var left = 50, top = 50;
    $.each(listDevice, function (index, item) {
 
        //外部设备
        if (view_tag == "A" && DeviceLocation.L_05 == item.location) {
            return true;
        }
        //内部
        if (view_tag == "B" && DeviceLocation.L_05 != item.location) {
            return true;
        }
 
        left = (parentWidth * item.posX).toFixed(4);
        top = (parentHeight * item.posY).toFixed(4);
        if (left < 1) left = 50;
        if (top < 1) top = 50;
        temp = "";
        temp += "<div id='" + item.id + "' class='device' "
            + " onclick=showTips('" + item.name + "') "
            + " ondblclick=shoControl('" + item.id + "') style='left:"
            + left + "px;top:" + top + "px;'>";
 
        if (DeviceStatus.OPEN == item.status) {
            temp += "<img src='../../static/img/device/lamp_OPEN.png' /></div>";
        } else {
            temp += "<img src='../../static/img/device/lamp_CLOSE.png' /></div>";
        }
        container.append(temp);
    });
};
 
function cut(tag) {
    if ("A" == tag) {
        $("#btnA").removeClass("layui-btn-primary");
        $("#btnB").addClass("layui-btn-primary");
    }
    if ("B" == tag) {
        $("#btnB").removeClass("layui-btn-primary");
        $("#btnA").addClass("layui-btn-primary");
    }
    view_tag = tag;
    renderDevice();
};
 
//内部操作
function executeIn(targetStatus) {
    toExecute(targetStatus, "IN");
};
 
//外部操作
function executeOut(targetStatus) {
    toExecute(targetStatus, "OUT");
};
 
//正库区操作
function executeALL(targetStatus) {
    depotId = null;
    toExecute(targetStatus, "ALL");
};
 
 
//全部状态查询
function queryAllStatus() {
    depotId = null;
    queryStatus();
};
 
//设备操作
function toExecute(targetStatus, type) {
    var param = {
        companyId: companyId,
        deptId: deptId,
        depotId: depotId,
        type: type,
        targetStatus: targetStatus,
        deviceList: listDevice
    };
 
    // console.log(param);
 
    // 开始调用后台执行
    layer.load(1);
    $.ajax({
        type: 'POST',
        url: "../../basic/lamp/control-device",
        dataType: 'JSON',
        contentType: "application/json;charset=UTF-8",
        data: JSON.stringify(param),
        success: function (result) {
            layer.closeAll();
            if (result.code != "ORDER_SUCCESS") {
                layer.alert("执行失败:" + result.msg);
            } else {
                layer.alert("操作指令发送成功,待终端响应……");
                query();
            }
        },
        error: function () {
            layer.closeAll();
            layer.alert("操作发生异常,暂时无法解决!!");
        }
    });
};
 
 
// 状态查询
function queryStatus() {
    layer.load(1);
    var param = {
        companyId: companyId,
        deptId: deptId,
        depotId: depotId,
        deviceList: listDevice
    };
    $.ajax({
        type: "POST",
        url: "../../basic/lamp/query-status",
        dataType: "json",
        contentType: "application/json;charset=UTF-8",
        data: JSON.stringify(param),
        success: function (result) {
            layer.closeAll();
            if ("ORDER_SUCCESS" != result.code) {
              //  layer.alert(result.msg);
                showTips(result.msg);
            }
            query();
        },
        error: function () {
            layer.closeAll();
            layer.alert("获取数据失败,请重新尝试!");
        }
    });
};
 
 
// 执行查询
function query() {
 
    //console.log('-----------query----------------');
 
    layer.load(1);
    var param = {
        companyId: companyId,
        deptId: deptId
    };
    $.ajax({
        type: "POST",
        url: "../../basic/lamp/list-device-group",
        dataType: "json",
        contentType: "application/json;charset=UTF-8",
        data: JSON.stringify(param),
        success: function (result) {
            layer.closeAll();
            if (result.code != "0000") {
                layer.msg(result.msg);
                return;
            }
            listDevice = result.data;
            // 根据设备渲染
            renderDevice();
        },
        error: function () {
            layer.closeAll();
            layer.alert("获取设备列表失败,请重新刷新页面!");
        }
    });
};
 
// 根据CSS标签控制那些组件支持拖拽.device
function dragDevice() {
    var tips = $(".device");
    if (tips.length == 0) {
        return;
    }
    var maxX = windowWidth;
    var maxY = windowHeight;
    $.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 = $("#m-container");
    var parentWidth = container.width();
    var parentHeight = container.height();
    var parentTop = container.offset().top;
    var parentLeft = container.offset().left;
 
 
    // 封装数据进行保存
    var data = new Array();
    var id = null, offset, posX = 0.0, posY = 0.0;
    $.each(tips, function (index, item) {
        id = item.id;
        offset = $('#' + id).offset();
        //调整为相对位置
        posX = (offset.left - parentLeft) / parentWidth;
        posY = (offset.top - parentTop) / parentHeight;
 
        data[index] = {
            bizId: id,
            posX: posX.toFixed(4),
            posY: posY.toFixed(4)
        };
    });
    $.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);
        }
    });
}