<template>
	<div class="inputs">
		<el-tooltip
			:disabled="inputWriteable && !errors.has('custom-form.' + inputName)"
			:placement="tooltipplacement || $tooltipplacement"
		>
			<div slot="content">{{ errors.first('custom-form.' + inputName) }}</div>
			<div
				v-if="inputWriteable"
				class="el-select"
				style="width: 100%;"
				@click="showDialog"
			>
				<div
					ref="tagSpans"
					:style="{ width: 'calc(100% - ' + inputSuffixWidth + 'px)' }"
					class="el-select__tags"
				>
					<span>
						<span
							v-for="(item, index) in inputVal"
							:key="item.value"
							class="el-tag el-tag--info el-tag--small"
							@click.stop
						>
							<span class="el-select__tags-text">{{ item.value }}</span>
							<i
								class="el-tag__close el-icon-close"
								@click="removeSelectOrg(index)"
							></i>
						</span>
					</span>
				</div>
				<div class="el-input el-input--suffix">
					<input
						v-model="inputVal"
						v-validate="inputValidate"
						:name="inputName"
						:placeholder="placeholderBo"
						:style="{ height: inputSuffixHeight + 'px' }"
						autocomplete="off"
						class="el-input__inner"
						readonly="readonly"
						type="text"
					/>
					<span ref="inputSuffix" class="el-input__suffix">
						<span class="el-input__suffix-inner">
							<el-button slot="append" size="mini" type="info">
								<i
									:class="
										this.custdialog.icon
											? 'el-input__icon ' + this.custdialog.icon
											: 'el-input__icon icon-department'
									"
									:style="{
										fontSize: '17px',
										lineHeight: inputSuffixHeight + 'px',
									}"
								></i
								>{{ custdialog.name }}</el-button
							>
						</span>
					</span>
				</div>
			</div>
		</el-tooltip>
		<span v-if="!inputWriteable">
			<span
				v-for="item in inputVal"
				:key="item.value"
				class="el-tag el-tag--info el-tag--small"
				style="margin-right: 8px;"
				@click.stop
			>
				<span class="el-select__tags-text">{{ item.value }}</span>
			</span>
		</span>
		<el-dialog
			:before-close="dialogCancel"
			:close-on-click-modal="false"
			:title="this.customDialog.name"
			:visible.sync="customDialogShowList"
			append-to-body
			top="6vh"
			width="60%"
			@opened="afterOpen"
		>
			<el-container :style="style" style="overflow: auto;">
				<!-- 组合对话框树 -->
				<el-aside
					v-if="customDialog.style == 2"
					v-show="treeShow"
					style="width: 23%;"
				>
					<el-card>
						<div slot="header" class="clearfix">
							<span style="font-size: 16px;">{{ leftTreeTitle }}</span>
						</div>
						<el-tree
							ref="combinationTree"
							:check-on-click-node="true"
							:data="combinationTreeData"
							:load="loadTree"
							:node-key="nodeKey"
							:props="defaultProps"
							highlight-current
							lazy
							@node-click="combiTreeClick"
						></el-tree>
					</el-card>
				</el-aside>
				<el-divider
					v-if="customDialog.style == 2"
					direction="vertical"
				></el-divider>
				<el-container>
					<el-header v-if="querysShow" class="middle-header">
						<div
							v-for="(condition, index) in conditionBind"
							:key="index"
							class="search-item"
						>
							<p style="font-size: 14px;">{{ condition.comment }}:</p>
							<div v-if="condition.controllerType == '1'">
								<el-input
									v-model="queryParams[condition.field]"
									:placeholder="placeholders[index]"
									clearable
									prefix-icon="el-icon-search"
									size="small"
									style="width: 180px; padding: 10px 0; margin: 0 5px 0 5px;"
									@keyup.enter.native="searchEnterFun"
								></el-input>
							</div>
							<div
								v-if="condition.controllerType == '2'"
								style="margin-right: 10px;"
							>
								<el-radio
									v-for="(itemR, $index1) in condition.config.options"
									:key="$index1"
									v-model="queryParams[condition.field]"
									:label="itemR.key"
									>{{ itemR.value }}
								</el-radio>
							</div>
							<div
								v-if="condition.controllerType == '3'"
								style="margin-right: 10px;"
							>
								<ht-select
									v-if="condition.config.choiceType == 'static'"
									v-model="queryParams[condition.field]"
									:options="condition.config.options"
									:placeholder="quickSearch"
								></ht-select>
								<eip-select-dia
									v-else
									v-model="queryParams[condition.field]"
									:allowCreate="false"
									:filterable="false"
									:ganged="{
										alias: condition.config.customQuery.alias,
										valueBind: condition.config.customQuery.valueBind,
										noInit: '',
										labelBind: condition.config.customQuery.labelBind,
										gangedBind: '{}',
										bind: condition.config.bind,
									}"
									:multiple="false"
									:placeholder="quickSearch"
									:queryParams="queryParams"
									:selectlist="[]"
								></eip-select-dia>
							</div>
							<div
								v-if="condition.controllerType == '4'"
								style="margin-right: 10px;"
							>
								<eip-tag
									v-model="queryParams[condition.field]"
									:expand="condition.config.expand"
									:filterable="condition.config.filterable"
									:placeholder="quickSearch"
									:tag-key="condition.config.tag"
								></eip-tag>
							</div>
						</div>
						<div
							v-if="conditionBind && conditionBind.length > 0"
							class="btn-wrap"
						>
							<el-button
								icon="el-icon-search"
								size="small"
								style="margin-left: 20px;"
								type="primary"
								@click="search(true)"
								>查询
							</el-button>
							<el-button icon="el-icon-refresh" size="small" @click="reset"
								>重置</el-button
							>
						</div>
					</el-header>
					<el-main style="padding: 0;">
						<el-table
							ref="orgTable"
							:data="dialogData"
							border
							class="org-table"
							size="medium"
							stripe
							style="width: 100%;"
							@select="onTableSelect"
							@row-click="orgRowClick"
							@selection-change="orgTableSelection"
							@select-all="selectAll"
						>
							<el-table-column
								v-if="this.customDialog.selectNum != 1"
								align="center"
								type="selection"
								width="45"
							></el-table-column>
							<el-table-column
								v-if="this.customDialog.selectNum === 1"
								align="center"
								width="50"
							>
								<template slot-scope="scope">
									<el-radio
										v-model="undefineda"
										:label="scope.$index"
										class="textRadio"
										@selection-change="orgTableSelection"
										>&nbsp;
									</el-radio>
								</template>
							</el-table-column>
							<el-table-column
								align="center"
								label="序号"
								type="index"
								width="50"
							></el-table-column>
							<el-table-column
								v-for="field in displayfield"
								:key="field.field"
								:label="field.comment"
								:prop="field.field"
								:show-overflow-tooltip="true"
								style="width: 100%;"
							></el-table-column>
						</el-table>
					</el-main>
					<el-footer>
						<el-row
							v-if="this.customDialog.needPage"
							justify="end"
							style="padding-top: 15px; justify-content: space-between;"
							type="flex"
						>
							<el-button
								v-if="customDialog.style == 2"
								:icon="toggleBtn"
								size="mini"
								type="default"
								@click="toggleTree"
							></el-button>
							<el-pagination
								:current-page="pagination.page"
								:page-size="pagination.pageSize"
								:page-sizes="[10, 20, 50, 100]"
								:total="total"
								layout="total, sizes, prev, pager, next, jumper"
								small
								@size-change="handleSizeChange"
								@current-change="handleCurrentChange"
							></el-pagination>
						</el-row>
					</el-footer>
				</el-container>
			</el-container>
			<span slot="footer" class="dialog-footer" style="text-align: center;">
				<el-button size="small" type="primary" @click="dialogConfirm"
					>确认</el-button
				>
				<el-button size="small" @click="dialogCancel">取 消</el-button>
			</span>
		</el-dialog>

		<!-- 树形对话框 -->
		<el-dialog
			:before-close="handleClose"
			:close-on-click-modal="false"
			:visible.sync="dialogVisible"
			title="动态传入参数查询"
			top="6vh"
			width="500px"
		>
			<!-- 动态传入参数查询树 -->
			<table
				border="0"
				cellpadding="0"
				cellspacing="0"
				class="form-table"
				style="margin-left: 20px; width: 90%;"
			>
				<tbody v-for="(item, $index) in conditionfieldTree" :key="$index">
					<tr v-if="item.defaultType == '4'">
						<th width="130px">{{ item.comment }}:</th>
						<td>
							<ht-input
								v-if="item.type != 'date'"
								v-model="item.paramVal"
								:placeholder="'请输入' + item.comment"
								autocomplete="off"
								style="width: 100%;"
								type="text"
							></ht-input>
							<ht-date
								v-if="item.type == 'date'"
								v-model="item.paramVal"
								:placeholder="'请输入' + item.comment"
								format="yyyy-MM-dd"
								style="width: 100%;"
							></ht-date>
						</td>
					</tr>
				</tbody>
			</table>
			<div slot="footer" class="dialog-footer">
				<el-button type="primary" @click="handleSave">确 定</el-button>
				<el-button @click="handleClose">取 消</el-button>
			</div>
		</el-dialog>
		<el-dialog
			:before-close="dialogCancelTree"
			:close-on-click-modal="false"
			:title="this.customDialog.name"
			:visible.sync="customDialogShowTree"
			append-to-body
			top="6vh"
      custom-class="custom-dialog"
      :style="{'--height': dialogStyle.height,'--width': dialogStyle.width}"
		>
			<el-container :style="style" style="overflow: auto;">
				<el-tree
					ref="tree"
					:check-on-click-node="true"
					:data="props1"
					:load="loadTree"
					:node-key="nodeKey"
					:props="defaultProps"
					:show-checkbox="this.customDialog.selectNum !== 1"
					:check-strictly="this.customDialog.selectNum === -2"
					highlight-current
					lazy
					@node-click="treeClick"
					@check-change="getChecked"
          style="width: 100%"
				></el-tree>
			</el-container>
			<span slot="footer" class="dialog-footer" style="text-align: center;">
				<el-button size="small" type="primary" @click="dialogTreeConfirm"
					>确认</el-button
				>
				<el-button size="small" @click="dialogCancelTree">取 消</el-button>
			</span>
		</el-dialog>
		<span v-validate style="display: none;">
			<slot name="labeldesc">{{ inputName }}</slot>
		</span>
	</div>
