Bladeren bron

Second Add

daisy 1 jaar geleden
bovenliggende
commit
0d90f55bd5

+ 25 - 3
fore-end/API/appraise.js

@@ -12,7 +12,8 @@ const API = {
 	getCategoryGoodsURL: '/goods/category',
 	getAllGoodsURL: '/goods',
     getSearchGoodsURL: '/goods/search',
-    postGoodsURL: '/goods/create'
+    postGoodsURL: '/goods/create',
+    getGoodsDetailURL: '/goods/detail',
 }
 
 //查询列表时传参---注意参数数据类型
@@ -119,13 +120,33 @@ function searchGoods(data) {
     )
 }
 
+//获取商品详细描述
+function getGoodsDetail(data) {
+    console.log(data); 
+    return request.get(
+        API.getGoodsDetailURL + `/${data.id}` + '?id=' + data.id + '&uid=' + data.uid + '&date=' + data.time
+    )
+}
+
 //上传商品
 function upLoadGoods(data) {
     return request.post(
         API.postGoodsURL,
-        data
+        {
+            data: {
+                "categories":  [data.gid],
+                "desc": data.desc,
+                "ownerId": 0,
+                "pic": data.fileList,
+                "place": data.address,
+                "price": data.price,
+                "state": 0,
+                "title": data.title
+            }
+        }
     )
 }
