<template>
	<view class="con">
		<view class="content">
			<view class="tab-list">
				<view @click="findOrderListByState(index)" class="tab-box" :class="{ 'lv-size' : tabindex == index  }"
					v-for="(item,index) in tablist" :key="index">
					<view class="">{{item.name}}</view>
					<view class="gang" :class="{ 'lv-gang' : tabindex == index  }"></view>
				</view>
			</view>
			<u-empty mode="list" v-if="orderList.length == 0">
			</u-empty>
			<view class="box_" v-for="(item,index) in orderList" :key="index">
				<view class="box-top" @click="goDetails(item.id)">
					<view class="">
						<view class="h-title">订单编号：{{item.orderNumber}}</view>
						<view class="hui-x">{{item.createTime}}</view>
					</view>
					<view class="icon-huang" v-if="item.state === 0">
						<view>已报名</view>

					</view>
					<view class="icon-huang" v-if="item.state === 1">
						<view>已付款</view>

					</view>
					<view class="icon-huang" v-if="item.state === 2">
						<view>已面签</view>

					</view>

				</view>
				<view class="box-ds">
					<view class="left-box" @click="goDetails(item.id)">
						<image :src="imagesUrl + item.photo" mode=""></image>
					</view>
					<view style="width: 60%;">

						<!-- <view class="box-title">AI智能</view> -->
						<view class="b-d-s">
							<view class="box-title" v-if="item.driveSchoolCourse" @click="goDetails(item.id)">
								{{item.driveSchoolCourse.automatic || '' }}
							</view>
							<view class="qhaaniu" @click="changeStateClick(item.id, item.state)">切换状态</view>


						</view>

						<view class="wrap-box" @click="goDetails(item.id)" style="	margin-bottom: 5px;">
							<view class="icon-lv">{{item.driveSchoolCourse.license}}</view>
							<view class="icon-h">{{item.driveSchoolCourse.name}}</view>
						</view>
						<view class="wrap-box">
							<view class="price_">￥{{item.driveSchoolCourse.price}}</view>
							<view class="sc">{{item.driveSchoolCourse.price}}</view>

						</view>
					</view>

				</view>

				<view class="liang-box">
					<view class="lb-box" style="margin-bottom: 5px;">
						<view class="">联系人：</view>
						<view style="color: #333333;">{{item.name}}</view>
					</view>
					<view class="lb-box">
						<view class="">联系电话：</view>
						<view style="color: #333333;">{{item.phone}}</view>
					</view>

				</view>

				<view class="right-icon">
					<view class="">实付:</view>
					<!--					<view style="font-size: 20px;color: #FB423B;">￥{{item.driveSchoolCourse.reserveMoney}}</view>-->
				</view>
			</view>

		</view>

		<u-popup :show="isState" @close="stateExitClick" @open="open">
			<view class="statePage">
				<view @click="chnageListDataIndex(index)" :class="{reactw: listDataIndex === index}"
					style="margin: 0 20rpx;" v-for="(item, index) in listData" class="state-item">{{item}}</view>
			</view>
		</u-popup>

	</view>
</template>

<script>
	import request from "@/utils/request.js"

	export default {
		data() {
			return {
				tabindex: 0,
				tablist: [{
						name: '全部订单'
					},
					{
						name: '已报名'
					},
					{
						name: '已付款'
					},
					{
						name: '已面签'
					}
				],
				userId: null,
				imagesUrl: this.$baseUrl,
				listData: ["全部订单", "已报名", "已付款", "已面签"],
				listDataIndex: 0,
				orderList: [],
				isState: false
			}
		},
		// open(){
		// 	this.$refs.popup.open('top')
		//   },
		onShow() {
			this.findOrderListByState(0)

		},
		onPullDownRefresh() {
			console.log("刷新");
			uni.stopPullDownRefresh()
		},
		onReachBottom() {
			// this.show = true
			setTimeout(() => {
				console.log("加载执行");
			}, 2000)
		},

		methods: {

			async findOrderListByState(index) {
				this.tabindex = index
				let state = null
				let isSign = null
				if (index == 1) {
					state = 3
				} else if (index == 2) {
					state = 3
				} else if (index == 3) {
					state = 3
					isSign = 1
				}

				let res = await request({
					url: `/system/pay/list`,
					method: 'get',
					params: {
						isSign: isSign,
						state: state,
						pageNum:1,
						pageSize:10
					}
				})

				this.orderList = res.data.records
			},

			// getindex(index) {
			// 	this.tabindex = index
			// },
			goDetails(id) {
				uni.navigateTo({
					url: `/pages/index/orderDetails?id=${id}`
				})
			},
			changeStateClick(userId, state) {
				this.isState = true
				this.userId = userId
				this.listDataIndex = state
				console.log(userId, state, "ddsda")

			},
			stateExitClick() {
				this.isState = false
			},
			async chnageListDataIndex(index) {
				console.log("添加添加", index)
				this.listDataIndex = index
				this.isState = false

				this.tabindex = index
				let state = null
				if (index == 1) {
					state = 0
				} else if (index == 2) {
					state = 1
				} else if (index == 3) {
					state = 2
				}

				let res = await request({
					url: `/system/pay`,
					method: 'put',
					data: {
						id: this.userId,
						state: state
					}
				})
				this.findOrderList()
			}

		}
	}
