// repair/abnormal/index.js
|
var Constant = require('../../utils/constant.js');
|
var app = getApp();
|
var userInfo = app.globalData.userInfo; //登陆用户的相关信息
|
var CorpID = 0; //登陆用户的公司id
|
var EmployeeID = 0; //登录用户的员工id
|
var TaskID = null;
|
var PointInfo = {};//异常地址坐标
|
Page({
|
|
/**
|
* 页面的初始数据
|
*/
|
data: {
|
showViewPageName: "main", //控制报修窗口显示和隐藏
|
imageList: [], //图片
|
|
longitude: 0, //经纬度
|
latitude: 0,
|
userLocAddress: "", //定位的地址(可能不是报修地址)
|
|
currentCorpID: 1,
|
currentUserID: 1, //当前用户ID
|
},
|
|
/**
|
* 生命周期函数--监听页面加载
|
*/
|
onLoad: function (options) {
|
console.log(options.TaskID);
|
TaskID = options.TaskID
|
|
var that = this;
|
var userInfo = app.globalData.userInfo;
|
if (userInfo) {
|
this.setData({
|
currentCorpID: userInfo.CorpID,
|
currentUserID: userInfo.EmployeeID
|
});
|
}
|
else{
|
return;
|
}
|
var CorpID = userInfo.CorpID; //登陆用户的公司id
|
var EmployeeID = userInfo.EmployeeID; //登录用户的员工id
|
|
setTimeout(function () {
|
//获取当前经纬度
|
that.getCurrentLocation();
|
}, 1000);
|
},
|
//表单提交
|
formSubmitCb: function (e) {
|
this.setData({
|
formNote: e.detail.value.Note
|
});
|
console.log('打印输入的备注的值', this.data.formNote);
|
|
if (this.data.longitude == 0 || this.data.latitude == 0) {
|
this.getCurrentLocation(); //获取当前经纬度
|
}
|
var that = this;
|
wx.showModal({
|
title: '提醒',
|
content: '请问是否提交?',
|
confirmColor: '#007aff',
|
cancelColor: '#007aff',
|
confirmText: '是',
|
cancelText: '否',
|
success: function (resDlg) {
|
if (resDlg.confirm) {
|
that.formSubmit();
|
} else if (resDlg.cancel) {
|
//wx.showToast({ title: '点击了 否', icon: 'none' });
|
}
|
}
|
});
|
},
|
//提交
|
formSubmit: function () {
|
var that = this;
|
wx.request({
|
url: "https://api.beng35.com/Inspect/SiteTask/SubmitTaskProblem_Picture",
|
method: 'POST',
|
data: {
|
CorpID: CorpID,
|
TaskID: TaskID,
|
PointInfo: PointInfo,
|
Description: that.data.formNote
|
},
|
header: {
|
'content-type': 'application/json'
|
},
|
fail: function (err) {
|
// wx.showModal({
|
// title: '',
|
// content: '通讯失败',
|
// })
|
}, //请求失败
|
complete: function () {}, //请求完成后执行的函数
|
success: function (res) {
|
console.log('提交成功');
|
|
console.log(res.data)
|
var result = res.data;
|
if (result.Code != 0) {
|
wx.showModal({
|
title: '',
|
content: result.Message
|
});
|
return;
|
}
|
|
var formId = res.data.Data;
|
if (formId <= 0) {
|
wx.showModal({
|
title: '',
|
content: "error 236"
|
});
|
return;
|
}
|
//console.log(formId)
|
|
// if (imageList.length > 0) { //上传图片
|
// wx.showLoading({
|
// title: '上传中...',
|
// mask: true
|
// });
|
// // 上传图片的方法 that.uploadNextImageFile(formId, 0);
|
// } else {
|
// that.submitSuccess(formId);
|
// return;
|
// }
|
}
|
});
|
},
|
//重置
|
formResetCb: function (e) {
|
//console.log('form发生了reset事件,携带数据为:', e.detail.value)
|
//this.setData({
|
// chosen: ''
|
//})
|
},
|
//赋值选择位置进行 选择当前位置
|
tapChooseLocation() {
|
let that = this;
|
wx.chooseLocation({
|
success: function (res) {
|
//console.log("chooseLocation",res)
|
that.setData({
|
addressInfo: res.address
|
})
|
}
|
});
|
},
|
isShowFilterProductComb() {
|
var that = this;
|
that.setData({
|
isShowFilterProductComb: false
|
})
|
},
|
//图片上传
|
chooseImage: function () {
|
var that = this;
|
var imageList = this.data.imageList;
|
wx.chooseImage({
|
sizeType: ['original', 'compressed'],
|
sourceType: ['album', 'camera'],
|
count: 9, //最多
|
success: function (res) {
|
var imgPaths = res.tempFilePaths;
|
for (var i = 0; i < imgPaths.length; i++) {
|
var imgPath = res.tempFilePaths[i];
|
imageList.push(imgPath)
|
};
|
//console.log(imageList, 55)
|
that.setData({
|
imageList: imageList
|
})
|
}
|
})
|
},
|
//查看图片
|
previewImage: function (e) {
|
// console.log(this.data.imageList,e.target.dataset.src)
|
var currentSrc = e.target.dataset.src
|
wx.previewImage({
|
current: currentSrc,
|
urls: this.data.imageList
|
})
|
console.log(currentSrc, this.data.imageList, "ywg")
|
},
|
//删除图片
|
deleteImage: function (e) {
|
var that = this;
|
var imageList = that.data.imageList;
|
var index = e.currentTarget.dataset.index; //获取当前长按图片下标
|
// console.log(imageList, index)
|
wx.showModal({
|
title: '系统提醒',
|
content: '确定要删除此图片吗?',
|
success: function (res) {
|
if (res.confirm) {
|
imageList.splice(index, 1);
|
} else if (res.cancel) {
|
return false;
|
}
|
that.setData({
|
imageList: imageList
|
});
|
}
|
})
|
},
|
//一键清空图片
|
onImageDel() {
|
var that = this;
|
wx.showModal({
|
title: '系统提醒',
|
content: '确定要删除全部图片吗?',
|
success: function (res) {
|
if (res.confirm) {
|
that.setData({
|
imageList: []
|
});
|
} else if (res.cancel) {
|
return false;
|
}
|
|
}
|
});
|
},
|
//迭代上传图片
|
uploadNextImageFile: function (formId, index_image) {
|
var that = this;
|
var image_count = this.data.imageList.length;
|
if (index_image >= image_count)
|
return;
|
var url_image = this.data.imageList[index_image];
|
|
wx.uploadFile({
|
url: Constant.BASE_SERVER_URL + "Repair/Service/RequestFileHandler.ashx?cmd=AddImageFile4MiniPro",
|
filePath: url_image,
|
formData: {
|
FormID: formId,
|
DispName: index_image
|
},
|
name: 'file',
|
success: function (res) {
|
//console.log(res.data)
|
if (index_image < image_count - 1) {
|
index_image++;
|
that.uploadNextImageFile(formId, index_image); //迭代下一张
|
return;
|
}
|
wx.hideLoading();
|
that.submitSuccess(formId);
|
}
|
});
|
},
|
//重置
|
onReset: function () {
|
// wx.showModal({
|
// title: '提醒',
|
// content: '返回上一页数据将被清空,确定返回吗?',
|
// confirmColor: '#007aff',
|
// cancelColor: '#007aff',
|
// confirmText: '是',
|
// cancelText: '否',
|
// success: function (res) {
|
// if (res.confirm) {
|
// wx.showToast({ title: '点击了 是', icon: 'none' });
|
// // wx.redirectTo({url: '/Report/report_form/report_form',})//指定界面
|
// } else if (res.cancel) {
|
// wx.showToast({ title: '点击了 否', icon: 'none' });
|
// }
|
// }
|
// })
|
|
this.setData({
|
urgencyLevel: 0
|
})
|
},
|
//加载定位
|
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) { //当前位置信号较弱,请换个位置尝试
|
return;
|
}
|
|
wx.showToast({
|
title: '成功获取当前位置',
|
icon: 'none'
|
});
|
var point= {
|
X:resLoc.latitude,
|
Y:resLoc.longitude
|
}
|
PointInfo = point //获取异常经纬度坐标
|
console.log('PointInfo',PointInfo);
|
|
//
|
that.setData({
|
longitude: resLoc.longitude,
|
latitude: resLoc.latitude,
|
})
|
//发送请求通过经纬度反查地址信息
|
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
|
})
|
|
}
|
});
|
}
|
});
|
},
|
/**
|
* 生命周期函数--监听页面初次渲染完成
|
*/
|
onReady: function () {
|
|
},
|
|
/**
|
* 生命周期函数--监听页面显示
|
*/
|
onShow: function () {
|
|
},
|
|
/**
|
* 生命周期函数--监听页面隐藏
|
*/
|
onHide: function () {
|
|
},
|
|
/**
|
* 生命周期函数--监听页面卸载
|
*/
|
onUnload: function () {
|
|
},
|
|
/**
|
* 页面相关事件处理函数--监听用户下拉动作
|
*/
|
onPullDownRefresh: function () {
|
|
},
|
|
/**
|
* 页面上拉触底事件的处理函数
|
*/
|
onReachBottom: function () {
|
|
},
|
|
/**
|
* 用户点击右上角分享
|
*/
|
onShareAppMessage: function () {
|
return Constant.Share;
|
},
|
})
|