<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="changeStatus(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">
				<template v-if="merchantType==10">
					<view class="header">
						<text style="font-weight: bold;">{{item.playDate}} {{item.playTime}}出发/{{item.orderType==3?'拼船':'包船'}}</text>
						<text :class="oscConfig[item.status]||'textDcx'">{{FishJialeOcfg[item.status]}}</text>
					</view>
					<view class="mainContent" @tap="navTo(item)">
						<image class="image" :src="item.coverImg||'../../../static/orderEg.png'" mode="aspectFill">
						</image>
						<view class="middle">
							<view class="title" style="display: flex; justify-content: space-between;">
								<span> {{item.goodsNameAndType}}</span>
								<span> ￥{{item.totalPrice}}</span>
							</view>
							<span class='info' style="display: flex; justify-content: space-between;">
								<span>
									<span style="margin-right: 15rpx;">{{item.linkName}}</span>
									<span>{{item.linkPhone}}</span>
								</span>
								<span>x{{item.num}}</span>
							</span>
						</view>
					</view>
					<!-- 待使用 -->
				<!-- 	<view class="bottom" @click="hexiao(item)" v-if="item.status==1">
						<view class="detail s1">
							核销订单
						</view>
					</view> -->
					<!-- <view class="bottom" @click="Detail(item)" v-else>
					<view class="detail">
						删除订单
					</view>
				</view> -->
				</template>
				<template v-if="merchantType==4">
					<view class="header">
						<text style="font-weight: bold;">{{item.merchantName}}</text>
						<text :class="oscConfig2[item.orderStatus]||'textDcx'">{{FishJialeOcfg2[item.orderStatus]}}</text>
					</view>
					<view class="mainContent" @tap="navTo(item)">
						<image class="image" :src="item.productImg&&item.productImg.split(',')[0]||'../../../static/orderEg.png'" mode="aspectFill">
						</image>
						<view class="middle">
							<view class="title" style="display: flex; justify-content: space-between;">
								<span> {{item.productName}}</span>
								<span> ￥{{item.realityPay}}</span>
							</view>
							<span class='info' style="display: flex; justify-content: space-between;">
								<span>
									<span style="margin-right: 15rpx;">{{item.activityStartTime||''}}至{{item.activityEndTime}}</span>
								</span>
								<span>x{{item.num}}</span>
							</span>
						</view>
					</view>
					<!-- 待使用 -->
					<view class="bottom" @click="hexiao2(item)" v-if="item.state==1">
						<view class="detail s1">
							核销订单
						</view>
					</view>
				</template>
			</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 {
				//渔家乐
				FishJialeOcfg: {
					0: '待支付',
					1: '待使用',
					2: '拼船中',
					3: '已使用',
					4: '退款中',
					5: '已退款',
					6: '已取消',
					7: '已完成',
					8: '拼团失败'
				},
				//餐饮
				FishJialeOcfg2: {
					0: '待支付',
					4: '待使用',
					3: '已完成',
					'-1': '已取消',
					'-2': '退款中',
					'-3': '已退款',
				},
				oscConfig2: {
					0: 'textDzf',
					4: 'textDcx',
					3: 'textQx',
					'-1': 'textQx',
					'-2': 'textQx',
					'-3': 'textQx',
				},
				oscConfig: {
					0: 'textDzf',
					1: 'textDcx',
					2: 'textDcx',
					3: 'textQx',
					4: 'textQx',
					5: 'textQx',
					6: 'textQx',
					7: 'textQx',
					8: 'textQx',
				},
				disScroll: false,
				pageIndex: 1,
				pageCount: 50,
				current: 0,
				dataList: [],
				status: '',
				state:'',
				merchantId: uni.getStorageSync('merchantId'),
				merchantType: uni.getStorageSync('merchantType'),
				tabList: [{
						name: '全部订单'
					},
					{
						name: '待支付'
					},
					{
						name: '待使用'
					},
					{
						name: '已完成'
					},
					{
						name: '退款/售后'
					},
				],
			}
		},
		onLoad(option) {
			if (option.index>=0) {
				const index = option.index;
				//其他页面入参
				if (index == 0) {
					this.changeStatus(1)
				} else if (index == 1) {
					this.changeStatus(2) 
				} else if (index == 2) {
					this.changeStatus(3)
				} else if (index == 3) {
					this.changeStatus(4) 
				}else {
					this.changeStatus(0)
				}
			}else if (option.typeTxt) {
				const typeTxt = option.typeTxt;
				//其他页面入参
				if (typeTxt =='待付款') {
					this.changeStatus(1)
				} else if (typeTxt =='待使用') {
					this.changeStatus(2)
				} else if (typeTxt =='已完成') {
					this.changeStatus(3)
				} else if (typeTxt == '退款售后') {
					this.changeStatus(4)
				}else if (typeTxt == '已取消') {
					this.changeStatus(0)
				}
			} else {
				if(this.merchantType==10){
					this.getOrderList()
				}else{
					this.getOrderList2()
				}
				
			}
		},
		methods: {
			// 去详情
			navTo(item) {
				uni.navigateTo({
					url: '/pagesHouse/Mine/ordersList/details/details?orderCode=' + item.orderCode
				})
			},
			hexiao(item) {
				let that = this;
				uni.showModal({
					title: '提示',
					content: '确定核销订单？',
					success: function(res) {
						if (res.confirm) {
							that.$api.get('/scenic/order/orderWriteOff/'+item.orderCode).then(res => {
								if (res.data.code === 0) {
									that.$showToast('订单已核销');
									that.init();
								} else that.$showToast(res.data.msg)
							})
						}
					}
				});
			},
			// 核销餐饮
			hexiao2(item) {
				let that = this;
				uni.showModal({
					title: '提示',
					content: '确定核销订单？',
					success: function(res) {
						if (res.confirm) {
							that.$api.post('/api/merchant/food/scenic/merchant/order/verifyOrderQrCode', {
								merchantId: that.merchantId,
								orderCode: item.orderCode,
								type: 4
							}).then(res => {
								if (res.data.code === 0) {
									that.$showToast('订单已核销');
									that.init();
								} else that.$showToast(res.data.msg)
							})
						}
					}
				});
			},
			init() {
				this.pageIndex = 1;
				this.dataList = [];
				if(this.merchantType==10){
					this.getOrderList()
				}else{
					this.getOrderList2()
				}
			},
			changeStatus(index) {
				this.current=index;
				if(this.merchantType==10){
					if (index === 0) this.status = '';
					else if (index === 1) this.status = '0'
					else if (index === 2) this.status = '1';
					else if (index === 3) this.status = '3,7';
					else if (index === 4) this.status = '4,5';
				}else{
					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';
				}
				this.init();
			},
			//渔家乐订单
			getOrderList() {
				let that = this;
				this.$api.get('/api/fishering/personCenterPage', {
					merchantId: this.merchantId,
					status: this.status,
					page: this.pageIndex,
					limit: this.pageCount,
				}).then(res => {
					if (res.data.code === 0) {
						let {
							list,
							total
						} = res.data.data;
						that.dataList = [...that.dataList, ...list];
						if (res.data.data.list.length < 10) {
							this.disScroll = true;
						} else {
							that.pageIndex++;
						}
					} else that.$showToast(res.data.msg);
				})
			},
			getOrderList2() {
				let that = this;
				this.$api.get('/api/merchant/food/queryPageMerchantOrder', {
					merchantId: this.merchantId,
					state: this.state,
					page: this.pageIndex,
					limit: this.pageCount,
				}).then(res => {
					if (res.data.code === 0) {
						let {
							list,
							total
						} = res.data.data;
						that.dataList = [...that.dataList, ...list];
						if (res.data.data.list.length < 10) {
							this.disScroll = true;
						} else {
							that.pageIndex++;
						}
					} else that.$showToast(res.data.msg);
				})
			},
			
		}
	}
