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.

275 lines
8.8 KiB

5 years ago
// pages/order/components/date/index.js
import commonApi from "../../../../utils/https/common"
import util from "../../../../utils/util"
let app = getApp()
Component({
/**
* 组件的属性列表
*/
options: {
styleIsolation: 'apply-shared',
addGlobalClass: true
},
properties: {
product: {
type: Object,
default: {}
},
// 是否是团体预约的场馆
isTeam: {
type: Number,
default: 0
11 months ago
},
// 日期结束天数
endDays: {
type: Number,
value: 60
5 years ago
}
},
/**
* 组件的初始数据
*/
data: {
threeDays: [],
activeDate: "",
datelist: [],
showMoreDateFlag: false,
moreFlag: true,
timelist: [],
timeIndex: 0,
isSzMuseum: false,
kjIdCom: null,
gpIdCom: null,
date_price:0,
today:util.formatDate(new Date()),
tomorrow:util.formatMing(new Date()),
afterTom:util.formatHou(new Date()),
2 years ago
skuName:'',
monthList:[]
5 years ago
},
lifetimes: {
attached: function () {
2 years ago
console.log(app.globalData.product);
let skuName = app.globalData.product.sku.sku_name
5 years ago
this.setData({
kjIdCom: app.globalData.kjId,
2 years ago
gpIdCom: app.globalData.gp_id || app.globalData.team_id,
skuName
5 years ago
})
5 years ago
// 在组件实例进入页面节点树时执行
11 months ago
let product = app.globalData.product, today = util.formatDate(new Date()), end_date = util.formatDate(new Date(new Date().getTime() + this.properties.endDays * 24 * 60 * 60 * 1000));
if (product.product.title.indexOf("苏州博物馆") != -1) {
5 years ago
this.setData({
isSzMuseum: true
5 years ago
})
}
let todayTimes = new Date(today.replace(/-/g,'/')).getTime()
commonApi.user_post("token/check").then(res => {
if (res.code == 1) {
5 years ago
// 获取价格日历
commonApi.user_post("product/product_date_price", {
start_date: today,
end_date: end_date,
sku_id: product.sku.id
}).then(res => {
for (let i = 0; i < res.data.length; i++) {
if(new Date(res.data[i].date.replace(/-/g,'/')).getTime()==todayTimes && (this.properties.isTeam || this.properties.product && this.properties.product.isTeam==1)){
// 如果是团队预约的场馆 并且是今天的话 不能预定
res.data[i].stock=0;
// res.data.price=100;
res.data[i].tipText = '不可定'
}
}
5 years ago
// 如果之前已经在详情页面选择了日期的话 默认日期不能是第一个有库存的日期了
if (app.globalData.product.infoDate) {
let dateIndex = res.data.slice(0, 3).findIndex(item => item.date == app.globalData.product.infoDate.date)
5 years ago
// if(!app.globalData.product.infoDate.short_date){
// app.globalData.product.infoDate.short_date = app.globalData.product.infoDate.date.split("-").splice(1,2).join("-")
// }
5 years ago
this.setData({
activeDate: app.globalData.product.infoDate,
moreFlag: dateIndex != -1
5 years ago
})
this.getTimeStock()
this.triggerEvent("onChangeDate", app.globalData.product.infoDate)
5 years ago
}
else {
for (let i = 0; i < res.data.length; i++) {
if (res.data[i].stock > 0) {
res.data[i].short_date = res.data[i].date.split("-").splice(1, 2).join("-")
5 years ago
this.setData({
activeDate: res.data[i]
5 years ago
})
this.getTimeStock()
this.triggerEvent("onChangeDate", this.data.activeDate)
5 years ago
break;
}
5 years ago
}
}
if (this.data.gpIdCom) {
5 years ago
// 拼团的话 价格日历无效 所有价格都是sku里面的event_price
res.data.map(item => {
5 years ago
item.price = product.sku.event_price
})
}
5 years ago
this.setData({
datelist: res.data
5 years ago
})
2 years ago
res.data.forEach(item=> {
item.short_date = item.date.split("-").splice(1, 2).join("-")
item.week = this.getDay(item.date)
})
let seldDate = ''
if (app.globalData.product.changeFlag) {
2 years ago
if( app.globalData.product.date) {
res.data.forEach(item=> {
if (item.date == app.globalData.product.date.date) {
seldDate = item
}
})
2 years ago
}
2 years ago
setTimeout(() => {
this.changeDate(seldDate)
})
2 years ago
// this.setData({
// activeDate:seldDate
// })
// this.getTimeStock()
}
5 years ago
this.setData({
2 years ago
threeDays: res.data.slice(0, 3),
monthList: res.data,
// monthList: res.data.slice(0, 30),
5 years ago
})
2 years ago
console.log(this.data.monthList);
let index = this.data.threeDays.findIndex(item => item.date == this.data.activeDate.date)
2 years ago
console.log(this.data.activeDate);
5 years ago
this.setData({
moreFlag: index != -1
5 years ago
})
5 years ago
})
}
})
5 years ago
},
detached: function () {
5 years ago
// 在组件实例被从页面节点树移除时执行
},
},
pageLifetimes: {
show: function () {
5 years ago
this.setData({
kjIdCom: app.globalData.kjId,
gpIdCom: app.globalData.gp_id || app.globalData.team_id
5 years ago
})
}
},
5 years ago
/**
* 组件的方法列表
*/
methods: {
2 years ago
getDay: function (date) {
let d = new Date(date.replace(/-/g, '/')).getDay();
let days = ["周日", "周一", "周二", "周三", "周四", "周五", "周六"];
return days[d];
},
showMoreDate: function () {
5 years ago
this.setData({
showMoreDateFlag: true
5 years ago
})
},
hideCalendar: function () {
5 years ago
this.setData({
showMoreDateFlag: false
5 years ago
})
},
changeDate: function (e) {
2 years ago
let date = e.currentTarget ? e.currentTarget.dataset.date : e
if (date.stock <= 0) return;
if (date.stock == null) return;
if (date.price == null) return;
5 years ago
this.setData({
activeDate: date,
moreFlag: true,
date_price:date.price
5 years ago
})
this.triggerEvent("onChangeDate", this.data.activeDate)
5 years ago
this.getTimeStock()
},
// 修改日期
onTapDay: function (e) {
let threeDays = this.data.threeDays, flag = false;
threeDays.map(item => {
if (item.date == e.detail.date) {
5 years ago
flag = true
}
})
e.detail.short_date = e.detail.date.substr(5, 5);
e.detail.date_price = this.data.activeDate.price;
5 years ago
this.setData({
activeDate: e.detail,
showMoreDateFlag: false,
moreFlag: flag
5 years ago
})
app.globalData.product.price = this.data.activeDate.price
this.triggerEvent("onChangeDate", this.data.activeDate)
5 years ago
this.getTimeStock()
},
getTimeStock: function () {
2 years ago
if (this.data.activeDate.is_time_stock != true) {
this.triggerEvent("onChangeTime", '')
return
};
commonApi.user_post("product/product_timestock_price", {
date: this.data.activeDate.date,
sku_id: this.data.activeDate.sku_id ? this.data.activeDate.sku_id : app.globalData.product.sku.id
}).then(res => {
5 years ago
let timeIndex = -1;
if (app.globalData.product.infoTime) {
this.triggerEvent("onChangeTime", app.globalData.product.infoTime);
timeIndex = res.data.findIndex(item => item.start_time == app.globalData.product.infoTime.start_time)
5 years ago
this.setData({
timelist: res.data,
timeIndex: timeIndex
5 years ago
})
return;
}
for (let i = 0; i < res.data.length; i++) {
2 years ago
if (res.data[i].stock_number > 0) {
2 years ago
if (app.globalData.product.changeFlag) {
if (res.data[i].start_time == app.globalData.product.time.start_time) {
timeIndex = i;
break;
}
} else {
timeIndex = i;
break;
}
5 years ago
}
}
this.setData({
timelist: res.data,
timeIndex: timeIndex
5 years ago
})
this.triggerEvent("onChangeTime", this.data.timelist[this.data.timeIndex])
5 years ago
})
app.globalData.product.price = this.data.activeDate.price
console.log('price',this.data.activeDate.price);
console.log(app.globalData.product);
5 years ago
},
selectTime: function (e) {
4 years ago
if (this.data.timelist[e.currentTarget.dataset.index].stock_number >0) {
5 years ago
this.setData({
timeIndex: e.currentTarget.dataset.index
5 years ago
})
this.triggerEvent("onChangeTime", this.data.timelist[this.data.timeIndex])
5 years ago
}
5 years ago
}
}
})