<template>
	<view class="pages" :style="{'min-height':h+'px','padding-top':(mt)+'px'}">
		<c-nav-bar title="我的订单"></c-nav-bar>
		<view class="tb">
			<view class="tabs">
				<view v-for="(item,index) in tabList" :key="index" @tap="changeTab1(index)">
					<text :class="index==current?'active':''">{{item.name}}</text>
				</view>
			</view>
		</view>
		<view class="mainContain">
			<view v-if="dataList.length>0" class="card" v-for="item,index  in dataList" :key="index">
				<view class="header">
					<span style="font-weight: 700;">下单时间：{{item.orderTime}}</span>
					<text v-if='item.state==0' class="orange">待支付</text>
					<text v-else-if='item.state==1' class="red">已支付</text>
					<text v-else-if='item.state==-1' class="red">已取消</text>
					<text v-else-if='item.state==-2' class="green">退款中</text>
					<text v-else-if='item.state==3' class="green">已完成</text>
					<text v-else-if='item.state==-3' class="green">已退款</text>
					<text v-else-if='item.state==4' class="red">待使用</text>
					<text v-else-if='item.state==5' class="green">已预约</text>

					<text v-else :class="statusClass[item.state]">{{status[item.state]}}</text>
				</view>
				<view class="mainContent" @click="navTo(item)">
					<image class="image" :src="item.pic" mode="aspectFill"></image>
					<view class="middle">
						<view class="title" style="display: flex; justify-content: space-between;">
							<span> {{item.thingName}}</span>
							<span> ￥{{item.totalPrice}}</span>
						</view>
						<span class='info' style="display: flex; justify-content: space-between;">
							<span>
								<span style="margin-right: 15rpx;">{{item.userName}}</span>
								<span>{{item.phone}}</span>
							</span>
							<span>x{{item.num}}</span>
						</span>
					</view>
				</view>
				<view class="bottom" @click="handleDetail(item)" v-if="item.state==4||item.state==5">
					<view class="detail del">
						核销订单
					</view>
				</view>
				<view class="bottom" @click="Detail(item)" v-else>
					<view class="detail">
						删除订单
					</view>
				</view>


			</view>
			<view class="nodata" v-if='dataList.length==0'>
				<NoData></NoData>
			</view>
		</view>
	</view>
</template>

<script>
	import TopTabs from '@/components/TopTabs/topTabs.vue';
	// import NoData from '../../components/NoData/index.vue';
	export default {
		components: {
			TopTabs,
			// NoData
		},
		data() {
			return {
				h: uni.getSystemInfoSync().windowHeight,
				mt: uni.getSystemInfoSync().statusBarHeight + 44,
				current: 0,
				mysearch: '',
				dataList: [],
				limit: 10,
				page: 1,
				state: '',
				fishermanId: uni.getStorageSync('merchantId'),
				statusClass: [
					'',
					'green',
					'blue',
					'grey',
					'grey',
				],
				status: [
					'',
					'已预订',
					'已入住',
					'已退房',
					'已取消',
				],
				// mt: uni.getSystemInfoSync().statusBarHeight + 44,
				tabList: [{
						name: '全部订单'
					},
					{
						name: '待支付'
					},
					{
						name: '待使用'
					},
					{
						name: '已完成'
					},
					{
						name: '退款/售后'
					},
				],
			}
		},
		onLoad(option) {
			console.log(option.type);
			if (option.type) {
				console.log('1111');
				const type = parseInt(option.type)

				if (type == 0) {
					this.changeTab1(1)
				} else if (type == 4) {
					this.changeTab1(2)
				} else if (type == 3) {
					this.changeTab1(3)
				} else if (type == -3) {
					this.changeTab1(4)
				}
			} else {
				console.log('2222');
				this.getOrderList()
			}
		},
		methods: {
			// 去详情
			navTo(item) {
				uni.setStorageSync('list', item);
				uni.navigateTo({
					url: '/pagesHouse/Mine/ordersList/details/details'
				})
			},
			// 核销
			handleDetail() {
				// let dto = {
				// 	writeOffCode: item.orderCode
				// }
				// this.$api.post('/merchant/merchantFisherman/home/writeOffOrder?dto=', dto).then(res => {

				// })
				uni.navigateTo({
					url: '/pagesHouse/Verification/index'
				})
			},
			// 删除
			Detail(item) {
				console.log(this.current);
				this.$api.del('/merchant/merchantFisherman/home', [
					item.id
				]).then(res => {
					if (res.data.code == 0) {
						this.$showToast('删除成功');
						// this.getOrderList()
						setTimeout(() => {
							this.changeTab1(this.current)
						}, 1000)
					} else {
						this.$showToast('删除失败');
						setTimeout(() => {
							this.changeTab1(this.current)
						}, 1000)
						// this.getOrderList()
					}
				})
			},
			changeTab1(index) {
				this.current = index;
				if (index === 0) this.state = '';
				else if (index === 1) this.state = '0'
				else if (index === 2) this.state = '4';
				else if (index === 3) this.state = '3';
				else if (index === 4) this.state = '-3';
				// else this.FormData.status = '0,1,-1,2,-2,-3,3,4,5,6,7,8,9,10,11';
				this.changeTab(index)
			},
			getOrderList(state) {
				this.$api.get('/merchant/merchantFisherman/home/queryMyOrderPage', {
					fishermanId: this.fishermanId,
					limit: this.limit,
					page: this.page,
					state: state ? state : ''
				}).then((res => {
					if (res.data.code == 0) {
						this.dataList = res.data.data.list
					} else {
						uni.showToast({
							title: res.data.msg,
							icon: 'none'
						})
					}


				}))
			},
			getOrderByStatusList(state) {
				this.$api.get('/merchant/merchantFisherman/home/queryMyOrderPage', {
					fishermanId: this.fishermanId,
					limit: this.limit,
					page: this.page,
					state: state
				}).then((res => {
					if (res.data.code == 0) {
						this.dataList = res.data.data.list
					} else {
						uni.showToast({
							title: res.data.msg,
							icon: 'none'
						})
					}


				}))
			},
			changeTab(index) {
				this.tabIdx = index;
				switch (index) {
					case 0:
						this.getOrderList()
						break
					case 1:
						// this.getOrderList(0)
						this.getOrderByStatusList(0)
						break
					case 2:

						this.getOrderList(4)
						break
					case 3:
						this.getOrderList(3)
						break
					case 4:
						this.getOrderList(-3)
						break
				}
			},
		}
	}
