// 页码
var pageNum = 1;
var treeClickId = '';

//存储选中的数据
var checkedData = [];
var checkedDeptData = [];
var checkedProcessData = [];
var checkedRegulationsData = [];

var respData = [];
var respDataPro = [];

var referType = "role"
var type = 'person'

// 复制人的信息
var copyPersonItem = null;
var copyid = ''

// 存储用户信息
var storeSelectUsers = []
// 存储已选择的对象的信息
var storeSelected = []

// $("body").on("click", ".chooseLeader", function () {
// 	if (!basFlow.curId[0]) {
// 		basFlow.alertBox($.i18n.prop("firstChooseNode") + "! ", 'danger');
// 		return false;
// 	}
// 	referType = "leader"
// 	$.ajax({
// 		type: "post",
// 		url: basFlow.baseUrl + "/select/user/cqp/getTotalOrg/0",
// 		success: function (data) {
// 			initOrgTree(data)
// 			initCheckList()
// 		}
// 	})
// 	var doTData = doT.template($('#attr_templ').text())
// 	if (/CONTROL/.test(basFlow.curId)) {
// 		temStore = basFlow.controls[basFlow.curId[0]]
// 	} else {
// 		temStore = basFlow.swimlanes[basFlow.curId[0]]
// 	}
// 	checkedData = temStore.leaders;
// 	$(".modalDialog").show();
// })
// $(".modalDialogProcessCopy").hide()

$("body").on("click", ".chooseLeader", function () {
	if (!basFlow.curId[0]) {
		basFlow.alertBox($.i18n.prop("firstChooseNode") + "! ", 'danger');
		return false;
	}
	referType = $(this).attr("data-type")
	$(".tabsContentDept .left .common").removeClass("active");
	$(".tabsContentDept .left .common").eq(0).addClass("active");
	$(".tabsContentDept .center .centerContent").removeClass("block");
	$(".tabsContentDept .center .centerContent").eq(0).addClass("block");
	$.ajax({
		type: "post",
		url: basFlow.baseUrl + "/select/user/cqp/getTotalOrg/0",
		success: function (data) {
			// initDeptTree(data)
			initStationTree(data)
		}
	})
	var doTData = doT.template($('#attr_templ').text());
	temStore = basFlow.controls[basFlow.curId[0]]
	checkedDeptData = JSON.parse('{"orglist":' + JSON.stringify(temStore[referType]) + '}').orglist;
	$(".modalDialogDept").show();
	var templ = "";
	for (var j = 0; j < checkedDeptData.length; j++) {
		if (!!checkedDeptData[j]) {
			templ += '<span class="commonFileName leadersDel" data-id="' + checkedDeptData[j].id + '">' + checkedDeptData[j].name + '(' + (!!checkedDeptData[j].deptTopname ? (checkedDeptData[j].upLeveldeptname + ',' + checkedDeptData[j].deptTopname) : checkedDeptData[j].upLeveldeptname) + ')<i></i></span>';
		}
	}
	$('.modalDialogDept .checkedList').html(templ);
})

$("body").on("click", ".surChooseLeaders", function () {
	if (!basFlow.isEdit) return false
	if (!basFlow.curId[0]) {
		basFlow.alertBox($.i18n.prop("firstChooseNode") + "! ", 'danger');
		return false
	}
	$(".tabsContentDept .left .common").removeClass("active");
	$(".tabsContentDept .left .common").eq(0).addClass("active");
	$(".tabsContentDept .center .centerContent").removeClass("block");
	$(".tabsContentDept .center .centerContent").eq(0).addClass("block");
	$.ajax({
		type: "post",
		url: basFlow.baseUrl + "/select/user/cqp/getTotalOrg/0",
		success: function (data) {
			// initDeptTree(data)
			initStationTree(data)
		}
	})
	var doTData = doT.template($('#attr_templ').text());
	temStore = basFlow.swimlanes[basFlow.curId[0]]
	checkedDeptData = JSON.parse('{"orglist":' + JSON.stringify(temStore.depts) + '}').orglist;
	$(".modalDialogDept").show();
	var templ = "";
	for (var j = 0; j < checkedDeptData.length; j++) {
		if (!!checkedDeptData[j]) {
			templ += '<span class="commonFileName leadersDel" data-id="' + checkedDeptData[j].id + '">' + checkedDeptData[j].name + '(' + (!!checkedDeptData[j].deptTopname ? (checkedDeptData[j].upLeveldeptname + ',' + checkedDeptData[j].deptTopname) : checkedDeptData[j].upLeveldeptname) + ')<i></i></span>';
		}
	}
	$('.modalDialogDept .checkedList').html(templ);
})

$("body").on("click", ".chooseDepts", function () {
	if (!basFlow.curId[0]) {
		basFlow.alertBox($.i18n.prop("firstChooseNode") + "! ", 'danger');
		return false
	}
	$(".tabsContentDept .left .common").removeClass("active");
	$(".tabsContentDept .left .common").eq(0).addClass("active");
	$(".tabsContentDept .center .centerContent").removeClass("block");
	$(".tabsContentDept .center .centerContent").eq(0).addClass("block");
	$.ajax({
		type: "post",
		url: basFlow.baseUrl + "/select/user/cqp/getTotalOrg/0",
		success: function (data) {
			initStationTree(data);
		}
	})
	var doTData = doT.template($('#attr_templ').text());
	var templ = '';
	temStore = basFlow.swimlanes[basFlow.curId[0]]
	checkedDeptData = temStore.depts;
	$(".modalDialogDept").show();
	for (var j = 0; j < checkedDeptData.length; j++) {
		if (!!checkedDeptData[j]) {
			templ += '<span class="commonFileName leadersDel" data-id="' + checkedDeptData[j].id + '">' + checkedDeptData[j].name + '(' + (!!checkedDeptData[j].deptTopname ? (checkedDeptData[j].upLeveldeptname + ',' + checkedDeptData[j].deptTopname) : checkedDeptData[j].upLeveldeptname) + ')<i></i></span>';
		}
	}
	$('.modalDialogDept .checkedList').html(templ);
})

// 流程选择器
$("body").on("click", "#processSelect", function () {
	if (!basFlow.curId[0]) {
		basFlow.alertBox($.i18n.prop("firstChooseNode") + "! ", 'danger');
		return false
	}
	$.ajax({
		type: "post",
		// url: basFlow.baseUrl + "/modeltree/getTreeNode/0",
		url: basFlow.baseUrl + "/modeltree/getTreeNodeWithoutAuth/0?username=" + basFlow.username,
		success: function (data) {
			console.log(data);
			for (var i = 0; i < data.length; i++) {
				data[i].isParent = data[i].isparent;
			}
			initProcessTree(data)
		}
	})
	var doTData = doT.template($('#attr_templ').text());
	var templ = '';
	if (/CONTROL/.test(basFlow.curId)) {
		temStore = basFlow.controls[basFlow.curId[0]]
	} else {
		temStore = basFlow.swimlanes[basFlow.curId[0]]
	}
	console.log(temStore)
	checkedProcessData = JSON.parse('{"process":' + JSON.stringify(temStore.processGroup) + '}').process;
	$(".modalDialogProcess").show();
	for (var j = 0; j < checkedProcessData.length; j++) {
		templ += '<span class="commonFileName processDel" data-id="' + checkedProcessData[j].id + '">' + checkedProcessData[j].name + '<i></i></span>'
	}
	$('.modalDialogProcess .checkedList').html(templ);
})

$("body").on("click", ".chooseRole", function () {
	if (!basFlow.curId[0]) {
		basFlow.alertBox($.i18n.prop("firstChooseNode") + "! ", 'danger');
		return false
	}
	referType = "role";
	$.ajax({
		type: "post",
		url: basFlow.baseUrl + "/select/user/cqp/getTotalOrg/0",
		success: function (data) {
			initOrgTree(data)
		}
	})
	var doTData = doT.template($('#attr_templ').text())
	if (/CONTROL/.test(basFlow.curId)) {
		temStore = basFlow.controls[basFlow.curId[0]]
	} else {
		temStore = basFlow.swimlanes[basFlow.curId[0]]
	}
	checkedData = temStore.role;
	$(".modalDialog").show();
})

$(".modalDialog .dialog-content").on("click", function (e) {
	event.stopPropagation();
})


// 选择规章制度文档
$("body").delegate("#selectRegulations", "click", function () {
	if (!basFlow.curId[0]) {
		basFlow.alertBox($.i18n.prop("firstChooseNode") + "! ", 'danger');
		return false
	}
	$.ajax({
		type: "Get",
		// url: basFlow.baseUrl + "/modeltree/getTreeNode/0",
		url: basFlow.baseUrl + "/regulation/getFolderAll",
		success: function (data) {
			console.log(data);
			// for (var i = 0; i < data.length; i++) {
			//
			// 	if (getCookie("lan-local") == 'en'){
			// 		data[i].foldername = data[i].foldername;
			// 	} else{
			// 		data[i].foldername = data[i].enname;
			// 	}
			//
			// }
			initRegulationsTree(data)
		}
	})
	var doTData = doT.template($('#attr_templ').text());
	var templ = '';
	if (/CONTROL/.test(basFlow.curId)) {
		temStore = basFlow.controls[basFlow.curId[0]]
	} else {
		temStore = basFlow.swimlanes[basFlow.curId[0]]
	}
	console.log(temStore)
	$(".modalDialogRegulations").show();
	if (!temStore.keyControl.documentlist) {
		return;
	}
	checkedRegulationsData = JSON.parse('{"documentlist":' + JSON.stringify(temStore.keyControl.documentlist) + '}').documentlist;

	for (var j = 0; j < checkedRegulationsData.length; j++) {
		templ += '<span class="commonFileName documentDel" data-id="' + checkedRegulationsData[j].id + '">' + checkedRegulationsData[j].foldername + '<i></i></span>'
	}
	$('.modalDialogRegulations .checkedList').html(templ);
})


/*tab 切换*/
$(".tabsContent .left .common").on("click", function () {
	var index = $(".tabsContent .left .common").index($(this));
	$(".tabsContent .left .common").removeClass("active");
	$(this).addClass("active");
	$(".tabsContent .center .centerContent").removeClass("block");
	$(".tabsContent .center .centerContent").eq(index).addClass("block");
	checkedData = [];
	if (index == 0) {
		$.ajax({
			type: "post",
			url: basFlow.baseUrl + "/select/user/cqp/getTotalOrg/0",
			success: function (data) {
				initOrgTree(data)
			}
		})
	} else if (index == 1) {
		getCommonlyUsers(11, function (resp) {
			if (!resp.pages) {
				$("#navagationPage").children("li").remove();
				return false;
			}
			$.jqPaginator('#navagationPage', {
				totalPages: resp.pages,
				visiblePages: 5,
				currentPage: pageNum,
				first: '<li class="first"><a href="javascript:;" class="iconfont icon-diyiyeshouyeshangyishou" title="' + $.i18n.prop("firstPage") + '"></a></li>',
				prev: '<li class="prev"><a href="javascript:;" class="iconfont icon-shangyiye" title="' + $.i18n.prop("prevPage") + '"></a></li>',
				next: '<li class="next"><a href="javascript:;" class="iconfont icon-xiayiye" title="' + $.i18n.prop("nextPage") + '"></a></li>',
				last: '<li class="last"><a href="javascript:;" class="iconfont icon-zuihouyiyemoyexiayishou" title="' + $.i18n.prop("endPage") + '"></a></li>',
				page: '<li><a href="javascript:;">{{page}}</a></li>',
				onPageChange: function (num, type) {
					getCommonlyUsers(11, false, num)
				}
			});
		}, pageNum)
	} else if (index == 2) {
		getUserQuery(function (resp) {
			if (!resp.pages) {
				$("#navagationPage").children("li").remove();
				return false;
			}
			$.jqPaginator('#navagationPage', {
				totalPages: resp.pages,
				visiblePages: 5,
				currentPage: pageNum,
				first: '<li class="first"><a href="javascript:;" class="iconfont icon-diyiyeshouyeshangyishou" title="' + $.i18n.prop("firstPage") + '"></a></li>',
				prev: '<li class="prev"><a href="javascript:;" class="iconfont icon-shangyiye" title="' + $.i18n.prop("prevPage") + '"></a></li>',
				next: '<li class="next"><a href="javascript:;" class="iconfont icon-xiayiye" title="' + $.i18n.prop("nextPage") + '"></a></li>',
				last: '<li class="last"><a href="javascript:;" class="iconfont icon-zuihouyiyemoyexiayishou" title="' + $.i18n.prop("endPage") + '"></a></li>',
				page: '<li><a href="javascript:;">{{page}}</a></li>',
				onPageChange: function (num, type) {
					getUserQuery(false, num)
				}
			});
		}, pageNum)
	}
})

// 人员组织搜索
$(".immediateSearch").on("click", function () {
	getUserQuery(function (resp) {
		if (!resp.pages) {
			$("#navagationPage").children("li").remove();
			return false;
		}
		$.jqPaginator('#navagationPage', {
			totalPages: resp.pages,
			visiblePages: 5,
			currentPage: pageNum,
			first: '<li class="first"><a href="javascript:;" class="iconfont icon-diyiyeshouyeshangyishou" title="' + $.i18n.prop("firstPage") + '"></a></li>',
			prev: '<li class="prev"><a href="javascript:;" class="iconfont icon-shangyiye" title="' + $.i18n.prop("prevPage") + '"></a></li>',
			next: '<li class="next"><a href="javascript:;" class="iconfont icon-xiayiye" title="' + $.i18n.prop("nextPage") + '"></a></li>',
			last: '<li class="last"><a href="javascript:;" class="iconfont icon-zuihouyiyemoyexiayishou" title="' + $.i18n.prop("endPage") + '"></a></li>',
			page: '<li><a href="javascript:;">{{page}}</a></li>',
			onPageChange: function (num, type) {
				getUserQuery(false, num)
			}
		});
	}, pageNum)
})

// 重置人员选择的条件
$(".resetOptions").on("click", function () {
	$("#inputName").val("");
	$("#inputPos").val("");
	$("#inputRole").val("");
})

// 确定
$(".modalDialog .confirmPerson").on("click", function () {
	if (!basFlow.curId[0]) {
		basFlow.alertBox($.i18n.prop("firstChooseNode") + "! ", 'danger');
		return false
	}
	var temStore = {};

	var doTData = doT.template($('#attr_templ').text())
	if (/CONTROL/.test(basFlow.curId)) {
		temStore = basFlow.controls[basFlow.curId[0]]
	} else {
		temStore = basFlow.swimlanes[basFlow.curId[0]]
	}
	if (referType == "role") {
		temStore.role = checkedData;
		$(".content_wrapper .content_item").eq(1).html(doTData({
			attrList: temStore,
			listProcess: basFlow.storeUpgressData.bpmDto ? (basFlow.storeUpgressData.bpmDto.outputlist ? basFlow.storeUpgressData.bpmDto.outputlist : []) : []
		}))
		$("#" + basFlow.curId).find('.role').text(checkedData[0].cnname)
	} else if (referType == "leader") {
		temStore.leaders = checkedData;
		$(".content_wrapper .content_item").eq(1).html(doTData({
			attrList: temStore,
			listProcess: basFlow.storeUpgressData.bpmDto ? (basFlow.storeUpgressData.bpmDto.outputlist ? basFlow.storeUpgressData.bpmDto.outputlist : []) : []
		}))
		if (temStore.id.indexOf("SWIMLANE") > -1) {
			var tempStr = "";
			for (var m = 0; m < temStore.leaders.length; m++) {
				tempStr += (m == 0 ? "" : ",") + temStore.leaders[m].cnname;
			}
			$("#" + temStore.id + " .J_swimlaneTitle").attr("title", tempStr);
		}
	}
	$(".modalDialog").hide();
})

