const app = getApp() const util = require("../../utils/util.js") Component({ /** * 组件的属性列表 */ properties: { isShow: { // 弹窗显示-隐藏 type: Boolean, value: true }, c_code: { // 课题编号 type: String, value: '' }, type: { // 课程类型 type: String, value: '' }, info: Object // 课程预约信息 }, /** * 组件的初始数据 */ data: { success: false, // 报名成功 // duedate: '', // 选择的日期 b_count: 1, //参与人数 name: '', phone: '', addOn: 'https://yuesuo.yueguanjia.com/MiniProgram/images/phaseI/addOn.png', addOff: 'https://yuesuo.yueguanjia.com/MiniProgram/images/phaseI/addOff.png', minusOn: 'https://yuesuo.yueguanjia.com/MiniProgram/images/phaseI/minusOn.png', minusOff: 'https://yuesuo.yueguanjia.com/MiniProgram/images/phaseI/minusOff.png', successImg: 'https://yuesuo.yueguanjia.com/MiniProgram/images/phaseI/chenggong.png', b_time: 1, yxsj: [{ i: 1, t: '平日上午' }, { i: 2, t: '平日下午' }, { i: 3, t: '周末上午' }, { i: 4, t: '周末下午' }] }, observers: { 'isShow': function (isShow) { if (!isShow) { if (this.properties.info && this.properties.info.name) { this.setData({ name: this.properties.info.name, phone: this.properties.info.phone, duedate: this.properties.info.duedate, b_count: this.properties.info.b_count }) } } } }, attached: function() { if (!this.data.phone) { this.setData({ phone: app.globalData.userphone }) } }, methods: { // 选择日期 // bindDateChange: function(e) { // this.setData({ // duedate: e.detail.value // }) // }, // 减参与人数 minusBtn: function() { if (this.data.b_count < 2) return this.setData({ b_count: this.data.b_count - 1 }) }, // 加参与人数 addBtn: function() { this.setData({ b_count: this.data.b_count + 1 }) }, // 选择意向时间 cliYxsj: function(event) { this.setData({ b_time: event.currentTarget.dataset.i }) }, // 提交 submitForm: function(data) { let obj = { ...data.detail.value, openid: app.globalData.openid, college_code: this.properties.c_code, b_count: this.data.b_count } if (this.properties.type == 'tiyan') { delete obj.b_count obj.b_time = this.data.b_time } if (obj.phone.length < 11) { wx.showToast({ title: '手机号填写不完整', icon: 'none', duration: 2000 }) return } if (!obj.name) { wx.showToast({ title: '姓名不能为空', icon: 'none', duration: 2000 }) return } util.postData('/college/addCollegeBooking', obj) .then(res => { if (res == 1) { this.setData({ success: true }) } }) }, // 取消-or-点击遮罩层 resetForm: function(data) { let isOver = this.data.success this.setData({ success: false }) let mask = data.currentTarget.dataset.mask if (mask == 'mask') { // 这时候是点击的遮罩层 this.triggerEvent('cancel', { cliType: 'mask', success: isOver }, {}) } else { // 这个是点的取消预约-取消报名,开始执行取消 util.postData('/college/bookingCancel', { openid: app.globalData.openid, college_code: this.properties.c_code, phone: app.globalData.userphone }) .then(res => { if (res == 1) { this.setData({ phone: app.globalData.userphone, b_count: 1, duedate: '' }) this.triggerEvent('cancel', { cliType: 'cancel' }, {}) } }) } } } })