LiShiwei 2 жил өмнө
parent
commit
fc16257e38

+ 40 - 17
pages/search/index.js

@@ -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
     })
     })

+ 4 - 3
pages/search/index.wxml

@@ -1,7 +1,7 @@
 <view class="search_container">
 <view class="search_container">
   <view class="inputContent">
   <view class="inputContent">
     <van-icon name="search" />
     <van-icon name="search" />
-    <input type="text" bindinput="onInput" placeholder="搜索商品名称" />
+    <input type="text" bindinput="onInput" bindconfirm="onInput" placeholder="搜索商品名称" />
     <button bindtap="onSearch" bintap="onSearch">搜索</button>
     <button bindtap="onSearch" bintap="onSearch">搜索</button>
   </view>
   </view>
   <view class="show_clear" hidden="true">
   <view class="show_clear" hidden="true">
@@ -35,14 +35,15 @@
         </van-col>
         </van-col>
 
 
         <van-col span="8">
         <van-col span="8">
-          <van-stepper data-id="{{item.id}}" style="position: relative;top:180rpx;right:-20rpx;" min="0" value="{{ item.num }}" bind:change="onChange" />
+          <van-stepper disable-input="true" data-id="{{item.id}}" style="position: relative;top:180rpx;right:-20rpx;" min="0" value="{{ item.num }}" bind:change="onChange" bind:plus="onPlus" bind:minus="onMinus" />
         </van-col>
         </van-col>
       </van-row>
       </van-row>
     </view>
     </view>
     <!-- 分割 -->
     <!-- 分割 -->
     <view style="height: 80rpx;width: 100%;"></view>
     <view style="height: 80rpx;width: 100%;"></view>
+    <!-- 结算 -->
     <view class="search_total" >
     <view class="search_total" >
-    <van-submit-bar  price="{{ totalPrice }}" button-text="去结算" bind:submit="onSubmit" />
+    <van-submit-bar  price="{{ totalPrice*100 }}" button-text="去结算" bind:submit="onSubmit" />
   </view>
   </view>
   </view>
   </view>