// 选择部门确定
$(".modalDialogDept .confirmPerson").on("click", function () {
	if (!basFlow.curId[0]) {
		basFlow.alertBox($.i18n.prop("firstChooseNode") + "! ", 'danger');
		return false
	}
	var temStore = {};
	var doTData = doT.template($('#attr_templ').text())
	if (basFlow.curId[0].indexOf('CONTROL') > -1) {
		temStore = basFlow.controls[basFlow.curId[0]]
		temStore[referType] = checkedDeptData;
		$(".content_wrapper .content_item").eq(1).html(doTData({
			attrList: temStore,
			listProcess: basFlow.storeUpgressData.bpmDto ? (basFlow.storeUpgressData.bpmDto.outputlist ? basFlow.storeUpgressData.bpmDto.outputlist : []) : []
		}))
	} else {
		temStore = basFlow.swimlanes[basFlow.curId[0]]
		temStore.depts = checkedDeptData;
		$(".content_wrapper .content_item").eq(1).html(doTData({
			attrList: temStore,
			listProcess: basFlow.storeUpgressData.bpmDto ? (basFlow.storeUpgressData.bpmDto.outputlist ? basFlow.storeUpgressData.bpmDto.outputlist : []) : []
		}))
		console.log(temStore)

		var swimlaneTempl = doT.template($('#swimlane-content').text());
		$("#" + basFlow.curId[0]).find(".swimlane-title").remove()
		$("#" + basFlow.curId[0]).prepend(swimlaneTempl(temStore))

		if (basFlow.swimYheight !== 90) {
			$("#" + basFlow.curId[0] + " .showMemberTitle").css({
				"width": basFlow.swimXwidth - 10,
				"transform": 'scale(' + basFlow.scaleTo + ') translateY(-50%) translateX(-50%)'
			})
			$("#" + basFlow.curId[0] + " .swimlane-title").css({
				"width": basFlow.swimXwidth * basFlow.scaleTo,
				"height": basFlow.swimlanes[basFlow.curId[0]].height * basFlow.scaleTo
			})
		} else {
			$("#" + basFlow.curId[0] + ".swimlaneY .swimlane-title .showMemberTitle ").css({
				"width": (basFlow.swimlanes[basFlow.curId[0]].width - 20),
				"transform": 'scale(' + basFlow.scaleTo + ') translateY(-50%) translateX(-50%)'
			})
			$("#" + basFlow.curId[0] + ".swimlaneY .swimlane-title").css({
				"height": basFlow.swimYheight * basFlow.scaleTo
			})
		}
	}
	$(".modalDialogDept").hide();
})

// 选择流程确定
$(".modalDialogProcess .confirmProcess").on("click", function () {
	if (!basFlow.curId[0]) {
		basFlow.alertBox($.i18n.prop("firstChooseNode") + "! ", 'danger');
		return false
	}
	var temStore = {};
	var doTData = doT.template($('#attr_templ').text())
	if (/CONTROL/.test(basFlow.curId)) {
		temStore = basFlow.controls[basFlow.curId[0]]
	} else {
		temStore = basFlow.swimlanes[basFlow.curId[0]]
	}
	console.log(temStore)
	temStore.processGroup = checkedProcessData;
	console.log(checkedProcessData)
	if (temStore.img.indexOf("process.png") > -1) {
		temStore.name = checkedProcessData[0].name
		$("#" + basFlow.curId[0] + " .text span").text(temStore.name)
		if (temStore.splitType) {
			console.log(temStore.splitType)
			if (temStore.splitType === 'upProcess') {
				temStore.inputname = checkedProcessData[0].id
				jQuery.support.cors = true;
				$.ajax({
					type: 'POST',
					url: basFlow.baseUrl + '/modellist/getByModelid/' + temStore.inputname + '?username=' + basFlow.username,
					data: {},
					async: false,
					success: function (res) {
						basFlow.storeUpgressData = res
					},
					error: function (err) {
						console.log(err)
					}
				})
			}
			else if (temStore.splitType === 'downProcess') {
				temStore.outputname = checkedProcessData[0].id
			}
		}
	}

	if ((temStore.img.indexOf("process02.png") > -1) || (temStore.img.indexOf("process03.png") > -1)) {
		temStore.name = checkedProcessData[0].name
		$("#" + basFlow.curId[0] + " .text span").text(temStore.name)
	}

	if (checkedProcessData.length != 0) {
		$("#point" + basFlow.curId[0]).show();
		// console.log(basFlow.curId[0])
	}

	var processlist = [];
	if (temStore && (temStore.splitType == "upProcess")) {
		if (!basFlow.storeUpgressData.bpmDto) {
			processlist = []
		} else {
			processlist = basFlow.storeUpgressData.bpmDto.outputlist ? basFlow.storeUpgressData.bpmDto.outputlist : [];
			if (basFlow.storeUpgressData.bpmDto.outputlist) {
				for (var i = 0; i < basFlow.storeUpgressData.bpmDto.outputlist.length; i++) {
					for (var j = 0; j < temStore.output.length; j++) {
						if (basFlow.storeUpgressData.bpmDto.outputlist[i].id == temStore.output[j].id) {
							basFlow.storeUpgressData.bpmDto.outputlist[i].isChecked = true;
						}
					}
				}
			}
		}
	}
	console.log(processlist)
	console.log(temStore)
	$(".content_wrapper .content_item").eq(1).html(doTData({
		attrList: temStore,
		listProcess: processlist
	}))

	for (var i = 0; i < $("#pointAttr li").length; i++) {
		if ($("#pointAttr li").eq(i).text() === $.i18n.prop("referProcess")) {
			$("#pointAttr li").eq(i).siblings().removeClass("active");
			$("#pointAttr li").eq(i).addClass("active");
			$(".attr1Box").children().siblings().css("display", "none");
			$(".attr1Box").children().eq(i).css("display", "block");
			break;
		}
	}
	$(".modalDialogProcess").hide();
})


// 选择文档确定
$(".modalDialogRegulations .confirmProcess").on("click", function () {
	if (!basFlow.curId[0]) {
		basFlow.alertBox($.i18n.prop("firstChooseNode") + "! ", 'danger');
		return false
	}
	var temStore = {};
	var doTData = doT.template($('#attr_templ').text())
	if (/CONTROL/.test(basFlow.curId)) {
		temStore = basFlow.controls[basFlow.curId[0]]
	} else {
		temStore = basFlow.swimlanes[basFlow.curId[0]]
	}
	console.log(temStore)
	temStore.keyControl.documentlist = checkedRegulationsData;
	console.log(checkedRegulationsData)
	if (checkedRegulationsData.length > 0) {
		$("input[name='remark']").val('')
	}
	console.log(temStore)
	var formData = $("#keyControlForm").serializeArray();
	$(".content_wrapper .content_item").eq(1).html(doTData({
		attrList: temStore,
		listProcess: []
	}))

	for (var i = 0; i < formData.length; i++) {
		$("#keyControlForm").find("*[name=" + formData[i].name + "]").val(formData[i].value)
	}


	for (var i = 0; i < $("#pointAttr li").length; i++) {
		if ($("#pointAttr li").eq(i).text() === $.i18n.prop("KRCP")) {
			$("#pointAttr li").eq(i).siblings().removeClass("active");
			$("#pointAttr li").eq(i).addClass("active");
			$(".attr1Box").children().siblings().css("display", "none");
			$(".attr1Box").children().eq(i).css("display", "block");
			break;
		}
	}
	$(".modalDialogRegulations").hide();
})


$("body").on("click", ".leadersDel i", function () {
	if (!basFlow.curId[0]) {
		basFlow.alertBox($.i18n.prop("firstChooseNode") + "! ", 'danger');
		return false
	}
	var doTData = doT.template($('#attr_templ').text());
	var userid = $(this).parent().attr('data-id');
	checkedData = basFlow.controls[basFlow.curId].leaders;
	for (var i = 0; i < checkedData.length; i++) {
		if (checkedData[i].userid == userid) {
			checkedData.splice(i, 1);
			$('input[data-id="' + userid + '"]').removeAttr('checked')
			break;
		}
	}
	temStore = basFlow.controls[basFlow.curId]
	temStore.leaders = checkedData;

	$(".content_wrapper").children().eq(1).html(doTData({
		attrList: temStore,
		listProcess: basFlow.storeUpgressData.bpmDto ? (basFlow.storeUpgressData.bpmDto.outputlist ? basFlow.storeUpgressData.bpmDto.outputlist : []) : []
	}))
})

$("body").on("click", ".processDel i", function () {
	if (!basFlow.curId[0]) {
		basFlow.alertBox($.i18n.prop("firstChooseNode") + "! ", 'danger');
		return false
	}
	var doTData = doT.template($('#attr_templ').text());
	var userid = $(this).parent().attr('data-id');
	checkedData = basFlow.controls[basFlow.curId].processGroup;
	for (var i = 0; i < checkedData.length; i++) {
		if (checkedData[i].id == userid) {
			checkedData.splice(i, 1);
			$('input[data-id="' + userid + '"]').removeAttr('checked')
			break;
		}
	}
	temStore = basFlow.controls[basFlow.curId]
	temStore.processGroup = checkedData;
	if (temStore.img.indexOf("process.png") > -1) {
		temStore.name = ''
		$("#" + basFlow.curId[0] + " .text span").text(temStore.name)
		if (temStore.splitType) {
			if (temStore.splitType === 'upProcess') {
				temStore.inputname = ''
			}
			else if (temStore.splitType === 'downProcess') {
				temStore.outputname = ''
			}
		}
	}
	if (checkedData.length === 0) {
		$("#point" + basFlow.curId[0]).hide();
	}
	var processlist = [];
	if (temStore && (temStore.splitType == "upProcess")) {
		if (!basFlow.storeData.bpmDto) {
			processlist = []
		} else {
			processlist = basFlow.storeData.bpmDto.outputlist ? basFlow.storeData.bpmDto.outputlist : [];
			if (basFlow.storeData.bpmDto.outputlist) {
				for (var i = 0; i < basFlow.storeData.bpmDto.outputlist.length; i++) {
					for (var j = 0; j < temStore.output.length; j++) {
						if (basFlow.storeData.bpmDto.outputlist[i].id == temStore.output[j].id) {
							basFlow.storeData.bpmDto.outputlist[i].isChecked = true;
						}
					}
				}
			}
		}
	}
	$(".content_wrapper").children().eq(1).html(doTData({
		attrList: temStore,
		listProcess: processlist
	}))
	for (var i = 0; i < $("#pointAttr li").length; i++) {
		if ($("#pointAttr li").eq(i).text() === $.i18n.prop("referProcess")) {
			$("#pointAttr li").eq(i).siblings().removeClass("active");
			$("#pointAttr li").eq(i).addClass("active");
			$(".attr1Box").children().siblings().css("display", "none");
			$(".attr1Box").children().eq(i).css("display", "block");
			break;
		}
	}
	$(this).parent().remove();
})
// 点击引用流程
$("body").on("click", ".processDel", function () {
	var id = $(this).attr('data-id')
	console.log(id)
	console.log(basFlow.storeUpgressData)
	// $(location).attr("href", "?id=" + id + "&listid=A739F2F74CF66625E0531701A8C0CB37&isReadAttr=true")
})

$("body").on("click", ".messageDel i", function () {
	if (!basFlow.curId[0]) {
		basFlow.alertBox($.i18n.prop("firstChooseNode") + "! ", 'danger');
		return false
	}
	var doTData = doT.template($('#attr_templ').text());
	var userid = $(this).parent().attr('data-id');
	checkedData = basFlow.controls[basFlow.curId].messageGroup;
	for (var i = 0; i < checkedData.length; i++) {
		if (checkedData[i].id == userid) {
			checkedData.splice(i, 1);
			$('input[data-id="' + userid + '"]').removeAttr('checked')
			break;
		}
	}
	temStore = basFlow.controls[basFlow.curId]
	temStore.messageGroup = checkedData;
	if (checkedData.length === 0) {
		$("#point" + basFlow.curId[0]).hide();
	}
	$(".content_wrapper").children().eq(1).html(doTData({
		attrList: temStore,
		listProcess: basFlow.storeUpgressData.bpmDto ? (basFlow.storeUpgressData.bpmDto.outputlist ? basFlow.storeUpgressData.bpmDto.outputlist : []) : []
	}))
	$(this).parent().remove();
})

$("body").on("click", ".deptsDel i", function () {
	if (!basFlow.curId[0]) {
		basFlow.alertBox($.i18n.prop("firstChooseNode") + "! ", 'danger');
		return false
	}
	var doTData = doT.template($('#attr_templ').text());
	var userid = $(this).parent().attr('data-id');
	checkedDeptData = basFlow.swimlanes[basFlow.curId].depts;
	for (var i = 0; i < checkedDeptData.length; i++) {
		if (checkedDeptData[i].id == userid) {
			if (checkedDeptData[i].type == 1 || checkedDeptData[i].type == 0 || checkedDeptData[i].type == 2) {
				checkedDeptData = []
				$(".tabsContentDept .left .common").removeClass("active");
				$(".tabsContentDept .left .common").eq(0).addClass("active");
				$(".tabsContentDept .center .centerContent").removeClass("block");
				$(".tabsContentDept .center .centerContent").eq(0).addClass("block");
				$.ajax({
					type: "post",
					url: basFlow.baseUrl + "/select/user/cqp/getTotalOrg/0",
					success: function (data) {
						initStationTree(data)
					}
				})
			} else {
				checkedDeptData.splice(i, 1);
			}
			break;
		}
	}
	if (!checkedDeptData.length) {
		$('.modalDialogDept .checkedList').html('');
	} else {
		var templ = "";
		for (var j = 0; j < checkedDeptData.length; j++) {
			if (!!checkedDeptData) {
				templ += '<span class="commonFileName leadersDel" data-id="' + checkedDeptData[j].id + '">' + checkedDeptData[j].name + '(' + (!!checkedDeptData[j].deptTopname ? (checkedDeptData[j].upLeveldeptname + ',' + checkedDeptData[j].deptTopname) : checkedDeptData[j].upLeveldeptname) + ')<i></i></span>';
			}
		}
		$('.modalDialogDept .checkedList').html(templ);
	}
	temStore = basFlow.swimlanes[basFlow.curId]
	temStore.depts = checkedDeptData;

	$(".content_wrapper").children().eq(1).html(doTData({
		attrList: temStore,
		listProcess: basFlow.storeUpgressData.bpmDto ? (basFlow.storeUpgressData.bpmDto.outputlist ? basFlow.storeUpgressData.bpmDto.outputlist : []) : []
	}))
	if (!temStore.depts.length) {
		$(".modalDialogDept").hide();
		$("#" + temStore.id + " .J_swimlaneTitle p").html('');
		$("#" + temStore.id + " .J_swimlaneTitle p").attr({
			'title': ''
		});
		return false;
	}
	var tempDepts = "";
	var tempStation = "";
	for (var m = 0; m < temStore.depts.length; m++) {
		tempDepts += (m == 0 ? "" : ",") + temStore.depts[m].upLeveldeptname + (!temStore.depts[m].deptTopname ? '' : '(' + temStore.depts[m].deptTopname + ')');
		tempStation += (m == 0 ? "" : ",") + temStore.depts[m].name;
	}
	// $("#" + temStore.id + " .J_swimlaneTitle").attr("title", tempStr);
	$("#" + temStore.id + " .J_swimlaneTitle p").html($.i18n.prop("depts") + ':' + temStore.depts[0].upLeveldeptname + (!temStore.depts[0].deptTopname ? '' : '(' + temStore.depts[0].deptTopname + ')') + (temStore.depts.length > 1 ? '...' : '') + '<br />' + $.i18n.prop("station") + ':' + temStore.depts[0].name + (temStore.depts.length > 1 ? '...' : ''));
	$("#" + temStore.id + " .J_swimlaneTitle p").attr({
		'title': $.i18n.prop("depts") + ':' + tempDepts + '\n' + $.i18n.prop("station") + ':' + tempStation
	});
	$(this).parent().remove();
})

