//获取应用实例
|
var Constant = require('../../utils/constant.js');
|
var utils = require('../../utils/util.js')
|
var app = getApp();
|
var CorpID = Constant.CorpID; //当前公司id
|
|
Page({
|
|
/**
|
* 页面的初始数据
|
*/
|
data: {
|
userInfo: null, //用户信息
|
isRotateRefreshIcon: false, //刷新图标的选择状态
|
addressInfo: "正在获取定位...", //巡检地址
|
userLocAddress: "", //定位的巡检地址(可能不是报修地址)
|
longitude: 0, //精度
|
latitude: 0, //纬度
|
tapTouchDirection: "", //手指滑动列表中的子项时计算的滑动距离
|
|
ToDay: utils.formatDay(new Date()), //显示的时间
|
allProductList: [], //存放巡检产品的列表
|
dispProductList: [], //存放巡检产品的列表
|
searchResult: false,
|
//
|
distanceText: "距离",
|
distanceFilter: { //距离筛选列表
|
distanceFilterOptions: [{ //距离筛选选项
|
value: "0",
|
text: "不限距离"
|
},
|
{
|
value: "100",
|
text: "100米"
|
}, {
|
value: "300",
|
text: "300米"
|
}, {
|
value: "500",
|
text: "500米"
|
}, {
|
value: "800",
|
text: "800米"
|
}, {
|
value: "1000",
|
text: "1000米"
|
}
|
],
|
distanceOptionsIndex: 0 //当前选择的距离选项下标
|
},
|
distanceFilterShowStatus: false, //距离筛选下拉框是否显示
|
distanceShowColorStatus: false, //距离筛选列表选项被选中后的颜色展示状态
|
isSelectDistance: true, //是否能点击距离筛选
|
bodyStyleName: "", //样式
|
|
inspectStatusText: "巡检状态",
|
inspectStatusFilter: { //巡检状态筛选列表
|
inspectStatusOptions: ["全部", "已巡检", "未巡检", "巡检中"], //巡检状态筛选选项
|
inspectStatusOptionsIndex: 0 //选择的巡检状态的下标
|
},
|
inspectStatusFilterShow: false, //巡检状态下拉框是否显示
|
inspectStatusShowColor: false, //巡检状态被选中后改变文字颜色
|
|
// type: 0,
|
productTypeShowColorStatus: false, //产品类型被选中后改变颜色状态
|
productTypeText: "类型",
|
productTypeShowStatus: false, //产品类型下拉框是否显示
|
productTypeIndex: 0, //产品类型被选择的下标
|
productTypeFilter: [{ //产品类型筛选列表及筛选选项
|
name: '全部类型',
|
value: '全部类型',
|
subType: 0
|
},
|
{
|
name: '流量计',
|
value: '流量计',
|
subType: 7501
|
},
|
{
|
name: '压力计',
|
value: '压力计',
|
subType: 7502
|
},
|
{
|
name: '水质仪',
|
value: '水质仪',
|
subType: 7504
|
},
|
{
|
name: '其他',
|
value: '其他',
|
subType: 7000
|
},
|
],
|
},
|
|
/**
|
* 生命周期函数--监听页面加载
|
*/
|
onLoad: function (options) {
|
var that = this
|
// console.log(options)
|
var userInfo = app.globalData.userInfo
|
if (userInfo == null) {
|
wx.redirectTo({
|
url: '/login/login/index',
|
})
|
return;
|
}
|
that.setData({
|
userInfo: userInfo
|
});
|
//console.log(userInfo)
|
wx.getSetting({ //判断用户有没有打开定位设置
|
success(res) {
|
// console.log(res.authSetting, '115')
|
if (res.authSetting["scope.userLocation"] != true) {
|
wx.showModal({
|
title: '提示',
|
content: '请您打开系统定位',
|
})
|
}
|
}
|
})
|
this.getCurrentLocation()
|
},
|
//初始化产品列表
|
initProductListData: function () {
|
var that = this
|
|
let userInfo = that.data.userInfo
|
let corpID = userInfo.CorpID //公司id
|
let employeeID = userInfo.EmployeeID //员工id
|
let PosiX = that.data.longitude //精度
|
let PosiY = that.data.latitude //纬度
|
wx.showLoading({
|
title: '数据加载中,请稍后...',
|
})
|
//console.log(corpID)
|
wx.request({
|
method: 'GET',
|
url: Constant.BASE_SERVER_URL + 'Repair/Mobile/InspectRecord/GetProductScheduleByToDay4Input',
|
data: {
|
CorpID: corpID,
|
EmployeeID: employeeID,
|
PosiX: PosiX,
|
PosiY: PosiY
|
},
|
success: res => {
|
wx.hideLoading()
|
//
|
let result = res.data
|
if (result.Code != 0) {
|
wx.showModal({
|
title: '提示',
|
content: '数据请求失败',
|
})
|
return;
|
}
|
wx.showToast({
|
title: '获取数据成功',
|
icon: 'success',
|
duration: 2000
|
})
|
//console.log(result, '产品列表')
|
|
let allProductList = []
|
for (let i = 0; i < result.Data.length; i++) {
|
let product = result.Data[i];
|
// console.log(product)
|
allProductList.push(product)
|
}
|
that.setData({
|
dispProductList: allProductList,
|
allProductList: allProductList
|
});
|
|
},
|
fail: err => {
|
wx.hideLoading({})
|
console.log(err)
|
}
|
})
|
},
|
//赋值选择位置进行 选择当前位置
|
tapChooseLocation() {
|
let that = this;
|
wx.chooseLocation({
|
success: function (res) {
|
//console.log("chooseLocation", res)
|
that.setData({
|
addressInfo: res.address.substring(3, res.address.length),
|
latitude: res.latitude,
|
longitude: res.longitude,
|
})
|
that.initProductListData()
|
}
|
});
|
},
|
|
//加载定位
|
getCurrentLocation: function () {
|
var that = this;
|
wx.getLocation({
|
type: 'gcj02', // 默认为 wgs84 返回 gps 坐标,gcj02 返回可用于 wx.openLocation 的坐标
|
success(resLoc) {
|
//console.log("getCurrentLocation", resLoc);
|
if (resLoc.longitude == 0 || resLoc.latitude == 0) { //当前位置信号较弱,请换个位置尝试
|
wx.showModal({
|
title: '提示',
|
content: '当前信号较弱请换个位置尝试',
|
success(res) {
|
if (res.confirm) {
|
return;
|
} else if (res.cancel) {
|
return;
|
}
|
}
|
})
|
}
|
//
|
that.setData({
|
longitude: resLoc.longitude,
|
latitude: resLoc.latitude,
|
})
|
|
//获取经纬度后,初始化产品列表
|
that.initProductListData()
|
|
//发送请求通过经纬度反查地址信息
|
var getAddressUrl = "https://apis.map.qq.com/ws/geocoder/v1/?location=" + resLoc.latitude + "," + resLoc.longitude + "&key=GFDBZ-D3NKX-LNL4Z-TSWGU-RYCE3-4HB3I";
|
wx.request({
|
url: getAddressUrl,
|
success: function (result) {
|
//console.log("getAddressUrl", result);
|
that.setData({
|
addressInfo: result.data.result.address,
|
userLocAddress: result.data.result.address
|
})
|
},
|
fail: err => {
|
wx.showModal({
|
title: '提示',
|
content: '获取位置失败请打开定位'
|
})
|
console.log(err)
|
}
|
});
|
},
|
fail: err => {
|
wx.showModal({
|
title: '提示',
|
content: '获取位置失败请打开定位,或者手动选择位置',
|
success(res) {
|
if (res.confirm) {
|
that.setData({
|
latitude: 0,
|
longitude: 0
|
})
|
that.initProductListData()
|
|
setTimeout(() => { //五秒之后调用位置接口
|
that.getCurrentLocation()
|
}, 5000);
|
} else if (res.cancel) {
|
console.log('用户点击取消')
|
return;
|
}
|
}
|
})
|
console.log(err)
|
}
|
|
});
|
},
|
|
|
//巡检距离筛选部分
|
distanceFilterShow: function () { //距离下拉
|
if (this.data.distanceFilterShowStatus) {
|
this.setData({
|
distanceFilterShowStatus: !this.data.distanceFilterShowStatus,
|
productTypeShowStatus: false,
|
inspectStatusFilterShow: false
|
})
|
} else {
|
this.setData({
|
distanceFilterShowStatus: !this.data.distanceFilterShowStatus,
|
productTypeShowStatus: false,
|
inspectStatusFilterShow: false
|
})
|
}
|
},
|
|
distanceOptionsChoice: function (e) { //距离下拉选择子项//
|
// console.log(e)
|
this.setData({
|
distanceText: e.currentTarget.dataset.item,
|
"distanceFilter.distanceOptionsIndex": e.currentTarget.dataset.index,
|
distanceFilterShowStatus: false,
|
distanceShowColorStatus: true,
|
distance: e.currentTarget.dataset.distance
|
})
|
},
|
inspectionStatusFilterShow: function () { //巡检状态筛选下拉
|
if (this.data.inspectStatusFilterShow) {
|
this.setData({
|
inspectStatusFilterShow: !this.data.inspectStatusFilterShow,
|
productTypeShowStatus: false,
|
distanceFilterShowStatus: false
|
})
|
} else {
|
this.setData({
|
inspectStatusFilterShow: !this.data.inspectStatusFilterShow,
|
productTypeShowStatus: false,
|
distanceFilterShowStatus: false
|
})
|
}
|
},
|
inspectionStatusOptionsChoice: function (e) { //巡检状态下拉选择子项
|
// console.log(e)
|
this.setData({
|
inspectStatusText: e.currentTarget.dataset.item,
|
"inspectStatusFilter.inspectStatusOptionsIndex": e.currentTarget.dataset.index,
|
inspectStatusFilterShow: false,
|
inspectStatusShowColor: true
|
})
|
},
|
|
productTypeFilterShow: function () { //类型下拉
|
if (this.data.productTypeShowStatus) {
|
this.setData({
|
productTypeShowStatus: !this.data.productTypeShowStatus,
|
inspectStatusFilterShow: false,
|
distanceFilterShowStatus: false,
|
})
|
} else {
|
this.setData({
|
productTypeShowStatus: !this.data.productTypeShowStatus,
|
inspectStatusFilterShow: false,
|
distanceFilterShowStatus: false,
|
|
})
|
}
|
},
|
productTypeOptionsChoice: function (e) { //类型下拉选项
|
this.setData({
|
subType: e.currentTarget.dataset.subType,
|
productTypeIndex: e.currentTarget.dataset.index,
|
productTypeText: e.currentTarget.dataset.typeName,
|
productTypeShowStatus: false,
|
productTypeShowColorStatus: true
|
})
|
},
|
|
handletouchtart: function (event) { //点击透明背景隐藏下拉
|
this.setData({
|
inspectStatusFilterShow: false,
|
distanceFilterShowStatus: false,
|
productTypeShowStatus: false
|
})
|
},
|
|
// 手部触摸开始
|
onTouchStart(e) {
|
this.setData({
|
ListTouchStart: e.touches[0].pageX,
|
})
|
// console.log(this.data.changeClick)
|
},
|
|
// 手指滑动过程计算方向
|
onTouchMove(e) {
|
this.setData({
|
tapTouchDirection: e.touches[0].pageX - this.data.ListTouchStart > -50 ? 'right' : 'left',
|
})
|
// console.log(this.data.changeClick)
|
},
|
|
// 手指滑动结束计算滚动
|
onTouchEnd(e) {
|
if (this.data.tapTouchDirection == 'left') {
|
this.setData({
|
bodyStyleName: e.currentTarget.dataset.target,
|
})
|
// console.log(this.data.changeClick)
|
} else {
|
this.setData({
|
bodyStyleName: ""
|
})
|
}
|
this.setData({
|
tapTouchDirection: null,
|
})
|
},
|
//跳转到巡检明细
|
gotoDetailPage: function (e) {
|
//
|
let productId = e.currentTarget.dataset.productId;
|
var product = this.getProductById(productId)
|
if (product == null)
|
return;
|
|
wx.navigateTo({
|
url: '../todayDetail/index?productId=' + productId + '&productName=' + product.ProductName + '&belongId=' + product.BelongID + '&belongType=' + product.BelongType,
|
})
|
},
|
//刷新对应id的泵的信息
|
getProductById: function (id) {
|
let allProductList = this.data.allProductList;
|
//console.log(id,allProductList);
|
for (let i = 0; i < allProductList.length; i++) {
|
const product = allProductList[i]
|
if (product.ProductID == id) {
|
return product;
|
}
|
}
|
return null;
|
},
|
//进入报修界面
|
tapOpenRepairReport: function (e) {
|
//console.log(e.target.dataset.productId);
|
var productId = e.target.dataset.productId;
|
wx.navigateTo({
|
url: "../../repair/addReport/index?ProductId=" + productId
|
})
|
},
|
//根据巡检内容页面传过来的值刷新产品列表的数据
|
refreshReordData: function (record) {
|
var that = this;
|
if (record == null)
|
return;
|
// console.log(record)
|
// console.log(that.data.allProductList)
|
let allProductList = that.data.allProductList
|
for (let i = 0; i < allProductList.length; i++) {
|
const product = allProductList[i]
|
if (product.RecordID == record.ID || product.ProductID == record.ProductID) {
|
product.RecordID == record.ID;
|
product.ProgressInfo = record.ProgressInfo;
|
product.WorryCount = record.WorryCount;
|
product.CompleteStatus = record.CompleteStatus;
|
}
|
}
|
|
let dispProductList = that.data.dispProductList
|
for (let i = 0; i < dispProductList.length; i++) {
|
const product = dispProductList[i]
|
if (product.RecordID == record.ID || product.ProductID == record.ProductID) {
|
product.RecordID == record.ID;
|
product.ProgressInfo = record.ProgressInfo;
|
product.WorryCount = record.WorryCount;
|
product.CompleteStatus = record.CompleteStatus;
|
}
|
}
|
// console.log(allProductList, dispProductList)
|
|
that.setData({
|
allProductList: allProductList,
|
dispProductList: dispProductList
|
})
|
},
|
//刷新设备列表
|
refreshProductList: function () {
|
var that = this
|
that.setData({
|
isRotateRefreshIcon: true
|
})
|
that.initProductListData()
|
setTimeout(function () {
|
that.setData({
|
isRotateRefreshIcon: false
|
})
|
}, 1000)
|
},
|
/**
|
* 生命周期函数--监听页面初次渲染完成
|
*/
|
onReady: function () {
|
|
},
|
|
/**
|
* 生命周期函数--监听页面显示
|
*/
|
onShow: function () {},
|
|
/**
|
* 生命周期函数--监听页面隐藏
|
*/
|
onHide: function () {
|
|
},
|
|
/**
|
* 生命周期函数--监听页面卸载
|
*/
|
onUnload: function () {
|
|
},
|
|
/**
|
* 页面相关事件处理函数--监听用户下拉动作
|
*/
|
onPullDownRefresh: function () {
|
|
},
|
|
/**
|
* 页面上拉触底事件的处理函数
|
*/
|
onReachBottom: function () {
|
|
},
|
|
/**
|
* 用户点击右上角分享
|
*/
|
onShareAppMessage: function () {
|
return Constant.Share;
|
}
|
})
|