</template>
<script>
import { mapState } from 'vuex';
import utils from '@/utils.js';
import haloseeUiUtils from '@/halosee-ui-util.js';
import { Message } from 'element-ui';
import req from '@/request.js';
import sub_pio_mixin from '@/sub-permission-mixin.js';
import EipTag from '@/components/eipControl/EipTag.vue';
import EipSelectDia from '@/components/eipControl/EipSelectDia.vue';
import haloseeUtils from '@/halosee-ui-util.js';

export default {
	components: { EipTag, EipSelectDia },
	name: 'eip-dialog',
	props: [
		'validate',
		'value',
		'name',
		'permission',
		'atter',
		'single',
		'selectorconfig',
		'custdialog',
		'placeholder',
		'tooltipplacement',
	],
	mixins: [sub_pio_mixin], //混入方式引入表单组件中公共属性，处理子表、孙表行内联动（切面修改permission_sub）
	data() {
		return {
			dialogVisible: false, //打开树形输入动态参数值的对话框
			pageParam: {}, //树形对话框参数
			conditionfieldTree: [], //树形对话框条件字段
			data: {
				qxdd: {},
			},
			inputSuffixWidth: 0,
			placeholderBo: '',
			quickSearch: '', //填写提示
			conditionBind: [], //参数查询字段
			nodeKey: 'ID_', //树形数据父Id
			customDialogShowList: false,
			customDialogShowTree: false,
			selectOrgProps: {
				label: 'name',
			},
			style: '', //对话框宽高
			selectOrgs: null,
			inputSuffixHeight: 33,
			config: null,
			updating: false,
			displayfield: [], //显示字段
			customDialog: {},
			queryParam: '', //查询条件输入的值
			props1: [],
			showData: [],
			checkBoxDataAll: [], //选中对象的集合
			defaultProps: {
				children: 'children',
				label: 'label',
				isLeaf: 'isLeaf',
			},
			propsData: [],
			querysShow: false, //是否显示搜索框
			undefineda: '',
			isCurrentChange: false, //是否不执行 orgTableSelection方法
			pagination: {
				page: 1,
				pageSize: 10,
				total: 0,
			},
			param: [], //绑定的表单字段
			treeList: [],
			displayField: {},
			queryParams: [],
			placeholders: [],
			oldselectOrgs: [],
			combinationTreeData: [],
			combiTreeDisplayField: [],
			combinationTreeQuerys: [],
			combinationRule: {},
			toggleBtn: 'el-icon-arrow-left',
			treeShow: true,
			transtionWidth: '25%',
			leftTreeTitle: '',
			writeable: true,
      dialogStyle:{
        width:'60%',
        height:'90%'
      }
		};
	},
	watch: {
		props1: function (newVal, oldVal) {
			//树形
			if (this.showData != undefined && this.showData.length > 0) {
				const this_ = this;
				let data = [];
				for (let i = 0; i < this.showData.length; i++) {
					data.push(this.showData[i]);
				}
				setTimeout(() => {
					for (let i = 0; i < data.length; i++) {
						this_.$refs.tree.setChecked(data[i], true);
						this_.checkNode(data[i], this_);
					}
				}, 200);
			}
		},
	},
	mounted() {
		const { subScopeEl, index } = haloseeUiUtils.getSubScopeElAndIndex(
			this.$el
		);
		if (
			subScopeEl &&
			(subScopeEl.getAttribute('row_readonly') == 'true' ||
				subScopeEl.getAttribute('row_readonly') === true)
		) {
			this.writeable = false;
		}
		//获取对话框按钮名称宽度
		if (this.$refs.inputSuffix) {
			this.inputSuffixWidth = this.$refs.inputSuffix.offsetWidth + 1;
		}
	},
	computed: mapState({
		// pagination: state => state.dialog.pagination,
		total: state => state.dialog.total,
		dialogData: state => {
			return state.dialog.rows;
		},
		inputVal: function () {
			if (!this.value || this.value == '||[]') {
				this.checkBoxDataAll = [];
				// this.showData = [];
				return null;
			} else {
				let nameAry = this.value.split(',');
				if (this.value.indexOf('||') > 0) {
					nameAry = this.value.split('||')[0].split(',');
					// this.showData=JSON.parse(this.value.split("||")[1]);
				}
				//  this.showData =this.selectOrgs;
				let idAry = null;
				let accountAry = null;
				let result = [];
				nameAry.forEach((m, i) => {
					let n = { value: m };
					result.push(n);
				});
				return result;
			}
		},
		inputWriteable: function () {
			return this.writeable
				? utils.getWriteable(this.permission_sub)
				: this.writeable;
		},
		inputValidate: function () {
			var validateObj = this.$store.state.index.validate;
			return utils.addRequiredOrNot(
				this.permission_sub,
				this.validate,
				validateObj,
				this
			);
		},
		inputName: function () {
			let labeldesc = '';
			if (
				this.$slots &&
				this.$slots.labeldesc &&
				this.$slots.labeldesc[0].children &&
				this.$slots.labeldesc[0].children[0].text
			) {
				labeldesc = this.$slots.labeldesc[0].children[0].text;
				return this.name ? this.name : utils.getName() + '-' + labeldesc;
			} else {
				return this.name ? this.name : utils.getName();
			}
		},
		// 是否有回填设置
		bindSet: function () {
			return this.selectorconfig ? this.selectorconfig.bind : null;
		},
	}),
	created() {
		if (!this.placeholder) {
			this.placeholderBo = '请选择内容';
		} else {
			this.placeholderBo = this.placeholder;
		}
		this.$validator = this.$root.$validator;
	},
	methods: {
		selectAll(selection) {
			if (this.oldselectOrgs != null && selection.length > 0) {
				for (let x = 0; x < selection.length; x++) {
					if (this.indexArray(this.oldselectOrgs, selection[x]) === -1) {
						this.oldselectOrgs.push(selection[x]);
					}
				}
				this.selectOrgs = _.cloneDeep(this.oldselectOrgs);
			} else {
				this.selectOrgs = _.cloneDeep(selection);
			}
		},
		checkNode(data, this_, pnode) {
			if (data.Pid) {
				let node = this_.$refs.tree.getNode(data.Pid);
				node.indeterminate = true;
				if (node.data.Pid) {
					this_.$refs.tree.getNode(node.data.Pid).indeterminate = true;
					this.checkNode(
						this_.$refs.tree.getNode(node.data.Pid).data,
						this_,
						this_.$refs.tree.getNode(node.data.Pid)
					);
				}
				if (!node.indeterminate) {
					node.indeterminate = true;
				}
			} else if (pnode && !pnode.indeterminate) {
				pnode.indeterminate = true;
			}
		},
		//回车查询
		searchEnterFun: function (e) {
			var keyCode = window.event ? e.keyCode : e.which;
			if (keyCode == 13) {
				this.search();
			}
		},
		handleSizeChange: function (size) {
			this.isCurrentChange = true;
			//每页下拉显示数据
			this.pagination.pageSize = size;
			this.search();
		},
		handleCurrentChange: function (currentPage) {
			const this_ = this;
			if (this.selectOrgs != undefined && this.selectOrgs.length > 0) {
				this.selectOrgs.forEach(row => {
					let res = this_.indexArray(this_.checkBoxDataAll, row);
					if (res == -1) {
						this_.checkBoxDataAll.push(row);
					}
				});
			}
			this.isCurrentChange = true;
			//点击第几页
			this.pagination.page = currentPage;
			this.search();
		},
		checkList() {
			const this_ = this;
			setTimeout(() => {
				//列表
				if (
					this_.checkBoxDataAll != undefined &&
					this_.checkBoxDataAll.length > 0
				) {
					this_.checkBoxDataAll.forEach(row => {
						let res = this_.indexArray(this_.dialogData, row);
						this_.undefineda = res;
						if (res != -1) {
							this_.isCurrentChange = true;
							this_.toggleRowSelection(res, true);
						}
					});
				}
			}, 300);
		},
		toggleRowSelection(res, val) {
			this.$refs.orgTable.toggleRowSelection(this.dialogData[res], val);
		},
		showDialog(item) {
			const this_ = this;
			var alias = this.custdialog.custDialog.alias;
			this.$store.dispatch('form/getByAlias', alias).then(customDialog => {
				if (!customDialog || !customDialog.alias) {
					Message.error('对话框别名【' + alias + '】不存在！');
					return;
				}
				if (customDialog.style == 1) {
					var displaylist = JSON.parse(customDialog.displayfield);
					this_.nodeKey = displaylist.id;
				}
				//对话框按表单字段查询（参数传入的）
				let bindList = this_.custdialog.custDialog.conditions;
				this_.param = []; //绑定的表单字段
				if (bindList.length > 0) {
					bindList.forEach(ele => {
						//绑定表单字段
						if (ele.defaultType == '3' && ele.bind) {
							let obj = {};
							obj.field = ele.field;
							obj.bind = ele.bind;
							this_.param.push(obj);
						}
					});
				}
				//判断对话框查询是否有条件
				let userInputList = JSON.parse(customDialog.conditionfield);
				this_.quickSearch = ''; //填写提示 placeholder
				this_.conditionBind = [];
				let queryParams = [];
				let placeholders = [];
				if (userInputList.length > 0) {
					userInputList.forEach(ele => {
						var obj = {};
						//条件查询参数（用户输入的） 文本框输入
						if (ele.defaultType == '1') {
							obj[ele.field] = '';
							queryParams.push(obj);
							this_.conditionBind.push(ele);
							placeholders.push('请输入' + ele.comment);
						}
					});
					this.$set(this, 'queryParams', queryParams);
					this.$set(this, 'placeholders', placeholders);
				}
				//判断是否显示条件查询输入框
				if (this_.quickSearch != '') {
					this_.querysShow = true;
				} else {
					this_.querysShow = false;
				}
				// 条件查询参数（用户输入的） 参数数量为0 不展示查询和重置按钮
				if (this_.conditionBind.length == 0) {
					this_.querysShow = false;
				}
				this_.quickSearch = '请输入' + this.quickSearch + '查询';

        this_.dialogStyle = {
          width: '60%',
          height: '90%'
        }
        if (customDialog.width&&customDialog.width!=0)
          this_.dialogStyle.width = customDialog.width+'px';
        if (customDialog.height&&customDialog.height!=0) {
          this_.dialogStyle.height = customDialog.height+'px';
        }

				if (customDialog.style == 0 || customDialog.style == 2) {
					//列表
					this_.customDialogShow({ alias: alias, customDialog: customDialog });
				} else if (customDialog.style == 1) {
					//树形
					this_.pageParam = { alias: alias, customDialog: customDialog };
					this_.customDialog = customDialog;
					let param = {};
					this_.conditionfieldTree = [];
					//判断是否存在条件
					if (customDialog.conditionfield) {
						this_.conditionfieldTree = JSON.parse(customDialog.conditionfield);
						if (this_.conditionfieldTree.length > 0) {
							for (let i = this_.conditionfieldTree.length - 1; i >= 0; i--) {
								//判断条件字段是否是动态传入（defaultType：4：动态传入，2：固定值 ）
								if (this_.conditionfieldTree[i].defaultType == '4') {
									param[this_.conditionfieldTree[i].field] =
										this_.conditionfieldTree[i].comment;
								}
							}
						}
					}
					//有动态传入的字段
					if (JSON.stringify(param) != '{}') {
						this_.dialogVisible = true;
					} else {
						//无动态传入的字段
						this_.customDialogTreeShow(this_.pageParam);
					}
				}
			});
		},
		//打开树形动态参数输入值的对话框
		handleSave() {
			this.customDialogTreeShow(this.pageParam);
			this.dialogVisible = false;
		},
		//关闭树形动态参数输入值的对话框
		handleClose() {
			this.dialogVisible = false;
		},
		//判断数据是否包含某个对象，并返回数据包含对象的下标
		indexArray(array, item) {
			if (array.length == 0) {
				return -1;
			}
			for (let i = 0; i < array.length; i++) {
				if (JSON.stringify(array[i]) == JSON.stringify(item)) {
					return i;
				}
			}
			return -1;
		},
		//点击列表某一个复选框时触发
		onTableSelect(rows, row) {
			this.isCurrentChange = false;
			//判断点击列表数据时复选框是否勾选  selected：true不勾选，false勾选
			let selected =
				this.selectOrgs &&
				this.selectOrgs.length > 0 &&
				this.indexArray(this.selectOrgs, row) !== -1;
			if (selected) {
				this.isCurrentChange = true;
				let res = this.indexArray(this.selectOrgs, row);
				this.selectOrgs.splice(res, 1);
			}
		},
		//点击列表某一条数据时触发
		orgRowClick(row, column, event) {
			if (this.customDialog.selectNum === 1) {
				$(event.currentTarget.children[0].children[0].children[0]).trigger(
					'click'
				);
				this.selectOrgs = [];
				this.selectOrgs.push(row);
			} else if (this.customDialog.selectNum != 1) {
				this.isCurrentChange = false;
				//判断点击列表数据时复选框是否勾选  selected：true不勾选，false勾选
				let selected =
					this.selectOrgs &&
					this.selectOrgs.length > 0 &&
					this.indexArray(this.selectOrgs, row) !== -1;
				if (selected) {
					this.isCurrentChange = true;
					let res = this.indexArray(this.selectOrgs, row);
					this.selectOrgs.splice(res, 1);
				}
				this.$refs.orgTable.toggleRowSelection(row);
			}
		},
		//列表复选框有改变时触发
		orgTableSelection(selection) {
			//全选的情况特殊处理(为了与原本功能逻辑不冲突,先复制一份旧的选中数据.然后拿到全选事件中去计算)
			this.oldselectOrgs = _.cloneDeep(this.selectOrgs);
			//多选
			if (this.customDialog.selectNum != 1 && !this.isCurrentChange) {
				if (selection && selection.length > 0) {
					if (
						selection.length == 1 &&
						(!this.selectOrgs || this.selectOrgs.length == 0)
					) {
						this.selectOrgs = selection;
					} else if (
						(!this.selectOrgs || this.selectOrgs.length == 0) &&
						selection.length > 1
					) {
						if (!this.selectOrgs) {
							this.selectOrgs = [];
						}
						for (let i = selection.length - 1; i >= 0; i--) {
							this.selectOrgs.push(selection[i]);
						}
					} else if (this.isCurrentChange && selection.length >= 10) {
						if (!this.selectOrgs) {
							this.selectOrgs = [];
						} else {
							for (let u = this.selectOrgs.length - 1; u >= 0; u--) {
								let res = this.indexArray(selection, this.selectOrgs[u]);
								if (res != -1) {
									this.selectOrgs.splice(res, 1);
								}
							}
						}
						for (let i = 0; i < selection.length; i++) {
							this.selectOrgs.push(selection[i]);
						}
					} else {
            this.selectOrgs.push(selection[selection.length - 1]);
						// for (let i = selection.length - 1; i >= 0; i--) {
						//
						// 	break;
						// }
					}
				}
			}
		},
		dialogConfirm() {
			this.queryParam = '';
			this.customDialogShowList = false;
			this.calacInputSuffixHeight();
			this.syncInputValue();
			// this.$store.dispatch("dialog/setDialogData", []);
		},
		//重置
		reset() {
			this.queryParams.forEach(paramObj => {
				for (let key in paramObj) {
					this.queryParams[key] = '';
				}
			});
			//组合树重置
			let nodes = this.$refs.combinationTree.store.nodesMap;
			for (let key in nodes) {
				nodes[key].expanded = false;
			}
			this.combinationTreeQuerys.splice(0);
			this.search(true);
		},
		//查询
		search(resetPagintion) {
			let querys = []; //查询条件
			let queryFilter = {};
			if (JSON.stringify(this.pagination) == '{}') {
				this.pagination = { page: '1', pageSize: '10', showTotal: 'true' };
			}
			let pageBean = { pageBean: this.pagination };
			if (resetPagintion) {
				pageBean.pageBean = { page: '1', pageSize: '10', showTotal: 'true' };
			}
			//用户输入的
			if (this.queryParams.length != 0 && this.queryParams[0] != '') {
				this.conditionBind.forEach((item, index) => {
					querys.push({
						property: item.field,
						value: this.queryParams[item.field],
						group: 'main',
						operation: 'LIKE',
						relation: 'AND',
					});
				});
			}
			//参数传入的查询拼接
			if (this.param) {
				const pInst = utils.getOnlineFormInstance(this);
				this.param.forEach(item => {
					querys.push({
						property: item.field,
						value: utils.getValueByPath(pInst, item.bind),
						group: 'main',
						operation: 'LIKE',
						relation: 'AND',
					});
				});
			}
			//来自组合对话框的
			if (
				this.combinationTreeQuerys &&
				this.combinationTreeQuerys.length != 0
			) {
				for (let i = 0; i < this.combinationTreeQuerys.length; i++) {
					querys.push(this.combinationTreeQuerys[i]);
				}
			}
			if (querys.length > 0) {
				queryFilter = this.handlePostData({
					pageBean: pageBean.pageBean,
					querys,
				});
				this.customDialog.pageBean = queryFilter;
				this.$store
					.dispatch('dialog/getlistJson', this.customDialog)
					.then(() => {
						this.checkList();
					});
			} else {
				this.customDialog.pageBean = pageBean;
				this.$store
					.dispatch('dialog/getlistJson', this.customDialog)
					.then(() => {
						this.checkList();
					});
			}
		},
		// 处理POST请求时的参数
		handlePostData(queryFilter) {
			if (
				!this.customDialog.dataParam ||
				this.customDialog.dataParam.constructor != String
			) {
				return queryFilter;
			}
			// 构建上下文数据对象
			let ctx = {};
			queryFilter &&
				queryFilter.querys.forEach(element => {
					ctx[element.property] = element.value;
				});
			const exp = haloseeUiUtils.parseExp(this.customDialog.dataParam, ctx);
			try {
				return JSON.parse(exp);
			} catch (e) {
				CustomQuery._throwException(
					`POST参数不是有效的JSON格式${query.dataParam}`
				);
			}
		},
		async doQuery(param) {
			let paramLoadData = [];
			const pInst = utils.getOnlineFormInstance(this);
			//获取关联查询绑定的表单参数
			for (let i = 0; i < param.conditionfield.length; i++) {
				if (param.conditionfield[i].fieldPath != '') {
					let bindVal = utils.getValueByPath(
						pInst,
						param.conditionfield[i].fieldPath,
						null
					);
					let obj = { key: param.conditionfield[i].field, value: bindVal };
					paramLoadData.push(obj);
				}
			}

			let queryUrl =
				param.dsType == 'dataSource'
					? '${form}/form/customQuery/v1/doQuery?alias=' +
					  param.alias +
					  '&page=1'
					: param.url;
			let requestMethod = 'POST';
			//如果关联数据列表查询数据不是数据源则请求方法为restful配置的请求方式
			if (param.dsType != 'dataSource') {
				requestMethod = param.requestType;
			}
			//查询数据
			req
				.request({ url: queryUrl, method: requestMethod, data: paramLoadData })
				.then(res => {
					//判断是否有关联查询数据返回
					if (res.data.rows.length > 0) {
						//获取关联查询返回的表单参数
						for (let io = 0; io < param.resultfield.length; io++) {
							if (param.resultfield[io].fieldPath != '') {
								let val = '';
								for (let j = 0; j < res.data.rows.length; j++) {
									if (res.data.rows[j][param.resultfield[io].field]) {
										val =
											val + res.data.rows[j][param.resultfield[io].field] + ',';
									}
								}
								val = val.substring(0, val.length - 1);
								let pathArr = param.resultfield[io].fieldPath.split('.');
								if (pathArr.length == 3) {
									//主表
									utils.setValueByPath(
										pInst,
										param.resultfield[io].fieldPath,
										val,
										null
									);
								} else if (pathArr.length == 4) {
									//子表
									let subData = pInst.data[pathArr[1]][pathArr[2]];
									if (subData.length == 0) {
										//子表没数据的情况
										let subTabName = pathArr[2].replace('sub_', '');
										//得到子表的所有字段
										let subInitData =
											pInst.data[pathArr[1]].initData[subTabName] || {};
										//把数组里面的值为 null 转换为空字符串
										let str = JSON.stringify(subInitData).replace(
											/null/g,
											'""'
										);
										let subData = JSON.parse(str);
										for (var key in subData) {
											//点添加时判断要新增子表记录中的孙表是否有值
											if (key.indexOf('sub_') == 0 && subData[key].length > 0) {
												subData[key] = []; //有则清空
											}
											//点添加时判断要新增子表记录中的字段是否有值
											if (subData[key]) {
												subData[key] = ''; //有则清空
											}
										}
										//新增一条数据
										pInst.data[pathArr[1]][pathArr[2]].push(subData);
										//对话框关联查询返回的值赋值给绑定的字段
										utils.setValueByPath(
											pInst,
											param.resultfield[io].fieldPath,
											val,
											0
										);
									} else {
										//子表有数据的情况
										for (let p = 0; p < subData.length; p++) {
											//对话框关联查询返回的值赋值给绑定的字段
											utils.setValueByPath(
												pInst,
												param.resultfield[io].fieldPath,
												val,
												p
											);
										}
									}
								}
							}
						}
					} else {
						//没有返回的值则清空
						//获取关联查询返回的表单参数
						for (let iop = 0; iop < param.resultfield.length; iop++) {
							if (param.resultfield[iop].fieldPath != '') {
								let pathArr = param.resultfield[iop].fieldPath.split('.');
								if (pathArr.length == 3) {
									//主表
									//赋值给绑定的字段
									utils.setValueByPath(
										pInst,
										param.resultfield[iop].fieldPath,
										'',
										null
									);
								} else if (pathArr.length == 4) {
									//子表
									let subData = pInst.data[pathArr[1]][pathArr[2]];
									for (let p = 0; p < subData.length; p++) {
										//对话框关联查询返回的值赋值给绑定的字段
										utils.setValueByPath(
											pInst,
											param.resultfield[iop].fieldPath,
											'',
											p
										);
									}
								}
							}
						}
					}
				});
		},
		// 同步选择结果
		syncInputValue() {
			let thisIndex = null; //当前数据所在下标
			let parentIndex = null; //父节点所在下标
			if (this.$el) {
				thisIndex = utils.getSomeAttributeFromParentElement(
					this.$el,
					'data-index'
				);
				parentIndex = utils.getSomeAttributeFromParentElement(
					this.$parent.$el,
					'data-index'
				);
			}
			var returnStr = JSON.parse(this.customDialog.resultfield);
			//拿到返回的字段
			var field = new Array([returnStr.length]);
			var comment = new Array([returnStr.length]);
			var fieldUp = new Array([returnStr.length]);
			var str = [];
			for (var i = 0; i < returnStr.length; i++) {
				field[i] =
					this.customDialog.dsType == 'dataSource'
						? returnStr[i].field.toLowerCase()
						: returnStr[i].field;
				comment[i] =
					this.customDialog.dsType == 'dataSource'
						? returnStr[i].comment.toLowerCase()
						: returnStr[i].comment;
				fieldUp[i] =
					this.customDialog.dsType == 'dataSource'
						? returnStr[i].field.toUpperCase()
						: returnStr[i].field;
			}
			const this_ = this;
			var s = this.propsData;
			if (this.customDialog.style === 0 || this.customDialog.style === 2) {
				// 列表
				s = this.selectOrgs;
				this.showData = [...this.selectOrgs];
				this.checkBoxDataAll = [...this.selectOrgs];
			}
			if (this.customDialog.selectNum === 1) {
				var temp = '';
				for (var i = 0; i < comment.length; i++) {
					let sField = s[0][field[i]] === undefined ? '' : s[0][field[i]];
					let encodeStr = encodeURIComponent(sField);
					temp += '"' + comment[i] + '":"' + encodeStr + '",';
				}
				if (temp != '') {
					temp = '{' + temp.substring(0, temp.length - 1) + '}';
				}
				str.push(utils.parseToJson(temp));
			} else {
				for (var i = 0; i < s.length; i++) {
					var temp = '';
					for (var j = 0; j < comment.length; j++) {
						let str =
							s[i][field[j]] === undefined ? s[i][fieldUp[j]] : s[i][field[j]];
						let encodeStr = encodeURIComponent(str);
						temp += '"' + comment[j] + '":"' + encodeStr + '",';
					}
					if (temp != '') {
						temp = '{' + temp.substring(0, temp.length - 1) + '}';
					}
					str.push(utils.parseToJson(temp));
				}
			}
			// this.$emit("input", JSON.stringify(str));
			const pInst = utils.getOnlineFormInstance(this);
			const _this = this;
			this.custdialog.custDialog.mappingConf.forEach(con => {
				var val = '';
				var from = '';
				if (_this.customDialog.dsType == 'restful') {
					from = con.from;
				} else {
					from = con.from.toLowerCase();
				}
				str.forEach(item => {
					val += decodeURIComponent(item[from]) + ',';
				});
				if (this.atter == 'data.' + con['target'][0]) {
					val = val.substring(0, val.length - 1);
					utils.setValueByPath(
						pInst,
						'data.' + con['target'][0],
						val,
						thisIndex
					);
				} else if (this.atter == 'searchForm.' + con['target'][0]) {
					utils.setValueByPath(
						pInst,
						'searchForm.' + con['target'][0],
						val.substring(0, val.length - 1),
						thisIndex
					);
				} else {
					let configAttr = con['target'][0].split('.');
					let path = con['target'][0];
					if (configAttr.length == 4 && parentIndex >= 0) {
						//孙表数据赋值
						path =
							configAttr[0] +
							'.' +
							configAttr[1] +
							'[' +
							parentIndex +
							'].' +
							configAttr[2] +
							'.' +
							configAttr[3];
					}
					if (pInst.data) {
						utils.setValueByPath(
							pInst,
							'data.' + path,
							val.substring(0, val.length - 1),
							thisIndex
						);
					} else {
						utils.setValueByPath(
							pInst,
							'model.' + path,
							val.substring(0, val.length - 1),
							thisIndex
						);
					}
				}
			});
			//判断对话框是否绑定了关联查询
			let custQueryJson = this.custdialog.custDialog.custQueryJson;
			if (custQueryJson.length > 0) {
				for (let i = 0; i < custQueryJson.length; i++) {
					if (custQueryJson[i].conditionfield.length > 0) {
						this.doQuery(custQueryJson[i]);
					} else {
						console.error(
							'[' + custQueryJson[i].comment + ']关联查询取值参数未绑定表单字段'
						);
					}
				}
			}
		},
		//取消按钮
		dialogCancel() {
			const this_ = this;
			this_.queryParam = '';
			this_.$store.dispatch('dialog/setDialogData', []).then(() => {
				this_.customDialogShowList = false;
				//判断是否是点击了确认再点击取消的  inputVal没有值则表示直接点击的取消
				if (!this_.inputVal) {
					this_.selectOrgs = [];
				} else {
					this_.selectOrgs = [...this_.showData];
					this.checkBoxDataAll = [...this_.selectOrgs];
				}
			});
		},
		dialogTreeConfirm() {
			this.calacInputSuffixHeight();
			let thisIndex = null; //当前数据所在下标
			let parentIndex = null; //父节点所在下标
			if (this.$el) {
				thisIndex = utils.getSomeAttributeFromParentElement(
					this.$el,
					'data-index'
				);
				parentIndex = utils.getSomeAttributeFromParentElement(
					this.$parent.$el,
					'data-index'
				);
			}
			this.$store.dispatch('dialog/setDialogData', []);
			var returnStr = JSON.parse(this.customDialog.resultfield);
			var field = new Array([returnStr.length]);
			var comment = new Array([returnStr.length]);
			var str = [];
			for (var i = 0; i < returnStr.length; i++) {
				field[i] = returnStr[i].field;
				comment[i] = returnStr[i].comment;
			}
			if (this.customDialog.selectNum === 1) {
				var nodes = this.propsData[0];
				var temp = '';
				for (var i = 0; i < comment.length; i++) {
					temp += '"' + comment[i] + '":"' + nodes[field[i]] + '",';
				}
				if (temp != '') {
					temp = '{' + temp.substring(0, temp.length - 1) + '}';
				}
				str.push(utils.parseToJson(temp));
			} else {
				var nodes = this.propsData;
				nodes.forEach((item, k) => {
					var temp = '';
					for (var i = 0; i < comment.length; i++) {
						temp += '"' + comment[i] + '":"' + nodes[field[i]] + '",';
						temp += '"' + comment[i] + '":"' + nodes[k][field[i]] + '",';
					}
					if (temp != '') {
						temp = '{' + temp.substring(0, temp.length - 1) + '}';
					}
					str.push(utils.parseToJson(temp));
				});
			}
			const pInst = utils.getOnlineFormInstance(this);
			this.custdialog.custDialog.mappingConf.forEach(con => {
				var val = '';
				str.forEach(item => {
					val += item[con.from] + ',';
				});
				if (this.atter == 'data.' + con['target'][0]) {
					utils.setValueByPath(
						pInst,
						'data.' + con['target'][0],
						val.substring(0, val.length - 1),
						thisIndex
					);
				} else if (this.atter == 'searchForm.' + con['target'][0]) {
					utils.setValueByPath(
						pInst,
						'searchForm.' + con['target'][0],
						val.substring(0, val.length - 1),
						thisIndex
					);
				} else {
					let configAttr = con['target'][0].split('.');
					let path = con['target'][0];
					if (configAttr.length == 4 && parentIndex >= 0) {
						//孙表数据赋值
						path =
							configAttr[0] +
							'.' +
							configAttr[1] +
							'[' +
							parentIndex +
							'].' +
							configAttr[2] +
							'.' +
							configAttr[3];
					}
					if (pInst.data) {
						utils.setValueByPath(
							pInst,
							'data.' + path,
							val.substring(0, val.length - 1),
							thisIndex
						);
					} else {
						utils.setValueByPath(
							pInst,
							'model.' + path,
							val.substring(0, val.length - 1),
							thisIndex
						);
					}
				}
			});
			//this.$emit("input", JSON.stringify(str));
			this.showData = [...this.propsData]; //回显的值
			this.customDialogShowTree = false;
		},
		dialogCancelTree() {
			this.$store.dispatch('dialog/setDialogData', []);
			this.customDialogShowTree = false;
		},
		getChecked(data, checked, indeterminate) {
			if (this.customDialog.selectNum === 1) {
				this.propsData = [];
				this.propsData.push(data);
			} else {
				this.propsData = this.$refs.tree.getCheckedNodes();
			}
		},
		treeClick(data, n, i) {
			if (this.customDialog.selectNum === 1) {
				this.propsData = [];
				this.propsData.push(data);
			}
		},
		clearAllSelectOrgs() {
			this.selectOrgs = null;
			this.$refs.orgTable.clearSelection();
		},
		removeSelectOrg(item) {
			if (this.customDialog.selectNum === 1) {
				this.$emit('input', '');
				this.selectOrgs.splice(item, 1);
				this.showData.splice(item, 1);
			} else {
				this.inputVal.splice(item, 1);
				// let removeId = this.showData[item];
				//树形
				if (this.propsData.length > 0) {
					this.propsData.splice(item, 1);
				}
				if (this.showData.length > 0) {
					this.showData.splice(item, 1);
				}
				//列表
				if (this.selectOrgs != null) {
					this.selectOrgs.splice(item, 1);
					this.checkBoxDataAll.splice(item, 1);
					this.selectOrgs.forEach(row => {
						// if(item.id ==removeId ){
						this.isCurrentChange = true;
						this.toggleRowSelection(row, false);
						// }
					});
				}
				this.calacInputSuffixHeight();
				let value = '';
				this.inputVal.forEach(val => {
					value += val.value + ',';
				});
				if (value.length > 0) {
					value = value.substring(0, value.length - 1);
				}
				if (value != '') {
					value = value + '||' + JSON.stringify(this.showData);
				}
				this.$emit('input', value);
			}
			this.syncInputValue();
		},
		calacInputSuffixHeight() {
			setTimeout(() => {
				if (!this.$refs.tagSpans) return;
				if (this.$refs.tagSpans.offsetHeight) {
					this.inputSuffixHeight = this.$refs.tagSpans.offsetHeight + 5;
				} else {
					this.inputSuffixHeight = 30;
				}
				// 触发验证
				this.$validator.validate();
			}, 0);
		},
		customDialogShow(pageParam) {
			this.customDialogShowList = true;
			this.customDialog = pageParam.customDialog;
			this.customDialog.queryUrl =
				this.customDialog.dsType == 'dataSource'
					? '${form}/form/customDialog/v1/getListData?alias=' +
					  this.customDialog.alias +
					  '&mapParam=' +
					  (this.customDialog.mapParam ? this.customDialog.mapParam : '')
					: this.customDialog.url;
			if (this.dialogData.length < 1) {
				this.search();
				this.displayfield = JSON.parse(pageParam.customDialog.displayfield);
				if (this.customDialog.dsType == 'dataSource') {
					for (var i = 0; i < this.displayfield.length; i++) {
						this.displayfield[i].field = this.displayfield[
							i
						].field.toLowerCase();
					}
				}
			} else if (this.dialogData.length > 1) {
				this.search();
			}
			if (this.dialogData.length > 0 && this.displayfield.length == 0) {
				this.search();
				this.displayfield = JSON.parse(pageParam.customDialog.displayfield);
				if (this.customDialog.dsType == 'dataSource') {
					for (var i = 0; i < this.displayfield.length; i++) {
						this.displayfield[i].field = this.displayfield[
							i
						].field.toLowerCase();
					}
				}
			}
		},
		customDialogTreeShow(pageParam) {
			var customDialog = this.customDialog;
			let mapParamObj = {}; //数据来源是数据源，且有动态参数传入时调用
			let mapParam = '';
			let defaultPValue = ''; //父ID值
			if (this.conditionfieldTree.length > 0) {
				for (let i = 0; i < this.conditionfieldTree.length; i++) {
					if (this.conditionfieldTree[i].defaultType == '4') {
						//动态传入
						//得到输入的条件字段值
						let val = this.conditionfieldTree[i].paramVal;
						if (!val) {
							continue;
						}
						//得到条件字段KEY
						let key = this.conditionfieldTree[i].field;
						mapParamObj[key] = val;
					} else if (this.conditionfieldTree[i].defaultType == '2') {
						//固定值
						//得到输入的条件字段值
						let val = this.conditionfieldTree[i].defaultValue;
						if (!val) {
							continue;
						}
						//得到条件字段KEY
						let key = this.conditionfieldTree[i].field;
						mapParamObj[key] = val;
					}
				}
				if (JSON.stringify(mapParamObj) != '{}') {
					//获取对话框配置的父ID字段
					let pid = JSON.parse(this.customDialog.displayfield).pid;
					for (let m in mapParamObj) {
						if (pid == m) {
							defaultPValue = mapParamObj[m];
							break;
						}
					}
					mapParam = JSON.stringify(mapParamObj);
					mapParam = mapParam.substring(1, mapParam.length - 1);
				}
			}
			var requestType =
				customDialog.dsType == 'dataSource'
					? 'GET'
					: customDialog.requestType
					? customDialog.requestType
					: 'POST';
			var url =
				'${form}/form/customDialog/v1/getTreeData?alias=' +
				pageParam.alias +
				'&mapParam=' +
				mapParam;
			var paramsObj = {};
			if (customDialog.dsType != 'dataSource') {
				url = customDialog.url;
				var templatePa = customDialog.dataParam;
				if (customDialog.conditionfield) {
					var conditions = JSON.parse(customDialog.conditionfield);
					for (var i = 0; i < conditions.length; i++) {
						var con = conditions[i];
						if (requestType == 'POST') {
							if (templatePa) {
								templatePa = templatePa.replace(
									new RegExp('\\{' + con.field + '\\}', 'g'),
									con.defaultValue
								);
							} else {
								paramsObj[con.field] = con.defaultValue;
							}
						} else {
							var ljChar = url.indexOf('?') == -1 ? '?' : '&';
							url = url + ljChar + con.field + '=' + con.defaultValue;
						}
					}
					if (templatePa) {
						paramsObj = JSON.parse(templatePa);
					}
				}
			}
			var requestParams = {};
			requestParams.requestType = requestType;
			requestParams.url = url;
			requestParams.paramsObj = paramsObj;
			this.searchTree(requestParams, defaultPValue);
			this.customDialogShowTree = true;
		},
		//树形查询
		searchTree(requestParams, defaultPValue) {
			const this_ = this;
			let query =
				requestParams.requestType == 'POST'
					? req.post(requestParams.url, requestParams.paramsObj)
					: req.get(requestParams.url);
			query.then(function (response) {
				//显示字段配置
				let displayfield = JSON.parse(this_.customDialog.displayfield);
				this_.displayField = displayfield;
				//把对话框配置的显示字段显示名称赋值给树形的显示值
				this_.defaultProps.label = displayfield.displayName;
				this_.treeList = response.data;
        let listKey = this_.customDialog.listKey;

        if (!(this_.treeList instanceof Array) && listKey) {
          this_.treeList = haloseeUtils.getValueByPath(
              this_.treeList,
              listKey
          );
        }
				//得到要加载树的信息
				if (defaultPValue) {
					displayfield.pvalue = defaultPValue;
				}
				this_.props1 = this_.toTreeData(
          this_.treeList,
					displayfield.id,
					displayfield.pid,
					displayfield.displayName,
					displayfield.pvalue ? displayfield.pvalue : 0
				);
			});
		},
		//加载树的信息
		toTreeData(data, id, pid, name, pvalue) {
      var treeData=[];
      function setTreeData(tree) {
        tree.forEach(m => {
          var option = m;
          option.isLeaf = true;
          if (option.children) {
            if (option.children.length > 0) {
              option.isLeaf = false;
              setTreeData(option.children)
              delete option.children;
            }
          } else {
            var children = tree.filter(
                value =>
                    m[id] == value[pid]
            );
            if (children && children.length > 0) {
              option.isLeaf = false;
            }
          }
          treeData.push(option);
        });
      }

      setTreeData(data);
      this.treeList=treeData;
			// 建立个树形结构,需要定义个最顶层的父节点，pvalue是0
			return this.translateDataToTree(treeData, pid, id, name, pvalue);
		},
		translateDataToTree(data, pid, id, name, pvalue) {
			//把树数据有子节点的数据全部过滤掉（只留父节点的数据）
			let parents = data.filter(
				value =>
					value[id] == value[pid] || value[pid] == null || value[pid] == pvalue
			);
			if (!parents) {
				parents = data.filter(
					value =>
						value[pid] !== 'undefined' &&
						value[pid] != null &&
						value[id] != value[pid]
				);
			}
			return parents;
		},
		loadTree(node, resolve) {
			if (node) {
				let this_ = this;
				let displayField =
					this_.customDialog.style == 2
						? this_.combiTreeDisplayField
						: this_.displayField;
				resolve(
					this.treeList.filter(
						value => value[displayField.pid] === node.data[displayField.id]
					)
				);
				if (this.showData && this.showData.length > 0) {
					setTimeout(() => {
						this.showData.forEach(v => {
							if (v.Pid == node.key) {
								this_.$refs.tree.setChecked(v, true);
							} else {
								this_.checkNode(v, this_);
							}
						});
					}, 400);
				}
			}
		},

		afterOpen() {
			//打开对话框之后加载树
			this.loadCombinationTree();
		},
		loadCombinationTree() {
			if (this.customDialog.style != 2) {
				return;
			}
			let combinationRule = JSON.parse(this.customDialog.combinationRule);
			this.combinationRule = combinationRule;
			let treeAlias = combinationRule.leftTree;
			//获取对话框数据
			req
				.get('${form}/form/customDialog/v1/getByAlias?alias=' + treeAlias)
				.then(resp => {
					let treeDialog = resp.data;
					this.leftTreeTitle = treeDialog.name;
					let reqParam = {};
					let requestType =
						treeDialog.dsType == 'dataSource'
							? 'GET'
							: treeDialog.requestType
							? treeDialog.requestType
							: 'POST';
					let url =
						'${form}/form/customDialog/v1/getTreeData?alias=' +
						treeAlias +
						'&mapParam=';
					let paramsObj = {};
					if (treeDialog.dsType != 'dataSource') {
						url = treeDialog.url;
						let templatePa = treeDialog.dataParam;
						if (treeDialog.conditionfield) {
							let conditions = JSON.parse(treeDialog.conditionfield);
							for (let i = 0; i < conditions.length; i++) {
								let con = conditions[i];
								if (requestType == 'POST') {
									if (templatePa) {
										templatePa = templatePa.replace(
											new RegExp('\\{' + con.field + '\\}', 'g'),
											con.defaultValue
										);
									} else {
										paramsObj[con.field] = con.defaultValue;
									}
								} else {
									let ljChar = url.indexOf('?') == -1 ? '?' : '&';
									url = url + ljChar + con.field + '=' + con.defaultValue;
								}
							}
							if (templatePa) {
								paramsObj = JSON.parse(templatePa);
							}
						}
					}
					let requestParams = {};
					requestParams.requestType = requestType;
					requestParams.url = url;
					requestParams.paramsObj = paramsObj;
					this.$store
						.dispatch('dialog/getTreeData', requestParams)
						.then(resp => {
							if (treeDialog.displayfield && treeDialog.resultfield) {
								let displayField = JSON.parse(treeDialog.displayfield);
								let resultfield = JSON.parse(treeDialog.resultfield);
								this.defaultProps.label = displayField.displayName;
								this.treeList = resp;
								this.combiTreeDisplayField = displayField;
								this.combinationTreeData = this.toTreeData(
									resp,
									displayField.id,
									displayField.pid,
									displayField.displayName,
									displayField.pvalue ? displayField.pvalue : '0',
									resultfield
								);
							}
						});
				});
		},
		combiTreeClick(paramObj, node, nodeComponent) {
			//组合对话框点击左树
			//清空旧的
			this.combinationTreeQuerys.splice(0);
			let combinationRule = JSON.parse(this.customDialog.combinationRule);
			if (!combinationRule.rules || combinationRule.rules.length == 0) {
				return;
			}
			let rules = combinationRule.rules;
			for (let i = 0; i < rules.length; i++) {
				let value = paramObj[rules[i].treeField];
				let property = rules[i].listField;
				this.combinationTreeQuerys.push({
					property: property,
					value: value,
					group: 'treeGroup',
					operation: this.getOperation(rules[i].condition),
					relation: 'AND',
				});
			}
			this.search();
		},
		//获取运算符号
		getOperation(old) {
			if (!old) {
				return '';
			}
			if (old == 'EQ') {
				return 'EQUAL';
			}
			if (old == 'LK') {
				return 'LIKE';
			}
			if (old == 'LFK') {
				return 'LIKE';
			}
			if (old == 'IN') {
				return 'IN';
			}
		},
		toggleTree() {
			if (this.treeShow) {
				this.treeShow = false;
				this.transtionWidth = '0%';
				this.toggleBtn = 'el-icon-arrow-right';
			} else {
				this.treeShow = true;
				this.transtionWidth = '25%';
				this.toggleBtn = 'el-icon-arrow-left';
			}
		},
	},
};
</script>
<style lang="scss" scoped>
/deep/ .el-button--mini {
	padding: 0px 15px;
	font-size: 12px;
	border-radius: 3px;
	height: 100%;
	border-top-left-radius: 0;
	border-bottom-left-radius: 0;
}

