<template>
	<view>
		<view class="search">
			<u-search placeholder="输入车辆名称" v-model="param.vehiclePlate" bgColor="white" @search="getByVehiclePlate()"
				@custom="getByVehiclePlate()" :showAction="true" @clear="refresh()"></u-search>
			<view class="clear"></view>
		</view>
		<view class="goodsList">
			<view class="item" v-for="(item, index) in vehiceList" :key="index">
				<view class="con">
					<view class="productName omit">{{ item.vehiclePlate }}</view>
					<view class="desc omit">{{item.vehicleModel}}</view>
				</view>
				<view>
					<button class="btn" @click="vehicleClick(item)">选择地址</button>
				</view>
				<view class="clear"></view>
			</view>
			<view class="loading" v-if="loadMore"><u-loadmore :status="loadMore ? 'loading' : 'nomore'" /></view>
			<u-empty v-if="!loadMore && vehiceList.length == 0"></u-empty>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				param: {
					pageNo: 1,
					pageSize: 10
				},
				vehiceList: [],
				loadMore: true,
				vehice: {},
				address: {},
			}
		},
		onLoad(e) {
			this.getByVehiclePlate()
			console.log(e)
			if(e){
				this.vehice.tradeAreaId = item.tradeAreaId
				this.vehice.tradeAreaName = item.tradeAreaName
				this.vehice.enterpriseId = item.enterpriseId
				this.vehice.orderId = item.id
			}
			uni.$on('one-address', function(res) {
				this.address = res
			})
			this.informDriver()
		},
		methods: {
			// 车牌查询 
			getByVehiclePlate() {
				// this.vehiceList = []
				this.param.vehiclePlate = ''
				this.http.request({
					url: '/transport-server/app/TbVehicle/getByVehiclePlate',
					loading: 'false',
					data: this.param,
					success: res => {
						this.loadMore = parseInt(res.data.pageCount) > this.param.pageNo;
						if (res.data.data) {
							// this.vehiceList.push(...r);
							this.vehiceList = res.data.data
						}
					}
				});
			},
			// 车辆绑定
			vehicleClick(item) {
				this.vehice.driverId = item.driverId
				this.vehice.vehicleId = item.id
				uni.navigateTo({
					url: '/pages/market/one/merchant/address/address'
				})
			},
		}
	}
</script>

<style lang="scss">
	page {
		background-color: $pg;
	}
	.btn {
		height: 30px;
		margin: 8px 0px;
		display: flex;
		align-items: center;
		justify-content: center;
	}
</style>