order-list.vue 9.0 KB
<template>
	<view class="content">
		<view class="topList">
			<view :class="tabIndex==index?'tabItem active' :'tabItem'" v-for="(item,index) in tabList" :key="index"
				@click="selectTab(index)">
				{{item}}
			</view>
		</view>
		<view class="orderListBox">
			<view class="orderItem" v-for="(item,index)  in orderList" :key="index"
				@click="orderDetail(item.id,item.item[0].dispatch_type,)">
				<!-- 单个商品 -->
				<view class="itemTop" v-if="!item.flag">
					<view class="" style="display: flex;">
						<view class="imageBox">
							<image :src="item.item[0].goods_image" mode=""></image>
						</view>
						<view class="titleBox">
							{{item.item[0].goods_title}}
						</view>
					</view>
					<view class="perceBox">
						<!-- 物流快递 -->
						<view class="status" v-if="item.item[0].dispatch_type=='express'">
							<text>
								{{item.status==-2?'交易关闭':item.status==-1?'已取消':item.status==0?'未支付':item.status=='1'?'已支付':'已完成'}}
							</text>
							<text
								v-if="item.status!=-2&&item.status!=0">{{item.item[0].dispatch_status==0?'未发货':item.item[0].dispatch_status==1?'已发货':item.item[0].dispatch_status==2?'待收货':''}}</text>
						</view>
						<!-- 商家配送-->
						<view class="status" v-if="item.item[0].dispatch_type=='store'">
							<text>
								{{item.status==-2?'交易关闭':item.status==-1?'已取消':item.status==0?'未支付':item.status=='1'?'已支付':'已完成'}}
							</text>
							<text
								v-if="item.status!=-2&&item.status!=0">{{item.item[0].dispatch_status==0?'待配送':item.item[0].dispatch_status==1?'配送中':item.item[0].dispatch_status==2?'配送中':''}}</text>
						</view>
						<!-- 用户字提-->
						<view class="status" v-if="item.item[0].dispatch_type=='selfetch'">
							<text>
								{{item.status==-2?'交易关闭':item.status==-1?'已取消':item.status==0?'未支付':item.status=='1'?'已支付':'已完成'}}
								<text v-if="item.status!=-2&&item.status!=0">拣货中</text>
							</text>
						</view>
						<view class="price">
							<text style="font-size: 26rpx;">¥</text>
							{{Number(item.item[0].goods_price).toFixed(2)}}
						</view>
						<view class="num">
							X{{item.item[0].goods_num}}
						</view>
					</view>
				</view>
				<!-- 多个商品 -->
				<view class="orderItems" v-else>
					<view class="status" style="display: block;">
						<view class="status" v-if="item.item[0].dispatch_type=='express'">
							<text>
								{{item.status==-2?'交易关闭':item.status==-1?'已取消':item.status==0?'未支付':item.status=='1'?'已支付':'已完成'}}
								<text v-if="item.status!==0&&item.status!=-2">
									{{item.item[0].dispatch_status==0?'未发货':item.item[0].dispatch_status==1?'已发货':item.item[0].dispatch_status==2?'待收货':''}}
								</text>
							</text>
						</view>
						<!-- 商家配送-->
						<view class="status" v-if="item.item[0].dispatch_type=='store'">
							<text>
								{{item.status==-2?'交易关闭':item.status==-1?'已取消':item.status==0?'未支付':item.status=='1'?'已支付':'已完成'}}
								<text v-if="item.status!=0&&item.status!=-2">
									{{item.item[0].dispatch_status==0?'待配送':item.item[0].dispatch_status==1?'配送中':item.item[0].dispatch_status==2?'配送中':''}}
								</text>
							</text>
						</view>
						<!-- 用户字提-->
						<view class="status" v-if="item.item[0].dispatch_type=='selfetch'">
							<text>
								{{item.status==-2?'交易关闭':item.status==-1?'已取消':item.status==0?'未支付':item.status=='1'?'已支付':'已完成'}}
								<text v-if="item.status!=-2&&item.status!=0">拣货中</text>
							</text>
						</view>
					</view>
					<view class="itemTops">

						<view class="" v-for="(items,indexs) in item.item" :key="indexs">
							<image :src="items.goods_image" mode="" class="moreImg"></image>
						</view>
					</view>
				</view>
				<!-- 待发货 -->
				<view class="btnBox" v-if="tabIndex==2">
					<view class="" @click.stop="onceBuy">
						再来一单
					</view>
					<view class="" v-if="item.status==0" @click.stop="closeOrder(index,item.id)">
						<!-- 取消订单1 -->
						<picker @change="bindChangeSend" :value="index" :range="arraySend">
							<view class="" style="display: flex;justify-content: space-between;">
								<view class="select">
									取消订单
								</view>
							</view>
						</picker>
					</view>
				</view>
				<!-- 全部 -->
				<view class="btnBox">
					<view class="" v-if="tabIndex==1" @click.stop="payment(index,item.order_sn)">
						微信支付
					</view>
					<view class="" v-if="tabIndex==1" @click.stop="closeOrder(index,item.id)">
						<!-- 取消订单1 -->
						<picker @change="bindChangeSend" :value="index" :range="arraySend">
							<view class="" style="display: flex;justify-content: space-between;">
								<view class="select">
									取消订单
								</view>
							</view>
						</picker>
					</view>
					<view class="" v-if="tabIndex==1" @click.stop="onceBuy">
						再来一单
					</view>
					<view class="" v-if="item.status==-2&&tabIndex==0" @click.stop="delOrder(index,item.id)">
						删除订单
					</view>
				</view>
			</view>

		</view>
		<view class="" v-if="orderlist.length==0" class="noDataBox">
			<image src="../../static/Material@2x.png" mode="" class="noDataImg"></image>
			<view class="" class="noData">
				您还没有相关订单
			</view>
		</view>
	</view>
