<template>
	<view class="page">
		<pyh-nv ref="nv" :config="nvConfig"></pyh-nv>
		<view class="listBox" :style="{'padding-top':(pageTop+'px')}">
		<view class="content">
		<!-- 订单tab -->
		<view class="order-tab">
			<view class="tab" :class="{'action':OrderType==0}" @click="onOrderTab(0)">
				<text>全部</text>
				<text class="line"></text>
			</view>
			<view class="tab" :class="{'action':OrderType==1}" @click="onOrderTab(1)">
				<text>待付款</text>
				<text class="line"></text>
			</view>
			<view class="tab" :class="{'action':OrderType==2}" @click="onOrderTab(2)">
				<text>已完成</text>
				<text class="line"></text>
			</view>
			<view class="tab" :class="{'action':OrderType==3}" @click="onOrderTab(3)">
				<text>待评价</text>
				<text class="line"></text>
			</view>
		</view>
		<!-- 订单列表 -->
		<view class="order-list">
			<view class="list" v-for="(item,index) in list" @click="onOrderList" :key="index">
				<view class="title-status">
					<view class="title">
						<text>订单号：{{item.funeralUserOrderInfoPo.orderId}}</text>
						<!-- <image :src="Baseapi + item.image"></image> -->
					</view>
					<view class="status">
						<text>待付款</text>
					</view>
				</view>
				<view class="goods-list">
					<view class="goods">
						<view class="thumb">
							<image :src="Baseapi + item.orderProductInfoVoList[0].productImage" mode=""></image>
						</view>
						<view class="item">
							<view class="goods-name">
								<view class="goods-name-title">{{item.orderProductInfoVoList[0].productName}}</view>
								<view>下单时间：{{item.funeralUserOrderInfoPo.orderPlacedTime}}</view>
							</view>
							<view class="goods-price">
								<view class="min">¥{{item.orderProductInfoVoList[0].totalPrice / item.orderProductInfoVoList[0].quantityNumber}}</view>
								<view>x{{item.orderProductInfoVoList[0].quantityNumber}}</view>
							</view>
						</view>
					</view>
				</view>
				<view class="status-btn">
					<view>共{{item.orderProductInfoVoList[0].quantityNumber}}件商品，合计<text class="red">¥</text><text class="red big">{{item.orderProductInfoVoList[0].totalPrice}}</text></view>
					<view class="btn" @click="myorderdetail(item)">
						<image src="../../static/btn.png" mode="widthFix"></image>
						<text>查看详情</text>
					</view>
				</view>
			</view>
		</view>
		</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				Baseapi:"http://8.130.38.56:2015",
				OrderType: 0,
				nvConfig:{
					title:"商城订单",
					bgColor:"#ffffff",
					color:"#000000",
					fixedAssist:{
						hide:true,
					},
				},
				list:[],
				cxinfo:{
					pageNum:1,
					pageSize:10,
					status:null,
					customerName:""
				}
			};
		},
		onPageScroll(e) {this.$refs.nv.pageScroll(e)},
		computed:{
			pageTop(){return parseInt(88*uni.getSystemInfoSync().windowWidth/750) + uni.getSystemInfoSync().statusBarHeight}
		},
		onLoad(params) {
			console.log("111",params);
			this.OrderType = params.type;
			this.onOrderTab(params.type);
			// this.getuserdd();
		},
		methods:{
			myorderdetail(info){
				info = JSON.stringify(info)
				uni.navigateTo({
					url: '/pages/myorderdetail/myorderdetail?info=' + info,
				})
			},
			onOrderTab(e){
				this.OrderType = e;
				this.list = []
				if(e == 0){
					this.cxinfo.status = ''
				}
				if(e == 1){
					this.cxinfo.status = "待付款"
				}
				if(e == 2){
					this.cxinfo.status = "已完成"
				}
				if(e == 3){
					this.cxinfo.status = "待评价"
				}
				var user = uni.getStorageSync('USERS_KEY')
				this.cxinfo.customerName = user.userName
				this.cxinfo.userId = user.userId
				console.log("user",user);
				this.API.getDdxq(this.cxinfo).then(res=>{
					console.log(res);
					this.list = res.data
				})
				// this.API.getuserdd(this.cxinfo).then(res=>{
				// 	console.log("用户订单",res);
				// 	for(let i = 0;i < res.rows.length;i++){
				// 		var info = {
				// 			ddid:"",
				// 			name:"",
				// 			time:"",
				// 			number:"",
				// 			price:"",
				// 			image:""
				// 		}
				// 		info.ddid = res.rows[i].orderId;
				// 		info.time = res.rows[i].orderPlacedTime
				// 		this.API.getuserddxq(res.rows[i].orderId).then(res1=>{
				// 			console.log("订单详情",res1);
				// 			info.number = res1.rows[0].quantityNumber
				// 			info.price = info.number * res1.rows[0].unitPrice
				// 			this.API.getspjcxx(res1.rows[0].productId).then(res2=>{
				// 				console.log("产品信息",res2);
				// 				info.name = res2.rows[0].productName;
				// 				info.image = res2.rows[0].productImage;
				// 				this.list.push(info)
				// 			})
				// 		})
				// 		console.log("list",this.list);
				// 	}
				// })
			},
			// 获取用户订单
			getuserdd(){
				this.list = []
				var is = {
					userId:uni.getStorageSync("USERS_KEY").userId
				}
				this.API.getuserdd(is).then(res=>{
					console.log("用户订单",res);
					for(let i = 0;i < res.rows.length;i++){
						console.log(11111);
						var info = {
							ddid:"",
							name:"",
							time:"",
							number:"",
							price:"",
							image:""
						}
						info.ddid = res.rows[i].orderId;
						info.time = res.rows[i].orderPlacedTime
						this.API.getuserddxq(res.rows[i].orderId).then(res1=>{
							console.log("订单详情",res1);
							info.number = res1.rows[0].quantityNumber
							info.price = info.number * res1.rows[0].unitPrice
							this.API.getspjcxx(res1.rows[0].productId).then(res2=>{
								console.log("产品信息",res2);
								info.name = res2.rows[0].productName;
								info.image = res2.rows[0].productImage;
							})
						})
						this.list.push(info)
						console.log("订单列表",this.list);
					}
				})
			},
		}
	}
</script>

<style scoped lang="scss">
	@import 'myorder.scss';
</style>
