<template>
	<view class="">
		<view class="date" v-if="dataList.type !=2">
			<!-- 2022年12月12日提出申请 -->
			{{dataList.create_time}} 提出申请

		</view>
		<view class="date" v-else>
			<!-- 2022年12月12日提出申请 -->
			{{dataList.create_time}} 提出解除申请

		</view>
		<!-- 公司信息 -->
		<view class="cards">
			<view class="cards_head">
				<view class="cards_head_top">
					<text><u--image src="../../static/img/company/company.png" width="33.29rpx" height="33.29rpx"
							style="margin-right:20rpx"></u--image></text>
					<text>{{dataList.company_b_name}}</text>
				</view>
				<text @click="navTo(`/subpkg/companySign/companySign?id=${dataList.company_b_id}`)">详情 <uni-icons
						type="forward" style="margin-left: 10rpx;" color="white"></uni-icons></text>
			</view>
			<view class="cards_content">
				<view class="right">
					<view class="is_contract">
						<view>
							<text>法人姓名 :</text>
							<text>{{dataList.company_b_user}}</text>
						</view>
						<view>
							<text style="color: green;" v-if="true">已签约</text>
						</view>
					</view>
					<view class="" @click="copyPhone()">
						<text>联系电话 :</text>
						<text>{{dataList.company_b_phone}}</text>
					</view>

				</view>
			</view>
		</view>

		<!-- 车辆列表 -->
		<view class="car_info" v-if="dataList.type==1">
			<view class="car_type">
				<text>自有车辆</text>
			</view>
			<view class="car_li">
				车牌号：{{dataList.cars_info}}
				<view class="" style="float: right;display: flex;">
					<text style="margin-right: 10rpx;">自有车辆</text>
					<u-radio-group v-model="dataList.cars_info">
						<u-radio active-color="#0122C7" shape="square" :name="dataList.cars_info" label=""></u-radio>
					</u-radio-group>
				</view>
			</view>
		</view>
		<view class="car_info" v-if="dataList.type==0">
			<view class="car_type">
				<text v-if="true">租赁车辆</text>
				<text v-else>自有车辆</text>
			</view>
			<view class="car_li" v-for="item,index in carList">
				车牌号：{{item.car_license}}
				<view class="" style="float: right;display: flex;">
					<text style="margin-right: 10rpx;">租赁车辆</text>
					<u-checkbox-group v-model="checked">
						<u-checkbox active-color="#0122C7" :label="id" :name="item" shape="square"
							label=""></u-checkbox>
					</u-checkbox-group>
				</view>
			</view>
		</view>
		<!-- 合同 -->
		<view class="card" v-if="dataList.type==2">
			<view class="contract">
				<view class="left">
					<u--image :showLoading="true" src="../../static/img/contract/pdf.png" width="80px"
						height="80px"></u--image>
					<view class="text">
						<view class="name">《解除合同》</view>
						<view>
							<text>{{dataList.create_time}}</text>
						</view>
					</view>
				</view>
				<!-- <view class="right" @click="navToContract(dataList.file)"> -->
				<view class="right">
					<uni-icons type="paperclip" color="#3274F9"></uni-icons>
					<view @click="navToContract(dataList.old_file)">查看</view>
				</view>
			</view>
		</view>

		<!-- 车辆信息为空 -->
		<u-empty v-if="flag1" text="你还没有车辆哦，快去向平台申请用车吧" icon="../../static/img/empty/data.png"> </u-empty>
		<!-- 按钮 -->
		<view class="btns">
			<!-- 生成合同 -->
			<view class="" v-if="dataList.status==-1">
				<u-button type="primary" @click="showPop=true" style="margin-bottom: 20rpx;width: 100%;" color="#FF7C32"
					text="申请驳回"></u-button>
				<u-button :disabled="flag1" type="primary" text="生成合同" @tap="contractFn" color="#0122C7"></u-button>
			</view>
			<!-- 审核中 -->
			<view class="" v-if="dataList.status==0">
				<u-button :disabled="true" type="primary" text="合同已上传,等待审核" color="grey"></u-button>
			</view>
			<!-- 审核通过 -->
			<view class="" v-if="dataList.status==1||dataList.status==2">
				<!-- <view class="" v-if="true"> -->
				<view class="card">
					<view class="contract">
						<view class="left">
							<u--image :showLoading="true" src="../../static/img/contract/pdf.png" width="80px"
								height="80px"></u--image>
							<view class="text">
								<view class="name">{{typeFn( dataList.type)  }}
								</view>
								<view>
									<text>{{'2023-03-03'}}</text>
								</view>
							</view>
						</view>
						<!-- <view class="right" @click="navToContract(dataList.file)"> -->
						<view class="right">
							<uni-icons type="paperclip" color="#3274F9"></uni-icons>
							<view @click="navToContract(dataList.file)">查看</view>
						</view>
					</view>
				</view>
				<u-button v-if="dataList.status==1" :disabled="false" type="primary" text="发送合同" @tap="sendFn"
					color="#0122C7"></u-button>
				<u-button v-else :disabled="times" type="primary" :text="`重新发送${times?times+'s':''}`" @tap="sendAgainFn"
					color="#0122C7"></u-button>
			</view>
		</view>
		<!--uview 组件 -->
		<view class="">
			<u-modal :show="showPop" @close="showPop=false" @confirm="confirm" :closeOnClickOverlay="true"
				title="请输入驳回理由">
				<view class="slot-content">
					<u--textarea v-model="overruleValue" placeholder="请输入内容" class="textarea_cls"></u--textarea>
				</view>
			</u-modal>
		</view>
	</view>
