Browse Source

完善我的订单

hwb0 3 years ago
parent
commit
9103446e44
2 changed files with 132 additions and 126 deletions
  1. 58 49
      pages/order/detail.vue
  2. 74 77
      pages/order/index.vue

+ 58 - 49
pages/order/detail.vue

@@ -1,7 +1,6 @@
 <template>
 	<view>
-		<u-navbar title="订单详情" :border="true" :placeholder="true" :autoBack="true" leftIconColor="#fff"
-			bgColor="#E96737" />
+		<u-navbar title="订单详情" :border="true" :placeholder="true" :autoBack="true" bgColor="#fff" />
 		<view class="detail">
 			<view class="detail-state">
 				<view class="detail-state-title">
@@ -19,24 +18,15 @@
 									<image class="img" :src="item.picUrl" mode="aspectFill">
 									</image>
 								</view>
-								<view class="info">
-									<text>{{ item.title }}</text>
-									<text>面值:{{ $numberFormat(item.facePrice) }}元</text>
-									<text>规格:{{ item.pkgUnit }}张/包 </text>
-								</view>
 							</view>
 							<view class="detail-info-content-goods__detail__right">
-								<text>¥{{ $numberFormat(item.pkgSalePrice) }}</text>
-								<text>x {{ item.orderNum }}</text>
+								<view class="title">{{ item.title }}</view>
+								<view class="num">x {{ item.goodsNum }}</view>
 							</view>
 						</view>
 					</view>
 
 					<view class="detail-info-content-money">
-						<view class="detail-info-content-money__item">
-							<text>商品金额</text>
-							<text>¥{{ $numberFormat(info.orderAmt) }}</text>
-						</view>
 						<view class="detail-info-content-money__item">
 							<text>运费</text>
 							<text>¥{{ $numberFormat(info.freightAmt) }}</text>
@@ -44,7 +34,7 @@
 					</view>
 
 					<view class="detail-info-content-toatl">
-						<text v-if="status.value == 0">需付款:</text>
+						<text v-if="status.value == 0 || status.value == -1">应付:</text>
 						<text v-else>实付:</text>
 						<text>¥{{ $numberFormat(info.payAmt) }}</text>
 					</view>
@@ -76,15 +66,15 @@
 				<view class="detail-info-content">
 					<view class="detail-info-content-desc">
 						<view>快递公司:</view>
-						<view>快递123</view>
+						<view>-</view>
 					</view>
 					<view class="detail-info-content-desc">
 						<view>物流单号:</view>
-						<view>123456789</view>
+						<view>-</view>
 					</view>
 					<view class="detail-info-content-desc">
 						<view>发货时间:</view>
-						<view>2345-234-234</view>
+						<view>-</view>
 					</view>
 				</view>
 			</view>
@@ -116,21 +106,27 @@
 		},
 		methods: {
 			getDetail() {
-				$http.post('/api/v1/mp/channel/mall/order/detail', {
+				uni.showLoading({
+					title: '加载中'
+				});
+				$http.post('/api/v1/mp/user/deliver/order/detail', {
 					orderId: this.orderId
 				}).then(res => {
+					uni.hideLoading();
 					this.info = res.data
 					this.status = JSON.parse(res.data.status)
 					res.data.items.forEach(item => {
-						let picUrlArr = item.picUrl.split(',')
-						item.picUrl = env.filePublic + picUrlArr[0]
+						item.picUrl = env.filePublic + item.picUrl
 					})
 					this.list = res.data.items
+				}).catch(() => {
+					uni.hideLoading();
 				})
 			},
 
 			cancelOrder() {
-				$http.post('/api/v1/mp/channel/mall/order/cancel', {
+				return
+				$http.post('/api/v1/mp/user/deliver/order/cancel', {
 					orderId: this.orderId
 				}).then(res => {
 					if (res.code == 0) {
@@ -139,23 +135,56 @@
 							uni.navigateBack({
 								delta: 1
 							})
-						}, 1000)
+						}, 500)
 					}
 				})
 			},
 
 			payOrder() {
-
+				let _this = this
+				let payIng = false
+				if (payIng) return
+				$http.post('/api/v1/mp/user/deliver/order/pay', {
+					orderId: _this.info.orderId,
+					payType: 2
+				}).then(ele => {
+					payIng = true
+					if (ele.code == 0) {
+						uni.requestPayment({
+							timeStamp: ele.data.timeStamp,
+							nonceStr: ele.data.nonceStr,
+							package: ele.data.package,
+							signType: ele.data.signType,
+							paySign: ele.data.paySign,
+							success() {
+								uni.showToast({
+									title: '支付成功',
+									icon: 'success',
+									duration: 2000
+								})
+								setTimeout(() => {
+									uni.navigateBack({
+										delta: 1
+									})
+								}, 500)
+							},
+							fail() {
+								payIng = false
+							}
+						})
+					} else {
+						payIng = false
+						uni.$u.toast('支付失败!');
+					}
+				}).catch(() => {
+					payIng = false
+					uni.$u.toast('支付失败!');
+				})
 			},
 		}
 	}
 </script>
 
