2024-11-15 03:51:28 +00:00
|
|
|
import {url} from '../request'
|
2024-11-19 10:12:40 +00:00
|
|
|
|
2024-11-10 07:01:22 +00:00
|
|
|
Page({
|
2024-11-15 03:51:28 +00:00
|
|
|
data: {
|
2024-11-19 10:12:40 +00:00
|
|
|
commoditiesImage: '',
|
|
|
|
commoditiesPrice: '',
|
|
|
|
commoditiesName: '',
|
|
|
|
businessId: '',
|
|
|
|
ids: '',
|
2024-12-17 11:46:10 +00:00
|
|
|
time: [
|
|
|
|
{ title: '9:00' },
|
|
|
|
{ title: '10:00' },
|
|
|
|
{ title: '11:00' },
|
|
|
|
{ title: '12:00' },
|
|
|
|
{ title: '13:00' },
|
|
|
|
{ title: '14:00' },
|
|
|
|
{ title: '15:00' },
|
|
|
|
{ title: '16:00' },
|
|
|
|
{ title: '17:00' },
|
2024-11-19 10:12:40 +00:00
|
|
|
],
|
2024-12-17 11:46:10 +00:00
|
|
|
selectedTime: '',
|
2024-11-15 03:51:28 +00:00
|
|
|
},
|
|
|
|
|
2024-11-19 10:12:40 +00:00
|
|
|
onLoad(options) {
|
|
|
|
const commoditiesImage = options.commoditiesImage;
|
|
|
|
const commoditiesName = options.commoditiesName;
|
|
|
|
const commoditiesPrice = options.commoditiesPrice;
|
|
|
|
const ids = options.ids;
|
|
|
|
const businessId = options.businessId;
|
|
|
|
|
|
|
|
this.setData({
|
|
|
|
commoditiesImage: commoditiesImage,
|
|
|
|
commoditiesName: commoditiesName,
|
|
|
|
commoditiesPrice: commoditiesPrice,
|
|
|
|
ids: ids,
|
|
|
|
businessId: businessId,
|
|
|
|
});
|
|
|
|
|
2024-11-15 03:51:28 +00:00
|
|
|
},
|
2024-11-19 10:12:40 +00:00
|
|
|
|
2024-11-15 03:51:28 +00:00
|
|
|
// 切换标签
|
|
|
|
onChange(current) {
|
|
|
|
this.setData({
|
2024-11-19 10:12:40 +00:00
|
|
|
current,
|
2024-11-15 03:51:28 +00:00
|
|
|
});
|
2024-11-19 10:12:40 +00:00
|
|
|
},
|
2024-12-17 11:46:10 +00:00
|
|
|
onSwipeChange(e) {
|
|
|
|
this.setData({
|
|
|
|
current: e.detail.current,
|
|
|
|
});
|
|
|
|
},
|
2024-11-19 10:12:40 +00:00
|
|
|
onShow(){
|
|
|
|
this.checkUserLogin
|
|
|
|
},
|
|
|
|
// 检查登录状态
|
|
|
|
checkUserLogin() {
|
|
|
|
my.getStorages({
|
|
|
|
key: 'userInfo',
|
|
|
|
success: (res) => {
|
|
|
|
if (res.data && res.data.openId) {
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
}
|
|
|
|
},
|
|
|
|
fail: (err) => {
|
|
|
|
console.error('获取用户信息失败:', err);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
jiaru() {
|
|
|
|
my.getStorage({
|
|
|
|
key: 'userInfo',
|
|
|
|
success: (res) => {
|
2024-12-17 11:46:10 +00:00
|
|
|
const userInfo = res.data;
|
|
|
|
if (userInfo && userInfo.cookie) {
|
|
|
|
my.request({
|
|
|
|
url: url + '/api/cart/add',
|
|
|
|
method: 'POST',
|
|
|
|
data: {
|
|
|
|
businessId: this.data.businessId,
|
|
|
|
commoditiesId: this.data.ids,
|
|
|
|
quantity: 1,
|
|
|
|
selectedOptions: "",
|
|
|
|
},
|
|
|
|
headers: {
|
|
|
|
'content-type': 'application/json',
|
|
|
|
'Cookie': userInfo.cookie, // 通过头部传递 cookie
|
|
|
|
},
|
|
|
|
dataType: 'json',
|
|
|
|
success: (res) => {
|
|
|
|
if(res.data.code===0){
|
|
|
|
console.log(res);
|
|
|
|
my.alert({ content: '成功添加到购物车' });
|
|
|
|
}
|
|
|
|
else if(res.data.code===40100){
|
|
|
|
my.alert({
|
|
|
|
content: '登录信息已过期,请重新登录'
|
|
|
|
});
|
|
|
|
my.navigateTo({
|
|
|
|
url:'/pages/denglu/denglu'
|
|
|
|
})
|
|
|
|
}
|
|
|
|
},
|
|
|
|
fail: (error) => {
|
|
|
|
console.error('请求失败: ', JSON.stringify(error));
|
|
|
|
my.alert({ content: '请求失败,请稍后重试' });
|
|
|
|
},
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
my.alert({
|
|
|
|
content: '您未登录,请先登录。',
|
|
|
|
success: () => {
|
|
|
|
my.navigateTo({
|
|
|
|
url: '/pages/denglu/denglu',
|
|
|
|
});
|
|
|
|
},
|
2024-11-19 10:12:40 +00:00
|
|
|
});
|
2024-12-17 11:46:10 +00:00
|
|
|
}
|
2024-11-19 10:12:40 +00:00
|
|
|
},
|
2024-12-17 11:46:10 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
selectTime(e) {
|
|
|
|
const selectedTime = e.currentTarget.dataset.time; // 获取点击的时间
|
|
|
|
console.log(selectedTime);
|
|
|
|
this.setData({
|
|
|
|
selectedTime: selectedTime, // 更新选中的时间
|
2024-11-19 10:12:40 +00:00
|
|
|
});
|
2024-12-17 11:46:10 +00:00
|
|
|
console.log('选中的时间:', this.data.selectedTime); // 打印选中的时间
|
2024-11-19 10:12:40 +00:00
|
|
|
},
|
2024-11-10 07:01:22 +00:00
|
|
|
});
|