var Constant = require('../../utils/constant.js');
|
var app = getApp();
|
import Request from "../../utils/api"
|
Page({
|
data: {
|
formEntity: {
|
ProductResultStatus: 0,
|
ProductResultStatusName: "",
|
|
ImprovedFeedback: "",
|
ResultOperateNote: "",
|
ReplacePartInfo: "",
|
|
longitude: 0, //经纬度
|
latitude: 0,
|
userLocAddress: "", //定位的地址(可能不是报修地址)
|
|
imageList: [], //图片
|
taskformid: 0,
|
|
currentCorpID: 1,
|
currentEmployeeID: 1 //当前用户ID
|
},
|
imageList: [] //图片
|
},
|
|
onLoad: function (options) {
|
|
var that = this;
|
|
var userInfo = app.globalData.userInfo;
|
if (userInfo) {
|
this.setData({
|
taskformid: options.taskformid,
|
currentCorpID: userInfo.CorpID,
|
currentEmployeeID: userInfo.EmployeeID
|
});
|
} else {
|
wx.navigateTo({
|
url: '/login/login/index',
|
});
|
}
|
//
|
setTimeout(function () {
|
//获取当前经纬度
|
that.getCurrentLocation();
|
}, 1000);
|
|
|
},
|
|
|
|
|
//表单提交
|
formSubmit: function (e) {
|
var that = this;
|
var taskformid = that.data.taskformid;
|
if (that.data.longitude == 0 || that.data.latitude == 0) {
|
that.getCurrentLocation(); //获取当前经纬度
|
}
|
|
var formDetail = e.detail.value; //表单所有数据
|
|
// console.log("表单数据", formDetail, this.data.ProductResultStatus);
|
|
if (formDetail.ProductResultStatusName == null || formDetail.ProductResultStatusName == '') {
|
wx.showToast({
|
title: '提醒:请选处理方式',
|
icon: 'none'
|
})
|
return;
|
}
|
Request({
|
url: Constant.BASE_SERVER_URL + "Repair/Task/Form/Finish@V1.0",
|
method: 'POST',
|
data: {
|
ID: taskformid,
|
Note:that.data.ProductResultStatusName
|
},
|
header: {
|
'content-type': 'application/x-www-form-urlencoded'
|
},
|
success:res=>{
|
console.log(res.data,379);
|
var result = res.data;
|
|
if (result.Code != 0) {
|
wx.showModal({
|
title: '',
|
content: result.message,
|
});
|
return;
|
}
|
if(that.data.imageList.length==0){
|
that.submitSuccess(taskformid);
|
return
|
}
|
if(that.data.imageList.length>0){
|
that.uploadNextImageFile(taskformid,0);
|
return
|
}
|
},
|
fail:err=>{
|
console.log(err)
|
}
|
})
|
|
},
|
|
|
//迭代上传
|
uploadNextImageFile: function (taskformid,index_image) {
|
//console.log(taskFileId)
|
|
var that = this;
|
var image_count = this.data.imageList.length;
|
if (index_image >= image_count)
|
return;
|
var url_image = this.data.imageList[index_image];
|
let tokenInfo = wx.getStorageSync('AccessToken')
|
wx.uploadFile({
|
url: Constant.BASE_SERVER_URL + "Repair/Task/Form/UploadFile@V1.0",
|
filePath: url_image,
|
header:{'Authorization': 'Bearer ' + tokenInfo.Token},
|
formData: {
|
FormID : taskformid,
|
},
|
name: 'file',
|
success: function (res) { //上传完成
|
// console.log(JSON.parse(res.data),"完成工单")
|
|
wx.hideLoading();
|
|
that.submitSuccess(taskformid);
|
|
}
|
});
|
|
},
|
|
//
|
submitSuccess: function (taskFormId) {
|
wx.showToast({
|
title: "提交成功",
|
icon: 'none'
|
});
|
// wx.navigateBack({
|
// delta: 2
|
// });
|
|
var pages = getCurrentPages();
|
if (pages.length >= 3) {
|
//var currPage = pages[pages.length - 1]; //当前页面
|
var prevPage = pages[pages.length - 3]; //上上一个页面
|
//console.log(prevPage.route)
|
if (prevPage) {
|
var fn = prevPage.refreshRepairInfo;
|
if (typeof fn == "function")
|
fn(taskFormId, "finishWork");
|
wx.navigateBack({
|
delta: 2
|
});
|
} else {
|
wx.navigateBack({
|
delta: 2
|
});
|
}
|
} else {
|
wx.navigateBack({
|
delta: 2
|
});
|
}
|
|
//wx.navigateTo({
|
// url: '/repair/myReport/index'
|
//});
|
},
|
|
|
|
//维修结果下拉
|
tapSelProductResult() {
|
var that = this;
|
var ProductResultStatusName = '';
|
var ProductResultStatus = 0;
|
wx.showActionSheet({
|
itemList: ['维修成功', '无法维修保持现状', '无需维修', '设备报废', '其他状态'],
|
success(res) {
|
if (res.tapIndex == 0) {
|
ProductResultStatusName = "维修成功";
|
ProductResultStatus = 1;
|
} else if (res.tapIndex == 1) {
|
ProductResultStatusName = "无法维修保持现状";
|
ProductResultStatus = 2;
|
} else if (res.tapIndex == 2) {
|
ProductResultStatusName = "无需维修";
|
ProductResultStatus = 3;
|
} else if (res.tapIndex == 3) {
|
ProductResultStatusName = "设备报废";
|
ProductResultStatus = 9;
|
} else if (res.tapIndex == 4) {
|
ProductResultStatusName = "其他状态";
|
ProductResultStatus = 10;
|
} else {
|
return;
|
}
|
that.setData({
|
ProductResultStatusName: ProductResultStatusName,
|
ProductResultStatus: ProductResultStatus
|
})
|
},
|
fail(res) {
|
console.log(res.errMsg)
|
}
|
})
|
},
|
|
|
|
|
//加载定位
|
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'
|
});
|
//
|
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({
|
userLocAddress: result.data.result.address
|
})
|
|
}
|
});
|
}
|
});
|
},
|
|
|
|
|
|
//图片上传
|
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)
|
};
|
that.setData({
|
imageList: imageList
|
})
|
}
|
})
|
},
|
//查看图片
|
previewImage: function (e) {
|
var currentSrc = e.target.dataset.src
|
wx.previewImage({
|
current: currentSrc,
|
urls: this.data.imageList
|
})
|
},
|
//删除图片
|
deleteImage: function (e) {
|
var that = this;
|
var imageList = that.data.imageList;
|
var index = e.currentTarget.dataset.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;
|
}
|
|
}
|
});
|
},
|
|
onShow: function () {},
|
/**用户点击右上角分享*/
|
onShareAppMessage: function () {
|
return Constant.Share;
|
},
|
})
|