$("body").on("click", ".deptsDel2 i", function () {
	if (!basFlow.curId[0]) {
		basFlow.alertBox($.i18n.prop("firstChooseNode") + "! ", 'danger');
		return false
	}
	var doTData = doT.template($('#attr_templ').text());
	var userid = $(this).parent().attr('data-id');
	referType = $(this).attr("data-type")
	checkedDeptData = basFlow.controls[basFlow.curId][referType];
	for (var i = 0; i < checkedDeptData.length; i++) {
		if (checkedDeptData[i].id == userid) {
			checkedDeptData.splice(i, 1);
			$('input[data-id="' + userid + '"]').removeAttr('checked')
			break;
		}
	}
	temStore = basFlow.controls[basFlow.curId]
	temStore[referType] = checkedDeptData;

	$(".content_wrapper").children().eq(1).html(doTData({
		attrList: temStore,
		listProcess: basFlow.storeUpgressData.bpmDto ? (basFlow.storeUpgressData.bpmDto.outputlist ? basFlow.storeUpgressData.bpmDto.outputlist : []) : []
	}))
})

// 删除选中的文档
$("body").on("click", ".uploadregutions .deleteFileDoc i", function () {
	if (!basFlow.curId[0]) {
		basFlow.alertBox($.i18n.prop("firstChooseNode") + "! ", 'danger');
		return false
	}
	var doTData = doT.template($('#attr_templ').text());
	var userid = $(this).parent().attr('file-id');
	for (var i = 0; i < checkedRegulationsData.length; i++) {
		if (checkedRegulationsData[i].id == userid) {
			checkedRegulationsData.splice(i, 1);
			break;
		}
	}
	if (!checkedRegulationsData.length) {
		$('.modalDialogRegulations .checkedList').html('');
	} else {
		var templ = "";
		for (var j = 0; j < checkedRegulationsData.length; j++) {
			templ += '<span class="commonFileName documentDel" data-id="' + checkedRegulationsData[j].id + '">' + checkedRegulationsData[j].foldername + '<i></i></span>'
		}
		$('.modalDialogRegulations .checkedList').html(templ);
	}
	temStore = basFlow.controls[basFlow.curId]
	temStore.keyControl.documentlist = checkedRegulationsData;

	$(".content_wrapper").children().eq(1).html(doTData({
		attrList: temStore,
		listProcess: []
	}))
	for (var i = 0; i < $("#pointAttr li").length; i++) {
		if ($("#pointAttr li").eq(i).text() === $.i18n.prop("KRCP")) {
			$("#pointAttr li").eq(i).siblings().removeClass("active");
			$("#pointAttr li").eq(i).addClass("active");
			$(".attr1Box").children().siblings().css("display", "none");
			$(".attr1Box").children().eq(i).css("display", "block");
			break;
		}
	}
})

//删除弹出框选中的文档
$("body").on("click", ".documentDel i", function () {
	if (!basFlow.curId[0]) {
		basFlow.alertBox($.i18n.prop("firstChooseNode") + "! ", 'danger');
		return false
	}
	var userid = $(this).parent().attr('data-id');
	for (var i = 0; i < checkedRegulationsData.length; i++) {
		if (checkedRegulationsData[i].id == userid) {
			checkedRegulationsData.splice(i, 1);
			break;
		}
	}
	var templ = "";
	for (var j = 0; j < checkedRegulationsData.length; j++) {
		templ += '<span class="commonFileName documentDel" data-id="' + checkedRegulationsData[j].id + '">' + checkedRegulationsData[j].foldername + '<i></i></span>'
	}
	$('.modalDialogRegulations .checkedList').html(templ);
})

// $(".modalDialog .checkedList").on('click', ".leadersDel i", function () {
// 	if (!basFlow.curId[0]) {
// 		basFlow.alertBox($.i18n.prop("firstChooseNode") + "! ", 'danger');
// 		return false
// 	}
// 	var userid = $(this).parent().attr('data-id');
// 	$('input[data-id="' + userid + '"]').removeAttr('checked');
// 	// 获取操作的下标
// 	var index = $("#tabTableData").find('input[data-id="' + userid + '"]').parents('tr').index();
// 	// 手动触发checkbox的onchange函数
// 	// 如果index等于-1那么就是手动删除checkList里面的元素
// 	checkData(index, $('input[data-id="' + userid + '"]')[0], userid);
// 	$(this).parent().remove();
// })

$(".modalDialogDept .checkedList").on('click', ".leadersDel i", function () {
	if (!basFlow.curId[0]) {
		basFlow.alertBox($.i18n.prop("firstChooseNode") + "! ", 'danger');
		return false
	}
	var userid = $(this).parent().attr('data-id');
	for (var i = 0; i < checkedDeptData.length; i++) {
		console.log(checkedDeptData[i].id)
		console.log(userid)
		if (checkedDeptData[i].id == userid) {
			if (checkedDeptData[i].type == 1 || checkedDeptData[i].type == 0 || checkedDeptData[i].type == 2) {
				checkedDeptData = [];
				$(".tabsContentDept .left .common").removeClass("active");
				$(".tabsContentDept .left .common").eq(0).addClass("active");
				$(".tabsContentDept .center .centerContent").removeClass("block");
				$(".tabsContentDept .center .centerContent").eq(0).addClass("block");
				$.ajax({
					type: "post",
					url: basFlow.baseUrl + "/select/user/cqp/getTotalOrg/0",
					success: function (data) {
						initDeptTree(data)
					}
				})
			} else {
				checkedDeptData.splice(i, 1);
			}
			break;
		}
	}
	if (!checkedDeptData.length) {
		$('.modalDialogDept .checkedList').html('');
		return false;
	}
	$(this).parent().remove();
})

$("body").on("click", ".rolesDel i", function () {
	if (!basFlow.curId[0]) {
		basFlow.alertBox($.i18n.prop("firstChooseNode") + "! ", 'danger');
		return false
	}
	var doTData = doT.template($('#attr_templ').text())
	if (/CONTROL/.test(basFlow.curId)) {
		temStore = basFlow.controls[basFlow.curId]
	} else {
		temStore = basFlow.swimlanes[basFlow.curId]
	}
	temStore.role = [];

	$(".content_wrapper").children().eq(1).html(doTData({
		attrList: temStore
	}))
})


$(".cancelChoose").on("click", function () {
	if (!basFlow.curId[0]) {
		basFlow.alertBox($.i18n.prop("firstChooseNode") + "! ", 'danger');
		return false
	}
	$(".modalDialog").hide();
	$(".modalDialogDept").hide();
	$(".modalDialogProcess").hide();
	$(".modalDialogRegulations").hide();

	if (/CONTROL/.test(basFlow.curId)) {
		temStore = basFlow.controls[basFlow.curId[0]];
		checkedProcessData = temStore.processGroup;
		if (!checkedProcessData) {
			return;
		}
		for (var j = 0; j < checkedProcessData.length; j++) {
			templ += '<span class="commonFileName processDel" data-id="' + checkedProcessData[j].id + '">' + checkedProcessData[j].name + '<i></i></span>'
		}
		$('.modalDialogProcess .checkedList').html(templ);
	} else {
		temStore = basFlow.swimlanes[basFlow.curId[0]]
		checkedDeptData = temStore.depts;
		var templ = "";
		for (var j = 0; j < checkedDeptData.length; j++) {
			if (!!checkedDeptData[j]) {
				templ += '<span class="commonFileName leadersDel" data-id="' + checkedDeptData[j].id + '">' + checkedDeptData[j].name + '(' + (!!checkedDeptData[j].deptTopname ? (checkedDeptData[j].upLeveldeptname + ',' + checkedDeptData[j].deptTopname) : checkedDeptData[j].upLeveldeptname) + ')<i></i></span>';
			}
		}
		$('.modalDialogDept .checkedList').html(templ);
	}
})


//筛选组织树
$("#searchOrg").on("click", function () {
	queryOrgMenu($("#searchOrg").prev().val())
})

//筛选组织树
$("#searchOrgDept").on("click", function () {
	queryOrgDept($("#searchOrgDept").prev().val())
})

//筛选组织树
$("#searchOrgStation").on("click", function () {
	queryOrgStation($("#searchOrgStation").prev().val())
})

$('#searchOrgStation_Input').bind('keyup', function (event) {
	if (event.keyCode == "13") {
		queryOrgStation($("#searchOrgStation").prev().val())
	}
})


//筛选组织树
$("#searchOrgProcess").on("click", function () {
	queryOrgProcess($("#searchOrgProcess").prev().val())
})
$('#searchOrg_Input').bind('keyup', function (event) {
	if (event.keyCode == "13") {
		queryOrgProcess($("#searchOrgProcess").prev().val())
	}
})

function treeFilter(treeId, parentNode, childNodes) {
	return childNodes;
}

function initCheckList() {
	// var checkList = basFlow.controls[basFlow.curId[0]].leaders;
	if (/CONTROL/.test(basFlow.curId)) {
		checkList = basFlow.controls[basFlow.curId].leaders;
	} else {
		checkList = basFlow.swimlanes[basFlow.curId].leaders;
	}
	var templ = '';
	for (var j = 0; j < checkList.length; j++) {
		templ += '<span class="commonFileName leadersDel" data-id="' + checkList[j].userid + '">' + checkList[j].cnname + '<i></i></span>'
	}
	$('.checkedList').html(templ);
}
// 初始化组织树
function initOrgTree(data) {
	if (!data.length) {
		$("#treeDemo").html('');
		return false;
	}
	var zTree = $.fn.zTree.init($("#treeDemo"), {
		async: {
			enable: true,
			url: function (treeid, treeNode) {
				return basFlow.baseUrl + "/select/user/cqp/getTotalOrg/" + treeNode.ID
			},
			// autoParam:["ID"],
			dataFilter: treeFilter()
		},
		check: {
			enable: false, //true / false 分别表示 显示 / 不显示 复选框或单选框
			chkboxType: {
				"Y": "",
				"N": ""
			}
		},
		data: {
			key: {
				name: "NAME"
			},
			simpleData: {
				enable: true,
				idKey: 'ID',
				pIdKey: 'PID',
				rootPId: 0,
			}
		},
		view: {
			showIcon: false
		},
		callback: {
			onClick: function (event, treeId, treeNode) {
				treeClickId = treeNode.ID;
				getOrgUsers(treeNode.ID, function (resp) {
					if (!resp.pages) {
						$("#processNavagationPage").children("li").remove();
						return false;
					}
					$.jqPaginator('#navagationPage', {
						totalPages: resp.pages,
						visiblePages: 5,
						currentPage: pageNum,
						first: '<li class="first"><a href="javascript:;" class="iconfont icon-diyiyeshouyeshangyishou" title="' + $.i18n.prop("firstPage") + '"></a></li>',
						prev: '<li class="prev"><a href="javascript:;" class="iconfont icon-shangyiye" title="' + $.i18n.prop("prevPage") + '"></a></li>',
						next: '<li class="next"><a href="javascript:;" class="iconfont icon-xiayiye" title="' + $.i18n.prop("nextPage") + '"></a></li>',
						last: '<li class="last"><a href="javascript:;" class="iconfont icon-zuihouyiyemoyexiayishou" title="' + $.i18n.prop("endPage") + '"></a></li>',
						page: '<li><a href="javascript:;">{{page}}</a></li>',
						onPageChange: function (num, type) {
							getOrgUsers(treeClickId, false, num)
						}
					});
				}, pageNum)
			},
		}
	}, data);
	//让第一个父节点展开
	var nodes = zTree.getNodes();
	zTree.selectNode(nodes[0]);
	zTree.setting.callback.onClick(null, zTree.setting.treeId, nodes[0]);
	if (nodes.length > 0) {
		for (var i = 0; i < nodes.length; i++) {
			zTree.expandNode(nodes[i], true, false, false); //默认展开第一级节点
		}
	}
}


// 选择部门
function initDeptTree(data) {
	if (!data.length) {
		$("#treeDept").html('');
		return false;
	}
	for (var i = 0; i < data.length; i++) {
		if (data[i].TYPE == '0' || data[i].TYPE == '1') {
			data[i].chkDisabled = true;
		}
	}
	var zTree = $.fn.zTree.init($("#treeDept"), {
		async: {
			enable: true,
			url: function (treeid, treeNode) {
				return basFlow.baseUrl + "/select/user/cqp/getTotalOrg1"
			},
			otherParam: function (treeid, treeNode) {
				return {
					pid: treeNode.ID,
					type: '0,1,2,4'
				};
			},
			dataType: 'json',
			contentType: 'application/json;charset=UTF-8',
			dataFilter: function (treeId, parentNode, childNodes) {
				for (var i = 0; i < childNodes.length; i++) {
					if (childNodes[i].TYPE == '3' || childNodes[i].TYPE == '0' || childNodes[i].TYPE == '1') {
						childNodes[i].chkDisabled = true;
					}
				}
				return childNodes;
			}
		},
		check: {
			enable: true, //true / false 分别表示 显示 / 不显示 复选框或单选框
			chkboxType: {
				"Y": "",
				"N": ""
			}
		},
		data: {
			key: {
				name: "NAME"
			},
			simpleData: {
				enable: true,
				idKey: 'ID',
				pIdKey: 'PID',
				rootPId: 0,
			}
		},
		view: {
			showIcon: false
		},
		callback: {
			onClick: function (event, treeId, treeNode) {
				treeClickId = treeNode.ID;
			},
			beforeCheck: function (treeId, treeNode) {
				// if(checkedDeptData[0]){
				//     if (checkedDeptData[0].id != treeNode.ID) {
				//         var treeObj = $.fn.zTree.getZTreeObj("treeDept");
				//         treeObj.checkAllNodes(false);
				//     }
				// }
			},
			onCheck: function (event, treeId, treeNode) {
				var treeObj = $.fn.zTree.getZTreeObj("treeDept");
				console.log(treeObj.getCheckedNodes())
				if (treeNode.checked) {
					checkedDeptData = [];
					checkedDeptData[0] = {
						id: treeNode.ID,
						name: treeNode.NAME,
						pid: treeNode.PID,
						type: treeNode.TYPE
					};
					var templ = "";
					for (var j = 0; j < checkedDeptData.length; j++) {
						templ += '<span class="commonFileName leadersDel" data-id="' + checkedDeptData[j].id + '">' + checkedDeptData[j].name + '<i></i></span>'
					}
					$('.modalDialogDept .checkedList').html(templ);
				} else {
					for (var i = 0; i < checkedDeptData.length; i++) {
						if (checkedDeptData[i].id == treeNode.ID) {
							checkedDeptData.splice(i, 1);
						}
					}
					var templ = "";
					for (var j = 0; j < checkedDeptData.length; j++) {
						templ += '<span class="commonFileName leadersDel" data-id="' + checkedDeptData[j].id + '">' + checkedDeptData[j].name + '<i></i></span>'
					}
					$('.modalDialogDept .checkedList').html(templ);
					return false;
				}
			}
		}
	}, data);
	//让第一个父节点展开
	var nodes = zTree.getNodes();
	zTree.selectNode(nodes[0]);
	zTree.setting.callback.onClick(null, zTree.setting.treeId, nodes[0]);
	if (nodes.length > 0) {
		for (var i = 0; i < nodes.length; i++) {
			zTree.expandNode(nodes[i], true, false, false); //默认展开第一级节点
		}
	}
}

