<template>
	<view class="container">
		<uni-navbar title="车辆审批"></uni-navbar>
		<view class="box">
			<view class="reject-box commonBj commonMt">
				<view class="reject-box-top">
					<view class="top-left">
						<image src="../../static/images/car/yunshu.png" mode="widthFix"></image>
						<text class="listTitle">车辆信息</text>
					</view>

				</view>
				<view class="reject-box-bottom infoHeight">
					<view class="state-icon">
						<view class="flexAlignCenter">
							<view class="greenCircle">
							</view>
							<text class="itemText">企业名称:</text>
						</view>
						<view class="flexAlignCenter">
							<text class="infoText">{{carInfo.companyName}}</text>
						</view>
					</view>
					<!-- <view class="border-style"></view> -->
					<view class="state-icon">
						<view class="flexAlignCenter">
							<view class="greenCircle">
							</view>
							<text class="itemText">车牌号码:</text>
						</view>
						<view class="flexAlignCenter">
							<text class="infoText">{{carInfo.carNumber}}</text>
						</view>
					</view>
					<!-- <view class="border-style"></view> -->
					<view class="state-icon">
						<view class="flexAlignCenter">
							<view class="greenCircle">
							</view>
							<text class="itemText">车&emsp;&emsp;型:</text>
						</view>
						<view class="flexAlignCenter">
							<text class="infoText">{{carInfo.carType}}</text>
						</view>
					</view>
					<!-- <view class="border-style"></view> -->
					<view class="state-icon">
						<view class="flexAlignCenter">
							<view class="greenCircle">
							</view>
							<text class="itemText">车&emsp;&emsp;系:</text>
						</view>
						<view class="flexAlignCenter">
							<text class="infoText">{{carInfo.carSeries}}</text>
						</view>
					</view>
					<!-- <view class="border-style"></view> -->
					<view class="state-icon">
						<view class="flexAlignCenter">
							<view class="greenCircle">
							</view>
							<text class="itemText">载重标准:</text>
						</view>
						<view class="flexAlignCenter">
							<text class="infoText">{{carInfo.carCarry}}</text>
						</view>
					</view>
					<!-- <view class="border-style"></view> -->
					<view class="state-icon block">
						<view class="flexAlignCenter">
							<view class="greenCircle">
							</view>
							<text class="itemText">车辆行驶证件</text>
						</view>
						<view class="uploadBox flexAlignCenter block  mt30 ">
							<!-- <xfx-image-upload class="radius15" :remove="false" :add=false :chooseNum="1"
								v-model="drivingLicense" mediaType="image"></xfx-image-upload> -->
							<u--image radius="15rpx" :showLoading="true" :src="drivingLicense" width="599rpx"
								height="270rpx" @tap="previewImg(drivingLicense)">
							</u--image>
						</view>
					</view>
					<view class="state-icon mb0 block">
						<view class="flexAlignCenter">
							<view class="greenCircle">
							</view>
							<text class="itemText">车辆状态</text>
						</view>
						<view class="mt30 zhanwei">
							<view class="state-box-size border radius15 ">
								<xfx-image-upload class="state-box-size radius15" :max="1" :remove="false" :add="false"
									v-model="vedioList" mediaType="video"></xfx-image-upload>
							</view>
							<u--image class="border radius15" radius="15rpx" :key="index"
								v-for="(item,index) in imgList" :showLoading="true" :src="item.url" width="180rpx"
								height="180rpx" @tap="previewImg(item.url)">
							</u--image>
						</view>
					</view>
				</view>
			</view>
			<!-- 审批状态 -->
			<view class="reject-box mt28 commonBj">
				<view class="reject-box-top just-content-start bg-color-green">
					<image src="../../static/images/car/yunshu.png" mode="widthFix"></image>
					<text class="listTitle">审批状态</text>
				</view>
				<view class="reject-box-bottom pb0">
					<view class="state-icon">
						<view class="flexAlignCenter center">
							<view class="redCircle">
							</view>
							<text class="itemText mr46">审批状态:</text>
							<view class="normal" :class="auditType===1?'success':''" @tap="successClick">
								<image style="width: 33rpx;height: 33rpx;margin-right: 12rpx;"
									src="../../static/images/cityCar/state2.png" mode="widthFix"></image>
								<text>通过</text>
							</view>
							<view class="normal ml37" :class="auditType===-1?'fail':''" @tap="failClick">
								<image style="width: 33rpx;height: 33rpx;margin-right: 12rpx;"
									src="../../static/images/cityCar/state1.png" mode="widthFix"></image>
								<text>驳回</text>
							</view>
						</view>
					</view>
					<!-- <view :class="isPass?'border-style mb':'border-style2'"></view> -->
					<u--form v-if="auditType === -1" :model="form" ref="uForm" :rules="rules" labelWidth="0"
						class='formStyle formClass'>
						<u-form-item prop="auditContent">
							<view class="flexBox mb40">
								<view class="redCircle"></view>
								<text class="itemText">驳回原因</text>
							</view>
							<u--textarea confirmType="done" v-if="auditType === -1" class="textareaStyle"
								maxlength="255" height="198rpx" v-model="form.auditContent" placeholder="请输入驳回原因">
							</u--textarea>
						</u-form-item>
					</u--form>
					<!-- <view class="state-icon" v-if="auditType === -1">
						<view class="flexAlignCenter center">
							<view class="redCircle">
							</view>
							<text class="itemText">驳回原因:</text>
						</view>
					</view>
					<u--textarea confirmType="done" v-if="auditType === -1" class="textareaStyle" height="198rpx"
						v-model="auditContent" placeholder="请输入驳回原因">
					</u--textarea> -->
					<!-- <view v-if="!isPass" class="border-style2 mb"></view> -->
				</view>
			</view>
			<u-button @click="submit" class="custom-style mt33 commonMb" shape="circle"
				color="linear-gradient(to top, #F59A02, #FFD334)">确认审批</u-button>
		</view>
	</view>
