<template>
	<view class="mafi">
		<head-view :title="title" url="/pages/shipWork/documentList"></head-view>
		<view class="container contentFixed">
			<view class="signBox">
				<p class="sign" @click="sign">点击签名</p>
			</view>
			<template v-if="infoList.length > 0">
				<view class="ul">
					<view class="li" v-for="(item,index) in infoList" :key="index" @click="add('look',item,index)">
						<view class="title">
							<image src="../../static/images/shipWork/hc.png" mode="widthFix"></image>
							<text>航次：{{item.vvyName}}</text>
						</view>
						<view class="liInfo">
							<p>马菲板号：<text>{{item.mafiBarcode}}</text></p>
							<p>尺码：<text>{{item.size}}</text></p>
							<p>类型：<text>{{item.type}}</text></p>
							<p>装卸方式：<text>{{item.loadType}}</text></p>
						</view>
						<view class="status didNot" v-if="item.status == 0 || item.status == 'null'">
							<p>待提交</p>
						</view>
						<view class="status didNot" v-if="item.status == 1">
							<p>待审核</p>
						</view>
						<view class="status didNot" v-if="item.status == 2">
							<p>审批中</p>
						</view>
						<view class="status success" v-if="item.status == 3">
							<p>审核通过</p>
						</view>
						<view class="status fail" v-if="item.status == 4">
							<p>审核驳回</p>
						</view>
						<view class="status success" v-if="item.status == 5">
							<p>审核通过</p>
						</view>
					</view>
				</view>
			</template>
			<o-empty v-else height="70vh" bg="#f5f6fa" />
			<view class="addBtn" @click="add('add')">+ 新增</view>
		</view>
	</view>
</template>

<script>
	import sqlite from "../../common/sqlite.js"
	export default {
		data() {
			return {
				title: "船名 - MAFI清单",
				shipInfo: {},
				infoList: [],
				vtpId: "",
			}
		},
		mounted() {
			this.vtpId = uni.getStorageSync('vtpId')
			let title = uni.getStorageSync('shipWorkTitle')
			this.title = `${title} / MAFI清单 `
			this.executeSql1('mafiListRespList')
			this.executeSql1('shipInfoTable')
		},
		methods: {
			// 查
			executeSql1(tableName) {
				let sql = `select * from ${tableName} WHERE vtpId = '${this.vtpId}'`
				sqlite.executeSqlCeshi(sql).then((value) => {
					// 在resolve时执行的回调函数
					if (tableName == 'shipInfoTable') {
						this.shipInfo = value[0]
					} else {
						this.infoList = value
					}
				}).catch((error) => {
					// 在reject时执行的回调函数
					console.error(error);
				});
			},
			// 点击签名
			sign() {
				const objType = {
					signType: "mafi"
				}
				const dataType = encodeURIComponent(JSON.stringify(objType));
				uni.navigateTo({
					url: `/pages/shipWork/mafiSign?dataType=${dataType}`
				})
			},
			// 点击新增
			add(state, item, index) {
				if (state != 'add') {
					uni.setStorageSync('mafiRow', item);
					uni.setStorageSync('mafiRowIndex', index);
				}
				const obj = {
					state: state,
				}
				const params = encodeURIComponent(JSON.stringify(obj));
				uni.navigateTo({
					url: `/pages/shipWork/mafiAdd?params=${params}`
				})
			},
		}
	}
</script>

<style lang="less" scoped>
	.mafi {
		.headInfo {
			/deep/.uniui-bottom {
				display: none;
			}
		}

		.container {
			padding: 30px 20px;

			.signBox {
				display: flex;
				justify-content: flex-end;

				.sign {
					width: 86px;
					height: 36px;
					line-height: 36px;
					text-align: center;
					color: #2979ff;
					border: 1px solid #2979ff;
					border-radius: 4px;
					color: #2979ff;
				}
			}

			.ul {
				padding: 20px 0;
				display: flex;
				flex-wrap: wrap;

				.li {
					width: 33%;
					padding: 16px;
					border: 1px solid #ccc;
					background-color: #fff;
					border-radius: 8px;
					position: relative;
					margin-bottom: 10px;

					.title {
						display: flex;

						text {
							font-size: 16px;
							font-weight: bold;
							display: flex;
							flex-direction: column;
							justify-content: center;
							margin-left: 8px;
						}

						image {
							width: 32px;
							height: 32px;
						}
					}

					.liInfo {
						display: flex;
						flex-wrap: wrap;
						justify-content: space-between;
						margin-top: 24px;

						p {
							width: 49%;
							margin-bottom: 12px;
							color: #999;

							text {
								font-weight: bold;
								color: #23262e;
							}
						}
					}

					.status {
						padding: 5px;

						position: absolute;
						top: 16px;
						right: 16px;
					}

					.didNot {
						background-color: #FFF7EE;
						color: #FC8300;
					}

					.success {
						background: #F1F8FF;
						color: #0067CF;
					}

					.fail {
						background: #FFF0F0;
						color: #E50101;
					}

					.shift {
						display: flex;
						padding: 16px 4px;
						background-color: #f7f7f7;
						margin: 5px 0;

						text:first-child {
							color: #0067CF;
							margin: 0 12px;
						}

						.text {
							color: #999;
						}

						.time {
							color: #23262E;
							margin-top: 3px;
							margin-right: 15px;
						}

					}

					.state {
						display: flex;
						flex-direction: column;
						justify-content: center;
					}
				}

				.li:nth-of-type(3n - 1) {
					margin: 0 0.5% 10px;
				}

				/deep/.o-empty {
					width: 100%;
				}
			}

			.addBtn {
				position: fixed;
				right: 50px;
				bottom: 50px;
				width: 100px;
				height: 100px;
				border-radius: 50%;
				background-color: #2979ff;
				color: #fff;
				font-size: 24px;
				text-align: center;
				line-height: 100px;
				font-weight: bold;
			}
		}
	}
</style>