<template>
	<view class="content">
		<view class="list" v-if="yearArr.length > 0">
			<view class="listItem" v-for="(item, index) in yearArr" :key="index">
				<view class="listItem-no">
					订单号：{{item.order.order_no}}
				</view>
				<view class="listItem-cont">
					<view class="listItem-cont-label">
						<view class="listItem-cont-name">
							订单状态
						</view>
						<view class="listItem-cont-text listItem-cont-status">
							{{item.status.text}}
						</view>
					</view>
					<view class="listItem-cont-label">
						<view class="listItem-cont-name">
							案件类型
						</view>
						<view class="listItem-cont-text">
							{{item.order.order_business}}
						</view>
					</view>
					<view class="listItem-cont-label">
						<view class="listItem-cont-name">
							补差价金额
						</view>
						<view class="listItem-cont-text listItem-cont-price">
							￥{{item.price}}
						</view>
					</view>
				</view>
				<view class="listItem-labor">
					<view class="listItem-labor-time">
						{{item.created_at}}
					</view>
					<view class="listItem-labor-btn">
						<view v-if="item.can.pay_status == 1" @click="cancelSheet(item)" class="listItem-labor-go active">
							取消支付
						</view>
						<view v-if="item.can.pay_status == 1" @click="expressSheet(item)" class="listItem-labor-go">
							去支付
						</view>
						<view v-else-if="item.can.pay_status == 2" class="listItem-labor-go active">
							审核中
						</view>
						<view v-else-if="item.can.pay_status == 3" @click="$Router.push({name: 'VoucherOpen', params: {payId: item.offline_pays.offline_pay_id, orderId: item.expand_order_id, orderType: item.order_type, type: 'edit'}})" class="listItem-labor-go">
							审核驳回
						</view>
					</view>
				</view>
			</view>
		</view>
		
		<view class="pack-center pages-hint" v-else>
		    <image src="https://douhuo-storage.oss-cn-beijing.aliyuncs.com/images/2023/06/06/7ad417d0c215db601b8e1bead05c3a5e.png"></image>
		    <view>暂无订单</view>
		</view>
		
		<!-- 打款凭证弹出 -->
		<view class="voucherBack" :class="{active : voucherState}"></view>
		<view class="voucherPop" :class="{active : voucherState}">
			<view class="tipsWhite">
				<image class="voucherPop-img" src="https://cdn.douhuofalv.com/images/2023/04/17/f4a3c45fe9aa7db143a362fc5b13b31d.png" mode="widthFix"></image>
				<view class="voucherPop-title">
					<view class="voucherPop-name">支付提示</view>
					<view class="voucherPop-text">抱歉，此订单不支持线上支付，请上传打款凭证</view>
					<view class="voucherPop-btn">
						<view class="voucherPop-go" @click="voucherState = false">
							暂不支付
						</view>
						<view class="voucherPop-go voucherPop-up" @click="clickOpen">
							上传凭证
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import { diffPrices, cancelPrices } from '@/apis/interfaces/synthesis'
	export default {
		data() {
			return {
				yearStatus 	 : 0,	   // 0 未付款 1 2
				yearArr	 	 : [],     // 委托单列表
				page         : {},     // 分页信息
				voucherState : false,  // 上传凭证弹出
				lodingStats  : false,  // 加载状态
				orderType    : '',	   // 委托单列表-类型
				orderId      : '',     // 委托单列表-id
			}
		},
		
		onShow() {
			// 获取-委托单-列表
			this.yearServe();
		},
		
		methods: {
			// 委托单-列表
			yearServe(page){
				diffPrices({
					order_type	: this.$Route.query.orderType,
					order_id	: this.$Route.query.orderId,
					page		: page || ''
				}).then(res => {
					let esArr = res.data
					let list = this.yearArr,
					    newData = []
					    if(page == 1 || page == undefined) list = []
					    newData = list.concat(esArr)
					this.yearArr     = newData
					this.page        = res.page
					this.lodingStats = false
					uni.stopPullDownRefresh()
				}).catch(err => {
					uni.showToast({
						title: err.message,
						icon : 'none'
					})
				})
			},
			
			// 选择支付方式
			expressSheet(item) {
				this.orderId   = item.synthesis_diff_price_id
				this.orderType = item.order_type
				uni.showActionSheet({
				    itemList: ['线上支付', '线下支付'],
				    success: sheetRes => {
						if(sheetRes.tapIndex == 0) {
							if(item.can.online) {
								this.$Router.push({name: 'FeePay', params: {id: item.synthesis_diff_price_id, orderType: item.order_type, price: item.price, style: 'diff', payForm: this.$Route.query.payForm}})
								return
							}
							this.voucherState = true
						} else if (sheetRes.tapIndex == 1) {
							this.$Router.push({name: 'VoucherOpen', params: {orderId: item.synthesis_diff_price_id, orderType: item.order_type}})
						}
				    },
				    fail: sheetFail => {}
				})
			},
			
			// 上传凭证
			clickOpen() {
				this.voucherState = false
				this.$Router.push({name: 'VoucherOpen', params: {orderId: this.orderId, orderType: this.orderType}})
			},
			
			// 取消订单
			cancelSheet(item) {
				uni.showModal({
					title		: '温馨提示',
					content		: '是否取消订单？',
					cancelText	: "取消", // 取消按钮的文字  
					confirmText : "确认", // 确认按钮的文字  
					showCancel  : true, // 是否显示取消按钮，默认为 true
					confirmColor: '#D4155A',
					cancelColor : '#999999',
					success: res => {
						if(res.confirm) {  
							cancelPrices(item.synthesis_diff_price_id).then(() => {
								uni.showToast({
									title: '取消成功',
									icon : 'none'
								})
								// 获取-委托单-列表
								this.yearServe();
							}).catch(err => {
								uni.showToast({
									title: err.message,
									icon : 'none'
								})
							})
						}
					} 
				})
			},
			
			// 页面相关事件处理函数--监听用户下拉动作
			onPullDownRefresh() {
			    // 获取-委托单-列表
			    this.yearServe();
			},
			        
			// 上拉加载
			onReachBottom(){
			    this.lodingStats = true
			    let pageNumber = this.page.current
			    if(this.page.has_more){
			        pageNumber++
			        // 获取-委托单-列表
			        this.yearServe(pageNumber);
			    }
			}
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		background-color: #f7f9fa;
		overflow-y: scroll;
	}
	
	.list {
		padding: 30rpx;
		box-sizing: border-box;
		.listItem {
			background-color: #ffffff;
			border-radius: 10rpx;
			margin-bottom: 30rpx;
			.listItem-no {
				line-height: 90rpx;
				padding: 0 30rpx;
				box-sizing: border-box;
				border-bottom: 2rpx solid #eeeeee;
			}
			.listItem-cont {
				padding: 15rpx 30rpx;
				box-sizing: border-box;
				.listItem-cont-label {
					display: flex;
					line-height: 54rpx;
					color: #666666;
					font-size: 28rpx;
					padding: 10rpx 0;
					.listItem-cont-name {
						flex: 1;
					}
					.listItem-cont-text {
						color: #000000;
						&.listItem-cont-status {
							color: #da2b56;
						}
						&.listItem-cont-price {
							font-weight: 600;
						}
					}
				}
			}
			.listItem-labor {
				border-top: 2rpx solid #eeeeee;
				line-height: 50rpx;
				padding: 25rpx 30rpx;
				box-sizing: border-box;
				font-size: 26rpx;
				display: flex;
				.listItem-labor-time {
					flex: 1;
					color: #999999;
				}
				.listItem-labor-go {
					display: inline-block;
					border: 2rpx solid #da2b56;
					color: #da2b56;
					border-radius: 80rpx;
					padding: 0 20rpx;
					margin-left: 20rpx;
					&.active { 
						color: #272727;
						border-color: #999999;
					}
				}
			}
		}
	}
	
	// 打款凭证弹出
	.voucherBack {
		position: fixed;
		width: 100vw;
		height: 100vh;
		left: 0;
		top: 0;
		z-index: 99;
		background-color: rgba(0, 0, 0, .6);
		display: none;
		&.active {
			display: block;
		}
	}
	.voucherPop {
		-webkit-box-orient: vertical;
		-webkit-box-pack: center;
		position: fixed;
		left: 0;
		right: 0;
		top: 0;
		bottom: 0;
		z-index: 100;
		padding: 0 10%;
		box-sizing: border-box;
		display: none;
		&.active {
			display: -webkit-box;
		}
		.tipsWhite {
			background-color: #ffffff;
			border-radius: 20rpx;
			position: relative;
			.voucherPop-img {
				position: absolute !important;
				top: -80rpx;
				right: calc(50% - 100rpx);
				width: 200rpx;
			}
			.voucherPop-title {
				box-sizing: border-box;
				padding: 50rpx 70rpx;
				margin-top: 100rpx;
				text-align: center;
				.voucherPop-name {
					font-weight: 600;
					font-size: 38rpx;
				}
				.voucherPop-text {
					padding: 30rpx 0 35rpx;
					line-height: 44rpx;
				}
				.voucherPop-btn {
					display: flex;
					.voucherPop-go {
						flex: 2;
						text-align: center;
						border: 2rpx solid #da2b56;
						color: #da2b56;
						margin: 0 15rpx;
						line-height: 74rpx;
						border-radius: 10rpx;
						background-color: #ffffff;
						&.voucherPop-up {
							background-color: #da2b56;
							color: #ffffff;
						}
					}
				}
			}
		}
	}
</style>