// 选择岗位
function initStationTree(data) {
	if (!data.length) {
		$("#treeStation").html('');
		return false;
	}
	for (var i = 0; i < data.length; i++) {
		if (data[i].TYPE == '0' || data[i].TYPE == '1' || data[i].TYPE == '2' || data[i].TYPE == '4') {
			data[i].chkDisabled = true;
		}
	}
	var zTree = $.fn.zTree.init($("#treeStation"), {
		async: {
			enable: true,
			url: function () {
				return basFlow.baseUrl + "/select/user/cqp/getTotalOrg1";
			},
			otherParam: function (treeid, treeNode) {
				return {
					pid: treeNode.ID,
					type: '0,1,2,3,4'
				};
			},
			dataType: 'json',
			contentType: 'application/json;charset=UTF-8',
			dataFilter: function (treeId, parentNode, childNodes) {
				for (var i = 0; i < childNodes.length; i++) {
					if (childNodes[i].TYPE == '0' || childNodes[i].TYPE == '1' || childNodes[i].TYPE == '4' || childNodes[i].TYPE == '2') {
						childNodes[i].chkDisabled = true;
					}
					for (var j = 0; j < checkedDeptData.length; j++) {
						if (childNodes[i].ID == checkedDeptData[j].id) {
							childNodes[i].checked = true;
							break;
						}
					}
				}
				return childNodes;
			}
		},
		check: {
			enable: true, //true / false 分别表示 显示 / 不显示 复选框或单选框
			chkboxType: {
				"Y": "",
				"N": ""
			}
		},
		data: {
			key: {
				name: "NAME"
			},
			simpleData: {
				enable: true,
				idKey: 'ID',
				pIdKey: 'PID',
				rootPId: 0,
			}
		},
		view: {
			showIcon: false
		},
		callback: {
			onClick: function (event, treeId, treeNode) {
				treeClickId = treeNode.ID;
				storeSelectUsers = []
				storeSelectUsers = [{
					name: '12212',
					isChecked: false
				}]
				showusers(storeSelectUsers)
			},
			beforeCheck: function (treeId, treeNode) {
				// if(checkedDeptData[0]){
				//     if (checkedDeptData[0].id != treeNode.ID) {
				//         var treeObj = $.fn.zTree.getZTreeObj("treeStation");
				//         treeObj.checkAllNodes(false);
				//     }
				// }
			},
			onCheck: function (event, treeId, treeNode) {
				var treeObj = $.fn.zTree.getZTreeObj("treeStation");
				// 岗位查询 判断是否未查询出的
				console.log(treeObj.getCheckedNodes(), zTree.getNodesByParam("ID", treeNode.PID, null)[0])
				if (treeNode.UP) {
					console.log(treeNode, 'choose')
					if (treeNode.checked) {
						checkedDeptData.push({
							id: treeNode.ID,
							name: treeNode.NAME,
							upPid: treeNode.UP.id,
							type: treeNode.TYPE,
							deptTopname: '',
							pidTop: '',
							upLeveldeptname: treeNode.UP.name
						});
						for (var j = 0; j < checkedDeptData.length; j++) {
							if (checkedDeptData[j].upPid == checkedDeptData[j].pidTop) {
								checkedDeptData[j].pidTop = '';
								checkedDeptData[j].deptTopname = '';
							}
						}
						var templ = "";
						for (var j = 0; j < checkedDeptData.length; j++) {
							if (!!checkedDeptData[j]) {
								templ += '<span class="commonFileName leadersDel" data-id="' + checkedDeptData[j].id + '">' + checkedDeptData[j].name + '(' + (!!checkedDeptData[j].deptTopname ? (checkedDeptData[j].upLeveldeptname + ',' + checkedDeptData[j].deptTopname) : checkedDeptData[j].upLeveldeptname) + ')<i></i></span>';
							}
						}
						$('.modalDialogDept .checkedList').html(templ);
					} else {
						for (var i = 0; i < checkedDeptData.length; i++) {
							if (checkedDeptData[i].id == treeNode.ID) {
								checkedDeptData.splice(i, 1);
							}
						}
						var templ = "";
						for (var j = 0; j < checkedDeptData.length; j++) {
							if (!!checkedDeptData) {
								templ += '<span class="commonFileName leadersDel" data-id="' + checkedDeptData[j].id + '">' + checkedDeptData[j].name + '(' + (!!checkedDeptData[j].deptTopname ? (checkedDeptData[j].upLeveldeptname + ',' + checkedDeptData[j].deptTopname) : checkedDeptData[j].upLeveldeptname) + ')<i></i></span>';
							}
						}
						$('.modalDialogDept .checkedList').html(templ);
						return false;
					}
				} else {
					if (treeNode.checked) {
						checkedDeptData.push({
							id: treeNode.ID,
							name: treeNode.NAME,
							upPid: (zTree.getNodesByParam("ID", treeNode.PID, null)[0].TYPE == '0' || zTree.getNodesByParam("ID", treeNode.PID, null)[0].TYPE == '1') ? zTree.getNodesByParam("TYPE", '0', null)[0].ID : treeNode.PID,
							type: treeNode.TYPE,
							deptTopname: lookForFather(treeNode).pid == treeNode.ID ? zTree.getNodesByParam("TYPE", '0', null)[0].NAME : lookForFather(treeNode).pname,
							pidTop: lookForFather(treeNode).pid == treeNode.ID ? zTree.getNodesByParam("TYPE", '0', null)[0].ID : lookForFather(treeNode).pid,
							upLeveldeptname: (zTree.getNodesByParam("ID", treeNode.PID, null)[0].TYPE == '0' || zTree.getNodesByParam("ID", treeNode.PID, null)[0].TYPE == '1') ? zTree.getNodesByParam("TYPE", '0', null)[0].NAME : zTree.getNodesByParam("ID", treeNode.PID, null)[0].NAME
						});
						for (var j = 0; j < checkedDeptData.length; j++) {
							if (checkedDeptData[j].upPid == checkedDeptData[j].pidTop) {
								checkedDeptData[j].pidTop = '';
								checkedDeptData[j].deptTopname = '';
							}
						}
						console.log(lookForFather(treeNode))
						console.log(checkedDeptData)
						var templ = "";
						for (var j = 0; j < checkedDeptData.length; j++) {
							if (!!checkedDeptData[j]) {
								templ += '<span class="commonFileName leadersDel" data-id="' + checkedDeptData[j].id + '">' + checkedDeptData[j].name + '(' + (!!checkedDeptData[j].deptTopname ? (checkedDeptData[j].upLeveldeptname + ',' + checkedDeptData[j].deptTopname) : checkedDeptData[j].upLeveldeptname) + ')<i></i></span>';
							}
						}
						$('.modalDialogDept .checkedList').html(templ);
					} else {
						for (var i = 0; i < checkedDeptData.length; i++) {
							if (checkedDeptData[i].id == treeNode.ID) {
								checkedDeptData.splice(i, 1);
							}
						}
						var templ = "";
						for (var j = 0; j < checkedDeptData.length; j++) {
							if (!!checkedDeptData) {
								templ += '<span class="commonFileName leadersDel" data-id="' + checkedDeptData[j].id + '">' + checkedDeptData[j].name + '(' + (!!checkedDeptData[j].deptTopname ? (checkedDeptData[j].upLeveldeptname + ',' + checkedDeptData[j].deptTopname) : checkedDeptData[j].upLeveldeptname) + ')<i></i></span>';
							}
						}
						$('.modalDialogDept .checkedList').html(templ);
						return false;
					}
				}
				function lookForFather(value) {
					if (zTree.getNodesByParam("ID", value.PID, null)[0].TYPE === '1' || zTree.getNodesByParam("ID", value.PID, null)[0].TYPE === '0') {
						return {
							pid: zTree.getNodesByParam("ID", value.PID, null)[0].TYPE === '1' ? value.ID : '',
							pname: zTree.getNodesByParam("ID", value.PID, null)[0].TYPE === '1' ? value.NAME : ''
						}
					} else {
						return lookForFather(zTree.getNodesByParam("ID", value.PID, null)[0]);
					}
				}
			}
		}
	}, data);
	//让第一个父节点展开
	var nodes = zTree.getNodes();
	zTree.selectNode(nodes[0]);
	// zTree.setting.callback.onClick(null, zTree.setting.treeId, nodes[0]);
	if (nodes.length > 0) {
		for (var i = 0; i < nodes.length; i++) {
			zTree.expandNode(nodes[i], true, false, false); //默认展开第一级节点
		}
	}
}

//回车事件绑定
$('#orgSearch_input').bind('keyup', function (event) {
	if (event.keyCode == "13") {
		//回车执行查询
		console.log('222222')
		var zTree = $.fn.zTree.init($("#treeStation"), {
			async: {
				enable: true,
				url: function () {
					return basFlow.baseUrl + "/select/user/cqp/getTotalOrgByNameCopy";
				},
				otherParam: function (treeid, treeNode) {
					return {
						orgname: $('#orgSearch_input').val()
					};
				},
				dataType: 'json',
				contentType: 'application/json;charset=UTF-8',
				dataFilter: function (treeId, parentNode, childNodes) {
					console.log(treeId, parentNode, childNodes.data)
					for (var i = 0; i < childNodes.data.length; i++) {
						if (childNodes.data[i].TYPE == '0' || childNodes.data[i].TYPE == '1' || childNodes.data[i].TYPE == '4' || childNodes.data[i].TYPE == '2') {
							childNodes.data[i].chkDisabled = true;
						}
						for (var j = 0; j < checkedDeptData.length; j++) {
							if (childNodes.data[i].ID == checkedDeptData[j].id) {
								childNodes.data[i].checked = true;
								break;
							}
						}
					}
					return childNodes.data;
				}
			},
			check: {
				enable: true, //true / false 分别表示 显示 / 不显示 复选框或单选框
				chkboxType: {
					"Y": "",
					"N": ""
				}
			},
			data: {
				key: {
					name: "NAME"
				},
				simpleData: {
					enable: true,
					idKey: 'ID',
					pIdKey: 'PID',
					rootPId: 0,
				}
			},
			view: {
				showIcon: false
			},
			callback: {
				onClick: function (event, treeId, treeNode) {
					treeClickId = treeNode.ID;
					storeSelectUsers = []
					storeSelectUsers = [{
						name: '12212',
						isChecked: false
					}]
					showusers(storeSelectUsers)
				},
				beforeCheck: function (treeId, treeNode) {
					// if(checkedDeptData[0]){
					//     if (checkedDeptData[0].id != treeNode.ID) {
					//         var treeObj = $.fn.zTree.getZTreeObj("treeStation");
					//         treeObj.checkAllNodes(false);
					//     }
					// }
				},
				onCheck: function (event, treeId, treeNode) {
					var treeObj = $.fn.zTree.getZTreeObj("treeStation");
					console.log(treeObj.getCheckedNodes(), zTree.getNodesByParam("ID", treeNode.PID, null)[0])
					if (treeNode.checked) {
						checkedDeptData.push({
							id: treeNode.ID,
							name: treeNode.NAME,
							upPid: treeNode.PID,
							type: treeNode.TYPE,
							deptTopname: lookForFather(treeNode).pname,
							pidTop: lookForFather(treeNode).pid,
							upLeveldeptname: treeNode.NAME
						});
						for (var j = 0; j < checkedDeptData.length; j++) {
							if (checkedDeptData[j].upPid == checkedDeptData[j].pidTop) {
								checkedDeptData[j].pidTop = '';
								checkedDeptData[j].deptTopname = '';
							}
						}
						console.log(lookForFather(treeNode))
						console.log(checkedDeptData)
						var templ = "";
						for (var j = 0; j < checkedDeptData.length; j++) {
							if (!!checkedDeptData[j]) {
								templ += '<span class="commonFileName leadersDel" data-id="' + checkedDeptData[j].id + '">' + checkedDeptData[j].name + '(' + (!!checkedDeptData[j].deptTopname ? (checkedDeptData[j].upLeveldeptname + ',' + checkedDeptData[j].deptTopname) : checkedDeptData[j].upLeveldeptname) + ')<i></i></span>';
							}
						}
						$('.modalDialogDept .checkedList').html(templ);
					} else {
						for (var i = 0; i < checkedDeptData.length; i++) {
							if (checkedDeptData[i].id == treeNode.ID) {
								checkedDeptData.splice(i, 1);
							}
						}
						var templ = "";
						for (var j = 0; j < checkedDeptData.length; j++) {
							if (!!checkedDeptData) {
								templ += '<span class="commonFileName leadersDel" data-id="' + checkedDeptData[j].id + '">' + checkedDeptData[j].name + '(' + (!!checkedDeptData[j].deptTopname ? (checkedDeptData[j].upLeveldeptname + ',' + checkedDeptData[j].deptTopname) : checkedDeptData[j].upLeveldeptname) + ')<i></i></span>';
							}
						}
						$('.modalDialogDept .checkedList').html(templ);
						return false;
					}
					function lookForFather(value) {
						return {
							pid: '',
							pname: ''
						}
					}
				}
			}
		});
	}
});


// 展示用户
function showusers(data) {
	var $this = $(".modalDialogDept .selectUser")
	$this.html('')
	var processInnerHtml5 = doT.template($("#selectUser").text());
	$this.append(processInnerHtml5({
		list: data
	}))
}
// 选择用户的复选框
function selectUser(index, $this) {
	console.log($this.checked)
	console.log(index)
	if ($this.checked) {
		storeSelectUsers[index].isChecked = true
	} else {
		storeSelectUsers[index].isChecked = false
	}
	var count = 0
	for (var i = 0; i < storeSelectUsers.length; i++) {
		if (storeSelectUsers[i].isChecked) {
			count++
		}
	}
	if (!count) {
		$("#rightBtn").prop("disabled", true)
	} else {
		$("#rightBtn").prop("disabled", false)
	}
}

// 已选对象
function showselected(data) {
	var $this = $(".modalDialogDept .selected")
	$this.html('')
	var processInnerHtml5 = doT.template($("#selectedObj").text());
	$this.append(processInnerHtml5({
		list: data
	}))
}

// 已选对象的复选框
function selectedObj(index, $this) {
	if ($this.checked) {
		storeSelected[index].isChecked = true
	} else {
		storeSelected[index].isChecked = false
	}
	var count = 0
	for (var i = 0; i < storeSelected.length; i++) {
		if (storeSelected[i].isChecked) {
			count++
		}
	}
	if (!count) {
		$("#leftBtn").prop("disabled", true)
	} else {
		$("#leftBtn").prop("disabled", false)
	}
}

$("#rightBtn").on("click", function () {
	var tempArr = []
	for (var i = 0; i < storeSelectUsers.length; i++) {
		if (storeSelectUsers[i].isChecked) {
			storeSelected.push(storeSelectUsers[i])
			storeSelected[storeSelected.length - 1].isChecked = false
		} else {
			tempArr.push(storeSelectUsers[i])
		}
	}
	storeSelectUsers = tempArr
	showusers(storeSelectUsers)
	showselected(storeSelected)
	var count = 0
	for (var i = 0; i < storeSelectUsers.length; i++) {
		if (storeSelectUsers[i].isChecked) {
			count++
		}
	}
	if (!count) {
		$("#rightBtn").prop("disabled", true)
	} else {
		$("#rightBtn").prop("disabled", false)
	}
	var countA = 0
	for (var i = 0; i < storeSelected.length; i++) {
		if (storeSelected[i].isChecked) {
			countA++
		}
	}
	if (!countA) {
		$("#leftBtn").prop("disabled", true)
	} else {
		$("#leftBtn").prop("disabled", false)
	}
})

$("#leftBtn").on("click", function () {
	var tempArr = []
	for (var i = 0; i < storeSelected.length; i++) {
		if (storeSelected[i].isChecked) {
			storeSelectUsers.push(storeSelected[i])
			storeSelectUsers[storeSelectUsers.length - 1].isChecked = false
		} else {
			tempArr.push(storeSelected[i])
		}
	}
	storeSelected = tempArr
	showselected(storeSelected)
	showusers(storeSelectUsers)
	var count = 0
	for (var i = 0; i < storeSelectUsers.length; i++) {
		if (storeSelectUsers[i].isChecked) {
			count++
		}
	}
	if (!count) {
		$("#rightBtn").prop("disabled", true)
	} else {
		$("#rightBtn").prop("disabled", false)
	}
	var countA = 0
	for (var i = 0; i < storeSelected.length; i++) {
		if (storeSelected[i].isChecked) {
			countA++
		}
	}
	if (!countA) {
		$("#leftBtn").prop("disabled", true)
	} else {
		$("#leftBtn").prop("disabled", false)
	}
})

