|
@@ -1,10 +1,12 @@
|
|
// pages/merchant_page/index.js
|
|
// pages/merchant_page/index.js
|
|
|
|
+var sum=0;
|
|
Page({
|
|
Page({
|
|
|
|
|
|
/**
|
|
/**
|
|
* 页面的初始数据
|
|
* 页面的初始数据
|
|
*/
|
|
*/
|
|
data: {
|
|
data: {
|
|
|
|
+
|
|
foods: [{
|
|
foods: [{
|
|
id: 0,
|
|
id: 0,
|
|
foodsImg: 'https://bpic.588ku.com/back_origin_min_pic/20/11/05/a7438bbf54ace893e790545815e14ef3.jpg',
|
|
foodsImg: 'https://bpic.588ku.com/back_origin_min_pic/20/11/05/a7438bbf54ace893e790545815e14ef3.jpg',
|
|
@@ -12,7 +14,7 @@ Page({
|
|
foodsDesc: '包含香菜、菠菜、面、豆芽、海带',
|
|
foodsDesc: '包含香菜、菠菜、面、豆芽、海带',
|
|
initPrice: 28.80,
|
|
initPrice: 28.80,
|
|
nowPrice: 10.98,
|
|
nowPrice: 10.98,
|
|
- num : 0
|
|
|
|
|
|
+ num: 0
|
|
},
|
|
},
|
|
{
|
|
{
|
|
id: 1,
|
|
id: 1,
|
|
@@ -21,7 +23,7 @@ Page({
|
|
foodsDesc: '包含香菜、菠菜、面、豆芽、海带',
|
|
foodsDesc: '包含香菜、菠菜、面、豆芽、海带',
|
|
initPrice: 28.80,
|
|
initPrice: 28.80,
|
|
nowPrice: 10.98,
|
|
nowPrice: 10.98,
|
|
- num : 0
|
|
|
|
|
|
+ num: 0
|
|
},
|
|
},
|
|
{
|
|
{
|
|
id: 2,
|
|
id: 2,
|
|
@@ -30,7 +32,7 @@ Page({
|
|
foodsDesc: '包含香菜、菠菜、面、豆芽、海带',
|
|
foodsDesc: '包含香菜、菠菜、面、豆芽、海带',
|
|
initPrice: 28.80,
|
|
initPrice: 28.80,
|
|
nowPrice: 10.98,
|
|
nowPrice: 10.98,
|
|
- num : 0
|
|
|
|
|
|
+ num: 0
|
|
},
|
|
},
|
|
{
|
|
{
|
|
id: 3,
|
|
id: 3,
|
|
@@ -39,7 +41,7 @@ Page({
|
|
foodsDesc: '包含香菜、菠菜、面、豆芽、海带',
|
|
foodsDesc: '包含香菜、菠菜、面、豆芽、海带',
|
|
initPrice: 28.80,
|
|
initPrice: 28.80,
|
|
nowPrice: 10.98,
|
|
nowPrice: 10.98,
|
|
- num : 0
|
|
|
|
|
|
+ num: 0
|
|
},
|
|
},
|
|
{
|
|
{
|
|
id: 4,
|
|
id: 4,
|
|
@@ -48,7 +50,7 @@ Page({
|
|
foodsDesc: '包含香菜、菠菜、面、豆芽、海带',
|
|
foodsDesc: '包含香菜、菠菜、面、豆芽、海带',
|
|
initPrice: 28.80,
|
|
initPrice: 28.80,
|
|
nowPrice: 10.98,
|
|
nowPrice: 10.98,
|
|
- num : 0
|
|
|
|
|
|
+ num: 0
|
|
},
|
|
},
|
|
{
|
|
{
|
|
id: 5,
|
|
id: 5,
|
|
@@ -57,7 +59,7 @@ Page({
|
|
foodsDesc: '包含香菜、菠菜、面、豆芽、海带',
|
|
foodsDesc: '包含香菜、菠菜、面、豆芽、海带',
|
|
initPrice: 28.80,
|
|
initPrice: 28.80,
|
|
nowPrice: 10.98,
|
|
nowPrice: 10.98,
|
|
- num : 0
|
|
|
|
|
|
+ num: 0
|
|
},
|
|
},
|
|
{
|
|
{
|
|
id: 6,
|
|
id: 6,
|
|
@@ -66,7 +68,7 @@ Page({
|
|
foodsDesc: '包含香菜、菠菜、面、豆芽、海带',
|
|
foodsDesc: '包含香菜、菠菜、面、豆芽、海带',
|
|
initPrice: 28.80,
|
|
initPrice: 28.80,
|
|
nowPrice: 10.98,
|
|
nowPrice: 10.98,
|
|
- num : 0
|
|
|
|
|
|
+ num: 0
|
|
},
|
|
},
|
|
{
|
|
{
|
|
id: 7,
|
|
id: 7,
|
|
@@ -75,7 +77,7 @@ Page({
|
|
foodsDesc: '包含香菜、菠菜、面、豆芽、海带',
|
|
foodsDesc: '包含香菜、菠菜、面、豆芽、海带',
|
|
initPrice: 28.80,
|
|
initPrice: 28.80,
|
|
nowPrice: 10.98,
|
|
nowPrice: 10.98,
|
|
- num : 0
|
|
|
|
|
|
+ num: 0
|
|
}
|
|
}
|
|
],
|
|
],
|
|
show: false,
|
|
show: false,
|
|
@@ -88,16 +90,37 @@ Page({
|
|
info: e.detail.value
|
|
info: e.detail.value
|
|
})
|
|
})
|
|
},
|
|
},
|
|
- onChange(e) {
|
|
|
|
- let id = e.currentTarget.dataset.id;
|
|
|
|
- let num = e.detail;
|
|
|
|
- // console.log(num);
|
|
|
|
- let ans = this.data.foods[0].num
|
|
|
|
- console.log(ans);
|
|
|
|
|
|
+ onMinus(e){
|
|
|
|
+ var id = e.currentTarget.dataset.id;
|
|
|
|
+ sum-=this.data.foods[id].nowPrice;
|
|
|
|
+ // console.log(sum.toFixed(2)+"---------");
|
|
this.setData({
|
|
this.setData({
|
|
- [ans ]:'num'
|
|
|
|
|
|
+ totalPrice:Math.abs(sum)
|
|
})
|
|
})
|
|
},
|
|
},
|
|
|
|
+ onPlus(e){
|
|
|
|
+ var id = e.currentTarget.dataset.id;
|
|
|
|
+ sum+=this.data.foods[id].nowPrice;
|
|
|
|
+ // console.log(sum.toFixed(2)+"+++++++++");
|
|
|
|
+ // console.log(typeof sum );
|
|
|
|
+ this.setData({
|
|
|
|
+ totalPrice:Math.abs(sum)
|
|
|
|
+ })
|
|
|
|
+
|
|
|
|
+ },
|
|
|
|
+ onChange(e) {
|
|
|
|
+ let id = e.currentTarget.dataset.id; //获取当前点击的Id
|
|
|
|
+ let num = e.detail; //获取当前步进器的值
|
|
|
|
+ //给当前的对象里面的属性绑定其步进器的值
|
|
|
|
+ this.setData({
|
|
|
|
+ ["foods["+id+"].num"]:num
|
|
|
|
+ })
|
|
|
|
+
|
|
|
|
+ //接下来我们利用这个步进器的值,forEach遍历求和即可
|
|
|
|
+ // console.log(sum);
|
|
|
|
+
|
|
|
|
+ },
|
|
|
|
+
|
|
onSearch() {
|
|
onSearch() {
|
|
let list = this.data.foods;
|
|
let list = this.data.foods;
|
|
// 给你一个数组 里面包含a这个字的元素 将这些元素抛入新数组
|
|
// 给你一个数组 里面包含a这个字的元素 将这些元素抛入新数组
|
|
@@ -109,7 +132,7 @@ Page({
|
|
showList.push(list[i]);
|
|
showList.push(list[i]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- console.log(showList);
|
|
|
|
|
|
+ // console.log(showList);
|
|
|
|
|
|
// showList
|
|
// showList
|
|
if (showList.length == 0) {
|
|
if (showList.length == 0) {
|
|
@@ -128,7 +151,7 @@ Page({
|
|
/**
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
*/
|
|
- onLoad(options) {
|
|
|
|
|
|
+ onLoad() {
|
|
this.setData({
|
|
this.setData({
|
|
showList: this.data.foods
|
|
showList: this.data.foods
|
|
})
|
|
})
|