city-casereport/pages/caseCheck/caseCheck.js
2021-03-20 10:59:52 +08:00

228 lines
5.2 KiB
JavaScript

// pages/caseCheck/caseCheck.js
var bmap = require('../../lib/bmap-wx.js');
var app = getApp()
Page({
/**
* 页面的初始数据
*/
data: {
caseId: '',
longitude: '111.759608',
latitude: '40.860318',
markers: [],
caseDetail: {},
token: wx.getStorageSync('token'),
requestUrl: app.requestUrl,
evaluateContent: '',
isPass: 1,
grade: '',
photoList: []
},
getDetail: function () {
var self = this
app.restAjax.get(app.restAjax.path('{reqesutUrl}app/reportcase/getreportcase/' + self.data.caseId, [app.requestUrl]), {}, {
headers: {
token: self.data.token
}
}, function (code, data) {
console.log(data)
var imgArr, handleArr
imgArr = data.casePhotos.split(',')
handleArr = data.handlePhotos.split(',')
var arr = [{longitude: data.caseLongitude,latitude: data.caseLatitude,iconPath:'../../images/marker_red.png',width:'25px',height: '30px'}]
self.setData({
markers: arr
});
self.setData({
caseDetail: data,
longitude: data.caseLongitude,
latitude: data.caseLatitude,
imageList: imgArr,
handleList: handleArr
})
});
},
isQualified: function (e) {
this.setData({
isPass: e.detail.value
})
},
isSatisfied: function (e) {
this.setData({
grade: e.detail.value
})
},
// 选择图片
chooseImage: function () {
var self = this
wx.chooseImage({
count: 9 - self.data.photoList.length,
sourceType: ['album', 'camera'],
success: function (res) {
console.log(res)
self.setData({
showPhotoList: self.data.photoList.concat(res.tempFiles)
})
wx.showToast({
title: '上传中',
icon: 'loading'
})
var arr = []
for (let i = 0; i < res.tempFiles.length; i++) {
var path = res.tempFiles[i].path;
app.restAjax.file(app.restAjax.path('{requestUrl}app/file/uploadimage', [app.requestUrl]), path, 'image', {
headers: {
token: self.data.token
}
}, function (code, data) {
var id = JSON.parse(data).data
arr.push(id)
if (arr.length == res.tempFiles.length) {
self.setData({
photoList: arr
})
wx.hideToast()
}
}, function (code, data) {
console.log(data)
})
}
}
})
},
// 删除图片
deleteImg: function (e) {
var idx = e.currentTarget.dataset.num
var self = this
self.data.photoList.splice(idx, 1)
self.data.showPhotoList.splice(idx, 1)
self.setData({
showPhotoList: self.data.showPhotoList,
photoList: self.data.photoList
})
},
// 确认处理
submitHandle: function () {
var photo = '', self = this
if (!self.data.evaluateContent) {
wx.showToast({
title: '请输入评价内容',
duration: 2000,
icon: 'none'
})
return
}
if (!self.data.grade) {
wx.showToast({
title: '请选择满意度',
duration: 2000,
icon: 'none'
})
return
}
if (this.data.photoList.length == 0) {
wx.showToast({
title: '请至少上传一张照片',
duration: 2000,
icon: 'none'
})
return
}
for (let i = 0; i < this.data.photoList.length; i++) {
if (i == this.data.photoList.length - 1) {
photo += this.data.photoList[i]
} else {
photo += this.data.photoList[i] + ','
}
console.log(i, photo)
}
var info = {
inspectPhotos: photo,
inspectOpinion: self.data.evaluateContent,
isPass: self.data.isPass,
grade: self.data.grade
}
app.restAjax.post(app.restAjax.path('{reqesutUrl}app/reportcase/savereportcaseinspect/' + self.data.caseId, [app.requestUrl]), info, {
headers: {
token: self.data.token
}
}, function (code, data) {
if (code == '200') {
wx.showToast({
title: '处理成功',
duration: 2000,
success: function () {
setTimeout(function () {
wx.navigateTo({
url: '../index/index',
})
}, 2000)
}
})
}
});
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
this.setData({
caseId: options.id
})
this.getDetail()
var BMap = new bmap.BMapWX({
ak: 'Zk732rbyjd327q7Zj9EOtRjUn2ED1GWK'
});
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
}
})