// 选择流程
function initProcessTree(data) {
	if (!data.length) {
		$("#treeProcess").html('');
		return false;
	}
	for (var i = 0; i < data.length; i++) {
		data[i].name = getCookie("lan-local") == 'en' ? data[i].ename : data[i].name;
	}
	var zTree = $.fn.zTree.init($("#treeProcess"), {
		async: {
			enable: true,
			url: function (treeid, treeNode) {
				// return basFlow.baseUrl + "/modeltree/getTreeNode/"+treeNode.id
				return basFlow.baseUrl + "/modeltree/getTreeNodeWithoutAuth/" + treeNode.id + "?username=" + basFlow.username

			},
			// autoParam:["ID"],
			dataFilter: function (treeId, parentNode, childNodes) {
				for (var i = 0; i < childNodes.length; i++) {
					console.log(childNodes[i])
					childNodes[i].chkDisabled = childNodes[i].release === 'N' ? true : false
					childNodes[i].isParent = childNodes[i].isparent;
					childNodes[i].name = getCookie("lan-local") == 'en' ? (childNodes[i].code + childNodes[i].ename) : childNodes[i].name;
				}
				return childNodes;
			}
		},
		check: {
			enable: true, //true / false 分别表示 显示 / 不显示 复选框或单选框
			chkboxType: {
				"Y": "",
				"N": ""
			}
		},
		data: {
			key: {
				name: "name"
			},
			simpleData: {
				enable: true,
				idKey: 'id',
				pIdKey: 'pid',
				rootPId: 0,
			}
		},
		view: {
			showIcon: false
		},
		callback: {
			onClick: function (event, treeId, treeNode) {
				treeClickId = treeNode.id;
				var count = 0;
				for (var key in basFlow.controls) {
					if (basFlow.controls[key].name === treeNode.name) {
						count++;
					}
				}
				if (treeClickId === getParam("treeId") || !!count) {
					return;
				}

				console.log(basFlow.controls)

				getProcess(treeNode.ID, function (resp) {
					if (!resp.pages) {
						$("#navagationPage").children("li").remove();
						return false;
					}
					$.jqPaginator('#navagationPage', {
						totalPages: resp.pages,
						visiblePages: 5,
						currentPage: pageNum,
						first: '<li class="first"><a href="javascript:;" class="iconfont icon-diyiyeshouyeshangyishou" title="' + $.i18n.prop("firstPage") + '"></a></li>',
						prev: '<li class="prev"><a href="javascript:;" class="iconfont icon-shangyiye" title="' + $.i18n.prop("prevPage") + '"></a></li>',
						next: '<li class="next"><a href="javascript:;" class="iconfont icon-xiayiye" title="' + $.i18n.prop("nextPage") + '"></a></li>',
						last: '<li class="last"><a href="javascript:;" class="iconfont icon-zuihouyiyemoyexiayishou" title="' + $.i18n.prop("endPage") + '"></a></li>',
						page: '<li><a href="javascript:;">{{page}}</a></li>',
						onPageChange: function (num, type) {
							getOrgUsers(treeClickId, false, num)
						}
					});
				}, pageNum)
			},
			beforeCheck: function (treeId, treeNode) {
				console.log(checkedProcessData[0])
				console.log(treeNode)
				if (checkedProcessData[0]) {
					if (checkedProcessData[0].id != treeNode.id) {
						var treeObj = $.fn.zTree.getZTreeObj("treeProcess");
						treeObj.checkAllNodes(false);
					}
				}
			},
			onCheck: function (event, treeId, treeNode) {
				if (treeNode.checked) {
					// var count = 0;
					// for (var key in basFlow.controls) {
					// 	if (basFlow.controls[key].name === treeNode.name) {
					// 		count ++;
					// 	}
					// }
					if (treeNode.id === getParam("treeId")) {
						var treeObj = $.fn.zTree.getZTreeObj("treeProcess");
						treeObj.checkAllNodes(false);
						basFlow.alertBox($.i18n.prop("thisnotUp") + '!', 'danger');
						return;
					}
					// if (!!count) {
					// 	var treeObj = $.fn.zTree.getZTreeObj("treeProcess");
					// 	treeObj.checkAllNodes(false);
					// 	basFlow.alertBox(treeNode.name + $.i18n.prop("cannotBoth")+'!','danger');
					// 	return ;
					// }
					for (var j = 0; j < checkedProcessData.length; j++) {
						if (checkedProcessData[j].id == treeNode.id) {
							return false;
						}
					}
					checkedProcessData[0] = {
						id: treeNode.id,
						name: treeNode.name,
						pid: treeNode.pid
					}
					// 					checkedProcessData.push({
					// 						id: treeNode.id,
					// 						name: treeNode.name,
					// 						pid: treeNode.pid
					// 					});
					var templ = "";
					for (var j = 0; j < checkedProcessData.length; j++) {
						templ += '<span class="commonFileName processDel" data-id="' + checkedProcessData[j].id + '">' + checkedProcessData[j].name + '<i></i></span>'
					}
					$('.modalDialogProcess .checkedList').html(templ);
				} else {
					for (var i = 0; i < checkedProcessData.length; i++) {
						if (checkedProcessData[i].id == treeNode.id) {
							checkedProcessData.splice(i, 1);

						}
					}
					var templ = "";
					for (var j = 0; j < checkedProcessData.length; j++) {
						templ += '<span class="commonFileName processDel" data-id="' + checkedProcessData[j].id + '">' + checkedProcessData[j].name + '<i></i></span>'
					}
					$('.modalDialogProcess .checkedList').html(templ);
					return false;
				}
			}
		}
	}, data);
	//让第一个父节点展开
	var nodes = zTree.getNodes();
	zTree.selectNode(nodes[0]);
	zTree.setting.callback.onClick(null, zTree.setting.treeId, nodes[0]);
	if (nodes.length > 0) {
		for (var i = 0; i < nodes.length; i++) {
			zTree.expandNode(nodes[i], true, false, false); //默认展开第一级节点
		}
	}
}

function getProcess(id, fn, num) { //点击组织拉取人员
	$.ajax({
		type: "post",
		url: basFlow.baseUrl + "/listhistory/getLast",
		contentType: "application/json",
		data: JSON.stringify({
			filters: [{
				key: "modelid",
				value: "7999B783067D2704E053BF1A13ACBB56"
			}, {
				key: "state",
				value: 1
			}],
			pageNum: 1,
			pageSize: 5
		}),
		success: function (data) {
			$("#processTable").html("");
			if (data.list.length) {
				if (/CONTROL/.test(basFlow.curId)) {
					checkedData = basFlow.controls[basFlow.curId].leaders
				} else {
					checkedData = basFlow.swimlanes[basFlow.curId].leaders
				}
				addDataTablePro(data);
			} else {
				$("#processTable").html('<tr><td colspan="8">' + $.i18n.prop("noData") + '</td></tr>');
			}
			if (fn) {
				fn(data)
			}
		}
	})
}


// 选择规章制度文档
function initRegulationsTree(data) {
	if (!data) {
		$("#treeRegulations").html('');
		return false;
	}
	data.open = true;
	var zTree = $.fn.zTree.init($("#treeRegulations"), {
		// async: {
		// 	enable: true,
		// 	url: function (treeid, treeNode) {
		// 		// return basFlow.baseUrl + "/modeltree/getTreeNode/"+treeNode.id
		// 		return basFlow.baseUrl + "/modeltree/getTreeNodeWithoutAuth/" + treeNode.id
		//
		// 	},
		// 	// autoParam:["ID"],
		// 	dataFilter: function (treeId, parentNode, childNodes) {
		// 		for (var i = 0; i < childNodes.length; i ++) {
		// 			childNodes[i].isParent = childNodes[i].isparent;
		// 			childNodes[i].name = getCookie("lan-local") == 'en' ? (childNodes[i].code + childNodes[i].ename):childNodes[i].name;
		// 		}
		// 		return childNodes;
		// 	}
		// },
		check: {
			enable: true, //true / false 分别表示 显示 / 不显示 复选框或单选框
			chkboxType: {
				"Y": "ps",
				"N": "ps"
			}
		},
		data: {
			key: {
				name: "foldername",
				children: "childList",
				isParent: "parent"
			},
			simpleData: {
				enable: false,
				idKey: 'id',
				pIdKey: 'pid',
				rootPId: "5",
			}
		},
		view: {
			showIcon: false
		},
		callback: {
			onCheck: function (event, treeId, treeNode) {
				if (treeNode.checked) {
					// var count = 0;
					// for (var key in basFlow.controls) {
					// 	if (basFlow.controls[key].name === treeNode.name) {
					// 		count ++;
					// 	}
					// }
					// if (!!count) {
					// 	var treeObj = $.fn.zTree.getZTreeObj("treeProcess");
					// 	treeObj.checkAllNodes(false);
					// 	basFlow.alertBox(treeNode.name + $.i18n.prop("cannotBoth")+'!','danger');
					// 	return ;
					// }
					for (var j = 0; j < checkedRegulationsData.length; j++) {
						if (checkedRegulationsData[j].id == treeNode.id) {
							return false;
						}
					}
					checkedRegulationsData.push({
						id: treeNode.id,
						foldername: treeNode.foldername,
						pid: treeNode.pid
					})
					// 					checkedProcessData.push({
					// 						id: treeNode.id,
					// 						name: treeNode.name,
					// 						pid: treeNode.pid
					// 					});
					var templ = "";
					for (var j = 0; j < checkedRegulationsData.length; j++) {
						templ += '<span class="commonFileName documentDel" data-id="' + checkedRegulationsData[j].id + '">' + checkedRegulationsData[j].foldername + '<i></i></span>'
					}
					$('.modalDialogRegulations .checkedList').html(templ);
				} else {
					for (var i = 0; i < checkedRegulationsData.length; i++) {
						if (checkedRegulationsData[i].id == treeNode.id) {
							checkedRegulationsData.splice(i, 1);

						}
					}
					var templ = "";
					for (var j = 0; j < checkedRegulationsData.length; j++) {
						templ += '<span class="commonFileName documentDel" data-id="' + checkedRegulationsData[j].id + '">' + checkedRegulationsData[j].foldername + '<i></i></span>'
					}
					$('.modalDialogRegulations .checkedList').html(templ);
					return false;
				}
			}
		}
	}, [data]);
}


// 筛选组织树
function queryOrgMenu(name) {
	if (!name) {
		$.ajax({
			type: "post",
			url: basFlow.baseUrl + "/select/user/cqp/getTotalOrg/0",
			success: function (data) {
				initOrgTree(data);
				initCheckList();
			}
		})
	} else {
		$.ajax({
			type: "post",
			url: basFlow.baseUrl + "/select/user/cqp/getTotalOrgByName",
			contentType: "application/json",
			data: JSON.stringify({
				orgname: name
			}),
			success: function (data) {
				initOrgTree(data);
			}
		})
	}
}

// 筛选组织树
function queryOrgDept(name) {
	if (!name) {
		$.ajax({
			type: "post",
			url: basFlow.baseUrl + "/select/user/cqp/getTotalOrg/0",
			success: function (data) {
				initDeptTree(data)
			}
		})
		var doTData = doT.template($('#attr_templ').text());
		var templ = '';
		temStore = basFlow.swimlanes[basFlow.curId[0]]
		checkedDeptData = temStore.depts;
	} else {
		$.ajax({
			type: "post",
			url: basFlow.baseUrl + "/select/user/cqp/getTotalOrgByName",
			contentType: "application/json",
			data: JSON.stringify({
				orgname: name
			}),
			success: function (data) {
				initDeptTree(data);
			}
		})
	}
}


// 筛选岗位组织树
function queryOrgStation(name) {
	if (!name) {
		$.ajax({
			type: "post",
			url: basFlow.baseUrl + "/select/user/cqp/getTotalOrg/0",
			success: function (data) {
				initStationTree(data)
			}
		})
		var doTData = doT.template($('#attr_templ').text());
		var templ = '';
		temStore = basFlow.swimlanes[basFlow.curId[0]]
		checkedDeptData = temStore.depts;
	} else {
		$.ajax({
			type: "post",
			url: basFlow.baseUrl + "/select/user/cqp/getTotalOrgByName",
			contentType: "application/json",
			data: JSON.stringify({
				orgname: name
			}),
			success: function (data) {
				initStationTree(data);
			}
		})
	}
}

// 筛选组织树
function queryOrgProcess(name) {
	if (!name) {
		$.ajax({
			type: "post",
			url: basFlow.baseUrl + "/select/user/cqp/getTotalOrg/0",
			success: function (data) {
				initOrgTree(data);
				initCheckList();
			}
		})
	} else {
		$.ajax({
			type: "post",
			url: basFlow.baseUrl + "/modeltree/getTreeNodeByNameWithoutAuthCopy?username=" + basFlow.username,
			contentType: "application/json",
			data: JSON.stringify({
				name: name
			}),
			success: function (data) {
				initProcessTree(data.data);
			}
		})
	}
}


function getOrgUsers(id, fn, num) { //点击组织拉取人员
	$.ajax({
		type: "post",
		url: basFlow.baseUrl + "/select/user/cqp/getUsersByOrgid",
		contentType: "application/json",
		data: JSON.stringify({
			attr: {
				orgid: id
			},
			filters: [],
			logic: "or",
			pageNum: num,
			pageSize: 5,
		}),
		success: function (data) {
			$("#tabTableData").html("");
			if (data.list.length) {
				if (/CONTROL/.test(basFlow.curId)) {
					checkedData = basFlow.controls[basFlow.curId].leaders
				} else {
					checkedData = basFlow.swimlanes[basFlow.curId].leaders
				}
				addDataTable(data)
			} else {
				$("#tabTableData").html('<tr><td colspan="5">' + $.i18n.prop("noData") + '</td></tr>');
			}
			if (fn) {
				fn(data)
			}
		}
	})
}


// 添加表格数据
function addDataTable(data) {
	var str = '';
	// 已选中的数据
	var checkId = '';
	respData = data.list;
	// if(checkedData.length){
	// 	checkId = checkedData[0].userid;
	// }
	if (!checkedData) {
		return;
	}

	var flag = true; // 增加这个字段是为了当页面初始化的时候 给选中的目标添加checked属性 同时也避免了重复渲染
	for (var i = 0; i < data.list.length; i++) {
		for (var j = 0; j < checkedData.length; j++) {
			if (checkedData[j].userid == data.list[i].userid) {
				flag = !flag;
				str += '<tr><td><label><input type="checkbox" data-id="' + checkedData[j].userid + '" ' + (checkedData[j].userid == data.list[i].userid ? 'checked' : '') + ' value="" onchange="checkData(' + i + ', this)"></label></td>' +
					'<td class="showEll" title="' + data.list[i].cnname + '">' + (data.list[i].cnname ? data.list[i].cnname : '') + '</td>' +
					'<td class="showEll" title="' + data.list[i].sex + '">' + (data.list[i].sex == 'M' ? $.i18n.prop("man") : $.i18n.prop("woman")) + '</td>' +
					'<td class="showEll" title="' + data.list[i].deptname + '">' + (data.list[i].deptname ? data.list[i].deptname : '') + '</td>' +
					'<td class="showEll" title="' + data.list[i].orgname + '">' + (data.list[i].orgname ? data.list[i].orgname : '') + '</td>' + '</tr>';
				break;
			}
		}
		if (!flag) {
			flag = !flag;
			continue;
		}
		str += '<tr><td><label><input type="checkbox" ' + 'data-id="' + data.list[i].userid + '" onchange="checkData(' + i + ', this)"></label></td>' +
			'<td class="showEll" title="' + data.list[i].cnname + '">' + (data.list[i].cnname ? data.list[i].cnname : '') + '</td>' +
			'<td class="showEll" title="' + (data.list[i].sex == 'M' ? $.i18n.prop("man") : $.i18n.prop("woman")) + '">' + (data.list[i].sex == 'M' ? $.i18n.prop("man") : $.i18n.prop("woman")) + '</td>' +
			'<td class="showEll" title="' + data.list[i].deptname + '">' + (data.list[i].deptname ? data.list[i].deptname : '') + '</td>' +
			'<td class="showEll" title="' + data.list[i].orgname + '">' + (data.list[i].orgname ? data.list[i].orgname : '') + '</td>' + '</tr>'
	}
	$("#tabTableData").append(str);
}
// 添加表格数据
function addDataTablePro(data) {
	var str = '';
	// 已选中的数据
	var checkId = '';
	respDataPro = data.list;
	// if(checkedData.length){
	// 	checkId = checkedData[0].userid;
	// }
	var flag = true; // 增加这个字段是为了当页面初始化的时候 给选中的目标添加checked属性 同时也避免了重复渲染
	for (var i = 0; i < data.list.length; i++) {
		for (var j = 0; j < checkedProcessData.length; j++) {
			if (checkedProcessData[j].userid == data.list[i].userid) {
				flag = !flag;
				str += '<tr><td><label><input type="checkbox" data-id="' + checkedProcessData[j].id + '" ' + (checkedProcessData[j].id == data.list[i].id ? 'checked' : '') + ' value="" onchange="checkData(' + i + ', this)"></label></td>' +
					'<td class="showEll" title="' + data.list[i].code + '">' + (data.list[i].code ? data.list[i].code : '') + '</td>' +
					'<td class="showEll" title="' + data.list[i].name + '">' + (data.list[i].name ? data.list[i].name : '') + '</td>' +
					'<td class="showEll" title="' + data.list[i].version + '">' + (data.list[i].version ? data.list[i].version : '') + '</td>' +
					'<td class="showEll" title="' + data.list[i].description + '">' + (data.list[i].description ? data.list[i].description : '') + '</td>' +
					'<td class="showEll" title="' + data.list[i].bpo + '">' + (data.list[i].bpo ? data.list[i].bpo : '') + '</td>' +
					'<td class="showEll" title="' + data.list[i].state + '">' + (data.list[i].state ? data.list[i].state : '') + '</td>' + '</tr>';
				break;
			}
		}
		if (!flag) {
			flag = !flag;
			continue;
		}
		str += '<tr><td><label><input type="checkbox" ' + 'data-id="' + data.list[i].id + '" onchange="checkData(' + i + ', this)"></label></td>' +
			'<td class="showEll" title="' + data.list[i].code + '">' + (data.list[i].code ? data.list[i].code : '') + '</td>' +
			'<td class="showEll" title="' + data.list[i].name + '">' + (data.list[i].name ? data.list[i].name : '') + '</td>' +
			'<td class="showEll" title="' + data.list[i].version + '">' + (data.list[i].version ? data.list[i].version : '') + '</td>' +
			'<td class="showEll" title="' + data.list[i].description + '">' + (data.list[i].description ? data.list[i].description : '') + '</td>' +
			'<td class="showEll" title="' + data.list[i].bpo + '">' + (data.list[i].bpo ? data.list[i].bpo : '') + '</td>' +
			'<td class="showEll" title="' + data.list[i].state + '">' + (data.list[i].state ? data.list[i].state : '') + '</td>' + '</tr>';
	}
	$("#tabTableData").append(str);
}

