Bladeren bron

feat: 对接订单列表和查看物流

Moss 1 jaar geleden
bovenliggende
commit
123b84b30f

+ 28 - 0
src/filters/index.js

@@ -59,3 +59,31 @@ export function priceFilter2(val) {
 	return `¥${val.toFixed(2)}`;
 }
 
+/**
+ * @param {number} time
+ * @returns {string}
+ */
+export function timeFilter(date) {
+  date = new Date(date);
+  let time = date.getTime();
+  if (('' + time).length === 10) {
+    time = parseInt(time) * 1000
+  } else {
+    time = +time
+  }
+  const d = new Date(time)
+  const now = Date.now()
+
+  const diff = (now - d) / 1000
+
+  if (diff < 30) {
+    return '刚刚'
+  } else if (diff < 3600) {
+    // less 1 hour
+    return Math.ceil(diff / 60) + '分钟前'
+  } else if (diff < 3600 * 24) {
+    return Math.ceil(diff / 3600) + '小时前'
+  } else if (diff < 3600 * 24 * 2) {
+    return '1天前'
+  }
+}

+ 1 - 1
src/pages/goods/detail.vue

@@ -39,7 +39,7 @@
           <view class="it">{{detail.energy}}</view>
         </view>
         <view class="info">
-          <text>{{detail.goodsCreateTime}}</text>
+          <text>{{detail.goodsCreateTime | timeFilter}}发布</text>
         </view>
         <view class="bottom">
           <view class="left-location"><text class="iconfont icon-dingwei"></text>{{detail.city}} {{detail.area}}</view>

+ 1 - 1
src/pages/index/index.vue

@@ -36,7 +36,7 @@
               <image src="@/static/common/logo.png"></image>
               <view class="user">
                 <view class="name">{{item.userName}}</view>
-                <view class="time">{{item.createTime}}</view>
+                <view class="time">{{item.createTime | timeFilter}}发布</view>
               </view>
               <view class="price">{{item.amount | priceFilter2}}</view>
             </view>

+ 41 - 13
src/pages/mine/myBuy/list.vue

@@ -12,7 +12,7 @@
         	:scrollable="false"
         	:list="tabList"
         	:current="tabCurrent"
-        	@click="changeTab"
+        	@click="clickTab"
         	lineColor="#01C30B"
         	:activeStyle="{
         		color: '#01C30B'
@@ -31,7 +31,7 @@
           <image src="@/static/common/logo.png"></image>
           <view class="user">
             <view class="name">{{item.userName}}</view>
-            <view class="time">{{item.goodsCreateTime}}</view>
+            <view class="time">{{item.goodsCreateTime | timeFilter}}发布</view>
           </view>
           <view class="status">{{item.status | statusFilter}}</view>
         </view>
@@ -45,9 +45,10 @@
         </view>
         <view class="total">订单总金额<text>{{item.price | priceFilter2}}</text></view>
         <view class="bottom">
-          <view class="left-location"><text class="iconfont icon-dingwei"></text>{{item.address}}</view>
+          <view class="left-location"><text class="iconfont icon-dingwei"></text>{{item.city}} {{item.area}}</view>
           <view class="right-btn" @tap.stop>
             <u-button text="取消订单" shape="circle"></u-button>
+            <u-button text="查看物流" shape="circle" @tap="toLogistics(item.logisticsNum)"></u-button>
           </view>
         </view>
       </view>
