<template>
	<view class="app">
		<head-view v-show="current!=2" title="船名/航次"></head-view>
		<head-info v-show="current==2"></head-info>
		<view class="content">
			<view class="form">
				<view class="input">
					<uni-easyinput class="input" suffixIcon="search" v-model="value1" placeholder="船名/航次"
						@iconClick="iconClick">
					</uni-easyinput>
				</view>
				<view class="select" v-show="current!=0">
					<uni-data-select v-model="value" :localdata="range" @change="change" placeholder="港区">
					</uni-data-select>
				</view>
				<view class="select" v-show="current!=0">
					<uni-data-select v-model="value" :localdata="range" @change="change" placeholder="贸易类型">
					</uni-data-select>
				</view>
				<view class="select">
					<uni-data-select v-model="value" :localdata="range" @change="change" placeholder="品牌">
					</uni-data-select>
				</view>
				<view class="select" v-show="current!=0">
					<uni-data-select v-model="value" :localdata="range" @change="change" placeholder="车型">
					</uni-data-select>
				</view>
				<view class="select">
					<uni-data-select v-model="value" :localdata="range" @change="change" placeholder="港口">
					</uni-data-select>
				</view>
				<view class="select" v-show="current!=0">
					<uni-data-select v-model="value" :localdata="range" @change="change" placeholder="计划状态">
					</uni-data-select>
				</view>
			</view>
			<view class="uni-list">
				<radio-group class="group" @change="radioChange">
					<label class="uni-list-cell uni-list-cell-pd" v-for="(item, index) in items" :key="item.value">
						<view>
							<radio :value="item.value" :checked="index === current" />{{item.name}}
						</view>
					</label>
				</radio-group>
			</view>
			<view class="buttonlist">
				<button v-show="current==0" class="button" type="default">指令发送</button>
				<button v-show="current!=2" class="button" type="default">装船要求</button>
				<button class="button" type="default">刷新</button>
				<button v-show="current==2" class="button" type="default">显示</button>
			</view>
			<view class="itemList" v-show="current==0">
				<view class="exp" v-for="(item,index) in itemList" :key="item.index">
					<view class="item">
						<view class="rowHead" v-show="active==1">
							<radio :value="item.value" />
						</view>
						<view class="row">
							<view class="col weight">
								船舱层数：5层3舱
							</view>
							<view class="col">
								数量：1,000
							</view>
							<view class="col">
								港口：厦门港
							</view>
						</view>
						<view class="row">
							<view class="col weight">
								计划状态：已发送
							</view>
							<view class="col">
								负责人：我是一个负责人
							</view>
							<view class="col">
								发送时间：2023/09/09 16:00
							</view>
						</view>
						<view class="rowFoot">
							<view class="col">
								装船进度
							</view>
							<view class="col">
								<view class="progress-box">
									<van-progress :percentage="itemSum(item.sum)" :pivot-text="'60/' + item.sum" />
								</view>
							</view>
						</view>
						<view class="fs blue">
							<text v-show="active==1" @click="onSend">发送</text>
							<text v-show="active==2">{{item.status}}</text>
						</view>
					</view>
					<view class="details">
						<uni-icons v-show="itemActive != index" class="jt" type="top" size="24" color="#108ee9"
							@click="isActive(index)"></uni-icons>
						<view class="itemDetails" v-show="itemActive == index">
							<view class="row" v-for="cell in item.xq">
								<view class="cell">
									TD90959749495
								</view>
								<view class="cell">
									中转港：厦门港
								</view>
								<view class="cell">
									数量：100
								</view>
								<view class="cell">
									品牌：特斯拉
								</view>
								<view class="cell">
									车型：电动车
								</view>
								<view class="cell">
									型号：特斯拉plus
								</view>
								<view class="cell blue" @click="toDetails">
									详情
								</view>
							</view>
							<uni-icons class="jt" type="bottom" size="24" color="#108ee9"
								@click="itemActive = '-1'"></uni-icons>
						</view>
					</view>
				</view>
			</view>
			<view class="tablist" v-show="current==1">
				<view class="tab" :class="active==1?'active':''" type="default" @click="tabChange(1)">未发送</view>
				<view class="tab" :class="active==2?'active':''" type="default" @click="tabChange(2)">已发送</view>
			</view>
			<view class="itemList" v-show="current==1">
				<view class="exp" v-for="(item,index) in itemList" :key="item.index">
					<view class="item">
						<view class="rowHead" v-if="active==1">
							<radio :value="item.value" />
						</view>
						<view class="row">
							<view class="col weight">
								船舱层数：5层3舱
							</view>
							<view class="col">
								数量：1,000
							</view>
							<view class="col">
								港口：厦门港
							</view>
						</view>
						<view class="row">
							<view class="col weight">
								计划状态：已发送
							</view>
							<view class="col">
								负责人：我是一个负责人
							</view>
							<view class="col">
								发送时间：2023/09/09 16:00
							</view>
						</view>
						<view class="rowFoot">
							<view class="col">
								装船进度
							</view>
							<view class="col">
								<view class="progress-box">
									<van-progress :percentage="itemSum(item.sum)" :pivot-text="'60/' + item.sum" />
								</view>
							</view>
						</view>
						<view class="fs blue">
							<text v-show="active==1" @click="onSend">发送</text>
							<text v-show="active==2" @click="onPause">{{item.status}}</text>
						</view>
					</view>
					<view class="details">
						<uni-icons v-show="itemActive != index" class="jt" type="top" size="24" color="#108ee9"
							@click="isActive(index)"></uni-icons>
						<view class="itemDetails" v-show="itemActive == index">
							<view class="row" v-for="cell in item.xq">
								<view class="cell">
									TD90959749495
								</view>
								<view class="cell">
									中转港：厦门港
								</view>
								<view class="cell">
									数量：100
								</view>
								<view class="cell">
									品牌：特斯拉
								</view>
								<view class="cell">
									车型：电动车
								</view>
								<view class="cell">
									型号：特斯拉plus
								</view>
								<view class="cell blue" @click="toDetails">
									详情
								</view>
							</view>
							<uni-icons class="jt" type="bottom" size="24" color="#108ee9"
								@click="itemActive = '-1'"></uni-icons>
						</view>
					</view>
				</view>
			</view>

			<view class="currentList" v-show="current==2">
				<view class="imgLi">
					<image src="@/static/images/u176.png" mode="widthFix">
				</view>
				<view class="title">
					第一层
				</view>
				<view class="nr">
					<text class="text">是否可调夹板: 是</text>
					<text class="text">是否有跳板: 双尾跳</text>
				</view>
				<view class="imgLi">
					<image src="@/static/images/u86.png" mode="widthFix">
				</view>
				<view class="tableHead">
					<text>明细(100)</text>
					<uni-icons class="jt" type="bottom" size="24"></uni-icons>
				</view>
				<uni-table border stripe emptyText="暂无更多数据">
					<!-- 表头行 -->
					<uni-tr class="gray">
						<uni-th align="center" width="20">提单号</uni-th>
						<uni-th align="center" width="20">港口</uni-th>
						<uni-th align="center" width="20">品牌</uni-th>
						<uni-th align="center" width="20">车型</uni-th>
						<uni-th align="center" width="20">型号</uni-th>
						<uni-th align="center" width="20">车型明细</uni-th>
						<uni-th align="center" width="20">数量</uni-th>
						<uni-th align="center" width="20">长</uni-th>
						<uni-th align="center" width="20">宽</uni-th>
						<uni-th align="center" width="20">高</uni-th>
						<uni-th align="center" width="20">位置</uni-th>
					</uni-tr>
					<!-- 表格数据行 -->
					<uni-tr>
						<uni-td>1123</uni-td>
						<uni-td>2</uni-td>
						<uni-td>3</uni-td>
						<uni-td>4</uni-td>
						<uni-td>1</uni-td>
						<uni-td>2</uni-td>
						<uni-td>3</uni-td>
						<uni-td>4</uni-td>
						<uni-td>1</uni-td>
						<uni-td>2</uni-td>
						<uni-td>3</uni-td>
					</uni-tr>

				</uni-table>
			</view>
		</view>
	</view>

