<template>
	<view>
		<u-navbar back-text="返回" title="车辆出入厂" :background="background"></u-navbar>
		<u-form ref="testForm">
			<u-form-item :border-bottom="false">
				<label>选择车牌:</label>&nbsp;&nbsp;&nbsp;&nbsp;
				<zxzUniDataSelect filterable v-model="carNum" :localdata="carNumList" @change="change">
				</zxzUniDataSelect>
			</u-form-item>
			<u-form-item :border-bottom="false">
				<label>入厂地磅:</label>
				<uni-number-box :max="999999999" :step="0.1" v-model="enterWeight"/>
			</u-form-item>
			<u-form-item :border-bottom="false">
				<label>出厂地磅:</label>
				<uni-number-box :max="999999999" :step="0.1" v-model="exitWeight"/>
			</u-form-item>
		</u-form>
		<u-row>
			<u-col span="3"><label>入厂类型：</label> </u-col>
			<u-col span="3"><label>{{model.efType_dictText}}</label> </u-col>
			<u-col span="3"><label>排队数：</label> </u-col>
			<u-col span="3"><label>{{model.lineUpCount}}</label> </u-col>
		</u-row>
		<u-row>
			<u-col span="3"><label>物流公司：</label> </u-col>
			<u-col span="3"><label>{{model.logistics}}</label> </u-col>
			<u-col span="3"><label>司机姓名：</label> </u-col>
			<u-col span="3"><label>{{model.driverName}}</label> </u-col>
		</u-row>
		<u-row>
			<u-col span="3"><label>司机电话：</label> </u-col>
			<u-col span="3"><label>{{model.driverTel}}</label> </u-col>
			<u-col span="3"><label>司机身份证：</label> </u-col>
			<u-col span="2"><label>{{model.driverIdCard}}</label> </u-col>
		</u-row>
		<u-row>
			<u-col span="3"><label>进厂门：</label> </u-col>
			<u-col span="3"><label>{{model.enterFactoryDoor}}</label> </u-col>
			<u-col span="3"><label>出厂门：</label> </u-col>
			<u-col span="2"><label>{{model.exitFactoryDoor}}</label> </u-col>
		</u-row>
		<u-row>
			<u-col span="3"><label>当前状态：</label> </u-col>
			<u-col span="3"><label>{{model.currentStatus_dictText}}</label> </u-col>
		</u-row>
		<br />
		<u-row>
			<u-col span="3"><u-button @click="handleConfirm('1')" type="primary" size="mini">对接人确认</u-button></u-col>
			<u-col span="3"><u-button @click="handleConfirm('3')" type="primary" size="mini">审核入厂</u-button></u-col>
			<u-col span="3"><u-button @click="handleConfirm('4')" type="primary" size="mini">审核出厂</u-button></u-col>
			<u-col span="3"><u-button @click="handleConfirm('5')" type="primary" size="mini">地磅确认</u-button></u-col>
		</u-row>
	</view>
</template>

<script>
	import zxzUniDataSelect from "@/components/zxz-uni-data-select/zxz-uni-data-select.vue"
	import uniNumberBox from "@/components/uni-number-box/uni-number-box.vue"
	
	export default {
		components: {
			zxzUniDataSelect,
			uniNumberBox
		},
		data() {
			return {
				title: 'Hello',
				background: {
					backgroundImage: 'linear-gradient(45deg, rgb(28, 187, 180), rgb(141, 198, 63))'
				},
				model:{},
				carNum: '',
				enterWeight: '',
				exitWeight: '',
				carNumList: [],
				vehicleList: [],
				baseUrl: 'http://114.215.188.164:9001/jeecg-boot',
				url: {
					getCarNum: '/vehicleinout/vehicleInOut/getCarNum',
					handleConfirm: '/vehicleinout/vehicleInOut/handleConfirm'
				}
			}
		
		},
		mounted() {
			this.getCarNum();
		},
		methods: {
			getCarNum(){
				this.getRequest(this.url.getCarNum,{},'GET').then(res => {
					if (res.success) {
						this.vehicleList = res.result.records;
						this.carNumList = res.result.records.map(item => ({
							text: item.carNum,
							value: item.id,
						}));
					}
				})
			},
			change(){
				this.model = this.vehicleList.filter(item => item.id == this.carNum)[0]
			},
			handleConfirm(currentStatus){
				if (this.carNum == '') {
					this.$showMessage('请选择车牌');
					return;
				}
				let param = {
					id: this.model.id,
				}
				if (currentStatus != '5') {
					param.currentStatus = currentStatus;
				} else {
					
					param.enterWeight = this.enterWeight;
					param.exitWeight = this.exitWeight;
				}
				this.getRequest(this.url.handleConfirm,param).then(res => {
					if (res.success) {
						this.$showMessage(res.result);
						this.model = {}
						this.carNum = ''
						this.enterWeight = ''
						this.exitWeight = ''
					} else {
						this.$showMessage(res.message);
					}
				})
			},
			getRequest(url='',data={},method='',){
				return new Promise((resolve, reject) => {
					uni.request({
						url: this.baseUrl + url, //请求的地址是拼接后的真正地址
						method: method||'POST',
						header: {
							'Content-type': 'application/json;charset=utf-8',
						}, //请求头会把数据转为Json格式	
						'timeout': 600000,							
						data:data,//调用此方法时的传进来的参数
						success:(res)=>{
							// console.log(res)
							resolve(res.data)//把数据返回出去
						},
						fail:(err)=>{
							// console.log(res)
							resolve(err)
						}
					})
				})
			}
		}
	}
</script>

<style scoped>
	::v-deep .uni-numbox__value{
		width: 80px;
	}
</style>