瀏覽代碼

:zap: 商品搜索前端,商品评论前端

nnkwrik 6 年之前
父節點
當前提交
3d0e116fb2

+ 22 - 7
wx-front/app.js

@@ -4,22 +4,37 @@ var user = require('./services/user.js');
 
 App({
   onLaunch: function () {
+    //!!生产环境专用测试数据
+    wx.setStorageSync('userInfo', this.testData.userInfo);
+    wx.setStorageSync('token', this.testData.token);
+
+    // wx.setStorageSync('userInfo', null);
+    // wx.setStorageSync('token', null);
+
     //获取用户的登录信息
-    user.checkLogin().then(res => {
-      console.log('app login')
+    // user.checkLogin().then(res => {
+    //   console.log('app login')
       this.globalData.userInfo = wx.getStorageSync('userInfo');
       this.globalData.token = wx.getStorageSync('token');
-    }).catch(() => {
+    // }).catch(() => {
       
-    });
+    // });
   },
   
   globalData: {
     userInfo: {
-      nickname: 'Hi,游客',
-      username: '点击去登录',
-      avatar: 'https://i.postimg.cc/RVbDV5fN/anonymous.png'
+      openId: '',
+      nickName: 'Hi,游客',
+      avatarUrl: 'https://i.postimg.cc/RVbDV5fN/anonymous.png'
     },
     token: '',
+  },
+  testData: {
+    userInfo: {
+      openId: '1',
+      nickName: '测试用户1',
+      avatarUrl: 'https://avatars2.githubusercontent.com/u/29662114?s=460&v=4'
+    },
+    token: 'Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJhdmF0YXJVcmwiOiJodHRwczovL2F2YXRhcnMyLmdpdGh1YnVzZXJjb250ZW50LmNvbS91LzI5NjYyMTE0P3M9NDYwJnY9NCIsIm9wZW5JZCI6IjEiLCJuaWNrTmFtZSI6Iua1i-ivleeUqOaItyIsImV4cCI6MTU0MzEyNzQ4OH0.ObcfDrCIgtY6AuqKqwZd_r8HnmjzHH_GsLA7161nBzUJeg2gvJ9xhMNniOKu0BmMI4dXn8TYyBLkee9y1xphLHCyQZwqgsLYKZFTfbcmSbpDAXjknA8qIsVAGpp5srChB6LoM1GDWiIRetJ-kBn0WopypMNck8kLFe6gdw7NyoafP0Wzrryf7DWAL56TlSOZ_IcubavcF58wX2oOMdS8_Q9NSh9Jj5lWJKkqAm395wdbnurFjOF3PtM5OlrJt4hqKcv3Sd9C_MOFiA3svlmmYjNfhUl8E9HEJpm1b5DmwxgkzMLty1VtZliL9hn0Ius4YOXJlk7IuLgHgBfDA2OyXQ',
   }
 })

+ 1 - 1
wx-front/config/api.js

@@ -1,5 +1,5 @@
 //const ApiRootUrl = 'https://23788fbf.ngrok.io/';
