<template>
	<view>
		<view>
			<view class='wrap'>
				<view class="c-row">
					<view class="title">车牌号</view>
					<view class="con-list">
						<input v-model='detailData.carNo' placeholder="请输入车牌号" maxlength="7"></input>
					</view>
				</view>
			</view>
			<view @click='startTrack' class="button" v-if='titleBtn=="开始轨迹"'>{{titleBtn}}</view>
			<view @click='startTrack' class="button1" v-if='titleBtn=="结束轨迹"'>{{titleBtn}}</view>
			<view @click='startTrack' class="button2" v-if='titleBtn=="申请报销"'>{{titleBtn}}</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				detailData: {
					carNo: '',
					travelStatus: '',
					originProvince: '',
					originCity: '',
					originArea: '',
					originLongitude: '',
					originLatitude: '',
					destinationProvince: '',
					destinationCity: '',
					destinationArea: '',
					destinationLongitude: '',
					destinationLatitude: '',
					trackFlag: '',
					compId: '',
					commonId: '',
					driverName: '',
					fillingNo: '',
					strokeType: '1',
				},
				titleBtn: "开始轨迹",
			}
		},
		onLoad(options) {
			this.id = options.id
		},
		onShow() {
			var that = this
			if (this.id) {
				this.seeInfo()
			}
		},
		methods: {
			seeInfo() {
				this.$api.doRequest('get', '/fuelFillingInfo/getFilling', {
					id: this.id
				}).then(res => {
					if (res.data.code == 200) {
						this.detailData = res.data.data
						if (this.detailData.travelStatus == "已开始") {
							this.titleBtn = "结束轨迹"
						} else if (this.detailData.travelStatus == "已结束") {
							this.titleBtn = "申请报销"
						}
					}
				})
			},
			startTrack() {
				if (this.titleBtn == "开始轨迹") {
					var that = this
					uni.showModal({
						content: "确定开始轨迹？",
						showCancel: true,
						confirmText: '确定',
						success: function(res) {
							if (res.confirm) {
								that.detailData.compId = uni.getStorageSync('pcUserInfo').compId
								that.detailData.commonId = uni.getStorageSync('pcUserInfo').userId
								that.detailData.driverName = uni.getStorageSync('userInfo').userName
								that.detailData.trackFlag = "0"
								that.detailData.fillingNo = "202207040001"
								that.detailData.originProvince = "辽宁省"
								that.detailData.originCity = "营口市"
								that.detailData.originArea = "鲅鱼圈区"
								that.detailData.originLongitude = "122.21"
								that.detailData.originLatitude = "40.664"
								that.$api.doRequest('post', '/fuelFillingInfo/api/addFilling',
										that.detailData
									)
									.then(res => {
										that.id = res.data.data
										if (res.data.code == 200) {
											that.$api.msg('提交成功')
											that.titleBtn = "结束轨迹"
										} else {
											that.$api.msg('提交失败')
										}
									})
							}
						}
					})
				} else if (this.titleBtn == "结束轨迹") {
					var that = this
					uni.showModal({
						content: "确定结束轨迹？",
						showCancel: true,
						confirmText: '确定',
						success: function(res) {
							if (res.confirm) {
								that.detailData.compId = uni.getStorageSync('pcUserInfo').compId
								that.detailData.commonId = uni.getStorageSync('pcUserInfo').userId
								that.detailData.driverName = uni.getStorageSync('userInfo').userName
								that.detailData.trackFlag = "1"
								that.detailData.destinationProvince = "江苏省"
								that.detailData.destinationCity = "宿迁市"
								that.detailData.destinationArea = "宿城区"
								that.detailData.destinationLongitude = "118.291"
								that.detailData.destinationLatitude = "33.942"
								that.$api.doRequest('post', '/fuelFillingInfo/api/addFilling',
										that.detailData
									)
									.then(res => {
										if (res.data.code == 200) {
											that.$api.msg('提交成功')
											that.titleBtn = "申请报销"
										} else {
											that.$api.msg('提交失败')
										}
									})
							}
						}
					})
				} else {
					uni.navigateTo({
						url: '/pages/fuelfilling/apply_for_reimbursement?id=' + this.id
					})
				}
			},
		}
	}
</script>

<style lang='scss' scoped>
	page {
		background: #F5F6FA;
	}

	.title_b {
		margin: 20rpx 20rpx 0rpx 20rpx;
		padding: 20rpx 10rpx 20rpx 10rpx;
		font-size: 18px;
		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: 20rpx 30rpx;
	}

	.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;
		padding-right: 20rpx;
	}

	.wrap {
		font-size: 14px;
		background: #fff;
		margin: 10px;
		border-radius: 15px 10px;

		input {
			font-size: 14px;
		}

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

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

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

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

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