</template>

<script>
	import {
		carDetail,
	} from "@/api/company/car.js"
	import {
		editState
	} from "@/api/city/car.js"
	export default {
		data() {
			return {
				rules: {
					auditContent: [{
						required: true,
						whitespace:true,
						message: '请输入驳回原因',
						trigger: ['blur', 'change']
					}, ],
				},
				// 驳回原因
				form: {
					auditContent: null,
				},
				// 通过样式开关
				auditType: 1,
				// 驳回样式开关
				isFail: false,
				// 详情数据列表
				carInfo: {},
				// 行驶证列表
				drivingLicense: '',
				// 视频列表
				vedioList: [],
				// 车辆状态图片列表
				imgList: [],
				// 接收的id
				id: null,
				srcVideo: '',
			}
		},
		methods: {
			async submit() {
				if (this.auditType === -1) {
					this.$refs.uForm.validate().then(async res => {
						if (res) {
							this.carInfo.auditType = this.auditType
							this.carInfo.auditContent = this.form.auditContent
							console.log(this.carInfo);
							const result = await editState(this.carInfo)
							console.log('提交', result);
							this.form.auditContent = null
							this.$tab.navigateBack()
						}
					})
				} else {
					this.carInfo.auditType = this.auditType
					this.carInfo.auditContent = this.form.auditContent
					console.log(this.carInfo);
					const result = await editState(this.carInfo)
					console.log('提交', result);
					this.form.auditContent = null
					this.$tab.navigateBack()
				}
			},
			// 切换按钮事件
			successClick() {
				if (this.auditType === 1) {
					return
				} else {
					this.auditType = 1
				}
			},
			failClick() {
				if (this.isFail === -1) {
					return
				} else {
					this.auditType = -1
				}
			},
			select() {
				uni.requireNativePlugin('TX-VideoTool').getVideoThumbnailImage({
					"videoPath": this.srcVideo,
					"saveImagePath": plus.io.convertLocalFileSystemURL(
						"_doc/TXVideoTool/"),
					"saveImageName": "testLocal" + new Date().getTime() + ".png",
					"second": 0
				}, result => {
					this.vedioList = [{
						cover: result.imagePath,
						url: this.srcVideo
					}]
				});
			},
			previewImg(urls) {
				uni.previewImage({
					urls: [urls],
					current: urls
				})
			},
			// previewImg(current) {
			// 	const urls = this.list.map(item => {
			// 		return item
			// 	})
			// 	uni.previewImage({
			// 		current,
			// 		urls
			// 	})
			// },
			// 获取详情
			getDetail() {
				carDetail(this.id).then((result) => {
					console.log(result);
					this.carInfo = result.data
					this.drivingLicense = result.data.drivingLicense[0].url;
					this.srcVideo = result.data.carVideo[0].url;
					this.imgList = result.data.imgList;
					this.vedioList = [{
						url: this.srcVideo
					}]
					this.select();
				}).catch(err => {
					console.log('请求失败rr');
				})
			},
		},
		onLoad: function(option) {
			if (option.id) {
				this.companyName = this.$store.state.user.companyName
				this.id = option.id
				this.auditContent = null
				this.getDetail()
			}
		},
	}
</script>

