<template>
	<view style="height: 100vh;display: flex;flex-direction: column;" @click="ejectOpen=false">
		<topBar height="343rpx" title="订单列表">
			<view slot="coment">
				<view class="header_seach">
					<view class="header_seach_seach">
						<view class="seach_input">
							<uni-easyinput :candidate='candidate' :ejectOpen='ejectOpen' @ejectFn='ejectFn'
								:letfText='letfText' confirmType='search' @confirm='seachFn'
								placeholder-style="color:#bbbbbb;font-weight: 100;" v-model="seachValue"
								:placeholder="letfText=='订单号'? '订单编号':letfText=='司机'?'司机姓名,手机号码':letfText=='企业'?'企业名称,企业编号':'油站名称'"
								@iconClick="ejectOpen = !ejectOpen">
							</uni-easyinput>
						</view>
					</view>
					<view class="Navigation">
						<view @tap="seleFn(item);seleindex=index"
							:class="seleindex==index?'navigation_seleitem':'navigation_item'"
							v-for="(item,index) in navigation">
							{{item.text}}
							<uni-icons :animation="animationData" class="icoon" v-if="index==0" type="refreshempty"
								style="margin-left: 10rpx;" size="15" color="#bbbbbb"></uni-icons>
						</view>
					</view>
				</view>
			</view>
		</topBar>
		<view style="flex: 1;overflow: hidden;">
			<scroll-view v-if="listData.length!=0" style="height: 100%;" scroll-y="true" @scrolltolower='scrolltolower'>
				<view v-for="(item,index) in listData" class="form_body">
					<view class="form_body_item">
						<view class="form_body_item_top">
							<view :style="{backgroundColor:item.payAccountType==0?'#FD9500':'#2866FF' }"
								class="form_body_item_top_label">{{item.payAccountType==0?'个人':'企业'}}</view>
							<view>{{item.orderSerialNumber}}</view>
						</view>
						<view style="padding: 0 25rpx; margin-top: 23rpx;">
							<view class="from_body_item_container">

								<view class="flex between">
									<view class="flex">
										<view>{{item.oilCustomerInfo.phone}}</view>
										<view class="samll_txext" style="margin-left:23rpx;">
											{{item.oilCustomerInfo.name}}
										</view>
										<view class="samll_txext" style="margin-left:23rpx;">
											{{item.plateNumber || ''}}
										</view>
									</view>
									<view :style="{fontSize: '24rpx', color:option(item.orderStatus).color }">
										{{option(item.orderStatus).text}}
									</view>
								</view>
								<view style="margin-bottom:23rpx ; font-size: 26rpx;" class="text">
									{{item.companyInfo.name || '暂无'}}
								</view>
								<view class="flex between">
									<view class="flex">
										<view class="samll_txext">{{item.siteName}}</view>
									</view>
									<view style="color: #999999;" class="bgtext">{{item.volume}}L</view>
								</view>
								<view class="flex between">
									<view class="flex">
										<view class="samll_txext">
											{{ item.oilProductType === 'GAS' ? '天然气' : item.oilProductType === 'PETROL' ? '汽油' : '柴油' }}/{{item.oilsCode}}
											{{item.realPrice}}/{{ item.oilProductType === 'GAS' ? 'KG' : 'L' }}
										</view>
									</view>
									<view class="bgtext">¥{{item.payRealAmount}}</view>
								</view>
							</view>
						</view>
						<view class="form_body_item_footer">
							<view style="font-size: 22rpx;" class="samll_txext">{{item.refundTime || ''}}</view>

							<view>
								<button style="margin: 0;" type="default" size="mini" class="button"
									:class="auditStatusEnum.find(_item=>_item.value == item.auditStatus).class"
									@click="examinePrev(item)">{{auditStatusEnum.find(_item=>_item.value == item.auditStatus).label}}</button>
								<button style="margin-left: 10px;" type="default" size="mini"
									v-if="item.callbackStatus == 2 && item.noticeStatus == 3"
									@click="refundPrev(item)">退款</button>
							</view>
						</view>
					</view>
				</view>
			</scroll-view>
			<view v-if="listData.length==0"
				style="width: 100vw; height: 100%; display: flex;align-items: center;justify-content: center;">
				<image src="@/static/qx.png" style="width: 536rpx; height: 399rpx;"></image>
			</view>
		</view>
		<uni-popup ref="popup" @change="changePopup">
			<view class="examine-frame">
				<view>订单退款审核</view>
				<input class="uni-input" v-model="auditRemark" placeholder="审核备注" />
				<view>
					<view class="red" @click="examine(-1)">审核失败</view>
					<view class="blue" @click="examine(1)">审核成功</view>
				</view>
			</view>
		</uni-popup>

		<uni-popup ref="popupRefund" @change="changePopup">
			<view class="examine-frame">
				<view>退款</view>
				<input class="uni-input" v-model="refundRemark" placeholder="退款原因" />
				<view>
					<view class="white" @click="closeRefund">取消</view>
					<view class="blue" @click="refund">退款</view>
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	import orderList from '@/api/orderList'
	import serve from '@/api/orderList/refundReview.js'
	export default {
		data() {
			return {
				orderId: '',
				auditRemark: '',
				refundRemark: '',
				animation: null,
				animationData: null,
				listData: [],
				letfText: '订单号',
				seleindex: 0,
				candidate: ['订单号'],
				ejectOpen: false,
				seachValue: '',
				navigation: [{
					text: '全部',
					index: ''
				}, {
					text: '支付成功',
					index: 1
				}, {
					text: '退款中',
					index: 4
				}, {
					text: '已退款',
					index: 3
				}, {
					text: '退款失败',
					index: 5
				}],
				auditStatusEnum: [{
						value: '0',
						label: '待审核',
						class: 'orange'

					},
					{
						value: '1',
						label: '审核通过',
						class: 'green'
					},
					{
						value: '2',
						label: '待上游审核',
						class: 'orange'
					},
					{
						value: '-1',
						label: '审核失败',
						class: 'red'
					}
				],
				getData: {
					pageSize: 15,
					currentPage: 1,
					params: {
						orderSerialNumber: ''
					}
				},
			}
		},
		onShow() {
			this.getlist()
		},
		onLoad() {
			this.rotateFn()
		},
		methods: {
			changePopup(e) {
				if (!e.show) {
					this.orderId = this.auditRemark = this.refundRemark = ''
				}
			},
			examinePrev(item) {
				if (item.auditStatus !== 0) return
				this.orderId = item.id
				this.$refs.popup.open('center')
			},
			examine(auditStatus) {
				serve.refundReview({
					auditStatus,
					auditRemark: this.auditRemark,
					orderId: this.orderId
				}).then(res => {
					if (res.code === 20000) {
						uni.showToast({
							title: res.msg,
							icon: 'none',
						})
						this.$refs.popup.close()
						this.seachFn()
					}
				})
			},
			refundPrev(item) {
				this.orderId = item.id
				this.$refs.popupRefund.open('center')
			},
			refund() {
				if (!this.refundRemark) {
					uni.showToast({
						title: "请输入退款原因",
						icon: 'none'
					})
					return
				}
				serve.unifiedRefund({
					refundRemark: this.refundRemark,
					id: this.orderId
				}).then(res => {
					if (res.code === 20000) {
						uni.showToast({
							title: res.msg,
							icon: 'none',
						})
						this.$refs.popup.close()
						this.seachFn()
					}
				})
			},
			closeRefund() {
				this.$refs.popupRefund.close()
			},
			scrolltolower() {
				this.getData.currentPage += 1
				this.getlist()
			},
			option(e) {
				switch (e) {
					case 1:
						return {
							text: '支付成功',
								color: '#17A00E'
						}
						break;
					case 3:
						return {
							text: '已退款',
								color: '#999999'
						}
						break;
					case 4:
						return {
							text: '退款中',
								color: '#EBC153'
						}
						break;
					case 5:
						return {
							text: '退款失败',
								color: '#EC4645'
						}
						break;
				}
			},
			getlist(e) {
				this.getData.params.orderSerialNumber = this.seachValue
				serve.orderRefundReviewPage(this.getData).then(res => {
					if (res.code !== 20000) return
					if (!res.data.list.length) {
						uni.showToast({
							title: '没有数据了哦',
							icon: 'none'
						})
					}
					if (this.getData.currentPage !== 1) {
						this.listData = this.listData.concat(res.data.list);
						return
					}
					this.listData = res.data.list
				})
			},
			seleFn(item) {
				this.rotateFn()
				this.getData.currentPage = 1
				this.getData.params.orderStatus = item.index
				this.getlist()
			},

			seachFn() {
				this.getData.currentPage = 1

				this.getlist()
			},
			ejectFn(e) {
				this.letfText = e
			},
			rotateFn() {
				var animation = uni.createAnimation({
					duration: 1000,
					timingFunction: 'ease',
				})
				this.animation = animation
				this.animation.rotate(360).step()
				this.animationData = this.animation.export()
				setTimeout(() => {
					this.animationFns()
				}, 1000)
			},
			animationFns() {
				var animation = uni.createAnimation({
					duration: 0,
					timingFunction: 'ease',
				})
				this.animation = animation
				this.animation.rotate(0).step()
				this.animationData = this.animation.export()
			},
		}
	}
