<template>
	<view class="lists">
		<view class="status_bar" :style="navHeight"></view>
		<!-- 	<view class="header-bg">
			<image class="header-bg-img" src="@/static/image/nav_bg@3x.png" mode="scaleToFill"></image>
		</view> -->
		<view class="main" :style="mainHeight">

			<view class="scroll-item">
				<view class="top">
					<text class="title-no">{{detail.id}}</text>
					<view class="title-info">
						<text class="order-date">{{detail.createDate}}</text>
						<text class="item-block-btn__text">{{detail.statusName}}</text>
					</view>
				</view>
				<view class="middle view">
					<view class="middle-title">
						<text class="middle-title__text">处罚说明：{{detail.notes}}</text>
					</view>
					<view class="text-block-box" v-for="(item2,index2) in detail.punishEntries" :key="index2">
						<view class="text-block">
							<text class="middle-date">类型</text>
							<text class="middle-date-des">{{item2.punishTypeName}}</text>
						</view>
						<view class="text-block" v-if="item2.terminalName">
							<text class="middle-date">终端名称</text>
							<text class="middle-date-des">{{item2.terminalName}}</text>
						</view>
						<view class="text-block">
							<text class="middle-date">截止时间</text>
							<text class="middle-date-des">{{item2.punishEndTime}}</text>
						</view>
					</view>
					<view v-if="detail.status!=='CONFIRMED'" class="text-block text-block-last">
						<text class="middle-date">有无异议</text>
						<text class="middle-date-des">{{detail.appealNotes=='1'?'有异议':'无异议'}}</text>
					</view>
					<view v-else class="text-block picker-row">
						<text class="middle-date">有无异议</text>
						<view class="middle-date-des uni-list picker-year">
							<view class="uni-list-cell">
								<view class="uni-list-cell-db">
									<picker class="picker-block" @change="appealNotesChange" mode="selector"
										range-key='name' :value="condition.appealNotes" :range="appealNotesPicker">
										<text
											class="uni-input-text">{{ appealNotesPicker[appealNotesIndex].name}}</text>
									</picker>
								</view>
							</view>
							<image class="icon-arrow" src="@/static/image/arrow_r@3x.png" mode="aspectFit"></image>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="bottom-area"></view>
		<view class="bottom">
			<button class="btn" type="default" @tap="submit" v-if="condition.type==='edit'">
				<text class="btn-text">提交</text>
			</button>
		</view>
	</view>
</template>

<script>
	import {
		mapState
	} from 'vuex'

	import {
		apiGetProcessOrderDetail,
		apiGetProcessOrderAppeal
	} from '@/servers/breakwords.js'


	export default {
		data() {
			return {
				loadingText: '加载中...',
				condition: {
					id: '',
					appealNotes: '0',
				},
				detail: {},
				appealNotesPicker: [{
						'code': '0',
						'name': '无异议'
					},
					{
						'code': '1',
						'name': '有异议'
					}
				],
				appealNotesIndex: 0,
			}
		},
		computed: {
			...mapState(['sysinfo', 'userInfo']),
			navHeight() {
				return {
					'height': `${this.sysinfo.safeArea.top + 44}px`
				}
			},
			mainHeight() {
				return {
					'height': `${this.sysinfo.safeArea.height - 44 }px`,
				}
			},
		},
		onLoad(option) {
			console.log('breakwords-handle-detail', option)
			if (option && option.id) {
				this.condition.id = option.id
				this.condition.type = option.type
				this.getOrderDetail()
			}
		},
		methods: {
			async getOrderDetail() {
				uni.showLoading({
					title: '加载中'
				});
				setTimeout(function() {
					uni.hideLoading();
				}, 2000);
				const res = await apiGetProcessOrderDetail(this.condition)
				uni.hideLoading();

				this.detail = res.data
			},
			async submit() {
				const params = {
					'createUserId': this.userInfo.code,
					'createUserName': this.userInfo.name,
					'id': this.condition.id,
					'appealNotes': this.condition.appealNotes,
				}
				uni.showLoading({
					title: '加载中'
				});
				setTimeout(function() {
					uni.hideLoading();
				}, 2000);
				const res = await apiGetProcessOrderAppeal(params)
				uni.hideLoading();
				uni.navigateBack()
			},
			appealNotesChange(e) {
				console.log('picker发送选择改变，携带值为', e.detail.value)
				this.appealNotesIndex = e.detail.value
				this.condition.appealNotes = this.appealNotesPicker[e.detail.value].code
			},
		},
	}