</template>

<script>
	import {
		mapActions
	} from 'vuex'
	import HeadView from '@/components/head-view/head-view.vue';
	import HeadInfo from '@/components/head-info/head-info';
	export default {
		data() {
			return {
				id: "",// 进入页面的初始id
				value1: "",
				value: '',
				itemList: [],
				range: [1],
				items: [{
						value: '1',
						name: '总指令',
						checked: 'true'
					},
					{
						value: '2',
						name: '分指令'
					},
					{
						value: '3',
						name: '配载图'
					},
					{
						value: '4',
						name: '场位图'
					},
				],
				current: 0,
				active: 1,
				itemActive: -1,
			}
		},
		computed: {
			itemSum() {
				return function(item) {
					let sum = (60 / item) * 100
					return sum
				};
			}
		},
		onLoad() {
			this.id = this.$route.query.id;
			this.loadSumOrder() // 总指令：分页查询
		},
		components: {
			HeadView,
			HeadInfo
		},
		methods: {
			...mapActions([
				'majax',
				'najax'
			]),
			loadSumOrder() {
				let data = {}
				data.bvmId = this.id
				this.majax({
					url: this.$local + "/api/shipInstructions/page",
					params: data,
					method: 'GET'
				}).then(res => {
					this.itemList = res.data.records
				})
				// 模拟
				this.itemList = [{ //已发送
						sum: 300,
						xq: 2
					},
					{
						sum: 600,
						xq: 3
					},
					{
						sum: 900,
						xq: 1
					},
					{
						sum: 100,
						xq: 2
					},
					{
						sum: 200,
						xq: 2
					}
				]
			},
			loadOtherOrder() {
				let data = {}
				data.bvmId = this.id
				this.majax({
					url: this.$local + "/api/shipInstructions/pageCommandForBranch",
					params: data,
					method: 'GET'
				}).then(res => {
					this.itemList = res.data.records
				})
				// 模拟分指令
				this.itemList = [{ //已发送
						sum: 100,
						xq: 2,
						status: '暂停'
					},
					{
						sum: 300,
						xq: 3,
						status: '重新发送'
					},
					{
						sum: 200,
						xq: 1,
						status: '重新发送'
					},
					{
						sum: 500,
						xq: 2,
						status: '暂停'
					},
					{
						sum: 800,
						xq: 2,
						status: '暂停'
					}
				]
			},
			tabChange(tag) {
				this.active = tag
				if (this.active == 1) {
					console.log(1);			
				} else {
					console.log(2);
					
				}
			},
			change() {},
			radioChange: function(evt) {
				for (let i = 0; i < this.items.length; i++) {
					if (this.items[i].value === evt.detail.value) {
						this.current = i;
						switch(this.current) {
						     case 1:
						        this.loadSumOrder()
						        break;
						     case 2:
						        this.loadOtherOrder()
						        break;
						     default:
						} 
						break;
					}
				}
				
			},
			isActive(e) {
				this.itemActive = e
			},
			// 发送指令
			onSend() {
				let data = {}
				this.majax({
					url: this.$local + "/api/shipInstructions/commandSendForBranch",
					params: data,
					method: 'GET'
				}).then(res => {
					console.log(res);
				})
			},
			// 重新发送指令
			onReissued() {
				let data = {}
				this.majax({
					url: this.$local + "/api/shipInstructions/commandReissuedForBranch",
					params: data,
					method: 'GET'
				}).then(res => {
					console.log(res);
				})
			},
			// 暂停指令
			onPause() {
				let data = {}
				data.lwpId = '111'
				this.majax({
					url: this.$local + "/api/shipInstructions/commandPause",
					params: data,
					method: 'GET'
				}).then(res => {
					console.log(res);
				})
			},
			toDetails() {
				uni.navigateTo({
					url: '/pages/index/instructDetails'
				})
			}
		}
	};
