<template>
	<view class="container-view">
		<view class="select-time-view">
			<view class="flex-row">选择取车时间</view>
			<view @tap="tapSelectTime" class="flex-row align-center">
				<text class="select-time-text">12-01 10:30</text>
				<img style="width: 28rpx;height: 28rpx;" src="https://qiniu.bms16.com/FpbKGisSPfL9r8a7QkZCYXolhu1Y" alt="">
			</view>
		</view>
		<view class="car-info-view">
			<view class="flex-row align-center">
				<img style="width: 160rpx;height: 160rpx;border-radius: 16rpx;" src="https://qiniu.bms16.com/FrwDlFZdSMiBgqnqDjB19PiDUmuu" alt="">
				<view class="flex-row car-info-grow">
					<view class="flex-row align-center">
						<view class="car-name">智能电动摩托车智驾</view>
						<img style="width: 28rpx;height: 28rpx;" src="https://qiniu.bms16.com/FpbKGisSPfL9r8a7QkZCYXolhu1Y" alt="">
					</view>
					<view class="car-information">月租 月租 共计60 天</view>
					<allPrice :amount="65"></allPrice>
				</view>
			</view>
			<view class="config-list-view">
				<view :class="service_list.length>4?'config-list-view-1 flex-row':'flex-row'">
					<view class="service_name-tab" v-for=" (item,indexs) in service_list" :key="indexs">
						{{item.service_name}}
					</view>
				</view>
			</view>
		</view>
		
		<view  class="deposit-info">
			<view class="deposit-info-title flex-row flex-between">
				<text>车辆押金</text>
				<text>$100</text>
			</view>
			<view class="deposit-info-text">需要支付100元押金，诺无车损、违章及逾期，还车后可退</view>
		</view>

		<view class="method-info">
			<view class="flex-row flex-between" style="margin-bottom: 40rpx;">
				<view class="font_32">前往门店取还</view>
				<view class="font_32">门店距您 <text class="distance-num">100m</text></view>
			</view>
			<view @tap="bindToNav" class="shop-bg flex-row flex-between">
				<view class="shop-name-view">
					<!-- <view class="shop-name">{{shopInfo.shop_name}}</view>
					<view class="shop-address">{{shopInfo.address}}</view> -->
					<view class="shop-name">这里是一个门店的名称</view>
					<view class="shop-address">南山区西丽留仙洞留仙村路南山区西丽留仙…</view>
				</view>
				<view class="nav-btn flex-row">
					<img style="width: 48rpx;height: 48rpx;" src="https://zxappfile.bms16.com/zx_admin/cab_nav.png"
						alt="">
					<view style="margin-top: 12rpx;font-size: 24rpx;">导航</view>
				</view>
			</view>
		</view>

	

		<view style="height: 224rpx;"></view>
		<view v-if="!isShowDetail" class="payment-info">
			<view class="payment-bottom flex-row flex-between">
				<view class="bottom-left flex-row">
					<allPrice :amount="amount"></allPrice>
					<view @tap="bindDetail" class="all-money">明细<img
							src="https://qiniu.bms16.com/Fvl1d-AWRvwY_ehNrw7bMZOK6LBZ" /></view>
				</view>
				<view @tap="navToPage">{{is_freeze==0?'立即支付':'支付·授权免押'}}</view>
			</view>
		</view>
		<view v-else class="show-detail">
			<view class="detail-info">
				<view class="pay-money">
					<view class="flex-row flex-between" style="margin-bottom: 46rpx;">
						<view>价格明细</view>
						<view>
							<image style="width: 32rpx;height: 32rpx;" @tap="isShowDetail = false"
								src="https://qiniu.bms16.com/FtoTEHOJiUf_gjPCJGGHMsAtHI5M" />
						</view>
					</view>
					<view class="flex-row flex-between" style="margin-bottom: 44rpx;">
						<view>车辆租金</view>
						<view>
							<!-- ￥{{(leaseTime * price_list[0].hire_price) /100}} -->
							￥{{(price/100)+'x'+count}}
							<text v-if="isSelectStatus==4">时</text>
							<text v-if="isSelectStatus==1">天</text>
							<text v-if="isSelectStatus==6">周</text>
							<text v-if="isSelectStatus==2">月</text>
							<text v-if="isSelectStatus==7">季</text>
						</view>
					</view>
					<view v-if="freeze_is_open==0||(freeze_is_open==1&&is_freeze==0)" class="flex-row flex-between"
						:style="insurance_setting!=null&&insurance_setting.price-0!=0?'margin-bottom: 44rpx;':''">
						<view>车辆押金</view>
						<view>￥{{modelInfo.deposit /100}}</view>
					</view>
					<view v-if="insurance_setting!=null&&insurance_setting.price-0!=0" class="flex-row flex-between"
						style="margin-bottom: 44rpx;">
						<view>骑行保障服务</view>
						<view v-if="isSelectStatus==4">{{'￥'+tools.toFix(insurance_setting.price / 100)+'x1天'}}</view>
						<view v-if="isSelectStatus==1">{{'￥'+tools.toFix(insurance_setting.price / 100)+'x'+count+'天'}}
						</view>
						<view v-if="isSelectStatus==6">
							{{'￥'+tools.toFix(insurance_setting.price / 100)+'x'+count*7+'天'}}
						</view>
						<view v-if="isSelectStatus==2">
							{{'￥'+tools.toFix(insurance_setting.price / 100)+'x'+count*30+'天'}}
						</view>
						<view v-if="isSelectStatus==7">
							{{'￥'+tools.toFix(insurance_setting.price / 100)+'x'+count*90+'天'}}
						</view>
					</view>
					<view class="detail-money flex-row" style="padding-bottom: 44rpx;">
						<view>支付金额</view>
						<allPrice :amount="amount"></allPrice>
					</view>
				</view>
				<view class="second">
					<view class="payment-bottom flex-row flex-between">
						<view class="bottom-left flex-row">
							<allPrice :amount="amount"></allPrice>
							<view @tap="isShowDetail = false" class="all-money">明细<img
									src="https://qiniu.bms16.com/FkzZI0r5jO-c2JRahNkZW2pHb9dR" /></view>
						</view>
						<view @tap="navToPage">{{is_freeze==0?'立即支付':'支付·授权免押'}}</view>
					</view>
				</view>
			</view>
		</view>
		<calendar ref="calendar" :showPopup.sync="isShowCalendar" @valuesUpdated="handleValuesUpdated"
			@close="() => isShowCalendar = false" />
		<view v-if="isShowReturnCar" class="return-box">
			<view class="return-item">
				<view class="return-title flex-row flex-between">
					<view>还车到门店</view>
					<view @tap="isShowReturnCar = false" class="close-view"><img style="width: 24rpx;height: 24rpx;" src="https://qiniu.bms16.com/FoWVlo-Nmx6wTDpsL2Rf9_BamU7L" alt=""></view>
				</view>
				<view class="return-text">系统会根据您的定位判断您是否已到还车位置，如您已经到达门店，请点击「我已到店」按钮，待门店确认还车后，即可还车成功。</view>
				<view class="return-btn flex-row">
					<view @tap="toRurnCarPage">导航到店</view>
					<view @tap="toNearbyStorePage">我已到店</view>
				</view>
			</view>
		</view>
		<view v-if="isShowCheckOrder" class="return-box">
			<view class="return-item">
				<view style="text-align: center;margin-bottom: 120rpx;">
					<img style="width: 88rpx;height: 88rpx;" src="https://qiniu.bms16.com/Fqb-i2uJWlZOg8EvUXHr_1qhlndf" alt="">
					<view class="check-order-text">租车订单已提交</view>
					<view>请于 <text class="get-car-time">3.5-20:00</text>  到 <text class="get-car-name">深圳南山深大店</text>  取车</view>
				</view>
				<view class="return-btn flex-row">
					<view @tap="toRurnCarPage">我知道了</view>
					<view @tap="toNearbyStorePage">订单详情</view>
				</view>
			</view>
		</view>
	</view>
