var _this, dataObj = [], baseTok = null;
var map;
var settIme;
new Vue({
el: '#app',
data: function() {
return {
shipLi: [],
nowTab: {},
userForm: {},
nowTime: "",
cctvWarm: [{ "name": "离岗检测", "count": 0 },
{ "name": "手机检测", "count": 0 },
{ "name": "抽烟检测", "count": 0 },
{ "name": "物品检测", "count": 0 }],
fenceWarm: [{ "name": "甲板警戒区", "count": 0 },
{ "name": "浮吊警戒区", "count": 0 }],
craneWarm: [{ "name": "钢丝绳检测", "count": 0 },
{ "name": "起重机检测", "count": 0 }],
genWarmDetail: [{ "name": "生理疲劳", "count": 0 },
{ "name": "分神驾驶", "count": 0 },
{ "name": "遮挡摄像头", "count": 0 },
{ "name": "超时驾驶", "count": 0 }]
// { "name": "定滑轮检测", "count": 0 },
}
},
created() {
_this = this;
baseTok = getCookie("Admin-Token") != "null" && getCookie("Admin-Token") != null ? getCookie("Admin-Token") : "";
_this.nowTime = parseTime(new Date(), `{y}/{m}/{d}`);
_this.userForm = JSON.parse(getCookie("Admin-User"));
_this.initAjax(0);
settIme = setInterval(()=>{
_this.initAjax(1);
},30*1000);
},
mounted(){
map = new AMap.Map("areaMap", {
center: [113.5556, 22.9422],
zoom: 14
});
map.addControl(new AMap.Scale({ visible: true }) );
window.addEventListener('message',(data)=>{
if(data.data != _this.nowTab.sn){
_this.changTab(data.data);
}
})
},
methods: {
initAjax(type){
if(type == 0){
var loading = this.$loading({
background: 'rgba(0, 0, 0, 0.4)'
})
}
let _opts = {
url: baseUrl + "/SelCctvListByUserId",
type:"GET"
};
let _data = {
"user_id": _this.userForm.userId
};
let _hea = {
"Authorization": "Bearer " + baseTok
};
getAxios(_opts,_data,_hea).then((res) => {
if(res.code == 200&&res.data.length){
let _xji = res.data;
let _bji = _xji.map(item => item.mmsi);
getCctvAis(_bji.toString(),function(_res){
let _arr = [];
_xji.forEach(item => {
let sd = _res.filter(subitem => subitem[0] == item.mmsi)[0];
let _newpo = GpsToGd(Number(sd[13]), Number(sd[12]));
_arr.push({
icon: staticUrl + "/img/ship.png",
position: [_newpo.lon,_newpo.lat],
lon: sd[12],
lat: sd[13],
prod: item.dev_name,
sn: item.sn,
mmsi: item.mmsi,
en_name: item.en_name,
speed: (item.mmsi == "413871376"&&sd[15]>1?0.1:sd[15]),
time: sd[23]// sd[23]
})
})
_this.shipLi = _arr;
dataObj = _arr;
let _sn = JSON.parse(localStorage.getItem("nowShip"));
if(_sn !=null && _sn != "null"){
let _ind = _this.shipLi.findIndex((i,ind) => {return i.sn == _sn.sn});
if(_ind != -1){
_sn = _this.shipLi[_ind];
}else{
_sn = _this.shipLi[0];
}
}else{
_sn = _this.shipLi[0];
}
_this.nowTab = _sn;
_this.setMap(_this.shipLi);
});
// let _obj = res.data;
// let _arr = [];
// _obj.forEach((item,ind) => {
// let _nlon = wgsGcj(item.lat, item.lon);
// _arr.push({
// icon: staticUrl + "/img/ship.png",
// position: [_nlon.lon, _nlon.lat],
// prod: item.prod,
// sn: item.sn,
// speed: item.speed,
// devicelist: item.devicelist
// })
// })
}else{
_this.shipLi = [];
_this.nowTab = null;
}
// _this.getWire();
// _this.getCctv();
// _this.getLedar();
_this.getGenAlarm();
if(type == 0){loading.close();}
})
},
changTab(id){
let ind = _this.shipLi.findIndex((it,ind) => {return id == it.sn});
if(ind != -1){
_this.nowTab = _this.shipLi[ind].sn;
window.parent.postMessage({id: _this.nowTab},staticUrl+ "/");
_this.openInfo(_this.nowTab);
}
},
setMap(_obj){
map.clearMap();
_obj.forEach(function(_obj) {
var marker = new AMap.Marker({
map: map,
icon: new AMap.Icon({
size: new AMap.Size(50, 50),
image: _obj.icon,
imageSize: new AMap.Size(50, 50)
}),
position: _obj.position,
offset: new AMap.Pixel(-13, -30),
extData: _obj.sn
});
marker.setLabel({
offset: new AMap.Pixel(0, 0),
content: "
" + _obj.prod + "
",
direction: 'bottom'
});
marker.on('click', markerClick);
});
_this.openInfo(_this.nowTab.sn);
function markerClick(e) {
let _ind = e.target.getExtData();
window.parent.postMessage({id: _ind}, staticUrl+ "/");
_this.openInfo(_ind);
}
},
openInfo(_sn){
let _cmk = _this.shipLi;
for (var i = 0; i < _cmk.length; i++) {
if (_sn == _cmk[i].sn) {
let _str = _cmk[i];
_this.nowTab = _str;
var info = [];
getFormattedAddress(_str.position, function(_pos) {
info.push(`
${_str.prod}
经度:
${duToGpsDM(_str.lon,'E')}
纬度:
${duToGpsDM(_str.lat,'N')}
时间:
${ parseTime(_str.time, '{y}-{m}-{d} {h}:{d}:{s}')}
`);
infoWindow = new AMap.InfoWindow({
offset: new AMap.Pixel(6, -30),
content: info.join("")
});
infoWindow.open(map, _str.position);
map.setCenter(_str.position);
return;
});
}
}
},
getWire(){
let dj = parseTime(new Date(), `{y}-{m}-{d}`);
var imieList = ["ZJ216801593395575038","ZJ217008114043323047"];
var total = 0;
imieList.forEach((item,index)=>{
getWireWarmHistory({
imei: item,
gt: (new Date(dj+" 00:00:00").getTime())/1000,
lt: (new Date(dj+" 23:59:59").getTime())/1000,
orderSql: "time desc",
page: 1,
rows: 1,
accessToken: getCookie("wireToken")
},function(res){
total += parseFloat(res.total);
if((index+1) == imieList.length){
let _obj = _this.craneWarm;
_obj[0].count = total;
_this.craneWarm = _obj;
}
});
});
},
getCctv(){
let _obj = _this.shipLi;
var _warnli = [];
for(let i=0;i<_obj.length;i++){
let _item = _obj[i];
if(_item.en_name != ""&&_item.en_name != null){
let _opts = {
url: vipUrl + "/receive",
type:"GET"
};
let _data = {
user: _item.en_name,
msgType: "",
enddate: _this.nowTime,
startdate: _this.nowTime,
pageNum: 0,
pageSize: 500
};
let _hea = {
"Authorization": "ZDhlNjhjOTAwM2EyJWd6eXolaWUldXNlciV6aF9DTg==",
"Content-Type": "application/json;charset=UTF-8"
};
getAxios(_opts, _data, _hea).then((res) => {
if(res.success&&res.data.length){
_warnli = [..._warnli, ...res.data];
}
if((i+1) == _obj.length){
_this.getCctvCount(_warnli);
}
})
}
}
},
getCctvCount(_obj){
if(_obj.length){
let al = 0, bl = 0, cl = 0, dl = 0, el = 0;
_obj.forEach((item,index) => {
if(item.msgType === "lgjc"){
al += 1;
}else if(item.msgType === "ddhjc"||item.msgType === "wsjjc"){
bl += 1;
}else if(item.msgType === "cyjc"){
cl += 1;
}else if(item.msgType === "aqmjc"||item.msgType === "gzfjc"||item.msgType === "kzjc"||item.msgType === "yhsb"){
dl += 1;
}else if(item.msgType === "qycr"){
el += 1;
}
});
_this.cctvWarm = [{ "name": "离岗检测", "count": al },
{ "name": "手机检测", "count": bl },
{ "name": "抽烟检测", "count": cl },
{ "name": "物品检测", "count": dl }];
let afsafbj = _this.fenceWarm;
afsafbj[0].count = el;
_this.fenceWarm = afsafbj;
}else{
_this.cctvWarm = [{ "name": "离岗检测", "count": 0 },
{ "name": "手机检测", "count": 0 },
{ "name": "抽烟检测", "count": 0 },
{ "name": "物品检测", "count": 0 }];
}
},
getLedar(){
let _obj = _this.shipLi;
var _warnli = 0;
for(let i=0;i<_obj.length;i++){
let _item = _obj[i];
if(_item.en_name != ""&&_item.en_name != null){
let _data = {
sn: _item.en_name,
endTime: _this.nowTime.replace(/\//g,"-"),
beginTime: _this.nowTime.replace(/\//g,"-"),
pageNum: 1,
pageSize: 2
};
getLedarData(_data, function(_res){
_warnli += _res.total;
if((i+1) == _obj.length){
let _obj = _this.craneWarm;
_obj[0].count = _warnli;
_this.craneWarm = _obj;
}
})
}
}
},
getGenAlarm(){
getAllAlarm(_this.nowTime).then(res => {
let g1 = 0, g2 = 0, g3 = 0, g4 = 0;
if(JSON.stringify(res.result) != "{}"){
let _obj = res.result;
for(let key in _obj){
let _subObj = _obj[key];
for(let val in _subObj){
console.log(_subObj[val])
if(val == "am"){
g2 += parseFloat(_subObj[val]);
}else if(val == "td"){
g4 += parseFloat(_subObj[val]);
}else if(val == "t3d"){
g3 += parseFloat(_subObj[val]);
}else if(val == "fd" || val == "ya" || val == "cey"){
g1 += parseFloat(_subObj[val]);
}
}
}
}
_this.genWarmDetail = [{ "name": "生理疲劳", "count": g1 },
{ "name": "分神驾驶", "count": g2 },
{ "name": "遮挡摄像头", "count": g3 },
{ "name": "超时驾驶", "count": g4 }];
})
}
}
})