<template>
	<div>
		<base-form ref="customForm" :formRow="formRow" :isFunBtn="false" @elDialogClick="elDialogClick"
			@onSubmit="getSubmit" :rules="rules" >
			<div slot="bm_IsAttachment" flex="cross:center main:justify" style="height: 100%;">
				<el-switch v-model="ruleForm.bm_IsAttachment" active-text="开启" inactive-text="关闭" :active-value="1"
					@change="fileSwitch = !fileSwitch" :inactive-value="0"></el-switch>
				<el-input v-if="ruleForm.bm_IsAttachment == 1" placeholder="归档文件夹名称" v-model="ruleForm.bm_AttachmentFolder"
					style="width: 60%;"></el-input>
			</div>
		</base-form>
		<!-- 选择上级菜单 -->
		<base-dialog :closeEscape="true" :showClose="true" :closeModal="false" @handleConfirmClick="menuConfirmClick"
			:appendBody="true" :dialogVisible.sync="menuDialog" class="userDialog" title="选择上级菜单" width="700px"
			top="10vh" :footerShow="true" >
			<div class="organizationBody">
				<base-layout title="菜单树" style="width: 45%;min-height: 300px;overflow: auto;" 
					:isPage="false" :mainHight="menuHight" :operateButtonSwitch="false">
					<div slot="main">
						<base-tree ref="baseTree" :isCenter="false" :isSaveBtn="false" :Allshow="false"
							:expandAll="false" :showCheckbox="false" :menuData="menuData"
							@handleNodeClick="menuTreeClick">
						</base-tree>
					</div>
				</base-layout>
				<base-layout title="菜单及上级菜单" style="width: 45%;" :operateButtonSwitch="false" :isPage="false"
					:mainHight="menuHight">
					<div slot="main" style="padding: 10px;">
						<div flex="cross:center">
							<label style="width: 35%;">模块名称</label>
							<el-input style="flex:1" v-model="dialogFrom.label"></el-input>
						</div>
					</div>
				</base-layout>
			</div>
		</base-dialog>
	</div>
</template>
<script>
	import bus from './eventBus'
	import baseForm from "@/components/base/baseNewForm"
	import baseTable from "@/components/base/baseTable"
	import baseTree from "@/components/base/BaseMenuTree"
	import baseDialog from "@/components/base/BaseNewDialog"
	import baseLayout from "@/components/base/baseLayout"
	import {
		GetMenuTree
	} from '@/api/apis/menuManage'
	import {
		getInfo,
	} from '@/utils/auth'
	import dialogConfigData from "./dialogConfigData"
	import {
		SaveData,
		GetBillData
	} from '@/api/apis/documentManagement'
	export default {
		components: {
			baseForm,
			baseLayout,
			baseTree,
			baseDialog,
			baseTable
		},
		data() {
			return {
				formRow: dialogConfigData.informationFormRow,
				rules: dialogConfigData.informationRules,
				menuDialog: false,
				menuHight: 'auto',
				menuData: [],
				dialogFrom: {},
				ruleForm: {},
				fileSwitch: false
			}
		},
		mounted() {

		},
		methods: {
			initPage(id) {
				this.$refs.customForm.resetFields()
				this.$refs.customForm.getField('bm_CreatePersonID', JSON.parse(getInfo()).personID)
				this.$refs.customForm.getField('bm_id', 0)
				this.formRow[1].elCol[1].disabled = false
				if (id) {
					this.getDetail(id)
				}
			},
			elDialogClick(row, index) {
				if (row.label == '上级菜单') {
					this.menuDialog = true
					this.getMenuData()
				}
			},
			getSubmit() {},
			// 菜单选择
			menuConfirmClick() {
				// this.$refs.customForm.incomingParameters(this.dialogFrom)
				this.$refs.customForm.getField('bm_parentMenuId', this.dialogFrom.id)
				this.$refs.customForm.getField('fatherMenuName', this.dialogFrom.label)
				this.menuDialog = false
			},
			//菜单树点击
			menuTreeClick(data) {
				this.dialogFrom = data
			},
			saveDto(type) {
				this.$refs.customForm.$refs['ruleForm'].validate(valid => {
					if (valid) {
						this.saveForm(type)
					}
				})
			},
			// 获得树状图
			async getMenuData() {
				let res = await GetMenuTree({})
				if (res.code == 1) {
					this.menuData = JSON.parse(res.data[0])
				}
			},
			async saveForm(type) {
				const loading = this.$loading({
					lock: true,
					text: '正在提交，请稍等',
					spinner: 'el-icon-loading',
					background: '#fff'
				});
				setTimeout(() => {
					loading.close();
				}, 10000);
				let params = {
					...this.$refs.customForm.ruleForm
				}
				let res = await SaveData({
					dataMain: params,
					tableCoulmnData: [],
					tablesData: []
				})
				if (res.success == 'true') {
					this.$vmNews('保存成功', 'success')
					loading.close();
					this.$refs.customForm.getField('bm_id', res.data[0])
					this.$emit('ingormationSave', type, res.data[0])
				}
			},
			async getDetail(id) {
				this.openLoading('details')
				let res = await GetBillData({
					id: id
				})
				// console.log(res)
				if (res.success == 'true') {
					this.$refs.customForm.choiceAssignment(res.data[0])
					this.ruleForm = this.$refs.customForm.ruleForm
					this.fileSwitch = this.ruleForm.bm_IsAttachment == 1 ? true : false
					bus.$emit('bm_DataSourceSQL',res.data[0].bm_DataSourceSQL)
					res.data[1].forEach(el=>{
						if(el.isCreate == 1){
							this.formRow[1].elCol[1].disabled = true
						}
					})
				}
			}
		}
	}
</script>
<style scoped lang="scss">
	.organizationBody {
		display: flex;
		justify-content: space-evenly;
		background-color: #f2f3f4;
		padding: 10px;
		max-height: 400px;
		overflow: auto;
	}
</style>