/deep/ .el-button--info {
	background-color: #f5f7fa;
	border-color: #e4e7ed;
	color: #c0c4cc;
}

/deep/ .el-input__suffix {
	position: absolute;
	height: 100%;
	right: 0px !important;
	top: 0;
	text-align: center;
	color: #c0c4cc;
	-webkit-transition: all 0.3s;
	transition: all 0.3s;
	pointer-events: none;
}

.el-input__inner[aria-invalid='true'] {
	border-color: #f56c6c;
}

.el-select__tags {
	background: #fff;
	margin-left: 1px;
}

.left-aside {
	border-right: 1px solid #eee;
	padding: 10px;
}

.org-tree {
	height: 440px;
	margin-top: 10px;
}

.middle-header {
	height: unset !important;
	display: flex;
	flex-direction: row;
	flex-wrap: wrap;

	.search-item {
		display: flex;
		// width: 33.33%;
		margin-right: 12px;
	}

	.btn-wrap {
		line-height: 50px;
	}
}

.org-table {
	width: 100%;
}

.right-aside {
	border-left: 1px solid #eee;
}

.select-aside {
	border-left: 1px solid #eee;
}

.select-header {
	border-bottom: 1px solid #eee;
	height: 52px !important;
}

.select-header > span {
	padding: 10px 0;
	line-height: 53px;
}

