131 lines
3.4 KiB
JavaScript
131 lines
3.4 KiB
JavaScript
// var app = getApp();
|
||
Component({
|
||
properties: {
|
||
goods: {
|
||
type: null
|
||
},
|
||
text: {
|
||
type: null
|
||
},
|
||
num: {
|
||
type: null
|
||
},
|
||
loading: {
|
||
type: null
|
||
}
|
||
},
|
||
data: {
|
||
language: '',
|
||
selectedGoodsID:[],
|
||
selectedGoods:[]
|
||
}, // 私有数据,可用于模板渲染
|
||
|
||
lifetimes: {
|
||
// 生命周期函数,可以为函数,或一个在methods段中定义的方法名
|
||
attached() {
|
||
let language = wx.getStorageSync('langIndex');
|
||
this.setData({ 'language': language.en});
|
||
},
|
||
moved() {},
|
||
detached() {},
|
||
},
|
||
|
||
// 生命周期函数,可以为函数,或一个在methods段中定义的方法名
|
||
attached() {
|
||
|
||
}, // 此处attached的声明会被lifetimes字段中的声明覆盖
|
||
ready() {
|
||
|
||
},
|
||
|
||
pageLifetimes: {
|
||
// 组件所在页面的生命周期函数
|
||
show() {},
|
||
hide() {},
|
||
resize() {},
|
||
},
|
||
methods: {
|
||
gogoods(e) {
|
||
let id = e.currentTarget.dataset.id;
|
||
wx.navigateTo({
|
||
url: '/packageA/detail_v2/detail_v2?id=' + id
|
||
});
|
||
// var urlStr = app.getNetAddresss("goods.goods.get-goods");
|
||
// urlStr += "&id=" + id;
|
||
// app._getNetWork({
|
||
// showToastIn: false,
|
||
// url: urlStr,
|
||
// success: function(resdata) {
|
||
// var res = resdata.data;
|
||
// if (res.result == 1) {
|
||
// if (res.data.is_course == 1) {
|
||
// //CourseDetail goods_id: id
|
||
// } else if (res.data.goods_type == 1) {
|
||
// wx.navigateTo({
|
||
// url: '/packageA/detail_v2/detail_v2?id=' + id + '&tag=o2o' + '&store_id=' + res.data.store_id
|
||
// });
|
||
// } else {
|
||
// wx.navigateTo({
|
||
// url: '/packageA/detail_v2/detail_v2?id=' + id
|
||
// });
|
||
// }
|
||
// } else {
|
||
// wx.showToast({
|
||
// icon: 'none',
|
||
// title: res.msg,
|
||
// duration: 1500
|
||
// });
|
||
// }
|
||
|
||
// },
|
||
// fail: function(res) {
|
||
|
||
// }
|
||
// });
|
||
},
|
||
// 选择商品的方法
|
||
addGood(e) {
|
||
let val = e.currentTarget.dataset.id;
|
||
let flag = true;
|
||
//通过该对象的属性(属性为具体的商品ID)的真假值来判断是否选中
|
||
this.data.selectedGoods.map((item)=> {
|
||
if(item.id == val) {
|
||
flag = false;
|
||
item.value = !item.value;
|
||
if(item.value) {
|
||
this.data.selectedGoodsID.push(val);
|
||
}else {
|
||
this.data.selectedGoodsID = this.data.selectedGoodsID.filter((item)=> {
|
||
return item != val;
|
||
});
|
||
}
|
||
}
|
||
});
|
||
// console.log(val,'va',flag)
|
||
let obj = {
|
||
id: val,
|
||
value: flag
|
||
};
|
||
if(flag) {
|
||
this.data.selectedGoodsID.push(val);
|
||
this.data.selectedGoods.push(obj);
|
||
}
|
||
|
||
this.setData({
|
||
selectedGoodsID: this.data.selectedGoodsID,
|
||
selectedGoods: this.data.selectedGoods
|
||
});
|
||
// let num = 0;
|
||
//计算已经选中的商品个数,通过遍历对象查找对象属性为true的个数
|
||
// for (var key in this.data.selectedGoods) {
|
||
// if (this.data.selectedGoods[key]) {
|
||
// num++;
|
||
// }
|
||
// }
|
||
// console.log(this.data.selectedGoods,'va')
|
||
//向外传递已选商品的个数
|
||
this.triggerEvent('selectTotal', this.data.selectedGoods);
|
||
}
|
||
}
|
||
});
|