-const ApiRootUrl = 'http://127.0.0.1:8803/';
+const ApiRootUrl = 'http://127.0.0.1:8804/';
 
 module.exports = {
   IndexUrl: ApiRootUrl + 'index/index', //首页数据接口

+ 1 - 2
wx-front/pages/auth/auth.js

@@ -39,8 +39,7 @@ Page({
         //登录远程服务器
         util.request(api.AuthLoginByWeixin, {
           code: code,
-          detail: detail,
-          firstLogin: true
+          detail: detail
         }, 'POST').then(res => {
           if (res.errno === 0) {
             //存储用户信息

+ 14 - 29
wx-front/pages/catalog/catalog.js

@@ -11,66 +11,51 @@ Page({
     goodsCount: 0,
     scrollHeight: 0
   },
-  onLoad: function (options) {
+  onLoad: function(options) {
     this.getCatalog();
   },
-  getCatalog: function () {
+  getCatalog: function() {
     //CatalogList
     let that = this;
     wx.showLoading({
       title: '加载中...',
     });
-    util.request(api.CatalogList).then(function (res) {
-        that.setData({
-          navList: res.data.categoryList,
-          currentCategory: res.data.currentCategory
-        });
-        wx.hideLoading();
-      });
-    util.request(api.GoodsCount).then(function (res) {
+    util.request(api.CatalogList).then(function(res) {
       that.setData({
-        goodsCount: res.data.goodsCount
+        navList: res.data.categoryList,
+        currentCategory: res.data.currentCategory
       });
+      wx.hideLoading();
     });
 
   },
-  getCurrentCategory: function (id) {
+  getCurrentCategory: function(id) {
     let that = this;
-    util.request(api.CatalogCurrent+"/"+id)
-      .then(function (res) {
+    util.request(api.CatalogCurrent + "/" + id)
+      .then(function(res) {
         that.setData({
           currentCategory: res.data.currentCategory
         });
       });
   },
-  onReady: function () {
+  onReady: function() {
     // 页面渲染完成
   },
-  onShow: function () {
+  onShow: function() {
     // 页面显示
   },
-  onHide: function () {
+  onHide: function() {
     // 页面隐藏
   },
-  onUnload: function () {
+  onUnload: function() {
     // 页面关闭
   },
-  getList: function () {
-    var that = this;
-    util.request(api.ApiRootUrl + 'api/catalog/' + that.data.currentCategory.cat_id)
-      .then(function (res) {
-        that.setData({
-          categoryList: res.data,
-        });
-      });
-  },
-  switchCate: function (event) {
+  switchCate: function(event) {
     var that = this;
     var currentTarget = event.currentTarget;
     if (this.data.currentCategory.id == event.currentTarget.dataset.id) {
       return false;
     }
-
     this.getCurrentCategory(event.currentTarget.dataset.id);
   }
 })

+ 3 - 3
wx-front/pages/catalog/catalog.wxml

@@ -2,7 +2,7 @@
   <view class="search">
     <navigator url="/pages/search/search" class="input">
       <image class="icon"></image>
-      <text class="txt">商品搜索, 共{{goodsCount}}款好物</text>
+      <text class="txt">商品搜索,搜索关键字</text>
     </navigator>
   </view>
   <view class="catalog">
@@ -10,9 +10,9 @@
         <view class="item {{ currentCategory.id == item.id ? 'active' : ''}}" wx:for="{{navList}}"  data-id="{{item.id}}" data-index="{{index}}" bindtap="switchCate">{{item.name}}</view>
     </scroll-view>
     <scroll-view class="cate" scroll-y="true">
-        <navigator url="url" class="banner">
+        <view class="banner">
             <image class="image" src="https://image.flaticon.com/icons/svg/743/743007.svg"></image>
-        </navigator>
+        </view>
         <view class="hd">
             <text class="line"></text>
             <text class="txt">{{currentCategory.name}}分类</text>

+ 3 - 3
wx-front/pages/category/category.wxss

@@ -34,8 +34,8 @@
 }
 
 .cate-nav .item.active .name{
-    color: #ab2b2b;
-    border-bottom: 2px solid #ab2b2b;
+    color: #000;
+    border-bottom: 2px solid #fd9f06;
 }
 
 .cate-item{
@@ -113,5 +113,5 @@
   height: 30rpx;
   text-align: center;
   font-size: 30rpx;
-  color: #b4282d;
+  color: #f94b4b;
 }

+ 193 - 192
wx-front/pages/goods/goods.js

@@ -26,7 +26,7 @@ Page({
   },
   getGoodsInfo: function () {
     let that = this;
-    util.request(api.GoodsDetail + '/' + that.data.id ).then(function (res) {
+    util.request(api.GoodsDetail + '/' + that.data.id).then(function (res) {
       if (res.errno === 0) {
         that.setData({
           goods: res.data.info,
@@ -68,130 +68,131 @@ Page({
     });
 
   },
-  clickSkuValue: function (event) {
-    let that = this;
-    let specNameId = event.currentTarget.dataset.nameId;
-    let specValueId = event.currentTarget.dataset.valueId;
+  // clickSkuValue: function (event) {
+  //   let that = this;
+  //   let specNameId = event.currentTarget.dataset.nameId;
+  //   let specValueId = event.currentTarget.dataset.valueId;
 
-    //判断是否可以点击
+  //   //判断是否可以点击
 
-    //TODO 性能优化,可在wx:for中添加index,可以直接获取点击的属性名和属性值,不用循环
-    let _specificationList = this.data.specificationList;
-    for (let i = 0; i < _specificationList.length; i++) {
-      if (_specificationList[i].specification_id == specNameId) {
-        for (let j = 0; j < _specificationList[i].valueList.length; j++) {
-          if (_specificationList[i].valueList[j].id == specValueId) {
-            //如果已经选中,则反选
-            if (_specificationList[i].valueList[j].checked) {
-              _specificationList[i].valueList[j].checked = false;
-            } else {
-              _specificationList[i].valueList[j].checked = true;
-            }
-          } else {
-            _specificationList[i].valueList[j].checked = false;
-          }
-        }
-      }
-    }
-    this.setData({
-      'specificationList': _specificationList
-    });
-    //重新计算spec改变后的信息
-    this.changeSpecInfo();
+  //   //TODO 性能优化,可在wx:for中添加index,可以直接获取点击的属性名和属性值,不用循环
+  //   let _specificationList = this.data.specificationList;
+  //   for (let i = 0; i < _specificationList.length; i++) {
+  //     if (_specificationList[i].specification_id == specNameId) {
+  //       for (let j = 0; j < _specificationList[i].valueList.length; j++) {
+  //         if (_specificationList[i].valueList[j].id == specValueId) {
+  //           //如果已经选中,则反选
+  //           if (_specificationList[i].valueList[j].checked) {
+  //             _specificationList[i].valueList[j].checked = false;
+  //           } else {
+  //             _specificationList[i].valueList[j].checked = true;
+  //           }
+  //         } else {
+  //           _specificationList[i].valueList[j].checked = false;
+  //         }
+  //       }
+  //     }
+  //   }
+  //   this.setData({
+  //     'specificationList': _specificationList
+  //   });
+  //   //重新计算spec改变后的信息
+  //   this.changeSpecInfo();
 
-    //重新计算哪些值不可以点击
-  },
+  //   //重新计算哪些值不可以点击
+  // },
 
   //获取选中的规格信息
-  getCheckedSpecValue: function () {
-    let checkedValues = [];
-    let _specificationList = this.data.specificationList;
-    for (let i = 0; i < _specificationList.length; i++) {
-      let _checkedObj = {
-        nameId: _specificationList[i].specification_id,
-        valueId: 0,
-        valueText: ''
-      };
-      for (let j = 0; j < _specificationList[i].valueList.length; j++) {
-        if (_specificationList[i].valueList[j].checked) {
-          _checkedObj.valueId = _specificationList[i].valueList[j].id;
-          _checkedObj.valueText = _specificationList[i].valueList[j].value;
-        }
-      }
-      checkedValues.push(_checkedObj);
-    }
+  // getCheckedSpecValue: function () {
+  //   let checkedValues = [];
+  //   let _specificationList = this.data.specificationList;
+  //   for (let i = 0; i < _specificationList.length; i++) {
+  //     let _checkedObj = {
+  //       nameId: _specificationList[i].specification_id,
+  //       valueId: 0,
+  //       valueText: ''
+  //     };
+  //     for (let j = 0; j < _specificationList[i].valueList.length; j++) {
+  //       if (_specificationList[i].valueList[j].checked) {
+  //         _checkedObj.valueId = _specificationList[i].valueList[j].id;
+  //         _checkedObj.valueText = _specificationList[i].valueList[j].value;
+  //       }
+  //     }
+  //     checkedValues.push(_checkedObj);
+  //   }
 
-    return checkedValues;
+  //   return checkedValues;
 
-  },
-  //根据已选的值,计算其它值的状态
-  setSpecValueStatus: function () {
+  // },
+  // //根据已选的值,计算其它值的状态
+  // setSpecValueStatus: function () {
 
-  },
-  //判断规格是否选择完整
-  isCheckedAllSpec: function () {
-    return !this.getCheckedSpecValue().some(function (v) {
-      if (v.valueId == 0) {
-        return true;
-      }
-    });
-  },
-  getCheckedSpecKey: function () {
-    let checkedValue = this.getCheckedSpecValue().map(function (v) {
-      return v.valueId;
-    });
+  // },
+  // //判断规格是否选择完整
+  // isCheckedAllSpec: function () {
+  //   return !this.getCheckedSpecValue().some(function (v) {
+  //     if (v.valueId == 0) {
+  //       return true;
+  //     }
+  //   });
+  // },
+  // getCheckedSpecKey: function () {
+  //   let checkedValue = this.getCheckedSpecValue().map(function (v) {
+  //     return v.valueId;
+  //   });
 
-    return checkedValue.join('_');
-  },
-  changeSpecInfo: function () {
-    let checkedNameValue = this.getCheckedSpecValue();
+  //   return checkedValue.join('_');
+  // },
+  // changeSpecInfo: function () {
+  //   let checkedNameValue = this.getCheckedSpecValue();
 
-    //设置选择的信息
-    let checkedValue = checkedNameValue.filter(function (v) {
-      if (v.valueId != 0) {
-        return true;
-      } else {
-        return false;
-      }
-    }).map(function (v) {
-      return v.valueText;
-    });
-    if (checkedValue.length > 0) {
-      this.setData({
-        'checkedSpecText': checkedValue.join(' ')
-      });
-    } else {
-      this.setData({
-        'checkedSpecText': '请选择规格数量'
-      });
-    }
+  //   //设置选择的信息
+  //   let checkedValue = checkedNameValue.filter(function (v) {
+  //     if (v.valueId != 0) {
+  //       return true;
+  //     } else {
+  //       return false;
+  //     }
+  //   }).map(function (v) {
+  //     return v.valueText;
+  //   });
+  //   if (checkedValue.length > 0) {
+  //     this.setData({
+  //       'checkedSpecText': checkedValue.join(' ')
+  //     });
+  //   } else {
+  //     this.setData({
+  //       'checkedSpecText': '请选择规格数量'
+  //     });
+  //   }
 
-  },
-  getCheckedProductItem: function (key) {
-    return this.data.productList.filter(function (v) {
-      if (v.goods_specification_ids == key) {
-        return true;
-      } else {
-        return false;
-      }
-    });
-  },
+  // },
+  // getCheckedProductItem: function (key) {
+  //   return this.data.productList.filter(function (v) {
+  //     if (v.goods_specification_ids == key) {
+  //       return true;
+  //     } else {
+  //       return false;
+  //     }
+  //   });
+  // },
   onLoad: function (options) {
     // 页面初始化 options为页面跳转所带来的参数
     this.setData({
       id: parseInt(options.id)
       // id: 1181000
     });
+
     var that = this;
     this.getGoodsInfo();
-    util.request(api.CartGoodsCount).then(function (res) {
-      if (res.errno === 0) {
-        that.setData({
-          cartGoodsCount: res.data.cartTotal.goodsCount
-        });
+    // util.request(api.CartGoodsCount).then(function (res) {
+    //   if (res.errno === 0) {
+    //     that.setData({
+    //       cartGoodsCount: res.data.cartTotal.goodsCount
+    //     });
 
-      }
-    });
+    //   }
+    // });
   },
   onReady: function () {
     // 页面渲染完成
@@ -209,18 +210,18 @@ Page({
     // 页面关闭
 
   },
-  switchAttrPop: function () {
-    if (this.data.openAttr == false) {
-      this.setData({
-        openAttr: !this.data.openAttr
-      });
-    }
-  },
-  closeAttr: function () {
-    this.setData({
-      openAttr: false,
-    });
-  },
+  // switchAttrPop: function () {
+  //   if (this.data.openAttr == false) {
+  //     this.setData({
+  //       openAttr: !this.data.openAttr
+  //     });
+  //   }
+  // },
+  // closeAttr: function () {
+  //   this.setData({
+  //     openAttr: false,
+  //   });
+  // },
   addCannelCollect: function () {
     let that = this;
     //添加或是取消收藏
@@ -247,85 +248,85 @@ Page({
         }
       });
   },
-  openCartPage: function () {
-    wx.switchTab({
-      url: '/pages/cart/cart',
-    });
-  },
-  addToCart: function () {
-    var that = this;
-    if (this.data.openAttr === false) {
-      //打开规格选择窗口
-      this.setData({
-        openAttr: !this.data.openAttr
-      });
-    } else {
+  // openCartPage: function () {
+  //   wx.switchTab({
+  //     url: '/pages/cart/cart',
+  //   });
+  // },
+  // addToCart: function () {
+  //   var that = this;
+  //   if (this.data.openAttr === false) {
+  //     //打开规格选择窗口
+  //     this.setData({
+  //       openAttr: !this.data.openAttr
+  //     });
+  //   } else {
 
-      //提示选择完整规格
-      if (!this.isCheckedAllSpec()) {
-        wx.showToast({
-          image: '/static/images/icon_error.png',
-          title: '请选择规格',
-          mask: true
-        });
-        return false;
-      }
+  //     //提示选择完整规格
+  //     if (!this.isCheckedAllSpec()) {
+  //       wx.showToast({
+  //         image: '/static/images/icon_error.png',
+  //         title: '请选择规格',
+  //         mask: true
+  //       });
+  //       return false;
+  //     }
 
-      //根据选中的规格,判断是否有对应的sku信息
-      let checkedProduct = this.getCheckedProductItem(this.getCheckedSpecKey());
-      if (!checkedProduct || checkedProduct.length <= 0) {
-        //找不到对应的product信息,提示没有库存
-        wx.showToast({
-          image: '/static/images/icon_error.png',
-          title: '库存不足',
-          mask: true
-        });
-        return false;
-      }
+  //     //根据选中的规格,判断是否有对应的sku信息
+  //     let checkedProduct = this.getCheckedProductItem(this.getCheckedSpecKey());
+  //     if (!checkedProduct || checkedProduct.length <= 0) {
+  //       //找不到对应的product信息,提示没有库存
+  //       wx.showToast({
+  //         image: '/static/images/icon_error.png',
+  //         title: '库存不足',
+  //         mask: true
+  //       });
+  //       return false;
+  //     }
 
-      //验证库存
-      if (checkedProduct.goods_number < this.data.number) {
-        //找不到对应的product信息,提示没有库存
-        wx.showToast({
-          image: '/static/images/icon_error.png',
-          title: '库存不足',
-          mask: true
-        });
-        return false;
-      }
+  //     //验证库存
+  //     if (checkedProduct.goods_number < this.data.number) {
+  //       //找不到对应的product信息,提示没有库存
+  //       wx.showToast({
+  //         image: '/static/images/icon_error.png',
+  //         title: '库存不足',
+  //         mask: true
+  //       });
+  //       return false;
+  //     }
 
-      //添加到购物车
-      util.request(api.CartAdd, { goodsId: this.data.goods.id, number: this.data.number, productId: checkedProduct[0].id }, "POST")
-        .then(function (res) {
-          let _res = res;
-          if (_res.errno == 0) {
-            wx.showToast({
-              title: '添加成功'
-            });
-            that.setData({
-              openAttr: !that.data.openAttr,
-              cartGoodsCount: _res.data.cartTotal.goodsCount
-            });
-          } else {
-            wx.showToast({
-              image: '/static/images/icon_error.png',
-              title: _res.errmsg,
-              mask: true
-            });
-          }
+  //     //添加到购物车
+  //     util.request(api.CartAdd, { goodsId: this.data.goods.id, number: this.data.number, productId: checkedProduct[0].id }, "POST")
+  //       .then(function (res) {
+  //         let _res = res;
+  //         if (_res.errno == 0) {
+  //           wx.showToast({
+  //             title: '添加成功'
+  //           });
+  //           that.setData({
+  //             openAttr: !that.data.openAttr,
+  //             cartGoodsCount: _res.data.cartTotal.goodsCount
+  //           });
+  //         } else {
+  //           wx.showToast({
+  //             image: '/static/images/icon_error.png',
+  //             title: _res.errmsg,
+  //             mask: true
+  //           });
+  //         }
 
-        });
-    }
+  //       });
+  //   }
 
-  },
-  cutNumber: function () {
-    this.setData({
-      number: (this.data.number - 1 > 1) ? this.data.number - 1 : 1
-    });
-  },
-  addNumber: function () {
-    this.setData({
-      number: this.data.number + 1
-    });
-  }
+  // },
+  // cutNumber: function () {
+  //   this.setData({
+  //     number: (this.data.number - 1 > 1) ? this.data.number - 1 : 1
+  //   });
+  // },
+  // addNumber: function () {
+  //   this.setData({
+  //     number: this.data.number + 1
+  //   });
+  // }
 })

+ 32 - 27
wx-front/pages/goods/goods.wxml

@@ -5,7 +5,7 @@
     </swiper-item>
   </swiper>
   <view class="location-time">
-    <view class="icon time">最后编辑 : 2018-10-30 19:12</view>
+    <view class="icon time">最后编辑 : {{goods.last_edit}}</view>
     <view class="icon location">地点 : 广东深圳</view>
   </view>
   <view class="goods-info">
@@ -45,11 +45,11 @@
   <!-- history -->
   <view class="seller-nav section-act">
     <view class="seller-t">
-      <image class="seller-avatar" src="https://avatars2.githubusercontent.com/u/29662114?s=460&v=4"></image>
+      <image class="seller-avatar" src="{{goods.seller.avatarUrl}}"></image>
     </view>
 
     <view class="seller-info">
-      <view class="name">测试用户</view>
+      <view class="name">{{goods.seller.nickName}}</view>
       <view class="history">加入平台第100天,出售过5件宝贝</view>
     </view>
 
@@ -85,37 +85,42 @@
     </view>
   </view> -->
 
-  <view class="comments">
+  <view class="comments" wx:if="{{comment.length > 0}}">
     <view class="h">
-        <text class="t">留言 (12)</text>
+      <text class="t">留言 ({{comment.length > 999 ? '999+' : comment.length}})</text>
     </view>
     <view class="b">
-    <!-- comment -->
-      <view class="item">
-        <view class="info">
-          <view class="user">
-            <image src="https://avatars2.githubusercontent.com/u/29662114?s=460&v=4"></image>
-            <text>nickname</text>
+      <view wx:for="{{comment}}" wx:for-index="index" wx:for-item="item" wx:key="{{item.id}}">
+        <!-- comment -->
+        <view class="item">
+          <view class="info">
+            <view class="user">
+              <image src="{{item.simpleUser.avatarUrl}}"></image>
+              <text>{{item.simpleUser.nickName}}</text>
+            </view>
+            <view class="time">{{item.create_time}}</view>
           </view>
-          <view class="time">2019-12-23 10:12</view>
-        </view>
-        <view class="content">
-          aaaaa
-        </view>
-        <!-- reply -->
-        <view class="reply-info">
-          <view class="reply-user">
-            <image src="https://avatars2.githubusercontent.com/u/29662114?s=460&v=4"></image>
-            <text>nickname</text>
+          <view class="content">
+            {{item.content}}
           </view>
-          <view class="time">2019-12-23 10:12</view>
-        </view>
-        <view class="reply-content">
-          回复@nickname:aaaaa
+          <!-- reply -->
+          <view wx:for="{{item.replyList}}" wx:for-index="iindex" wx:for-item="iitem" wx:key="{{iitem.id}}">
+            <view class="reply-info">
+              <view class="reply-user">
+                <image src="{{iitem.simpleUser.avatarUrl}}"></image>
+                <text>{{iitem.simpleUser.nickName}}</text>
+              </view>
+              <view class="time">{{iitem.create_time}}</view>
+            </view>
+            <view class="reply-content">
+              回复@{{iitem.reply_user_name}}:{{item.content}}
+            </view>
+          </view>
+
+          <!-- reoly-end -->
         </view>
-        <!-- reoly-end -->
+        <!-- comment-end -->
       </view>
-      <!-- comment-end -->
 
     </view>
 

+ 3 - 2
wx-front/pages/goods/goods.wxss

@@ -294,7 +294,7 @@ font-weight:bold;
 }
 
 .comments .content {
-  width: 720rpx;
+  width: 630rpx;
   padding-right: 30rpx;
   line-height: 45.8rpx;
   font-size: 29rpx;
@@ -303,7 +303,8 @@ font-weight:bold;
 }
 
 .comments .reply-content {
-  width: 720rpx;
+  /* width: 720rpx; */
+  width: 600rpx;
   padding-right: 30rpx;
   line-height: 45.8rpx;
   font-size: 29rpx;

+ 2 - 2
wx-front/pages/index/index.js

@@ -19,8 +19,8 @@ Page({
   },
   onShareAppMessage: function () {
     return {
-      title: 'NideShop',
-      desc: '仿网易严选微信小程序商城',
+      title: '古早交易平台',
+      desc: '一款开源仿闲鱼交易平台!',
       path: '/pages/index/index'
     }
   },

+ 87 - 89
wx-front/pages/search/search.js

@@ -7,19 +7,19 @@ Page({
     keywrod: '',
     searchStatus: false,
     goodsList: [],
-    helpKeyword: [],
+    // helpKeyword: [],
     historyKeyword: [],
-    categoryFilter: false,
-    currentSortType: 'default',
-    currentSortOrder: '',
-    filterCategory: [],
-    defaultKeyword: {},
+    // categoryFilter: false,
+    // currentSortType: 'default',
+    // currentSortOrder: '',
+    // filterCategory: [],
+    defaultKeyword: '输入关键字',
     hotKeyword: [],
     page: 1,
     size: 20,
-    currentSortType: 'id',
-    currentSortOrder: 'desc',
-    categoryId: 0
+    // currentSortType: 'id',
+    // currentSortOrder: 'desc',
+    // categoryId: 0
   },
   //事件处理函数
   closeSearch: function () {
@@ -32,7 +32,6 @@ Page({
     });
   },
   onLoad: function () {
-
     this.getSearchKeyword();
   },
 
@@ -42,62 +41,61 @@ Page({
       if (res.errno === 0) {
         that.setData({
           historyKeyword: res.data.historyKeywordList,
-          defaultKeyword: res.data.defaultKeyword,
           hotKeyword: res.data.hotKeywordList
         });
       }
     });
   },
 
-  inputChange: function (e) {
+  // inputChange: function (e) {
 
-    this.setData({
-      keyword: e.detail.value,
-      searchStatus: false
-    });
-    this.getHelpKeyword();
-  },
-  getHelpKeyword: function () {
-    let that = this;
-    util.request(api.SearchHelper, { keyword: that.data.keyword }).then(function (res) {
-      if (res.errno === 0) {
-        that.setData({
-          helpKeyword: res.data
-        });
-      }
-    });
-  },
+  //   this.setData({
+  //     keyword: e.detail.value,
+  //     searchStatus: false
+  //   });
+  //   this.getHelpKeyword();
+  // },
+  // getHelpKeyword: function () {
+  //   let that = this;
+  //   util.request(api.SearchHelper, { keyword: that.data.keyword }).then(function (res) {
+  //     if (res.errno === 0) {
+  //       that.setData({
+  //         helpKeyword: res.data
+  //       });
+  //     }
+  //   });
+  // },
   inputFocus: function () {
     this.setData({
       searchStatus: false,
       goodsList: []
     });
 
-    if (this.data.keyword) {
-      this.getHelpKeyword();
-    }
+    // if (this.data.keyword) {
+    //   this.getHelpKeyword();
+    // }
   },
   clearHistory: function () {
+    let that = this;
     this.setData({
       historyKeyword: []
     })
 
-    util.request(api.SearchClearHistory, {}, 'POST')
+    util.request(api.SearchClearHistory)
       .then(function (res) {
         console.log('清除成功');
       });
   },
   getGoodsList: function () {
     let that = this;
-    util.request(api.GoodsList, { keyword: that.data.keyword, page: that.data.page, size: that.data.size, sort: that.data.currentSortType, order: that.data.currentSortOrder, categoryId: that.data.categoryId }).then(function (res) {
+    util.request(api.SearchResult + '/' + that.data.keyword).then(function (res) {
       if (res.errno === 0) {
         that.setData({
           searchStatus: true,
           categoryFilter: false,
-          goodsList: res.data.data,
-          filterCategory: res.data.filterCategory,
-          page: res.data.currentPage,
-          size: res.data.numsPerPage
+          goodsList: res.data,
+          // page: res.data.currentPage,
+          // size: res.data.numsPerPage
         });
       }
 
@@ -120,59 +118,59 @@ Page({
 
     this.getGoodsList();
   },
-  openSortFilter: function (event) {
-    let currentId = event.currentTarget.id;
-    switch (currentId) {
-      case 'categoryFilter':
-        this.setData({
-          'categoryFilter': !this.data.categoryFilter,
-          'currentSortOrder': 'asc'
-        });
-        break;
-      case 'priceSort':
-        let tmpSortOrder = 'asc';
-        if (this.data.currentSortOrder == 'asc') {
-          tmpSortOrder = 'desc';
-        }
-        this.setData({
-          'currentSortType': 'price',
-          'currentSortOrder': tmpSortOrder,
-          'categoryFilter': false
-        });
+  // openSortFilter: function (event) {
+  //   let currentId = event.currentTarget.id;
+  //   switch (currentId) {
+  //     case 'categoryFilter':
+  //       this.setData({
+  //         'categoryFilter': !this.data.categoryFilter,
+  //         'currentSortOrder': 'asc'
+  //       });
+  //       break;
+  //     case 'priceSort':
+  //       let tmpSortOrder = 'asc';
+  //       if (this.data.currentSortOrder == 'asc') {
+  //         tmpSortOrder = 'desc';
+  //       }
+  //       this.setData({
+  //         'currentSortType': 'price',
+  //         'currentSortOrder': tmpSortOrder,
+  //         'categoryFilter': false
+  //       });
 
-        this.getGoodsList();
-        break;
-      default:
-        //综合排序
-        this.setData({
-          'currentSortType': 'default',
-          'currentSortOrder': 'desc',
-          'categoryFilter': false
-        });
-        this.getGoodsList();
-    }
-  },
-  selectCategory: function (event) {
-    let currentIndex = event.target.dataset.categoryIndex;
-    let filterCategory = this.data.filterCategory;
-    let currentCategory = null;
-    for (let key in filterCategory) {
-      if (key == currentIndex) {
-        filterCategory[key].selected = true;
-        currentCategory = filterCategory[key];
-      } else {
-        filterCategory[key].selected = false;
-      }
-    }
-    this.setData({
-      'filterCategory': filterCategory,
-      'categoryFilter': false,
-      categoryId: currentCategory.id,
-      page: 1,
-      goodsList: []
-    });
-    this.getGoodsList();
-  },
+  //       this.getGoodsList();
+  //       break;
+  //     default:
+  //       //综合排序
+  //       this.setData({
+  //         'currentSortType': 'default',
+  //         'currentSortOrder': 'desc',
+  //         'categoryFilter': false
+  //       });
+  //       this.getGoodsList();
+  //   }
+  // },
+  // selectCategory: function (event) {
+  //   let currentIndex = event.target.dataset.categoryIndex;
+  //   let filterCategory = this.data.filterCategory;
+  //   let currentCategory = null;
+  //   for (let key in filterCategory) {
+  //     if (key == currentIndex) {
+  //       filterCategory[key].selected = true;  //checked?
+  //       currentCategory = filterCategory[key];
+  //     } else {
+  //       filterCategory[key].selected = false;
+  //     }
+  //   }
+  //   this.setData({
+  //     'filterCategory': filterCategory,
+  //     'categoryFilter': false,
+  //     categoryId: currentCategory.id,
+  //     page: 1,
+  //     goodsList: []
+  //   });
+  //   this.getGoodsList();
+  // },
   onKeywordConfirm(event) {
     this.getSearchResult(event.detail.value);
   }

+ 44 - 42
wx-front/pages/search/search.wxml

@@ -2,66 +2,68 @@
   <view class="search-header">
     <view class="input-box">
       <image class="icon" src="http://nos.netease.com/mailpub/hxm/yanxuan-wap/p/20150730/style/img/icon-normal/search2-2fb94833aa.png"></image>
-      <input name="input" class="keywrod" focus="true" value="{{keyword}}" confirm-type="search" bindinput="inputChange" bindfocus="inputFocus" bindconfirm="onKeywordConfirm" confirm-type="search" placeholder="{{defaultKeyword.keyword}}" />
+      <!-- TODO 输入辅助 -->
+      <!-- <input name="input" class="keywrod" focus="true" value="{{keyword}}" confirm-type="search" bindinput="inputChange" bindfocus="inputFocus" bindconfirm="onKeywordConfirm" confirm-type="search" placeholder="{{defaultKeyword}}" /> -->
+            <input name="input" class="keywrod" focus="true" value="{{keyword}}" confirm-type="search" bindfocus="inputFocus" bindconfirm="onKeywordConfirm" confirm-type="search" placeholder="{{defaultKeyword}}" />
       <image class="del" wx:if="{{keyword}}" bindtap="clearKeyword" src="http://nos.netease.com/mailpub/hxm/yanxuan-wap/p/20150730/style/img/icon-normal/clearIpt-f71b83e3c2.png"></image>
     </view>
     <view class="right" bindtap="closeSearch">取消</view>
   </view>
   <view class="no-search" wx:if="{{ !searchStatus}}">
-      <view class="serach-keywords search-history" wx:if="{{!keyword  && historyKeyword.length}}">
-    <view class="h">
-      <text class="title">历史记录</text>
-      <image class="icon" bindtap="clearHistory" src="http://nos.netease.com/mailpub/hxm/yanxuan-wap/p/20150730/style/img/icon-normal/del1-93f0a4add4.png"></image>
-    </view>
-    <view class="b">
-      <view class="item" bindtap="onKeywordTap" data-keyword="{{item}}" wx:for="{{historyKeyword}}" hover-class="navigator-hover">{{item}}</view>
+    <view class="serach-keywords search-history" wx:if="{{historyKeyword.length}}">
+      <view class="h">
+        <text class="title">历史记录</text>
+        <image class="icon" bindtap="clearHistory" src="http://nos.netease.com/mailpub/hxm/yanxuan-wap/p/20150730/style/img/icon-normal/del1-93f0a4add4.png"></image>
+      </view>
+      <view class="b">
+        <view class="item" bindtap="onKeywordTap" data-keyword="{{item}}" wx:for="{{historyKeyword}}" hover-class="navigator-hover">{{item}}</view>
+      </view>
     </view>
-  </view>
-  <view class="serach-keywords search-hot" wx:if="{{!keyword}}">
-    <view class="h">
-      <text class="title">热门搜索</text>
+    <view class="serach-keywords search-hot" wx:if="{{!keyword}}">
+      <view class="h">
+        <text class="title">热门搜索</text>
+      </view>
+      <view class="b">
+        <view class="item active" hover-class="navigator-hover" bindtap="onKeywordTap" data-keyword="{{item}}" wx:for="{{hotKeyword}}">{{item}}</view>
+      </view>
     </view>
-    <view class="b">
-    <view class="item active" hover-class="navigator-hover">aa</view>
-    <view  class="item" hover-class="navigator-hover">aa</view>
-      <view class="item {{item.is_hot === 1 ? 'active' : ''}}" hover-class="navigator-hover" bindtap="onKeywordTap" data-keyword="{{item.keyword}}" wx:for="{{hotKeyword}}">{{item.keyword}}</view>
+    <view class="shelper-list" wx:if="{{keyword}}">
+      <view class="item" hover-class="navigator-hover" wx:for="{{helpKeyword}}" bindtap="onKeywordTap" data-keyword="{{item}}">{{item}}</view>
     </view>
   </view>
-  <view class="shelper-list" wx:if="{{keyword}}">
-    <view class="item" hover-class="navigator-hover" wx:for="{{helpKeyword}}" bindtap="onKeywordTap" data-keyword="{{item}}">{{item}}</view>
-  </view>
-  </view>
 
   <view class="search-result" wx:if="{{ searchStatus && goodsList.length}}">
-    <view class="sort">
-    <view class="sort-box">
-      <view class="item {{currentSortType == 'default' ? 'active' : ''}}" bindtap="openSortFilter" id="defaultSort">
-        <text class="txt">综合</text>
+
+    <!-- <view class="sort">
+      <view class="sort-box">
+        <view class="item {{currentSortType == 'default' ? 'active' : ''}}" bindtap="openSortFilter" id="defaultSort">
+          <text class="txt">综合</text>
+        </view>
+        <view class="item by-price {{currentSortType == 'price' ? 'active' : ''}} {{currentSortOrder == 'asc'  ? 'asc' : 'desc'}}" bindtap="openSortFilter" id="priceSort">
+          <text class="txt">价格</text>
+        </view>
+        <view class="item {{currentSortType == 'category' ? 'active' : ''}}" bindtap="openSortFilter" id="categoryFilter">
+          <text class="txt">分类</text>
+        </view>
       </view>
-      <view class="item by-price {{currentSortType == 'price' ? 'active' : ''}} {{currentSortOrder == 'asc'  ? 'asc' : 'desc'}}" bindtap="openSortFilter" id="priceSort">
-        <text class="txt">价格</text>
+      <view class="sort-box-category" wx-if="{{categoryFilter}}">
+        <view class="item {{item.checked ? 'active' : ''}}" wx:for="{{filterCategory}}" wx:key="cate-{{item.id}}" data-category-index="{{index}}" bindtap="selectCategory">{{item.name}}</view>
       </view>
-      <view class="item {{currentSortType == 'category' ? 'active' : ''}}" bindtap="openSortFilter" id="categoryFilter">
-        <text class="txt">分类</text>
+    </view> -->
+    
+    <view class="cate-item">
+      <view class="b">
+        <navigator class="item {{(iindex + 1) % 2 == 0 ? 'item-b' : ''}}" url="/pages/goods/goods?id={{iitem.id}}" wx:for="{{goodsList}}" wx:for-item="iitem" wx:for-index="iindex">
+          <image class="img" src="{{iitem.list_pic_url}}" background-size="cover"></image>
+          <text class="name">{{iitem.name}}</text>
+          <text class="price">¥{{iitem.price}}</text>
+        </navigator>
       </view>
     </view>
-    <view class="sort-box-category" wx-if="{{categoryFilter}}">
-      <view class="item {{item.checked ? 'active' : ''}}" wx:for="{{filterCategory}}" wx:key="cate-{{item.id}}" data-category-index="{{index}}" bindtap="selectCategory">{{item.name}}</view>
-    </view>
-  </view>
-  <view class="cate-item">
-    <view class="b">
-      <navigator class="item {{(iindex + 1) % 2 == 0 ? 'item-b' : ''}}" url="/pages/goods/goods?id={{iitem.id}}" wx:for="{{goodsList}}" wx:for-item="iitem" wx:for-index="iindex">
-        <image class="img" src="{{iitem.list_pic_url}}" background-size="cover"></image>
-        <text class="name">{{iitem.name}}</text>
-        <text class="price">¥{{iitem.retail_price}}</text>
-      </navigator>
-    </view>
-  </view>
   </view>
 
   <view class="search-result-empty" wx:if="{{!goodsList.length && searchStatus}}">
     <image class="icon" src="http://yanxuan.nosdn.127.net/hxm/yanxuan-wap/p/20161201/style/img/icon-normal/noSearchResult-7572a94f32.png"></image>
-    <text class="text">您寻找的商品还未上架</text>
+    <text class="text">没有您寻找的商品</text>
   </view>
 </scroll-view>

+ 3 - 3
wx-front/pages/search/search.wxss

@@ -127,8 +127,8 @@ page{
 }
 
 .serach-keywords .item.active{
-    color: #b4282d;
-    border: 1px solid #b4282d;
+    color: #f94b4b;
+    border: 1px solid #f94b4b;
 }
 
 .shelper-list{
@@ -310,7 +310,7 @@ page{
   height: 30rpx;
   text-align: center;
   font-size: 30rpx;
-  color: #b4282d;
+  color: #f94b4b;
 }
 
 .search-result-empty{

+ 2 - 2
wx-front/pages/ucenter/index/index.js

@@ -23,8 +23,8 @@ Page({
 
     // 页面显示
     if (userInfo && token) {
-      app.globalData.userInfo = userInfo;
-      app.globalData.token = token;
+      // app.globalData.userInfo = userInfo;
+      // app.globalData.token = token;
       this.setData({
         isLogin: true
       });

+ 2 - 2
wx-front/pages/ucenter/index/index.wxml

@@ -1,9 +1,9 @@
 <view class="container">
 <!-- TODO 点击,查看个人主页 -->
   <view class="profile-info" op bindtap="goLogin">
-    <image class="avatar" src="{{userInfo.avatar}}"></image>
+    <image class="avatar" src="{{userInfo.avatarUrl}}"></image>
     <view class="info">
-      <text class="name">{{userInfo.nickname}}</text>
+      <text class="name">{{userInfo.nickName}}</text>
 
       <text  wx:if="{{isLogin}}" class="level">点击查看个人主页</text>
       <text wx:else  class="level">马上授权登录</text>

+ 39 - 23
wx-front/utils/util.js

@@ -29,38 +29,54 @@ function request(url, data = {}, method = "GET") {
       method: method,
       header: {
         'Content-Type': 'application/json',
-        'X-Nideshop-Token': wx.getStorageSync('token')
+        'Authorization': wx.getStorageSync('token')
       },
       success: function (res) {
         console.log("success");
 
         if (res.statusCode == 200) {
 
-          if (res.data.errno == 401) {
+          if (res.data.errno == 3003) {
+            //TOKEN_IS_EMPTY
             //需要登录后才可以操作
-
+            wx.navigateTo({
+              url: '/pages/auth/auth'
+            })
+          } else if (res.data.errno == 3004){
+            // TOKEN_IS_EXPIRED
+            
             let code = null;
-            return login().then((res) => {
-              code = res.code;
-              return getUserInfo();
-            }).then((userInfo) => {
-              //登录远程服务器
-              request(api.AuthLoginByWeixin, { code: code, userInfo: userInfo }, 'POST').then(res => {
-                if (res.errno === 0) {
-                  //存储用户信息
-                  wx.setStorageSync('userInfo', res.data.userInfo);
-                  wx.setStorageSync('token', res.data.token);
-                  
-                  resolve(res);
-                } else {
-                  reject(res);
-                }
-              }).catch((err) => {
+            return new Promise(function (resolve, reject) {
+              return util.login().then((res) => {
+                code = res.code;
+              }).then(() => {
+                //登录远程服务器
+                util.request(api.AuthLoginByWeixin, {
+                  code: code,
+                  detail: detail,
+                  expiredToken: wx.getStorageSync('token')
+                }, 'POST').then(res => {
+                  if (res.errno === 0) {
+                    //存储用户信息
+                    wx.setStorageSync('userInfo', res.data.userInfo);
+                    wx.setStorageSync('token', res.data.token);
+
+                    //反应到当前登录
+                    app.globalData.userInfo = res.data.userInfo;
+                    app.globalData.token = res.data.token;
+
+                    resolve(res.data.userInfo);
+                  } else {
+                    reject(res.data.userInfo);
+                  }
+                }).catch((err) => { //request
+                  reject(err);
+                });
+              }).catch((err) => {   //login
                 reject(err);
-              });
-            }).catch((err) => {
-              reject(err);
-            })
+              })
+            });
+
           } else {
             resolve(res.data);
           }