/**
 * 专员维护考核人和评分人页面(专员) 动态列表专员操作
 */
shr.defineClass("shr.custom.ExpandAssessKHRDynamicList", shr.custom.CustomDynamicList, {
    editColumns: [],
    initalizeDOM: function () {
        this.editColumns.push("entrys.onelift");
        this.editColumns.push("entrys.shareliftres");
        this.editColumns.push("entrys.shareliftzy");
        this.editColumns.push("entrys.shareliftlc");
        this.editColumns.push("entrys.unitelift");
        var _self = this;
        _self.isSum = false
        shr.custom.ExpandAssessKHRDynamicList.superClass.initalizeDOM.call(this);
    },
    /**
  * 描述: 导入action
  */
    importAction: function () {
        var billId = shr.getUrlRequestParam("billId");
        var customParam = { parentId: billId };
        this.doImportData('import', customParam);
    },
    /**
     * 	单元格点击事件触发
     * @param {*} rowid 
     * @param {*} colIndex 
     * @param {*} cellcontent 
     * @param {*} e 
     * @returns 
     */
    onCellSelect: function (rowid, colIndex, cellcontent, e) {
        shr.custom.ExpandAssessKHRDynamicList.superClass.onCellSelect.call(this);
        // 选择的是选择框
        if (colIndex != 0) {
            var state = $("#grid").jqGrid("getCell", rowid, "entrys.assestatus");
            if (3 == state || 4 == state) {
                //考核人已提交状态单据行不能编辑
                $("#grid").jqGrid("setGridParam", { cellEdit: false })
            } else {
                //考核人已提交状态单据行能编辑
                $("#grid").jqGrid("setGridParam", { cellEdit: true })
            }
            return;
        }
    },
    /**
     * 表格加载完成后操作，供子类复写
     */
    afterLoadComplete: function (ret) {
        //当考核人已提交状态 编辑列单元格背景色显示白色
        if (ret.records > 0) {
            for (let i = 0; i < ret.rows.length; i++) {
                var rowData = ret.rows[i];
                var state = rowData["entrys.assestatus"];
                if (3 == state.value || 4 == state.value) {
                    //考核人已提交状态
                    var fid = rowData['entrys.id'];
                    var tr = $('tr[id="' + fid + '"]')
                    var tds = tr.find('.cellEditItem');
                    for (var j = 0; j < tds.length; j++) {
                        $(tds[j]).removeClass('cellEditItem')
                    }
                }
            }
        }
    },
    /**
     * 提交至负责人
     */
    submitPrincipalAction() {
        var _self = this;
        var $grid = $(this.gridId);
        var selectedIds = $grid.jqGrid("getSelectedRows");
        if (selectedIds.length > 0) {
            // shr.showConfirm($.shrI18n.common.tips.deleteConfirm, function () {
            _self.remoteCall({
                method: 'submitPrincipal',
                param: {
                    idArray: selectedIds + "",
                },
                success: function (data) {
                    shr.showInfo({
                        message: "提交成功",
                        hideAfter: 2
                    });
                    setTimeout(function () {
                        _self.queryGrid();
                    }, 2000); // 2000 毫秒即为两秒钟
                }, error: function (response) {
                    shr.showError({
                        message: response.summary,
                        hideAfter: 2
                    });
                }
                // });

            });
        } else {
            shr.showWarning({
                message: $.shrI18n.common.tips.chooseTableDataFirst
                ,hideAfter: 2
            });
        }
    },
    /**
       * 组装保存时传至服务端的数据
       */
    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();
            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_entrys\\.id']").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;
    },
    // 根据动态列表配置 取业务主键
    getBillIdFieldName: function () {
        return 'expandAssess.id';
    },

    /**
    * 描述: 导入action
    */
    importAction: function () {
        var billId = shr.getUrlRequestParam("billId");
        var customParam = { parentId: billId };
        this.doImportData('import', customParam);
    },

})