+
 module.exports = {
     createCommont,
 	getCommentList,
@@ -140,5 +161,6 @@ module.exports = {
     registerURL: API.registerURL,
     getAllGoods,
     searchGoods,
-    upLoadGoods
+    upLoadGoods,
+    getGoodsDetail
 }

+ 21 - 35
fore-end/pages/append/append.js

@@ -1,7 +1,8 @@
 // pages/append/append.js
 const { getCategoryAPI, upLoadGoods } = require('../../API/appraise')
 const { upLoad, chooseImage } = require('../../utils/util')
-const baseURL = "http://192.168.31.30:8084";
+const baseURL = "http://192.168.31.27:8084";
+import Toast from '@vant/weapp/toast/toast'
 
 Page({
 
@@ -18,14 +19,15 @@ Page({
         clssify: [],
         valueKeyName: "",
         index: 0,
+        fileImg: [],
         // 页面数据们
         title: "",
         desc: "",
-        price: Number,
+        price: 0,
         address: "",
         fileList: [],
+        gid: Number,
         maxgoodsURL: 6
-        // clssify: Number
     },
     popChange() {
         this.setData({
@@ -62,7 +64,7 @@ Page({
     numInput(e){
         const {value, cursor, keyCode} = e.detail;
         this.setData({
-            price: value
+            price: parseInt(value)
         })
     },
     adressInput(e) {
@@ -72,36 +74,18 @@ Page({
         })
     },
     upData(){
-        // const price = this.data.price;
-        // const address = this.data.address;
-        // const classify = this.data.id[this.data.index];
-        // upLoadGoods(this.data).then((res) => {
-        //     console.log(res);
-        // }).catch((err) => {
-        //     console.log(err);
-        // })
-        wx.request({
-          url: baseURL + '/goods/create',
-          method: "POST",
-          header: {
-              "content-type": "application/x-www-form-urlencoded"
-          },
-          data: {
-            "categories": [
-               this.data.id[this.data.index]
-            ],
-            "desc": this.data.desc,
-            "ownerId": 0,
-            "pic": this.data.fileList,
-            "place": this.data.address,
-            "price": this.data.price,
-            "state": 0,
-            "title": this.data.title
-          },
-          success: function(res) {
-              console.log(res);
-          }
+        this.setData({
+            gid: this.data.id[this.data.index]
+        })
+        upLoadGoods(this.data).then((res) => {
+            console.log(res);
+            Toast({
+                message: '发布商品成功!'
+            })
+        }).catch((err) => {
+            console.log(err); 
         })
+        console.log(this.data);
     },
     /**
      * 生命周期函数--监听页面加载
@@ -177,10 +161,12 @@ Page({
     afterRead(e) {
         const { file } = e.detail;
         upLoad(file.url).then((res) => {
-            const { fileList = [] } = this.data;
-            fileList.push({ ...file, url: res.data });
+            const { fileList = [], fileImg = [] } = this.data;
+            fileImg.push({ ...file, url: res.data });
+            fileList.push(file.url)
             this.setData({
                 fileList,
+                fileImg
             })
             console.log(this.data.fileList);
         })

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

@@ -1,5 +1,7 @@
 {
-    "usingComponents": {},
+    "usingComponents": {
+        "van-toast": "@vant/weapp/toast/index"
+    },
     "navigationBarTitleText": "发布商品",
     "requiredPrivateInfos": [
       "getLocation"

+ 3 - 2
fore-end/pages/append/append.wxml

@@ -9,6 +9,7 @@
     <view style="float: right;" bind:tap="upData">
         <van-button round type="info">发布</van-button>
     </view>
+    <van-toast id="van-toast"/>
 </view>
 
 <!-- 商品描述模块 -->
@@ -23,7 +24,7 @@
     <!-- 选择图片 -->
     <view class="upLoad">
         <!-- <van-image fit="cover" width="100" height="100" src="{{goodsURL}}" bindtap="chooseImage" style="float: left;"/> -->
-        <van-uploader file-list="{{ fileList }}" bind:after-read="afterRead" max-count="3" deletable="{{true}}"/>
+        <van-uploader file-list="{{ fileImg }}" bind:after-read="afterRead" max-count="3" deletable="{{true}}"/>
     </view>
 </view>
 
@@ -38,7 +39,7 @@
     <view class="nav">
         <text style="float: left; font-weight: 600; margin-top: 8rpx;">交易地点</text>
         <view style="float: left; margin-left: 310rpx; margin-top: -50rpx; margin-right: -70rpx; position: relative;">
-                <input type="number" placeholder="                           地点" bindinput="adressInput"/>
+                <input type="text" maxlength="20" bindinput="adressInput"/>
         </view>
     </view>
     <view class="nav">

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

@@ -1,3 +1,4 @@
 {
-	"usingComponents": {}
+    "usingComponents": {},
+    "navigationBarTitleText": "搜索结果"
 }

+ 30 - 5
fore-end/pages/details/details.js

@@ -1,4 +1,7 @@
 // pages/details/details.js
+const { getGoodsDetail } = require('../../API/appraise')
+const { formatTime } = require('../../utils/util')
+
 Page({
 
     /**
@@ -8,27 +11,49 @@ Page({
         id: 0,
         title: "",
         price: 0,
-        pic: ""
+        pic: [],
+        desc: "",
+        uid: Number,
+        time: Number
     },
 
     /**
      * 生命周期函数--监听页面加载
      */
     onLoad(options) {
-        console.log(options);
+        //将传递过来的关于商品的数据渲染到页面
         this.setData({
             id: options.id,
             title: options.title,
             price: options.price,
-            pic: options.img
+            pic: options.img,
+            uid: parseInt(options.uid)
+        })
+        console.log(this.data.pic);
+        //获取时间戳
+        var date = Date.parse(new Date())
+        date = date / 1000
+        this.setData({
+            time: date
+        })
+        this.GoodsDetail();
+    },
+    GoodsDetail() {
+        getGoodsDetail(this.data).then((res) => {
+            const { code, data, message} = res.data; 
+            //通过获取详细信息将商品的描述获取并渲染
+            this.setData({
+                desc: data.Desc
+            })
+        }).catch((err) => {
+            console.log(err);
         })
     },
-
     /**
      * 生命周期函数--监听页面初次渲染完成
      */
     onReady() {
-
+        
     },
 
     /**

+ 3 - 2
fore-end/pages/details/details.wxml

@@ -1,7 +1,8 @@
 <!--pages/details/details.wxml-->
 <!-- 商品图片展示 -->
 <view class="detail_pic">
-    <van-image width="350" height="300" fit="cover" radius="10" src="{{pic}}" />
+    <!-- <van-image width="350" height="300" fit="cover" radius="10" src="{{pic}}" /> -->
+    <image src="{{pic}}" mode="" style="width: 700rpx; height: 600rpx;"/>
 </view>
 
 <!-- 用户展示 -->
@@ -17,7 +18,7 @@
     <!-- 卖的商品信息 -->
     <view class="sell_msg">
         <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 class="sell_detail" style="width: 100%; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;">{{desc}}</view>
     </view>
 </view>
 

+ 28 - 11
fore-end/pages/home/home.js

@@ -1,6 +1,11 @@
 // pages/home/home.js
-const { getCategoryAPI, getAllGoods} = require('../../API/appraise')
-
+const { getCategoryAPI, getAllGoods, getUserInfo} = require('../../API/appraise')
+const { formatTime } = require('../../utils/util')
+var getOrderOption = {
+	data: {
+		id: wx.getStorageSync('uid'),
+	}
+}
 
 Page({
 
@@ -16,8 +21,10 @@ Page({
         allGoods: [],
         page: 1,
         pageSize: 6,
-        flag: true,
-        isLoading: false
+        isLoading: false,
+        time: Number,
+        id: 0,
+        uid: Number
     },
 
     userTo() {
@@ -48,11 +55,6 @@ Page({
             url: '/pages/classify_detail/classify_detail?classify_id=' + id + '&title=' + title,
         })
     },
-    flagChange() {
-        this.setData({
-            flag: false
-        })
-    },
     /**
      * 生命周期函数--监听页面加载
      */
@@ -76,6 +78,10 @@ Page({
     },
     //获取推荐商品
     getGoodsList() {
+        var time = formatTime(new Date());
+        this.setData({
+            time: time
+        })
         //加载的loading效果
         wx.showLoading({
             title: '数据获取中',
@@ -92,15 +98,26 @@ Page({
             isLoading: false
         })
     },
+    // GoodsDetail() {
+    //     getGoodsDetail(this.data).then((res) => {
+    //         console.log(res);
+    //     }).catch((err) => {
+    //         console.log(err);
+    //     })
+    // },
     //推荐商品传递数据
     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;
+        this.setData({
+            uid: parseInt(getOrderOption.data.id)
+        })
+        const uid = this.data.uid;
+        // this.GoodsDetail();
         wx.navigateTo({
-          url: '/pages/details/details?id=' + id + '&title=' + title + '&price=' + price + '&img=' + comImg,
+          url: '/pages/details/details?id=' + id + '&title=' + title + '&price=' + price + '&img=' + comImg + '&uid=' + uid,
         })
     },
     /**

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

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

+ 2 - 2
fore-end/pages/home/home.wxml

@@ -40,7 +40,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}}' bind:tap="flagChange">
+        <view bind:tap="detailClassifyTo" data-num='{{item.Id}}' data-title='{{item.Name}}'>
             <van-image width="75" height="75" radius="20rpx" src="{{item.Pic}}" />
             <view class="name_show">{{item.Name}}</view>
         </view>
@@ -56,7 +56,7 @@
 <!-- 商品卡片 -->
 <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}}'>
+        <view  bind:tap="detailTo" data-id='{{item.Id}}' data-price='{{item.Price}}' data-Title='{{item.Title}}' data-pic='{{item.Pic}}' data-uid='{{item.OwnerId}}'>
             <image src="{{item.Pic}}" alt="" class="commodity_image"/>
             <text class="commodity_name">{{item.Title}}</text>
             <text class="price">¥{{item.Price}}</text>

+ 5 - 3
fore-end/pages/home/home.wxss

@@ -26,11 +26,13 @@
     height: 100rpx;
     border-radius: 20rpx;
 }
-
+ 
 .username {
     float: left;
-    /* width: 100rpx; */
-    width: fit-content;
+    width: 530rpx;
+    white-space: nowrap;
+    overflow: hidden;
+    text-overflow: ellipsis;
     margin-top: 30rpx;
     margin-left: 20rpx;
     font-size: 18px;

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

@@ -45,7 +45,6 @@ Page({
         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)   
@@ -58,7 +57,7 @@ Page({
             wx.navigateTo({
                 url: '../../pages/com_search/com_search?comList=' + new_arr,
             })
-        }, 1000)
+        }, 100)
     },
     //删除搜索数据
     deleteInput(){

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

@@ -22,7 +22,7 @@ Page({
      * 生命周期函数--监听页面加载
      */
     onLoad(options) {
-
+        console.log(getOrderOption);
     },
 
     /**

+ 3 - 3
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.30:8084";//后台服务提供的地址
+const baseURL = "http://124.222.126.172:8084";//后台服务提供的地址  
 const uploadUrl = "/pic/upload";
 const formatTime = date => {
   const year = date.getFullYear()
@@ -25,7 +25,7 @@ function http(url, option) {
         wx.request({
 		  url: baseURL + url,
 		  header:{
-			"Authorization": (url!=loginURL && url!=registerURL) ? wx.getStorageSync('token') : '' 
+            "Authorization": (url!=loginURL && url!=registerURL) ? wx.getStorageSync('token') : '' 
 		  },
 		  ...option,
           success(res) {
@@ -94,7 +94,7 @@ function chooseImage(){
 
 
 module.exports = {
-    formatTime,
+    formatTime: formatTime,
 	http,
 	upLoad,
     chooseImage