Browse Source

分类接口添加

sharp-agezi 6 years ago
parent
commit
a91a88c2b1

+ 91 - 43
pages/kind/index.js

@@ -8,9 +8,7 @@ Page({
     classifyNavList:[],
     classifyNavActiveId: 2981,
     goodsList:[],
-    commodity_levelTwo:null,
     requestState:true, //默认为true,表示还有数据
-    page:0,
     filterArray: [
       { name: '1', value: '0~499元' },
       { name: '2', value: '500~999元'},
@@ -18,12 +16,17 @@ Page({
       { name: '4', value: '2000元以上' },
     ],
     filterStatic:false,
-    isNew:true,
-    isMin:true,
+    page: 1, //默认第一页
+    channelId:null, //渠道id,登录后给,默认为null
+    maxPrice:null, //最大价格
+    minPrice:null, //最低价格
+    limit:10, //分页大小
+    priceSort: null, //价格排序 desc asc
+    timeSort: null, //时间排序 desc asc
+
   },
   onLoad(){
     this.getNavList(this);
-    this.getGoodsListAllfor(this)
   },
   onShow(){
 
@@ -39,13 +42,18 @@ Page({
   },
   getNavList(that){
     wx.request({
-      url: host + '/classifyapi/findAllforhome',
+      url: host + '/classifyapi/classifyTwoAll',
       method:'get',
+      data:{
+        classifyHigher:'3053',
+      },
       success(res){
         console.log(res,"成功后的")
         that.setData({
-          classifyNavList:[...res.data.rows]
+          classifyNavList:res.data.rows,
+          classifyNavActiveId: res.data.rows[0].id
         })
+        that.getGoodsList(that)
       }
     })
   },
@@ -55,44 +63,46 @@ Page({
     that.setData({
       classifyNavActiveId:item.id,
       requestState: true, //数据初始化
-      page: 0,//数据初始化
+      page: 1,//数据初始化
       goodsList: []//数据初始化
     })
-    that.getGoodsListAllfor(that)
+    that.getGoodsList(that)
     
   },
-  getGoodsListAllfor(that){
-    wx.request({
-      url: host +'/classifyapi/findAllforviewSce',
-      method:'get',
-      data:{
-        id:that.data.classifyNavActiveId
-      },
-      success(res){
-        that.setData({
-          commodity_levelTwo:res.data.rows[0].id,
-        })
-        that.getGoodsList(that)
-      }
-    })
-  },
   getGoodsList(that){
-    let goodsList = that.data.goodsList, requestState = true
+    let data = {
+      classId: that.data.classifyNavActiveId,
+      limit: that.data.limit,
+      offset:that.data.page,
+    }
+    if(that.data.channelId){
+      data.channelId = that.data.channelId
+    }
+    if (that.data.maxPrice) {
+      data.maxPrice = that.data.maxPrice
+    }
+    if (that.data.minPrice) {
+      data.minPrice = that.data.minPrice
+    }
+    if (that.data.priceSort) {
+      data.priceSort = that.data.priceSort
+    }
+    if (that.data.timeSort) {
+      data.timeSort = that.data.timeSort
+    }
     wx.request({
-      url: host + '/commodityapi/commoditviewfoeeverybody?commodity_levelTwo=2983&offset=0&limit=10',
+      url: host +'/commodityapi/queryCommodityByClass',
       method:'get',
-      data:{
-        commodity_levelTwo: that.data.commodity_levelTwo,
-        offset:that.data.page,
-        limit:10,
-      },
+      data:data,
       success(res){
-        console.log(res)
-        res.data.rows.length < 10 ? requestState = false : requestState = true
-        goodsList.push(...res.data.rows)
+        let dataArray = that.data.goodsList;
+        res.data.rows.forEach(el => {
+          el.logo = el.commodity_logo.split(",")
+        })
+        dataArray.push(...res.data.rows)
         that.setData({
-          goodsList: goodsList,
-          requestState: requestState
+          goodsList: dataArray,
+          requestState: res.data.rows.length > that.data.limit
         })
       }
     })
@@ -100,23 +110,61 @@ Page({
   filterTap(){
     let that = this;
     that.setData({
-      filterStatic: !that.data.filterStatic
+      filterStatic: !that.data.filterStatic,
+      page:1,
+      goodsList:[],
     })
+    that.getGoodsList(that)
   },
-  newTap(){
-    this.setData({
-      isNew:!this.data.isNew
+  timeSortTap(){
+    let that = this;
+    that.setData({
+      timeSort: that.data.timeSort === null ? 'asc' : that.data.timeSort === 'asc' ? 'desc' : 'asc',
+      page:1,
+      goodsList: [],
     })
+    that.getGoodsList(that)
   },
-  priceTap() {
-    this.setData({
-      isMin: !this.data.isMin
+  priceSortTap() {
+    let that = this;
+    that.setData({
+      priceSort: that.data.priceSort === null ? 'asc' : that.data.priceSort === 'asc' ? 'desc' : 'asc',
     })
   },
+  blurPriceMin(e) {
+    // event.detail = {value: value}
+    let that = this;
+    that.setData({
+      minPrice: e.detail.value,
+      page: 1,
+      goodsList: [],
+    })
+    that.getGoodsList(that)
+  },
+  blurPriceMax(e) {
+    let that = this;
+    that.setData({
+      maxPrice: e.detail.value,
+      page: 1,
+      goodsList: [],
+    })
+    that.getGoodsList(that)
+  },
   close(){
     this.setData({
       filterStatic:false
     })
+  },
+  toGoodsDetail(e) { // 进入商品详情页
+    let that = this, id = e.currentTarget.dataset.id;
+    wx.navigateTo({
+      url: '/pages/buy/buy?com_id=' + id,
+    })
+  },
+  search(){
+    wx.redirectTo({
+      url: "/pages/search/search",
+    })
   }
 
 })

+ 15 - 14
pages/kind/index.wxml

@@ -4,9 +4,9 @@
     <view class='header-box'>
     <view class='auto f-box'>
     <image class='mar-r20' src='../../images/news/l_icon.png' mode="aspectFit"></image>
-      <view class='f-item f-box f-align-items-center h-search mar-t20 mar-b20'>
+      <view class='f-item f-box f-align-items-center h-search mar-t20 mar-b20' bindtap='search'>
         <icon class='iconfont icon-sousuo'></icon>
-        <input placeholder='输入搜索关键词' class='f-s26'></input>
+        <input placeholder='输入搜索关键词' disabled="true" class='f-s26'></input>
       </view>
     </view>
       
@@ -25,20 +25,20 @@
       <!-- 筛选-->
       <view class='filter-box'>
         <view class='f-box'>
-          <view class='f-item f-box f-align-items-center f-justify-content-center' bindtap='newTap'>
+          <view class='f-item f-box f-align-items-center f-justify-content-center' bindtap='timeSortTap'>
             <text>最新</text>
             <!-- 三角形 -->
             <view class='triangle-box'>
-              <view class='triangle-just {{isNew ? "active" : ""}}'></view>
-              <view class='triangle-invert {{isNew ? "" : "active"}}'></view>
+              <view class='triangle-just {{timeSort=="asc" ? "active" : ""}}'></view>
+              <view class='triangle-invert {{timeSort=="desc" ? "active" : ""}}'></view>
             </view>
           </view>
-          <view class='f-item f-box f-align-items-center f-justify-content-center' bindtap='priceTap'>
+          <view class='f-item f-box f-align-items-center f-justify-content-center' bindtap='priceSortTap'>
             <text>价格</text>
             <!-- 三角形 -->
             <view class='triangle-box'>
-              <view class='triangle-just {{isNew ? "active" : ""}}'></view>
-              <view class='triangle-invert {{isNew ? "" : "active"}}'></view>
+              <view class='triangle-just {{priceSort == "asc" ? "active" : ""}}'></view>
+              <view class='triangle-invert {{priceSort == "desc" ? "active" : ""}}'></view>
             </view>
           </view>
           <view class='f-item f-box f-align-items-center f-justify-content-center' bindtap='filterTap'>
@@ -63,11 +63,11 @@
             <view class='filter-next-title'>价格区间(元)</view>
             <view class='f-box filter-range'>
               <view class='f-item'>
-                <input placeholder='最低价'></input>
+                <input placeholder='最低价' value="{{minPrice}}" bindblur="blurPriceMin"></input>
               </view>
                <view class='f-item'>——</view>
                <view class='f-item'>
-                <input placeholder='最高价'></input>
+                <input placeholder='最高价' value="{{maxPrice}}" bindblur="blurPriceMax"></input>
               </view>
             </view>
           </view>
@@ -81,16 +81,17 @@
       <!-- goodsList -->
       <view class='goods-box '>
         <view class='f-box f-flex-wrap f-justify-content-between'>
-          <view class='goods-list' wx:for="{{goodsList}}">
-            <image src='{{item.commodity_logo}}' class='goods-img' mode='aspectFit'></image>
+          <view class='goods-list' wx:for="{{goodsList}}" data-id='{{item.id}}' bindtap='toGoodsDetail'>
+            <image src='{{host}}/images/{{item.logo[0]}}' class='goods-img' mode='aspectFit'></image>
             <!-- <view class='goods-summary'></view> -->
             <view class='goods-title'>{{item.commodity_name}}</view>
             <view class='goods-price'>¥{{item.commodity_sale}}</view>
           </view>
         </view>
-        <divider wx:if="{{!requestState}}"></divider>
-        <data-none wx:if="{{goodsList.length === 0}}"></data-none>
+        
       </view>
+      <divider wx:if="{{!requestState && page!=1}}"></divider>
+      <data-none wx:if="{{goodsList.length === 0}}"></data-none>
        
     </view>
   </view>

+ 7 - 10
pages/kind/index.wxss

@@ -1,7 +1,4 @@
 
-.classify-main{
-  background:#fff;
-}
 
 .header image{
   width:70rpx;
@@ -37,9 +34,9 @@
   border-top:2rpx solid #e0e0e0;
   z-index:100;
 }
-/* .class-right{
-  border-top:2rpx solid #e0e0e0;
-} */
+.class-right{
+  background:#fff;
+}
 .nav-list{
   height:54rpx;
   margin:25rpx 0;
@@ -68,22 +65,22 @@
 .triangle-just{
   width: 0;
   height: 0;
-  border-bottom: 11rpx solid #2d2d2d;
+  border-bottom: 11rpx solid #dcdcdc;
   border-left: 8rpx solid transparent;
   border-right: 8rpx solid transparent;
   margin:5rpx 0;
 }
 .triangle-just.active{
-  border-bottom-color:#dcdcdc;
+  border-bottom-color:#2d2d2d;
 }
 .triangle-invert.active{
-  border-bottom-color:#dcdcdc;
+  border-top-color:#2d2d2d;
 }
 .triangle-invert{
   margin:5rpx 0;
   width: 0;
   height: 0;
-  border-top: 11rpx solid #2d2d2d;
+  border-top: 11rpx solid #dcdcdc;
   border-left: 8rpx solid transparent;
   border-right: 8rpx solid transparent;
 }

+ 2 - 2
pages/patternMenu/patternMenu.wxml

@@ -53,11 +53,11 @@
             <view class='filter-next-title'>价格区间(元)</view>
             <view class='f-box filter-range'>
               <view class='f-item'>
-                <input placeholder='最低价' bindblur="blurPriceMin"></input>
+                <input placeholder='最低价' value="{{minPrice}}" bindblur="blurPriceMin"></input>
               </view>
                <view class='f-item'>——</view>
                <view class='f-item'>
-                <input placeholder='最高价' bindblur="blurPriceMax"></input>
+                <input placeholder='最高价' value="{{maxPrice}}" bindblur="blurPriceMax"></input>
               </view>
             </view>
           </view>

+ 1 - 1
pages/search/search.wxml

@@ -2,7 +2,7 @@
 <view class="container"  bindtouchstart="touchStart" bindtouchmove="touchMove" bindtouchend="touchEnd">
   <form bindsubmit="searchSubmit" action="">
     <!-- 头部搜索 -->
-    <view class="header">
+    <view class="header-search">
       <view class="header_search_wrap">
         <view class="header_search">
           <icon type="search"  size="12" color="#929aa0"  class="header_search_icon"></icon>

+ 4 - 4
pages/search/search.wxss

@@ -2,7 +2,7 @@
 page{
   background-color: #fff;
 }
-.header{
+.header-search{
   display: flex;
   flex-direction: row;
   height:104rpx;
@@ -104,16 +104,16 @@ page{
 .each_word{
   display: inline-block;
   font-size: 24rpx;
-  color:#b4a078;
+  color:#e60012;
   background-color: #f9f9f9;
   padding:9rpx 20rpx;
-  border:1rpx solid #b4a078;
+  border:1rpx solid #e60012;
   border-radius: 20px;
   margin:0 30rpx 30rpx 0; 
 }
 .each_word_active{
   color:#fff;
-  background-color: #b4a078;
+  background-color: #e60012;
 }
 /* logo */
 .logo_title_space{

+ 5 - 12
project.config.json

@@ -28,7 +28,7 @@
 			"list": []
 		},
 		"miniprogram": {
-			"current": 23,
+			"current": -1,
 			"list": [
 				{
 					"id": 0,
@@ -159,16 +159,16 @@
 					"scene": null
 				},
 				{
-					"id": -1,
+					"id": 19,
 					"name": "classify",
-					"pathName": "newsShop/pages/kind/index",
+					"pathName": "pages/kind/index",
 					"query": "",
 					"scene": null
 				},
 				{
-					"id": -1,
+					"id": 20,
 					"name": "selGift",
-					"pathName": "newsShop/pages/patternMenu/patternMenu",
+					"pathName": "pages/patternMenu/patternMenu",
 					"query": "",
 					"scene": null
 				},
@@ -180,13 +180,6 @@
 					"scene": null
 				},
 				{
-					"id": -1,
-					"name": "商品详情",
-					"pathName": "newsShop/pages/buy/buy",
-					"query": "",
-					"scene": null
-				},
-				{
 					"id": 23,
 					"name": "详情页",
 					"pathName": "pages/buy/buy",