<template>
	<view class="content">
		<view class="content1-top">
			<view class="top2">
				<!-- <view class="left top-content"> -->
				<view @click='tabcarchange(0)' class='line' :class='searchType==0?"active":""'>全部</view>
				<view @click='tabcarchange(1)' class='line' :class='searchType==1?"active":""'>未完成</view>
				<view @click='tabcarchange(3)' class='line' :class='searchType==3?"active":""'>已完成</view>
				<!-- </view> -->

			</view>
		</view>
		<mescroll-body ref="mescrollRef" :down="downOption" @down="downCallback" @up="upCallback">
			<checkbox-group>
				<view v-for="(item,index) in shortDetail.shortFillingList" :key="index" @click="getInfo(item)"
					class="list-content">
					<view class="fuxuankuang" @click.stop="checkedChange(item)" v-if="isShowCheck">
						<checkbox value="cb" style="transform:scale(0.7)" :disabled="item.travelStatus == '已报销'"
							:checked="item.check" />
					</view>
					<view class="good-list">
						<view style="padding: 0 35rpx 20rpx 35rpx;position: relative;">
							<view class="flex top">
								<view class="flex left">
									<view class="item1">
										<view class="ssx">{{$helper.getProvinceAbbreviation(item.originProvince)}}
										</view>
										<view class="level2-title" style="font-size: 14px;">
											{{$helper.filterUrban(item.originCity)}}
											{{$helper.filterArea(item.originArea)}}
										</view>
									</view>
									<image class="jt-icon item2" src="@/static/images/fuel/jt.png" mode='widthFix'>
									</image>
									<view class="item3">
										<view class="ssx">{{$helper.getProvinceAbbreviation(item.destinationProvince)}}
										</view>
										<view class="level2-title">{{$helper.filterUrban(item.destinationCity)}}
											{{$helper.filterArea(item.destinationArea)}}
										</view>
									</view>
								</view>
								<view class="flex">
									<view class="audit1" v-if="item.travelStatus == '已开始'">已开始</view>
									<view class="audit2" v-if="item.travelStatus == '已结束'">已结束</view>
									<view class="audit3" v-if="item.travelStatus == '已报销'">已报销</view>
								</view>
							</view>
							<view class="car-info">
								<view style="display: flex;">
									<view class="car-num">车牌号 : {{item.carNo}}</view>
									<view style="margin-left: 20rpx;" v-if="item.travelStatus != '已开始'">
										{{item.mileage}}km
									</view>
								</view>

								<view class="car-date">{{item.createDate.split(" ")[0]}}</view>
							</view>
							<view class="qk" v-if="item.travelStatus == '已结束'">
								<view class="qkbtn" @click="qkClick(item)">请款</view>
							</view>
						</view>
					</view>
				</view>
			</checkbox-group>
		</mescroll-body>
		<view v-if='show1' class="shade">
			<view class="wrap1">
				<view class="alert-top">
					<view class="title1">
						请款
					</view>
					<u-icon name="close" class="close" color="#8890B1" @click="close()"></u-icon>
				</view>
				<view class="c-row">
					<view class="title2">请款金额</view>
					<view class="con-list">
						<input type="digit" v-model='shortDetail.amountRequested' placeholder="请输入请款金额(元)">
						<view style="width: 0px;margin-left: 162px;margin-top: -20px;"></view></input>
					</view>
				</view>
				<view class="c-row">
					<view class="title2">仓库名称</view>
					<view class="con-list">
						<view @click='show=true'>{{shortDetail.warehouseName?shortDetail.warehouseName:"请选择仓库"}}</view>
						<u-picker :range="warehouseBaseInfoList" range-key="warehouseName"
							@confirm='targetLPicker($event)' v-model="show" mode="selector">
						</u-picker>
					</view>
				</view>
				<view class="c-row">
					<view class="title2">备注</view>
				</view>
				<view class="con-list">
					<u-input class='textarea' v-model="shortDetail.remark" :type="type" :border="border"
						:height="height" :auto-height="autoHeight" />
					<!-- <view style='right:10px;bottom:20px;color:#AFB3BF;'>
						{{shortDetail.remark.length}}/150个字
					</view> -->
				</view>
				<view @click="close()" class="cancel">取消</view>
				<view @click='requestFundsSubmit()' class="confirm">确定</view>
			</view>
		</view>
		<view class="bottom-view">
			<!-- 	<button v-if="searchType==3" style="line-height: 28px;margin-right: 5px;"
				class="right-contrent1" @click="requestFunds">请款</button> -->
			<view class="bottom-btn" @click="trackAddition" v-if="!isShowCheck">添加</view>
			<view class="row2" v-if="isShowCheck">
				<view class="left" v-if="!isSelectChecked">
					请选择要请款的记录
				</view>
				<view class="left" v-if="isSelectChecked">
					已选择{{selectTotal}}个
				</view>
				<view class="right" v-if="!isSelectChecked">
					一键请款
				</view>
				<view class="right green" @click="yjqkClick" v-if="isSelectChecked">
					一键请款
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins.js";
	export default {
		mixins: [MescrollMixin], // 使用mixin (在main.js注册全局组件)
		data() {
			return {
				downOption: {
					auto: false //是否在初始化后,自动执行downCallback; 默认true
				},
				selectTotal: 0,
				isSelectChecked: false,
				isShowCheck: false,
				show2: false,
				searchType: 0,
				pageSize: 10,
				show1: false,
				show: false,
				currentPage: 1,
				shortDetail: {
					shortFillingList: []
				},
				// shortDetail: {
				// 	shortFillingList: [{
				// 		destinationProvince: "辽宁省",
				// 		destinationCity: "营口市",
				// 		destinationArea: "鲅鱼圈区",
				// 		destinationAddress: '鲅鱼圈5号门',
				// 		carNo: "辽H11111",
				// 		originProvince: "辽宁省",
				// 		originCity: "营口",
				// 		originArea: "鲅鱼圈区",
				// 		originAddress: '中天昊元',
				// 		createDate: "2022-01-01 15:30:20",
				// 		travelStatus: "已开始",
				// 		totalCost: "233.20",
				// 		tfc: "60L",
				// 		check: false
				// 	}],
				// 	amountRequested: '',
				// 	warehouseName: '请选择仓库名称',
				// 	remark: '',
				// },
				warehouseType: '1',
				warehouseBaseInfoList: [],
				type: 'textarea',
				border: true,
				height: 150,
				autoHeight: true,

				// infoList:[],

			}
		},

		onLoad() {},
		onShow() {
			// this.getList()
		},
		onNavigationBarButtonTap(e) {
			console.log(e)
			this.isShowCheck = !this.isShowCheck
			// this.isSelectChecked = false
			// 	const index = e.index;
			// 	if (index == 1) {
			// 		uni.navigateBack()
			// 	} else {

			// 		this.naviageToPage("/pages/user/depotAcquisition/grainDeliveryRecord")
			// 	}
		},
		methods: {
			// 单条请款
			qkClick(item) {
				this.infoList = []
				this.infoList.push(item)
				this.show1 = true

			},
			// 一键请款
			yjqkClick() {
				// this.requestFundsSubmit()
				this.show1 = true
			},
			/*下拉刷新的回调 */
			downCallback() {
				this.getList(10, 1, 'down')
			},
			/*上拉加载的回调: 其中page.num:当前页 从1开始, page.size:每页数据条数,默认10 */
			upCallback(page) {
				//联网加载数据
				this.getList(page.size, page.num, 'up')
			},
			checkedChange(item) {
				item.check = !item.check
				this.isSelectChecked = false
				this.selectTotal = 0
				for (let i = 0; i < this.shortDetail.shortFillingList.length; i++) {
					if (this.shortDetail.shortFillingList[i].check) {
						this.isSelectChecked = true
						this.selectTotal++
					}
				}
				if (item.travelStatus == '已报销') {
					this.show2 = false
					this.$api.msg('已报销的不可再选')
					return
				} else {

					this.infoList.push(item)
				}
			},
			tabcarchange(searchType) {
				this.searchType = searchType
				this.getList()
			},
			trackAddition() {
				uni.navigateTo({
					url: '/pages/shortDistance/short_track_addition'
				})
			},
			getList(size, page, type) {
				this.$api.doRequest('get', '/shortFillingInfo/selectShortFilling', {
					pageSize: size,
					currentPage: page,
					// pcFlag: 0,
					searchType: this.searchType,
					compId: uni.getStorageSync('pcUserInfo').compId,
					commonId: uni.getStorageSync('pcUserInfo').userId,
				}).then(res => {
					if (res.data.code == 200) {
						uni.showLoading({
							mask: true,
							title: '加载中'
						})
						this.getWarehouse()
						if (type == 'down') {
							this.mescroll.endSuccess();
							this.shortDetail.shortFillingList = []
						} else {
							console.log(res.data)
							this.mescroll.endBySize(res.data.data.records.length, res.data.data.total
								.length); //必传参数(当前页的数据个数, 总数据量)
						}

						this.shortDetail.shortFillingList = this.shortDetail.shortFillingList.concat(res.data.data
							.records)
						for (let i = 0; i < this.shortDetail.shortFillingList.length; i++) {
							this.shortDetail.shortFillingList[i].check = false
						}

					}
				})
			},
			getWarehouse() {
				this.$api.doRequest('get', '/warehouseBaseInfo/selectWarehouse', {
					compId: uni.getStorageSync("pcUserInfo").compId,
					warehouseType: '1'
				}).then(res => {
					if (res.data.data.length != 0) {
						uni.hideLoading()
						this.warehouseBaseInfoList = res.data.data
					}
				})
			},
			targetLPicker(e) {
				this.shortDetail.warehouseName = this.warehouseBaseInfoList[e[0]].warehouseName
			},
			requestFunds() {
				this.show1 = true

			},
			close() {
				this.show1 = false
			},
			getInfo(item) {
				if (item.travelStatus == '已结束') {
					return
				} else {
					uni.navigateTo({
						url: '/pages/shortDistance/short_track_addition?id=' + item.id
					})
				}
			},
			requestFundsSubmit() {
				var that = this
				uni.showModal({
					content: "确定提交请款信息？",
					showCancel: true,
					confirmText: '提交',
					success: function(res) {
						if (res.confirm) {
							// that.shortDetail.remark = that.remark
							// that.shortDetail.amountRequested = that.amountRequested
							// that.shortDetail.warehouseName = that.warehouseName
							let dataInfo = {}
							dataInfo.amountRequested = that.shortDetail.amountRequested
							dataInfo.warehouseName = that.shortDetail.warehouseName
							dataInfo.remark = that.shortDetail.remark
							// dataInfo.compId = uni.getStorageSync('pcUserInfo').compId
							// dataInfo.commonId = uni.getStorageSync('pcUserInfo').userId
							// dataInfo.empName = uni.getStorageSync('userInfo').userName
							dataInfo.shortFillingInfoList = that.infoList
							that.$api.doRequest('post', '/shortFillingInfo/api/shortRequestFunds',
									dataInfo
								)
								.then(res => {
									if (res.data.code == 200) {
										that.$api.msg('提交成功')
										that.infoList = []
									} else {
										that.$api.msg('提交失败')
									}
								})
						}
					}
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		padding-bottom: 180rpx;
	}

	.tag {
		background: #F5F6F9;
		padding: 5px;
		color: #333333;
		display: inline-flex;
		font-size: 22rpx;
		border-radius: 3px;
		margin: 3px;
	}

	.introduce-section .title {
		justify-content: space-between;
		align-items: flex-start;
	}

	.introduce-section .title text {
		font-size: 28rpx;
	}

	.introduce-section .title .title-tip {
		flex: 1;
		font-size: 28rpx;
		color: #FE6430;
		font-weight: 500;
		height: 50px;
		line-height: 50px;
		border-bottom: 1px solid #EEEEEE;

	}

	.introduce-section .title .title-tip-a {
		flex: 1;
		font-size: 15px;
		color: #AFB3BF;
		font-weight: 500;
		height: 50px;
		line-height: 50px;
		border-bottom: 1px solid #EEEEEE;
	}

	.line {
		display: inline-block;
		padding: 5px;
		position: relative;
		font-size: 17px;
	}

	.line.active {
		font-size: 19px;
		font-weight: 900;
	}

	.line.active:after {
		content: '';
		display: block;
		position: absolute;
		width: 18px;
		left: 50%;
		transform: translateX(-50%);
		bottom: 0;
		border-bottom: 3px solid #22C572;
	}

	/deep/.u-action-active {
		margin-right: 6px;
	}

	.content1-top {
		background: white;
		padding: 10px 16px 0 10px;
		border-radius: 0 0 15px 15px;
		padding-bottom: 10px;
		margin-bottom: 20rpx;
	}

	.top2 {
		display: flex;
		align-items: center;
		justify-content: space-between;

		.right.uni-button {
			display: flex;
			align-items: center;
			font-weight: normal;

			.right-contrent1 {
				background: #22C572;
				height: 25px;
				font-size: 14px;
				color: #fff;

			}

		}
	}

	.good-list {
		background-color: white;
		// margin: -10px 10px 20px 10px;
		padding: 20px 0px;
		width: 100%;
		margin: 10rpx 20rpx;
		border-radius: 30rpx;
		box-shadow: 0px 5rpx 20rpx #E3E3E3;

		.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;
		}

		.top {
			align-items: center;
			justify-content: space-between;

			.left {
				align-items: center;
			}
		}

		.car-info {
			background: #F9F9FA;
			padding: 20rpx;
			display: flex;
			border-radius: 20rpx;
			flex-direction: column;

			.car-num {
				font-size: 26rpx;
				// font-weight: 700;
			}

			.car-date {
				margin-top: 10rpx;
				color: #878C9C;
			}
		}

		.qk {
			display: flex;
			justify-content: flex-end;
		}

		.qkbtn {
			display: flex;
			justify-content: center;
			align-items: center;
			background: #FFFFFF;
			border-radius: 33px;
			border: 1px solid #CDCDCD;
			padding: 15rpx 40rpx;
			box-sizing: border-box;
			margin-top: 20rpx;
		}
	}

	.fuxuankuang {
		margin-top: 10px;
	}

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

	.level2-title {
		font-size: 28rpx;
		width: 84px;
	}

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

	}

	.ssx {
		width: 20px;
		height: 20px;
		background: linear-gradient(180deg, #C8D7E5 0%, #AFC1D6 100%);
		font-size: 13px;
		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;
	}

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

	.wenzi {
		margin-top: -65px;
		text-align: right;
		border-radius: 5px;
		height: 5px;
	}

	.audit1 {
		color: #22C572;
	}

	.audit2 {
		color: #ff0000;
	}

	.audit3 {
		color: #AFB3BF;
	}

	.c-row {
		display: flex;
		-webkit-box-align: center;
		align-items: center;
		// padding: 0px 15px;
		position: relative;
	}

	.shade {
		position: fixed;
		top: 0;
		left: 0;
		height: 100%;
		width: 100%;
		background: rgba(0, 0, 0, 0.4);
		z-index: 3;

		.wrap1 {
			position: absolute;
			left: 0;
			top: 0;
			right: 0;
			bottom: 0;
			margin: auto;
			background: #fff;
			width: calc(100% - 198rpx);
			height: 340px;
			border-radius: 20rpx;

			input {
				font-size: 14px;
			}

			.alert-top {
				padding: 33rpx;
				display: flex;
				justify-content: center;
				align-items: center;
				position: relative;
			}

			.title1 {
				font-size: 32rpx;
				font-weight: 600;
				color: #333333;
			}

			.close {
				position: absolute;
				right: 33rpx;
			}
		}

		.title2 {
			padding: 10px 16px;
		}

		.con-list {
			-webkit-box-flex: 1;
			flex: 1;
			display: flex;
			-webkit-box-orient: vertical;
			-webkit-box-direction: normal;
			flex-direction: column;
			color: #303133;
			line-height: 20px;
			text-align: right;
			padding-right: 10px;
		}

		.cancel {
			position: absolute;
			display: inline-block;
			width: 50%;
			text-align: center;
			bottom: 0;
			padding: 10px;
			border-top: 1px solid #eee;
			font-size: 34rpx;
		}

		.confirm {
			position: absolute;
			display: inline-block;
			width: 50%;
			text-align: center;
			bottom: 0;
			padding: 10px;
			border-top: 1px solid #eee;
			font-size: 34rpx;
		}

		.cancel {
			left: 0;
			border-right: 1px solid #eee;
			color: #ff0000;
		}

		.confirm {
			right: 0;
			color: #22C572;
		}

		.bottom-btn {
			width: 100%;
			position: fixed;
			bottom: 0;
			display: flex;
			z-index: 2;
			left: 0;
			background-color: #f8f8f8;
			flex-direction: column;

			.btn1,
			.btn2 {
				width: 100%;
				margin-bottom: 26rpx;
				border-radius: 90rpx;
			}

			.btn1 {
				background: white;
				color: #00C265;
			}
		}
	}

	.textarea {
		background: #F9F9FA;
		border: 1px solid #EEEEEE;
		margin: 20rpx;

	}

	// .top-content{
	// 	display: flex;
	// 	// justify-content: ;
	// }
	.list-content {
		display: flex;
		align-items: center;
	}

	.bottom-view {
		position: fixed;
		bottom: 0;
		width: 100%;
		padding: 40rpx;
		background-color: #fff;

		.bottom-btn {
			background-color: #22C572;
			width: 100%;
			display: flex;
			align-items: center;
			justify-content: center;
			color: #fff;
			font-size: 32rpx;
			padding: 20rpx;
			border-radius: 50rpx;

		}

		.row2 {
			display: flex;
			justify-content: space-around;
			align-items: center;
			color: #ACAFB6;

			.right {
				background-color: #F7F8FA;
				padding: 20rpx 60rpx;
				border-radius: 50rpx;
			}

			.green {
				background: #22C572;
				color: #fff;
			}

		}
	}
</style>
