<template>
	<!-- logisticsEntruckingLogs -->
	<view>
		<view style="height: 90%;overflow: scroll;">
			<view v-for="(item,index) in lineList" :key="index" style="width: 95%;height: 250rpx;margin: 20rpx auto 0;line-height: 50rpx;border: 2px solid #eee;border-radius: 20rpx;padding: 10px;">
				<view>出发站：{{item.goStation}}</view>
				<view>到达站：{{item.arrivalStation}}</view>
				<view>费用规则：{{item.transitFee}}</view>
				<view style="display: flex;float: right;">
					<view @tap="editPeople('edit',item)"><u-icon name="edit-pen-fill" size="28"></u-icon></view>
					<view @tap="delItem(item)"><u-icon name="trash-fill" size="28"></u-icon></view>
				</view>
			</view>
			
		</view>
		<view style="position: fixed;bottom: 0;width: 100%;display: flex;height: 140rpx;padding-top: 20rpx;">
			<view @tap="editPeople('add')" class="bottom-btn" style="width: 95%;">新增一条</view>
		</view>
		<uni-popup ref="inputDialog" background-color="#fff" :is-mask-click="true">
			<view class="type-popup">
				<view v-if="addType == 'add'" style="height: 120rpx;font-size: 36rpx;font-weight: bold;line-height: 120rpx;text-align: center;">
					新增中转
				</view>
				<view v-if="addType == 'edit'" style="height: 120rpx;font-size: 36rpx;font-weight: bold;line-height: 120rpx;text-align: center;">
					编辑信息
				</view>
				<uni-forms-item label="出发站" labelWidth='80px' name="goStation">
					<uni-easyinput type="text" v-model="addForm.goStation" placeholder="请输入出发站" />
				</uni-forms-item>
				<uni-forms-item label="到达站" labelWidth='80px' name="arrivalStation">
					<uni-easyinput type="text" v-model="addForm.arrivalStation" placeholder="请输入到达站" />
				</uni-forms-item>
				<uni-forms-item label="费用规则" labelWidth='80px' name="transitFee">
					<uni-easyinput type="digit" v-model="addForm.transitFee" placeholder="请输入费用规则" />
				</uni-forms-item>
				
				<view
					style="width: 100%;height: 90rpx;line-height: 90rpx;text-align: center;border-radius: 0;background: linear-gradient(90deg, #60F3FF, #088FEB);color: #fff;display: flex;">
					<view style="width:50%;" @tap="$refs.inputDialog.close()">取消</view>
					<view style="width:50%;background: linear-gradient(90deg, #FF9797, #FFC1E0);"
						@tap="onDotClick()">确认</view>
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				upCarList:[],
				lineValue:'',
				lineList:[],
				single: '',
				addType:'add',
				stationId:'',
				addForm:{
					stationId:'',
					goStation:'',
					arrivalStation:'',
					transitFee:"0"
				}
			};
		},
		onLoad(option) {
			this.addForm.stationId = option.stationId
			this.stationId = option.stationId
		}, 
		onShow(){
			this.getLine()
		},
		methods: {
			lineChange(e){
				
				for(let i=0;i<this.lineList.length;i++){
					
					if(this.lineList[i].circuitId == e){
						
						this.addForm.circuitId = this.lineList[i].circuitId
						this.addForm.circuitName = this.lineList[i].circuitName
					}
				}
			},
			getLine(){ 
				uni.request({
					url: this.tui.interfaceUrl() + '/app/logisticsTransferStation/getLogisticsTransferStationPageList',
					data:{
						pageNum:1,
						pageSize:100,
						stationId:this.stationId
					},
					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){
							setTimeout(res1=>{
								this.lineList = res.data.result.records
							},500)
						}
					},
					fail: (res) => {
						this.tui.toast("网络不给力，请稍后再试~")
					}
				})
			},
			editPeople(type,item){
				this.addType = type
				if(item){
					this.addForm.goStation = item.goStation
					this.addForm.arrivalStation = item.arrivalStation
					this.addForm.transitFee = item.transitFee
					this.addForm.id = item.id
				}else{
					this.addForm = {
						stationId:this.stationId,
						goStation:'',
						arrivalStation:'',
						transitFee:"0"
					}
				}
				
				this.$refs.inputDialog.open()
			},
			delItem(item) {
				let that = this;
				uni.showModal({
					title: '提示',
					content: '确定要删除该到达站吗？',
					success(res1) {
						if (res1.confirm) {
							uni.request({
								url: that.tui.interfaceUrl() + '/app/logisticsTransferStation/deleteLogisticsTransferStation',
								data: {
									id: item.id
								},
								header: {
									'content-type': 'application/x-www-form-urlencoded',
									'appWLToken': that.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) {
										that.tui.toast("删除成功")
										setTimeout(res1=>{
											that.getLine()
										},1000)
									}
								},
								fail: (res) => {
									that.tui.toast("网络不给力，请稍后再试~")
								}
							})
						}
					}
				})
			
			},
			onDotClick() {
				if (this.addType == 'edit') {
					if(this.addForm.stationName == '' ){
						this.tui.toast('到达站名称不能为空')
						return
					}
					uni.request({
						url: this.tui.interfaceUrl() + '/app/logisticsTransferStation/updateLogisticsTransferStation',
						data: this.addForm,
						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.getLine()
								},1000)
							}
							
						},
						fail: (res) => {
							this.tui.toast("网络不给力，请稍后再试~")
						}
					})
				} else if (this.addType == 'add') {
						uni.request({
							url: this.tui.interfaceUrl() + '/app/logisticsTransferStation/addLogisticsTransferStation',
							data: this.addForm,
							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.getLine()
									},1000)
								}
							},
							fail: (res) => {
								this.tui.toast("网络不给力，请稍后再试~")
							}
					}, (reason) => {
					
					})
				}
				this.$refs.inputDialog.close()
			},
		}
	}
</script>

<style>
	page{
		background: #fff;
	}
	.type-popup {
		width: 600rpx;
		height: 680rpx;
		background: #fff;
		border-radius: 10px;
		position: relative;
		padding: 0 20rpx;
	}
	.bottom-btn{
		width: 45%;
		height: 100rpx;
		background: linear-gradient(90deg, #60F3FF, #088FEB);
		border-radius: 20px;
		text-align: center;
		line-height: 100rpx;
		color: #fff;
		font-size: 36rpx;
		margin: 0 3%;
	}
</style>