// subpages/heart/pages/dropByPublish/dropByPublish.js const api = require("../../utils/api") import { getTimestamp } from '../../../../utils/common' Page({ /** * 页面的初始数据 */ data: { dialogVisible: false, //提示框 showPicker: false, //是否显示底部时间选择器插件 dataForm: { departure: '', //目的地 destination: '', //出发地 departureTime: '', //出发时间 mobile: '', //手机 carryContent: '', //携带内容 carryStatus: '', //捎带状态 0:我需要捎 1:我可以捎 id: '', //主键 更新时携带 }, violationsCount: 0, //内容审核计数 isConReview: false, //内容审核标志 lock: false, //锁定发布按钮状态,防止连击 selectedTab: 'tab0', }, /** * 生命周期函数--监听页面加载 */ 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 () { // } onInputDeparture (e) { this.setData({ 'dataForm.departure': e.detail.value }) }, onInputDestination (e) { this.setData({ 'dataForm.destination': e.detail.value }) }, onInputMobile (e) { this.setData({ 'dataForm.mobile': e.detail.value }) }, onInputContent (e) { this.setData({ 'dataForm.carryContent': e.detail.value }) }, pickerCancel () { console.log('取消日期选择') this.setData({ showPicker: false, 'dataForm.departureTime': '' }) }, pickerConfirm (e) { console.log('选择日期', e.detail.time) if (e.detail.time < getTimestamp()) { this.showToast("出发时间应该大于当前时间") } else { this.setData({ showPicker: false, 'dataForm.departureTime': e.detail.time }) } }, //日期选择插件显示入口 selectTime (e) { this.data.showPicker = !this.data.showPicker this.setData({ showPicker: this.data.showPicker, 'dataForm.departureTime': this.data.dataForm.departureTime || getTimestamp() }) }, //发布 submitApply () { if (this.data.lock) { return false } if (!this.data.dataForm.departure.trim('')) { this.showToast("请填出发地") return false } if (this.data.dataForm.departure.length>100) { this.showToast("出发地请在100字以内") return false } if (!this.data.dataForm.destination.trim('')) { this.showToast("请填写目的地") return false } if (this.data.dataForm.destination.length>100) { this.showToast("目的地请在100字以内") return false } if (!this.data.dataForm.departureTime) { this.showToast("请填写出发时间") return false } if (!this.data.dataForm.mobile.trim('')) { this.showToast("请填写联系电话") return false } if (this.data.dataForm.mobile.length>20) { this.showToast("联系电话请在20字以内") return false } if (!this.data.dataForm.carryContent.trim('')) { this.showToast("请填写携带内容") return false } if (this.data.dataForm.carryContent.length>500) { this.showToast("携带内容请在500字以内") return false } if (this.data.selectedTab == 'tab0') { this.data.dataForm.carryStatus = '0' } else if(this.data.selectedTab == 'tab1') { this.data.dataForm.carryStatus = '1' } 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.sdsUpdate(para).then(res => { this.setData({ lock: false }) if(res.code == 0) { wx.hideLoading() this.setData({ dialogVisible: !this.data.dialogVisible, 'dataForm.departure': '', 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 }) }) }, //简化提示 showToast (title) { wx.showToast({ title: title, icon: "none", duration: 2000 }) }, // 关闭弹框 closeDialog () { wx.navigateBack({ delta: 1 }) }, // 弹框确定按钮 confirmDialog () { wx.navigateBack({ delta: 1 }) }, // tab 切换 tabBarChange (e) { this.setData({ selectedTab: e.currentTarget.dataset.tab }) }, initDataForm () { wx.showLoading({ title: '加载中...' }) api.getSdsDetail(this.data.dataForm.id).then(res => { wx.hideLoading() this.data.dataForm = { ...res.data } let tab = 'tab' + this.data.dataForm.carryStatus this.setData({ selectedTab: tab, dataForm: this.data.dataForm }) }) } })