472 lines
12 KiB
JavaScript
472 lines
12 KiB
JavaScript
const app = getApp()
|
||
var bmap = require('../../lib/bmap-wx.js');
|
||
let wxMarkerData = [];
|
||
// pages/caseReport/caseReport.js
|
||
Page({
|
||
|
||
/**
|
||
* 页面的初始数据
|
||
*/
|
||
data: {
|
||
address: '获取案件地址中...',
|
||
recodePath: '',
|
||
recorderManager: wx.getRecorderManager(),
|
||
innerAudioContext: wx.createInnerAudioContext(),
|
||
// 办事处
|
||
officeIndex: 0,
|
||
officeArray: [],
|
||
officeList: [],
|
||
officeSelectedId: '',
|
||
// 社区
|
||
communityIndex: 0,
|
||
communityArray: [],
|
||
communityList: [],
|
||
communitySelectedId: '',
|
||
// 类型
|
||
typeIndex: 0,
|
||
typeArray: [],
|
||
typeList: [],
|
||
typeSelectedId: '',
|
||
// 类型二级
|
||
typeLvIndex: 0,
|
||
typeLvArray: [],
|
||
typeLvList: [],
|
||
typeLvSelectedId: '',
|
||
// 案件类型
|
||
caseIndex: 0,
|
||
caseArray: [],
|
||
caseList: [],
|
||
caseSelectedId: '',
|
||
photoList: [],
|
||
startTouch: {},
|
||
selfHandle: 0,
|
||
caseDesc: '',
|
||
imageList: [],
|
||
token: ''
|
||
},
|
||
// 办事处列表
|
||
getOfficeList: function () {
|
||
var self = this
|
||
app.restAjax.get(app.restAjax.path('{reqesutUrl}app/dict/listdict/9d179f05-3ea0-48f7-853c-d3b7124b791c', [app.requestUrl]), {}, {
|
||
headers: {
|
||
token: self.data.token
|
||
}
|
||
}, function (code, data) {
|
||
var arr = []
|
||
for (let i = 0 ; i < data.length; i++) {
|
||
arr.push(data[i].dictName)
|
||
}
|
||
self.setData({
|
||
officeArray: arr,
|
||
officeList: data,
|
||
officeSelectedId: data[0].dictId
|
||
})
|
||
self.getCommunityList()
|
||
});
|
||
},
|
||
// 办事处选中
|
||
bindPickerChange: function (e) {
|
||
var self = this
|
||
this.setData({
|
||
officeIndex: e.detail.value,
|
||
officeSelectedId: self.data.officeList[e.detail.value].dictId
|
||
})
|
||
wx.showToast({
|
||
title: '加载中',
|
||
icon: 'loading'
|
||
})
|
||
this.getCommunityList()
|
||
},
|
||
// 社区列表
|
||
getCommunityList: function () {
|
||
var self = this
|
||
self.setData({
|
||
communityIndex: 0
|
||
})
|
||
app.restAjax.get(app.restAjax.path('{reqesutUrl}app/community/listareacommunity/' + self.data.officeSelectedId, [app.requestUrl]), {}, {
|
||
headers: {
|
||
token: self.data.token
|
||
}
|
||
}, function (code, data) {
|
||
var arr = []
|
||
for (let i = 0 ; i < data.length; i++) {
|
||
arr.push(data[i].communityName)
|
||
}
|
||
self.setData({
|
||
communityArray: arr,
|
||
communityList: data,
|
||
communitySelectedId: data[0].communityId
|
||
})
|
||
wx.hideToast()
|
||
});
|
||
},
|
||
// 选中社区
|
||
bindCommunityChange: function (e) {
|
||
var self = this
|
||
this.setData({
|
||
communityIndex: e.detail.value,
|
||
communitySelectedId: self.data.communityList[e.detail.value].communityId
|
||
})
|
||
},
|
||
// 类型列表
|
||
getTypeList: function () {
|
||
var self = this
|
||
app.restAjax.get(app.restAjax.path('{reqesutUrl}app/dict/listdict/46d108b2-4ef9-4f6f-b30c-0c700e3ee852' + self.data.officeSelectedId, [app.requestUrl]), {}, {
|
||
headers: {
|
||
token: self.data.token
|
||
}
|
||
}, function (code, data) {
|
||
var arr = []
|
||
for (let i = 0 ; i < data.length; i++) {
|
||
arr.push(data[i].dictName)
|
||
}
|
||
self.setData({
|
||
typeArray: arr,
|
||
typeList: data,
|
||
typeSelectedId: data[0].dictId
|
||
})
|
||
self.getTypeLv()
|
||
});
|
||
},
|
||
// 类型选中
|
||
bindTypeChange: function (e) {
|
||
var self = this
|
||
this.setData({
|
||
typeIndex: e.detail.value,
|
||
typeSelectedId: self.data.typeList[e.detail.value].dictId
|
||
})
|
||
self.getTypeLv()
|
||
},
|
||
// 类型二级
|
||
getTypeLv: function () {
|
||
var self = this
|
||
self.setData({
|
||
typeLvIndex: 0
|
||
})
|
||
wx.showToast({
|
||
title: '加载中',
|
||
icon: 'loading'
|
||
})
|
||
app.restAjax.get(app.restAjax.path('{reqesutUrl}app/dict/listdict/' + self.data.typeSelectedId, [app.requestUrl]), {}, {
|
||
headers: {
|
||
token: self.data.token
|
||
}
|
||
}, function (code, data) {
|
||
var arr = []
|
||
for (let i = 0 ; i < data.length; i++) {
|
||
arr.push(data[i].dictName)
|
||
}
|
||
self.setData({
|
||
typeLvArray: arr,
|
||
typeLvList: data,
|
||
typeLvSelectedId: data[0].dictId
|
||
})
|
||
wx.hideToast()
|
||
});
|
||
},
|
||
// 类型二级选中
|
||
bindTypeLvChange: function (e) {
|
||
var self = this
|
||
this.setData({
|
||
typeLvIndex: e.detail.value,
|
||
typeLvSelectedId: self.data.typeLvList[e.detail.value].dictId
|
||
})
|
||
self.getTypeLv()
|
||
},
|
||
// 案件类型列表
|
||
getCaseList: function () {
|
||
var self = this
|
||
app.restAjax.get(app.restAjax.path('{reqesutUrl}app/dict/listdict/46d108b2-4ef9-4f6f-b30c-0c700e3ee852' + self.data.officeSelectedId, [app.requestUrl]), {}, {
|
||
headers: {
|
||
token: self.data.token
|
||
}
|
||
}, function (code, data) {
|
||
var arr = []
|
||
for (let i = 0 ; i < data.length; i++) {
|
||
arr.push(data[i].dictName)
|
||
}
|
||
self.setData({
|
||
typeArray: arr,
|
||
typeList: data,
|
||
typeSelectedId: data[0].dictId
|
||
})
|
||
self.getTypeLv()
|
||
});
|
||
},
|
||
// 录音
|
||
recordVoice: function (e) {
|
||
this.setData({
|
||
startTouch: e.touches[0]
|
||
})
|
||
var options = {
|
||
format: 'mp3'
|
||
}
|
||
this.data.recorderManager.start(options)
|
||
wx.showToast({
|
||
title: "正在录音",
|
||
icon: "none",
|
||
duration: 60000//先定义个60秒,后面可以手动调用wx.hideToast()隐藏
|
||
});
|
||
},
|
||
// 录音结束
|
||
recordEnd: function () {
|
||
var self = this
|
||
this.data.recorderManager.stop()
|
||
this.data.recorderManager.onStop(function (res) {
|
||
var path = res.tempFilePath
|
||
self.setData({
|
||
recodePath: path
|
||
})
|
||
wx.showToast({
|
||
title: '上传中',
|
||
icon: 'loading'
|
||
})
|
||
app.restAjax.file(app.restAjax.path('{requestUrl}app/file/uploadaudio', [app.requestUrl]), path, 'audio', {
|
||
headers: {
|
||
token: self.data.token
|
||
}
|
||
}, function (code, data) {
|
||
var id = JSON.parse(data).data
|
||
self.setData({
|
||
audioId: id
|
||
})
|
||
wx.hideToast()
|
||
}, function (code, data) {
|
||
console.log(data)
|
||
})
|
||
})
|
||
var self = this
|
||
wx.hideToast()
|
||
},
|
||
// 播放录音
|
||
playRecord: function () {
|
||
var innerAudioContext = wx.createInnerAudioContext()
|
||
innerAudioContext.src = this.data.recodePath
|
||
innerAudioContext.play()
|
||
},
|
||
// 选择图片
|
||
chooseImage: function () {
|
||
var self = this
|
||
wx.chooseImage({
|
||
count: 9 - self.data.photoList.length,
|
||
sourceType: ['album', 'camera'],
|
||
success: function (res) {
|
||
self.setData({
|
||
photoList: 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({
|
||
imageList: 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.imageList.splice(idx, 1)
|
||
self.setData({
|
||
photoList: self.data.photoList,
|
||
imageList: self.data.imageList
|
||
})
|
||
},
|
||
// touchMove: function (e) {
|
||
// var moveLenght = e.touches[e.touches.length - 1].clientY - this.data.startTouch.clientY;
|
||
// if (Math.abs(moveLenght) > 50) {
|
||
// wx.showToast({
|
||
// title: "松开手指,取消发送",
|
||
// icon: "none",
|
||
// duration: 60000
|
||
// });
|
||
// } else {
|
||
// wx.showToast({
|
||
// title: "正在录音,上划取消发送",
|
||
// icon: "none",
|
||
// duration: 60000
|
||
// });
|
||
// }
|
||
// },
|
||
/**
|
||
* 生命周期函数--监听页面加载
|
||
*/
|
||
// 是否自行处理
|
||
isSelfHandle: function (e) {
|
||
this.setData({
|
||
selfHandle: e.detail.value
|
||
})
|
||
},
|
||
// 提交上报
|
||
submitReport: function () {
|
||
var self = this
|
||
var photos = ''
|
||
if (!self.data.caseDesc) {
|
||
wx.showToast({
|
||
title: '案件内容不能为空',
|
||
icon: 'none',
|
||
duration: 2000
|
||
})
|
||
return
|
||
}
|
||
if (self.data.imageList.length != 'undefined' && self.data.imageList.length != 0) {
|
||
for (let i = 0; i < self.data.imageList.length; i++) {
|
||
if (i == self.data.imageList.length - 1) {
|
||
photos += self.data.imageList[i]
|
||
} else {
|
||
photos += self.data.imageList[i] + ','
|
||
}
|
||
}
|
||
} else {
|
||
wx.showToast({
|
||
title: '请至少上传一张照片',
|
||
icon: 'none',
|
||
duration: 2000
|
||
})
|
||
return
|
||
}
|
||
|
||
var info = {
|
||
areaId: self.data.officeSelectedId,
|
||
areaName: self.data.officeArray[self.data.officeIndex],
|
||
casePhotos: photos,
|
||
caseAudio: self.data.audioId,
|
||
communityId: self.data.communitySelectedId,
|
||
communityName: self.data.communityArray[self.data.communityIndex],
|
||
caseSource: 1,
|
||
isSelf: self.data.selfHandle,
|
||
caseTypeId: self.data.typeLvSelectedId,
|
||
caseTypeName: self.data.typeLvArray[self.data.typeLvIndex],
|
||
caseContent: self.data.caseDesc,
|
||
caseLatitude: self.data.latitude,
|
||
caseLongitude: self.data.longitude,
|
||
casePosition: self.data.address
|
||
}
|
||
wx.showToast({
|
||
title: '上传中',
|
||
icon: 'loading'
|
||
})
|
||
app.restAjax.post(app.restAjax.path('{reqesutUrl}app/reportcase/saveappautoreportcase', [app.requestUrl]), info, {
|
||
headers: {
|
||
token: self.data.token
|
||
}
|
||
}, function (code, data) {
|
||
if (code == '200') {
|
||
wx.hideToast()
|
||
wx.showToast({
|
||
title: '上报成功',
|
||
duration: 1500
|
||
})
|
||
setTimeout(function () {
|
||
wx.navigateTo({
|
||
url: '../index/index',
|
||
})
|
||
}, 1500)
|
||
}
|
||
}, function (code, data) {
|
||
wx.showToast({
|
||
title: data.msg,
|
||
duration: 2000
|
||
})
|
||
});
|
||
},
|
||
onLoad: function (options) {
|
||
var self = this
|
||
wx.getStorage({
|
||
key: 'token',
|
||
success: function (res) {
|
||
self.setData({
|
||
token: res.data
|
||
})
|
||
self.getOfficeList()
|
||
self.getTypeList()
|
||
}
|
||
})
|
||
var BMap = new bmap.BMapWX({
|
||
ak: 'Zk732rbyjd327q7Zj9EOtRjUn2ED1GWK'
|
||
});
|
||
var success = function (data) {
|
||
self.setData({
|
||
address: data.wxMarkerData[0].address,
|
||
latitude: data.wxMarkerData[0].latitude,
|
||
longitude: data.wxMarkerData[0].longitude
|
||
})
|
||
}
|
||
var fail = function (data) {
|
||
console.log(data);
|
||
}
|
||
BMap.regeocoding({
|
||
fail:fail,
|
||
success:success
|
||
});
|
||
},
|
||
|
||
/**
|
||
* 生命周期函数--监听页面初次渲染完成
|
||
*/
|
||
onReady: function () {
|
||
|
||
},
|
||
|
||
/**
|
||
* 生命周期函数--监听页面显示
|
||
*/
|
||
onShow: function () {
|
||
|
||
},
|
||
|
||
/**
|
||
* 生命周期函数--监听页面隐藏
|
||
*/
|
||
onHide: function () {
|
||
|
||
},
|
||
|
||
/**
|
||
* 生命周期函数--监听页面卸载
|
||
*/
|
||
onUnload: function () {
|
||
|
||
},
|
||
|
||
/**
|
||
* 页面相关事件处理函数--监听用户下拉动作
|
||
*/
|
||
onPullDownRefresh: function () {
|
||
|
||
},
|
||
|
||
/**
|
||
* 页面上拉触底事件的处理函数
|
||
*/
|
||
onReachBottom: function () {
|
||
|
||
},
|
||
|
||
/**
|
||
* 用户点击右上角分享
|
||
*/
|
||
onShareAppMessage: function () {
|
||
|
||
}
|
||
}) |