daisy hace 1 año
padre
commit
91508481ce

+ 20 - 5
fore-end/API/appraise.js

@@ -9,9 +9,9 @@ const API = {
 	modifyURL: '/user/modify',
 	getOrderURL: '/order/user',
 	getCategoryURL: '/category',
-	getCategoryGoods: '/goods/category'
-	
-    //放接口URL
+	getCategoryGoodsURL: '/goods/category',
+	getAllGoodsURL: '/goods',
+    getSearchGoodsURL: '/goods/search'
 }
 
 //查询列表时传参---注意参数数据类型
@@ -100,10 +100,23 @@ function getCategoryAPI() {
 // 获取分类出来的商品信息
 function getClassifyGoods(data) {
     return request.get(
-		API.getCategoryGoods + `/${data.page}/${data.pageSize}` + '?category=' + data.id
+		API.getCategoryGoodsURL + `/${data.page}/${data.pageSize}` + '?category=' + data.id
 	)
 }
 
+//获取所有的商品
+function getAllGoods(data) {
+    return request.get(
+        API.getAllGoodsURL + `/${data.page}/${data.pageSize}`
+    )
+}
+
+//搜索获取商品
+function searchGoods(data) {
+    return request.get(
+        API.getSearchGoodsURL + `/${data.page}/${data.pageSize}` + '?search=' + data.inputValue
+    )
+}
 module.exports = {
     createCommont,
 	getCommentList,
@@ -115,5 +128,7 @@ module.exports = {
 	getCategoryAPI,
 	getClassifyGoods,
 	loginURl: API.loginURL,
-	registerURL: API.registerURL
+    registerURL: API.registerURL,
+    getAllGoods,
+    searchGoods
 }

+ 6 - 1
fore-end/app.json

@@ -64,5 +64,10 @@
         ],
         "borderStyle": "white"
     },
-    "sitemapLocation": "sitemap.json"
+    "sitemapLocation": "sitemap.json",
+    "permission": {
+        "scope.userLocation": {
+          "desc": "你的位置信息将用于小程序位置接口的效果展示"
+        }
+    }
 }

+ 1 - 1
fore-end/components/commodity_card/commodity_card.js

@@ -1,5 +1,5 @@
 // components/commodity_card/commodity_card.js
