<template>
	<view class="all">
		<view class="fixedBox">
			<view class="navList flex">
				<view v-for="(item, index) in navItem" :key="index" class="navItem"
					:class="{ activeItem: tabIndex === index,tip:index == 0 }" @click="tabClick(index,1)">{{ item }}
				</view>
			</view>
			<view class="navList flex navList2">
				<view v-for="(item, index) in navList[tabIndex]" :key="index" class="navItem"
					:class="{ activeItem: tabCurr === index}" @click="tabClick(index,2)">{{ item.name }}
				</view>
			</view>
		</view>
		<view class="listItemBox">
			<view class="listItem" v-for="item,index in list" :key="index" @click="navItemTo(item)">
				<view class="itemInfo flex">
					<view class="flex_item">
						<image src="/static/image/img20.png" style="width: 55rpx;height: 55rpx;" mode="widthFix"></image>
						<view class="name">{{item.real_name}}</view>
					</view>
					<view class="" style="font-size: 24rpx;font-weight: bold;color: #0C5AFA;">
						<text v-if="item.status==0">结束</text>
						<text v-else-if="item.status==1">挂出</text>
						<text v-else-if="item.status==2">完成</text>
						<text v-else-if="item.status==3">待上传</text>
						<text v-else-if="item.status==5">已上传</text>
						
					</view>
				</view>
				<view class="itemTip flex">
					<view class="tipBox">
						<view class="tipText">数量：{{item.num}}{{item.money_type}}</view>
						<view class="tipText">总价：￥{{item.money}}</view>
						<view class="tipText">{{item.add_time|dateFormat}}</view>
					</view>
					<view class="" style="text-align: right;">
						<image src="/static/image/img21.png" style="width: 40rpx;height: 31rpx;margin-bottom: 25rpx;" mode="widthFix">
						</image>
						<view class="tipBtn" v-if="item.voucher">查看凭证</view>
						<view class="tipBtn" v-if="status==3">上传凭证</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		sellMy,
		sellBuyMy
	} from '@/api/game.js';
	import {
		mapState
	} from 'vuex';
	import dayjs from '@/libs/dayjs/dayjs.min.js';
	export default {
		computed: {
			...mapState('user', ['hasLogin'])
		},
		filters: {
			dateFormat: function(value) {
				return dayjs(value * 1000).format('YYYY/MM/DD HH:mm');
			}
		},
		data() {
			return {
				tabIndex: 0, //当前选中的一级分类
				navItem: ['卖币订单', '买币订单'],
				tabCurr: 0, //当前选中的二级分类
				status: 0, //当前选中状态
				navList: [
					[ {
						name: '挂出',
						status: 1
					}, {
						name: '待上传',
						status: 3
					}, {
						name: '完成',
						status: 2
					},{
						name: '结束',
						status: 0
					},],
					[ {
						name: '待上传',
						status: 3
					}, {
						name: '已上传',
						status: 5
					}, {
						name: '完成',
						status: 2
					}]
				],
				page: 1,
				limit: 10,
				loadingType: "more",
				list: []
			}
		},
		onLoad() {
			this.loadData()
		},
		onReachBottom() {
			this.loadData()
		},
		methods: {
			navItemTo(item){
				uni.navigateTo({
					url:`/pages/index/orderDetail?id=${item.id}`
				})
			},
			loadData() {
				let obj = this;
				if (obj.loadingType == "nomore" ||
					obj.loadingType == "loading") {
					return;
				}
				obj.loadingType = "loading";
				console.log(obj.status);
				if (this.tabIndex == 0) {
					sellMy({
						page: obj.page,
						limit: 10,
						status:obj.status
					}, obj.status).then(res => {
						obj.dataList(res.data.list)
					});
				} else if (this.tabIndex == 1) {
					sellBuyMy({
						page: obj.page,
						limit: 10,
						status:obj.status
					}, obj.status).then(res => {
						let ar = res.data.list.map((re)=>{
							console.log(re,'re');
							re.num = +re.num;
							re.price = +re.price;
							re.money = +(re.num*re.price).toFixed(8);
							
							return re
						})
						obj.dataList(ar)
					});
				}
			},
			dataList(ar) {
				const obj = this;
				if (ar.length > 0) {
					obj.list = obj.list.concat(ar);
					obj.page++;
					if (obj.limit == ar.length) {
						obj.loadingType = "more";
					} else {
						obj.loadingType = "nomore";
					}
				}
				console.log(obj.list,"list");
			},
			tabClick(index,type) {
				if (type == 1) {
					if (index == this.tabIndex) {
						return
					}
					this.tabIndex = index;
					this.tabCurr = 0
				} else if (type == 2) {
					if (index == this.tabCurr) {
						return
					}
					this.tabCurr = index
				}
				this.status = this.navList[this.tabIndex][this.tabCurr].status;
				this.page = 1;
				this.loadingType = "more";
				this.list = []
				this.loadData()
			},
		}
	};
</script>

<style lang="scss">
	.all {
		width: 750rpx;
		height: 100%;
		background-color: #051137;
		padding-top: var(--status-bar-height);
	}

	.fixedBox {
		position: fixed;
		top: 44px;
		left: 0;
		width: 100%;
		z-index: 9;
	}

	.navList {
		padding: 20rpx 50rpx 20rpx 50rpx;
		background: #1F2A4A;

		.navItem {
			color: #fff;
			font-size: 30rpx;
			text-align: center;
			width: 50%;

			&.activeItem {
				color: #0C5AFA;
				position: relative;

				&:after {
					content: '';
					position: absolute;
					left: 36%;
					bottom: -20rpx;
					width: 30%;
					height: 8rpx;
					// transform: translateX(-50%);
					border-bottom: 4rpx solid #0C5AFA;
					border-radius: 0rpx 20rpx 0rpx 0rpx;
				}
			}

			&.tip {
				border-right: 1rpx solid #333D5B;
			}
		}
	}

	.navList2 {
		background: #051137;
		padding: 20rpx 25rpx 20rpx 25rpx;
	}

	.listItemBox {
		padding-top: 88px;

		.listItem {
			padding: 34rpx 34rpx;
			background: #1F2A4A;
			margin-bottom: 25rpx;

			.name {
				font-family: PingFang SC;
				font-weight: bold;
				font-size: 30rpx;
				color: #FFFFFF;
				padding-left: 25rpx;
			}

			.itemTpl {
				font-family: PingFang SC;
				font-weight: bold;
				font-size: 36rpx;
				color: #0C5AFA;
				padding-top: 25rpx;
			}

			.itemTip {
				.tipText {
					font-family: PingFang SC;
					font-weight: 500;
					font-size: 26rpx;
					color: #999999;
					padding-top: 15rpx;
				}

				.tipBtn {
					font-family: PingFang SC;
					font-weight: bold;
					font-size: 24rpx;
					color: #FFFFFF;
					background: linear-gradient(90deg, #0C5AFA, #1356FF);
					border-radius: 7rpx;
					padding: 15rpx 35rpx;
				}
			}
		}
	}
</style>