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.

148 lines
3.7 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:{}
}
},
/**
* 组件的初始数据
*/
data: {
threeDays:[],
activeDate:"",
datelist:[],
showMoreDateFlag:false,
moreFlag:true,
timelist:[],
timeIndex:0
},
lifetimes: {
attached: function() {
// 在组件实例进入页面节点树时执行
let product = app.globalData.product,today = util.formatDate(new Date()),end_date = util.formatDate(new Date(new Date().getTime() + 60 * 24 * 60 * 60 * 1000));
commonApi.user_post("token/check").then(res=>{
if(res.code==1){
// 获取价格日历
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(res.data[i].stock>0){
this.setData({
activeDate:res.data[i]
})
this.getTimeStock()
this.triggerEvent("onChangeDate",this.data.activeDate)
break;
}
}
this.setData({
datelist:res.data
})
this.setData({
threeDays:res.data.slice(0,3)
})
console.log(res)
})
}
})
},
detached: function() {
// 在组件实例被从页面节点树移除时执行
},
},
/**
* 组件的方法列表
*/
methods: {
showMoreDate:function(){
this.setData({
showMoreDateFlag:true
})
},
hideCalendar:function(){
this.setData({
showMoreDateFlag:false
})
},
changeDate:function(e){
let date = e.currentTarget.dataset.date;
if(date.stock<=0) return;
if(date.stock==null) return;
if(date.price==null) return;
this.setData({
activeDate:date,
moreFlag:true
})
this.triggerEvent("onChangeDate",this.data.activeDate)
this.getTimeStock()
},
// 修改日期
onTapDay:function(e){
console.log(e)
let threeDays = this.data.threeDays,flag=false;
threeDays.map(item=>{
if(item.date==e.detail.date){
flag = true
}
})
e.detail.short_date = e.detail.date.substr(5,5);
console.log(e.detail)
this.setData({
activeDate:e.detail,
showMoreDateFlag:false,
moreFlag:flag
})
this.triggerEvent("onChangeDate",this.data.activeDate)
this.getTimeStock()
},
getTimeStock:function(){
if(this.data.activeDate.is_time_stock!=true) return;
commonApi.user_post("product/product_timestock_price",{
date:this.data.activeDate.date,
sku_id:app.globalData.product.sku.id
}).then(res=>{
let timeIndex = -1;
for(let i=0;i<res.data.length;i++){
if(res.data[i].stock_number>0){
timeIndex = i;
break;
}
}
this.setData({
timelist:res.data,
timeIndex:timeIndex
})
this.triggerEvent("onChangeTime",this.data.timelist[this.data.timeIndex])
})
},
selectTime:function(e){
if(this.data.timelist[e.currentTarget.dataset.index].stock_number!=0){
this.setData({
timeIndex:e.currentTarget.dataset.index
})
this.triggerEvent("onChangeTime",this.data.timelist[this.data.timeIndex])
}
}
}
})