-<style lang="scss" scoped>
-	/deep/ .u-navbar__content__title.u-navbar__content__title {
-		color: #FFFFFF;
-	}
-</style>
 <style lang="scss" scoped>
 	.detail {
 		margin: 10rpx;
@@ -203,35 +232,15 @@
 									margin-right: 20rpx;
 								}
 							}
-
-							.info {
-								display: flex;
-								flex-direction: column;
-								justify-content: space-between;
-
-								text {
-									font-size: 24rpx;
-									color: #9D9D9D;
-								}
-
-								text:first-child {
-									color: rgba(16, 16, 16, 100);
-									font-size: 28rpx;
-								}
-							}
 						}
 
 						&__right {
+							flex: 1;
 							display: flex;
 							height: 170rpx;
 							flex-direction: column;
 							justify-content: space-between;
 							align-items: flex-end;
-
-							text:first-child {
-								font-size: 32rpx;
-								color: $uni-text-color;
-							}
 						}
 
 					}

+ 74 - 77
pages/order/index.vue

@@ -1,7 +1,6 @@
 <template>
 	<view>
-		<u-navbar title="我的订单" @leftClick="back" :border="true" :placeholder="true" :autoBack="false"
-			leftIconColor="#fff" bgColor="#E96737" />
+		<u-navbar title="我的订单" :border="true" :placeholder="true" :autoBack="true" bgColor="#fff" />
 		<view class="order">
 			<view class="flex order-state-search">
 				<u-tabs @change="changeTab" :scrollable="false" :list="statusArr" lineWidth="30" lineHeight="1"
@@ -11,7 +10,7 @@
 									}" :inactiveStyle="{
 										color: '#333',
 										transform: 'scale(1)'
-									}" itemStyle="padding-left: 25px; padding-right: 25px; height: 44px;">
+									}" itemStyle="padding-left: 15px; padding-right: 15px; height: 44px;">
 				</u-tabs>
 				<view class="test"></view>
 			</view>
@@ -35,21 +34,16 @@
 											<image class="img" :src="items.picUrl" mode="aspectFill">
 											</image>
 										</view>
-										<view class="info">
-											<text>{{ items.title }}</text>
-											<text>面值:{{ $numberFormat(items.facePrice) }}元</text>
-											<text>规格:{{ items.pkgUnit }}张/包 </text>
-										</view>
 									</view>
 									<view class="order-list-data-item__info__detail__right">
-										<text>¥{{ $numberFormat(items.pkgSalePrice) }}</text>
-										<text>x {{ items.orderNum }}</text>
+										<view class="title">{{ items.title }}</view>
+										<view class="num">x {{ items.goodsNum }}</view>
 									</view>
 								</view>
 							</navigator>
 
 							<view class="order-list-data-item__info__total">
-								<view>共{{ item.pkgNum }}个票包</view>
+								<view>共{{ item.orderNum }}个商品</view>
 								<view class="money">
 									<text>实付:</text>
 									<text>¥{{ $numberFormat(item.payAmt) }}</text>
@@ -58,12 +52,12 @@
 
 							<view class="order-list-data-item__info__btn" v-if="item.status.value == 0">
 								<text @click="cancelOrder(item.orderId)">取消订单</text>
-								<text @click="payOrder">去支付</text>
+								<text @click="payOrder(item)">去支付</text>
 							</view>
 						</view>
 					</view>
 				</view>
-				<view class="flex empty" v-if="!list.length">
+				<view class="flex empty" v-if="!list.length && !loading">
 					<u-empty text="订单为空" mode="order" />
 				</view>
 			</view>
@@ -78,13 +72,10 @@
 		data() {
 			return {
 				loading: false,
-				days: '1',
 				pageNum: 1,
 				total: 100,
 				list: [],
 				status: null,
-				top: '',
-
 				statusArr: [{
 					name: '全部'
 				}, {
@@ -93,64 +84,96 @@
 					name: '待发货'
 				}, {
 					name: '已发货'
+				}, {
+					name: '已取消'
 				}, ],
-				backNum: ''
 			};
 		},
