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

290 lines
6.6 KiB

// subpages/heart/pages/myApply/myApply.js
const api = require("../../../../utils/api")
import { getTimestamp } from "../../../../utils/common"
Page({
/**
* 页面的初始数据
*/
data: {
showPicker: false, //是否显示底部时间选择器插件
dataForm: {
actTitle: '',
actContent: '',
actAddress: '',
actStartTime: '', //起始时间
actEndTime: '', //结束时间
actPeopleNum: '',
actContacts: '',
actTel: '',
dialogVisible: false, //提示框
},
curCode: '', //区分是start还是end,
violationsCount: 0, //内容审核计数
isConReview: false, //内容审核标志
lock: false, //锁定发布按钮状态,防止连击
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
// onShareAppMessage: function () {
// }
onInputTitle (e) {
this.setData({
'dataForm.actTitle': e.detail.value
})
},
onInputContent (e) {
this.setData({
'dataForm.actContent': e.detail.value
})
},
onInputAddress (e) {
this.setData({
'dataForm.actAddress': e.detail.value
})
},
onInputPeopleNum (e) {
this.setData({
'dataForm.actPeopleNum': e.detail.value
})
},
onInputContacts (e) {
this.setData({
'dataForm.actContacts': e.detail.value
})
},
onInputTel (e) {
this.setData({
'dataForm.actTel': e.detail.value
})
},
pickerCancel () {
console.log('取消日期选择')
this.setData({
showPicker: false
})
},
pickerConfirm (e) {
console.log('选择日期', e.detail.time)
if (this.data.curCode == 'start') {
this.setData({
showPicker: false,
'dataForm.actStartTime': e.detail.time
})
if (this.data.dataForm.actStartTime < getTimestamp()) {
this.showToast("开始时间应该大于当前时间")
}
} else if (this.data.curCode == 'end') {
this.setData({
showPicker: false,
'dataForm.actEndTime': e.detail.time
})
if (this.data.dataForm.actStartTime > this.data.dataForm.actEndTime) {
this.showToast('结束时间应该大于起始时间')
}
}
},
//日期选择插件显示入口
selectTime (e) {
this.data.showPicker = !this.data.showPicker
this.setData({
showPicker: this.data.showPicker,
curCode: e.currentTarget.dataset.code
})
},
//提交申请
submitApply () {
if (this.data.lock) {
return false
}
if (!this.data.dataForm.actTitle.trim('')) {
this.showToast("请填写活动标题")
return false
}
if (!this.data.dataForm.actContent.trim('')) {
this.showToast("请填写活动内容")
return false
}
if (!this.data.dataForm.actAddress.trim('')) {
this.showToast("请填写活动地址")
return false
}
if (!this.data.dataForm.actStartTime) {
this.showToast("请填写开始时间")
return false
}
if (this.data.dataForm.actStartTime < getTimestamp()) {
this.showToast("开始时间应该大于当前时间")
return false
}
if (!this.data.dataForm.actEndTime) {
this.showToast("请填写结束时间")
return false
}
if (this.data.dataForm.actStartTime > this.data.dataForm.actEndTime) {
this.showToast('结束时间应该大于起始时间')
return false
}
if (!this.data.dataForm.actPeopleNum.trim('')) {
this.showToast("请填写需要人数")
return false
}
if (!(parseInt(this.data.dataForm.actPeopleNum) > 0)) {
this.showToast("请填写正确的人数")
return false
}
if (!this.data.dataForm.actContacts.trim('')) {
this.showToast("请填写联系人")
return false
}
if (!this.data.dataForm.actTel.trim('')) {
this.showToast("请填写联系人电话")
return false
}
wx.showLoading({
title: "加载中",
})
this.setData({
lock: true,
'dataForm.actPeopleNum': parseInt(this.data.dataForm.actPeopleNum)
})
const para = { ...this.data.dataForm }
para.isConReview = this.data.isConReview
console.log('submit apply', para)
let that = this
api.applyAct(para).then(res => {
wx.hideLoading()
this.setData({
lock: false
})
if(res.code == 0) {
this.setData({
dialogVisible: !this.data.dialogVisible,
'dataForm.actTitle': '',
violationsCount: 0,
isConReview: false
})
} 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.submitApply()
} else if (res.cancel) {
console.log('用户点击取消')
that.setData({
violationsCount: 0,
isConReview: false
})
}
}
})
}
}
}).catch(err => {
console.log('err',err)
wx.hideLoading()
this.setData({
lock: false
})
})
},
//简化提示
showToast (title) {
wx.showToast({
title: title,
icon: "none",
duration: 2000
})
},
//跳转到我提交的申请列表
toApplyList () {
wx.navigateTo({
url: "/subpages/heart/pages/myApplyList/myApplyList"
})
},
// 关闭弹框
closeDialog () {
wx.navigateTo({
url: "/pages/heartNew/heartNew"
})
},
// 弹框确定按钮
confirmDialog () {
wx.navigateTo({
url: "/pages/heartNew/heartNew"
})
}
})