-const { getClassifyGoods } = require('../../API/appraise')
+const { getClassifyGoods, getAllGoods } = require('../../API/appraise')
 
 Component({
     lifetimes: {

+ 4 - 0
fore-end/components/commodity_card/commodity_card.wxss

@@ -24,6 +24,10 @@
     position: absolute;
     top: 360rpx;
     left: 15rpx;
+    width: 350rpx;
+    white-space: nowrap;
+    overflow: hidden;
+    text-overflow: ellipsis;
 }
 
 .price {

+ 22 - 1
fore-end/pages/append/append.js

@@ -5,9 +5,30 @@ Page({
      * 页面的初始数据
      */
     data: {
-
+        fileList: [],
+        latitude: 0,
+        longtitude: 0,
+        mapName: ""
     },
 
+    moveLocation() {
+        let _this = this;
+        wx.chooseLocation({
+            success: function(res) {
+                console.log(res.name);
+                _this.setData({
+                    mapName: res.name
+                })
+            },
+            fail: function() {
+                console.log(err);
+            }
+        })
+    },
+    numInput(e){
+        const {value, cursor, keyCode} = e.detail;
+        console.log(value);
+    },
     /**
      * 生命周期函数--监听页面加载
      */

+ 12 - 1
fore-end/pages/append/append.json

@@ -1,3 +1,14 @@
 {
-    "usingComponents": {}
+    "usingComponents": {
+        "van-uploader": "@vant/weapp/uploader/index"
+    },
+    "navigationBarTitleText": "发布商品",
+    "requiredPrivateInfos": [
+      "getLocation"
+    ],
+    "permission": {
+      "scope.userLocation": {
+        "desc": "你的位置信息将用于小程序位置接口的效果展示"
+      }
+    }
 }

+ 34 - 1
fore-end/pages/append/append.wxml

@@ -1,2 +1,35 @@
 <!--pages/append/append.wxml-->
-<text>pages/append/append.wxml</text>
+<!-- title -->
+<view class="title">
+    <!-- 标题 -->
+    <view style="float: left; font-weight: 700; font-size: 45rpx; margin-top: 10rpx;">发布商品</view>
+    <!-- 存草稿--缓存 -->
+    <view style="float: left; margin-left: 300rpx; margin-top: 20rpx;">存草稿</view>
+    <!-- 发布 -->
+    <view style="float: right;">
+        <van-button round type="info">发布</van-button>
+    </view>
+</view>
+
+<!-- 商品描述模块 -->
+<view class="discribe">
+    <input type="text" placeholder="描述一下商品..."/>
+    <view class="upLoad">
+        <van-uploader file-list="{{ fileList }}" bind:after-read="afterRead"/>
+    </view>
+</view>
+
+<!-- 商品导航栏 -->
+<view class="navigation">
+    <view class="nav nav_price">
+        <text style="float: left; font-weight: 600;">价格</text>
+        <view style="float: left; margin-left: 540rpx; margin-top: -50rpx; position: relative;">
+                <input type="number" placeholder="¥0.00" bindinput="numInput"/>
+        </view>
+        <van-icon name="arrow" />
+    </view>
+    <view class="nav" bind:tap="moveLocation">
+        <text style="float: left; font-weight: 600; margin-top: 8rpx;">交易地点</text>
+        <van-icon name="map-marked" size="50rpx" style="float: right; margin-top: 10rpx; margin-right: 5rpx;"/>
+    </view>
+</view>

+ 33 - 1
fore-end/pages/append/append.wxss

@@ -1 +1,33 @@
-/* pages/append/append.wxss */
+/* pages/append/append.wxss */
+.title{
+    width: 100%;
+    height: 90rpx;
+}
+
+.discribe { 
+    width: 96%;
+    height: 600rpx;
+    margin-top: 20rpx;
+    padding: 15rpx;
+    background-color: #DDDEDF;
+    border-radius: 20rpx;
+}
+
+.upLoad {
+    margin-top: 350rpx;
+    width: 300rpx;height: 300rxp;
+    overflow: hidden;
+}
+.navigation {
+    width: 90%;
+    height: 240rpx;
+    margin-top: 20rpx;
+    padding: 34rpx;
+    background-color: #DDDEDF;
+    border-radius: 20rpx;
+}
+
+.nav {
+    height: 30%;
+    border-bottom: 4rpx solid rgba(0, 0, 0, 0.3);
+}

+ 1 - 1
fore-end/pages/classify/classify.js

@@ -1,5 +1,5 @@
 // pages/classify/classify.js
-const { getCategoryAPI,getClassifyGoods} = require('../../API/appraise')
+const { getCategoryAPI } = require('../../API/appraise')
 
 
 Page({

+ 2 - 1
fore-end/pages/classify/classify.json

@@ -1,3 +1,4 @@
 {
-    "usingComponents": {}
+    "usingComponents": {},
+    "navigationBarTitleText": "分类"
 }

+ 7 - 2
fore-end/pages/classify_detail/classify_detail.js

@@ -11,7 +11,7 @@ Page({
         classifyShow: [],
         page: 1,
         pageSize: 6,
-        id: 1,
+        id: 3,
         title: "",
         //节流阀
         isLoading: false
@@ -21,13 +21,17 @@ Page({
      * 生命周期函数--监听页面加载
      */
     onLoad(options) {
-        this.getGoods()
+        //setData和getGoods的顺序也非常重要
         this.setData({
             // 传递点击的分类id
             id: options.classify_id,
             //传递点击的分类名称
             title: options.title
+        }),
+        wx.setNavigationBarTitle({
+          title: this.data.title,
         })
+        this.getGoods()
     },
 
     getGoods() {
@@ -36,6 +40,7 @@ Page({
           title: '数据获取中',
         })
         getClassifyGoods(this.data).then((res) => {
+            console.log(this.data);
             const { data } = res.data;
             console.log(res);
             this.setData({

+ 2 - 1
fore-end/pages/details/details.json

@@ -1,5 +1,6 @@
 {
     "usingComponents": {
         "commodity-card": "/components/commodity_card/commodity_card"
-    }
+    },
+    "navigationBarTitleText": "商品详情"
 }

+ 1 - 1
fore-end/pages/details/details.wxml

@@ -16,7 +16,7 @@
     </view>
     <!-- 卖的商品信息 -->
     <view class="sell_msg">
-        <text class="sell_title">女士夏秋套装\n</text>
+        <text class="sell_title">{{title}}\n</text>
         <view class="sell_detail" style="width: 100%; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;">女士T恤+短裤+鞋,未穿过,出售,价格可谈,女士T恤+短裤+鞋,未穿过,出售,价格可谈</view>
     </view>
 </view>

+ 4 - 0
fore-end/pages/details/details.wxss

@@ -19,6 +19,10 @@
     top: 10rpx;
     left: 160rpx;
     font-weight: 600;
+    width: 300rpx;
+    overflow: hidden;
+    white-space: nowrap;
+    text-overflow: ellipsis;
 }
 
 .price {

+ 53 - 7
fore-end/pages/home/home.js

@@ -1,5 +1,5 @@
 // pages/home/home.js
-const { getCategoryAPI,getClassifyGoods} = require('../../API/appraise')
+const { getCategoryAPI, getAllGoods} = require('../../API/appraise')
 
 
 Page({
@@ -12,6 +12,12 @@ Page({
         classifyList: [],
         //用于存放页面上划高度
         scrollTop: 0,
+        //存放所有商品
+        allGoods: [],
+        page: 1,
+        pageSize: 6,
+        flag: true,
+        isLoading: false
     },
 
     userTo() {
@@ -24,6 +30,11 @@ Page({
           url: '/pages/classify/classify',
         })
     },
+    messageTo() {
+        wx.switchTab({
+          url: '/pages/message/message',
+        })
+    },
     searchTo() {
         wx.navigateTo({
           url: '/pages/search/search',
@@ -37,11 +48,17 @@ Page({
             url: '/pages/classify_detail/classify_detail?classify_id=' + id + '&title=' + title,
         })
     },
+    flagChange() {
+        this.setData({
+            flag: false
+        })
+    },
     /**
      * 生命周期函数--监听页面加载
      */
     onLoad(options) {
         this.getClassifyList();
+        this.getGoodsList();
         this.setData({
             avatarUrl:wx.getStorageSync('avatarUrl'),
             nickName: wx.getStorageSync('nickName')
@@ -57,11 +74,35 @@ Page({
             })
         })
     },
-    // getGoodsList() {
-    //     getClassifyGoods(this.data).then((data) => {
-    //         console.log(data);
-    //     })
-    // },
+    //获取推荐商品
+    getGoodsList() {
+        //加载的loading效果
+        wx.showLoading({
+            title: '数据获取中',
+        })
+        getAllGoods(this.data).then((res) => {
+            const { code, data, message } = res.data;
+            const d = data.data;
+            this.setData({
+                allGoods: [...this.data.allGoods, ...d],
+                isLoading: true
+            })
+        })
+        this.setData({
+            isLoading: false
+        })
+    },
+    //推荐商品传递数据
+    detailTo(e) {
+        console.log(e.currentTarget.dataset);
+        const id = e.currentTarget.dataset.id;
+        const title = e.currentTarget.dataset.title;
+        const price = e.currentTarget.dataset.price;
+        const comImg = e.currentTarget.dataset.pic;
+        wx.navigateTo({
+          url: '/pages/details/details?id=' + id + '&title=' + title + '&price=' + price + '&img=' + comImg,
+        })
+    },
     /**
      * 生命周期函数--监听页面初次渲染完成
      */
@@ -101,7 +142,12 @@ Page({
      * 页面上拉触底事件的处理函数
      */
     onReachBottom() {
-
+        if(this.data.isLoading) {
+            this.setData({
+                page: this.data.page + 1,
+            })
+            this.getGoodsList()
+        }
     },
 
     /**

+ 2 - 1
fore-end/pages/home/home.json

@@ -1,5 +1,6 @@
 {
     "usingComponents": {
         "commodity_card": "/components/commodity_card/commodity_card"
-    }
+    },
+    "navigationBarTitleText": "主页"
 }

+ 22 - 13
fore-end/pages/home/home.wxml

@@ -2,19 +2,19 @@
 <!-- 头部 -->
 <view class="bigBox">
     <view class="head" style="position: fixed;">
-    <view bind:tap="userTo">
-        <!-- 头像 -->
-        <view class="head-portrait-bg">
-            <van-image width="100rpx" height="100rpx" fit="cover" src="{{avatarUrl}}" radius="20rpx"></van-image>
+        <view bind:tap="userTo">
+            <!-- 头像 -->
+            <view class="head-portrait-bg">
+                <van-image width="100rpx" height="100rpx" fit="cover" src="{{avatarUrl}}" radius="20rpx"></van-image>
+            </view>
+            <!-- 昵称 -->
+            <view class="username">{{nickName}}</view>
+        </view>
+        <!-- 消息提示 -->
+        <view  bind:tap="messageTo">
+            <van-icon name="bell" custom-style="margin" class="head_bell" size="50rpx" info="9" color="var(--themeColor)"/>
         </view>
-        <!-- 昵称 -->
-        <view class="username">{{nickName}}</view>
-    </view>
-    <!-- 消息提示 -->
-    <view>
-        <van-icon name="bell" custom-style="margin" class="head_bell" size="50rpx" info="9" color="var(--themeColor)"/>
     </view>
-</view>
     <!-- 搜索框 -->
     <view class="search_box" style="position: fixed; top: 129rpx">
         <input type="search" name="" placeholder="搜索..." class="search_text" bind:tap="searchTo"/>
@@ -38,7 +38,7 @@
  <!-- 分类推荐 -->
 <scroll-view scroll-x style='display: flex;white-space:nowrap; margin-top: 80rpx;'>
     <view class="categories_card" wx:for="{{classifyList}}" wx:for-item="item" wx:key="index">
-        <view bind:tap="detailClassifyTo" data-num='{{item.Id}}' data-title='{{item.Name}}'>
+        <view bind:tap="detailClassifyTo" data-num='{{item.Id}}' data-title='{{item.Name}}' bind:tap="flagChange">
             <van-image width="75" height="75" radius="20rpx" src="{{item.Pic}}" />
             <view class="name_show">{{item.Name}}</view>
         </view>
@@ -52,6 +52,15 @@
 </view>
 
 <!-- 商品卡片 -->
-<commodity_card></commodity_card>
+<view class="commodity">
+    <view class="commodity_show" wx:for="{{allGoods}}" wx:key="index">
+        <view  bind:tap="detailTo" data-id='{{item.Id}}' data-price='{{item.Price}}' data-Title='{{item.Title}}' data-pic='{{item.Pic}}'>
+            <image src="{{item.Pic}}" alt="" class="commodity_image"/>
+            <text class="commodity_name">{{item.Title}}</text>
+            <text class="price">¥{{item.Price}}</text>
+            <avatar></avatar>
+        </view>
+    </view>
+</view>
 
 <van-toast id="van-toast" />

+ 42 - 9
fore-end/pages/home/home.wxss

@@ -51,14 +51,6 @@
     border-radius: 20rpx;
 }
 
-.addClass {
-    position: fixed;
-    top: 0rpx;
-    z-index: 100;
-    margin-right: 20rpx;
-    margin-top: 130rpx;
-}
-
 .search_text {
     float: left;
     padding-left: 15rpx;
@@ -68,6 +60,7 @@
 .search_icon {
     margin-bottom: 1rpx;
 }
+
 .search_button {
     float: right;
     width: 80rpx;
@@ -123,4 +116,44 @@ button[plain]{ border:0 }
     top: 32rpx
 }
 
-/* ------------------------------ */
+/* ------------------------------ */
+
+/* 商品 */
+.commodity {
+    display: flex;
+    flex-wrap: wrap; /*自动换行*/
+    margin-top: 10rpx;
+}
+
+.commodity_show {
+    display: flex;
+    position: relative;
+    width: 48%;
+    height: 500rpx;
+    padding: 7rpx;
+    justify-content: center;
+}
+
+.commodity_image {
+    width: 340rpx;
+    height: 340rpx;
+    border-radius: 20rpx;
+}
+
+.commodity_name {
+    position: absolute;
+    top: 360rpx;
+    left: 15rpx;
+    width: 350rpx;
+    white-space: nowrap;
+    overflow: hidden;
+    text-overflow: ellipsis;
+}
+
+.price {
+    position: absolute;
+    top: 400rpx;
+    left: 12rpx;
+    color: #a08016;
+    font-weight: 600;
+}

+ 86 - 3
fore-end/pages/search/search.js

@@ -1,20 +1,101 @@
 // pages/search/search.js
+const { searchGoods } = require('../../API/appraise')
+
 Page({
 
     /**
      * 页面的初始数据
      */
     data: {
-
+        historyStorage: [],//历史搜索
+        historyStorageShow: false,//清空历史记录
+        flag: true,//换一批推荐
+        inputValue: "",
+        replaceValue: "",
+        searchResult: [{title: "短裤"}, {title: "短裙"}, {title: "连衣裙"}, {title: "卫衣"}, {title: "外套"}],
+        search: false,
+        page: 1,
+        pageSize: 6
     },
 
+    //输入数据显示搜索推荐
+    showResult(){
+        this.setData({
+            show: true
+        })
+    },
+    getInputValue(e){
+        const {value, cursor, keyCode} = e.detail;
+        this.setData({
+            inputValue: value
+        })
+        if(this.data.inputValue != "") {
+            this.getSearchGoods()
+        }
+    },
+    putInputValue(e){
+        this.setData({
+            inputValue: e.currentTarget.dataset.postname
+        })
+    },
+    //开始搜索
+    searchBegin(e){
+        let _this = this;
+        var data = e.currentTarget.dataset.searchdata;
+        console.log(data);
+        // _this.data.replaceValue = e.currentTarget.dataset.postname;
+        wx.setStorageSync(
+            'historyStorage',
+            _this.data.historyStorage.concat(_this.data.inputValue)   
+        )
+    },
+    //删除搜索数据
+    deleteInput(){
+        this.setData({
+            inputValue: ""
+        })
+    },
+    //清空历史记录
+    remove(){
+        var _this = this
+        wx.showModal({
+            title: '提示',
+            content: '确认清除所有历史记录?',
+            success: function(res) {
+                if(res.confirm) {
+                    wx.removeStorageSync(
+                        'historyStorage'
+                    ),
+                    _this.setData({
+                        historyStorage: []
+                    })
+                } else {
+                    console.log("点击取消");
+                }
+            }
+          })
+    },
     /**
      * 生命周期函数--监听页面加载
      */
     onLoad(options) {
-
+        //异步获取数据
+        var x =  wx.getStorageSync(
+            'historyStorage',    
+        )
+        //将之前的数据和现在得到的异步数据拼接渲染
+        this.setData({
+            historyStorage: [...this.data.historyStorage ,...x]
+        })
     },
 
+    getSearchGoods() {
+        searchGoods(this.data).then((res) => {
+            console.log(res);
+        }).catch((err) => {
+            console.log(err);
+        })
+    },
     /**
      * 生命周期函数--监听页面初次渲染完成
      */
@@ -26,7 +107,9 @@ Page({
      * 生命周期函数--监听页面显示
      */
     onShow() {
-
+        if(this.data.inputValue != "") {
+            this.getSearchGoods()
+        }
     },
 
     /**

+ 2 - 1
fore-end/pages/search/search.json

@@ -2,5 +2,6 @@
     "usingComponents": {
         "van-search": "@vant/weapp/search/index",
         "avater": "/components/avatar/avatar"
-    }
+    },
+    "navigationBarTitleText": "搜索"
 }

+ 21 - 9
fore-end/pages/search/search.wxml

@@ -1,28 +1,40 @@
 <!--pages/search/search.wxml-->
 <!-- 搜素框 -->
-<view class="search_box">
+<view class="search_box" bind:tap="showResult">
     <view class="base_search">
         <van-icon name="search" size="50rpx" color="#696969" style="margin-top: 15rpx; margin-left: -430rpx;"/>
-        <input type="search" name="" placeholder="搜索..." class="search_text"/>
+        <input type="search" name="" placeholder="搜索..." bindinput="getInputValue" value="{{inputValue}}" class="search_text"/>
+        <van-icon name="cross" style="float: right; margin-top: 24rpx; margin-right: 15rpx;" bind:tap="deleteInput"/>
     </view>
     <!-- 搜索按钮 -->
-    <view class="search_button">搜索</view>
+    <view class="search_button" bind:tap="onClose" catch:tap="searchBegin" data-searchdata="{{inputValue}}">搜索</view>
 </view>
 
+<!-- 搜索结果展示 -->
+<!-- 当搜索框数据不为0才显示搜索结果 wx:if="{{inputValue != ''}}" -->
+<view class="searchResult" wx:if="{{inputValue != ''}}" hidden="{{show ? false : true}}">
+    <!-- 单个结果 -->
+    <view class="preResult" wx:for="{{searchResult}}" wx:key="index" bind:tap="putInputValue" data-postname="{{item.title}}">
+        <text class="textResult">{{item.title}}</text>
+        <van-icon name="arrow" style="float: right; margin-top: 10rpx;"/>
+    </view>
+</view>
 <!-- 搜索历史 -->
 <view class="history">
     <view class="history_title">搜索历史</view>
     <!-- 清空 -->
-    <view class="empty">
-        <van-icon name="delete-o" />\t
+    <view class="empty" catch:tap="remove">
+        <van-icon name="delete-o"/>\t
         <text>清空</text>
     </view>
     <!-- 历史记录展示 -->
-    <view class="history_show">
-        <view class="history_card">
-            <text space="nbsp">  iPhone手机  </text>
+    <scroll-view class="scroll" scroll-y="true">
+        <view class="history_show">
+            <view class="history_card" wx:for="{{historyStorage}}" wx:key="index">
+                <text space="nbsp">{{item}}</text>
+            </view>
         </view>
-    </view>
+    </scroll-view>
 </view>
 
 <!-- 猜你喜欢界面 -->

+ 27 - 1
fore-end/pages/search/search.wxss

@@ -20,6 +20,25 @@
     color: #494545;
 }
 
+/* 搜索结果展示 */
+.searchResult {
+    width: 100%;
+    height: 100%;
+    position: absolute;
+    margin-right: -20rpx;
+    z-index: 100;
+}
+
+.preResult {
+    width: 95%;
+    height: 80rpx;
+    padding-top: 30rpx;
+    padding-left: 10rpx;
+    padding-right: 10rpx;
+    background-color: #F5F5F5;
+    border-bottom: 2px solid #eee;
+}
+
 /* 搜索历史 */
 .history {
     width: 100%;
@@ -37,6 +56,10 @@
     margin-left: 580rpx;
 }
 
+.scroll {
+    height: 150rpx;
+}
+
 .history_show {
     width: 100%;
     height: 100rpx;
@@ -44,8 +67,11 @@
 }
 
 .history_card {
+    display: inline-block;
     width: fit-content;
-    height: 65rpx;
+    margin-left: 20rpx;
+    margin-top: 4rpx;
+    padding: 0 10rpx;
     background-color: #E8E7E7;
     border-radius: 20rpx;
     line-height: 65rpx;

+ 4 - 4
fore-end/project.private.config.json

@@ -2,7 +2,7 @@
 	"description": "项目私有配置文件。此文件中的内容将覆盖 project.config.json 中的相同字段。项目的改动优先同步到此文件中。详见文档:https://developers.weixin.qq.com/miniprogram/dev/devtools/projectconfig.html",
 	"projectname": "wechatTrading",
 	"setting": {
-		"compileHotReLoad": false,
+		"compileHotReLoad": true,
 		"urlCheck": false
 	},
 	"condition": {
@@ -10,15 +10,15 @@
 			"list": [
 				{
 					"name": "",
-					"pathName": "pages/home/home",
+					"pathName": "pages/append/append",
 					"query": "",
 					"launchMode": "default",
 					"scene": null
 				},
 				{
 					"name": "",
-					"pathName": "pages/classify_detail/classify_detail",
-					"query": "classify_id=1",
+					"pathName": "pages/home/home",
+					"query": "",
 					"launchMode": "default",
 					"scene": null
 				}

+ 1 - 1
fore-end/utils/util.js

@@ -1,6 +1,6 @@
 import Toast from '@vant/weapp/toast/toast';
 const { loginURL, registerURL } = require('../API/appraise')
-const baseURL = "http://192.168.31.28:8084";//后台服务提供的地址
+const baseURL = "http://192.168.31.30:8084";//后台服务提供的地址
 const uploadUrl = "/pic/upload";
 const formatTime = date => {
   const year = date.getFullYear()