</script>

<style lang="scss" scoped>
	.view {
		flex-direction: column;
	}

	.header-bg {
		height: 284rpx;
		margin-top: -88rpx;
	}

	.header-bg-img {
		width: 750rpx;
	}

	.status_bar {
		background-color: #fff;
	}

	.lists {
		position: relative;
		flex-direction: column;
		background: #f0f4f5;
		flex: 1;
	}

	.main {
		position: relative;
		flex-direction: column;
		// margin-top: -164rpx;
		padding-top: 40rpx;
		padding: 0 16rpx;
	}

	.scroll-item {
		position: relative;
		display: flex;
		flex-direction: column;
		flex: 1;
		background: #ffffff;
		border-radius: 12px;
		margin-top: 28rpx;
		padding-top: 30rpx;
	}

	.top {
		height: 72rpx;
		align-items: center;
		justify-content: space-between;
		padding: 0 48rpx;
		border-bottom: 1px solid #f4f5f6;
	}

	.title-no {
		font-size: 24rpx;
		color: #555555;
	}

	.title-info {
		align-items: center;
	}

	.order-date {
		color: #333;
		font-size: 24rpx;
		margin-right: 16px;
	}

	.item-block-btn__text {
		font-size: 12px;
		color: #FF1D32;
	}

	.title-info__status-fail__text {
		color: #888888;
	}

	.middle {
		position: relative;
		padding: 26rpx 48rpx 40rpx;
	}

	.middle-title {
		display: flex;
		align-items: center;
		margin-bottom: 32rpx;
	}

	.middle-title__text {
		font-size: 24rpx;
		color: $text-base-color;
		font-family: PingFangSC, PingFangSC-Medium;
	}

	.text-block {
		flex: 1;
		justify-content: space-between;
		align-items: center;
		margin-bottom: 12rpx;
	}

	.text-block-last {
		margin-bottom: 0;
		margin-top: 60rpx;
	}

	.picker-row {
		height: 96rpx;
	}

	.middle-date {
		flex: 3;
		font-size: 24rpx;
		color: #999;
		margin-right: 16rpx;
	}

	.middle-date-des {
		font-size: 28rpx;
		color: $text-base-color;
	}

	.picker-year {
		flex: 5.5;
		position: relative;
		align-items: center;
		height: 96rpx;
		line-height: 96rpx;
		text-align: center;
	}

	.uni-list-cell {
		flex: 1;
		padding-right: 52rpx;
	}

	.uni-list-cell-db {
		flex: 1;
	}

	.picker-block {
		flex: 1;
	}

	.uni-input-text {
		font-size: 24rpx;
	}

	.icon-arrow {
		position: absolute;
		right: 22rpx;
		top: 40rpx;
		width: 7px;
		height: 10px;
		z-index: 10;
	}

	.text-block-box {
		display: flex;
		flex-direction: column;
		border-bottom: 1px solid #F4F5F6;
		margin-bottom: 30rpx;
	}

	.middle-date-right {
		display: flex;
		align-items: center;
		justify-content: flex-end;
		text-align: right;
	}

	.bottom-area {
		height: 140rpx;
		margin-top: 12rpx;
	}

	.bottom {
		position: fixed;
		bottom: 0;
		left: 0;
		z-index: 10;
		width: 750rpx;
		height: 140rpx;
		padding: 0 32rpx;
		background-color: #fff;
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.btn {
		flex: 1;
		height: 92rpx;
		background: $wly-primary-color;
		border-radius: 46rpx;
	}

	.btn-text {
		color: #fff;
		font-size: 34rpx;
	}
</style>
