332 lines
9.3 KiB
JavaScript
332 lines
9.3 KiB
JavaScript
// pages/home/homefree.js
|
||
const app = getApp();//获取全局对象
|
||
Page({
|
||
|
||
/**
|
||
* 页面的初始数据
|
||
*/
|
||
data: {
|
||
imgUrl: "../../images/yijianqiujiuguan.png",
|
||
|
||
toptabel: 'Welcome Home!',
|
||
userName: '',
|
||
userPhone: '',
|
||
province: '',
|
||
addrDetail: '',
|
||
unitName:'',
|
||
items: [],
|
||
|
||
userid: '',
|
||
code:'1',
|
||
},
|
||
/**
|
||
* 生命周期函数--监听页面加载
|
||
*/
|
||
onLoad: function (options) {
|
||
this.refreshweb2()
|
||
|
||
},
|
||
|
||
/**
|
||
* 生命周期函数--监听页面初次渲染完成
|
||
*/
|
||
onReady: function () {
|
||
|
||
},
|
||
|
||
/**
|
||
* 生命周期函数--监听页面显示
|
||
*/
|
||
onShow: function () {
|
||
this.refreshweb2();
|
||
},
|
||
|
||
/**
|
||
* 生命周期函数--监听页面隐藏
|
||
*/
|
||
onHide: function () {
|
||
|
||
},
|
||
|
||
/**
|
||
* 生命周期函数--监听页面卸载
|
||
*/
|
||
onUnload: function () {
|
||
|
||
},
|
||
|
||
/**
|
||
* 页面相关事件处理函数--监听用户下拉动作
|
||
*/
|
||
onPullDownRefresh: function () {
|
||
|
||
},
|
||
|
||
/**
|
||
* 页面上拉触底事件的处理函数
|
||
*/
|
||
onReachBottom: function () {
|
||
|
||
},
|
||
|
||
/**
|
||
* 用户点击右上角分享
|
||
*/
|
||
onShareAppMessage: function () {
|
||
|
||
},
|
||
onPullDownRefresh: function () {
|
||
this.refreshweb2();
|
||
wx.stopPullDownRefresh();
|
||
},
|
||
refreshweb2: function () {
|
||
wx.login({
|
||
//获取code
|
||
success: res=> {
|
||
this.setData({
|
||
code:res.code,
|
||
})
|
||
console.log(this.data.code)
|
||
//获取OpenID
|
||
wx.request({
|
||
url: 'https://www.mpecloud.com:8443/na/iocm/devNotify/v1.1.0/getOpenId/' + this.data.code,
|
||
header: { 'content-type': 'application/json' },
|
||
success: res => {
|
||
console.log(res.data)
|
||
if (res.data.message == 'success') {
|
||
wx.request({
|
||
url: 'https://www.mpecloud.com:8443/na/iocm/devNotify/v1.1.0/detailInfo/' + res.data.openid,
|
||
header: { 'content-type': 'application/json' },
|
||
success: res => {
|
||
var lenth =999999999;
|
||
console.log(app.globalData.userid);
|
||
for(var x = 0;x<res.data.user.length;x++)
|
||
{
|
||
var userid = app.globalData.userid;
|
||
var userphone = res.data.user[x].userPhone;
|
||
if (userphone.indexOf(userid)!=-1)
|
||
{
|
||
lenth=x;
|
||
}
|
||
}
|
||
//如果不存在对应的手机号,默认取第一个
|
||
if (lenth == 999999999)
|
||
{
|
||
lenth=0;
|
||
}
|
||
console.log(res.data.user[lenth]);
|
||
//账号信息
|
||
this.setData({
|
||
userName: res.data.user[lenth]['userName'],
|
||
userPhone: res.data.user[lenth]['userPhone'],
|
||
unitName: res.data.user[lenth]['unitName'],
|
||
province: res.data.user[lenth]['province'] + res.data.user[lenth]['city'],
|
||
addrDetail: res.data.user[lenth]['area'] + res.data.user[lenth]['addrDetail']
|
||
})
|
||
|
||
//设置数据加载
|
||
var rrr = new Array();
|
||
rrr = res.data.user[lenth]['deviceList'];//设备信息
|
||
for (var i = 0; i < rrr.length; i++) {
|
||
//设置设备网络状态
|
||
if (rrr[i]['status'] ==0)
|
||
{
|
||
rrr[i]['status'] = '基本信息注册中'
|
||
}
|
||
else if (rrr[i]['status'] == 1)
|
||
{
|
||
rrr[i]['status'] = '产品信息注册中'
|
||
}
|
||
else if (rrr[i]['status'] == 2) {
|
||
rrr[i]['status'] = '注册成功'
|
||
}
|
||
else if (rrr[i]['status'] == 3) {
|
||
rrr[i]['status'] = '在线'
|
||
}
|
||
else if (rrr[i]['status'] == 4) {
|
||
rrr[i]['status'] = '离线'
|
||
}
|
||
else if (rrr[i]['status'] == 6) {
|
||
rrr[i]['status'] = '过期'
|
||
}
|
||
|
||
//设置设备状态
|
||
if (rrr[i]['mute'] == 0) {
|
||
if (rrr[i]['alarms'] == '' || rrr[i]['alarms'] == null)
|
||
{
|
||
rrr[i]['mute'] = '正常'
|
||
rrr[i]['attr3'] = 'white'
|
||
rrr[i]['attr4'] = '400'
|
||
rrr[i]['attr5'] = '1em'
|
||
}
|
||
else
|
||
{
|
||
//电池告警
|
||
if (rrr[i].alarms.type == 'callbattery' || rrr[i].alarms.type == 'smkbattery'){
|
||
rrr[i]['mute'] = '正常'
|
||
rrr[i]['attr3'] = 'white'
|
||
rrr[i]['attr4'] = '400'
|
||
rrr[i]['attr5'] = '1em'
|
||
rrr[i]['areaCode'] = 'red'
|
||
}
|
||
else{
|
||
rrr[i]['mute'] = '告警'
|
||
rrr[i]['attr3'] = 'red'
|
||
rrr[i]['attr4'] = '800'
|
||
rrr[i]['attr5'] = '1.5em'
|
||
}
|
||
}
|
||
}
|
||
else if (rrr[i]['mute'] == 1) {
|
||
rrr[i]['mute'] = '故障'
|
||
rrr[i]['attr3']='red'
|
||
rrr[i]['attr4'] ='800'
|
||
rrr[i]['attr5'] ='1.5em'
|
||
}
|
||
else if (rrr[i]['mute'] == 2) {
|
||
rrr[i]['mute'] = '状态未设'
|
||
rrr[i]['attr3'] = 'white'
|
||
rrr[i]['attr4'] = '400'
|
||
rrr[i]['attr5'] = '1em'
|
||
}
|
||
|
||
//设置设备特殊字段
|
||
if (rrr[i]['productId'] == 4 || rrr[i]['productId'] == 8) {
|
||
rrr[i]['attr2'] = '燃气浓度'
|
||
rrr[i]['areaCode'] = 'white'
|
||
}
|
||
else {
|
||
rrr[i]['attr2'] = '电池电量'
|
||
}
|
||
|
||
//设置按钮
|
||
if (rrr[i]['productId'] == 3) {
|
||
rrr[i]['area']='true'
|
||
}
|
||
}
|
||
|
||
this.setData({
|
||
items: rrr,
|
||
|
||
})
|
||
}, fail: function () {
|
||
wx.showToast({
|
||
title: app.globalData.userid + '接口null',
|
||
icon: 'none',
|
||
duration: 2000
|
||
})
|
||
}
|
||
})
|
||
|
||
}
|
||
else {
|
||
wx.showToast({
|
||
title: '设备未绑定!',
|
||
icon: 'none',
|
||
duration: 2000
|
||
})
|
||
}
|
||
}, fail: function () {
|
||
wx.showToast({
|
||
title: 'openid获取错误!',
|
||
icon: 'none',
|
||
duration: 2000
|
||
})
|
||
}
|
||
})
|
||
}
|
||
|
||
})
|
||
|
||
},
|
||
btnclick_xiaoyin: function (e) {
|
||
var that = this;
|
||
wx.request({
|
||
url: 'https://www.mpecloud.com:8443/na/iocm/devNotify/v1.1.0/command/' + e.target.id +'?command=CJ',
|
||
header: { 'content-type': 'application/json' },
|
||
success: res => {
|
||
console.log(res.data.code)
|
||
if (res.data.code == 'Ok') {
|
||
wx.showToast({
|
||
title: '持续静音已成功!',
|
||
icon: 'none',
|
||
duration: 2000
|
||
})
|
||
}
|
||
else
|
||
{
|
||
wx.showToast({
|
||
title: '操作失败!',
|
||
icon: 'none',
|
||
duration: 2000
|
||
})
|
||
}
|
||
}, fail: function () {
|
||
wx.showToast({
|
||
title: '操作失败!',
|
||
icon: 'none',
|
||
duration: 2000
|
||
})
|
||
}
|
||
})
|
||
},
|
||
btnclick_chefang: function (e) {
|
||
var that = this;
|
||
wx.request({
|
||
url: 'https://www.mpecloud.com:8443/na/iocm/devNotify/v1.1.0/command/' + e.target.id + '?command=CF',
|
||
header: { 'content-type': 'application/json' },
|
||
success: res => {
|
||
if (res.data.code =='Ok')
|
||
{
|
||
wx.showToast({
|
||
title: '撤防已成功!',
|
||
icon: 'none',
|
||
duration: 2000
|
||
})
|
||
}
|
||
else {
|
||
wx.showToast({
|
||
title: '操作失败!',
|
||
icon: 'none',
|
||
duration: 2000
|
||
})
|
||
}
|
||
}, fail: function () {
|
||
wx.showToast({
|
||
title: '操作失败!',
|
||
icon: 'none',
|
||
duration: 2000
|
||
})
|
||
}
|
||
})
|
||
},
|
||
btnclick_cancelchefang: function (e) {
|
||
var that = this;
|
||
wx.request({
|
||
url: 'https://www.mpecloud.com:8443/na/iocm/devNotify/v1.1.0/command/' + e.target.id + '?command=BF',
|
||
header: { 'content-type': 'application/json' },
|
||
success: res => {
|
||
if (res.data.code == 'Ok') {
|
||
wx.showToast({
|
||
title: '取消撤防已成功!',
|
||
icon: 'none',
|
||
duration: 2000
|
||
})
|
||
}
|
||
else {
|
||
wx.showToast({
|
||
title: '操作失败!',
|
||
icon: 'none',
|
||
duration: 2000
|
||
})
|
||
}
|
||
}, fail: function () {
|
||
wx.showToast({
|
||
title: '操作失败!',
|
||
icon: 'none',
|
||
duration: 2000
|
||
})
|
||
}
|
||
})
|
||
}
|
||
}) |