<template>
	<view class="index">
		<scroll-view scroll-y="true" @scrolltolower="scrolltolower">
			<view class="list">
				<view class="item" @tap="toDetail(item)" v-for="item in tableData" :key="item.id">
					<view class="top">
						岗位名称:{{item.postName}}
					</view>
					<view class="content">
						<view>学号：{{item.stuNo}}</view>
						<view>姓名：{{item.stuName}}</view>
						<view>工作日期：{{item.workDate}}</view>
						<view>工作时长：{{ item.postType == "固定岗位A" ? item.workTime + "天" : item.workTime + "小时" }}</view>
					</view>
					<!-- <view class="form-item">
						<text class="label">学号</text>
						<text>{{leave.stuNo}}</text>
					</view>
					<view class="form-item">
						<text class="label">姓名</text>
						<text>{{leave.stuName}}</text>
					</view>
					<view class="form-item">
						<text class="label">岗位名称</text>
						<text>{{leave.postName}}</text>
					</view>
					<view class="form-item">
						<text class="label">工作日期</text>
						<text>{{leave.workDate}}</text>
					</view>
					<view class="form-item">
						<text class="label">工作时长</text>
						<text>{{ leave.postType == "固定岗位A" ? leave.workTime + "天" : leave.workTime + "小时" }}</text>
					</view>
					<view class="form-item">
						<text class="label">审核状态</text>
						<DictType :types="get_qgzx_stu_post_status" :type="leave.applyStatus" />
					</view> -->

					<view class="status">
						<view class="bottom">
							<view class="edit" >
								<!-- compose -->
								<uni-icons color="#1890ff" type="compose" size="18"> 审批</uni-icons>
							</view>
						</view>
					</view>
					<!-- <view class="cancellation-leave" @tap="toCancellationLeave">
					销假
				</view> -->
				</view>
			</view>
		</scroll-view>
		<!-- 审核弹窗 -->
		<uni-popup ref="popup" type="center" background-color="#fff" :is-mask-click="false"
			border-radius="3px 3px 3px 3px">
			<view class="popup-content">
				<uni-forms ref="applyForm" :model="lookForm" label-width="148rpx">
					<uni-forms-item label="工作岗位">
						<uni-easyinput v-model="lookForm.postName" readonly />
					</uni-forms-item>

					<uni-forms-item label="主要工作">
						<uni-easyinput v-model="lookForm.mainWork" readonly type="textarea" />
					</uni-forms-item>

					<uni-forms-item label="工作附件">
						<image :src="baseUrl + lookForm.workMaterial" mode="" style="width: 200rpx; height: 200rpx;" />
					</uni-forms-item>

					<uni-forms-item label="工作日期">
						<uni-easyinput v-model="lookForm.workDate" readonly />
					</uni-forms-item>

					<uni-forms-item label="工作时长">
						<uni-easyinput v-model="lookForm.workTime" type="number" />
						<text>{{ lookForm.postType == '固定岗位A' ? '天' : '小时' }}</text>
						<text style="color: red;">*工作时长可修改</text>
					</uni-forms-item>
				</uni-forms>

				<view style="height: 1px; background-color: #e5e5e5; margin: 20rpx 0;"></view>

				<uni-forms ref="auditForm" :model="auditForm" label-width="148rpx">
					<uni-forms-item label="审核意见">
						<uni-data-checkbox v-model="auditForm.zdlsCmt" :localdata="zdlsCmt" />

						<!-- 
						<radio-group v-model="auditForm.zdlsCmt">
							<view class="uni-padding-wrap">
								<label class="radio">
									<radio value="通过" />通过
								</label>
								<label class="radio">
									<radio value="不通过" />不通过
								</label>
							</view>
						</radio-group> -->
					</uni-forms-item>

					<!-- 					<uni-forms-item label="指导老师签章">
						<view @tap="uploadSignature">
							<image v-if="auditForm.zdlsSign" :src="baseurl + auditForm.zdlsSign"
								style="width: 200rpx; height: 50rpx;" />
							<text v-else>点击上传</text>
						</view>
					</uni-forms-item> -->

					<uni-forms-item>
						<button @click="closePopup" type="primary" plain>关闭</button>
						<button @click="doAudit" type="primary" plain>审核</button>
					</uni-forms-item>
				</uni-forms>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	import {
		getOwnSign
	} from "@/api/workStudy/post";
	import DictType from "@/components/dict-type/dict-type.vue"
	import {
		doAudit,
		listZdls as getList,
		manyAudit
	} from "@/api/workStudy/worklog";
	import {
		getDicts,
	} from '@/api/system/dict/data.js';
	import {
		CheckImgExists,
		isEmpty
	} from "@/api/helpFunc";
	import {
		baseUrl
	} from "@/config.js";

	export default {
		components: {
			DictType
		},
		data() {
			return {
				isEmpty,
				tableData: [],
				get_qgzx_stu_post_status: [],
				auditForm: {
					id: null,
					zdlsCmt: null,
					zdlsSign: null
				},
				lookForm: {},
				applyForm: {},

				lookV: false,
				baseUrl: baseUrl,
				zdlsCmt: [{
					text: '通过',
					value: '通过'
				}, {
					text: '不通过',
					value: '不通过'
				}],
			}
		},
		created() {
			this.getList();
		},
		methods: {
			toDetail(item) {
				uni.navigateTo({
					url: "./detail?detailData=" + JSON.stringify(item)
				})
			},
			closePopup() {
				this.$refs.popup.close()
			},
			async doAudit() {
				let sdata = {
					...this.auditForm
				};
				sdata.workTime = this.lookForm.workTime;

				if (isEmpty(sdata.workTime)) {
					this.$message.info("请输入工作时间");
					return;
				}

				if (sdata.workTime <= 0 || sdata.workTime > 24) {
					this.$message.info("请输入正确的工作时间");
					return;
				}
				if (isEmpty(sdata.zdlsCmt)) {
					this.$message.info("请选择是否通过");
					return;
				}

				if (isEmpty(sdata.zdlsSign)) {
					this.$message.info("请上传签章");
					return;
				}

				// if (!CheckImgExists(this.baseurl + sdata.zdlsSign)) {
				// 	this.$message.info("签名失效，请重新上传");
				// 	return;
				// }

				let res = await doAudit(sdata);
				if (res.code == 200) {
					uni.showToast({
						title: res.msg,
						icon: "success"
					});
					this.getList();
					this.lookV = false;
				}
			},
			async getList() {
				let res = await getList(this.queryParams);
				if (res.code == 200) {
					this.tableData = [...res.rows];
					this.total = res.total;
				}
			},
			async qgzx_stu_post_status() {
				let res = await getDicts('qgzx_stu_post_status');
				this.get_qgzx_stu_post_status = res.data;
			},
			async lookVClick(row) {

				let res1 = await getOwnSign();
				if (res1.code == 200) {
					let data = {
						...res1.data
					};

					this.lookForm = {};
					this.lookForm = {
						...row
					};
					this.auditForm.id = this.lookForm.id;
					this.auditForm.zdlsSign = data.signature;
					this.signImg = baseUrl + data.workMaterial;
					this.lookV = true;
					this.$refs.popup.open('centent')
				}

			},
		}
	}
