<template>
	<view class="untieAdd">
		<view class="container">
			<ul>
				<li>
					<p>船名：</p>
					<span>快乐号</span>
				</li>
				<li>
					<p><span class="required" v-if="obj.state != 'look'">*</span>船舶净吨：</p>
					<uni-number-box v-model="zlShip" v-if="obj.state != 'look'" />
					<span v-else>100</span>
				</li>
				<li>
					<p><span class="required" v-if="obj.state != 'look'">*</span>航次：</p>
					<uni-data-select v-model="hcValue" :localdata="hcList" @change="hcChange"
						v-if="obj.state != 'look'"></uni-data-select>
					<span v-else>CK98796</span>
				</li>
				<li>
					<p>进出口：</p>
					<span>进口</span>
				</li>
				<li>
					<p>贸易类型：</p>
					<span>内贸</span>
				</li>
				<li>
					<p><span class="required" v-if="obj.state != 'look'">*</span>泊位：</p>
					<uni-data-select v-model="bwValue" :localdata="bwList" @change="bwChange"
						v-if="obj.state != 'look'"></uni-data-select>
					<span v-else>1泊位</span>
				</li>
				<li>
					<p><span class="required" v-if="obj.state != 'look'">*</span>系缆时间：</p>
					<uni-datetime-picker v-model="xlTime" type="datetimerange" rangeSeparator="-" @change="changeLog"
						v-if="obj.state != 'look'" />
					<span v-else>2020-04-21 00:00 - 2020-04-21 00:00</span>
				</li>
				<li>
					<p>解缆时间：</p>
					<uni-datetime-picker v-model="jlTime" type="datetimerange" rangeSeparator="-" @change="changeLog"
						v-if="obj.state != 'look'" />
					<span v-else>2020-04-21 00:00 - 2020-04-21 00:00</span>
				</li>
				<li>
					<p>移泊时间：</p>
					<uni-datetime-picker v-model="ybTime" type="datetimerange" rangeSeparator="-" @change="changeLog"
						v-if="obj.state != 'look'" />
					<span v-else>2020-04-21 00:00 - 2020-04-21 00:00</span>
				</li>
				<li>
					<p>停泊时间：</p>
					<uni-datetime-picker v-model="tbTime" type="datetimerange" rangeSeparator="-" @change="changeLog"
						v-if="obj.state != 'look'" />
					<span v-else>2020-04-21 00:00 - 2020-04-21 00:00</span>
				</li>
			</ul>
			<view class="btnList">
				<van-button type="default" @click="cancel">取消</van-button>
				<van-button type="default" v-if="obj.state == 'look'">删除</van-button>
				<van-button type="info" v-if="obj.state == 'add' || obj.state == 'edit'" @click="save">保存</van-button>
				<van-button type="info" v-if="obj.state == 'look'" @click="toGo('edit')">编辑</van-button>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				obj: {},
				// 航次下拉框
				hcValue: "",
				hcList: [{
						value: 0,
						text: "航次0"
					},
					{
						value: 1,
						text: "航次1"
					},
					{
						value: 2,
						text: "航次2"
					},
				],
				// 船舶净吨
				zlShip: 100,
				// 泊位下拉框
				bwValue: "",
				bwList: [{
						value: 0,
						text: "泊位0"
					},
					{
						value: 1,
						text: "泊位1"
					},
					{
						value: 2,
						text: "泊位2"
					},
				],
				// 系缆时间
				xlTime: "",
				// 解缆时间
				jlTime: "",
				// 移泊时间
				ybTime: "",
				// 停泊时间
				tbTime: "",
			}
		},
		onLoad(options) {
			if ('params' in options) {
				// 获取传递的对象参数，使用decodeURIComponent解码，并转为对象
				this.obj = JSON.parse(decodeURIComponent(options.params))
			}
		},
		methods: {
			// 航次下拉
			hcChange(e) {
				this.hcValue = e;
			},
			// 泊位下拉
			bwChange(e) {
				this.bwValue = e;
			},
			// 取消
			cancel() {
				uni.navigateTo({
					url: '/pages/shipWork/untieCord'
				})
			},
			// 保存
			save() {
				uni.navigateTo({
					url: '/pages/shipWork/untieCord'
				})
			},
			// 编辑
			toGo(state) {
				this.obj.state = state;
				const params = encodeURIComponent(JSON.stringify(this.obj));
				uni.navigateTo({
					url: `/pages/shipWork/untieAdd?params=${params}`
				})
			}
		}
	}
</script>

<style lang="less" scoped>
	.untieAdd {
		.container {
			padding: 30px 20px;

			ul {
				display: flex;
				flex-wrap: wrap;
				justify-content: space-between;

				li {
					width: 44%;
					border-top: 1px solid #ccc;
					border-bottom: 1px solid #ccc;
					display: flex;
					padding: 10px 20px;
					line-height: 35px;
					margin-bottom: 20px;

					.required {
						color: red;
						margin-right: 5px;
					}

					p {
						min-width: 85px;
						text-align: right;
					}

					/deep/.uni-numbox {
						border: 1px solid #ccc;
						box-sizing: border-box;
					}

					/deep/.uni-numbox-btns {
						border-right: 1px solid #ccc;
						border-left: 1px solid #ccc;
						padding: 0 14px;
						box-sizing: border-box;
					}

					/deep/.uni-numbox__value {
						width: 100px;
						height: 35px;
						line-height: 35px;
						background-color: #fff !important;
					}
				}
			}

			.btnList {
				display: flex;
				justify-content: center;

				/deep/ .van-button {
					margin: 30px 20px;
					width: 120px;
					height: 50px;
				}
			}
		}
	}
</style>