</script>

<style lang="scss" scoped>
	.pages {
		background: #F9FAFC;
		box-sizing: border-box;

		.tb {
			width: 100%;

			top: 0;
			left: 0;
			z-index: 999;

			.searchBoxParent {
				width: 100%;
				background: #fff;
				padding: 20rpx 24rpx 6rpx;
				box-sizing: border-box;

				.searchBox {
					width: 100%;
					background-color: #fff;
				}
			}

			.tabs {
				background: #fff;
				padding: 26rpx 0;
				display: flex;
				align-items: center;
				width: 100%;

				&>view {
					width: 25%;
					font-size: 28rpx;
					font-family: PingFangSC-Regular, PingFang SC;
					font-weight: 400;
					color: black;
					line-height: 40rpx;
					position: relative;
					text-align: center;
				}

				.active {
					font-size: 32rpx;
					font-family: PingFang-SC-Bold, PingFang-SC;
					font-weight: bold;
					color: black;
					line-height: 45rpx;
				}

				.active::after {
					position: absolute;
					content: '';
					width: 50rpx;
					height: 8rpx;
					background: #007A69;
					bottom: -26rpx;
					left: 60%;
					margin-left: -42rpx;
				}
			}
		}

		.green {}

		.mainContain {
			display: flex;
			flex-direction: column;
			padding: 0 20rpx;

			.nodata {
				background: white;

			}

			.card {
				background: #fff;
				border-radius: 16rpx;
				margin: 20rpx 0;
				padding: 20rpx;

				.header {
					display: flex;
					justify-content: space-between;
					border-bottom: 1px #f3f3f3 solid;
					padding: 20rpx;

					.red {
						color: indianred;
					}

					.green {
						color: #999999;
					}

					.blue {
						color: #1372FF;
					}

					.grey {
						color: #4C5F76;
					}

					.orange {
						color: #FF9100;
					}
				}

				.mainContent {
					// border-bottom: 1px #f3f3f3 solid;
					display: flex;
					padding: 20rpx 0;


					// justify-content: space-evenly;

					.image {
						background-repeat: no-repeat;
						background-size: cover;
						width: 198rpx;
						height: 180rpx;
						border-radius: 16rpx;
					}

					.middle {
						padding-top: 16rpx;
						color: #777777;
						// display: flex;
						// flex-direction: column;
						// justify-content: space-between;
						margin-left: 25rpx;
						width: 100%;


						.title {
							font-weight: 700;
							font-size: 32rpx;
							color: black;
						}

						.info {
							padding-top: 30rpx;
							color: #777777;
							// display: flex;
							// flex-direction: column;

							&>span {
								margin-top: 10rpx;

							}
						}
					}

					.price {
						color: red;
						text-align: center;
						height: 100%;
						align-items: center;
						align-self: center;
						font-size: 29rpx;
						font-weight: 700;
					}

				}

				.bottom {
					// padding: 30rpx 20rpx;
					display: flex;
					justify-content: flex-end;

					.detail {

						// border: 1rpx solid darkgrey;
						border-radius: 16rpx;
						color: darkgrey;
						padding: 13rpx 34rpx;
						background-color: #F6F6F6;
						font-size: 26rpx;
						color: #333333;
						font-weight: Regular;

					}

					.del {
						border-radius: 16rpx;
						color: darkgrey;
						padding: 13rpx 34rpx;
						background-color: #007A69;
						font-size: 26rpx;
						color: #fff;
						font-weight: Regular;
					}
				}

			}
		}
	}
</style>