</script>

<style lang="scss">
	@import url("./index.css");

	::v-deep {
		.navigation_item {
			width: 140rpx !important;
		}
	}

	.button {
		&.green {
			background-color: #13ce66 !important;
			border-color: #13ce66 !important;
			color: #fff !important;
		}

		&.red {
			background-color: #ff4949 !important;
			border-color: #ff4949 !important;
			color: #fff !important;
		}

		&.orange {
			background-color: #ffba00 !important;
			border-color: #ffba00 !important;
			color: #fff !important;
		}
	}

	.examine-frame {
		background: #fff;
		width: 600rpx;
		height: 300rpx;
		border-radius: 15rpx;
		padding: 30rpx 50rpx;

		>input {
			padding-left: 10rpx;
			height: 60rpx;
			background: #33333320;
			border-radius: 5rpx;
		}

		>view {
			&:nth-of-type(1) {
				margin-bottom: 23rpx;
				font-size: 28rpx;
				text-align: center;
			}

			&:nth-of-type(2) {
				margin-top: 55rpx;
				text-align: right;

				>view {
					display: inline-block;
					width: 150rpx;
					height: 65rpx;
					line-height: 65rpx;
					color: #fff;
					font-size: 24rpx;
					text-align: center;
					background: pink;
					border-radius: 10rpx;

					&.red {
						background: #ff6d6d;
					}

					&.blue {
						background: #1890ff;
					}

					&.white {
						border: 1rpx solid #333;
						background: #fff;
						color: #333;
					}

					&:nth-of-type(2) {
						margin-left: 30rpx;

					}
				}
			}
		}

	}

	.icoon :active {
		color: #007AFF;
	}

	.yuan {
		width: 13rpx;
		height: 13rpx;
		background: #E9CF31;
		border-radius: 50%;
		margin-right: 5rpx;
	}

	.large_text {
		font-size: 32rpx;
		font-family: PingFang SC;
		font-weight: bold;
		color: #333333;
	}

	.company_msg_content {
		max-width: 330rpx;
		font-size: 28rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #333333;
		text-align: end;
	}

	.examine_popup_body {
		padding: 0 47rpx;
		margin: 33rpx 0;
	}

	.company_msg {
		display: flex;
		justify-content: space-between;
		align-items: baseline;
	}

	.bgtext {
		font-size: 28rpx;
		font-family: PingFang SC;
		font-weight: bold;
		color: #333333;

	}

	.item_price {
		font-size: 24rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #333333;
	}

	.text {
		font-size: 26rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #333333;
	}

	.samll_txext {
		font-size: 24rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #999999;
		display: flex;
		align-items: center;
	}

	.leftTip {
		position: absolute;
		top: 0;
		left: 0;
		height: 100%;
		background-color: #E9CF31;
		width: 10rpx;
	}

	.seach_input {
		background-color: #FFFFFF;
		border-radius: 12rpx;
		flex: 1;
	}

	.typeyuan {
		background-color: #17A00E;
		width: 14rpx;
		height: 14rpx;
		border-radius: 50px;
		margin-right: 6rpx;
	}

	.seletypeyuan {
		background-color: red;
		width: 14rpx;
		height: 14rpx;
		border-radius: 50px;
		margin-right: 6rpx;
	}

	.is-input-border {
		border: 0px !important;
	}

	page {
		background-color: #F0F2FF;
	}

	.form_body_item {
		min-height: 339rpx;
		background: #FFFFFF;
		box-shadow: 0px 3px 9px 0px rgba(88, 88, 88, 0.2);
		border-radius: 12rpx;
		font-size: 28rpx;
		display: flex;
		flex-direction: column;
		position: relative;
		overflow: hidden;
	}

	.form_body {
		width: 100vw;
		padding: 0 10px;
		margin-top: 40rpx;
		box-sizing: border-box;
	}

	.navigation_seleitem {
		width: 150rpx;
		height: 59rpx;
		background: #F0F2FF;
		border-top-left-radius: 11rpx;
		border-top-right-radius: 11rpx;
		font-size: 26rpx;
		color: #333333;
		display: flex;
		justify-content: center;
		align-items: center;
		transition: all 0.3s;
		position: relative;
		bottom: -2px;
	}

	.navigation_item {
		width: 150rpx;
		height: 59rpx;
		border-top-left-radius: 11rpx;
		border-top-right-radius: 11rpx;
		font-size: 26rpx;
		color: #F0F2FF;
		display: flex;
		justify-content: center;
		align-items: center;
		transition: all 0.3s;
		bottom: -2px;
	}

	.Navigation {
		display: flex;
		position: absolute;
		bottom: 0px;
		transition: all .5s;
	}

	.header_seach_butten {
		font-size: 24rpx !important;
		display: flex !important;
		align-items: center !important;
		margin: 0 !important;
		flex-shrink: 1;
		margin-left: 9rpx !important;
		background: #FFFFFF !important;
		justify-content: center;
	}

	.uni-easyinput__content {
		height: 80rpx;
	}

	.uni-easyinput {
		height: 80rpx;
	}

	.header_seach_seach {
		display: flex;
		height: 80rpx;
		margin-top: 23rpx;
	}

	.header_seach_title {
		display: flex;
		align-items: center;
	}

	.header_seach {
		font-size: 26rpx;
		padding: 0 10px;
	}

	.uni-navbar--border {
		border: 0px !important;
	}

	.uni-navbar__header-btns-right {
		padding-right: 0 !important;
		width: 120rpx !important;
	}

	.top {
		height: var(--status-bar-height);
	}
</style>
