city-casereport/pages/caseReport/caseReport.js

439 lines
9.2 KiB
JavaScript
Raw Normal View History

2021-03-20 10:59:52 +08:00
const app = getApp()
2023-12-07 09:31:56 +08:00
var bmap = require('../../lib/bmap-wx.js');
let wxMarkerData = [];
2021-03-20 10:59:52 +08:00
// pages/caseReport/caseReport.js
Page({
2023-12-07 09:31:56 +08:00
/**
* 页面的初始数据
*/
data: {
address: '获取案件地址中...',
recodePath: '',
recorderManager: wx.getRecorderManager(),
innerAudioContext: wx.createInnerAudioContext(),
//街道
streetPicker: false,
streetList: [],
streetKeys: {
label: 'dictName',
value: 'dictId'
},
selStreet: null,
//社区
communityPicker: false,
communityList: [],
communityKeys: {
label: 'communityName',
value: 'communityId'
},
selCommunity: null,
//类型
typePicker: false,
typeList: [],
typeKeys: {
label: 'dictName',
value: 'dictId'
},
selType: null,
//详细类型
type2Picker: false,
type2List: [],
type2Keys: {
label: 'dictName',
value: 'dictId'
},
selType2: null,
2021-03-20 10:59:52 +08:00
2023-12-07 09:31:56 +08:00
// 案件类型
photoList: [],
startTouch: {},
selfHandle: 0,
caseDesc: '',
imageList: [],
token: '',
scrollHeight: 0,
},
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
});
let screenHeight = wx.getSystemInfoSync().windowHeight;
this.setData({
scrollHeight: screenHeight
})
},
//街道选择
onShowStreetPick() {
this.setData({
streetPicker: true
})
},
onStreetPick(e) {
var _self = this;
var index = e.detail.columns[0].index;
_self.setData({
communityList: [],
selCommunity: null,
selStreet: _self.data.streetList[index]
})
_self.getCommunityList();
},
onStreetCancel(e) {
this.setData({
streetPicker: false,
})
},
//社区
onShowCommunitPicker() {
this.setData({
communityPicker: true,
})
},
onCommunityPick(e) {
var index = e.detail.columns[0].index;
var _self = this;
_self.setData({
selCommunity: _self.data.communityList[index]
})
},
onCommunityCancel(e) {
this.setData({
communityPicker: false
})
},
//类型选择
onShowType1() {
this.setData({
typePicker: true
})
},
onTypePick(e) {
var index = e.detail.columns[0].index;
var _self = this;
_self.setData({
selType: _self.data.typeList[index]
})
_self.getTypeLv();
},
onTypeCancel(e) {
this.setData({
typePicker: false
})
},
2021-03-20 10:59:52 +08:00
2023-12-07 09:31:56 +08:00
//详细类型
onShowType2() {
this.setData({
type2Picker: true
})
},
onType2Pick(e) {
var index = e.detail.columns[0].index;
var _self = this;
_self.setData({
selType2: _self.data.type2List[index]
})
},
onType2Cancel(e) {
this.setData({
typePicker: false
})
},
2021-03-20 10:59:52 +08:00
2023-12-07 09:31:56 +08:00
// 办事处列表
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) {
self.setData({
streetList: data,
selStreet: data[0]
})
self.getCommunityList()
});
},
2021-03-20 10:59:52 +08:00
2023-12-07 09:31:56 +08:00
// 社区列表
getCommunityList: function () {
var self = this
self.setData({
communityIndex: 0
})
app.restAjax.get(app.restAjax.path('{reqesutUrl}app/community/listareacommunity/' + self.data.selStreet.dictId, [app.requestUrl]), {}, {
headers: {
token: self.data.token
}
}, function (code, data) {
self.setData({
communityList: data,
selCommunity: data[0]
})
wx.hideToast()
});
},
2021-03-20 10:59:52 +08:00
2023-12-07 09:31:56 +08:00
// 类型列表
getTypeList: function () {
var self = this
app.restAjax.get(app.restAjax.path('{reqesutUrl}app/dict/listdict/46d108b2-4ef9-4f6f-b30c-0c700e3ee852', [app.requestUrl]), {}, {
headers: {
token: self.data.token
}
}, function (code, data) {
self.setData({
typeList: data,
selType: data[0]
})
self.getTypeLv()
});
},
2021-03-20 10:59:52 +08:00
2023-12-07 09:31:56 +08:00
// 类型二级
getTypeLv: function () {
var self = this
wx.showLoading({
title: '加载中...',
})
app.restAjax.get(app.restAjax.path('{reqesutUrl}app/dict/listdict/' + self.data.selType.dictId, [app.requestUrl]), {}, {
headers: {
token: self.data.token
}
}, function (code, data) {
self.setData({
type2List: data,
selType2: data[0]
})
wx.hideLoading()
}, (code, error) => {
wx.hideLoading()
});
},
//案件描述
inputCaseDesc(e) {
this.setData({
caseDesc: e.detail.value
})
},
// 案件类型列表
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
})
},
2021-03-20 10:59:52 +08:00
2023-12-07 09:31:56 +08:00
// 提交上报
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
}
2021-03-20 10:59:52 +08:00
2023-12-07 09:31:56 +08:00
var info = {
areaId: self.data.selStreet.dictId,
areaName: self.data.selStreet.dictName,
casePhotos: photos,
caseAudio: self.data.audioId,
communityId: self.data.selCommunity.communityId,
communityName: self.data.selCommunity.communityName,
caseSource: 1,
isSelf: self.data.selfHandle,
caseTypeId: self.data.selType2.dictId,
caseTypeName: self.data.selType2.dictName,
caseContent: self.data.caseDesc,
caseLatitude: self.data.latitude,
caseLongitude: self.data.longitude,
casePosition: self.data.address
}
wx.showLoading({
title: '上报中...',
})
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.hideLoading()
wx.showToast({
title: '上报成功',
duration: 1500
})
setTimeout(function () {
wx.navigateBack()
}, 1500)
}
}, function (code, data) {
wx.hideLoading()
wx.showToast({
title: data.msg,
duration: 2000
})
});
},
2021-03-20 10:59:52 +08:00
})