</script>

<style lang="scss" scoped>
	.index {
		background-color: #F5F5F7;

		scroll-view {
			height: calc(100vh - 10px);

			.no-more {
				text-align: center;
				color: gray;
				padding-bottom: 10px;
			}

			.empty {
				display: flex;
				flex-direction: column;
				align-items: center;
				margin-top: 200rpx;
				color: #9E9E9E;
				font-size: 36rpx;

				image {
					width: 250rpx;
					margin-bottom: 50rpx;
				}
			}
		}

		.list {
			padding: 20rpx 40rpx 15rpx 40rpx;

			.item {
				background-color: white;
				margin-bottom: 20rpx;
				padding: 40rpx 40rpx 80rpx;
				border-radius: 16px;
				border-bottom-right-radius: 0;
				position: relative;

				.top {
					display: flex;
					justify-content: space-between;
					border-bottom: 1px solid #F5F5F7;
					padding-bottom: 20rpx;

					.uni-icons {
						opacity: 0.5;
					}
				}

				.content {
					padding-top: 20rpx;

					.level {
						display: flex;

					}

					&>view:not(:last-child) {
						margin-bottom: 15rpx;

						.progress {
							color: #1890FF;
						}
					}

					.status {
						position: absolute;
						bottom: 0;
						right: 0;
						color: white;

						.status-text {
							position: absolute;
							bottom: 15px;
							right: 8%;
							font-size: 35rpx;
						}

						.triangle-right {
							width: 0;
							height: 0;
							/* 上边框设置为透明 */
							border-left: 120px solid transparent;
						}

						&.submit {
							color: #202020;

							.triangle-right {
								/* 左边框设置为与文本相同的颜色 */
								border-bottom: 100px solid #D7D7D7;
							}
						}

						&.agree {
							.triangle-right {
								/* 左边框设置为与文本相同的颜色 */
								border-bottom: 100px solid #2FB15B;
							}
						}

						&.refuse {
							.triangle-right {
								/* 左边框设置为与文本相同的颜色 */
								border-bottom: 100px solid #FF759F;
							}
						}
					}
				}

				.bottom {
					position: absolute;
					right: 0;
					bottom: 10px;

					button {
						margin: 0;
						background-color: transparent;
						margin-right: 10px;
						padding: 0px 10px;
						height: 32px;
						line-height: 32px;
						font-size: 28rpx;
						width: 160rpx;
						border: 1px solid #007aff;
						color: #007aff;
					}
				}
			}
		}

	}

	.popup-content {
		align-items: center;
		padding: 15px;
		background-color: #fff;
	}
</style>