// 选中的数据
function checkData(index, self, userid) {
	var userid = userid || $(self).attr('data-id');
	// 	if(/CONTROL/.test(basFlow.curId)){
	// 		checkedData = basFlow.controls[basFlow.curId].leaders
	// 	}else{
	// 		checkedData = basFlow.swimlanes[basFlow.curId].leaders
	// 	}
	// var checkedData = basFlow.controls[basFlow.curId].leaders;
	var templ = '';
	if ($(self).is(':checked')) {
		$(self).attr('checked', 'checked')
		checkedData.push(respData[index]);
	} else {
		for (var i = 0; i < checkedData.length; i++) {
			if (checkedData[i].userid == userid) {
				checkedData.splice(i, 1);
				break;
			}
		}
	}
	for (var j = 0; j < checkedData.length; j++) {
		templ += '<span class="commonFileName leadersDel" data-id="' + checkedData[j].userid + '">' + checkedData[j].cnname + '<i></i></span>'
	}
	$('.checkedList').html(templ);
}

$(".dialog_wrapper .center .centerContent p").on("click", function () {
	var index = $(".dialog_wrapper .center .centerContent p").index($(this));
	$(".dialog_wrapper .center .centerContent p").removeClass("active");
	$(".dialog_wrapper .center .centerContent p").eq(index).addClass("active");
	if (index == 0) {
		getCommonlyUsers(11, function (resp) {
			if (!resp.pages) {
				$("#navagationPage").children("li").remove();
				return false;
			}
			$.jqPaginator('#navagationPage', {
				totalPages: resp.pages,
				visiblePages: 5,
				currentPage: pageNum,
				first: '<li class="first"><a href="javascript:;" class="iconfont icon-diyiyeshouyeshangyishou" title="' + $.i18n.prop("firstPage") + '"></a></li>',
				prev: '<li class="prev"><a href="javascript:;" class="iconfont icon-shangyiye" title="' + $.i18n.prop("prevPage") + '"></a></li>',
				next: '<li class="next"><a href="javascript:;" class="iconfont icon-xiayiye" title="' + $.i18n.prop("nextPage") + '"></a></li>',
				last: '<li class="last"><a href="javascript:;" class="iconfont icon-zuihouyiyemoyexiayishou" title="' + $.i18n.prop("endPage") + '"></a></li>',
				page: '<li><a href="javascript:;">{{page}}</a></li>',
				onPageChange: function (num, type) {
					getCommonlyUsers(11, false, num)
				}
			});
		}, pageNum)
	} else if (index == 1) {
		getCommonlyUsers(12, function (resp) {
			if (!resp.pages) {
				$("#navagationPage").children("li").remove();
				return false;
			}
			$.jqPaginator('#navagationPage', {
				totalPages: resp.pages,
				visiblePages: 5,
				currentPage: pageNum,
				first: '<li class="first"><a href="javascript:;" class="iconfont icon-diyiyeshouyeshangyishou" title="' + $.i18n.prop("firstPage") + '"></a></li>',
				prev: '<li class="prev"><a href="javascript:;" class="iconfont icon-shangyiye" title="' + $.i18n.prop("prevPage") + '"></a></li>',
				next: '<li class="next"><a href="javascript:;" class="iconfont icon-xiayiye" title="' + $.i18n.prop("nextPage") + '"></a></li>',
				last: '<li class="last"><a href="javascript:;" class="iconfont icon-zuihouyiyemoyexiayishou" title="' + $.i18n.prop("endPage") + '"></a></li>',
				page: '<li><a href="javascript:;">{{page}}</a></li>',
				onPageChange: function (num, type) {
					getCommonlyUsers(12, false, num)
				}
			});
		}, pageNum)
	} else if (index == 2) {
		getCommonlyUsers(13, function (resp) {
			if (!resp.pages) {
				$("#navagationPage").children("li").remove();
				return false;
			}
			$.jqPaginator('#navagationPage', {
				totalPages: resp.pages,
				visiblePages: 5,
				currentPage: pageNum,
				first: '<li class="first"><a href="javascript:;" class="iconfont icon-diyiyeshouyeshangyishou" title="' + $.i18n.prop("firstPage") + '"></a></li>',
				prev: '<li class="prev"><a href="javascript:;" class="iconfont icon-shangyiye" title="' + $.i18n.prop("prevPage") + '"></a></li>',
				next: '<li class="next"><a href="javascript:;" class="iconfont icon-xiayiye" title="' + $.i18n.prop("nextPage") + '"></a></li>',
				last: '<li class="last"><a href="javascript:;" class="iconfont icon-zuihouyiyemoyexiayishou" title="' + $.i18n.prop("endPage") + '"></a></li>',
				page: '<li><a href="javascript:;">{{page}}</a></li>',
				onPageChange: function (num, type) {
					getCommonlyUsers(13, false, num)
				}
			});
		}, pageNum)
	} else if (index == 3) {
		getCommonlyUsers(10, function (resp) {
			if (!resp.pages) {
				$("#navagationPage").children("li").remove();
				return false;
			}
			$.jqPaginator('#navagationPage', {
				totalPages: resp.pages,
				visiblePages: 5,
				currentPage: pageNum,
				first: '<li class="first"><a href="javascript:;" class="iconfont icon-diyiyeshouyeshangyishou" title="' + $.i18n.prop("firstPage") + '"></a></li>',
				prev: '<li class="prev"><a href="javascript:;" class="iconfont icon-shangyiye" title="' + $.i18n.prop("prevPage") + '"></a></li>',
				next: '<li class="next"><a href="javascript:;" class="iconfont icon-xiayiye" title="' + $.i18n.prop("nextPage") + '"></a></li>',
				last: '<li class="last"><a href="javascript:;" class="iconfont icon-zuihouyiyemoyexiayishou" title="' + $.i18n.prop("endPage") + '"></a></li>',
				page: '<li><a href="javascript:;">{{page}}</a></li>',
				onPageChange: function (num, type) {
					getCommonlyUsers(10, false, num)
				}
			});
		}, pageNum)
	}
})

//获取token
function fnAccessMethod() {
	var url = '?1=1';
	var access_token = window.localStorage.getItem('portalAccessToken');
	if (access_token) {
		url += '&access_token=' + access_token;
	}
	return url;
}

// 常用联系人进行选择
function getCommonlyUsers(id, fn, num) {
	$.ajax({
		type: "post",
		url: basFlow.baseUrl + "/select/user/cqp/getUsersInfo",
		contentType: "application/json",
		data: JSON.stringify({
			attr: {
				type: id,
				id: null
			},
			filters: [],
			logic: "or",
			pageNum: num,
			pageSize: 5
		}),
		success: function (data, id) {
			$("#tabTableData").html("");
			if (data.list.length) {
				var templ = '';
				if (/CONTROL/.test(basFlow.curId)) {
					checkedData = basFlow.controls[basFlow.curId].leaders
				} else {
					checkedData = basFlow.swimlanes[basFlow.curId].leaders
				}
				for (var j = 0; j < checkedData.length; j++) {
					templ += '<span class="commonFileName leadersDel" data-id="' + checkedData[j].userid + '">' + checkedData[j].cnname + '<i></i></span>'
				}
				$('.checkedList').html(templ);
				addDataTable(data)
			} else {
				if (id) {
					$("#" + id).html('<tr><td colspan="5">' + $.i18n.prop("noData") + '</td></tr>');
				} else {
					$("#tabTableData").html('<tr><td colspan="5">' + $.i18n.prop("noData") + '</td></tr>');
				}
			}
			if (fn) {
				fn(data)
			}
		}
	})
}

// 自定义组
function getUserQuery(fn, num) {
	$.ajax({
		type: "post",
		url: basFlow.baseUrl + "/select/user/cqp/getAllUsersInfo",
		contentType: "application/json",
		data: JSON.stringify({
			attr: {
				rolename: $("#inputRole").val() ? $("#inputRole").val() : ''
			},
			filters: [{
				key: "cnname",
				value: $("#inputName").val() ? $("#inputName").val() : '',
				opt: "LIKE",
				type: "S"
			},
			{
				key: "orgname",
				value: $("#inputPos").val() ? $("#inputPos").val() : '',
				opt: "LIKE",
				type: "S"
			}
			],
			pageNum: num,
			pageSize: 5,
		}),
		success: function (data) {
			$("#tabTableData").html("");
			if (data.list.length) {
				var templ = '';
				if (/CONTROL/.test(basFlow.curId)) {
					checkedData = basFlow.controls[basFlow.curId].leaders
				} else {
					checkedData = basFlow.swimlanes[basFlow.curId].leaders
				}
				for (var j = 0; j < checkedData.length; j++) {
					templ += '<span class="commonFileName leadersDel" data-id="' + checkedData[j].userid + '">' + checkedData[j].cnname + '<i></i></span>'
				}
				$('.checkedList').html(templ);
				addDataTable(data)
			} else {
				$("#tabTableData").html('<tr><td colspan="5">' + $.i18n.prop("noData") + '</td></tr>');
			}
			if (fn) {
				fn(data)
			}
		}
	})
}

var referCompleteUpload = 0
var totalUpload = 0;

// 输入附件上传
$("body").on("change", "#updateFile", function () {
	if (!basFlow.curId[0]) {
		basFlow.alertBox($.i18n.prop("firstChooseNode") + "! ", 'danger');
		return false
	}
	var picFileList = $(this)[0].files;
	referCompleteUpload = 0;
	totalUpload = picFileList.length;
	for (var i = 0; i < picFileList.length; i++) {
		var formData = new FormData();
		formData.append("file", picFileList[i]);
		formData.append("name", picFileList[i].name);
		uploadFile(formData, "input")
	}
})


// 信息表单
$("body").on("change", "#messageFile", function () {
	if (!basFlow.curId[0]) {
		basFlow.alertBox($.i18n.prop("firstChooseNode") + "! ", 'danger');
		return false
	}
	var picFileList = $(this)[0].files;
	referCompleteUpload = 0;
	totalUpload = picFileList.length;
	console.log(basFlow)
	if (/CONTROL/.test(basFlow.curId[0])) {
		temStore = basFlow.controls[basFlow.curId]
	} else {
		temStore = basFlow.swimlanes[basFlow.curId]
	}
	for (var i = 0; i < picFileList.length; i++) {
		var formData = new FormData();
		formData.append("file", picFileList[i]);
		formData.append("name", picFileList[i].name);
		uploadFile(formData, "messageGroup")
	}
})

$("body").on("change", "#messageOrg", function () {
	if (!basFlow.curId[0]) {
		basFlow.alertBox($.i18n.prop("firstChooseNode") + "! ", 'danger');
		return false
	}
	var picFileList = $(this)[0].files;
	referCompleteUpload = 0;
	totalUpload = picFileList.length;
	console.log(basFlow)
	if (/CONTROL/.test(basFlow.curId[0])) {
		temStore = basFlow.controls[basFlow.curId]
	} else {
		temStore = basFlow.swimlanes[basFlow.curId]
	}
	for (var i = 0; i < picFileList.length; i++) {
		var formData = new FormData();
		formData.append("file", picFileList[i]);
		formData.append("name", picFileList[i].name);
		uploadFile(formData, "messageFile")
	}
})

// 审批规则上传附件
$("body").on("change", "#selectAppovalRule", function () {
	if (!basFlow.curId[0]) {
		basFlow.alertBox($.i18n.prop("firstChooseNode") + "! ", 'danger');
		return false
	}
	var picFileList = $(this)[0].files;
	referCompleteUpload = 0;
	totalUpload = picFileList.length;
	console.log(basFlow)
	if (/CONTROL/.test(basFlow.curId[0])) {
		temStore = basFlow.controls[basFlow.curId]
	} else {
		temStore = basFlow.swimlanes[basFlow.curId]
	}
	for (var i = 0; i < picFileList.length; i++) {
		var formData = new FormData();
		formData.append("file", picFileList[i]);
		formData.append("name", picFileList[i].name);
		uploadFile(formData, "approvalGroup")
	}
})

// $("body").on("click", "#outputUpdateFile,#updateFile,#workResultFile", function () {
// 	if (!basFlow.controls[basFlow.curId[0]].processGroup.length) {
// 		basFlow.alertBox($.i18n.prop("firstProcess") + "! ", 'danger');
// 		return false;
// 	}
// })

// 输出附件上传
$("body").on("change", "#outputUpdateFile", function () {
	if (!basFlow.curId[0]) {
		basFlow.alertBox($.i18n.prop("firstChooseNode") + "! ", 'danger');
		return false
	}
	var picFileList = $(this)[0].files;
	referCompleteUpload = 0;
	totalUpload = picFileList.length;
	for (var i = 0; i < picFileList.length; i++) {
		var formData = new FormData();
		formData.append("file", picFileList[i]);
		formData.append("name", picFileList[i].name);
		uploadFile(formData, "output")
	}
})
// 工作成果输出附件上传
// $("body").on("change", "#workResultUpdateFile", function () {
// 	if (!basFlow.curId[0]) {
// 		basFlow.alertBox($.i18n.prop("firstChooseNode") + "! ", 'danger');
// 		return false
// 	}
// 	var picFileList = $(this)[0].files;
// 	referCompleteUpload = 0;
// 	totalUpload = picFileList.length;
// 	for (var i = 0; i < picFileList.length; i++) {
// 		var formData = new FormData();
// 		formData.append("file", picFileList[i]);
// 		formData.append("name", picFileList[i].name);
// 		uploadFile(formData, "file")
// 	}
// })

//操作手册
$("body").on("change", "#opertBooksUpdateFile", function () {
	if (!basFlow.curId[0]) {
		basFlow.alertBox($.i18n.prop("firstChooseNode") + "! ", 'danger');
		return false
	}
	var picFileList = $(this)[0].files;
	referCompleteUpload = 0;
	totalUpload = picFileList.length;
	for (var i = 0; i < picFileList.length; i++) {
		var formData = new FormData();
		formData.append("file", picFileList[i]);
		formData.append("name", picFileList[i].name);
		uploadFile(formData, "opertBooks")
	}
})



