<template>
	<view class="page">
		<view class="pageMain">
			<view class="tabBox flex">
				<view class="eveTab" v-for="(item,index) in tabs" :key="index"
					:class="index == tabIndex ? 'text-28 text-bold text-2f9' : 'text-26 text-33'"
					@click="changeTab(index)">
					{{item}}
					<view class="tabLine" v-if="tabIndex == index"></view>
				</view>
			</view>
			<view class="listBox bg-ff">
				<ty-list-list :status="load_status">
					<view class="eveList border-bottom-f5" v-for="(item,index) in list" :key="index"
						@click="go('/pages/expert/orderDetail?id=' + item.id)">
						<view class="flex align-center justify-between margin-bottom-20">
							<view class="flex-one flex align-center">
								<view class="tyIcon-dingdanhaochaxun text-28 text-33 margin-right-5"></view>
								<view class="flex-one text-24 text-33 line-40">{{item.order_number}}</view>
							</view>
							<view class="text-2f9 text-26 line-40">{{item.status_text}}</view>
						</view>
						<view class="flex margin-bottom-20">
							<view class="headerImg">
								<image :src="item.expert_head_img" class="width-100p height-100p block"
									mode="aspectFill">
								</image>
							</view>
							<view class="flex-one margin-left-15">
								<view class="flex justify-between align-center margin-bottom-10">
									<view class="text-34 text-33 text-bold line-50">{{item.expert_name}}</view>
									<view class="text-price text-bold text-32 text-ff85">{{item.expert_price}}</view>
								</view>
								<view class="text-cut-one text-26 text-909298">{{item.expert_brief}}
								</view>
							</view>
						</view>
						<view class="text-28 line-40 text-cut-two">
							<text class="text-aa">咨询内容：</text>
							<text class="text-33 text-cut-two">{{item.ask_content}}</text>
						</view>
						<!-- 待支付 -->
						<view class="margin-top-30 flex justify-end align-center" v-if="item.status == 1">
							<view class="btn1" @click.stop="cancelOrder(item.id)">取消订单</view>
							<view class="btn2 margin-left-20" @click.stop="tapPay(item.id)">支付</view>
						</view>
						<!-- 进行中 -->
						<view class="margin-top-30 flex justify-end align-center"
							v-if="item.status == 2 && item.append_times < 3">
							<view class="btn2 margin-left-20" @click="go('/pages/expert/addQues?id='+item.id)">追加提问
							</view>
						</view>
						<!-- 待评价 -->
						<view class="margin-top-30 flex justify-end align-center" v-if="item.status == 3">
							<view class="btn2 margin-left-20" @click="go('/pages/expert/evaluate?id=' + item.id)">去评价
							</view>
						</view>
						<!-- 已完成 已退款 已取消 -->
						<view class="margin-top-30 flex justify-end align-center"
							v-if="item.status == 6 || item.status == 4 || item.status == 5">
							<view class="btn1" @click.stop="delOrder(item.id)">删除订单</view>
						</view>
					</view>
				</ty-list-list>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				tabs: ['全部', '待支付', '进行中', '待评价', '已完成'],
				tabIndex: 0,
				load_status: '',
				list: [],
			}
		},
		onLoad(options) {
			this.tabIndex = options.index ? options.index : 0;
		},
		onShow() {
			this.loadList(1)
		},
		onReachBottom() {
			this.loadList(2)
		},
		methods: {
			changeTab(i) {
				if (this.tabIndex == i) {
					return;
				} else {
					this.tabIndex = i;
					this.loadList(1)
				}
			},
			loadList(first_page) {
				this.rq.getList('fire/api/Fire/getOrderList', {
					index: this.tabIndex
				}, {
					that: this,
					first_page
				})
			},
			// 取消订单
			cancelOrder(id) {
				this.cn.confirm('确认取消订单吗?').then(r => {
					if (r.confirm) {
						this.rq.getData('fire/api/Fire/submitCancelOrder', {
							order_id: id
						}).then(res => {
							if (res.code == 0) {
								this.loadList(1)
							}
						})
					}
				})
			},
			// 支付
			tapPay(id) {
				this.rq.getData('fire/api/Fire/submitOrderRePay', {
					order_id: id
				}, {
					loading: 1
				}).then(res => {
					if (res.code == 0) {
						if (res.data.need_pay == 1) { //需要支付
							this.cn.requestPayment(res.data.pay_params, 1).then(res => {
								this.loadList(1)
							}).catch(res => {
								this.loadList(1)
							})
						} else { //不需要支付
							this.cn.alert(res.msg).then(res => {
								this.loadList(1)
							})
						}
					}
				})
			},
			// 删除订单
			delOrder(id) {
				this.cn.confirm('确认删除订单吗?').then(r => {
					if (r.confirm) {
						this.rq.getData('fire/api/Fire/submitOrderDelete', {
							order_id: id
						}).then(res => {
							if (res.code == 0) {
								this.loadList(1)
							}
						})
					}
				})
			}
		}
	}
</script>

<style scoped>
	.pageMain {
		min-height: 100vh;
		padding: 105rpx 0 0;
		box-sizing: border-box;
	}

	.tabBox {
		position: fixed;
		top: 0;
		left: 0;
		width: 100vw;
		height: 90rpx;
		background: #fff;
		z-index: 10;
	}

	.eveTab {
		flex: 1;
		line-height: 90rpx;
		text-align: center;
		position: relative;
	}

	.tabLine {
		width: 40rpx;
		height: 4rpx;
		background: #2F97FF;
		position: absolute;
		left: 0;
		right: 0;
		bottom: 20rpx;
		margin: auto;
	}

	.listBox {
		min-height: calc(100vh - 105rpx);
		box-sizing: border-box;
		padding-bottom: calc(35rpx + env(safe-area-inset-bottom));
	}

	.eveList {
		width: 100%;
		padding: 20rpx 30rpx 30rpx;
		box-sizing: border-box;
	}

	.headerImg {
		width: 110rpx;
		height: 110rpx;
		border-radius: 10rpx;
		overflow: hidden;
	}

	.btn1,
	.btn2 {
		width: 180rpx;
		text-align: center;
		line-height: 64rpx;
		border-radius: 36px;
		font-size: 28rpx;
		font-weight: bold;
	}

	.btn1 {
		border: 2rpx solid #CCCCCC;
		color: #777777;
	}

	.btn2 {
		border: 2rpx solid #2F97FF;
		color: #2F97FF;
	}
</style>
