锦水居民端小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

433 lines
12 KiB

const QQMapWX = require("../../utils/qqmap-wx-jssdk")
import { $wuxActionSheet } from "../../../../dist/index"
const config = require("../../../../utils/config")
import { addIssue, getEventTagList, getEventtagWorkuser } from "../../utils/api"
Page({
data: {
issueContent: "",
addressContent: "",
latitude: "",
longitude: "",
qqMapWX: "",
uploadImageList: [],
imageId: 1,
dialogVisible: false,
publishIssuePrevious: 0,
focus: false,
isBlock: true,
violationsCount: 0,
isConReview: false,
tagIds: [],
checkboxs: [],
lock: false, //锁定发布状态,防止连击
showDialog: false,
boxTitle: '', // checkbox 对话框标题
leaderList: [],
pageIndex: 1,
pageSize: 10,
loadMoreType: "none",
workuserId: '', // 选中工作人员id
workUserIds: [], // 选中工作人员id集合
},
onLoad () {
this.getEventTagList()
this.data.qqMapWX = new QQMapWX({
key: "CMJBZ-4DECI-JXGGN-5B4WU-QLV2H-B5BEJ"
})
this.getLocation().then(() => {
this.reverseLocation()
})
},
// 双向绑定 内容输入框
bindTextareaInput (e) {
this.setData({
issueContent: e.detail.value.trim(' ')
})
},
// 双向绑定 地址输入框
bindAddressInput (e) {
this.setData({ //失去焦点以后view隐藏
isBlock: true
})
this.setData({
addressContent: e.detail.value.trim('')
})
},
//
getEventtagWorkuser () {
let param = {
pageIndex: this.data.pageIndex,
pageSize: this.data.pageSize,
eventTagId: this.data.workuserId
}
getEventtagWorkuser(param).then(res => {
let leaderList = [ ...this.data.leaderList, ...res.data ]
this.setData({
leaderList,
loadMoreType: res.data.length === 10 ? "loading" : "none"
})
if (this.data.leaderList.length > 0 && !this.data.showDialog) {
this.setData({
showDialog: true
})
}
}).catch(err => {
this.setData({
leaderList: [],
loadMoreType: "none"
})
console.log(err)
})
},
//获取事件标签列表
getEventTagList () {
getEventTagList().then(res => {
console.log(res.data)
for (let i=0; i<res.data.length; i++) {
this.data.checkboxs.push({
id: res.data[i].id,
name: res.data[i].tagName,
checked: false
})
}
this.setData({
checkboxs: this.data.checkboxs
})
})
},
// 获取经纬度
getLocation () {
return new Promise((resolve, reject) => {
const _this = this
wx.getLocation({
success (res) {
if (res.latitude && res.longitude) {
_this.setData({
latitude: res.latitude,
longitude: res.longitude
})
resolve(true)
}
},
fail (err) {
reject(err)
}
})
})
},
// 逆地址解析
reverseLocation () {
const _this = this
this.data.qqMapWX.reverseGeocoder({
location: {
latitude: _this.data.latitude,
longitude: _this.data.longitude
},
success (res) {
_this.setData({
addressContent: res.result.address
})
},
fail (err) {
console.debug(err)
}
})
},
// 选择图片 上传弹窗 - 上传图片方式 - 选择图片 - 上传图片 - 回调赋值
chooseImage () {
const _this = this
$wuxActionSheet().showSheet({
buttons: [
{ text: "拍照" },
{ text: "从相册中获取" },
],
className: "dialog-class",
buttonClicked (index) {
if (index === 0) {
wx.chooseImage({
count: 1,
sizeType: ["original", "compressed"],
sourceType: ["camera"],
success (res) {
const uploadImageList = [..._this.data.uploadImageList]
uploadImageList.push({
uploaded: false,
ossUrl: "",
imgUrl: res.tempFilePaths[0],
imageId: ++_this.data.imageId
})
_this.setData({
uploadImageList
})
wx.uploadFile({
url: `${config.BASEURL()}group/topic/upload`,
filePath: res.tempFilePaths[0],
name: "file",
header: {
"Content-type": "multipart/form-data"
},
success (fileRes){
uploadImageList[uploadImageList.length - 1].uploaded = true
uploadImageList[uploadImageList.length - 1].ossUrl = JSON.parse(fileRes.data).data
_this.setData({
uploadImageList
})
}
})
}
})
} else if (index === 1) {
wx.chooseImage({
count: 3 - _this.data.uploadImageList.length,
sizeType: ["original", "compressed"],
sourceType: ["album"],
success (res) {
const uploadImageList = []
const endIndex = _this.data.uploadImageList.length
res.tempFilePaths.forEach(item => {
uploadImageList.push({
uploaded: false,
ossUrl: "",
imgUrl: item,
imageId: ++_this.data.imageId
})
})
_this.setData({
uploadImageList: [..._this.data.uploadImageList,...uploadImageList]
})
uploadImageList.forEach((item, index) => {
return (function (index) {
wx.uploadFile({
url: `${config.BASEURL()}group/topic/upload`,
filePath: res.tempFilePaths[index],
name: "file",
header: {
"Content-type": "multipart/form-data"
},
success (fileRes){
uploadImageList[index].uploaded = true
uploadImageList[index].ossUrl = JSON.parse(fileRes.data).data
_this.data.uploadImageList = _this.data.uploadImageList.slice(0, endIndex)
_this.setData({
uploadImageList: [..._this.data.uploadImageList, ...uploadImageList]
})
}
})
})(index)
})
}
})
}
return true
},
cancelText: "取消",
cancel () {},
destructiveButtonClicked () {},
})
},
// 删除选中的图片
deleteImage (e) {
const index = this.data.uploadImageList.findIndex(item => item.imageId === e.currentTarget.dataset.imageid)
if (index > -1) {
this.data.uploadImageList.splice(index, 1)
this.setData({
uploadImageList: this.data.uploadImageList
})
}
},
throttlePublisgIssue () {
let now = new Date()
if (now - this.data.publishIssuePrevious > 2000) {
console.log(1)
this.publishIssue()
this.data.publishIssuePrevious = now
}
},
// 发布议题
publishIssue () {
if (!this.data.issueContent) {
wx.showToast({
title: "请填写议题内容",
icon: "none",
duration: 1500
})
return false
} else if (!this.data.addressContent) {
wx.showToast({
title: "请填写地址",
icon: "none",
duration: 1500
})
return false
}
const imagesList = []
if (this.data.uploadImageList.length > 0) {
const isUploadDown = this.data.uploadImageList.some(item => !item.uploaded)
if (isUploadDown) {
wx.showToast({
title: "请等待图片上传完成",
icon: "none",
duration: 1000
})
return false
}
}
if (this.data.uploadImageList.length > 0) {
this.data.uploadImageList.forEach(item => {
imagesList.push(item.ossUrl)
})
}
const para = {
eventContent: this.data.issueContent,
issueAddress: this.data.addressContent,
issueLongitude: this.data.longitude,
issueLatitude: this.data.latitude,
images: imagesList,
isConReview: this.data.isConReview,
tagIds: this.data.tagIds,
workUserIds: this.data.workUserIds
}
this.setData({
lock: true
})
wx.showLoading({
title: "加载中..."
})
let that = this
addIssue(para).then(res => {
wx.hideLoading()
this.setData({
lock: false
})
console.log("发布议题", res)
if (res.code == 0) {
this.setData({
dialogVisible: !this.data.dialogVisible,
violationsCount: 0,
isConReview: false
})
} else if (res.code == 533) {
this.data.violationsCount++
if (this.data.violationsCount == 1){
wx.showToast({
title: res.msg,
icon: "none",
duration: 2000
})
} else if (this.data.violationsCount == 2) {
wx.showModal({
title: '提示',
content: '您提交的内容再次被判定为违规,您确定是否要提交?',
success (res) {
if (res.confirm) {
console.log('用户点击确定')
that.data.isConReview = true
that.publishIssue()
} else if (res.cancel) {
console.log('用户点击取消')
that.setData({
violationsCount: 0,
isConReview: false
})
}
}
})
}
}
}).catch(err => {
this.setData({
lock: false
})
wx.showToast({
title: err,
icon: "none",
duration: 1500
})
})
},
// 知道了 确认按钮
confirmDialog () {
// wx.redirectTo({
// url: '/pages/discussion/discussion'
// })
wx.navigateBack({
delta: 1
})
},
// Textarea获取焦点
clickTextarea () {
this.setData({
isBlock: false,
focus: true
})
},
checkboxClick (e) {
this.data.tagIds = [] //当前版本标签单选
this.data.workUserIds = []
if (this.data.checkboxs[e.currentTarget.dataset.index].checked) {
this.data.checkboxs[e.currentTarget.dataset.index].checked = false
} else {
for(let i=0;i<this.data.checkboxs.length;i++) {
this.data.checkboxs[i].checked = false
}
this.data.checkboxs[e.currentTarget.dataset.index].checked = true
this.data.tagIds = [] //当前版本标签单选
this.data.tagIds.push(this.data.checkboxs[e.currentTarget.dataset.index].id)
this.setData({
boxTitle: e.currentTarget.dataset.title,
workuserId: this.data.tagIds[0]
}, () => {
this.getEventtagWorkuser()
})
}
this.setData({
checkboxs: this.data.checkboxs
})
// console.log(this.data.tagIds)
},
// 关闭对话框
closeCheckboxDialog () {
this.setData({
showDialog: false,
leaderList: [],
loadMoreType: "none",
pageIndex: 1
})
},
//
confirmCheckboxDialog () {
let list = []
this.data.leaderList.forEach(item => {
if (item.checked) {
list.push(item.id)
}
})
this.setData({
showDialog: false,
leaderList: [],
loadMoreType: "none",
pageIndex: 1,
workUserIds: [ ...list ]
})
},
checkboxChange (e) {
let item = this.data.leaderList[e.currentTarget.dataset.index]
item.checked = !item.checked
this.setData({
leaderList: this.data.leaderList
})
},
dialogReachBottom () {
if (this.data.loadMoreType === "loading") {
this.setData({
pageIndex: this.data.pageIndex + 1
})
this.getEventtagWorkuser()
}
}
})