</script>

<style>
	.blue {
		color: #108ee9;
	}

	.content {
		padding: 20px;
		background-color: #fff;

		.form {
			display: flex;

			.select {
				width: 100px;
				margin-left: 15px;
			}

			.input {
				width: 200px;
				height: 35px;
				line-height: 35px;
			}
		}

		.uni-list {
			margin-top: 20px;

			.group {
				width: 360px;
				height: 50px;
				display: flex;
				justify-content: space-between;
			}
		}

		.buttonlist {
			width: 340px;

			.button {
				display: inline-block;
				width: 100px;
				height: 40px;
				line-height: 40px;
				margin-right: 20rpx;
			}
		}

		.tablist {
			width: 175px;
			height: 60px;
			line-height: 60px;
			font-size: 21px;
			display: flex;
			justify-content: space-between;

			.tabs {
				width: 80px;
				height: 60px;
				border-bottom: 2rpx solid #ebebeb;
			}

			.active {
				color: #1890ff;
				border-bottom: 2rpx solid #1890ff;
			}

		}

		.itemList {
			margin-top: 30px;

			.exp {
				border-bottom: 2px solid #e9e9e9;
				text-align: center;
				padding-bottom: 10px;

				.item {
					height: 110px;
					padding: 20px 20px 0;
					display: flex;
					justify-content: space-between;
					text-align: left;

					.weight {
						font-weight: 900;
					}

					.rowHead {
						width: 4%;
					}

					.row {
						width: 28%;
						flex-direction: column;
						display: flex;
						justify-content: space-between;
					}

					.rowFoot {
						width: 34%;
						flex-direction: column;
						display: flex;
						justify-content: space-around;
					}

					.fs {
						width: 6%;
						text-align: right;
						line-height: 110px;
					}
				}

				.details {
					padding: 20px;

					.itemDetails {
						border-top: 2px dotted #7d7d7d;

						.row {
							display: flex;
							justify-content: space-between;
							height: 50px;
							line-height: 50px;

						}
					}
				}

			}
		}

		.currentList {
			width: 85%;
			margin: 10px auto;

			.tableHead {
				margin-top: 10px;
				height: 50px;
				line-height: 50px;
				background-color: #fff;
				display: flex;
				justify-content: space-between;
				padding: 0 12px;
				font-size: 20px;
				border: 1px solid #f2f2f2;
			}

			.gray {
				background-color: #f9f9f9;
			}

			.imgLi {
				margin-bottom: 5px;
			}

			.title {
				line-height: 50px;
				font-size: 21px;
				font-weight: 900;
			}

			.nr {
				font-size: 16px;

				.text {
					display: inline-block;
					margin-right: 50px;
				}
			}
		}
	}
</style>