<template>
	<view style="overflow: hidden;">
		<view class='wrap1' style="padding-bottom: 20rpx;">
			<view class="c-row">
				<view class="title">车牌号</view>
				<view class="con-list ">
					{{detailData.carNo}}
				</view>
			</view>
			<view class="c-row">
				<view class="title">油耗(升)</view>
				<view class="con-list ">
					{{detailData.fillingDetailInfo.oilConsumption}}
				</view>
			</view>
			<view class="c-row">
				<view class="title">当前油价(元/升)</view>
				<view class="con-list ">
					{{detailData.fillingDetailInfo.currentOilPrice}}
				</view>
			</view>
			<view class="c-row">
				<view class="title">计算金额(元)</view>
				<view class="con-list">
					{{detailData.fillingDetailInfo.currentConsumption}}
				</view>
			</view>
			<view class="c-row" style="justify-content: space-between;">
				<view class="title">加油凭证</view>
			</view>
			<view class="voucher">
				<u-upload :action="action" imageMode='aspectFill' :file-list="detailData.fillingDetailInfo.urlList"
					max-count="1" :deletable="false" :show-progress="false"></u-upload>
			</view>
		</view>
		<view class="c-row">
			<view class="left">备注</view>
		</view>
		<view style='position:relative;' class="wrap1 no-boder">
			<u-input disabled ref='textarea' class='textarea' v-model="detailData.remark" :type="typeRemark"
				:border="border" placeholder="选填,不超过150字" :height="height" :auto-height="autoHeight" maxlength="150" />
			<view class="remark">
				{{detailData.remark?detailData.remark.length:'0'}}/150个字
			</view>
		</view>
	</view>
	<!-- <u-skeleton class='skeletonwrap' :loading="loading" :animation="true" bgColor="#FFF"></u-skeleton> -->
	</view>
</template>

<script>
	import upload from '@/components/upload.vue';
	export default {
		components: {
			upload,
		},
		data() {
			return {
				detailData: {
					fillingDetailInfo: {}
				},
				action: this.$uploadUrl,
				maxSize: 50 * 1024 * 1024, //限制文件大小 50M
				btnLoading: false, //防止重复点击
				isAdd: true,
				tfc: "",
				totalCost: "",
				loading: true,
				height: 150,
				autoHeight: true,
				typeRemark: 'textarea',
				border: true,
			}
		},
		onLoad(options) {
			this.id = options.id
			// this.fillingDetail.fillingDetailInfoList[0].fillingId = this.id
		},
		onShow() {
			var that = this
			if (this.id) {
				this.seeInfo()
			}
		},
		methods: {
			previewImage(src) {
				uni.previewImage({
					urls: [src],
					longPressActions: {
						itemList: ['发送给朋友', '保存图片', '收藏'],
						success: function(data) {
							console.log('选中了第' + (data.tapIndex + 1) + '个按钮,第' + (data.index + 1) + '张图片');
						},
						fail: function(err) {
							console.log(err.errMsg);
						}
					}
				});
			},
			seeInfo() {
				var that = this
				this.$api.doRequest('get', '/fuelFillingInfo/getFilling', {
					id: this.id
				}).then(res => {
					if (res.data.code == 200) {
						this.detailData = res.data.data
						let urlList = []
						if (this.detailData.fillingDetailInfo.addressUrl) {
							let datalist = this.detailData.fillingDetailInfo.addressUrl.split(",")
							for (let j = 0; j < datalist.length; j++) {
								urlList.push({
									url: datalist[j]
								})
							}
							this.detailData.fillingDetailInfo.urlList = urlList
						}

						// setTimeout(()=>{
						// 	that.loading=false
						// },1000)
					}
				})
			},
			onError(error) {
				alert(error)
				console.log('------------error-----------')
				console.log(error)
			},
			onProgress(e) {
				console.log(e)
			},
			onRemove(index, num) {
				this.fillingDetail.fillingDetailInfoList[num].addressUrl.splice(index, 1)
			},
			filterFileType(index, lists) {
				if (lists[index].fileType != 'jpg' && lists[index].fileType != 'png' && lists[index].fileType != 'gif') {
					lists.splice(index, 1);
					// 当前文件不支持
					uni.showModal({
						title: '暂不支持当前图片类型',
						showCancel: false
					});
				} else {
					this.isAdd = false;
				}
			},
			calculate(index) {
				this.fillingDetail.fillingDetailInfoList[index].currentConsumption = (this.fillingDetail
						.fillingDetailInfoList[index].oilConsumption * this.fillingDetail.fillingDetailInfoList[index]
						.currentOilPrice)
					.toFixed(2)
				this.tfc = ""
				this.totalCost = ""
				for (let i = 0; i < this.fillingDetail.fillingDetailInfoList.length; i++) {
					this.tfc = (Number(this.tfc) + Number(this.fillingDetail.fillingDetailInfoList[i].oilConsumption))
						.toFixed(2)
					this.totalCost = (Number(this.totalCost) + Number(this.fillingDetail.fillingDetailInfoList[i]
						.currentConsumption)).toFixed(2)
					this.$forceUpdate()
				}
			},
			delApply(index) {
				this.fillingDetail.fillingDetailInfoList.splice(index, 1)
			},
			addApply() {
				this.fillingDetail.fillingDetailInfoList.push({
					oilConsumption: "",
					currentOilPrice: "",
					currentConsumption: "",
					addressUrl: [],
					compId: uni.getStorageSync('pcUserInfo').compId,
					commonId: uni.getStorageSync('pcUserInfo').userId,
					fillingId: this.id
				})
			},
			submitApply() {
				var that = this
				uni.showModal({
					content: "确定提交申请信息？",
					showCancel: true,
					confirmText: '提交',
					success: function(res) {
						if (res.confirm) {
							that.fillingDetail.tfc = that.tfc
							that.fillingDetail.totalCost = that.totalCost
							for (let i = 0; i < that.fillingDetail.fillingDetailInfoList.length; i++) {
								that.fillingDetail.fillingDetailInfoList[i].addressUrl = that.fillingDetail
									.fillingDetailInfoList[i].addressUrl.toString()
							}
							that.$api.doRequest('post', '/fillingDetailInfo/api/addFillingDetail',
									that.fillingDetail
								)
								.then(res => {
									if (res.data.code == 200) {
										that.$api.msg('提交成功')
										uni.navigateBack({
											delta: 1
										});
									} else {
										that.$api.msg('提交失败')
									}
								})
						}
					}
				})
			},
		}
	}
