<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">
					<u-form-item label="征集日期：" prop="START_TIME" borderBottom>
						<u--input v-model="model.START_TIME" disabled disabledColor="#fff" border="none"
							inputAlign="right"></u--input>
					</u-form-item>
					<u-form-item label="征集部门：" prop="Nav_Department" borderBottom>
						<u--input v-if="model.Nav_Department" v-model="model.Nav_Department.NAME" disabled disabledColor="#fff" border="none"
							inputAlign="right"></u--input>
					</u-form-item>
					<u-form-item label="征集人员：" prop="Nav_User" borderBottom>
						<u--input v-if="model.Nav_User" v-model="model.Nav_User.NAME" disabled disabledColor="#fff" border="none"
							inputAlign="right"></u--input>
					</u-form-item>
					<u-form-item label="征集截止时间：" prop="END_TIME" borderBottom @click="showCheckDate2 = true;">
						<u--input v-model="model.END_TIME" disabled disabledColor="#fff" placeholder="请选择结束时间"
							border="none" inputAlign="right"></u--input>
						<u-icon style="margin-left: 4px;" slot="right" name="arrow-down"></u-icon>
					</u-form-item>
				</u--form>
			</uni-card>
		</view>
		<view class="bottom-button">
			<button type="primary" @click="submit">提交</button>
		</view>
		<u-datetime-picker :show="showCheckDate2" mode="datetime" v-model='currentTime' @confirm="handleCheckDate2"
			@close="showCheckDate2 = false;" @cancel="showCheckDate2 = false;"></u-datetime-picker>
	</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: {
					ORG_ID: "",
				},
				options: [{
					text: '删除',
					style: {
						backgroundColor: '#f56c6c'
					}
				}],
				rules: {
					'JOB_CONTENT': {
						type: 'string',
						required: true,
						trigger: ['blur', 'change']
					}
				},
				comPickerInfo: {
					showSheet: false,
					columns: [],
					title: '',
					dataIndex: undefined,
					formIndex: undefined,
					name: ''
				},
				currentTime:uni.$u.timeFormat(new Date(), 'yyyy-mm-dd hh:MM'),
				tableKey: '0',
				TaskID: '',
				showCheckDate2: false,
				ORG_ID: uni.getStorageSync('orgId')
			}
		},
		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_Department")
				extendInclude(json, "Nav_User")
				// TODO: id 未获取
				extendRule(json, 'ID', 1, this.model.ID)
				getRequest(json, "/OG/EventGet/Get").then(res => {
					this.model = res
				})
			},
			submit() {
				const ele = this.$refs
				ele['wForm'].validate().then(res => {
					this.model.PUBLISH = "SaveAndNotify";
					if (this.TaskID != "") {
						this.model.TaskID = this.TaskID;
					}
					if (this.model.ORG_ID == "") {
						this.model.ORG_ID = this.ORG_ID;
					}
					getRequest(this.model, "/OG/OGEventGet/FullUpdate").then(res => {
						if (res) {
							uni.$showMsgFunc('操作成功!', () => {
								uni.navigateBack()
							}, 'success', 1000)
						}
					})
				}).catch(err => {
					uni.$showErrorInfo('请检查必填项，必填项不能为空')
				})
			},
			handleCheckDate2(e) {
				this.showCheckDate2 = false;
				this.model.END_TIME = uni.$u.timeFormat(e.value, 'yyyy-mm-dd hh:MM:ss');
			},
		}
	}
</script>

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

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