<style lang="scss" scoped>
	.mr46 {
		margin-right: 46rpx !important;
	}

	// 驳回表单样式
	.flexBox {
		display: flex;
		align-items: center;
	}

	.mb40 {
		margin-bottom: 40rpx;
	}

	.formClass {
		/deep/.u-form-item {
			margin-bottom: 56rpx;
		}

		/deep/.u-form-item__body {
			padding: 0;
		}

		/deep/.u-form-item__body__right__content__slot {
			display: block !important;
			// margin-bottom: 56rpx;
		}

	}

	// 审批状态按钮样式
	.normal {
		width: 170rpx;
		height: 58rpx;
		background: rgba(126, 142, 193, 0.6);
		border-radius: 36rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		font-size: 28rpx;
		font-weight: bold;
		color: #FFFFFF;
	}

	.success {
		background: linear-gradient(90deg, #3FC377 0%, #83D992 100%);
		box-shadow: 0px 2rpx 13rpx 0px rgba(27, 43, 95, 0.25);
	}

	.fail {
		background: linear-gradient(90deg, #FF2D04 0%, #FFA53E 100%);
		box-shadow: 0px 2rpx 13rpx 0px rgba(27, 43, 95, 0.25);
	}

	.ml37 {
		margin-left: 37rpx;
	}

	.center {
		justify-content: center;
		align-items: center;
	}

	.textareaStyle {
		background: rgba(255, 255, 255, 0.1);
		border: 2rpx solid #495B93 !important;
		border-radius: 15rpx;

		/deep/ .input-placeholder {
			color: #7E8EC1 !important;
			font-size: 26rpx;
		}
	}

	// 上传组件样式
	.uploadBox {

		// width: 599rpx;
		// height: 250rpx;
		// /deep/ .u-image__loading{
		// 	width: 100%;
		// 	height: 250rpx;
		// }
		/deep/ .u-image {
			border: 1rpx solid #495B93;
		}
	}

	/deep/.xfx-image-upload-Item {
		uni-image {
			width: 180rpx;
			height: 180rpx;
		}

		.xfx-image-upload-Item-video-fixed {
			width: 180rpx;
			height: 180rpx;
		}
	}

	.zhanwei {
		display: flex;
	}

	.zhanwei uni-view:not(:first-child) {
		width: 180rpx !important;
	}

	.zhanwei uni-view:not(:last-child) {
		margin-right: 29rpx;
	}

	.reject-box {

		.reject-box-top {
			width: 100%;
			height: 69rpx;
			background: #7FB5FF;
			border-radius: 26rpx 26rpx 0px 0px;
			display: flex;
			justify-content: space-between;

			.top-right {
				display: flex;
				justify-content: start;
				align-items: center;
				margin-right: 36rpx;

				uni-image {
					width: 28rpx;
					margin-left: 32rpx;
					vertical-align: middle;
				}

				.state-text {

					margin-left: 13rpx;
					line-height: 69rpx;
				}
			}

			uni-image {
				width: 50rpx;
				margin-left: 32rpx;
				vertical-align: middle;
			}
		}

		.reject-box-bottom {
			padding: 40rpx;

			.state-icon {
				display: flex;
				margin: 40rpx 0;
			}

			.state-icon:nth-child(1) {
				margin: 0 0 40rpx;
			}

			.border-style {
				border-top: 1rpx dashed #F98803;
				width: 90%;
				margin: 0 auto;
			}

			.border-style2 {
				border-top: 1rpx dashed #FB5637;
				width: 90%;
				margin: 0 auto;
			}
		}
	}

	.reject-box-bottom:nth-child(2) {
		padding: 40rpx 40rx 20rpx !important;
	}

	.block {
		display: block !important;
	}

	.border {
		border: 1rpx solid #495B93;
	}

	.box-size {
		width: 598rpx;
		height: 198rpx;
	}

	.mt30 {
		margin-top: 30rpx;
	}

	.radius15 {
		border-radius: 15rpx;
	}

	.state-box-size {
		width: 180rpx;
		height: 180rpx;
	}

	.state-box-size-video {
		width: 175rpx !important;
		height: 175rpx !important;
	}

	.space-between {
		justify-content: space-between;
	}

	.just-content-start {
		justify-content: flex-start !important;
		align-items: center;
	}

	.bg-color-green {
		background: #7FB5FF !important;
	}

	.bg-color-red {
		background: #FB5637 !important;
	}

	.fontTongGuo {
		font-size: 28rpx !important;
		font-weight: bold !important;
		color: #007C3C !important;
	}

	.mb {
		margin-bottom: 53rpx !important;
	}

	.pb0 {
		padding-bottom: 0 !important;
	}

	.mt28 {
		margin-top: 28rpx;
	}

	.mb0 {
		margin-bottom: 0rpx !important;
	}
</style>
