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.
390 lines
11 KiB
390 lines
11 KiB
// pages/order/show/index.js
|
|
let app = getApp();
|
|
import commonApi from "../../../utils/https/common"
|
|
import util from "../../../utils/util"
|
|
Page({
|
|
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
productId: null,
|
|
dateArr: [],
|
|
times:[],
|
|
skuArr: [],
|
|
product:null,
|
|
dateindex:-1,
|
|
timeindex:-1,
|
|
skuindex: -1,
|
|
|
|
selectSku: {price:0},
|
|
|
|
activeDate: {date: ''},
|
|
noStock: false,
|
|
|
|
cartTop: 0,
|
|
cartImgInfo: null,
|
|
cartCount: 0,
|
|
|
|
// 日历
|
|
showMoreDateFlag: false,
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
onLoad: function (options) {
|
|
let that = this
|
|
let id = options.id
|
|
this.setData({
|
|
productId: id
|
|
})
|
|
// let product = app.globalData.product
|
|
// console.log(product)
|
|
// this.setData({
|
|
// product:product,
|
|
// })
|
|
|
|
this.getProductDetail()
|
|
|
|
},
|
|
|
|
// 获取商品详情
|
|
getProductDetail () {
|
|
commonApi._post("product/get_product_detail", {
|
|
id: this.data.productId
|
|
}).then(res => {
|
|
res.data.flag = res.data.sku.find(item => item.flag == 'on') ? res.data.flag : 0
|
|
let resData = res.data
|
|
this.setData({
|
|
product: resData,
|
|
})
|
|
|
|
this.initDate()
|
|
})
|
|
},
|
|
|
|
getDay: function (date) {
|
|
let d = new Date(date.replace(/-/g, '/')).getDay();
|
|
let days = ["周日", "周一", "周二", "周三", "周四", "周五", "周六"];
|
|
return days[d];
|
|
},
|
|
|
|
showMoreDate: function () {
|
|
this.setData({
|
|
showMoreDateFlag: true
|
|
})
|
|
},
|
|
hideCalendar: function () {
|
|
this.setData({
|
|
showMoreDateFlag: false
|
|
})
|
|
},
|
|
|
|
// 修改日期
|
|
onTapDay: function (e) {
|
|
console.log(e.detail)
|
|
let date = e.detail.date
|
|
let index = this.data.dateArr.findIndex(v=>v.date==date)
|
|
|
|
let param = {currentTarget: {dataset: {date: index}}}
|
|
if (index>=0) {
|
|
this.changeDate(param)
|
|
this.hideCalendar()
|
|
}
|
|
},
|
|
// 初始化日期
|
|
initDate () {
|
|
let _this = this
|
|
// 设置90天日期
|
|
let dateArr = []
|
|
let now = new Date().getTime()
|
|
for(let i=0 ;i<=90;i++) {
|
|
let date = now+i*24*60*60*1000
|
|
dateArr.push({date: util.formatDate(new Date(date))})
|
|
}
|
|
|
|
dateArr.forEach(v=>{
|
|
v.short_date = v.date.split("-").splice(1, 2).join("-")
|
|
})
|
|
this.setData({dateArr: dateArr})
|
|
// 默认选中第一天
|
|
let param = {currentTarget: {dataset: {date: 0}}}
|
|
this.changeDate(param)
|
|
// console.log(dateArr)
|
|
setTimeout(() => {
|
|
this.setPriceCalendar()
|
|
}, 500);
|
|
},
|
|
|
|
// 选择日期
|
|
changeDate:function(e){
|
|
let _this = this
|
|
let dateindex = e.currentTarget.dataset.date
|
|
let date = this.data.dateArr[dateindex]
|
|
let activeDate = {date: date.date}
|
|
// 获取时间
|
|
commonApi.user_post("product/get_time_slots", {
|
|
product_id: _this.data.product.id,
|
|
date: date.date
|
|
}).then(res => {
|
|
console.log(res)
|
|
let week = _this.getDay(res.data.date)
|
|
let times = res.data.time_slots
|
|
times.forEach(v=>{
|
|
v.sale_date = res.data.date
|
|
v.week = week
|
|
})
|
|
console.log(times)
|
|
|
|
let timeindex = times.findIndex(v=>v.total_stock>0 && v.skus.some(x=>x.stock_number>0))
|
|
|
|
this.setData({
|
|
dateindex: dateindex,
|
|
activeDate:activeDate,
|
|
times: times,
|
|
timeindex: -1,
|
|
skuindex: -1,
|
|
selectSku: {price:0}
|
|
})
|
|
|
|
if (timeindex>=0) {
|
|
let param = {currentTarget: {dataset: {date: timeindex}}}
|
|
this.changeTime(param)
|
|
}
|
|
this.judgeNoStock()
|
|
|
|
})
|
|
|
|
|
|
},
|
|
|
|
// 选择时间
|
|
changeTime:function(e){
|
|
console.log(e.currentTarget.dataset)
|
|
let dateindex = e.currentTarget.dataset.date;
|
|
let time = this.data.times[dateindex]
|
|
let skuArr = time.skus || []
|
|
console.log(time)
|
|
if (time.total_stock<=0) { return}
|
|
|
|
//给sku设置余票
|
|
this.setData({
|
|
timeindex: dateindex,
|
|
skuArr: skuArr,
|
|
skuindex: -1,
|
|
selectSku: {price:0}
|
|
})
|
|
let trueSkuIndex = skuArr.findIndex(v=>v.stock_number>0)
|
|
if (trueSkuIndex>=0) {
|
|
let param = {currentTarget: {dataset: {date: trueSkuIndex}}}
|
|
this.changeSku(param)
|
|
}
|
|
},
|
|
|
|
// 选择sku
|
|
changeSku:function(e){
|
|
console.log(e.currentTarget.dataset)
|
|
let dateindex = e.currentTarget.dataset.date;
|
|
let sku = this.data.skuArr[dateindex]
|
|
if (sku.stock_number<=0) { return }
|
|
this.setData({
|
|
skuindex: dateindex,
|
|
selectSku: sku
|
|
})
|
|
},
|
|
|
|
judgeNoStock () {
|
|
let times = this.data.times
|
|
let data = times.length<=0 || times.every(v=>v.total_stock<=0)
|
|
this.setData({
|
|
noStock: data
|
|
})
|
|
},
|
|
|
|
showOrder:function(){
|
|
let date = this.data.dateArr[this.data.dateindex]
|
|
if (!date) {
|
|
wx.showToast({title: '请选择日期',icon: "none"});
|
|
return
|
|
}
|
|
date.week = this.getDay(date.date)
|
|
|
|
let time = this.data.times[this.data.timeindex]
|
|
if (!time) {
|
|
wx.showToast({title: '请选择场次',icon: "none"});
|
|
return
|
|
}
|
|
|
|
if (this.data.skuindex<0) {
|
|
wx.showToast({title: '请选择票档',icon: "none"});
|
|
return
|
|
}
|
|
|
|
let product = this.data.product
|
|
console.log(product)
|
|
let skuSelect = this.data.skuArr[this.data.skuindex]
|
|
let sku = this.data.product.sku.find(v=>v.id == skuSelect.id)
|
|
sku = JSON.parse(JSON.stringify(sku))
|
|
sku.display_tags = sku.display_tags?sku.display_tags.split(","):[];
|
|
|
|
|
|
|
|
// commonApi.user_post("/product/checkStock", {
|
|
// sku_id: sku.id
|
|
// }).then(res => {
|
|
// if (res && res.code != 1) {
|
|
// wx.showModal({
|
|
// title: "温馨提示",
|
|
// content: '商品已经被抢光啦~要不要瞧瞧别的~',
|
|
// showCancel: false
|
|
// })
|
|
// return;
|
|
// } else {
|
|
app.globalData.postProduct = []
|
|
app.globalData.list = []
|
|
app.globalData.listName = null
|
|
|
|
if (product.flag==0 || sku.flag=='off') return;
|
|
// if (e.currentTarget.dataset.disable === 1) return;
|
|
// util.pagePoint({
|
|
// event: 'scene_order',
|
|
// param: {
|
|
// type: this.data.info.type,
|
|
// id: this.data.info.id
|
|
// }
|
|
// }, 1)
|
|
// wx.setStorageSync('login_from', 'scene_order_login')
|
|
// wx.setStorageSync('order_from', 'scene_order_submit')
|
|
app.globalData.couponInfo = null;
|
|
// app.globalData.retailId = this.data.retailId;
|
|
|
|
app.globalData.product = {
|
|
product: {...product, price: skuSelect.price},
|
|
sku: sku
|
|
}
|
|
|
|
date.price = skuSelect.price
|
|
app.globalData.product.date = date
|
|
app.globalData.product.time = time
|
|
app.globalData.product.price = skuSelect.price
|
|
app.globalData.product.productNum = 1
|
|
console.log(app.globalData.product)
|
|
app.globalData.index = 0
|
|
wx.navigateTo({
|
|
url: '/pages/order/showOrderNew/index',
|
|
})
|
|
// }
|
|
|
|
// })
|
|
},
|
|
|
|
|
|
setPriceCalendar () {
|
|
let _this = this
|
|
let skus = this.data.product.sku || []
|
|
wx.showLoading()
|
|
Promise.all(skus.map(x=>commonApi.user_post("product/product_date_price", {
|
|
start_date: _this.data.dateArr[0].date,
|
|
end_date: _this.data.dateArr[this.data.dateArr.length-1].date,
|
|
sku_id: x.id
|
|
}))).then((res)=>{
|
|
let timData = res.map(v=>v.data)
|
|
|
|
_this.data.dateArr.forEach((item,i)=>{
|
|
item.haveStock = timData.some(x=>x[i].stock>0)
|
|
})
|
|
console.log(_this.data.dateArr)
|
|
_this.setData({
|
|
dateArr: _this.data.dateArr
|
|
})
|
|
}).finally(()=>{
|
|
wx.hideLoading();
|
|
})
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
*/
|
|
onReady: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面显示
|
|
*/
|
|
onShow: function () {
|
|
// this.getCartNum()
|
|
},
|
|
|
|
// 获取购物车数量
|
|
getCartNum () {
|
|
commonApi.user_post('cart/get_list', {}).then(res => {
|
|
this.setData({
|
|
cartCount: res.data.length
|
|
})
|
|
})
|
|
},
|
|
// 加入购物车
|
|
showCart: function () {
|
|
commonApi.user_post('wx/get_user_keep', {
|
|
jumpurl: '/pages/info/postProductInfo/index?id=' + this.data.id,
|
|
title: this.data.info.title,
|
|
type: 'mini'
|
|
}).then(res => {
|
|
if (res.data.subscribe == 0) {
|
|
this.setData({
|
|
wxqrcode: res.data.qrcode,
|
|
showQrCode: true
|
|
})
|
|
} else {
|
|
if (this.data.info.sku.length == 0) {
|
|
wx.showToast({
|
|
title: '该产品未设置规格,不能加购',
|
|
icon: 'none'
|
|
})
|
|
return;
|
|
}
|
|
this.setData({
|
|
skuFlag: "cart"
|
|
})
|
|
let that = this
|
|
wx.createSelectorQuery().select('#skuImg').boundingClientRect(function (res) {
|
|
console.log(res)
|
|
that.setData({
|
|
cartImgInfo: 'top:' + res.top + 'px;left:' + res.left + 'px;'
|
|
})
|
|
}).exec()
|
|
}
|
|
})
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面隐藏
|
|
*/
|
|
onHide: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面卸载
|
|
*/
|
|
onUnload: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
*/
|
|
onPullDownRefresh: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 页面上拉触底事件的处理函数
|
|
*/
|
|
onReachBottom: function () {
|
|
|
|
}
|
|
})
|