-		onLoad(opthios) {
-			this.backNum = opthios.back
-		},
+		onLoad(opthios) {},
 		onShow() {
-			this.getList()
+			this.pageList()
 		},
 		methods: {
-			back() {
-				if (this.backNum) {
-					uni.navigateBack({
-						delta: 2
-					})
-				} else {
-					uni.navigateBack({
-						delta: 1
-					})
-				}
-			},
-			getList(flag) {
-				let data = {
+			getList() {
+				uni.showLoading({
+					title: '加载中'
+				});
+				this.loading = true
+				$http.post(`/api/v1/mp/user/deliver/order/list?pageNum=${ this.pageNum }&pageSize=20`, {
 					status: this.status
-				}
-				$http.post(`/api/v1/mp/channel/mall/order/list?pageNum=${ this.pageNum }&pageSize=15`,
-					data).then(res => {
+				}).then(res => {
+					uni.hideLoading();
+					this.loading = false
 					if (res.code == 0) {
 						res.rows.forEach(item => {
 							let items = item.items
 							items.forEach(item => {
-								let picUrlArr = item.picUrl.split(',')
-								item.picUrl = env.filePublic + picUrlArr[0]
+								item.picUrl = env.filePublic + item.picUrl
 							})
 							item.status = JSON.parse(item.status)
 						})
 						this.total = res.total
 						this.list = this.list.concat(res.rows)
 					}
+				}).catch(() => {
+					uni.hideLoading();
+					this.loading = false
 				})
 			},
 
+			pageList() {
+				this.pageNum = 1
+				this.list = []
+				this.getList()
+			},
+
 			cancelOrder(id) {
-				$http.post('/api/v1/mp/channel/mall/order/cancel', {
+				$http.post('/api/v1/mp/user/deliver/order/cancel', {
 					orderId: id
 				}).then(res => {
 					if (res.code == 0) {
 						uni.$u.toast('订单取消成功');
-						this.pageNum = 1
-						this.list = []
-						this.getList()
+						this.pageList()
 					}
 				})
 			},
 
-			payOrder() {
-
+			payOrder(item) {
+				let _this = this
+				let payIng = false
+				if (payIng) return
+				$http.post('/api/v1/mp/user/deliver/order/pay', {
+					orderId: item.orderId,
+					payType: 2
+				}).then(ele => {
+					payIng = true
+					if (ele.code == 0) {
+						uni.requestPayment({
+							timeStamp: ele.data.timeStamp,
+							nonceStr: ele.data.nonceStr,
+							package: ele.data.package,
+							signType: ele.data.signType,
+							paySign: ele.data.paySign,
+							success() {
+								uni.showToast({
+									title: '支付成功',
+									icon: 'success',
+									duration: 2000
+								})
+								_this.pageList()
+							},
+							fail() {
+								payIng = false
+							}
+						})
+					} else {
+						payIng = false
+						uni.$u.toast('支付失败!');
+					}
+				}).catch(() => {
+					payIng = false
+					uni.$u.toast('支付失败!');
+				})
 			},
 
 			changeTab(e) {
@@ -160,18 +183,18 @@
 					this.status = 0
 				} else if (e.index == 2) {
 					this.status = 1
-				} else {
+				} else if (e.index == 3) {
 					this.status = 2
+				} else if (e.index == 4) {
+					this.status = -1
 				}
-				this.pageNum = 1
-				this.list = []
-				this.getList()
+				this.pageList()
 			},
 		},
 
 		onReachBottom() {
 			// 判断是否有数据
-			if (this.total >= this.pageNum * 15) {
+			if (this.total > this.pageNum * 20) {
 				setTimeout(() => {
 					++this.pageNum
 					this.getList()
@@ -183,11 +206,6 @@
 	}
 </script>
 
-<style lang="scss" scoped>
-	/deep/ .u-navbar__content__title.u-navbar__content__title {
-		color: #FFFFFF;
-	}
-</style>
 <style lang="scss" scoped>
 	.order {
 		padding-bottom: 40rpx;
@@ -249,42 +267,21 @@
 								height: 170rpx;
 
 								.img {
-
 									image {
 										width: 134rpx;
 										height: 170rpx;
 										margin-right: 20rpx;
 									}
 								}
-
-								.info {
-									display: flex;
-									flex-direction: column;
-									justify-content: space-between;
-
-									text {
-										font-size: 24rpx;
-										color: #9D9D9D;
-									}
-
-									text:first-child {
-										color: rgba(16, 16, 16, 100);
-										font-size: 28rpx;
-									}
-								}
 							}
 
 							&__right {
+								flex: 1;
 								display: flex;
 								height: 170rpx;
 								flex-direction: column;
 								justify-content: space-between;
 								align-items: flex-end;
-
-								text:first-child {
-									font-size: 32rpx;
-									color: $uni-text-color;
-								}
 							}
 
 						}