</template>

<script>
	import request from '../../utils/request.js'
	export default {
		data() {
			return {
				pageNum: 1,
				tabIndex: 0,
				tabList: ['全部', '待付款', '待发货','待收货', '待评价', '已完成'],
				orderList: [],
				index: 0, //取消订单原因
				arraySend: ['我不想买了', '信息写错了,重新填写', '其他原因'],
				concelReson: '', //取消原因
				orderId:'',     //取消订单id
				indexs:'',      //取消订单index
			}
		},
		onLoad(options) {
			this.tabIndex=options.index
			this.getList()
		},
		onReachBottom() {
			this.pageNum += 1
			this.getList()
		},
		methods: {
			selectTab(index) {
				this.tabIndex = index
				this.pageNum = 1
				this.getList()
			},
			//订单详情
			orderDetail(ids, status) {
				if (status == 'selfetch') {
					uni.navigateTo({
						url: '/pages/order/self-order-detail?id=' + ids+'&tabIndex='+this.tabIndex
					})
				} else {
					uni.navigateTo({
						url: '/pages/order/sen-order-detail?id=' + ids
					})
				}
			},
			//再来一单
			onceBuy() {
				uni.showToast({
					title: '再来一单',
					icon: 'none'
				})
			},
			//微信支付
			payment(index,ids){
				let Data = {
					order_sn: ids,
					payment: 'wechat',
					platform: 'wxMiniProgram'
				}
				request.post('/api/pay/prepay', Data).then(res => {
					if (res.code == 1) {
						uni.requestPayment({
							provider: 'wxpay',
							timeStamp: res.data.pay_data.timeStamp,
							nonceStr: res.data.pay_data.nonceStr,
							package: res.data.pay_data.package,
							signType: res.data.pay_data.signType,
							paySign: res.data.pay_data.paySign,
							appId: res.data.pay_data.appId,
							success: function(res) {
								console.log('success成功:' + JSON.stringify(res));
								// uni.redirectTo({
								// 	url: '/pages/order/order-list'
								// })
							},
							fail: function(err) {
								console.log('fail失败:' + JSON.stringify(err));
								// uni.redirectTo({
								// 	url: '/pages/order/order-list'
								// })
							}
						});
					}
				}).catch(err => {})
			},
			//取消订单
			closeOrder(index, ids) {
				let that = this
				that.orderId=ids,
				that.indexs=index

			},
			//取消订单选择原因
			bindChangeSend: function(e) {
				this.index = e.target.value
				request.post('/api/order/cancel', {
					id: ids
				}).then(res => {
					if (res.code == 1) {
						uni.showToast({
							title: '取消成功'
						})
					}
				})
				
			},
			//删除订单
			delOrder(index, ids) {
				uni.showModal({
					title: '提示',
					content: '确定删除订单吗?',
					success: function(res) {
						if (res.confirm) {
							request.post('/api/order/delete', {
								id: ids
							}).then(res => {
								if (res.code == 1) {
									uni.showToast({
										title: '删除成功'
									})
									that.orderList.splice(index,1)
								}
							})
						} else if (res.cancel) {
						}
					}
				});

			},
			//获取订单列表
			getList() {
				request.get('/api/order/index', {
					type: this.tabIndex == 0 ? 'all' : this.tabIndex == 1 ? 'nopay' : this.tabIndex == 2 ?
						'nosend' : this.tabIndex == 3 ? 'nocomment' : 'aftersale',
					page: this.pageNum
				}).then(res => {
					if (res.code == 1) {
						let list = this.pageNum == 1 ? res.data.data : this.orderList.concat(res.data.data)
						this.orderList = list
						this.orderList.forEach((item, index) => {
							if (item.item.length > 1) {
								item.flag = true
							} else {
								item.flag = false
							}
						})
					}
				}).catch(err => {

				})
			}
		}
	}
</script>

<style>
	@import url("/common/order-list.css");

	.itemTops {
		display: flex;
	}
</style>