//上传文件函数
function uploadFile(formData, selector) {
	$.ajax({
		url: basFlow.baseUrl + "/attach/upload?username=" + basFlow.username,
		type: "POST",
		data: formData,
		processData: false, //告诉jquery不要去处理发送的数据
		contentType: false, //告诉jquery不要去设置请求头Content-Type
		progress: function (e) {
			// 				var loaded = e.loaded;
			// 				var total = e.total;
			// 				var per = Math.floor(100*loaded/total);
			// 				$("#per").html(per+"%");
		},
		success: function (data) {
			var doTData = doT.template($('#attr_templ').text())
			if (/CONTROL/.test(basFlow.curId)) {
				temStore = basFlow.controls[basFlow.curId]
			} else {
				temStore = basFlow.swimlanes[basFlow.curId]
			}
			console.log(temStore)
			temStore[selector].push(data)
			if (temStore.inputDesc === '') {
				temStore.inputDesc = temStore.inputDesc ? temStore.inputDesc : (temStore.input[0] ? temStore.input[0].newName : '')
			}
			if (temStore.outputDesc === '') {
				temStore.outputDesc = temStore.outputDesc ? temStore.outputDesc : (temStore.output[0] ? temStore.output[0].newName : '')
			}
			if (temStore.workResults === '') {
				temStore.workResults = temStore.workResults ? temStore.workResults : (temStore.file[0] ? temStore.file[0].newName : '')
			}
			console.log(temStore)
			$(".content_wrapper").children().eq(1).html(doTData({
				attrList: temStore,
				listProcess: basFlow.storeUpgressData.bpmDto ? (basFlow.storeUpgressData.bpmDto.outputlist ? basFlow.storeUpgressData.bpmDto.outputlist : []) : []
			}))


			if (basFlow.controls[basFlow.curId[0]].type === 'processTask' || basFlow.controls[basFlow.curId[0]].img.indexOf('process.png') > -1 || basFlow.controls[basFlow.curId[0]].img.indexOf('process02.png') > -1 || basFlow.controls[basFlow.curId[0]].img.indexOf('process03.png') > -1 || basFlow.controls[basFlow.curId[0]].type === 'spliceGroup' || basFlow.controls[basFlow.curId[0]].type === 'processIt') {
				if (/CONTROL/.test(basFlow.curId)) {
					if (temStore.input.length != 0) {
						if (!$("#" + basFlow.curId[0] + " .text .input").length) {
							$("#" + basFlow.curId[0] + " .text").append('<div class="inputImgCss input">' + (basFlow.controls[basFlow.curId[0]].inputDesc ? basFlow.controls[basFlow.curId[0]].inputDesc : $.i18n.prop("input")) + '<img src="' + basFlow.options.toolsPath + '/processInput.png" /></div>');
						}
					}
					if (temStore.output.length != 0) {
						if (!$("#" + basFlow.curId[0] + " .text .outputCss").length) {
							$("#" + basFlow.curId[0] + " .text").append('<div class="inputImgCss outputCss">' + (basFlow.controls[basFlow.curId[0]].outputDesc ? basFlow.controls[basFlow.curId[0]].outputDesc : $.i18n.prop("output")) + '<img src="' + basFlow.options.toolsPath + '/processOutput.png" /></div>');
						}
					}
					if (temStore.messageGroup && ((temStore.messageGroup.length != 0) || (temStore.messageFile.length != 0))) {
						if (!$("#" + basFlow.curId[0] + " .text .messageFormCss").length) {
							$("#" + basFlow.curId[0] + " .text").append('<div class="messageFormCss">' + $.i18n.prop("formsDocuments") + '<img src="' + basFlow.options.toolsPath + '/processForm.png" /></div>');
						}
					}
				}
			}
			if (basFlow.controls[basFlow.curId[0]].type === 'approveRules') {
				if (temStore.approvalGroup && ((temStore.approvalGroup.length !== 0) || (temStore.approveForm.length != 0))) {
					if (!$("#" + basFlow.curId[0] + " .text .messageFormCss").length) {
						$("#" + basFlow.curId[0] + " .text").append('<div class="messageFormCss">' + $.i18n.prop("approveRules") + '<img src="' + basFlow.options.toolsPath + '/processForm.png" /></div>');
					}
				}
			}
			referCompleteUpload++;
			if (totalUpload == referCompleteUpload) {
				basFlow.alertBox($.i18n.prop("uploadComplete") + "! ", "success");
				if (selector == 'messageGroup') {
					for (var i = 0; i < $("#pointAttr li").length; i++) {
						if ($("#pointAttr li").eq(i).text() === $.i18n.prop("informs")) {
							$("#pointAttr li").eq(i).siblings().removeClass("active");
							$("#pointAttr li").eq(i).addClass("active");
							$(".attr1Box").children().siblings().css("display", "none");
							$(".attr1Box").children().eq(i).css("display", "block");
							break;
						}
					}
					var attrId = '7A88687D266C3D7CE053BF1A13ACD2C3';
					jQuery.support.cors = true;
					$.ajax({
						type: 'PUT',
						url: basFlow.baseUrl + '/document/save?username=' + basFlow.username,
						data: JSON.stringify({
							'docId': data.id,
							'docTitle': data.newName,
							'downloadUrl': data.downloadUrl,
							'viewUrl': data.viewUrl,
							'folderDocumentList': [{ "documentid": data.id, "folderid": attrId }],
							'provideruser': basFlow.username,
							'revId': data.revId
						}),
						contentType: 'application/json',
						dataType: 'json',
						async: true,
						success: function (res) {
							console.log(res);
						},
						error: function (err) {
							console.log(err)
						}
					})
					jQuery.support.cors = true;
					$.ajax({
						type: 'POST',
						url: basFlow.baseUrl + '/modellistdoc/save?username=' + basFlow.username,
						data: JSON.stringify({
							"description": "",
							"docid": data.id,
							"folderid": attrId,
							"modelid": getParam("id"),
							"name": data.newName
						}),
						contentType: 'application/json',
						dataType: 'json',
						async: true,
						success: function (res) {
							console.log(res);
							for (var i = 0; i < temStore.messageGroup.length; i++) {
								if (temStore[selector][i].id === data.id) {
									temStore[selector][i].docid = res.id;
									basFlow.controls[basFlow.curId][selector][i].docid = res.id;
									break;
								}
							}
							$(".content_wrapper").children().eq(1).html(doTData({
								attrList: temStore,
								listProcess: basFlow.storeUpgressData.bpmDto ? (basFlow.storeUpgressData.bpmDto.outputlist ? basFlow.storeUpgressData.bpmDto.outputlist : []) : []
							}))
							for (var i = 0; i < $("#pointAttr li").length; i++) {
								if ($("#pointAttr li").eq(i).text() === $.i18n.prop("informs")) {
									$("#pointAttr li").eq(i).siblings().removeClass("active");
									$("#pointAttr li").eq(i).addClass("active");
									$(".attr1Box").children().siblings().css("display", "none");
									$(".attr1Box").children().eq(i).css("display", "block");
									break;
								}
							}
						},
						error: function (err) {
							console.log(err)
						}
					})
				}
				if (selector == 'approvalGroup') {
					for (var i = 0; i < $("#pointAttr li").length; i++) {
						if ($("#pointAttr li").eq(i).text() === $.i18n.prop("approveRules")) {
							$("#pointAttr li").eq(i).siblings().removeClass("active");
							$("#pointAttr li").eq(i).addClass("active");
							$(".attr1Box").children().siblings().css("display", "none");
							$(".attr1Box").children().eq(i).css("display", "block");
							break;
						}
					}
					var attrId = '7A88687D266C3D7CE053BF1A13ACD2C3';
					jQuery.support.cors = true;
					$.ajax({
						type: 'PUT',
						url: basFlow.baseUrl + '/document/save?username=' + basFlow.username,
						data: JSON.stringify({
							'docId': data.id,
							'docTitle': data.newName,
							'downloadUrl': data.downloadUrl,
							'viewUrl': data.viewUrl,
							'folderDocumentList': [{ "documentid": data.id, "folderid": attrId }],
							'provideruser': basFlow.username,
							'revId': data.revId
						}),
						contentType: 'application/json',
						dataType: 'json',
						async: true,
						success: function (res) {
							console.log(res);
						},
						error: function (err) {
							console.log(err)
						}
					})
					jQuery.support.cors = true;
					$.ajax({
						type: 'POST',
						url: basFlow.baseUrl + '/modellistdoc/save?username=' + basFlow.username,
						data: JSON.stringify({
							"description": "",
							"docid": data.id,
							"folderid": attrId,
							"modelid": getParam("id"),
							"name": data.newName
						}),
						contentType: 'application/json',
						dataType: 'json',
						async: true,
						success: function (res) {
							console.log(res);
							for (var i = 0; i < temStore.approvalGroup.length; i++) {
								if (temStore[selector][i].id === data.id) {
									temStore[selector][i].docid = res.id;
									basFlow.controls[basFlow.curId][selector][i].docid = res.id;
									break;
								}
							}
							console.log(temStore)
							$(".content_wrapper").children().eq(1).html(doTData({
								attrList: temStore,
								listProcess: basFlow.storeUpgressData.bpmDto ? (basFlow.storeUpgressData.bpmDto.outputlist ? basFlow.storeUpgressData.bpmDto.outputlist : []) : []
							}))
							for (var i = 0; i < $("#pointAttr li").length; i++) {
								if ($("#pointAttr li").eq(i).text() === $.i18n.prop("approveRules")) {
									$("#pointAttr li").eq(i).siblings().removeClass("active");
									$("#pointAttr li").eq(i).addClass("active");
									$(".attr1Box").children().siblings().css("display", "none");
									$(".attr1Box").children().eq(i).css("display", "block");
									break;
								}
							}
						},
						error: function (err) {
							console.log(err)
						}
					})
				}
				if (selector == 'messageFile') {
					for (var i = 0; i < $("#pointAttr li").length; i++) {
						if ($("#pointAttr li").eq(i).text() === $.i18n.prop("inforDoc")) {
							$("#pointAttr li").eq(i).siblings().removeClass("active");
							$("#pointAttr li").eq(i).addClass("active");
							$(".attr1Box").children().siblings().css("display", "none");
							$(".attr1Box").children().eq(i).css("display", "block");
							break;
						}
					}
					var attrId = '7A88818B46493D7EE053BF1A13AC8955';
					jQuery.support.cors = true;
					$.ajax({
						type: 'PUT',
						url: basFlow.baseUrl + '/document/save?username=' + basFlow.username,
						data: JSON.stringify({
							'docId': data.id,
							'docTitle': data.newName,
							'downloadUrl': data.downloadUrl,
							'viewUrl': data.viewUrl,
							'folderDocumentList': [{ "documentid": data.id, "folderid": attrId }],
							'provideruser': basFlow.username,
							'revId': data.revId
						}),
						contentType: 'application/json',
						dataType: 'json',
						async: true,
						success: function (res) {
							console.log(res);
						},
						error: function (err) {
							console.log(err)
						}
					})

					jQuery.support.cors = true;
					$.ajax({
						type: 'POST',
						url: basFlow.baseUrl + '/modellistdoc/save?username=' + basFlow.username,
						data: JSON.stringify({
							"description": "",
							"docid": data.id,
							"folderid": attrId,
							"modelid": getParam("id"),
							"name": data.newName
						}),
						contentType: 'application/json',
						dataType: 'json',
						async: true,
						success: function (res) {
							console.log(res);
							for (var i = 0; i < temStore.messageFile.length; i++) {
								if (temStore[selector][i].id === data.id) {
									temStore[selector][i].docid = res.id;
									basFlow.controls[basFlow.curId][selector][i].docid = res.id;
									break;
								}
							}
							$(".content_wrapper").children().eq(1).html(doTData({
								attrList: temStore,
								listProcess: basFlow.storeUpgressData.bpmDto ? (basFlow.storeUpgressData.bpmDto.outputlist ? basFlow.storeUpgressData.bpmDto.outputlist : []) : []
							}))
							for (var i = 0; i < $("#pointAttr li").length; i++) {
								if ($("#pointAttr li").eq(i).text() === $.i18n.prop("inforDoc")) {
									$("#pointAttr li").eq(i).siblings().removeClass("active");
									$("#pointAttr li").eq(i).addClass("active");
									$(".attr1Box").children().siblings().css("display", "none");
									$(".attr1Box").children().eq(i).css("display", "block");
									break;
								}
							}
						},
						error: function (err) {
							console.log(err)
						}
					})
				}
				if (selector == 'input' || selector == 'output' || selector == 'file') {
					var attrId = selector == 'input' ? '6CCAFE3781CA4875E053BF1A13AC0E97' : '7A88687D266A3D7CE053BF1A13ACD2C3';

					console.log(data);
					console.log(temStore["input"])
					jQuery.support.cors = true;
					$.ajax({
						type: 'PUT',
						url: basFlow.baseUrl + '/document/save?username=' + basFlow.username,
						data: JSON.stringify({
							'docId': data.id,
							'docTitle': data.newName,
							'downloadUrl': data.downloadUrl,
							'viewUrl': data.viewUrl,
							'folderDocumentList': [{ "documentid": data.id, "folderid": attrId }],
							'provideruser': basFlow.username,
							'revId': data.revId
						}),
						contentType: 'application/json',
						dataType: 'json',
						async: true,
						success: function (res) {
							console.log(res);
						},
						error: function (err) {
							console.log(err)
						}
					})

					jQuery.support.cors = true;
					$.ajax({
						type: 'POST',
						url: basFlow.baseUrl + '/modellistdoc/save?username=' + basFlow.username,
						data: JSON.stringify({
							"description": "",
							"docid": data.id,
							"folderid": attrId,
							"modelid": getParam("id"),
							"name": data.newName
						}),
						contentType: 'application/json',
						dataType: 'json',
						async: true,
						success: function (res) {
							console.log(res);
							for (var i = 0; i < temStore[selector].length; i++) {
								if (temStore[selector][i].id === data.id) {
									temStore[selector][i].docid = res.id;
									basFlow.controls[basFlow.curId][selector][i].docid = res.id;
									break;
								}
							}
							$(".content_wrapper").children().eq(1).html(doTData({
								attrList: temStore,
								listProcess: basFlow.storeUpgressData.bpmDto ? (basFlow.storeUpgressData.bpmDto.outputlist ? basFlow.storeUpgressData.bpmDto.outputlist : []) : []
							}))
						},
						error: function (err) {
							console.log(err)
						}
					})
				}
				if ((selector == 'input' || selector == 'output') && (temStore.type === 'process' || (temStore.type === 'process02') || (temStore.type === 'process03'))) {
					for (var i = 0; i < $("#pointAttr li").length; i++) {
						if ($("#pointAttr li").eq(i).text() === $.i18n.prop("activityDes")) {
							$("#pointAttr li").eq(i).siblings().removeClass("active");
							$("#pointAttr li").eq(i).addClass("active");
							$(".attr1Box").children().siblings().css("display", "none");
							$(".attr1Box").children().eq(i).css("display", "block");
							break;
						}
					}
				}
			}
		}
	})
}


// 文件删除
$("body").on("click", ".deleteFile i", function () {
	if (!basFlow.curId[0]) {
		basFlow.alertBox($.i18n.prop("firstChooseNode") + "! ", 'danger');
		return false
	}
	console.log($(this).parent().attr("doc-id"), $(this).parent().attr("file-type"), $(this).parent().attr("file-id"))
	deleteFile($(this).parent().attr("doc-id"), $(this).parent().attr("file-type"), $(this).parent().attr("file-id"))
	// console.log($(this).parents("tr").prev().find("input .attr-table-inp"));
	// $(this).parents("tr").prev().find("input .attr-table-inp").val("")
})