</script>

<style lang='scss' scoped>
	.center {
		padding-bottom: 220rpx;
	}

	page {
		background: #F5F6FA;
	}

	.title_b {
		margin: 20rpx 20rpx 0rpx 20rpx;
		padding: 20rpx 10rpx 20rpx 10rpx;
		font-weight: 550;
	}

	.c-row {
		display: -webkit-box;
		display: -webkit-flex;
		display: flex;
		-webkit-box-align: center;
		-webkit-align-items: center;
		align-items: center;
		padding: 10rpx 30rpx;
		position: relative;
	}

	.level2-title {}

	.level2-title {
		font-weight: 700;
		color: #000000;
	}

	.jt-icon {
		position: relative;
		top: 6rpx;
		width: 60rpx;
		margin: 0 20rpx;

	}

	.xf-iamge {
		width: 74rpx;
		height: 43rpx;
		position: absolute;
		top: -20rpx;
		right: 0;
	}

	.ssx {
		width: 20px;
		height: 20px;
		background: linear-gradient(180deg, #C8D7E5 0%, #AFC1D6 100%);
		font-family: PingFangSC-Medium, PingFang SC;
		font-weight: 500;
		color: #FFFFFF;
		border-radius: 50%;
		display: flex;
		justify-content: center;
		align-items: center;
		margin-right: 5px;
	}

	.con-list {
		-webkit-box-flex: 1;
		-webkit-flex: 1;
		flex: 1;
		display: -webkit-box;
		display: -webkit-flex;
		display: flex;
		-webkit-box-orient: vertical;
		-webkit-box-direction: normal;
		-webkit-flex-direction: column;
		flex-direction: column;
		color: #303133;
		line-height: 40rpx;
		text-align: right;

		.item1,
		.item3 {
			// width: 40%;
			display: flex;

			.text {
				text-overflow: ellipsis;
				overflow: hidden;
				white-space: nowrap;
			}

		}

		.item1 .text {
			text-align: left;
		}

		.item3 .text {
			text-align: right;
		}
	}

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

	.wrap1 {
		margin: 10px;
		border-radius: 15px 10px;
		margin-top: 18px;

		.tit {
			margin-left: 14px;
			width: 47px;
			padding-top: 10px;
		}

		.eliminate1 {
			max-width: 50%;
			width: 20px;
			height: 20px;
			font-family: PingFangSC-Medium, PingFang SC;
			font-weight: 500;
			border-radius: 50%;
			display: flex;
			justify-content: center;
			align-items: center;
			margin-right: 5px;
			margin-top: -20px;
			margin-left: 73px;
		}

		.eliminate2 {
			max-width: 50%;
			width: 20px;
			height: 20px;
			font-family: PingFangSC-Medium, PingFang SC;
			font-weight: 500;
			border-radius: 50%;
			display: flex;
			justify-content: center;
			align-items: center;
			margin-right: 5px;
			margin-top: -20px;
			margin-left: 100px;
		}

		.upload {
			margin-left: 157px;
		}
	}

	.wrap {
		background: #fff;
		margin: 10px;
		border-radius: 15px 10px;
		margin-top: 18px;

		input {}

		>.title {
			padding: 10px 16px;
		}

	}

	.footer {
		background: #fff;
		position: fixed;
		bottom: 0;
		width: 100%;
		padding: 20px 10px;
		z-index: 10;

		.button {
			background: #4089ff;
			width: 90%;
			margin: 250px auto;
			padding: 10px;
			color: #fff;
			text-align: center;
			border-radius: 30px;
			margin-top: 10px;
		}
	}


	.buns_item {
		display: flex;
		padding: 80rpx 0 50rpx 0;
		justify-content: space-around;
	}

	.but_css {
		background: #22C572;
		width: 40%;
		padding: 20rpx;
		color: #fff;
		text-align: center;
		border-radius: 20rpx;
	}

	/deep/.u-radio-group {
		flex-direction: row-reverse;
	}

	.no-boder {
		border: 0;
	}

	.textarea {
		background: #F9F9FA;
		border: 1px solid #EEEEEE;
	}

	.remark {
		position: absolute;
		right: 10px;
		bottom: 20px;
		color: #AFB3BF;
	}

	.voucher {
		margin-left: 20rpx;
	}

	.wrap1 {
		/* padding-bottom: 10px; */
		font-size: 14px;
		background: #fff;
		margin: 10px;
		border-radius: 10px;

		input {
			font-size: 14px;
		}

		>.title {
			padding: 10px 16px;
		}

	}

	/deep/.skeletonwrap {
		height: 100vh !important;
		top: -18px !important;
	}
</style>
