<template>
	<view>
		<view @tap="goAddUpCar" style="width: 95%;height: 80rpx;line-height: 80rpx;text-align: center;background: #088FEB;color: #fff;border-radius: 10px;margin: 0 auto;margin-top: 20rpx;">
			新增装车记录
		</view>
		<uni-search-bar class="uni-mt-10" radius="5" placeholder="输入线路/物流公司/收发货人搜索" cancelButton="none"
			@confirm="searchList" />
		<view v-for="(item,index) in upCarList" :key="index">
			<uni-card :title="item.entruckingDate">
				<view v-for="(item1,index1) in item.logisticsEntruckingLogList" :key="index1" style="border-bottom: 1px solid #eee;padding: 20rpx 0;">
					<view>车牌号：{{item1.carNumber}}</view>
					<view>司机手机号：{{item1.carPhone}}</view>
					<view>
						运费：{{item1.carFreight}} 
						<text style="padding-left:20rpx;">装车费：{{item1.carFee}}</text>
					</view>
				</view>
			</uni-card>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				pageNum:1,
				upCarList:[],
				lineValue:'',
				lineList:[],
				range:[],
				formData:{
					circuitId:"",
					circuitName:"",
					carNumber:'',
					carUserName:'',
					carPhone:'',
					carFee:'',
					carFreight:""
				}
			};
		},
		onShow(){
			this.getUpCarList()
			this.getLine()
		},
		methods: {
			lineChange(e){
				
				for(let i=0;i<this.lineList.length;i++){
					
					if(this.lineList[i].circuitId == e){
						
						this.formData.circuitId = this.lineList[i].circuitId
						this.formData.circuitName = this.lineList[i].circuitName
					}
				}
			},
			getLine(){
				uni.request({
					url: this.tui.interfaceUrl() + '/app/logisticsCompanyRoute/getLogisticsCompanyRoutePageList',
					data:{
						pageNum:1,
						pageSize:100,
						companyId:uni.getStorageSync('transCompany'),
						companyName:"",
						circuitId:"",
						circuitName:""
					},
					header: {
						'content-type': 'application/json',
						'appWLToken': this.tui.getToken()
					},
					method: 'POST', //'GET','POST'
					dataType: 'json',
					success: (res) => {
						if(res.data.code == 401){
							uni.clearStorage()
							uni.navigateTo({
								url: '/package2/login/login'
							})
						}
						if (res.data.code == 200){
							for (let i = 0; i < res.data.result.records.length; i++) {
								res.data.result.records[i].value = res.data.result.records[i].circuitId
								res.data.result.records[i].text = res.data.result.records[i].circuitName
							}
							setTimeout(res1=>{
								this.lineList = res.data.result.records
							},500)
						}
					},
					fail: (res) => {
						this.tui.toast("网络不给力，请稍后再试~")
					}
				})
			},
			goAddUpCar(){
				uni.navigateTo({
					url:'/package2/other/addUpCarReacord'
				})
			},
			addUpCar(){
				uni.request({
					url: this.tui.interfaceUrl() + '/app/logisticsEntruckingLog/addLogisticsEntruckingLog',
					data:{
						companyId:uni.getStorageSync('transCompany'),
						companyName:uni.getStorageSync('companyName'),
						circuitId:this.formData.circuitId,
						circuitName:this.formData.circuitName,
						carUserName:this.formData.carUserName,
						carNumber:this.formData.carNumber,
						carPhone:this.formData.carPhone,
						carFee:this.formData.carFee,
						carFreight:this.formData.carFreight
					},
					header: {
						'content-type': 'application/json',
						'appWLToken': this.tui.getToken()
					},
					method: 'POST', //'GET','POST'
					dataType: 'json',
					success: (res) => {
						if(res.data.code == 401){
							uni.clearStorage()
							uni.navigateTo({
								url: '/package2/login/login'
							})
						}
						if (res.data.code == 200){
							this.tui.toast('保存成功')
							
							setTimeout(res1=>{
								this.$refs.inputDialog.close()
								this.getUpCarList()
							},1000)
						}
					},
					fail: (res) => {
						this.tui.toast("网络不给力，请稍后再试~")
					}
				})
			},
			getUpCarList(){
				uni.request({
					url: this.tui.interfaceUrl() + '/app/logisticsEntruckingLog/getDateLogisticsEntruckingLogPageList',
					data:{
						companyId:uni.getStorageSync('transCompany'),
						companyName:uni.getStorageSync('companyName'),
						pageNum:this.pageNum,
						pageSize:"10",
						startDate:this.range[0],
						endDate:this.range[1],
						circuitId:"",
						circuitName:"",
						carNumber:"",
					},
					header: {
						'content-type': 'application/json',
						'appWLToken': this.tui.getToken()
					},
					method: 'POST', //'GET','POST'
					dataType: 'json',
					success: (res) => {
						if(res.data.code == 401){
							uni.clearStorage()
							uni.navigateTo({
								url: '/package2/login/login'
							})
						}
						if(res.data.code == 200){
							this.upCarList = res.data.result.records
						}
						
					},
					fail: (res) => {
						this.tui.toast("网络不给力，请稍后再试~")
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	page{
		background: #fff;
	}
	.type-popup {
		width: 600rpx;
		height: 950rpx;
		background: #fff;
		border-radius: 10px;
		position: relative;
		padding: 0 20rpx;
	}
</style>