/**
 * 分配人员明细列表_已提交_专员list.js
 */
shr.defineClass("shr.custom.DetailDynamicList", shr.custom.CustomDynamicList, {
	//可编辑列 数组(不区分大小写)
	editColumns: [],
	isSum: false,
	initalizeDOM: function () {
		//新增编辑列
		// this.editColumns.push("bdpapd.remarks");
		// this.editColumns.push("bdpapd.approvalamount");
		this.editColumns.push("bdpapd.performancegradeq1");
		this.editColumns.push("bdpapd.performancegradeq2");
		this.editColumns.push("bdpapd.performancecoeffq1");
		this.editColumns.push("bdpapd.performancecoeffq2");
		this.editColumns.push("bdpapd.initialproportion");
		this.editColumns.push("bdpapd.adjustmentdesc");
		this.editColumns.push("bdpapd.opinionamount");
		shr.custom.DetailDynamicList.superClass.initalizeDOM.call(this);
		var self = this;
		$('#busDep').shrPromptBox("option", {
			//确定按钮设置值,之后执行方法
			afterOK: function (datas, e) {
				//查询表格数据
				self.queryGrid();
			},
			// onchange: function (previous, current) {
			// 	//查询表格数据
			// 	self.queryGrid();
			// },
			//open方法里调用
			verifyBeforeOpenCallback: function (e, value) {
				//var parentId = shr.getUrlParam('parentId');
				var parentId = self.getParentUrlParam('parentId')
				$("#busDep").shrPromptBox("setFilter", "id in ( SELECT CFBusDepID FROM CT_PB_BONUSCYCLEBUSDEPPROJECT where FParentID ='" + parentId + "'  and CFState = '2')");
			},
		});
	},
	/**
	 * 返回
	 */
	backAction: function (callback) {
		var self = this;
		var callback = function () {
			var url = "/shr/dynamic.do?"
			var parentId = self.getParentUrlParam('parentId')
			var params = {
				uipk: "com.kingdee.eas.custom.projectbonus.app.BonusCycle.dynamicList",
				inFrame: true,
				parentId: parentId
			}
			url = url + $.param(params);
			window.parent.location.href = url;
			//shr.urlLocate(url, params);
		};
		shr.custom.DetailDynamicList.superClass.backAction.call(this, callback);
	},
	// 根据动态列表配置 取业务主键
	getBillIdFieldName: function () {
		return 'bdpapd.id';
	},
	//导出选中
	getExportFieldName: function () {
		return 'bdpapd.id';
	},
	/**
	 * @Override
	 */
	queryGrid: function () {
		//设置按钮是否可见
		this.setButtonVisible();
		shr.custom.DetailDynamicList.superClass.queryGrid.call(this);
	},
	/**
	 * 设置按钮是否可见
	 */
	setButtonVisible: function () {
		//var bonusCycleId = shr.getUrlParam('parentId');
		var self = this;
		var bonusCycleId = self.getParentUrlParam('parentId')
		shr.callHandler({
			handler: "com.kingdee.eas.custom.projectbonus.web.handler.BusDepProjectDynamicListHandler",
			action: 'getStateByBonusCycleId',
			param: {
				bonusCycleId: bonusCycleId
			},
			async: false,  //异步
			type: "POST",
			success: function (res) {
				if (1 == res.value) {
					$("#saveDynGrid").hide();
					$("#import").hide();
				} else {
					$("#saveDynGrid").show();
					$("#import").show();
				}
			}
		});
	},
	/**
	 * 	单元格点击事件触发
	 * @param {*} rowid 
	 * @param {*} colIndex 
	 * @param {*} cellcontent 
	 * @param {*} e 
	 * @returns 
	 */
	onCellSelect: function (rowid, colIndex, cellcontent, e) {
		shr.custom.DetailDynamicList.superClass.onCellSelect.call(this);
		if (colIndex != 0) {
			//周期锁定状态
			var bonuscycleState = $("#grid").jqGrid("getCell", rowid, "bonuscycle.state");
			if (1 == bonuscycleState) {
				//锁定
				$("#grid").jqGrid("setGridParam", { cellEdit: false })
			} else {
				//非启用状态不能编辑
				$("#grid").jqGrid("setGridParam", { cellEdit: true })
			}
		}
	},
	/**
	 * 表格加载完成后操作，供子类复写
	 */
	afterLoadComplete: function (ret) {
		//当状态非启用 编辑列单元格背景色显示白色
		if (ret.records > 0) {
			for (let i = 0; i < ret.rows.length; i++) {
				var rowData = ret.rows[i];
				var fid = rowData["_row_index"];
				var tr = $('tr[id="' + fid + '"]')
				var tds = tr.find('.cellEditItem');
				//周期锁定状态
				var bonuscycleState = rowData["bonuscycle.state"];
				if (1 == bonuscycleState.value) {
					//锁定状态
					//启用状态,提交状态
					for (var j = 0; j < tds.length; j++) {
						$(tds[j]).removeClass('cellEditItem')
					}
				} else {
					for (var j = 0; j < tds.length; j++) {
						$(tds[j]).addClass('cellEditItem')
					}
				}
			}
		}
	},
	/**
	* 描述: 导入action
	*/
	importAction: function () {
		//自定义参数
		//var bonusCycleId = shr.getUrlParam('parentId');
		var self = this;
		var bonusCycleId = self.getParentUrlParam('parentId')
		var busDepIds = $("#busDep_el").val();
		var customParam = { "bonusCycleId": bonusCycleId, "busDepIds": busDepIds }
		shr.custom.DetailDynamicList.superClass.importAction.call(this, customParam);
	},
	/**
	 * 获得自定义过滤条件，供子类覆写使用
	 */
	getCustomFilterItems: function () {
		//ar parentId = shr.getUrlParam('parentId');
		var self = this;
		var parentId = self.getParentUrlParam('parentId')
		var busDepIds = $("#busDep_el").val();
		var filter = "bonusCycle.id = '" + parentId + "' and bDPAPD.id is not null";
		if (busDepIds) {
			busDepIds = busDepIds.replace(/,/g, "','");
			return filter += " and busDep.id in ('" + busDepIds + "')";
		}
		return filter;
	},
	/**
	* 组装保存时传至服务端的数据
	*/
	assembleSaveData: function (action) {
		var _self = this;
		//组装需要修改的数据
		var data = [];
		var meta;
		var id, column, value, cur, element, personCode, datatype;
		var tds = $("#grid td[class*='dirty-cell']");
		var $table = $("#grid")[0];

		for (var i = 0; i < tds.length; i++) {
			//获取父节点，以获取对应id
			meta = {};
			var cur = $(tds[i]);
			//获取输入的内容，而不是转以后的字符实体，同时对单引号处理

			fid = cur.parent().attr('id');
			element = cur.attr('aria-describedby').replace('grid_', '');
			value = $($table).getCell(fid, element);
			//value = cur.text().replace(/\'/g, "''").trim();
			fid = cur.parent().attr('id');
			element = cur.attr('aria-describedby').replace('grid_', '');
			datatype = _self.getColumnType(element);
			if ("promptbox" == datatype) {
				column = element.split('.')[0];
				value = value["id"];
			} else {
				column = element.split('.')[1];
			}
			//列表需要显示id列
			id = $("#" + _self.getEscapeChars(fid) + " td[aria-describedby='grid_" + _self.getBillIdFieldName() + "']").attr('title');
			// //校验输入内容

			if (!_self.checkNumValid(value, datatype)) {
				$(tds[i]).focus();
				$(tds[i]).css({
					"border": "solid 2px red"
				});
				throw new Error("请输入正确的格式");
			}
			meta.fid = id;
			meta.column = column;
			meta.value = value;
			meta.type = datatype;
			data.push(meta);
		}
		return data;
	},
	/**
	 * 默认的action处理方法
	 */
	defaultBatchActionHandle: function (option) {
		var selectedIds = this.getSelectedIds();
		if (!selectedIds) {
			shr.showWarning({ message: "请先选中数据!", hideAfter: 3 })
			return;
		}
		shr.custom.BusDepProjectDynamicList.superClass.defaultBatchActionHandle.call(this, option);
	},
	/**
	 * 获取url参数
	 */
	getParentUrlParam: function (param) {
		var url = window.parent.location.search;
		return shr.getUrlRequestParam(param, url);
	}
});

