<template>
	<view class="modultInfo">
		<headers :showBack="true" :themeType="'white'">
			<view class="headerName">
				{{type==1?'合同':type==2?'体检':type==3?'保险':type==4?'安全教育':''}}
			</view>
		</headers>
		<view class="content">
			<view class="info_wrap" v-if="type==1">
				<view class="title">
					<text class="state1" v-if="info.length==0">未签订</text>
					<text class="state2" v-else>已签订</text>
				</view>
				<view class="detailInfo" v-for="(item,index) in info" :key="index">
					<view>合同编号：{{item.contractNumber}}</view>
					<view>合同类型：{{item.contractType==1?'纸质合同':item.contractType==2?'电子合同':''}}</view>
					<view>合同期限：{{item.laborContractType==1?'固定期限合同':item.laborContractType==2?'以完成一定工作为期限的合同':''}}</view>
					<view>生效日期：{{item.contractBeginDate}}</view>
					<view>失效日期：{{item.contractEndDate}}</view>
					<view>工资核定方式：{{
                    item.wagesVerificationType == 1
                      ? "按天"
                      : item.wagesVerificationType == 2
                      ? "按小时"
                      : item.wagesVerificationType == 3
                      ? "按月"
                      : item.wagesVerificationType == 4
                      ? "按件"
                      : ""
                  }}</view>
					<view>合同附件：
						<text v-for="(val, valIndex) in item.fileList" @click="handlePreview(val.url)" :key="valIndex" style="cursor: pointer;margin-right:5px">{{val.name}}</text>

					</view>
				</view>
			</view>
			<view class="info_wrap" v-if="type==2">
				<view class="title">
					<text class="state1" v-if="info.length==0">未体检</text>
					<text class="state2" v-else>已体检</text>
				</view>
				<view class="detailInfo" v-for="(item,index) in info" :key="index">
					<view>身高：{{item.personHeight}}cm</view>
					<view>体重：{{item.personWeight}}kg</view>
					<view>体检日期：{{item.physicalsTime}}</view>
					<view>体检状态：{{item.state==1?'未体检':item.state==2?'体检合格':item.state==1?'体检不合格':''}}</view>
					<view>结论：{{item.conclusion}}</view>
				</view>
			</view>
			<view class="info_wrap" v-if="type==3">
				<!-- <view class="title">
					<text class="state1" v-if="info.length==0">未购买</text>
					<text class="state2" v-else>已购买</text>
				</view> -->
				<view class="detailInfo" v-for="(item,index) in info" :key="index">
					<view>保险购买日期：{{item.insuranceTime}}</view>
					<view>保险到期日期：{{item.expireTime}}</view>
					<view>保险状态：{{item.state==1?'未购买':item.state==2?'已购买':''}}</view>
					<view>险种：{{item.insuranceType}}</view>
					<view>城乡居民医疗保险：{{item.medicalInsurance==1?'否':item.medicalInsurance==2?'是':''}}</view>
					<view>城乡居民养老保险：{{item.endowmentInsurance==1?'否':item.endowmentInsurance==2?'是':''}}</view>
				</view>
			</view>
			<view class="info_wrap" v-if="type==4">
				<view class="title">
					<text class="state1" v-if="info.length==0">未培训</text>
					<text class="state2" v-else>已培训</text>
				</view>
				<view class="detailInfo" v-for="(item,index) in info" :key="index">
					<view>培训类型： {{
                    item.eduType == 1
                      ? "入场三级教育"
                      : item.eduType == 2
                      ? "定期安全教育"
                      : item.eduType == 3
                      ? "安全技术交底"
                      : item.eduType == 4
                      ? "VR安全教育"
                      : ""
                  }}</view>
					<view>培训主题：{{item.eduCourseName}}</view>
					<view>培训课时：{{item.eduClasshour}}</view>
					<view>培训得分：{{item.score}}</view>
					<view>是否合格：{{item.isQualified == 1 ? "合格":item.isQualified == 2? "不合格":''}}</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				type: 1,
				info: null
			}
		},
		onLoad(option) {
			this.type = Number(option.type);
			this.info = uni.getStorageSync('moduleInfo');
			this.getFileInfo();
		},
		methods: {
			//获取附件信息
			getFileInfo() {
				let data = JSON.parse(JSON.stringify(this.info))
				if (this.type == 1) {
					//获取合同照片
					if (data.length > 0 && data[0].imageUrl) {
						let arr = data[0].imageUrl.split(",");
						let fileList = [];
						arr.forEach((item) => {
							let valArr = item.split("*");
							fileList.push({
								name: valArr[0],
								url: valArr[1]
							});
						});
						data[0].fileList = fileList;
					} else {
						if (data.length > 0) {
							data[0].fileList = [];
						}
					}
				}
				this.info = data;
			},
			//预览文件                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               
			handlePreview(url) {
				let type = url.split('.')[1];
				if (type == 'doc' || type == 'xls' || type == 'ppt' || type == 'pdf' || type == 'docx' || type == 'xlsx' || type ==
					'pptx') {
					uni.openDocument({
						filePath: this.url_config + 'image/' + url,
					})
				}else{
					let fileList = [];
					fileList = [this.url_config + 'image/' + url];
					uni.previewImage({
						current: 0,
						urls: fileList
					})
				}
				
			},
		}
	}
</script>

<style>
	.info_wrap {
		text-align: center;
	}

	.detailInfo {
		text-align: left;
		padding: 10px 30rpx;
		box-sizing: border-box;
		margin: 10px 0 20px;
		box-shadow: 0 0px 10px rgba(220, 220, 220, 0.8);
		font-size: 30rpx;
		line-height: 28px;
	}

	.info_wrap .title {
		font-size: 30rpx;
		margin-top: 8px;
	}

	.title .state1 {
		color: red;
	}

	.title .state2 {
		color: #4181FE;
	}
</style>
