<template>
	<view class="documentList">
		<head-view :title="title" :type="true" url="/pages/shipWork/index"></head-view>
		<uni-notice-bar show-icon single :text="noticeText" style="margin-top: 68px;" />
		<view class="container">
			<view class="workBox">
				<view class="title">
					<image src="../../static/images/shipWork/zydz.png" mode="widthFix"></image>
					<text>作业单证</text>
				</view>
				<view class="ul">
					<view class="li" v-for="(item,index) in infoList" :key="index" @click="toGo(item.url)">
						<image :src="item.imgUrl" mode="widthFix"></image>
						<p>{{item.name}}</p>
						<!-- <view class="uploadStatus" v-if="!item.status">
							<text>未上传</text>
						</view> -->
					</view>
				</view>
			</view>
			<view class="workBox">
				<view class="title">
					<image src="../../static/images/shipWork/qtzy.png" mode="widthFix"></image>
					<text>其他作业</text>
				</view>
				<view class="ul">
					<view class="li" v-for="(item,index) in otherListh" :key="index" @click="toGo(item.url)">
						<image :src="item.imgUrl" mode="widthFix"></image>
						<p>{{item.name}}</p>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import sqlite from "../../common/sqlite.js"
	export default {
		data() {
			return {
				title: "",
				vtpId: "",
				noticeText: "",
				infoList: [{
						name: "杂项作业单",
						url: "mixWork",
						imgUrl: "../../static/images/shipWork/zxzyd.png",
						status: false,
						tableName: "messageRespList",
					},
					{
						name: "系解缆",
						url: "untieCord",
						imgUrl: "../../static/images/shipWork/zxzyd.png",
						status: false,
						tableName: "attachUnmoorRespList",
					},
					{
						name: "供给",
						url: "supply",
						imgUrl: "../../static/images/shipWork/gj.png",
						status: true,
						tableName: "shipmentShipSupplyRespList",
					},
					{
						name: "指导员作业布置",
						url: "workAssign",
						imgUrl: "../../static/images/shipWork/zybz.png",
						status: true,
						tableName: "shipmentAdviserLayoutRespList",
					},
					{
						name: "船舶装卸通知单",
						url: "notice",
						imgUrl: "../../static/images/shipWork/tzd.png",
						status: true,
						tableName: "shipmentLoadUnloadNoticeRespList",
					},
					{
						name: "质量意见征询",
						url: "opinion",
						imgUrl: "../../static/images/shipWork/zlyj.png",
						status: true,
						tableName: "shipmentQualityConsultationRespList",
					},
					{
						name: "异常情况",
						url: "abnormal",
						imgUrl: "../../static/images/shipWork/yczk.png",
						status: true,
						tableName: "abnormalConditionRespList",
					},
					{
						name: "MAFI清单",
						url: "mafi",
						imgUrl: "../../static/images/shipWork/mafiqd.png",
						status: true,
						tableName: "mafiListRespList",
					}
				],
				otherListh: [{
						name: "安全巡检",
						url: "patrol",
						imgUrl: "../../static/images/shipWork/aqxj.png",
						tableName: "safetyInspectionRespList",
					},
					{
						name: "船舶资料",
						url: "shipInfo",
						imgUrl: "../../static/images/shipWork/cbzl.png",
						tableName: ""
					},
					{
						name: "船舶计划",
						url: "shipPlan",
						imgUrl: "../../static/images/shipWork/cbjh.png",
						tableName: ""
					},
					{
						name: "作业查询",
						url: "brandDetails",
						imgUrl: "../../static/images/shipWork/zycx.png",
						tableName: "shipmentShipLoadPlansRespList",
					}
				],
				tableStatusList: [],
				noticeList: [],
				vtpId: "",
				inVvyId: "",
				inVvyName: "",
				outVvyId: "",
				outVvyName: "",

				shipName: "",
			}
		},
		mounted() {
			this.vtpId = uni.getStorageSync('vtpId')
			this.getTableStauts()
		},
		methods: {
			getTableStauts() {
				this.infoList.forEach((v, index) => {
					this.executeSql(v.tableName)
				})
				this.executeSql("voyageScheduleDataDetailRespDTOList")
			},
			// 查
			executeSql(tableName) {
				let sql = `select * from ${tableName}  WHERE vtpId = '${this.vtpId}'`
				sqlite.executeSqlCeshi(sql).then((value) => {
					// 在resolve时执行的回调函数
					if (tableName == "voyageScheduleDataDetailRespDTOList") {
						value.forEach(v => {
							if (v.importExportFlagName == '出口') {
								this.inVvyId = v.vvyId
								this.inVvyName = v.vvyName
							} else {
								this.outVvyId = v.vvyId
								this.outVvyName = v.vvyName
							}
						})
						this.shipName = `${value[0].spmName}`
						this.title = `${value[0].spmName} 进口航次：${this.inVvyName} / 出口航次：${this.outVvyName}`
					} else {
						if (value.length == 0) {
							this.tableStatusList.push(tableName)
						}
						value.forEach(v => {
							if (v.webStatus == 0) {
								this.tableStatusList.push(tableName)
							}
						})
						this.tableStatusList = Array.from(new Set(this.tableStatusList))
						let meg = ""
						this.infoList.forEach((v, index) => {
							this.tableStatusList.forEach(item => {
								if (v.tableName == item) {
									v.status = false
									meg += `${v.name}、`
									let megs = meg.substring(0, meg.length - 1)
									this.noticeText = `${megs}单证未填写`
								}
							})
						})
					}
				}).catch((error) => {
					// 在reject时执行的回调函数
					console.error(error);
				});
			},
			toGo(url) {
				if (url != "") {
					uni.setStorageSync('shipWorkTitle', this.shipName)
					uni.navigateTo({
						url: `/pages/shipWork/${url}`
					})
				}
			},
		}
	}
</script>

<style lang="less" scoped>
	.documentList {
		.container {
			padding: 30px 20px;
			min-height: calc(100vh - 119px);

			.workBox {
				background-color: #fff;
				margin-bottom: 20px;
				padding: 25px 16px;
			}

			.title {
				display: flex;

				image {
					width: 18px;
					height: 18px;
					margin-top: 3px;
				}

				text {
					margin-left: 10px;
					font-size: 16px;
					font-weight: bold;
				}
			}

			.ul {
				display: flex;
				flex-wrap: wrap;

				.li {
					margin: 10px 20px;
					width: 195px;
					height: 70px;
					line-height: 70px;
					box-shadow: 1px 1px 6px 0 rgba(52, 52, 52, 0.20);
					border-radius: 8px;
					display: flex;
					position: relative;
					overflow: hidden;

					image {
						width: 38px;
						height: 38px;
						margin: 16px;
					}

					p {
						color: #23262E;
						font-size: 16px;
						font-weight: bold;
					}

					.uploadStatus {
						padding: 0 8px;
						height: 20px;
						line-height: 20px;
						background: #FFF7EE;
						border-radius: 4px;
						color: #FC8300;
						position: absolute;
						right: 0;
						top: 0;
					}
				}
			}
		}
	}
</style>