<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="END_TIME" borderBottom>
						<u--input v-model="model.END_TIME" border="none" inputAlign="right" disabled
							disabledColor="#fff"></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" border="none"
							inputAlign="right" disabled disabledColor="#fff"></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" border="none" inputAlign="right"
							disabled disabledColor="#fff"></u--input>
					</u-form-item>
					<u-form-item label="工余事件数：" prop="Nav_ReplyUser" borderBottom>
						<u--input v-model="model.EVENT_COUNT" border="none" inputAlign="right" disabled
							disabledColor="#fff"></u--input>
					</u-form-item>
					<u-form-item label="对比数：" prop="Nav_ReplyUser" borderBottom>
						<u--input v-model="model.EVENT_COMPARE" border="none" inputAlign="right" disabled
							disabledColor="#fff"></u--input>
					</u-form-item>
				</u--form>
			</uni-card>
		</view>
		<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" accordion>
							<uni-card style="margin-bottom: 16px;" margin="0" spacing="0" :is-shadow="false"
								v-if="items" v-for="(item, index) in items">
								<u-collapse-item :title="(index + 1) + '. ' + item.TYPE_SHOW+' | '+item.DESC">
									<view slot="right-icon" class="row-action"></view>
									<u-form-item label="事件类型：" prop="TYPE_SHOW" borderBottom>
										<u--input v-model="item.TYPE_SHOW" border="none" disabled disabledColor="#fff"
											inputAlign="right"></u--input>
									</u-form-item>
									<u-form-item label="事件描述：" prop="DESC" borderBottom>
									</u-form-item>
									<u-textarea autoHeight v-model="item.DESC" disabled></u-textarea>
									<u-form-item label="有意见人员：" prop="NAME" borderBottom>
										<u--input v-model="item.NAME" border="none" disabled disabledColor="#fff"
											inputAlign="right"></u--input>
									</u-form-item>
									<u-form-item label="反馈意见：" prop="REPLY" borderBottom>
									</u-form-item>
									<u-textarea autoHeight v-model="item.REPLY" disabled></u-textarea>
								</u-collapse-item>
							</uni-card>
						</u-collapse>
					</u--form>
				</view>
			</view>
		</u-sticky>
		<view class="bottom-button">
			<button type="primary" @click="submit">提交</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: {
					Nav_Items: []
				},
				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,
				showDelModalIndex: undefined,
				ORG_ID: uni.getStorageSync('orgId'),
				isReply: false,
				items: [],
			}
		},
		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_User")
				extendInclude(json, "Nav_Department")
				extendInclude(json, "Nav_Details")
				extendInclude(json, "Nav_Details.Nav_User")
				extendInclude(json, "Nav_Details.Nav_Items")
				extendRule(json, 'ID', 1, this.model.ID)
				getRequest(json, "/OG/EventGet/Get").then(res => {
					this.model = res;
					res.Nav_Details.forEach(it => {
						if (it.STATUS == 2) {
							it.Nav_Items.forEach(i => {
								if (i.DESC) {
									this.items.push({
										ID: i.ID,
										TYPE: i.TYPE,
										DESC: i.DESC,
										NAME: it.Nav_User.NAME,
										REPLY: i.REPLY
									})
								}
							});
						}
					})
					this.items.forEach(item => {
						if (item.TYPE == 0) {
							item.TYPE_SHOW = "交通"
						} else if (item.TYPE == 1) {
							item.TYPE_SHOW = "火灾"
						} else if (item.TYPE == 2) {
							item.TYPE_SHOW = "爆炸"
						} else if (item.TYPE == 3) {
							item.TYPE_SHOW = "溺水"
						} else if (item.TYPE == 4) {
							item.TYPE_SHOW = "中毒"
						} else if (item.TYPE == 5) {
							item.TYPE_SHOW = "触电"
						} else if (item.TYPE == 6) {
							item.TYPE_SHOW = "其他"
						}
					})
				})
			},
			submit() {
				const json = initFilter(this.ORG_ID, this.model.ID);
				json.Parameter1 = this.TaskID;
				getRequest(json, "/OG/OGEventGet/Agree").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>