<template>
	<view>
		<form @submit="formSubmit">
			<view class='personal-data' :style="colorStyle">
				<view class='list'>
					<view class='item acea-row row-between-wrapper'>
						<view>{{$t(`创建时间`)}}</view>
						<view class='input'>
							{{carDateil.add_time}}
						</view>
					</view>
					<view class='item acea-row row-between-wrapper'>
						<view>{{$t(`类型`)}}</view>
						<view class='input' v-if="carDateil.car_lease==1">
							以租代购
						</view>
						<view class='input' v-if="carDateil.car_lease==0">
							月租
						</view>
					</view>
					<view class='item acea-row row-between-wrapper' v-if="carDateil.car_lease==1">
						<view>{{$t(`总月份`)}}</view>
						<view class='input'>
							{{carDateil.several_months}}
						</view>
					</view>
					<view class='item acea-row row-between-wrapper' v-if="carDateil.car_lease==1">
						<view>{{$t(`已付月份`)}}</view>
						<view class='input'>
							{{carDateil.months}}
						</view>
					</view>
					<view class='item acea-row row-between-wrapper'>
						<view>{{$t(`月租`)}}</view>
						<view class='input'>
							{{carDateil.pay_price}}
						</view>
					</view>
					<view class='item acea-row row-between-wrapper'>
						<view>{{$t(`绑定人`)}}</view>
						<view class='input'>
							{{carDateil.real_name}}
						</view>
					</view>
					<view class='item acea-row row-between-wrapper'>
						<view>绑定车辆编号</view>
						<view class='input acea-row row-between-wrapper' @click="carDateil.machine_no?'':bind()">
							{{carDateil.machine_no?carDateil.machine_no:'未绑定'}}
						</view>
					</view>
				</view>
			</view>
		</form>
		<view class="monthslist" v-for="(item,ind) in carDateil.info">
			<view class="item acea-row row-between-wrapper row-middle">
				<view class="title">
					<view class="info">
						支付第{{item.months}}月租金
					</view>
					<view class="time">
						{{item.pay_time}}
					</view>
				</view>
				<view class="right">
					<view class="money">
						{{item.pay_price}}
					</view>
					<block v-if="item.paid!=0">
						<view class="peytype" v-if="item.pay_type=='yue'">
							余额支付
						</view>
						<view class="peytype" v-if="item.pay_type=='alipay'">
							支付宝支付
						</view>
						<view class="peytype" v-if="item.pay_type=='weixin'">
							微信支付
						</view>
					</block>
					<view v-else class="peytype">
						未支付
					</view>
				</view>
			</view>

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

<script>
	import {
		toLogin
	} from '@/libs/login.js';
	import {
		getRentOrderDteail,
		rentSetcar
	} from '@/api/rent.js';
	import {
		mapGetters
	} from "vuex";
	import colors from '@/mixins/color.js';
	export default {
		mixins: [colors],
		data() {
			return {
				id: '',
				carDateil: {
					machine_no: '',
				}

			};
		},
		computed: mapGetters(['isLogin']),
		watch: {
			isLogin: {
				handler: function(newV, oldV) {
					if (newV) {
						this.getRentOrderDteail();
					}
				},
				deep: true
			}
		},
		onLoad(options) {
			this.id = options.id
			if (this.isLogin) {
				this.getRentOrderDteail();
			} else {
				toLogin();
			}
		},
		methods: {
			// #ifndef APP-PLUS
			// 打开二维码
			openQr() {
				const that = this;
				uni.scanCode({
					onlyFromCamera: true,
					scanType: ['barCode', 'qrCode', 'datamatrix', 'pdf417'],
					success(res) {
						that.carDateil.machine_no = res.result;
					}
				})
			},
			// #endif

			bind() {
				const that = this;
				// #ifndef H5
				uni.showModal({
					title: '提示',
					content: '请选择绑定方式',
					showCancel: false,
					cancelText: '扫码',
					confirmText: '手填',
					success: res => {
						if (res.confirm) {
							that.bindImport(that.id)
						}
						if (res.cancel) {
							that.bindQr(that.id)
						}
					},
					fail: () => {},
					complete: () => {}
				});
				// #endif
				// #ifdef H5
				that.bindImport(that.id)
				// #endif

			},
			// 手输
			bindImport(id) {
				const that = this;
				uni.showModal({
					title: '绑定车辆',
					placeholderText: '请输入车辆编号',
					editable: true,
					cancelText: '取消',
					confirmText: '确定',
					success: res => {
						if (res.confirm) {
							if (res.content) {
								that.rentSetcar(res.content, id)
							} else {
								uni.showToast({
									title: '请输入车辆编号',
									icon: 'error'
								})
								that.bindImport(id)
							}
						}
					},
					fail: () => {},
					complete: () => {}
				});
			},
			// 扫码绑定
			bindQr(id) {
				uni.scanCode({
					onlyFromCamera: true,
					scanType: ['barCode', 'qrCode', 'datamatrix', 'pdf417'],
					success(res) {
						that.rentSetcar(res.result, id)
					}
				})
			},
			// 提交绑定
			rentSetcar(content, id) {
				rentSetcar({
					id,
					machine_no: content
				}).then((res) => {
					uni.showToast({
						title:res.msg,
					})
				}).catch((res) => {
					uni.showToast({
						title:res,
						icon:'error'
					})
					console.log(res);
				})
			},
			// 查询车辆详情
			getRentOrderDteail() {
				getRentOrderDteail(this.id).then((res) => {
					console.log(res, 'fh');
					this.carDateil = res.data;
				}).catch((res) => {
					console.log(res);
				})
			},
		}
	}
</script>

<style scoped lang="scss">
	.personal-data .list {
		/* #ifndef H5 */
		margin-top: 15rpx;
		/* #endif */
		background-color: #fff;

		.item {
			padding: 30rpx 30rpx 30rpx 0;
			border-bottom: 1rpx solid #f2f2f2;
			margin-left: 30rpx;
			font-size: 28rpx;
			color: #282828;

			.input {
				max-width: 400rpx;
				text-align: right;
				color: #868686;

				.icon-suozi {
					margin-left: 10rpx;
				}

				.id {
					// width: 180rpx;
				}

				.iconfont {
					font-size: 24rpx;
				}
			}
		}
	}

	.monthslist {
		background-color: #FFF;
		border-radius: 10rpx;
		margin: 20rpx 20rpx 0rpx 20rpx;
		padding: 20rpx;

		.time,
		.peytype {
			font-size: 24rpx;
			color: #999;
		}

		.info {
			color: var(--view-theme);
		}

		.right {
			text-align: right;
			.money {
				color: var(--view-theme);
			}
		}
	}
</style>