function deleteFile(id, selector, fileid) {
	$.ajax({
		url: basFlow.baseUrl + "/modellistdoc/delete/" + id + '?username=' + basFlow.username,
		type: "POST",
		data: {},
		processData: false, //告诉jquery不要去处理发送的数据
		contentType: false, //告诉jquery不要去设置请求头Content-Type
		success: function (data) {
			if (data) {
				var doTData = doT.template($('#attr_templ').text())
				if (/CONTROL/.test(basFlow.curId)) {
					temStore = basFlow.controls[basFlow.curId]
				} else {
					temStore = basFlow.swimlanes[basFlow.curId]
				}
				if (temStore.input) {
					for (var k = 0; k < temStore.input.length; k++) {
						if (temStore[selector][k] && (temStore[selector][k].id == fileid)) {
							temStore[selector].splice(k, 1);
							break;
						}
					}
				}
				if (temStore.output) {
					for (var k = 0; k < temStore.output.length; k++) {
						if (temStore[selector][k] && (temStore[selector][k].id == fileid)) {
							temStore[selector].splice(k, 1);
							break;
						}
					}
				}
				if (temStore.file) {
					for (var k = 0; k < temStore.file.length; k++) {
						if (temStore[selector][k] && (temStore[selector][k].id == fileid)) {
							temStore[selector].splice(k, 1);
							break;
						}
					}
				}
				if (temStore.messageGroup) {
					for (var k = 0; k < temStore.messageGroup.length; k++) {
						if (temStore[selector][k] && (temStore[selector][k].id == fileid)) {
							temStore[selector].splice(k, 1);
							break;
						}
					}
				}
				if (temStore.approvalGroup) {
					for (var k = 0; k < temStore.approvalGroup.length; k++) {
						if (temStore[selector][k] && (temStore[selector][k].id == fileid)) {
							temStore[selector].splice(k, 1);
							break;
						}
					}
				}
				if (temStore.messageFile) {
					for (var k = 0; k < temStore.messageFile.length; k++) {
						if (temStore[selector][k] && (temStore[selector][k].id == fileid)) {
							temStore[selector].splice(k, 1);
							break;
						}
					}
				}
				$(".content_wrapper").children().eq(1).html(doTData({
					attrList: temStore,
					listProcess: basFlow.storeUpgressData.bpmDto ? (basFlow.storeUpgressData.bpmDto.outputlist ? basFlow.storeUpgressData.bpmDto.outputlist : []) : []
				}))
				if (/CONTROL/.test(basFlow.curId[0])) {
					var doTData = doT.template($('#img_templ').text())
					$("#" + basFlow.curId[0]).remove()
					basFlow.addControl(basFlow.controls[basFlow.curId[0]])
					basFlow.focusItem(basFlow.curId[0], "single");
				}
				if (selector == 'messageGroup') {
					for (var i = 0; i < $("#pointAttr li").length; i++) {
						if ($("#pointAttr li").eq(i).text() === $.i18n.prop("informs")) {
							$("#pointAttr li").eq(i).siblings().removeClass("active");
							$("#pointAttr li").eq(i).addClass("active");
							$(".attr1Box").children().siblings().css("display", "none");
							$(".attr1Box").children().eq(i).css("display", "block");
							break;
						}
					}

					// jQuery.support.cors = true;
					// $.ajax({
					// 	type: 'GET',
					// 	url: basFlow.baseUrl + '/document/docdelete/'  + fileid,
					// 	data: {},
					// 	async: true,
					// 	success: function(res){
					// 		console.log(res);
					// 	},
					// 	error: function(err) {
					// 		console.log(err)
					// 	}
					// })

					// jQuery.support.cors = true;
					// $.ajax({
					// 	type: 'POST',
					// 	url: basFlow.baseUrl + '/modellistdoc/delete/'  + id,
					// 	data: {},
					// 	async: true,
					// 	success: function(res){
					// 		console.log(res);
					// 	},
					// 	error: function(err) {
					// 		console.log(err)
					// 	}
					// })
				}

				if (selector == 'approvalGroup') {
					for (var i = 0; i < $("#pointAttr li").length; i++) {
						if ($("#pointAttr li").eq(i).text() === $.i18n.prop("approveRules")) {
							$("#pointAttr li").eq(i).siblings().removeClass("active");
							$("#pointAttr li").eq(i).addClass("active");
							$(".attr1Box").children().siblings().css("display", "none");
							$(".attr1Box").children().eq(i).css("display", "block");
							break;
						}
					}

					// jQuery.support.cors = true;
					// $.ajax({
					// 	type: 'GET',
					// 	url: basFlow.baseUrl + '/document/docdelete/'  + fileid,
					// 	data: {},
					// 	async: true,
					// 	success: function(res){
					// 		console.log(res);
					// 	},
					// 	error: function(err) {
					// 		console.log(err)
					// 	}
					// })

					// jQuery.support.cors = true;
					// $.ajax({
					// 	type: 'POST',
					// 	url: basFlow.baseUrl + '/modellistdoc/delete/'  + id,
					// 	data: {},
					// 	async: true,
					// 	success: function(res){
					// 		console.log(res);
					// 	},
					// 	error: function(err) {
					// 		console.log(err)
					// 	}
					// })
				}

				if (selector == 'messageFile') {
					for (var i = 0; i < $("#pointAttr li").length; i++) {
						if ($("#pointAttr li").eq(i).text() === $.i18n.prop("inforDoc")) {
							$("#pointAttr li").eq(i).siblings().removeClass("active");
							$("#pointAttr li").eq(i).addClass("active");
							$(".attr1Box").children().siblings().css("display", "none");
							$(".attr1Box").children().eq(i).css("display", "block");
							break;
						}
					}
					// jQuery.support.cors = true;
					// $.ajax({
					// 	type: 'POST',
					// 	url: basFlow.baseUrl + '/document/docdelete/'  + fileid,
					// 	data: {},
					// 	async: true,
					// 	success: function(res){
					// 		console.log(res);
					// 	},
					// 	error: function(err) {
					// 		console.log(err)
					// 	}
					// })

					// jQuery.support.cors = true;
					// $.ajax({
					// 	type: 'POST',
					// 	url: basFlow.baseUrl + '/modellistdoc/delete/'  + id,
					// 	data: {},
					// 	async: true,
					// 	success: function(res){
					// 		console.log(res);
					// 	},
					// 	error: function(err) {
					// 		console.log(err)
					// 	}
					// })
				}
				if (selector == 'input' || selector == 'output' || selector == 'file') {
					for (var i = 0; i < $("#pointAttr li").length; i++) {
						if ($("#pointAttr li").eq(i).text() === $.i18n.prop("activityDes")) {
							$("#pointAttr li").eq(i).siblings().removeClass("active");
							$("#pointAttr li").eq(i).addClass("active");
							$(".attr1Box").children().siblings().css("display", "none");
							$(".attr1Box").children().eq(i).css("display", "block");
							break;
						}
					}

					// jQuery.support.cors = true;
					// $.ajax({
					// 	type: 'GET',
					// 	url: basFlow.baseUrl + '/document/docdelete/'  + fileid,
					// 	data: {},
					// 	async: true,
					// 	success: function(res){
					// 		console.log(res);
					// 	},
					// 	error: function(err) {
					// 		console.log(err)
					// 	}
					// })

					// jQuery.support.cors = true;
					// $.ajax({
					// 	type: 'POST',
					// 	url: basFlow.baseUrl + '/modellistdoc/delete/'  + id,
					// 	data: {},
					// 	async: true,
					// 	success: function(res){
					// 		console.log(res);
					// 	},
					// 	error: function(err) {
					// 		console.log(err)
					// 	}
					// })
				}

				basFlow.alertBox($.i18n.prop("delSuccess") + "! ", 'success');
			}
		}
	})
}

$("body").on("click", ".closeRightMoal", function () {
	$('.btn_wrapper li i').removeClass('active');
	$(".content_wrapper .content_item").hide()
})
$(".cancelVersion").on("click", function () {
	$(".modalDialogVersions").hide();
})

function chooselistProcess(index, node) {
	if (!basFlow.curId[0]) {
		basFlow.alertBox($.i18n.prop("firstChooseNode") + "! ", 'danger');
		return false
	}
	console.log(node.checked)
	var inputList = basFlow.controls[basFlow.curId[0]];
	if (node.checked) {
		var count = 0;
		for (var i = 0; i < inputList.output.length; i++) {
			if (basFlow.storeUpgressData.bpmDto.outputlist[index].id == inputList.output[i].id) {
				count++;
			}
		}
		if (!count) {
			basFlow.storeUpgressData.bpmDto.outputlist[index].isChecked = "checked";
			var attrId = '7A88687D266A3D7CE053BF1A13ACD2C3';

			jQuery.support.cors = true;
			$.ajax({
				type: 'POST',
				url: basFlow.baseUrl + '/modellistdoc/save?username=' + basFlow.username,
				data: JSON.stringify({
					"description": "",
					"docid": basFlow.storeUpgressData.bpmDto.outputlist[index].attatchid,
					"folderid": attrId,
					"modelid": getParam("id"),
					"name": basFlow.storeUpgressData.bpmDto.outputlist[index].newName
				}),
				contentType: 'application/json',
				dataType: 'json',
				async: false,
				success: function (res) {
					basFlow.storeUpgressData.bpmDto.outputlist[index].docid = res.id;
					basFlow.storeUpgressData.bpmDto.outputlist[index].id = res.docid;
				},
				error: function (err) {
					console.log(err)
				}
			})
			inputList.output.push(basFlow.storeUpgressData.bpmDto.outputlist[index])
			inputList.outputDesc = inputList.outputDesc ? inputList.outputDesc : inputList.output[0].newName;
			var doTData = doT.template($('#attr_templ').text())
			$(".content_wrapper").children().eq(1).html(doTData({
				attrList: inputList,
				listProcess: basFlow.storeUpgressData.bpmDto ? (basFlow.storeUpgressData.bpmDto.outputlist ? basFlow.storeUpgressData.bpmDto.outputlist : []) : []
			}))
			if ($("#" + basFlow.curId[0] + " .text .outputCss").length > 0) {
				$("#" + basFlow.curId[0] + " .text .outputCss").remove()
			}
			if (!$("#" + basFlow.curId[0] + " .text .outputCss").length) {
				console.log(basFlow.controls[basFlow.curId[0]])
				var desc = ((inputList.output.length > 1 ? basFlow.controls[basFlow.curId[0]].outputDesc.substring(0, 10) + '...' : (basFlow.controls[basFlow.curId[0]].outputDesc.length > 10 ? basFlow.controls[basFlow.curId[0]].outputDesc.substring(0, 10) + '...' : basFlow.controls[basFlow.curId[0]].outputDesc.substring(0, 10))));
				$("#" + basFlow.curId[0] + " .text").append('<div class="inputImgCss outputCss">' + desc + '<img src="' + basFlow.options.toolsPath + '/processOutput.png" /></div>');
			}
			$("#pointAttr li").eq(1).siblings().removeClass("active");
			$("#pointAttr li").eq(1).addClass("active");
			$(".attr1Box").children().siblings().css("display", "none");
			$(".attr1Box").children().eq(1).css("display", "block");

		}
	}
	else {
		basFlow.storeUpgressData.bpmDto.outputlist[index].isChecked = '';

		var nameDesc = '';
		for (var i = 0; i < inputList.output.length; i++) {
			console.log(basFlow.storeUpgressData.bpmDto.outputlist[index].id == inputList.output[i].id)
			if (
				basFlow.storeUpgressData.bpmDto.outputlist[index].docid == inputList.output[i].id ||
				basFlow.storeUpgressData.bpmDto.outputlist[index].id == inputList.output[i].id
			) {
				nameDesc = inputList.output[i].newName;
				$.ajax({
					url: basFlow.baseUrl + "/modellistdoc/delete/" + inputList.output[i].docid + '?username=' + basFlow.username,
					type: "POST",
					data: {},
					processData: false, //告诉jquery不要去处理发送的数据
					contentType: false, //告诉jquery不要去设置请求头Content-Type
					success: function (data) {
					}
				})
				inputList.output.splice(i, 1);
				break;
			}
		}
		inputList.outputDesc = inputList.outputDesc == nameDesc ? (inputList.output.length > 0 ? inputList.output[0].newName : '') : inputList.outputDesc;
		$("#" + basFlow.curId[0]).remove()
		console.log(basFlow.controls[basFlow.curId[0]])
		basFlow.addControl(basFlow.controls[basFlow.curId[0]])
		basFlow.focusItem(basFlow.curId[0], "single");
		$("#pointAttr li").eq(1).siblings().removeClass("active");
		$("#pointAttr li").eq(1).addClass("active");
		$(".attr1Box").children().siblings().css("display", "none");
		$(".attr1Box").children().eq(1).css("display", "block");
	}
}

// 流程校验部分--------------------------开始
$(".modalDialogProcessTable .confirmProcess, .modalDialogProcessTable .cancelChoose").off("click").on("click", function () {
	$(".modalDialogProcessTable").hide();
})

// 流程校验部分--------------------------结束

// 选择复制流程的方法--------------------------开始
$(".modalDialogProcessCopy .confirmProcess").on("click", function () {
	if (!copyPersonItem) {
		basFlow.alertBox("请选择人员! ", 'danger');
		return false
	}
	$("#processTableCopy").html('');
	console.log(basFlow.copyChartData)
	console.log(copyPersonItem)
	jQuery.support.cors = true;
	$.ajax({
		type: 'POST',
		url: basFlow.baseUrl + '/listhistory/getLastByModelid/' + basFlow.copyChartData.id + '?empuid=' + copyPersonItem.empuid + '&username=' + basFlow.username,
		success: function (res) {
			console.log(res.data)
			copyid = res.data
			$("#iframeSee").attr("src", './processChart/BaseNewPage.html?showChart=yes&id=' + copyid.split(",")[0] + '&listid=' + copyid.split(",")[1])
			// $(".modalDialogProcessCopy").hide()
			$(".modalDialogProcessCopy").css("display", "none");
			$(".modalDialogProcessSee").show()
			$(".bg-rect").show()
		}
	})
})
$(".modalDialogProcessCopy .cancelChoose").off('click').on("click", function () {
	$("#processTableCopy").html('');
	$('.modalDialogProcessCopy .checkedList').html('');
	// $(".modalDialogProcessCopy").hide()
	$(".modalDialogProcessCopy").css("display", "none");
})

$(".modalDialogProcessCopy").off("click").delegate(".leadersDel i", "click", function () {
	copyPersonItem = {}
	$('.modalDialogProcessCopy .checkedList').html('');
	$(".modalDialogProcessCopy input").prop("checked", false)
	return false
})

$(".modalDialogProcessSee .confirmProcess").on("click", function () {
	jQuery.support.cors = true;
	$.ajax({
		type: 'POST',
		url: basFlow.baseUrl + '/listhistory/saveLast/' + copyid.split(',')[0] + '/' + basFlow.id + '?username=' + basFlow.username,
		success: function (res) {
			console.log(res)
			if (res) {
				$(".modalDialogProcessSee").hide()
				$(".bg-rect").hide()
				location.reload()
			}
		}
	})

})

$(".modalDialogProcessSee .cancelChoose").off("click").on("click", function () {
	$('.modalDialogProcessCopy .checkedList').html('');
	$(".modalDialogProcessSee").hide()
	$(".bg-rect").hide()

})
function checkCopyData(str) {
	copyPersonItem = str
	var templ = '<span class="commonFileName leadersDel" data-id="' + copyPersonItem.id + '">' + copyPersonItem.cnname + '(' + basFlow.copyChartData.name + ')<i></i></span>';
	$('.modalDialogProcessCopy .checkedList').html(templ);
}


// 选择复制流程的方法--------------------------结束


function getParam(paramName) {
	paramValue = "", isFound = !1;
	if (this.location.search.indexOf("?") == 0 && this.location.search.indexOf("=") > 1) {
		arrSource = decodeURI(this.location.search).substring(1, this.location.search.length).split("&"), i = 0;
		while (i < arrSource.length && !isFound) arrSource[i].indexOf("=") > 0 && arrSource[i].split("=")[0].toLowerCase() == paramName.toLowerCase() && (paramValue = arrSource[i].split("=")[1], isFound = !0), i++
	}
	return paramValue == "" && (paramValue = null), paramValue
}

// // 隐藏泳道
// $('.J_swimlaneTitle').hide()

