123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212 |
- const api = require('../../config/api.js');
- const util = require('../../utils/util.js');
- import play from '../../utils/pay.js'
- // 手机号校验
- const PHONE = {
- REG: /^((13[0-9]|14[01456879]|15[0-3,5-9]|16[2567]|17[0-8]|18[0-9]|19[0-3,5-9])\d{8})|(8){11}$/,
- tip: '手机号格式不正确!'
- }
- // pages/reserve/reserve.js
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- date: '',
- people: 0,
- showDate: '',
- name: '',
- phone: '',
- code: '',
- sex:1,
- showShare: false,
- sendMis: 0
- },
- focusHandle() {
- console.log(this.data.name, this.data.name.length)
- this.setData({
- name: this.data.name.substr(0, 4)
- })
- },
- setSex1() {
- this.setData({sex: 1})
- },
- setSex0() {
- this.setData({sex: 0})
- },
- async sendCode() {
- if (this.data.sendMis !== 0) return;
- if (!PHONE.REG.test(this.data.phone)) {
- return wx.showToast({
- icon: 'none',
- title: '请输入正确的手机号码',
- })
- }
- this.data.sendMis = 60
- try {
- await util.request(api.OrderSendCode, {phoneNum: this.data.phone}, 'GET')
-
- this.setData({
- sendMis: 60
- })
- let interval = setInterval(() => {
- if (this.data.sendMis === 0) return clearInterval(interval)
- this.setData({ sendMis: this.data.sendMis - 1 })
- }, 1000)
- } catch (e) {
- this.data.sendMis = 0
- }
- },
- updateName(ev) {
- this.setData({name: ev.detail.value})
- },
-
- updatePhone(ev) {
- this.setData({phone: ev.detail.value})
- },
-
- updateCode(ev) {
- this.setData({code: ev.detail.value})
- },
- enter() {
- this.quit()
- },
- quit() {
- wx.navigateBack()
- },
- async getBrandDetail(id) {
- let res = await util.request(api.BrandDetail, { canteenId: id}, 'GET')
- this.setData({
- brand: res.data
- })
-
- wx.setNavigationBarTitle({
- title: res.data.canteenName//页面标题为路由参数
- })
-
- },
-
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function (res) {
- let userInfo = wx.getStorageSync('userInfo')
- if (res.from === 'button') {
- setTimeout(() => {
- this.quit()
- }, 50)
- return {
- title: '【好友分享】特设薄宴,静待贵客',
- imageUrl: '/static/images/share.png',
- path: `pages/scene/scene?id=${this.data.brand.id}&scene=${this.data.brand.sceneNum}&shareUserId=${userInfo.id}`
- }
- } else {
- return {
- title: '【好友推荐】场景还原,实现线上选座',
- imageUrl: '/static/images/share.png',
- path: `pages/scene/scene?id=${this.data.brand.id}&scene=${this.data.brand.sceneNum}&shareUserId=${userInfo.id}`
- }
- }
- },
- async getDeskDetail(canteenId, qid) {
- let res = await util.request(api.deskList, {canteenId: canteenId, pageNum: 1, pageSize: 1000}, 'GET')
- this.setData({
- desk: res.data.list.find(item => item.tmDesk.id === qid).tmDesk
- })
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: async function (options) {
- this.getBrandDetail(options.canteenId)
- this.getDeskDetail(options.canteenId, options.deskId)
- this.setData({ people: options.people, date: options.date, showDate: options.date.substring(5, 16) })
- },
- async save() {
- if (this.saveIng) return;
- this.saveIng = true
- if (!PHONE.REG.test(this.data.phone)) {
- return wx.showToast({
- icon: 'none',
- title: '请输入正确的手机号码',
- })
- } else if (!Number(this.data.code) || this.data.code.length !== 6) {
- return wx.showToast({
- icon: 'none',
- title: '验证码错误',
- })
- } else if (!this.data.name.trim().length) {
- return wx.showToast({
- icon: 'none',
- title: '请输入预订人',
- })
- }
- let res = await util.request(api.OrderSubmit, {
- canteenId: this.data.brand.id,
- deskId: this.data.desk.id,
- deskName: this.data.desk.deskName,
- deskType: this.data.desk.type,
- msgCode: this.data.code,
- orderPrice: 0.01,
- reserveDate: this.options.date.substr(0, 10),
- reserveUserGender: this.data.sex,
- reservePersonNum: this.options.people,
- reserveTime: this.options.date+":00",
- // reserveUserId 预订人的ID false
- reserveUserName: this.data.name,
- reserveUserPhone: this.data.phone
- }, 'POST', 'application/json')
- if (res.code !== 0) {
- return wx.showToast({
- icon: 'none',
- title: res.msg,
- })
- }
- try {
- await play(res.data.id)
- let res1 = await util.request(api.OrderQuery, { orderId: res.data.id})
- wx.showToast({
- icon: 'success',
- title: res1.errmsg
- })
-
- getApp().callOrderBuyCbs({deskId: this.data.desk.id})
- this.saveIng = false
- return this.setData({showShare: true})
- } catch (e) {
- wx.showToast({
- icon: 'none',
- title: '付款失败',
- })
- wx.redirectTo({
- url: '/pages/ucenter/order/order',
- })
- this.saveIng = false
- }
- },
- })
|