</script>

<style lang="scss" scoped>
	.textQx {
		color: #999;
	}

	.textDcx {
		color: #333333;
	}

	.textDzf {
		color: #FF7D01;
	}

	.pages {
		// background: #F9FAFC;
		box-sizing: border-box;
		padding-bottom: 50rpx;

		.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: 0 24rpx 30rpx;

				.header {
					display: flex;
					justify-content: space-between;
					padding: 34rpx 0;
					font-size: 28rpx;
				}

				.mainContent {
					display: flex;

					.image {
						background-repeat: no-repeat;
						background-size: cover;
						width: 136rpx;
						min-width: 136rpx;
						height: 136rpx;
						border-radius: 12rpx;
					}

					.middle {
						color: #777777;
						margin-left: 20rpx;
						width: 100%;

						.title {
							font-weight: bold;
							font-size: 30rpx;
							margin: 16rpx 0 30rpx;
						}

						.info {
							font-size: 26rpx;
							color: #777777;
						}
					}

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

				}

				.bottom {
					display: flex;
					justify-content: flex-end;
					margin-top: 16rpx;

					.detail {
						border-radius: 16rpx;
						color: darkgrey;
						padding: 13rpx 34rpx;
						background-color: #F6F6F6;
						font-size: 26rpx;
						color: #333333;
						font-weight: Regular;

					}

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

			}
		}
	}
</style>