var app = getApp();
var server = require('../../utils/server');
Page({
data: {
goods: {
1: {
id: 1,
name: '娃娃菜',
pic: '../../imgs/goods/1.jpg',
sold: 1014,
price: 2,
type: '01',
},
2: {
id: 2,
name: '01',
pic: '../../imgs/goods/2.jpg',
sold: 1029,
price: 3,
type: '01',
},
3: {
id: 3,
name: '方便面',
pic: '../../imgs/goods/1.jpg',
sold: 1030,
price: 2,
type: '02',
},
4: {
id: 4,
name: '粉丝',
pic: '../../imgs/goods/1.jpg',
sold: 1059,
price: 1,
type: '01',
},
5: {
id: 5,
name: '生菜',
pic: '../../imgs/goods/1.jpg',
sold: 1029,
price: 2,
type: '02',
},
6: {
id: 6,
name: '白菜',
pic: '../../imgs/goods/1.jpg',
sold: 1064,
price: 2,
type: '03',
},
7: {
id: 7,
name: '杏鲍菇',
pic: '../../imgs/goods/1.jpg',
sold: 814,
price: 3,
type: '04',
},
8: {
id: 8,
name: '香菇',
pic: '../../imgs/goods/1.jpg',
sold: 124,
price: 3,
type: '04',
},
9: {
id: 9,
name: '猴头菇',
pic: '../../imgs/goods/2.jpg',
sold: 102,
price: 5,
type: '05',
}
},
goodsList: [
{
id: '01',
classifyName: '热销',
goods: [1,2,4]
},
{
id: '02',
classifyName: '新品',
goods: [3,5]
},
{
id: '03',
classifyName: '蔬菜',
goods: [6]
},
{
id: '04',
classifyName: '蘑菇',
goods: [7, 8]
},
{
id: '05',
classifyName: '主食',
goods: [9]
}
],
cart: {
count: 0,
total: 0,
list: {},
num:{}
},
showCartDetail: false
},
onLoad: function (options) {
var shopId = options.id;
for (var i = 0; i < app.globalData.shops.length; ++i) {
if (app.globalData.shops[i].id == shopId) {
this.setData({
shop: app.globalData.shops[i]
});
break;
}
}
},
onShow: function () {
this.setData({
classifySeleted: this.data.goodsList[0].id
});
},
//加第1步
tapAddCart: function (e) {
this.addCart(e.target.dataset.id, e.target.dataset.type);
},
//减第1步
tapReduceCart: function (e) {
this.reduceCart(e.target.dataset.id,e.target.dataset.type);
},
//加第2步
addCart: function (id, type) {
var num = this.data.cart.list[id] || 0;
var num2 = this.data.cart.num[type] || 0;
this.data.cart.list[id] = num + 1;
let a = this.data.goodsList;
console.log(a[0].id);
for(var i=0;i<a.length;i++){
if(type == a[i].id){
this.data.cart.num[type] = num2 + 1;
}
}
this.countCart();
},
//减第2步
reduceCart: function (id,type) {
var num = this.data.cart.list[id] || 0;
var num2 = this.data.cart.num[type];
let a = this.data.goodsList;
if (num <= 1) {
delete this.data.cart.list[id];
} else {
this.data.cart.list[id] = num - 1;
}
for (var i = 0; i < a.length; i++) {
if (type == a[i].id) {
this.data.cart.num[type] = num2 - 1;
}
}
this.countCart();
},
// 加减走后一步
countCart: function () {
var count = 0,
total = 0;
for (var id in this.data.cart.list) {
var goods = this.data.goods[id];
count += this.data.cart.list[id];
total += goods.price * this.data.cart.list[id];
}
this.data.cart.count = count;
this.data.cart.total = total;
this.setData({
cart: this.data.cart
});
},
follow: function () {
this.setData({
followed: !this.data.followed
});
},
onGoodsScroll: function (e) {
if (e.detail.scrollTop > 10 && !this.data.scrollDown) {
this.setData({
scrollDown: true
});
} else if (e.detail.scrollTop < 10 && this.data.scrollDown) {
this.setData({
scrollDown: false
});
}
var scale = e.detail.scrollWidth / 570,
scrollTop = e.detail.scrollTop / scale,
h = 0,
classifySeleted,
len = this.data.goodsList.length;
this.data.goodsList.forEach(function (classify, i) {
var _h = 70 + classify.goods.length * (46 * 3 + 20 * 2);
if (scrollTop >= h - 100 / scale) {
classifySeleted = classify.id;
}
h += _h;
});
this.setData({
classifySeleted: classifySeleted
});
},
tapClassify: function (e) {
var id = e.target.dataset.id;
this.setData({
classifyViewed: id
});
var self = this;
setTimeout(function () {
self.setData({
classifySeleted: id
});
}, 100);
},
showCartDetail: function () {
this.setData({
showCartDetail: !this.data.showCartDetail
});
},
hideCartDetail: function () {
this.setData({
showCartDetail: false
});
},
submit: function (e) {
server.sendTemplate(e.detail.formId, null, function (res) {
if (res.data.errorcode == 0) {
wx.showModal({
showCancel: false,
title: '恭喜',
content: '订单发送成功!下订单过程顺利完成,本例不再进行后续订单相关的功能。',
success: function(res) {
if (res.confirm) {
wx.navigateBack();
}
}
})
}
}, function (res) {
console.log(res)
});
}
});
没有合适的资源?快使用搜索试试~ 我知道了~
小程序外卖点餐购物车效果
共59个文件
jpg:18个
png:10个
js:9个
4星 · 超过85%的资源 需积分: 49 66 下载量 19 浏览量
2018-07-02
17:19:12
上传
评论 1
收藏 123KB ZIP 举报
温馨提示
具体效果https://www.jianshu.com/p/5297bb542e2a,只有点餐的效果,价格和数量的计算。
资源推荐
资源详情
资源评论
收起资源包目录
cart.zip (59个子文件)
cart
app.js 1KB
utils
server.js 1KB
imgs
shop
add1.png 245B
plus.png 1KB
reduce.png 192B
cart.png 4KB
tabBar
mine_1.png 3KB
home_1.png 2KB
mine_2.png 2KB
home_2.png 2KB
index
icon_6.jpg 5KB
icon_14.jpg 5KB
icon_location.png 2KB
icon_15.jpg 5KB
icon_9.jpg 6KB
icon_5.jpg 5KB
icon_3.jpg 4KB
icon_4.jpg 5KB
icon_11.jpg 4KB
icon_2.jpg 5KB
icon_8.jpg 4KB
icon_12.jpg 5KB
icon_1.jpg 5KB
icon_10.jpg 6KB
icon_7.jpg 4KB
icon_16.jpg 5KB
icon_search.png 1KB
icon_13.jpg 5KB
goods
1.jpg 6KB
2.jpg 6KB
page
shop
test.json 2B
test.wxml 60B
test.js 330B
shop.js 5KB
shop.wxss 5KB
test.wxss 25B
shop.wxml 3KB
shop.json 2B
mine
mine.js 200B
mine.wxml 842B
mine.wxss 653B
mine.json 2B
index
search.wxml 1KB
search.json 45B
index.wxml 2KB
index.js 4KB
search.js 1KB
index.wxss 3KB
search.wxss 1KB
index.json 2B
order
order.wxml 18B
order.js 90B
test
test.json 2B
test.wxml 987B
test.js 5KB
test.wxss 4KB
.gitattributes 378B
app.json 908B
app.wxss 461B
共 59 条
- 1
资源评论
- 1210172018-08-16还行吧,没有两个列表点击联动效果联动KK的猫咪2019-09-12左右联动。如果数据量比较少的话,可以用原生的。百度能找到一大推demo。如果数据量很大,使用框架可以解决
- moor25502018-07-02看着不错,我要用一下那个数量加减功能,还需要sku加入购物车功能,楼主有吗?
KK的猫咪
- 粉丝: 1
- 资源: 4
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功