</template>
<script module="tools" lang="wxs" src="@/pages/common/wxs/tools.wxs"></script>
<script module="tools" lang="sjs" src="@/pages/common/wxs/tools.sjs"></script>
<script>
	var config = require('../../common/config.js');
	var common = require('../../common/common.js');
	var http = require('../../common/http.js');
	var storage = require('../../common/storage.js');
	var user = require('../../common/user.js');
	import allPrice from '@/component/allPrice/allPrice';
	import calendar from '@/component/smartCalendar';
	import {
		MAX_LIMITS
	} from '@/common/constant.js';
	export default {
		components: {
			allPrice,
			calendar
		},
		data() {
			return {
				isShowReturnCar:false,
				isShowCheckOrder:false,
				takeCar: '',
				returnCar: '',
				leaseTime: '',
				// rentalUnit: '',
				startDate: '',
				desc_city: '',
				modelId: '',
				modelInfo: {},
				shopInfo: {},
				service_list: [],
				cancel_setting: [],
				return_type: 1,
				is_freeze: 0,//是否选择免押 1是  0否
				freeze_is_open: 0,
				distance: '',
				longitude: '',
				latitude: '',
				isSelectGuarantee: 0,
				isArgee: false,
				from: '',
				duration_unit: '',
				free_order_no: '', // 免押订单号
				contract_id: 0,
				contractInfo: [],
				insurance_setting: null,
				isAgree: false,
				amount: '',
				price_list: [],
				order_sn: '',
				out_request_no: '',
				isOpenNoDeposit: false, // 是否去开通免押
				noDepositStatusTimer: null,
				pay_type: 0,
				out_request_no: '',
				wallet_money: 0, // 用户钱包余额信息
				returnType: [], // 数组
				isShowDetail: false,
				isSelectStatus: 4,
				count: 1,
				isShowCalendar: false, //选择预约订单时间
				showInput: true,
				userInfo: {
					is_auth: 0,
					status: 0
				},
			};
		}
		/**
		 * 生命周期函数--监听页面加载
		 */
		,
		onLoad: function(options) {
			//#ifdef MP-WEIXIN
			this.is_freeze = 0
			//#endif
			this.setData({
				takeCar: options.takeCar || '',
				returnCar: options.returnCar || '',
				leaseTime: options.leaseTime || '',
				isSelectStatus: options.duration_unit || ''
			})
			this.modelId = options.modelId || ''
			this.longitude = options.longitude || ''
			this.latitude = options.latitude || ''
			this.desc_city = options.desc_city || ''
			this.startDate = options.startDate || ''
			// if (this.rentalUnit == '小时') {
			// 	this.duration_unit = 4
			// } else if (this.rentalUnit == '天') {
			// 	this.duration_unit = 1
			// } else if (this.rentalUnit == '周') {
			// 	this.duration_unit = 6
			// }
			this.loadCarInfo()
			this.loadContractTitles();
			this.walletInfo()
		},
		/**
		 * 生命周期函数--监听页面显示
		 */
		onShow: function() {
			let pages = getCurrentPages();
			let currPage = pages[pages.length - 1];
			let isAgree = currPage.isAgree
			if (isAgree) {
				this.setData({
					isAgree: isAgree
				});
			}
			var userInfo = storage.getUserInfoData()
			if (userInfo) this.userInfo = userInfo.userInfo
		},
		computed: {
			serviceListLength() {
				return this.service_list.length;
			}
		},
		methods: {
			clickShowInsuranceDesc() {
				uni.navigateTo({
					url: '/pages/webContent/webContent?webContent=' + this.insurance_setting.illustrate +
						'&title=' + '保险须知',
					success: function(res) {},
					fail: function(res) {},
					complete: function(res) {},
				})
			},

			bindToNav() {
				const {
					address,
					latitude,
					longitude,
					shop_name
				} = this.shopInfo
				uni.openLocation({
					latitude: latitude - 0,
					longitude: longitude - 0,
					scale: 15,
					name: shop_name,
					address: address,
					success: function(res) {},
				})
			},

			loadCarInfo() {
				const me = this
				common.loading()
				http.postApi(config.API_DAYHIRE_CAR_MODEL_INFO, {
					model_id: me.modelId,
					longitude: me.longitude,
					latitude: me.latitude,
				}, (resp) => {
					if (resp.data.code === 200) {
						uni.hideLoading()
						me.freeze_is_open = resp.data.data.freeze_is_open //门店是1否0开启免押配置
						//#ifdef MP-ALIPAY
							me.is_freeze = resp.data.data.freeze_is_open==0?0:1
						//#endif
						me.modelInfo = resp.data.data.model_info
						me.shopInfo = resp.data.data.shop_info
						me.cancel_setting = resp.data.data.cancel_setting
						me.distance = common.formatDistance(me.shopInfo.distance - 0)
						me.modelInfo.endurance = common.formatDistance(me.modelInfo.endurance - 0)
						me.modelInfo.weight = common.formatWeight(me.modelInfo.weight - 0)
						me.service_list = resp.data.data.service_list
						me.insurance_setting = resp.data.data.insurance_setting
						me.returnType = resp.data.data.return_type
						me.return_type = resp.data.data.return_type[0]
						me.modelInfo.model_images = me.modelInfo.model_images.split(',')
						if (resp.data.data.price_list && Array.isArray(resp.data.data.price_list)) {
							me.price_list = resp.data.data.price_list
							resp.data.data.price_list.forEach(i => {
								if (i.hire_duration_unit == me.isSelectStatus) {
									me.setData({price:i.hire_price})
									// me.price = i.hire_price
								}
							})
						}

						me.bindDuration()
					} else {
						uni.hideLoading()
						common.simpleToast(resp.data.msg)
					}
				})
			},

			getServiceStyle(index) {
				if (index % 2 === 0) {
					return {
						borderRadius: '16rpx 0 0 16rpx'
					};
				} else {
					return {
						borderRadius: '0 16rpx 16rpx 0'
					};
				}
			},

			clickSelectMethod(e) {
				const status = e.currentTarget.dataset.status
				this.setData({
					return_type: status
				})
			},

			clickSelectDeposit(e) {
				const me = this
				const status = e.currentTarget.dataset.status
				me.setData({
					is_freeze: status
				})
				me.bindDuration()
			},

			clickSelectGuarantee(e) {
				const status = e.currentTarget.dataset.status
				this.setData({
					isSelectGuarantee: status
				})
			},

			navToPage(e) {
				const me = this
				if (this.userInfo.is_auth - 0 == 1 && this.userInfo.status - 0 != 2) {
					uni.showModal({
						title: '身份认证提示',
						content: '尚未完成身份认证，是否进行身份认证?',
						cancelText: '取消',
						confirmText: '确定',
						success: function(res) {
							if (res.confirm) {
								me.loadFaceToken()
							}
						},
						fail: function(res) {},
						complete: function(res) {},
					})
					return
				}
				// if (this.contractInfo.length > 0 && (!this.isAgree || this.contract_id == 0)) {
				// 	// if (有合同&&(没查看合同||没勾选同意)) {
				// 	common.simpleToast('请查阅合同')
				// 	return
				// }
				const isBuyModel= storage.getIsBuyModel()
				if(isBuyModel){//TODO
					common.simpleToast('您已有租车订单，请先完成订单')
					return
				}
				// if(storage.setIsBuyModel)
				//#ifdef MP-ALIPAY
				this.bindToPayAli()
				//#endif
				//#ifdef MP-WEIXIN
				this.bindToPayWx()
				//#endif
			},
			
			loadFaceToken() {
				const me = this
				http.postApi(config.API_USER_FACE_TOKEN, {}, (resp) => {
					if (resp.data.code === 200) {
						me.face_token = resp.data.data.token
						me.face_key = resp.data.data.key
						uni.navigateTo({
							url: '/pages/livenessView/livenessView?face_token=' + me.face_token +
								'&face_key=' + this.face_key,
							success: function(res) {},
							fail: function(res) {},
							complete: function(res) {},
						})
					} else {
						common.simpleToast(resp.data.msg)
					}
				})
			},

			bindToPayAli() {
				const me = this
				me.from = 'ali'
				const money = me.amount * 100
				// 默认钱包余额不够支付走支付宝(2)否则走钱包余额类型9
				me.pay_type = me.wallet_money < money ? '2' : '9'
				if (me.freeze_is_open == 1 && me.is_freeze == 1) { // 等于0表开启免押
					if (me.isOpenNoDeposit) {
						me.bindToPay()
						return
					}
					http.postApi(config.API_ALI_FREEZE, {
						model_id: me.modelInfo.model_id
					}, (resp) => {
						const params = resp.data.data.params
						my.tradePay({
							orderStr: params,
							success: (res) => {
								if (res.resultCode == 9000) {
									me.out_request_no = resp.data.data.request_no
									me.isOpenNoDeposit = true //开通成功后 不显示去开通免押金
									me.bindDuration()
									// me.amount = ((me.leaseTime * me.price_list[0].hire_price) + (me.insurance_setting!=null?(me.insurance_setting.price - 0):0)) / 100
									me.queryNoDepositStatus(me.out_request_no)
								} else {
									my.alert({
										content: '未成功开通免押金,需支付全部押金',
									});
									me.is_freeze = 0
									me.bindDuration()
									me.bindToPay()
								}
							},
							fail: (res) => {
								my.alert({
									content: '未成功开通免押金！',
								});
							}
						})
					})
				} else {
					me.bindToPay()
				}
			},

			bindToPayWx() {
				this.from = 'wx'
				this.free_order_no = ''
				const money = this.amount * 100
				// 默认钱包余额不够支付走微信(0)否则走钱包余额类型9
				this.pay_type = this.wallet_money < money ? '0' : '9'
				this.bindToPay()
			},

			bindToPay() {
				const me = this
				if (me.pay_type == '9' && me.wallet_money >= (me.amount * 100)) {
					uni.showModal({
						title: '支付提示',
						content: '确认使用钱包余额进行支付吗?',
						cancelText: '取消',
						confirmText: '确定',
						success: function(res) {
							if (res.confirm) {
								me.payMoney()
							} else if (res.cancel) {
								common.simpleToast('支付取消')
								return
							}
						},
						fail: function(res) {
							common.simpleToast(res.data.msg)
						},
						complete: function(res) {},
					})
				} else {
					me.payMoney()
				}
			},

			payMoney() {
				const me = this
				const begin_time = Math.floor(Date.parse(me.startDate + ':00') / 1000);
				http.postApi(config.API_DAYHIRE_HIRE_PREDETERMINE, {
					model_id: me.modelId,
					hire_duration: me.count, // 周期
					hire_duration_unit: me.isSelectStatus, // 周期单位
					begin_time: begin_time,
					from: me.from,
					return_type: me.return_type,
					free_order_no: me.free_order_no,
					pay_type: me.pay_type,
					city: me.desc_city,
					address: me.shopInfo.address,
					longitude: me.longitude,
					latitude: me.latitude,
				}, (resp) => {
					common.loading()
					if (resp.data.code === 200) {
						uni.hideLoading()
						me.order_sn = resp.data.data.order_sn;
						if (me.pay_type == '9') {
							common.simpleToast('支付成功')
							setTimeout(function() {
								uni.navigateTo({
									url: '/pages/orderStatus/orderStatus?order_sn=' + me.order_sn,
									success: function(res) {},
									fail: function(res) {},
									complete: function(res) {},
								})
							}, 500)
						} else {
							//#ifdef MP-ALIPAY
							my.tradePay({
								tradeNO: resp.data.data.trade_no,
								success: function(res) {
									if (res.resultCode == 9000) {
										common.simpleToast('支付成功');
									}
									setTimeout(function() {
										uni.navigateTo({
											url: '/pages/orderStatus/orderStatus?order_sn=' +
												me.order_sn + '&longitude=' + me
												.longitude + '&latitude=' + me
												.latitude,
											success: function(res) {},
											fail: function(res) {},
											complete: function(res) {}
										});
									}, 1000);
								},
								fail: function(res) {
									uni.navigateTo({
										url: '/pages/orderStatus/orderStatus?order_sn=' + me
											.order_sn + '&longitude=' + me.longitude +
											'&latitude=' + me.latitude,
										success: function(res) {},
										fail: function(res) {},
										complete: function(res) {}
									});
								},
							})
							//#endif
							//#ifdef MP-WEIXIN
							var payParams = JSON.parse(resp.data.data.payParams);
							user.wxPay(me.order_sn, payParams, function(isSuccess) {
								if (isSuccess) {
									common.simpleToast('支付成功')
									// // 跳转激活车辆
									// 	uni.navigateTo({
									// 		url: '/pages/inputLicensePlate/inputLicensePlate?order_sn=' + me.order_sn +'&order_model_id='+me.modelId,
									// 		success: function(res) {},
									// 		fail: function(res) {},
									// 		complete: function(res) {}
									// 	})
									setTimeout(function() {
										uni.navigateTo({
											url: '/pages/orderStatus/orderStatus?order_sn=' +
												me.order_sn + '&longitude=' + me
												.longitude +
												'&latitude=' + me.latitude,
											success: function(res) {},
											fail: function(res) {},
											complete: function(res) {}
										});
									}, 1000)
								} else {
									uni.navigateTo({
										url: '/pages/orderStatus/orderStatus?order_sn=' + me
											.order_sn +
											'&longitude=' + me.longitude + '&latitude=' + me
											.latitude,
										success: function(res) {},
										fail: function(res) {},
										complete: function(res) {}
									});
								}
							});
							//#endif
						}
					} else {
						uni.hideLoading()
						common.simpleToast(resp.data.msg)
					}
				})
			},

			queryNoDepositStatus(_out_request_no) {
				const me = this
				me.clearNoDepositStatusTimer();
				me.noDepositStatusTimer = setInterval(function() {
					http.postApi(
						config.API_ALI_FREEZE_STATUS, {
							model_id: me.modelInfo.model_id,
							out_request_no: _out_request_no
						},
						function(resp) {
							uni.hideLoading();
							if (resp.data.code === 200) {
								const {
									status
								} = resp.data.data
								if (status === 2) {
									common.simpleToast('开通免押金成功,正在前往租赁车辆~');
									me.clearNoDepositStatusTimer();
									setTimeout(function() {
										me.free_order_no = _out_request_no
										me.bindToPay()
									}, 1500);
								} else if (status === 1 || status === 0) {
									common.simpleToast('查询免押金开通状态中，请稍后~');
								}
							} else {
								common.simpleToast(resp.data.msg);
								me.clearNoDepositStatusTimer();
							}
						}
					);
				}, 1000)
			},

			// 清空查询免押金状态
			clearNoDepositStatusTimer: function() {
				if (this.noDepositStatusTimer == null) {
					return;
				}

				clearInterval(this.noDepositStatusTimer);
				this.noDepositStatusTimer = null;
			},

			bindContractInfo(e) {
				// if (!this.isAgree && this.contract_id == 0) {
				// 	common.simpleToast('请先点击阅读租赁合同');
				// 	return;
				// }
				const contract_id = e.currentTarget.dataset.contractid;
				if (this.contract_id == contract_id) {
					this.setData({
						contract_id: 0,
					});
				} else {
					this.setData({
						contract_id: contract_id
					});
				}
			},

			loadContractTitles() {
				const accountInfo = uni.getAccountInfoSync();
				const me = this;
				http.postApi(
					config.API_CONTRACT_TITLE, {
						appid: accountInfo.miniProgram.appId
					},
					function(resp) {
						if (resp.data.code === 200) {
							const contractInfo = resp.data.data.contractInfo;
							me.setData({
								contractInfo: contractInfo
							});
						}
					}
				);
			},

			bindContractTo(e) {
				const contract_id = e.currentTarget.dataset.contractid;
				this.setData({
					contract_id: contract_id
				});
				uni.navigateTo({
					url: '/pages/contract/contract?contract_id=' + contract_id,
					success: function(res) {},
					fail: function(res) {},
					complete: function(res) {}
				});
			},

			clickNotShow() {
				common.simpleToast('门店未开通，不可自选');
			},

			walletInfo() {
				const me = this
				http.postApi(config.API_DAYHIRE_USER_WALLET_INFO, {}, function(resp) {
					if (resp.data.code === 200) {
						me.wallet_money = resp.data.data.balance // 用户钱包余额信息，用于展示用户钱包余额信息。
					} else {
						common.simpleToast(resp.data.msg)
					}
				})
			},

			bindDetail() {
				this.isShowDetail = true
			},

			//计算价格
			bindDuration() {
				const me = this
				var _insurance_price //保险金
				const unit_price = (me.price / 100) * me.count //租金
				// insurance_setting 保险
				if (me.insurance_setting != null) { // 有保险的时候
					// isSelectDeposit==0为免押  isOpenNoDeposit为是否成功开通免押  total_money为总金额
					// unit_price 租金   insurance_setting.price 保险金   deposit 押金
					if (me.isSelectStatus == 4) { // 时
						_insurance_price = (me.insurance_setting.price - 0) * 1
					} else if (me.isSelectStatus == 6) { // 周
						_insurance_price = (me.insurance_setting.price - 0) * 7 * me.count
					} else if (me.isSelectStatus == 1) { //天
						_insurance_price = (me.insurance_setting.price - 0) * me.count
					} else if (me.isSelectStatus == 2) { //月
						_insurance_price = (me.insurance_setting.price - 0) * 30 * me.count
					} else if (me.isSelectStatus == 7) { //季
						_insurance_price = (me.insurance_setting.price - 0) * 90 * me.count
					}
				} else { // 无保险
					_insurance_price = 0
				}

				if (me.freeze_is_open == 1 &&( me.isOpenNoDeposit || me.is_freeze == 1)) {
					// 金额=(周期数*周期价格)+保险金
					me.amount = ((me.count * me.price - 0) + (_insurance_price - 0)) / 100
				} else {
					// 金额=(周期数*周期价格)+押金+保险金
					me.amount = ((me.count * me.price - 0) + (me.modelInfo.deposit - 0) + (_insurance_price - 0)) / 100
				}
			},
			bindChangeStatus(e) {
				const {
					status,
					unit,
					price
				} = e.currentTarget.dataset
				this.setData({
					isSelectStatus: unit,
					selectIndex: status,
					price: price,
					count: 1
				})
				this.bindDuration()
			},

			bindMinus() {
				if (this.count > 1) {
					this.setData({
						count: this.count - 1
					});
				}
				this.bindDuration()
			},
			blurHandle() {
				this.showInput = false
				this.$nextTick(() => {
					this.showInput = true
				})
			},
			bindInput(e) {
				// let count = Number(e.detail.value)
				// this.setData({
				//     count: count,
				// })
				const num = e.detail.value
				this.bindTipCount(num)
				this.bindDuration()
			},

			bindBlur(e) {
				const count = e.detail.value
				this.bindTipCount(count)
				if (count < 1) {
					this.setData({
						count: 1
					})
				}
				this.bindDuration()
			},

			bindAdd() {
				// this.setData({
				//     count: this.count + 1
				// });
				const num = this.count - 0 + 1
				this.bindTipCount(num)
				this.bindDuration()
			},
			bindTipCount(num) {
				const limit = MAX_LIMITS[this.isSelectStatus];
				if (limit && num > limit.max) {
					common.simpleToast(limit.message);
					this.setData({
						count: limit.max
					})
					this.blurHandle()
				} else {
					this.setData({
						count: num
					})
				}
			},
			handleValuesUpdated(e) {
				this.takeCar = e.takeCar
				this.returnCar = e.returnCar
				this.leaseTime = e.leaseTime
				this.startDate = e.startDate
				this.isShowCalendar = false;
			},
			tapSelectTime() {
				this.setData({
					isShowCalendar: true
				})
				this.$refs.calendar['leaseType'] = +this.selectType
				this.$nextTick(() => {
					this.$refs.calendar && this.$refs.calendar.setTakeCarData({
						takeCar: this.takeCar,
						dateText: this.startDate.replace('T', ' ')
					})
				})
			},
		}
	};
</script>

<style>
	@import './purchaseOrder.css';
</style>