<template>
	<view class="page-wrap" v-bind:style="{paddingBottom:paddingBottom+'px'}">
		<uni-card margin="0" :is-shadow="true">
			<u--form labelPosition="left" labelWidth="auto" labelAlign="center" :model="model">
				<u-form-item label="名称：" prop="NAME" borderBottom>
					<u--input v-model="model.NAME" border="none" inputAlign="right" disabled
						disabledColor="#ffffff"></u--input>
				</u-form-item>
				<u-form-item label="需求类别	：" prop="Nav_LawType" borderBottom>
					<u--input v-if="model.Nav_LawType" v-model="model.Nav_LawType.NAME" border="none" slot="right"
						inputAlign="right" disabled disabledColor="#ffffff"></u--input>
				</u-form-item>
			</u--form>
		</uni-card>
		<u-sticky offset-top="20">
			<view class="sub-form">
				<view class="sub-form-wrap">
					<u--form labelPosition="left" labelWidth="auto" labelAlign="center" errorType="border-bottom"
						ref="sForm">
						<u-collapse :border="false" :value="['0']">
							<uni-card style="margin-bottom: 16px;" margin="0" spacing="0" :is-shadow="false"
								v-for="(item, index) in model.Nav_LawVersion">
								<u-collapse-item :title="index + 1 + '. '+item.VERSION_NUM" :name="index">
									<u-form-item label="入库时间：" prop="ENTER_TIME" borderBottom>
										<u--input disabled disabledColor="#fff"
											v-model="item.ENTER_TIME.substring(0,10)" border="none" slot="right"
											inputAlign="right"></u--input>
									</u-form-item>
									<u-form-item label="制修订日期：" prop="EXECUTE_TIME" borderBottom>
										<u--input disabled disabledColor="#fff"
											v-model="item.EXECUTE_TIME.substring(0,10)" border="none" slot="right"
											inputAlign="right"></u--input>
									</u-form-item>
									<u-form-item label="施行日期：" prop="UPDATE_TIME" borderBottom>
										<u--input disabled disabledColor="#fff"
											v-model="item.UPDATE_TIME.substring(0,10)" border="none" slot="right"
											inputAlign="right"></u--input>
									</u-form-item>
									<u-form-item label="状态：" prop="VERSION_STATUS" borderBottom>
										<u--input disabled disabledColor="#fff" v-model="item.VERSION_STATUS"
											border="none" slot="right" inputAlign="right"></u--input>
									</u-form-item>
									<u-form-item label="附件" prop="flowFiles" borderBottom>
										<view class="link-content">
											<view class="link-content-border" v-for="itemChild in item.Files">
												<u-link :href="itemChild.url" :text="itemChild.name" color="#005BEA">
												</u-link>
											</view>
										</view>
									</u-form-item>
								</u-collapse-item>
							</uni-card>
						</u-collapse>
					</u--form>
				</view>
			</view>
		</u-sticky>
		<view class="bottom-button">
			<button type="primary" class="bottom" v-if='isLoadOK&&tableKey==1&&!isApprove'
				@click="onTableBtnAgree">签到</button>
			<button type="primary" class="bottom" v-if='isLoadOK&&tableKey==1&&isApprove'
				@click="onTableBtnApprove">审阅</button>
		</view>
	</view>
</template>

<script>
	import {
		initFilter,
		extendRule,
		extendInclude
	} from '../../../../utils/common'
	import {
		getRequest,
	} from '../../../../services/apply/FOServices/FOServices'
	import '../../../../utils/showMsg.js'
	import color from '../../../../uni_modules/uview-ui/libs/config/color'
	import config from '../../../../config/common'
	export default {
		data() {
			return {
				ID: "",
				model: {},
				TaskID: "",
				tableKey: '0',
				isLoadOK: false,
				paddingBottom: '170',
				orgId: uni.getStorageSync('orgId'),
				isApprove: false
			}
		},
		onLoad(option) {
			this.ID = option.ID;
			this.TaskID = option.taskID;
			this.tableKey = option.tableKey ? option.tableKey : '0'
			this.loadData()
		},
		methods: {
			loadData() {
				const json = initFilter(this.orgId, "", "CODE", 1)
				extendRule(json, 'ID', 1, this.ID);
				extendInclude(json, 'Nav_LawType');
				extendInclude(json, 'Nav_LawVersion');
				extendInclude(json, 'Nav_LawVersion.Nav_Files.Nav_ImgFile.Nav_File');
				extendInclude(json, 'Nav_LawSCSystem.Nav_SCSystem');
				getRequest(json, "/LR/Law/Get").then(res => {

					this.model = res
					let strUserFiles = [{
						url: '',
						name: ''
					}]
					if (res.Nav_LawVersion && res.Nav_LawVersion.length > 0) {
						for (let i = 0; i < res.Nav_LawVersion.length; i++) {
							this.model.Nav_LawVersion[i].Files = [];
							if(res.Nav_LawVersion[i].Nav_Files.length>0){
								for (let j = 0; j < res.Nav_LawVersion[i].Nav_Files.length; j++) {
									this.model.Nav_LawVersion[i].Files.push({
										url: config.uni_app_web_source_url + res.Nav_LawVersion[i].Nav_Files[j]
											.Nav_ImgFile.Nav_File.FILE_PATH,
										name: res.Nav_LawVersion[i].Nav_Files[j].Nav_ImgFile.FILE_NAME
									})
								}
							}
							
						}
					}
					this.model.Nav_LawVersion.Nav_Files = strUserFiles;
					this.isLoadOK = true;
				})
			},
			returnModel(level) {
				let str = '';
				if (level == undefined) {
					return str;
				}
				if (level.indexOf('1') >= 0) {
					str += '讲授法 ';
				}
				if (level.indexOf('2') >= 0) {
					str += '视听法 ';
				}
				if (level.indexOf('3') >= 0) {
					str += '研讨法 ';
				}
				if (level.indexOf('4') >= 0) {
					str += '演示法 ';
				}
				return str;
			},
			transLevel(level) {
				if (level == 0) {
					return '部门 ';
				}
				if (level == 1) {
					return '车间 ';
				}
				if (level == 2) {
					return '班组 ';
				}
				if (level == 3) {
					return '公司 ';
				}
			},
			onTableBtnAgree() {
				const json = initFilter(this.orgId)
				json.Parameter1 = this.ID;
				json.Parameter2 = this.TaskID;
				getRequest(json, "/SE/SEThreeLevelSafeTrainRecord/PersonalAgree").then(res => {
					if (res) {
						uni.$showMsgFunc('操作成功!', () => {
							uni.navigateBack()
						}, 'success', 1000)
					}
				})
			},
			onTableBtnApprove() {
				const json = initFilter(this.orgId)
				json.Parameter1 = this.ID;
				json.Parameter2 = this.TaskID;
				getRequest(json, "/SE/SEThreeLevelSafeEduCard/Approve").then(res => {
					if (res) {
						uni.$showMsgFunc('操作成功!', () => {
							uni.navigateBack()
						}, 'success', 1000)
					}
				})
			}
		},
		computed: {

		}
	}
</script>

<style>
	@import url("@/style/css/editTemplate.css");

	.btn-wrap {
		position: fixed;
		bottom: 0;
		left: 0;
		width: 100%;
		box-sizing: border-box;
		padding: 16px;
		z-index: 1000;
		background: #fff;
		box-shadow: 0 -1px 2px 0 rgba(0, 0, 0, .05);
	}

	.buttons {
		margin-top: 10px;
		display: flex;
		justify-content: space-between;
	}

	.buttons .first-btn {
		margin-right: 20px;
	}
</style>