// pages/problemList/problemList.js
|
import { CheckEdit, GetQuList, Delete, TOperation } from '../../utils/network'
|
Page({
|
|
/**
|
* 页面的初始数据
|
*/
|
data: {
|
showPage: false,
|
showNull: false,
|
roleKey: wx.getStorageSync('roleKey'),
|
nextlevel: 0,
|
showTabs: false,
|
erectoListLevel: [],
|
state: 0,
|
listdata: [],
|
active1: 0,
|
active2: 0,
|
active3: 0,
|
isadmin: true,
|
bohui: true,
|
show: false,
|
text: '',
|
itemId: '',
|
modalHidden: true,
|
delModal: true,
|
// currentIndex:1,
|
// totalPage:0,
|
index: 1,
|
total: 10,
|
pageMask: false,
|
prevBtnDis: true,
|
nextBtnDis: false,
|
properties: {
|
currentIndex: { //当前页码
|
type: Number,
|
value: 1
|
},
|
totalPage: {
|
type: Number
|
}
|
},
|
form: {
|
},
|
nickName:'',
|
|
},
|
lifetimes: {
|
// 在组件实例进入页面节点树时执行
|
attached: function () {
|
this.setData({
|
index: this.properties.currentIndex,
|
total: this.properties.totalPage
|
})
|
}
|
},
|
|
// 详情展示
|
toxiangqin(e) {
|
console.log(e.target.dataset.id)
|
var id = e.target.dataset.id
|
wx.navigateTo({
|
url: '/pages/xiangqing/xiangqing?id=' + id,
|
})
|
},
|
/**
|
* 生命周期函数--监听页面加载
|
*/
|
onLoad: function (options) {
|
|
|
},
|
// 设置异步请求之后的页面、总记录数
|
setPage(index, total) {
|
this.setData({
|
index,
|
total
|
})
|
},
|
|
//每次改变页码就调用该函数
|
triggerParent: function () {
|
|
// 通知父组件当前加载的页数
|
|
// 自定义组件向父组件传值
|
const option = {
|
currentIndex: this.data.index
|
};
|
|
// pagingChange 自定义名称事件,父组件中使用
|
this.triggerEvent('pagingChange', option)
|
|
},
|
//开启页码弹窗
|
showPagePopUp: function () {
|
this.setData({
|
pageMask: true
|
})
|
},
|
//关闭页码弹窗
|
hidePagePopUp: function () {
|
this.setData({
|
pageMask: false
|
})
|
},
|
//更改页码点击事件
|
onChangePage: function (e) {
|
//console.log("更改页码事件:",e);
|
this.setData({
|
pageMask: false,
|
index: e.currentTarget.dataset.index //点击的页数
|
})
|
this.getList()
|
// 先判断当前页数,是否需要更新disabled的状态
|
this.updateBtnDis();
|
this.triggerParent();
|
},
|
//上一页点击事件
|
prevPage: function () {
|
if (this.data.index <= 1) return;
|
let num = this.data.index - 1;
|
this.setData({
|
index: num
|
})
|
this.getList()
|
this.triggerParent();
|
更新按钮状态
|
this.updateBtnDis();
|
},
|
//下一页点击事件
|
nextPage: function () {
|
if (this.data.index >= this.data.total) return;
|
let num = this.data.index + 1;
|
this.setData({
|
index: num
|
})
|
this.getList()
|
this.triggerParent();
|
|
// 更新按钮状态
|
this.updateBtnDis();
|
},
|
changeActive1(e) {
|
console.log(e.detail.index);
|
this.setData({
|
state: e.detail.index,
|
active1: e.detail.index,
|
nickName:wx.getStorageSync('nickName')
|
})
|
this.getList()
|
},
|
changeActive2(e) {
|
console.log(e.detail.index);
|
this.setData({
|
active2: e.detail.index,
|
nextlevel: this.data.erectoListLevel[0].userId
|
})
|
this.getList()
|
},
|
changeActive3(e) {
|
console.log(e.detail.index);
|
this.setData({
|
active3: e.detail.index,
|
nextlevel: this.data.erectoListLevel[e.detail.index].userId
|
})
|
this.getList()
|
},
|
getList() {
|
wx.showLoading({
|
title: '加载中',
|
})
|
this.setData({
|
tableData: []
|
})
|
var erectoId = wx.getStorageSync("erectoId")
|
var roleKey = wx.getStorageSync('roleKey')
|
let data = {
|
pageNum: this.data.index,
|
pageSize: 10,
|
state: this.data.state,
|
orderType: 1,
|
}
|
if (roleKey == 'tenantservice') {
|
data.createUserId = 0
|
data.erectoId = erectoId
|
}
|
if (roleKey == 'admin') {
|
data.createUserId = 0;
|
data.erectoId = 0;
|
}
|
if (roleKey == 'tenant' || roleKey == 'tenanthelper') {
|
data.createUserId = erectoId;
|
data.erectoId = 0;
|
}
|
if (this.data.active2 == 1) { //当选择下级时\
|
data.createUserId = this.data.nextlevel
|
}
|
// console.log(data);
|
wx.request({
|
url: 'https://puyue.yhupai.com/prod-api/iot/deviceOrder/list',
|
method: "GET",
|
header: {
|
"Access-Control-Allow-Headers": 'token',
|
Authorization: `Bearer ${wx.getStorageSync('token')}`
|
},
|
data: data,
|
success: (res, header) => {
|
if (res.data.code == 200 && res.data.rows.length > 0) {
|
|
let data = res.data
|
let total = Math.ceil(res.data.total / 10)
|
this.setData({
|
listdata: data.rows,
|
total: total,
|
showPage: true,
|
showNull: false
|
})
|
console.log(this.data.listdata)
|
wx.hideLoading()
|
|
} else {
|
this.setData({
|
listdata: [],
|
total: 0,
|
showPage: false,
|
showNull: true
|
})
|
wx.hideLoading()
|
}
|
}
|
})
|
},
|
getErectoListLevel() {
|
this.setData({
|
erectoListLevel: []
|
})
|
let data = {
|
pageNum: 1,
|
pageSize: 10000,
|
deptId: wx.getStorageSync('deptId'),
|
roleKey: 'tenanthelper',
|
}
|
console.log(data);
|
wx.request({
|
url: 'https://puyue.yhupai.com/prod-api/system/user/list',
|
method: "GET",
|
header: {
|
"Access-Control-Allow-Headers": 'token',
|
Authorization: `Bearer ${wx.getStorageSync('token')}`
|
},
|
params: data,
|
success: (res, header) => {
|
if (res.data.code == 200 || res.data.rows.length > 0) {
|
let data = res.data.rows
|
this.setData({
|
nextlevel: data[0].userId,
|
erectoListLevel: data,
|
showTabs: true
|
})
|
} else {
|
this.setData({
|
showTabs: false
|
})
|
}
|
}
|
})
|
},
|
/**
|
* 生命周期函数--监听页面初次渲染完成
|
*/
|
onReady: function () {
|
},
|
|
/**
|
* 生命周期函数--监听页面显示
|
*/
|
onShow: function () {
|
// wx.showLoading({
|
// title: '加载中',
|
// })
|
this.setData({
|
nickName:wx.getStorageSync('nickName')
|
})
|
this.getErectoListLevel()
|
this.getList()
|
},
|
edit(e) {
|
console.log(e);
|
var item = e.currentTarget.dataset.base
|
wx.navigateTo({
|
url: '/pages/problemReport/proRep?info=' + JSON.stringify(item),
|
})
|
},
|
statements(e) {
|
console.log(e);
|
let item = JSON.parse(JSON.stringify(e.currentTarget.dataset.base))
|
console.log(item);
|
item.state = 3
|
console.log(item);
|
wx.navigateTo({
|
url: '/pages/problemReport/proRep?info=' + JSON.stringify(item),
|
})
|
},
|
goAddress(e) {
|
var address = e.currentTarget.dataset.base.address
|
console.log(e.currentTarget.dataset);
|
wx.request({
|
url: 'https://apis.map.qq.com/ws/geocoder/v1/',
|
data: {
|
address: address,
|
key: 'SRGBZ-FLCKU-2TIVH-BFHUM-D5CTO-LFBHQ'
|
},
|
success: function (res) {
|
console.log(res.data.result.location); // 打印出经纬度
|
let params = res.data.result.location
|
params.name = e.currentTarget.dataset.base.userName
|
params.address = e.currentTarget.dataset.base.address
|
console.log(params);
|
wx.navigateTo({
|
url: '/pages/devicelogs/devicelogs?address=' + JSON.stringify(params),
|
})
|
|
}
|
});
|
},
|
jd(e) {
|
var item = e.currentTarget.dataset.base
|
this.setData({
|
modalHidden: false,
|
form: item
|
})
|
},
|
getreceiveTime() {
|
let date = new Date();
|
let year = date.getFullYear();
|
let month = date.getMonth() + 1;
|
let day = date.getDate();
|
let hour = date.getHours();
|
let minute = date.getMinutes();
|
let second = date.getSeconds();
|
|
return `${year}-${month < 10 ? '0' + month : month}-${day < 10 ? '0' + day : day} ${hour < 10 ? '0' + hour : hour}:${minute < 10 ? '0' + minute : minute}:${second < 10 ? '0' + second : second}`;
|
|
|
},
|
modalChange() {
|
this.data.form.state = 2
|
let data = this.data.form
|
data.id = this.data.form.id
|
data.receiveTime=this.getreceiveTime()
|
// console.log(this.data.form);
|
// return
|
// data.receiveTime=this.getreceiveTime()
|
wx.request({
|
url: 'https://puyue.yhupai.com/prod-api/iot/deviceOrder',
|
method: "PUT",
|
header: {
|
"Access-Control-Allow-Headers": 'token',
|
Authorization: `Bearer ${wx.getStorageSync('token')}`
|
},
|
data: data,
|
success: (res, header) => {
|
if (res.data.code == 200) {
|
this.setData({
|
index: 1,
|
modalHidden: true
|
})
|
this.getList()
|
} else {
|
this.setData({
|
index: 1,
|
modalHidden: true
|
})
|
this.getList()
|
}
|
}
|
})
|
|
|
},
|
modalCancel() {
|
this.setData({
|
modalHidden: true
|
})
|
},
|
delAZ(e) {
|
console.log(e);
|
var item = e.currentTarget.dataset.base
|
this.setData({
|
delModal: false,
|
form: item
|
})
|
|
},
|
DelChange() {
|
wx.request({
|
url: `https://puyue.yhupai.com/prod-api/iot/deviceOrder/${this.data.form.id}`,
|
method: "DELETE",
|
header: {
|
"Access-Control-Allow-Headers": 'token',
|
Authorization: `Bearer ${wx.getStorageSync('token')}`
|
},
|
success: (res, header) => {
|
if (res.data.code == 200) {
|
this.setData({
|
index: 1,
|
delModal: true
|
})
|
this.getList()
|
} else {
|
this.setData({
|
index: 1,
|
delModal: true
|
})
|
this.getList()
|
}
|
}
|
})
|
},
|
DelCancel() {
|
this.setData({
|
delModal: true
|
})
|
},
|
|
/**
|
* 生命周期函数--监听页面隐藏
|
*/
|
onHide: function () {
|
|
},
|
|
/**
|
* 生命周期函数--监听页面卸载
|
*/
|
onUnload: function () {
|
wx.switchTab({
|
url: '/pages/home/home',
|
})
|
},
|
|
/**
|
* 页面相关事件处理函数--监听用户下拉动作
|
*/
|
onPullDownRefresh: function () {
|
|
},
|
|
/**
|
* 页面上拉触底事件的处理函数
|
*/
|
onReachBottom: function () {
|
|
},
|
|
/**
|
* 用户点击右上角分享
|
*/
|
onShareAppMessage: function () {
|
|
}
|
})
|