.select-tree-div {
	height: calc(100% - 60px);
	overflow-y: auto;
	min-height: unset;
}

/deep/ .el-dialog__body {
	padding: 0;
	height: calc(100% - 120px);
	overflow-y: auto;
}

> .el-card__header {
	padding: 10px;
}

> .el-card__body {
	padding: 10px;
}

.org-find-card > .el-card__header {
	background: #f5f7fa;
}

> .el-main {
	padding: 0 20px !important;
}

.button-group {
	width: 70px;
	height: 170px;
	margin: 0px auto;
	position: relative;
	top: 50%;
	-webkit-transform: translateY(-50%);
	-moz-transform: translateY(-50%);
	-ms-transform: translateY(-50%);
	-o-transform: translateY(-50%);
	transform: translateY(-50%);
}

.button-group > button {
	display: block;
	margin: 8px 0;
}

@media (max-width: 1280px) {
	/deep/ .el-dialog {
		width: 96% !important;
		margin-top: 2vh !important;
	}
}

/deep/ .el-dialog__wrapper {
	overflow: unset !important;

	&::-webkit-scrollbar {
		width: 0;
		background-color: transparent;
	}
}

/deep/ .el-dialog {
	height: 90%;
	min-height: 400px;
}

@media (max-height: 960px) {
	/deep/ .el-dialog__body .el-container {
		height: 100% !important;
	}
}

/deep/ .el-divider--vertical {
	height: 100%;
}
/deep/ .custom-dialog{
  height: var(--height);
  width: var(--width);
  min-height: auto;
}
/deep/ .el-dialog__body {
  padding: 10px 20px;
  height: calc(100% - 120px);
  overflow-y: auto;
}
</style>
