|
@@ -1,7 +1,13 @@
|
|
// pages/creatOrder/creatOrder.js
|
|
// pages/creatOrder/creatOrder.js
|
|
-import { shuoAPIClient } from '../../common/api/api.js';
|
|
|
|
|
|
+import {
|
|
|
|
+ shuoAPIClient
|
|
|
|
+} from '../../common/api/api.js';
|
|
import user from '../../common/user/user.js';
|
|
import user from '../../common/user/user.js';
|
|
-import { parseDate } from '../../lib/util/util.js';
|
|
|
|
|
|
+import {
|
|
|
|
+ parseDate
|
|
|
|
+} from '../../lib/util/util.js';
|
|
|
|
+var touchstart = 0
|
|
|
|
+var touchend = 0
|
|
Page({
|
|
Page({
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -12,7 +18,7 @@ Page({
|
|
curr: "",
|
|
curr: "",
|
|
isMoreDate: false, // 日期框展示
|
|
isMoreDate: false, // 日期框展示
|
|
isMask: false,
|
|
isMask: false,
|
|
- num:1,
|
|
|
|
|
|
+ num: 1,
|
|
choosedData: 1,
|
|
choosedData: 1,
|
|
infoId: null,
|
|
infoId: null,
|
|
year: null,
|
|
year: null,
|
|
@@ -88,50 +94,74 @@ Page({
|
|
});
|
|
});
|
|
shuoAPIClient.request('/api/minapp/order/order',
|
|
shuoAPIClient.request('/api/minapp/order/order',
|
|
data, true, 'POST').then(res => {
|
|
data, true, 'POST').then(res => {
|
|
- wx.hideLoading()
|
|
|
|
- console.log('下单返回', res)
|
|
|
|
- if (res.data.state == 2) { // 下单成功,可以立即发起支付
|
|
|
|
- let orderId = res.data.orderId
|
|
|
|
- wx.requestPayment({
|
|
|
|
- 'timeStamp': res.data.timestamp,
|
|
|
|
- 'nonceStr': res.data.noncestr,
|
|
|
|
- 'package': res.data.packages,
|
|
|
|
- 'signType': res.data.signtype,
|
|
|
|
- 'paySign': res.data.paysign,
|
|
|
|
- 'complete': function (res) {
|
|
|
|
- console.log(res, '支付信息')
|
|
|
|
- let isPay = res.errMsg.indexOf('fail') > -1 ? 2 : 1;// 支付失败或取消支付:2, 支付成功:1;
|
|
|
|
- wx.redirectTo({
|
|
|
|
- url: `/pages/orderDetail/orderDetail?orderId=${orderId}&isPay=${isPay}`
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
-
|
|
|
|
- } else if (res.data.state == 1) {
|
|
|
|
- let orderId = res.data.orderId
|
|
|
|
- wx.redirectTo({
|
|
|
|
- url: `/pages/orderDetail/orderDetail?orderId=${orderId}`
|
|
|
|
- });
|
|
|
|
- } else {
|
|
|
|
- wx.showModal({
|
|
|
|
- title: '提示',
|
|
|
|
- content: res.data.msg,
|
|
|
|
- showCancel: false
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
- })
|
|
|
|
|
|
+ wx.hideLoading()
|
|
|
|
+ console.log('下单返回', res)
|
|
|
|
+ if (res.data.state == 2) { // 下单成功,可以立即发起支付
|
|
|
|
+ let orderId = res.data.orderId
|
|
|
|
+ wx.requestPayment({
|
|
|
|
+ 'timeStamp': res.data.timestamp,
|
|
|
|
+ 'nonceStr': res.data.noncestr,
|
|
|
|
+ 'package': res.data.packages,
|
|
|
|
+ 'signType': res.data.signtype,
|
|
|
|
+ 'paySign': res.data.paysign,
|
|
|
|
+ 'complete': function(res) {
|
|
|
|
+ console.log(res, '支付信息')
|
|
|
|
+ let isPay = res.errMsg.indexOf('fail') > -1 ? 2 : 1; // 支付失败或取消支付:2, 支付成功:1;
|
|
|
|
+ wx.redirectTo({
|
|
|
|
+ url: `/pages/orderDetail/orderDetail?orderId=${orderId}&isPay=${isPay}`
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ } else if (res.data.state == 1) {
|
|
|
|
+ let orderId = res.data.orderId
|
|
|
|
+ wx.redirectTo({
|
|
|
|
+ url: `/pages/orderDetail/orderDetail?orderId=${orderId}`
|
|
|
|
+ });
|
|
|
|
+ } else {
|
|
|
|
+ wx.showModal({
|
|
|
|
+ title: '提示',
|
|
|
|
+ content: res.data.msg,
|
|
|
|
+ showCancel: false
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ })
|
|
},
|
|
},
|
|
|
|
|
|
/**
|
|
/**
|
|
* 弹框提示
|
|
* 弹框提示
|
|
*/
|
|
*/
|
|
- openToast (title, icon) {
|
|
|
|
|
|
+ openToast(title, icon) {
|
|
wx.showToast({
|
|
wx.showToast({
|
|
title: title,
|
|
title: title,
|
|
icon: icon,
|
|
icon: icon,
|
|
duration: 2000
|
|
duration: 2000
|
|
})
|
|
})
|
|
},
|
|
},
|
|
|
|
+
|
|
|
|
+ touchstart: function(e) {
|
|
|
|
+ console.log('滑动')
|
|
|
|
+ console.log(e.changedTouches[0].clientX)
|
|
|
|
+ touchstart = e.changedTouches[0].clientX
|
|
|
|
+ },
|
|
|
|
+ touchend: function(e) {
|
|
|
|
+ console.log('停止')
|
|
|
|
+ console.log(e)
|
|
|
|
+ console.log(e.changedTouches[0].clientX)
|
|
|
|
+ touchend = e.changedTouches[0].clientX
|
|
|
|
+ if (touchstart - touchend > 60) {
|
|
|
|
+ console.log('左滑了')
|
|
|
|
+ this.nextMonth()
|
|
|
|
+ }
|
|
|
|
+ if (touchstart - touchend < -60) {
|
|
|
|
+ console.log('右滑了')
|
|
|
|
+ let today = new Date();
|
|
|
|
+ let amonth = today.getMonth() + 1
|
|
|
|
+ if (this.data.month > amonth) {
|
|
|
|
+ this.lastMonth()
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ },
|
|
/**
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
*/
|
|
@@ -146,20 +176,30 @@ Page({
|
|
})
|
|
})
|
|
this.initDate(this.data.year, this.data.month)
|
|
this.initDate(this.data.year, this.data.month)
|
|
this.blankDays(this.data.year, this.data.month)
|
|
this.blankDays(this.data.year, this.data.month)
|
|
|
|
+ this.getProdDetail()
|
|
},
|
|
},
|
|
/**
|
|
/**
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
*/
|
|
*/
|
|
- onReady: function () {
|
|
|
|
|
|
+ onReady: function() {
|
|
|
|
|
|
},
|
|
},
|
|
|
|
|
|
- onShow: function () {
|
|
|
|
|
|
+ onShow: function(options) {
|
|
console.log('creatOrder')
|
|
console.log('creatOrder')
|
|
this.getPrice()
|
|
this.getPrice()
|
|
- this.getProdDetail()
|
|
|
|
},
|
|
},
|
|
|
|
+ onUnload: function() {
|
|
|
|
+ console.log('onUnload')
|
|
|
|
+ if (this.data.linkInfo[0].nameValue || this.data.linkInfo[0].phoneValue || this.data.linkInfo[0].idCardValue) {
|
|
|
|
+ wx.showToast({
|
|
|
|
+ title: '你曾经说,最大的愿望,就是去旅行',
|
|
|
|
+ icon: "none",
|
|
|
|
+ duration: 2000
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
|
|
|
|
+ },
|
|
/**
|
|
/**
|
|
* 初始化日历
|
|
* 初始化日历
|
|
*/
|
|
*/
|
|
@@ -182,7 +222,7 @@ Page({
|
|
// } else if (day + 1 == i) {
|
|
// } else if (day + 1 == i) {
|
|
// dateList.push('明天')
|
|
// dateList.push('明天')
|
|
// } else {
|
|
// } else {
|
|
- dateList.push(i)
|
|
|
|
|
|
+ dateList.push(i)
|
|
// }
|
|
// }
|
|
}
|
|
}
|
|
this.setData({
|
|
this.setData({
|
|
@@ -196,9 +236,9 @@ Page({
|
|
/**
|
|
/**
|
|
* 当前月第一日前面的空白格
|
|
* 当前月第一日前面的空白格
|
|
*/
|
|
*/
|
|
- blankDays(year, month){
|
|
|
|
|
|
+ blankDays(year, month) {
|
|
let date = new Date(year, month - 1, 1)
|
|
let date = new Date(year, month - 1, 1)
|
|
- console.log('date', date.getFullYear() + '-' + date.getMonth() + '-' +date.getDate());
|
|
|
|
|
|
+ console.log('date', date.getFullYear() + '-' + date.getMonth() + '-' + date.getDate());
|
|
let week = date.getDay();
|
|
let week = date.getDay();
|
|
let blankDays = []
|
|
let blankDays = []
|
|
for (let i = 0; i < week; i++) {
|
|
for (let i = 0; i < week; i++) {
|
|
@@ -223,7 +263,7 @@ Page({
|
|
/**
|
|
/**
|
|
* 非日历内的选中日期事件
|
|
* 非日历内的选中日期事件
|
|
*/
|
|
*/
|
|
- chooseDate: function (e) {
|
|
|
|
|
|
+ chooseDate: function(e) {
|
|
console.log(e.currentTarget.dataset.traveldate)
|
|
console.log(e.currentTarget.dataset.traveldate)
|
|
this.setData({
|
|
this.setData({
|
|
selectDate: e.currentTarget.dataset.traveldate
|
|
selectDate: e.currentTarget.dataset.traveldate
|
|
@@ -234,7 +274,7 @@ Page({
|
|
/**
|
|
/**
|
|
* 数量减少
|
|
* 数量减少
|
|
*/
|
|
*/
|
|
- increaseNum: function () {
|
|
|
|
|
|
+ increaseNum: function() {
|
|
let num = this.data.num
|
|
let num = this.data.num
|
|
if (num > 1) {
|
|
if (num > 1) {
|
|
num--
|
|
num--
|
|
@@ -249,7 +289,7 @@ Page({
|
|
/**
|
|
/**
|
|
* 数量增加
|
|
* 数量增加
|
|
*/
|
|
*/
|
|
- addNum: function () {
|
|
|
|
|
|
+ addNum: function() {
|
|
let num = this.data.num
|
|
let num = this.data.num
|
|
num++
|
|
num++
|
|
this.setData({
|
|
this.setData({
|
|
@@ -262,7 +302,7 @@ Page({
|
|
/**
|
|
/**
|
|
* 价格计算
|
|
* 价格计算
|
|
*/
|
|
*/
|
|
- priceCalculation: function () {
|
|
|
|
|
|
+ priceCalculation: function() {
|
|
let num = this.data.num
|
|
let num = this.data.num
|
|
let selectDate = this.data.selectDate
|
|
let selectDate = this.data.selectDate
|
|
if (!selectDate) {
|
|
if (!selectDate) {
|
|
@@ -278,28 +318,33 @@ Page({
|
|
/**
|
|
/**
|
|
* 上个月
|
|
* 上个月
|
|
*/
|
|
*/
|
|
- lastMonth: function () {
|
|
|
|
- let year = this.data.year
|
|
|
|
- let month = this.data.month
|
|
|
|
- if (month == 1) {
|
|
|
|
- year = year - 1
|
|
|
|
- month = 12
|
|
|
|
- } else {
|
|
|
|
- month--
|
|
|
|
|
|
+ lastMonth: function() {
|
|
|
|
+ let today = new Date();
|
|
|
|
+ let amonth = today.getMonth() + 1
|
|
|
|
+ if (this.data.month > amonth) {
|
|
|
|
+ let year = this.data.year
|
|
|
|
+ let month = this.data.month
|
|
|
|
+ if (month == 1) {
|
|
|
|
+ year = year - 1
|
|
|
|
+ month = 12
|
|
|
|
+ } else {
|
|
|
|
+ month--
|
|
|
|
+ }
|
|
|
|
+ this.setData({
|
|
|
|
+ year: year,
|
|
|
|
+ month: month
|
|
|
|
+ })
|
|
|
|
+ this.initDate(year, month)
|
|
|
|
+ this.blankDays(year, month)
|
|
|
|
+ this.getPrice()
|
|
}
|
|
}
|
|
- this.setData({
|
|
|
|
- year: year,
|
|
|
|
- month: month
|
|
|
|
- })
|
|
|
|
- this.initDate(year, month)
|
|
|
|
- this.blankDays(year, month)
|
|
|
|
- this.getPrice()
|
|
|
|
|
|
+
|
|
},
|
|
},
|
|
|
|
|
|
/**
|
|
/**
|
|
* 下个月
|
|
* 下个月
|
|
*/
|
|
*/
|
|
- nextMonth: function () {
|
|
|
|
|
|
+ nextMonth: function() {
|
|
let year = this.data.year
|
|
let year = this.data.year
|
|
let month = this.data.month
|
|
let month = this.data.month
|
|
if (month == 12) {
|
|
if (month == 12) {
|
|
@@ -320,7 +365,7 @@ Page({
|
|
/**
|
|
/**
|
|
* 价格日历内选择日期
|
|
* 价格日历内选择日期
|
|
*/
|
|
*/
|
|
- select: function (e) {
|
|
|
|
|
|
+ select: function(e) {
|
|
console.log('select', e.currentTarget.dataset.day)
|
|
console.log('select', e.currentTarget.dataset.day)
|
|
let select = e.currentTarget.dataset.day
|
|
let select = e.currentTarget.dataset.day
|
|
let price = this.data.prices[this.data.year + '-' + (this.data.month < 10 ? '0' + this.data.month : this.data.month) + '-' + (select < 10 ? '0' + select : select)]
|
|
let price = this.data.prices[this.data.year + '-' + (this.data.month < 10 ? '0' + this.data.month : this.data.month) + '-' + (select < 10 ? '0' + select : select)]
|
|
@@ -332,7 +377,7 @@ Page({
|
|
selectDate: price.travelDate
|
|
selectDate: price.travelDate
|
|
})
|
|
})
|
|
this.priceCalculation()
|
|
this.priceCalculation()
|
|
-
|
|
|
|
|
|
+
|
|
|
|
|
|
let week = new Date().getDay()
|
|
let week = new Date().getDay()
|
|
let day = select
|
|
let day = select
|
|
@@ -353,7 +398,7 @@ Page({
|
|
/**
|
|
/**
|
|
* 价格日历开启
|
|
* 价格日历开启
|
|
*/
|
|
*/
|
|
- tapMoreDate: function () {
|
|
|
|
|
|
+ tapMoreDate: function() {
|
|
this.setData({
|
|
this.setData({
|
|
isMoreDate: true,
|
|
isMoreDate: true,
|
|
isMask: true
|
|
isMask: true
|
|
@@ -363,13 +408,13 @@ Page({
|
|
/**
|
|
/**
|
|
* 价格日历关闭
|
|
* 价格日历关闭
|
|
*/
|
|
*/
|
|
- close: function () {
|
|
|
|
|
|
+ close: function() {
|
|
this.setData({
|
|
this.setData({
|
|
isMoreDate: false,
|
|
isMoreDate: false,
|
|
isMask: false
|
|
isMask: false
|
|
})
|
|
})
|
|
},
|
|
},
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 获取价格
|
|
* 获取价格
|
|
*/
|
|
*/
|
|
@@ -378,36 +423,35 @@ Page({
|
|
// title: '加载中...',
|
|
// title: '加载中...',
|
|
// mask: true
|
|
// mask: true
|
|
// });
|
|
// });
|
|
- shuoAPIClient.request('/api/minapp/ticket/productPrices',
|
|
|
|
- {
|
|
|
|
- year: this.data.year,
|
|
|
|
- month: this.data.month,
|
|
|
|
- infoId: this.data.infoId
|
|
|
|
- }, false).then(res => {
|
|
|
|
- // wx.hideLoading()
|
|
|
|
- let prices = {}
|
|
|
|
- console.log('价格', res)
|
|
|
|
- if (res.data && res.data) {
|
|
|
|
- for (let data of res.data) {
|
|
|
|
- prices[data.travelDate] = data
|
|
|
|
- }
|
|
|
|
- if (!this.data.price3) { //如果前三日价格不存在则加载,存在就不变
|
|
|
|
- let price3 = []
|
|
|
|
- for (let i = 0; i < 3; i++) {
|
|
|
|
- if (res.data[i]) {
|
|
|
|
- price3.push(res.data[i])
|
|
|
|
- }
|
|
|
|
|
|
+ shuoAPIClient.request('/api/minapp/ticket/productPrices', {
|
|
|
|
+ year: this.data.year,
|
|
|
|
+ month: this.data.month,
|
|
|
|
+ infoId: this.data.infoId
|
|
|
|
+ }, false).then(res => {
|
|
|
|
+ // wx.hideLoading()
|
|
|
|
+ let prices = {}
|
|
|
|
+ console.log('价格', res)
|
|
|
|
+ if (res.data && res.data) {
|
|
|
|
+ for (let data of res.data) {
|
|
|
|
+ prices[data.travelDate] = data
|
|
|
|
+ }
|
|
|
|
+ if (!this.data.price3) { //如果前三日价格不存在则加载,存在就不变
|
|
|
|
+ let price3 = []
|
|
|
|
+ for (let i = 0; i < 3; i++) {
|
|
|
|
+ if (res.data[i]) {
|
|
|
|
+ price3.push(res.data[i])
|
|
}
|
|
}
|
|
- this.setData({
|
|
|
|
- price3: price3
|
|
|
|
- })
|
|
|
|
}
|
|
}
|
|
this.setData({
|
|
this.setData({
|
|
- prices: prices,
|
|
|
|
|
|
+ price3: price3
|
|
})
|
|
})
|
|
- console.log('prices', this.data.prices)
|
|
|
|
}
|
|
}
|
|
- })
|
|
|
|
|
|
+ this.setData({
|
|
|
|
+ prices: prices,
|
|
|
|
+ })
|
|
|
|
+ console.log('prices', this.data.prices)
|
|
|
|
+ }
|
|
|
|
+ })
|
|
},
|
|
},
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -416,21 +460,20 @@ Page({
|
|
getProdDetail() {
|
|
getProdDetail() {
|
|
let self = this
|
|
let self = this
|
|
let date = parseDate(new Date())
|
|
let date = parseDate(new Date())
|
|
- shuoAPIClient.request('/api/minapp/common/product/' + self.data.infoId,
|
|
|
|
- {
|
|
|
|
- isOrder: 1,
|
|
|
|
- travelDate: date.year + '-' + date.month + '-' +date.date
|
|
|
|
- }, false).then(res => {
|
|
|
|
- console.log('产品详情', res)
|
|
|
|
- if (res && res.data) {
|
|
|
|
- self.setData({
|
|
|
|
- prodDetail: res.data
|
|
|
|
- })
|
|
|
|
- }
|
|
|
|
- this.initLinkInfo()
|
|
|
|
- })
|
|
|
|
|
|
+ shuoAPIClient.request('/api/minapp/common/product/' + self.data.infoId, {
|
|
|
|
+ isOrder: 1,
|
|
|
|
+ travelDate: date.year + '-' + date.month + '-' + date.date
|
|
|
|
+ }, false).then(res => {
|
|
|
|
+ console.log('产品详情', res)
|
|
|
|
+ if (res && res.data) {
|
|
|
|
+ self.setData({
|
|
|
|
+ prodDetail: res.data
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+ this.initLinkInfo()
|
|
|
|
+ })
|
|
},
|
|
},
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 初始取票人信息
|
|
* 初始取票人信息
|
|
*/
|
|
*/
|
|
@@ -496,7 +539,7 @@ Page({
|
|
})
|
|
})
|
|
}
|
|
}
|
|
},
|
|
},
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 输入姓名
|
|
* 输入姓名
|
|
*/
|
|
*/
|