<template>
	<view class="todo-page">
		<view class="card">
			<uni-card margin="0" :is-shadow="true">
				<u--form labelPosition="left" labelWidth="auto" labelAlign="center" :model="model" :rules="rules"
					ref="wForm" errorType="border-bottom">
					<view v-if="model.Nav_StandardCreate" v-html="model.Nav_StandardCreate.NAME" style="text-align: center;font-weight: bold;font-size: 1.5em;margin: 20px 0;"></view>
					<rich-text autoHeight v-html="model.FILE_CONTENT" border="none" disabled></rich-text>
				</u--form>
			</uni-card>
		</view>

		<view class="bottom-button">
			<button type="primary" @click="submit1" v-if="BtnUserDisplay">签订</button>
			<button type="primary" @click="submit2" v-if="BtnChargeUserDisplay">主管签订</button>
		</view>
	</view>
</template>

<script>
	import {
		mapState,
		mapMutations
	} from 'vuex'
	import {
		extendFilterGroup,
		extendGroupRule,
		extendInclude,
		extendOrder,
		extendRule,
		guid,
		initFilter,
		initFilterGroup
	} from '../../../../utils/common'
	import {
		getRequest,
	} from '../../../../services/apply/FOServices/FOServices';
	import config from '../../../../config/common'

	export default {
		data() {
			return {
				model: {},
				options: [{
					text: '删除',
					style: {
						backgroundColor: '#f56c6c'
					}
				}],
				rules: {
					'TITLE': {
						type: 'string',
						required: true,
						trigger: ['blur', 'change']
					}
				},
				comPickerInfo: {
					showSheet: false,
					columns: [],
				},
				currentOperateUser: {},
				showPopup: false,
				tableKey: '0',
				TaskID: '',
				isLoadOK: false,
				ORG_ID: uni.getStorageSync('orgId'),
				BtnUserDisplay: false,
				BtnChargeUserDisplay: false,
				userId:uni.getStorageSync('appInfo').User["ID"],
			}
		},
		onLoad(option) {
			this.TaskID = option.taskID ? option.taskID : '';
			this.model.ID = option.ID ? option.ID : '';
			this.loadData();
		},
		methods: {
			loadData() {
				const json = initFilter(this.ORG_ID)
				extendInclude(json, 'Nav_SafePdtSignedPost.Nav_User.Nav_UserSignFiles.Nav_ImgFile.Nav_File');
				extendInclude(json, 'Nav_SafePdtSignedPost.Nav_ChargeUser.Nav_UserSignFiles.Nav_ImgFile.Nav_File');
				extendInclude(json, 'Nav_StandardCreate');
				extendRule(json, 'ID', 1, this.model.ID)
				getRequest(json, "/OG/OGSafePdtSigned/FullGet").then(res => {
					this.model = res;
					let findChargeUser = res.Nav_SafePdtSignedPost.find(item => item.CHARGE_USER_ID == this.userId && item.CHARGE_DEAL_STATUS == 0);
					if (findChargeUser != undefined) {
						this.BtnChargeUserDisplay = true;
					} else {
						let finduser = res.Nav_SafePdtSignedPost.find(item => item.USER_ID == this.userId && item.DEAL_STATUS == 0);
						if (finduser != undefined) {
							this.BtnUserDisplay = true;
						}
					}

				})
			},
			submit1() {
				let json = {};
				json.ID = this.model.ID;
				json.TaskID = this.TaskID;
				getRequest(json, "/OG/OGSafePdtSigned/UserAgree").then(res => {
					if (res) {
						uni.$showMsgFunc('操作成功!', () => {
							uni.navigateBack()
						}, 'success', 1000)
					}
				})
			},
			submit2() {
				let json = {};
				json.ID = this.model.ID;
				json.TaskID = this.TaskID;
				getRequest(json, "/OG/OGSafePdtSigned/ChargeUserAgree").then(res => {
					if (res) {
						uni.$showMsgFunc('操作成功!', () => {
							uni.navigateBack()
						}, 'success', 1000)
					}
				})
			},
		}
	}
</script>

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

	.todo-page {
		padding: 16px 16px 70px;
	}
</style>