锦水居民端小程序
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.

363 lines
10 KiB

import { $wuxActionSheet } from "../../../../dist/index"
import { addTopic } from "../../utils/api"
const QQMapWX = require("../../utils/qqmap-wx-jssdk")
const config = require("../../../../utils/config")
5 years ago
Page({
data: {
topicValue: "",
5 years ago
imageList: [],
qqmapsdk: "",
addressValue: "",
5 years ago
imageId: 1,
location: {
latitude: "",
longitude: ""
5 years ago
},
partyGroupId: "",
topicType:"",//0:事好儿鼓个掌 1:话对捧个场
addTopicPrevious: 0,
violationsCount: 0,
isConReview: false,
lock: false, //锁定发布按钮状态,防止连击
5 years ago
},
onShow () {
},
onLoad (options) {
const qqmapsdk = new QQMapWX({
key: "CMJBZ-4DECI-JXGGN-5B4WU-QLV2H-B5BEJ"
5 years ago
})
this.setData({
qqmapsdk,
partyGroupId: options.partyGroupId,
topicType: options.topicType,
})
5 years ago
if(options.topicType == 0){
wx.setNavigationBarTitle({
title: "事好鼓个掌"
5 years ago
})
}else{
wx.setNavigationBarTitle({
title: "话对捧个场"
5 years ago
})
}
5 years ago
this.getLocation()
},
// 话题内容框 值双向绑定
bindTopicValue (e) {
this.setData({
topicValue: e.detail.value
})
console.log(this.data.topicValue)
},
// 地址框 值双向绑定
bindAddressValue (e) {
this.setData({
addressValue: e.detail.value
})
console.log(this.data.addressValue)
},
// 选择图片
chooseImage () {
const that = this
$wuxActionSheet().showSheet({
buttons: [{
text: "拍照"
},
{
text: "从相册中获取"
},
5 years ago
],
buttonClicked (index) {
5 years ago
if (index === 0) {
wx.chooseImage({
count: 1,
sizeType: ["original", "compressed"],
sourceType: ["camera"],
5 years ago
success (res) {
const imageList = [...that.data.imageList]
imageList.push({
img: res.tempFilePaths[0],
upload: true,
id: that.data.imageId++,
ossUrl: ""
5 years ago
})
that.setData({
imageList
})
wx.uploadFile({
url: config.BASEURL() + "group/topic/upload",
5 years ago
filePath: res.tempFilePaths[0],
name: "file",
5 years ago
header: {
"Content-Type": "multipart/form-data"
5 years ago
},
success (fileres) {
const data = JSON.parse(fileres.data)
if (data.code === 0 && data.msg === "success") {
5 years ago
imageList[imageList.length - 1].ossUrl = data.data
imageList[imageList.length - 1].upload = false
} else {
imageList.pop()
wx.showToast({
title: "上传图片失败,请重试",
icon: "none",
5 years ago
duration: 2000
})
}
that.setData({
imageList
})
},
fail (err) {
console.log(err)
imageList.pop()
wx.showToast({
title: "上传图片失败,请重试",
icon: "none",
duration: 2000
})
that.setData({
5 years ago
imageList
})
}
})
}
})
} else if (index === 1) {
wx.chooseImage({
count: 3 - that.data.imageList.length,
sizeType: ["original", "compressed"],
sourceType: ["album"],
5 years ago
success (res) {
let imageList = []
res.tempFilePaths.forEach(item => {
imageList.push({
img: item,
upload: true,
id: that.data.imageId++,
ossUrl: ""
5 years ago
})
})
that.setData({
imageList: [...that.data.imageList, ...imageList]
})
imageList.forEach((item, index) => {
(function (index) {
wx.uploadFile({
url: `${config.BASEURL()}group/topic/upload`,
filePath: imageList[index].img,
name: "file",
5 years ago
header: {
"Content-Type": "multipart/form-data"
5 years ago
},
success (fileRes) {
const data = JSON.parse(fileRes.data)
if (data.code === 0 && data.msg === "success") {
5 years ago
imageList[index].ossUrl = data.data
imageList[index].upload = false
} else {
imageList.splice(index, 1)
wx.showToast({
title: "上传图片失败,请重试",
icon: "none",
5 years ago
duration: 2000
})
}
that.data.imageList = that.data.imageList.slice(0, that.data.imageList.length - res.tempFilePaths.length)
that.setData({
imageList: [...that.data.imageList, ...imageList]
})
},
fail (err) {
console.log(err)
imageList.splice(index, 1)
wx.showToast({
title: "上传图片失败,请重试",
icon: "none",
5 years ago
duration: 2000
})
that.data.imageList = that.data.imageList.slice(0, that.data.imageList.length - res.tempFilePaths.length)
that.setData({
imageList: [...that.data.imageList, ...imageList]
})
}
})
})(index)
})
}
})
}
return true
},
cancelText: "取消",
cancel () {},
destructiveButtonClicked () {},
5 years ago
})
},
// 获取经纬度
getLocation () {
wx.getLocation({
type: "gcj02",
5 years ago
success: (res) => {
console.log("经纬度", res)
5 years ago
this.reverseGeocoder(res)
this.setData({
location: {
latitude: res.latitude,
longitude: res.longitude
}
})
}
})
},
// 逆地址解析
reverseGeocoder ({latitude, longitude}) {
this.data.qqmapsdk.reverseGeocoder({
location: {
latitude,
longitude
},
success: (res) => {
console.log("逆地址解析", res)
if (res.message === "query ok") {
5 years ago
this.setData({
addressValue: res.result.address
})
}
}
})
},
// throttleAddTopic () {
// let now = new Date()
// if (now - this.data.addTopicPrevious > 2000) {
// this.addTopic()
// this.data.addTopicPrevious = now
// }
// },
// 添加话题事件
addTopic () {
if (this.data.topicValue === "") {
5 years ago
wx.showToast({
title: "请输入-话题内容",
icon: "none",
5 years ago
duration: 2000
})
return false
} else if (this.data.topicValue.length > 1000) {
wx.showToast({
title: "超出1000字数限制",
icon: "none",
duration: 2000
})
return false
} else if (this.data.addressValue === "") {
5 years ago
wx.showToast({
title: "请输入-地址",
icon: "none",
5 years ago
duration: 2000
})
return false
}
const imagesList = []
if (this.data.imageList.length > 0) {
const isUploadingStatus = this.data.imageList.some(item => item.upload)
if (isUploadingStatus) {
wx.showToast({
title: "请等待图片上传完成",
icon: "none",
5 years ago
duration: 2000
})
return false
}
this.data.imageList.forEach(item => {
imagesList.push(item.ossUrl)
})
}
const para = {
topicType:this.data.topicType,//话题类型:0:事好儿鼓个掌 1:话对捧个场
topicContent: this.data.topicValue,//话题内容
topicAddress: this.data.addressValue,//话题地址
topicLatitude: this.data.location.latitude,//话题位置纬度
topicLongitude: this.data.location.longitude,//话题位置经度
partyGroupId:this.data.partyGroupId,//党群ID
images: imagesList,
isConReview: this.data.isConReview
5 years ago
}
this.setData({
lock: true
})
5 years ago
wx.showLoading({
title: "加载中",
5 years ago
})
let that = this
5 years ago
addTopic(para).then(res => {
wx.hideLoading()
this.setData({
lock: false
})
// console.log(res)
if (res.code == 0) {
wx.showToast({
title: "发布成功",
icon: "none",
duration: 2000
})
this.setData({
violationsCount: 0,
isConReview: false
})
// var prePages = pages[pages.length - 2]
setTimeout(() => {
// prePages.pullRefreshGetTopicList()
wx.navigateBack()
}, 1000)
} else if (res.code == 533) {
this.data.violationsCount++
console.log(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.addTopic()
} else if (res.cancel) {
console.log('用户点击取消')
that.setData({
violationsCount: 0,
isConReview: false
})
}
}
})
}
}
5 years ago
}).catch(err => {
console.log('err',err)
wx.hideLoading()
this.setData({
lock: false
})
5 years ago
})
},
// 删除图片
deleteImage (e) {
const index = this.data.imageList.findIndex((item,index) => index === e.currentTarget.dataset.index)
this.data.imageList.splice(index, 1)
const imageList = this.data.imageList
this.setData({
imageList
})
}
})