syshxcx/pages/report/report.js
dong_bo0602 a1f9e23f6d 0607
2022-06-07 15:43:05 +08:00

634 lines
16 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// pages/caseReport/caseReport.js
const app = getApp()
var bmap = require('../../utils/bmap-wx.min.js');
var util = require('../../utils/WSCoordinate.js')
var wxMarkerData = [];
Page({
/**
* 页面的初始数据
*/
data: {
sourceUrl: app.baseUrls.sourceUrl,
// 事件类型
typeAll: [],
typeArray: [],
typeIdx: 0,
typeSelected: '',
typeSelectedCode: '',
typeSelectedName: '',
// 事件类型二级
type2All: [],
type2Array: ['请选择上级类型'],
type2Idx: 0,
type2Selected: '',
type2SelectedName: '',
// 区县
areaAll: [],
areaArray: [],
areaIdx: 0,
areaSelected: '',
areaSelectedName: '',
// 乡镇
villageAll: [],
villageArray: [],
villageIdx: 0,
villageSelected: '',
villageSelectedName: '',
// 委员会
committeeAll: [],
committeeArray: [],
committeeIdx: 0,
committeeSelected: '',
committeeSelectedName: '',
recodePath: '',
recorderManager: wx.getRecorderManager(),
baseImgUrl: app.baseUrls.baseImgUrl,
caseUrl: app.baseUrls.caseUrl,
imageList: [],
videoId: '',
audioId: '',
latitude: '',
longitude: '',
reportAddress: '',
reportContent: '',
reportInfo: {
bGId: "",
casePartsObjId: "123",
casePartsObjName: "123",
caseTypeCode1: "",
caseTypeCode2: "",
caseTypeName1: "",
caseTypeName2: "",
reportAddress: "",
reportAreaCod: "",
reportAreaName: "例如北京市 / xx区 / xx街道 / xx",
reportAudio: "",
reportContent: "",
reportLat: "",
reportLng: "",
reportPhotos: "",
reportVideo: ""
},
isLoading: false
},
// 获取区县
getArea: function () {
var self = this
app.restAjax.get(app.restAjax.path(app.apis.getArea, [app.baseUrls.caseUrl, '110889']), {}, {
headers: {
token: app.globalData.token
}
}, function (code, data) {
var arr = ['请选择区县']
for (let i = 0; i < data.length; i++) {
arr.push(data[i].areaName)
}
self.setData({
areaAll: data,
areaArray: arr
})
// self.getVillage()
}, function (code, data) {
console.log(data)
})
},
// 获取乡镇
getVillage: function () {
var self = this
app.restAjax.get(app.restAjax.path(app.apis.getChildArea, [app.baseUrls.caseUrl, self.data.areaSelected]), {}, {
headers: {
token: app.globalData.token
}
}, function (code, data) {
var arr = ['请选择乡镇']
for (let i = 0; i < data.length; i++) {
arr.push(data[i].areaName)
}
self.setData({
villageAll: data,
villageArray: arr
})
// self.getCommittee()
}, function (code, data) {
console.log(data)
})
},
// 获取委员会
getCommittee: function () {
var self = this
app.restAjax.get(app.restAjax.path(app.apis.getChildArea, [app.baseUrls.caseUrl, self.data.villageSelected]), {}, {
headers: {
token: app.globalData.token
}
}, function (code, data) {
var arr = ['请选择委员会']
for (let i = 0; i < data.length; i++) {
arr.push(data[i].areaName)
}
self.setData({
committeeAll: data,
committeeArray: arr
})
}, function (code, data) {
console.log(data)
})
},
// 获取事件类型
getCaseType: function () {
var self = this
app.restAjax.get(app.restAjax.path(app.apis.caseType, [app.baseUrls.caseUrl]), {}, {
headers: {
token: app.globalData.token
}
}, function (code, data) {
var arr = ['请选择事件类型']
for (let i = 0; i < data.length; i++) {
arr.push(data[i].name)
}
self.setData({
typeAll: data,
typeArray: arr
})
}, function (code, data) {
console.log(data)
})
},
// 获取事件类型子级
getCaseTypeChild: function () {
var self = this
app.restAjax.get(app.restAjax.path(app.apis.caseTypeChild + '/' + self.data.typeSelected, [app.baseUrls.caseUrl]), {}, {
headers: {
token: app.globalData.token
}
}, function (code, data) {
var arr = ['请选择事件类型']
for (let i = 0; i < data.length; i++) {
arr.push(data[i].typeName)
}
self.setData({
type2All: data,
type2Array: arr
})
}, function (code, data) {
console.log(data)
})
},
// 选择事件类型
bindPickerChange: function (e) {
var self = this
if (e.detail.value != 0) {
this.setData({
typeIdx: e.detail.value,
typeSelected: self.data.typeAll[e.detail.value - 1].id,
typeSelectedCode: self.data.typeAll[e.detail.value - 1].code,
typeSelectedName: self.data.typeAll[e.detail.value - 1].name
})
self.getCaseTypeChild()
} else {
this.setData({
typeIdx: 0,
typeSelected: '',
type2Array: []
})
}
},
// 选择事件类型子级
bindCaseTypeChange: function (e) {
var self = this
if (e.detail.value != 0) {
this.setData({
type2Idx: e.detail.value,
type2Selected: self.data.type2All[e.detail.value - 1].typeCode,
type2SelectedName: self.data.type2All[e.detail.value - 1].typeName
})
} else {
this.setData({
type2Idx: 0,
type2Selected: ''
})
}
},
// 选择区县
bindAreaPickerChange: function (e) {
var self = this
if (e.detail.value != 0) {
this.setData({
areaIdx: e.detail.value,
areaSelected: self.data.areaAll[e.detail.value - 1].areaCode,
areaSelectedName: self.data.areaAll[e.detail.value - 1].areaName
})
this.getVillage()
} else {
this.setData({
areaIdx: 0,
areaSelected: '',
villageArray: [],
committeeArray: []
})
}
},
// 选择乡镇
bindVillagePickerChange: function (e) {
var self = this
if (e.detail.value != 0) {
this.setData({
villageIdx: e.detail.value,
villageSelected: self.data.villageAll[e.detail.value - 1].areaId,
villageSelectedName: self.data.villageAll[e.detail.value - 1].areaName
})
this.getCommittee()
} else {
this.setData({
villageIdx: 0,
villageSelected: '',
committeeArray: []
})
}
},
// 选择委员会
bindCommitteePickerChange: function (e) {
var self = this
if (e.detail.value != 0) {
this.setData({
committeeIdx: e.detail.value,
committeeSelected: self.data.committeeAll[e.detail.value - 1].areaId,
committeeSelectedName: self.data.committeeAll[e.detail.value - 1].areaName
})
} else {
this.setData({
committeeIdx: 0,
committeeSelected: ''
})
}
},
// 录音
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
wx.showToast({
title: '上传中',
icon: 'loading'
})
app.restAjax.file(app.restAjax.path(app.apis.uploadAudio, [app.baseUrls.caseUrl]), path, 'audio', {
headers: {
token: app.globalData.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.caseUrl + this.data.baseImgUrl + this.data.audioId
innerAudioContext.play()
},
// 登录
doLogin: function () {
var self = this;
wx.login({
success(res) {
app.restAjax.post(app.restAjax.path(app.apis.login, [app.baseUrls.loginUrl]), {
jsCode: res.code
}, null, function (code, data) {
console.log(data)
}, function (code, data) {
app.dialog.msg(data.msg);
});
}
})
},
// 上传图片
uploadImage: function () {
var self = this
if (!self.data.isLoading) {
self.setData({
isLoading: true
})
wx.chooseImage({
count: 9 - self.data.imageList.length,
sourceType: ['album', 'camera'],
success: function (res) {
wx.showToast({
title: '上传中',
icon: 'loading'
})
for (let i = 0; i < res.tempFiles.length; i++) {
var path = res.tempFiles[i].path;
app.restAjax.file(app.restAjax.path(app.apis.uploadImg, [app.baseUrls.caseUrl]), path, 'image', {
headers: {
token: app.globalData.token
}
}, function (code, data) {
if (code == '200') {
self.setData({
isLoading: false
})
var id = JSON.parse(data).data
var arr = self.data.imageList
arr.push(id)
self.setData({
imageList: arr
})
wx.hideToast()
}
}, function (code, data) {
console.log(data)
self.setData({
isLoading: false
})
})
}
}
})
}
},
// 上传视频
uploadVideo: function () {
var self = this
if (!self.data.isLoading) {
self.setData({
isLoading: true
})
wx.chooseVideo({
sourceType: ['album','camera'],
maxDuration: 60,
camera: 'back',
success: function (res) {
wx.showToast({
title: '上传中',
icon: 'loading'
})
var path = res.tempFilePath
app.restAjax.file(app.restAjax.path(app.apis.uploadVideo, [app.baseUrls.caseUrl]), path, 'video', {
headers: {
token: app.globalData.token
}
}, function (code, data) {
if (code == '200') {
var id = JSON.parse(data).data
self.setData({
videoId: id,
isLoading: false
})
wx.hideToast()
}
}, function (code, data) {
console.log(data)
self.setData({
isLoading: false
})
})
}
})
}
},
// 选择坐标
chooseLocation: function () {
var self = this
wx.chooseLocation({
success: function (res) {
console.log(res)
var result = util.transformFromGCJToWGS(res.latitude, res.longitude);
console.log(result)
self.setData({
longitude: result.longitude,
latitude: result.latitude
})
}
})
},
editInfo: function (e) {
var type = e.currentTarget.dataset.type
if (type == 'location') {
this.setData({
reportAddress: e.detail.value
})
} else {
this.setData({
reportContent: e.detail.value
})
}
},
// 提交上报
submitReport: function () {
var self = this
if (!self.data.isLoading) {
if (!this.data.typeSelected) {
wx.showToast({
title: '请选择事件类型',
icon: 'error'
})
return
}
if (!this.data.type2Selected) {
wx.showToast({
title: '请选择事件类型',
icon: 'error'
})
return
}
// if (!this.data.areaSelected) {
// wx.showToast({
// title: '请选择区县',
// icon: 'error'
// })
// return
// }
if (!this.data.reportAddress) {
wx.showToast({
title: '请输入事发位置',
icon: 'error'
})
return
}
if (!this.data.longitude && !this.data.latitude) {
wx.showToast({
title: '请选择事发坐标',
icon: 'error'
})
return
}
if (!this.data.reportContent) {
wx.showToast({
title: '请输入事件说明',
icon: 'error'
})
return
}
var areaName = '内蒙古自治区 / 乌兰察布市 / ' + wx.getStorageSync('curCommunityName')
// if (self.data.villageIdx != 0) {
// areaName += ' / ' + self.data.villageSelectedName
// }
// if (self.data.committeeIdx != 0) {
// areaName += ' / ' + self.data.committeeSelectedName
// }
var photo
for (let i = 0; i < self.data.imageList.length; i++) {
if (i == 0) {
photo = self.data.imageList[i]
} else {
photo += ',' + self.data.imageList[i]
}
}
var area = wx.getStorageSync('areaCode')
// if (self.data.committeeAll.length > 0 && self.data.committeeIdx != 0) {
// area = self.data.committeeSelected
// } else if (self.data.villageAll.length > 0 && self.data.villageIdx != 0) {
// area = self.data.villageSelected
// } else {
// area = self.data.areaSelected
// }
var info = {
bGId: "",
casePartsObjId: "",
casePartsObjName: "",
caseTypeCode1: self.data.typeSelectedCode,
caseTypeCode2: self.data.type2Selected,
caseTypeName1: self.data.typeSelectedName,
caseTypeName2: self.data.type2SelectedName,
reportAddress: self.data.reportAddress,
reportAreaCode: area,
isSelf: '0',
reportAreaName: areaName,
reportAudio: self.data.audioId,
reportContent: self.data.reportContent,
reportLat: self.data.latitude,
reportLng: self.data.longitude,
reportPhotos: photo,
reportVideo: self.data.videoId,
gridMiniId: wx.getStorageSync('gridMiniId')
}
self.setData({
isLoading: true
})
app.restAjax.post(app.restAjax.path(app.apis.submitReport, [app.baseUrls.requestUrl]), info, {
headers: {
token: 'cVJWWXQ1UWpQWTQ1TDZMbEVtTmxiMlJVNkdvTzUwSTNHYzZaK3VTZmF0RXNITnQ3RXUxZ2F6eVU4dGpZWjFqWm5Pc0Fqd2l6MzAvMlZSckZaTkZITFZmVXk4YVNWVVErcEJ5SGZzVFRGeGFEenBMaDhZU0FFc1hnZ2RGc2hLUWZvMTJtWHRkcENmWThROTZFL2d5WDJxc0RBY2RzUkUzUzIyNlBmblFhUGdPZWdFY3JOeU5mME5veEk1aVU4a1hNMFNlaW1BemFwRjhRbXVRUUt1MTlObEViSTlhMUVoSEJDZ2ZFVTFYZlJNNGFoMTVOTXgyYytBdE96SUVmWmpYRQ=='
}
}, function (code, data) {
if (code == '200') {
wx.showToast({
title: '上报成功',
icon: 'success'
})
setTimeout(function () {
self.setData({
isLoading: false
})
wx.navigateBack({
delta: 1,
})
}, 1500)
}
}, function (code, data) {
console.log(data)
self.setData({
isLoading: false
})
})
}
},
// 删除附件
deleteSource: function (e) {
var self = this
var type = e.currentTarget.dataset.type
if (type == 'video') {
self.setData({
videoId: ''
})
} else {
var cur = e.currentTarget.dataset.cur
self.data.imageList.splice(cur, 1)
self.setData({
imageList: self.data.imageList
})
}
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
// this.doLogin()
this.getCaseType()
this.getArea()
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
}
})