</script>

<style scoped lang="scss">
	.reactw {
		color: #4AA76F;
		font-weight: bold;
	}

	.statePage {
		height: 400rpx;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.box-right {
		padding: 10rpx;
		border: 1rpx solid #ccc;
		border-radius: 12rpx;
		margin-left: 130rpx;
	}

	.con {
		width: 100%;
		height: 100vh;
		background: #f4f5f6;
	}

	.content {
		width: 100%;
		background: #f4f5f6;

		box-sizing: border-box;

	}

	.tab-list {
		width: 100%;
		height: 50px;
		background: #fff;
		display: flex;
		align-items: center;
		justify-content: space-between;
	}

	.tab-box {
		width: 25%;
		text-align: center;
		font-weight: 400;
		font-size: 14px;
	}

	.lv-size {
		font-weight: bold;
		font-size: 14px;
		color: #4AA76F !important;
	}

	.gang {
		width: 16px;
		height: 3px;
		// background: #4AA76F;
		margin: 0px auto;
		margin-top: 10px;
	}

	.lv-gang {
		background: #4AA76F !important;

	}

	.box_ {
		width: 95%;
		margin: 15px auto;
		background: #FFFFFF;
		border-radius: 8px;
		box-sizing: border-box;
		padding: 15px;
	}

	.box-top {
		width: 100%;
		border-bottom: 1px solid #DDDDDD;
		box-sizing: border-box;
		padding-bottom: 10px;
		margin-bottom: 10px;
		display: flex;
		align-items: center;
		justify-content: space-between;
	}

	.icon-huang {
		width: 48px;
		height: 20px;
		background: #FFFFFF;
		border-radius: 3px 3px 3px 3px;
		border: 1px solid #EDA23A;
		color: #EDA23A;
		display: flex;
		align-items: center;
		justify-content: center;
		font-size: 12px;
	}

	.h-title {
		font-size: 12px;
		color: #333333;
		margin-bottom: 10px;
	}

	.hui-x {
		font-size: 12px;
		color: #999999;
	}

	.box-ds {
		display: flex;
		align-items: center;

	}

	.left-box {
		width: 106px;
		height: 66px;
		overflow: hidden;
		border-radius: 6px;
		margin-right: 10px;

		image {
			width: 100%;
			height: 100%;
		}
	}

	.box-title {
		font-weight: 800;
		font-size: 14px;
		color: #333333;
		margin-bottom: 5px;
	}

	.wrap-box {
		width: 100%;
		box-sizing: border-box;
		display: flex;
		align-items: center;
		flex-wrap: wrap;

	}

	.icon-lv {
		background: #E6F5F0;
		border-radius: 2px 2px 2px 2px;

		box-sizing: border-box;
		padding: 5px;
		font-weight: 400;
		font-size: 10px;
		font-size: 10px;
		color: #4AA76F;
		margin-right: 10px;
	}

	.icon-h {
		background: #FFEDD4;
		border-radius: 2px 2px 2px 2px;

		box-sizing: border-box;
		padding: 5px;
		font-weight: 400;
		font-size: 10px;
		font-size: 10px;
		color: #EDA23A;
	}

	.price_ {
		font-weight: bold;
		font-size: 14px;
		color: #FB423B;
		margin-right: 15px;
	}

	.sc {
		font-size: 10px;
		color: #AAAAAA;
		text-decoration-line: line-through;
		text-transform: none;
	}

	.liang-box {
		border-top: 1px solid #DDDDDD;
		border-bottom: 1px solid #DDDDDD;
		box-sizing: border-box;
		padding: 10px 0px;
		margin-top: 10px;
	}

	.lb-box {
		width: 100%;
		display: flex;
		align-items: center;
		justify-content: space-between;
		font-size: 12px;
		color: #999999;

	}

	.right-icon {
		width: 100%;
		display: flex;
		align-items: center;
		justify-content: flex-end;
		font-size: 12px;
		font-weight: bold;
		margin-top: 10px;

	}

	.b-d-s {
		width: 100%;
		display: flex;
		align-items: center;
		justify-content: space-between;
	}

	.qhaaniu {
		width: 70px;
		height: 30px;
		background: #1b9137;
		display: flex;
		align-items: center;
		justify-content: center;
		color: #fff;
		font-size: 12px;
		border-radius: 4px;
	}
</style>