@@ -81,12 +82,12 @@
       return {
         imageUrl: this.$imageUrl,
         tabList: [
-          {name: '全部', value: 1},
-          {name: '待付款', value: 2},
-          {name: '待发货', value: 3},
-          {name: '待收货', value: 4},
-          {name: '已收货', value: 5},
-          {name: '售后中', value: 6},
+          {name: '全部', value: 0},
+          {name: '待付款', value: 1},
+          {name: '待发货', value: 2},
+          {name: '待收货', value: 3},
+          {name: '已收货', value: 4},
+          {name: '售后中', value: 5},
         ],
         tabCurrent: 0,
         dataList: [],
@@ -104,11 +105,23 @@
     methods: {
       //获取列表数据
       async getList() {
+        const statusMap = {
+          0: '',
+          1: 'WAIT',
+          2: 'WAIT_SEND',
+          3: 'SEND',
+          4: 'COMPLETE',
+          5: 'AFTER_WAIT',
+        }
         this.$api.post('/orderPay/list', {
           pageNum: this.pageNum,
           pageSize: 10,
           params: [{
-            param: 'a.user_id',
+            param: 'a.status',
+            compare: '=',
+            value: statusMap[this.tabCurrent]
+          }, {
+            param: 'a.buyer_user_id',
             compare: '=',
             value: this.$store.state.user.userId
           }]
@@ -137,9 +150,18 @@
       // 触发下拉刷新
       refresherrefresh(e) {
       	this.refresherTriggered = true;
-      	this.dataList = [];
-      	this.pageNum = 1;
-      	this.getList();
+      	this.refreshLish();
+      },
+
+      refreshLish() {
+        this.dataList = [];
+        this.pageNum = 1;
+        this.getList();
+      },
+
+      clickTab(item) {
+        this.tabCurrent = item.value;
+        this.refreshLish();
       },
 
       toDetail(id) {
@@ -148,6 +170,12 @@
         })
       },
 
+      toLogistics(logisticsNum) {
+        this.$navToPage({
+          url: `/pages/mine/myBuy/logistics?logisticsNum=${logisticsNum}`
+        })
+      }
+
     }
   }
   // #endif

+ 13 - 18
src/pages/mine/myBuy/logistics.vue

@@ -2,16 +2,16 @@
 	<view class="app-container">
 		<view class="all-container" v-if="!isNoData">
 			<view class="top-container">
-				<view class="left">{{logisticsData[0].comName}}<text>{{logisticsData[0].logisticsNo}}</text></view>
+				<view class="left">{{logisticsData[0].comName}}<text>{{logisticsData[0].logisticsNum}}</text></view>
 				<view class="right">
-					<text @tap="copy(logisticsData[0].logisticsNo)">复制单号</text>
+					<text @tap="copy(logisticsData[0].logisticsNum)">复制单号</text>
 				</view>
 			</view>
 			<view class="mian-container">
 				<common-logistics :logisticsData="logisticsData"></common-logistics>
 			</view>
 		</view>
-		
+
 		<no-data v-if="isNoData" :showText="noDataText"></no-data>
 	</view>
 </template>
@@ -19,39 +19,34 @@
 <script>
 	import { setAttribute, changeAttribute } from '@/components/logistics/init-logistics.js';
 	import CommonLogistics from '@/components/logistics/common-logistics.vue';
-	
+
 	export default {
 		components: {
 			CommonLogistics
 		},
-		
+
 		data() {
 			return {
 				companyCode: null,
-				logisticsNo: null,
+				logisticsNum: null,
 				logisticsData: [],
 				testStrList: [0,1,2,3,4,5,6],
 				isNoData: false,
 				noDataText: '',
 			}
 		},
-		
-		onLoad({companyCode, logisticsNo}) {
+
+		onLoad({companyCode, logisticsNum}) {
 			this.companyCode = companyCode == 'undefined' ? 'shunfeng' : companyCode;
-			this.logisticsNo = logisticsNo;
+			this.logisticsNum = logisticsNum;
 			this.getDetail();
 		},
-		
+
 		methods: {
 			// 获取物流详情
 			getDetail() {
-				this.$axios({
-					url: '/common/express',
-					method: 'get',
-					params: {
-						companyCode: this.companyCode,
-						logisticsNo: this.logisticsNo,
-					}
+				this.$api.postJson('/orderPay/logisticsList', {
+          num: this.logisticsNum,
 				}).then(res => {
 					if(res.code == 200 && res.data.length >= 1) {
 						let logisticsData = res.data;
@@ -68,7 +63,7 @@
 					this.noDataText = res.message;
 				})
 			},
-			
+
 			// 复制
 			copy(val) {
 				let that = this;

+ 2 - 0
src/styles/common.scss

@@ -211,8 +211,10 @@
         }
       }
       .right-btn {
+        display: flex;
         .u-button {
           height: 60rpx;
+          margin-left: 12rpx;
         }
       }
     }