//index.js
var app = getApp()
Page({
data: {
goodsList:{
saveHidden:true,
totalPrice:0,
allSelect:true,
noSelect:false,
list:[]
},
delBtnWidth:120, //删除按钮宽度单位(rpx)
},
//获取元素自适应后的实际宽度
getEleWidth:function(w){
var real = 0;
try {
var res = wx.getSystemInfoSync().windowWidth;
var scale = (750/2)/(w/2); //以宽度750px设计稿做宽度的自适应
// console.log(scale);
real = Math.floor(res/scale);
return real;
} catch (e) {
return false;
// Do something when catch error
}
},
initEleWidth:function(){
var delBtnWidth = this.getEleWidth(this.data.delBtnWidth);
this.setData({
delBtnWidth:delBtnWidth
});
},
onLoad: function () {
this.initEleWidth();
this.onShow();
},
onShow: function(){
var shopList = [];
// 获取购物车数据
var shopCarInfoMem = wx.getStorageSync('shopCarInfo');
if (shopCarInfoMem && shopCarInfoMem.shopList) {
shopList = shopCarInfoMem.shopList
}
this.data.goodsList.list = shopList;
this.setGoodsList(this.getSaveHide(),this.totalPrice(),this.allSelect(),this.noSelect(),shopList);
},
toIndexPage:function(){
wx.switchTab({
url: "/pages/index/index"
});
},
touchS:function(e){
if(e.touches.length==1){
this.setData({
startX:e.touches[0].clientX
});
}
},
touchM:function(e){
var index = e.currentTarget.dataset.index;
if(e.touches.length==1){
var moveX = e.touches[0].clientX;
var disX = this.data.startX - moveX;
var delBtnWidth = this.data.delBtnWidth;
var left = "";
if(disX == 0 || disX < 0){//如果移动距离小于等于0,container位置不变
left = "margin-left:0px";
}else if(disX > 0 ){//移动距离大于0,container left值等于手指移动距离
left = "margin-left:-"+disX+"px";
if(disX>=delBtnWidth){
left = "left:-"+delBtnWidth+"px";
}
}
var list = this.data.goodsList.list;
if(index!="" && index !=null){
list[parseInt(index)].left = left;
this.setGoodsList(this.getSaveHide(),this.totalPrice(),this.allSelect(),this.noSelect(),list);
}
}
},
touchE:function(e){
var index = e.currentTarget.dataset.index;
if(e.changedTouches.length==1){
var endX = e.changedTouches[0].clientX;
var disX = this.data.startX - endX;
var delBtnWidth = this.data.delBtnWidth;
//如果距离小于删除按钮的1/2,不显示删除按钮
var left = disX > delBtnWidth/2 ? "margin-left:-"+delBtnWidth+"px":"margin-left:0px";
var list = this.data.goodsList.list;
if(index!=="" && index != null){
list[parseInt(index)].left = left;
this.setGoodsList(this.getSaveHide(),this.totalPrice(),this.allSelect(),this.noSelect(),list);
}
}
},
delItem:function(e){
var index = e.currentTarget.dataset.index;
var list = this.data.goodsList.list;
list.splice(index,1);
this.setGoodsList(this.getSaveHide(),this.totalPrice(),this.allSelect(),this.noSelect(),list);
},
selectTap:function(e){
var index = e.currentTarget.dataset.index;
var list = this.data.goodsList.list;
if(index!=="" && index != null){
list[parseInt(index)].active = !list[parseInt(index)].active ;
this.setGoodsList(this.getSaveHide(),this.totalPrice(),this.allSelect(),this.noSelect(),list);
}
},
totalPrice:function(){
var list = this.data.goodsList.list;
var total = 0;
for(var i = 0 ; i < list.length ; i++){
var curItem = list[i];
if(curItem.active){
total+= parseFloat(curItem.price)*curItem.number;
}
}
total = parseFloat(total.toFixed(2));//js浮点计算bug,取两位小数精度
return total;
},
allSelect:function(){
var list = this.data.goodsList.list;
var allSelect = false;
for(var i = 0 ; i < list.length ; i++){
var curItem = list[i];
if(curItem.active){
allSelect = true;
}else{
allSelect = false;
break;
}
}
return allSelect;
},
noSelect:function(){
var list = this.data.goodsList.list;
var noSelect = 0;
for(var i = 0 ; i < list.length ; i++){
var curItem = list[i];
if(!curItem.active){
noSelect++;
}
}
if(noSelect == list.length){
return true;
}else{
return false;
}
},
setGoodsList:function(saveHidden,total,allSelect,noSelect,list){
this.setData({
goodsList:{
saveHidden:saveHidden,
totalPrice:total,
allSelect:allSelect,
noSelect:noSelect,
list:list
}
});
var shopCarInfo = {};
var tempNumber = 0;
shopCarInfo.shopList = list;
for(var i = 0;i<list.length;i++){
tempNumber = tempNumber + list[i].number
}
shopCarInfo.shopNum = tempNumber;
wx.setStorage({
key:"shopCarInfo",
data:shopCarInfo
})
},
bindAllSelect:function(){
var currentAllSelect = this.data.goodsList.allSelect;
var list = this.data.goodsList.list;
if(currentAllSelect){
for(var i = 0 ; i < list.length ; i++){
var curItem = list[i];
curItem.active = false;
}
}else{
for(var i = 0 ; i < list.length ; i++){
var curItem = list[i];
curItem.active = true;
}
}
this.setGoodsList(this.getSaveHide(),this.totalPrice(),!currentAllSelect,this.noSelect(),list);
},
jiaBtnTap:function(e){
var index = e.currentTarget.dataset.index;
var list = this.data.goodsList.list;
if(index!=="" && index != null){
if(list[parseInt(index)].number<10){
list[parseInt(index)].number++;
this.setGoodsList(this.getSaveHide(),this.totalPrice(),this.allSelect(),this.noSelect(),list);
}
}
},
jianBtnTap:function(e){
var index = e.currentTarget.dataset.index;
var list = this.data.goodsList.list;
if(index!=="" && index != null){
if(list[parseInt(index)].number>1){
list[parseInt(index)].number-- ;
this.setGoodsList(this.getSaveHide(),this.totalPrice(),this.allSelect(),this.noSelect(),list);
}
}
},
editTap:function(){
var list = this.data.goodsList.list;
for(var i = 0 ; i < list.length ; i++){
var curItem = list[i];
curItem.active = false;
}
this.setGoodsList(!this.getSaveHide(),this.totalPrice(),this.allSelect(),this.noSelect(),list);
},
saveTap:function(){
var list = this.data.goodsList.list;
for(var i = 0 ; i < list.length ; i++){
var curItem = list[i];
curItem.active = true;
}
this.setGoodsList(!this.getSaveHide(),this.totalPrice(),this.allSelect(),this.noSelect(),list);
},
getSaveHide:function(){
var saveHidden = this.data.goodsList.saveHidden;
return saveHidden;
},
deleteSelected:function(){
var list = this.data.goodsList.list;
/*
for(let i = 0 ; i < list.length ; i++){
let curItem = list[i];
if(curItem.active){
list.splice(i,1);
}
}
*/
// above codes that remove elements in a for statement may change the length of list dynamically
list = list.filter(function(curGoods) {
return !curGoods.active;
});
this.setGoodsList(this.getSaveHide(),this.totalPrice(),this.allSelect(),this.noSelect(),list);
},
toPayOrder:function(){
wx.showLoading();
var that = this;
if (this.data.goodsList.noSelect) {
wx.hideLoading();
return;
}
// 重新计算价格,判断库存
var
没有合适的资源?快使用搜索试试~ 我知道了~
基于JavaScript开发的智慧社区小程序源码(课设项目).zip
共477个文件
js:130个
wxss:93个
json:84个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 70 浏览量
2023-07-28
13:50:37
上传
评论 1
收藏 1.72MB ZIP 举报
温馨提示
基于JavaScript开发的智慧社区小程序源码(课设项目).zip 基于JavaScript开发的智慧社区小程序源码(课设项目).zip 基于JavaScript开发的智慧社区小程序源码(课设项目).zip 基于JavaScript开发的智慧社区小程序源码(课设项目).zip 基于JavaScript开发的智慧社区小程序源码(课设项目).zip基于JavaScript开发的智慧社区小程序源码(课设项目).zip基于JavaScript开发的智慧社区小程序源码(课设项目).zip基于JavaScript开发的智慧社区小程序源码(课设项目).zip基于JavaScript开发的智慧社区小程序源码(课设项目).zip基于JavaScript开发的智慧社区小程序源码(课设项目).zip基于JavaScript开发的智慧社区小程序源码(课设项目).zip基于JavaScript开发的智慧社区小程序源码(课设项目).zip基于JavaScript开发的智慧社区小程序源码(课设项目).zip
资源推荐
资源详情
资源评论
收起资源包目录
基于JavaScript开发的智慧社区小程序源码(课设项目).zip (477个子文件)
saoxue.jpeg 183KB
shequ.jpeg 138KB
yiqing.jpeg 136KB
saoxue.jpg 749KB
touxiang.jpg 43KB
shequ2.jpg 43KB
index.js 11KB
add.js 9KB
index.js 6KB
app.js 5KB
index.js 5KB
index.js 5KB
changePhone.js 4KB
index.js 4KB
transition.js 4KB
add.js 4KB
util.js 4KB
index.js 4KB
index.js 3KB
index.js 3KB
component.js 3KB
feedback.js 3KB
index.js 3KB
index.js 3KB
countdown.js 3KB
index.js 2KB
index.js 2KB
index.js 2KB
index.js 2KB
index.js 2KB
index.js 2KB
index.js 2KB
index.js 2KB
index.js 2KB
util.js 2KB
index.js 2KB
toLogin.js 2KB
index.js 2KB
index.js 2KB
index.js 2KB
index.js 2KB
type.js 2KB
index.js 2KB
index.js 2KB
index.js 1KB
index.js 1KB
index.js 1KB
index.js 1KB
index.js 1KB
index.js 1KB
rules.js 1KB
messages.js 1KB
index.js 1KB
index.js 1KB
index.js 1KB
index.js 1KB
index.js 1KB
index.js 1KB
touch.js 1KB
index.js 1KB
index.js 1010B
index.js 994B
index.js 988B
index.js 960B
index.js 923B
index.js 912B
index.js 894B
index.js 873B
index.js 849B
index.js 845B
index.js 845B
index.js 844B
add.js 843B
index.js 838B
index.js 830B
basic.js 824B
utils.js 797B
info.js 771B
index.js 742B
eventBus.js 720B
index.js 689B
range.js 683B
index.js 682B
scrollCenter.js 682B
open-type.js 674B
index.js 643B
index.js 615B
index.js 587B
index.js 583B
index.js 539B
index.js 529B
utils.js 489B
index.js 462B
button.js 442B
index.js 441B
index.js 440B
index.js 435B
string.js 422B
pattern.js 402B
shared.js 388B
共 477 条
- 1
- 2
- 3
- 4
- 5
资源评论
z同学的编程之路
- 粉丝: 1813
- 资源: 2129
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- Surfer,线性函数
- MyBatis 的动态 SQL 是其核心特性之一.txt
- 时代的sdddsddsddsd
- 基于哈希链表的简单人员信息管理系统
- 其他类别JdonFramework开源框架 v5.1 Build20071025-jdonframework-5.1.rar
- 2001~2022年上市公司数字赋能指数.dta
- 2001~2022年上市公司数字赋能指数.xlsx
- 信息办公石大在线财务管理系统(含源码)-shidacaiwu.rar
- 信息办公电信计费系统完整代码-netctossconformity.rar
- matlab实现TD-SCDMA中初始同步捕捉DwPTS下行同步导频时隙的仿真.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功