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

255 lines
5.7 KiB

// subpages/heart/pages/groupBuyPublish/groupBuyPublish.js
const api = require("../../utils/api")
import { getTimestamp } from '../../../../utils/common'
Page({
/**
* 页面的初始数据
*/
data: {
dialogVisible: false, //提示框
showPicker: false, //是否显示底部时间选择器插件
dataForm: {
groupBuyTitle: '', //标题
groupBuyContent: '', //内容
groupBuyTime: '', //团购时间
groupBuyMobile: '', //手机
id: '', //主键 更新时携带
},
violationsCount: 0, //内容审核计数
isConReview: false, //内容审核标志
lock: false, //锁定发布按钮状态,防止连击
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
this.setData({
'dataForm.id': options.id || ''
})
if (options.id) {
this.initDataForm()
}
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
// onShareAppMessage: function () {
// }
onInputGroupBuyTitle (e) {
this.setData({
'dataForm.groupBuyTitle': e.detail.value
})
},
onInputGroupBuyMobile (e) {
this.setData({
'dataForm.groupBuyMobile': e.detail.value
})
},
onInputContent (e) {
this.setData({
'dataForm.groupBuyContent': e.detail.value
})
},
pickerCancel () {
console.log('取消日期选择')
this.setData({
showPicker: false,
'dataForm.groupBuyTime': ''
})
},
pickerConfirm (e) {
console.log('选择日期', e.detail.time)
if (e.detail.time < getTimestamp()) {
this.showToast("团购时间应该大于当前时间")
} else {
this.setData({
showPicker: false,
'dataForm.groupBuyTime': e.detail.time
})
}
},
//日期选择插件显示入口
selectTime (e) {
this.data.showPicker = !this.data.showPicker
this.setData({
showPicker: this.data.showPicker,
'dataForm.groupBuyTime': this.data.dataForm.groupBuyTime || getTimestamp()
})
},
//发布
submitApply () {
if (this.data.lock) {
return false
}
if (!this.data.dataForm.groupBuyTitle) {
this.showToast("请填标题")
return false
}
if (this.data.dataForm.groupBuyTitle.length>50) {
this.showToast("标题限制在50字以内")
return false
}
if (!this.data.dataForm.groupBuyTime) {
this.showToast("请填写团购时间")
return false
}
if (!this.data.dataForm.groupBuyContent) {
this.showToast("请填写团购内容")
return false
}
if (this.data.dataForm.groupBuyContent.length>500) {
this.showToast("团购内容限制在500字以内")
return false
}
if (!this.data.dataForm.groupBuyMobile) {
this.showToast("请填写联系电话")
return false
}
if (this.data.dataForm.groupBuyMobile.length>20) {
this.showToast("联系电话限制在20字以内")
return false
}
wx.showLoading({
title: "发布中",
})
this.setData({
lock: true
})
const para = { ...this.data.dataForm }
para.isConReview = this.data.isConReview
console.log('submit', para)
let that = this
api.groupBuyUpdate(para).then(res => {
this.setData({
lock: false
})
if(res.code == 0) {
wx.hideLoading()
this.setData({
dialogVisible: !this.data.dialogVisible,
'dataForm.groupBuyTitle': '',
violationsCount: 0,
isConReview: false
})
} else if (res.code == 533) {
wx.hideLoading()
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.hideLoading()
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
})
})
},
initDataForm () {
wx.showLoading({
title: '加载中...'
})
api.getGroupBuyDetail(this.data.dataForm.id).then(res => {
wx.hideLoading()
this.setData({
dataForm: res.data
})
})
},
//简化提示
showToast (title) {
wx.showToast({
title: title,
icon: "none",
duration: 2000
})
},
// 关闭弹框
closeDialog () {
wx.navigateBack({
delta: 1
})
},
// 弹框确定按钮
confirmDialog () {
wx.navigateBack({
delta: 1
})
},
})