</template>

<script>
	import {
		getAgencyDetailApi,
		contractApi,
		overruleApi,
		sendcontractApi,
		sendMsgApi
	} from "@/api/property.js"
	import {
		download_file
	} from "@/api/junziqian.js"
	import {
		Toast
	} from "../../libs/uniApi"
	export default {
		data() {
			return {
				flag1: true,
				times: 0,
				dataList: {},
				overruleValue: "",
				showPop: false,
				checked: [],
				carList: [],
				flag: true,
				lg: false,
			}
		},
		onLoad(options) {
			getAgencyDetailApi({
				id: options.id
			}).then(res => {
				// 13043214321
				this.dataList = res.data.vehicleContract
				this.carList = res.data.vehicleRentCars
				this.dataList.cars_info ? this.dataList.cars_info = JSON.parse(this.dataList.cars_info).license :
					""
				if (this.dataList.status == 3) {
					uni.navigateBack()
				}
				if (this.carList.length > 0 || this.dataList.cars_info) {
					console.log(this.dataList.cars_info)
					this.flag1 = false
				}
				// console.log(this.dataList)
			})
			// console.log(this.dataList.cars_info)


		},
		methods: {
			sendAgainFn() {
				let that = this
				sendMsgApi({
					id: this.dataList.id,
				}).then(res => {
					Toast("发送成功")
					that.times = 10
					that.timer()
					// that.num = 10
				})
			},
			sendFn() {
				let that = this
				sendcontractApi({
					id: this.dataList.id
				}).then(res => {
					Toast("操作成功")
					that.times = 10
					that.timer()
					that.dataList.status = 2
				})
			},
			typeFn(status) {
				if (status == 0) {
					return "租赁合同"
				}
				if (status == 1) {
					return "自有车两"
				}
				if (status == 2) {
					"解除合同"
				}
			},
			confirm() {
				// console.log(this.overruleValue)
				overruleApi({
					id: this.dataList.id,
					content: this.overruleValue,
				}).then(res => {
					this.showPop = false
					Toast("操作成功")
					setTimeout(() => {
						uni.navigateBack()
					}, 2000)
				})
			},
			timer() {
				let that = this
				let timers = setInterval(() => {
					that.times--
					if (that.times <= 0) {
						clearInterval(timers)
					}
				}, 1000)

			},
			navToContract(contract_no) {
				uni.navigateTo({
					url: `/subpkg/pdfView/pdfView?url=${contract_no}`
				})

			},
			contractFn() {
				console.log(this.checked)
				contractApi({
					id: this.dataList.id,
					car_id: this.checked[0]?.car_id ? this.checked[0].car_id : ""
				}).then(res => {
					this.navTo('/subpkg/property/success')
				})
				// this.navTo('/subpkg/property/success')
			},
			// sendcontractFn() {

			// 	// this.sendFn()
			// 	Toast("操作成功")
			// 	this.times = 10
			// 	this.timer()

			// },
			navTo(url) {
				uni.navigateTo({
					url
				})
			}
		}

	}
</script>

<style lang="scss" scoped>
	.date {
		padding: 10rpx 28rpx 0;
	}

	.card {
		background-color: white;
		border-radius: 14rpx;
		padding: 20rpx;

		.contract {
			display: flex;
			justify-content: space-between;

			.left {
				display: flex;
				align-items: center;

				.text {
					// background-color: red;
					height: 80px;
					display: flex;
					flex-direction: column;
					justify-content: space-around;
					margin-left: 15rpx;
				}
			}

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


	}



	.cards {
		margin: 28rpx;
		width: 694rpx;
		background: #ffffff;
		border-radius: 30rpx;
		overflow: hidden;


		.cards_head {
			padding: 28rpx;
			background-color: $theme-oa-color;
			color: white;

			display: flex;
			justify-content: space-between;

			.cards_head_top {
				display: flex;
				width: 70vw;
			}
		}

		.cards_content {
			padding: 28rpx;
			display: flex;
			justify-content: space-between;

			.left {
				text-align: center;
				// padding: 15rpx 25rpx;
				padding-top: 20rpx;

				width: 160rpx;
				background-color: $theme-oa-color;
				color: white;
				border-radius: 40rpx;

				.cir {
					width: 120rpx;
					height: 120rpx;
					background-color: #ffffff;
					margin-left: 25rpx;
					border-radius: 120rpx;
					position: relative;
				}
			}

			.right {
				display: flex;
				flex-direction: column;
				justify-content: space-between;

				.is_contract {
					width: 85vw;
					display: flex;
					justify-content: space-between;
					height: 40rpx;
				}

				view {
					margin-bottom: 10rpx;

					text:nth-child(2) {
						margin-left: 20rpx;
					}
				}
			}
		}

		.u_avatar {
			position: absolute;
			top: 50%;
			left: 50%;

			transform: translate(-50%, -50%);
		}
	}

	.car_info {
		padding: 10rpx 28rpx 0;

		.car_type {
			margin-bottom: 20rpx;
		}

		.car_li {
			background-color: white;
			margin-bottom: 17.54rpx;
			padding: 20rpx;
			border-radius: 10rpx;
		}
	}

	.btns {
		position: fixed;
		bottom: 5rpx;
		width: 100%;
		padding: 10rpx 28rpx 0;
	}

	.textarea_cls {
		width: 70vw;
		border: 1px solid #DADBDE;
	}
</style>