/**
 * 专员维护考核人和评分人页面(专员) 动态列表专员操作
 */
shr.defineClass("shr.custom.ExpandAssessZYDynamicList", shr.custom.CustomDynamicList, {
    editColumns: [],
    initalizeDOM: function () {
        this.editColumns.push("assessor.name");
        this.editColumns.push("adminorg.name");
        this.editColumns.push("entrys.threshold");
        this.editColumns.push("entrys.target");
        this.editColumns.push("entrys.challenge");
        this.editColumns.push("principal.name");
        this.editColumns.push("entrys.checkrate");
        this.editColumns.push("entrys.remark");
        var _self = this;
        _self.isSum = false

        shr.custom.ExpandAssessZYDynamicList.superClass.initalizeDOM.call(this);
        _self.verifyeriodIsLockAction();
    },

    /**
     * 校验周期是否锁定
     */
    verifyeriodIsLockAction() {
        var billId = shr.getUrlRequestParam("billId");
        var _self = this;
        _self.remoteCall({
            method: 'verifyeriodIsLock',
            param: {
                billId: billId,
            },
            async: false,
            success: function (data) {
                if (data) {
                    _self.hideFuntion(1);
                }else{
                    _self.hideFuntion(2);
                }
            }
        });
    },
    hideFuntion(type){
        if(type==1){
            $("#delete").hide();
            $("#startCheck").hide();
            $("#closeCheck").hide();
            $("#import").hide();
            $("#withdraw").hide();
            $("#prass").hide();
            $("#lock").hide();
            $("#unlock").show();
        }
        if(type==2){
            $("#delete").show();
            $("#startCheck").show();
            $("#closeCheck").show();
            $("#import").show();
            $("#withdraw").show();
            $("#prass").show();
            $("#lock").show();
            $("#unlock").hide();
        }
       
    },
    //显示季度比例
    showQuarterlyRatioAction() {
        var billId = shr.getUrlRequestParam("billId");
        this.reloadPage({
            uipk: "com.kingdee.eas.custom.expandassess.app.QuarterlyRatio.list",
            billId: billId
        });
    },
    /**
    * 催办
    */
    prassAction() {
        var _self = this;
        if (_self.checkEditCell()) {
            shr.showWarning({
                message: "请先保存数据，再进行操作！",
                hideAfter: 2
            });
            return;
        }
        var _self = this;
        var billId = shr.getUrlRequestParam("billId");
        _self.remoteCall({
            method: 'prass',
            param: {
                billId: billId,
            },
            async: false,
            success: function (data) {
                shr.showInfo({
                    message: data,
                    hideAfter: 2
                });
            }
        });
    },
    /**
  * 撤回至负责人
  */
    withdrawAction() {
        var _self = this;
        var $grid = $(this.gridId);
        var selectedIds = $grid.jqGrid("getSelectedRows");
        if (selectedIds.length > 0) {
            shr.showConfirm("确认是否撤回至负责人", function () {
                _self.remoteCall({
                    method: 'withdraw',
                    param: {
                        idArray: selectedIds + "",
                    },
                    success: function (data) {
                        shr.showInfo({
                            message: "撤回成功",
                            hideAfter: 3
                        });
                        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
            });
        }
    },
    /**
     * 	单元格点击事件触发
     * @param {*} rowid 
     * @param {*} colIndex 
     * @param {*} cellcontent 
     * @param {*} e 
     * @returns 
     */
    onCellSelect: function (rowid, colIndex, cellcontent, e) {
        shr.custom.ExpandAssessZYDynamicList.superClass.onCellSelect.call(this);
        // 选择的是选择框
        if (colIndex != 0) {
            var state = $("#grid").jqGrid("getCell", rowid, "entrys.assestatus");
            var columnName = $("#grid").getColumnName(colIndex);
            if (1 != state && (columnName == "assessor.name"
                || columnName == "adminorg.name"
                || columnName == "entrys.threshold"
                || columnName == "entrys.target"
                || columnName == "entrys.challenge"
                || columnName == "principal.name")) {
                //考核人已提交状态单据行不能编辑
                $("#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 (1 != 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++) {
                        var describedby = tds[j].getAttribute('aria-describedby').split("grid_")[1];
                        if (describedby == "entrys.checkrate" || "entrys.remark" == describedby) {
                            continue;
                        }
                        $(tds[j]).removeClass('cellEditItem')
                    }
                }
            }
        }
    },
    /**
       * 组装保存时传至服务端的数据
       */
    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';
    },
    /**
    * 删除
    */
    deleteAction() {
        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: 'customDelete',
                    param: {
                        idArray: selectedIds + "",
                    },
                    success: function (data) {
                        shr.showInfo({
                            message: "刪除成功",
                            hideAfter: 3
                        });
                        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
            });
        }
    },
    /**
    * 描述: 导入action
    */
    importAction: function () {
        var billId = shr.getUrlRequestParam("billId");
        var customParam = { parentId: billId };
        this.doImportData('import', customParam);
    },
    /**
     * 解锁周期
     */
    unlockAction() {
        var _self = this;
        var billId = shr.getUrlRequestParam("billId");
        _self.remoteCall({
            method: 'unlock',
            param: {
                billId: billId,
            },
            success: function (data) {
                shr.showInfo({
                    message: "解锁成功",
                    hideAfter: 3
                });
                setTimeout(function () {
                    _self.queryGrid();
                }, 2000); // 2000 毫秒即为两秒钟
                _self.hideFuntion(2);
            }, error: function (response) {
                shr.showError({
                    message: response.summary,
                    hideAfter: 2
                });
            }
        });
    },
    /**
     * 锁定周期
     */
    lockAction() {
        var _self = this;
        var billId = shr.getUrlRequestParam("billId");
        _self.remoteCall({
            method: 'lock',
            param: {
                billId: billId,
            },
            success: function (data) {
                shr.showInfo({
                    message: "锁定成功",
                    hideAfter: 3
                });
                _self.hideFuntion(1);
                setTimeout(function () {
                    _self.queryGrid();
                }, 2000); // 2000 毫秒即为两秒钟
            }, error: function (response) {
                shr.showError({
                    message: response.summary,
                    hideAfter: 2
                });
            }
        });
    },
    /**
     * 启动考核
     */
    startCheckAction() {
        var _self = this;
        var billId = shr.getUrlRequestParam("billId");
        _self.remoteCall({
            method: 'startCheck',
            param: {
                billId: billId,
            },
            success: function (data) {
                shr.showInfo({
                    message: "启动考核成功",
                    hideAfter: 3
                });
                setTimeout(function () {
                    _self.queryGrid();
                }, 2000); // 2000 毫秒即为两秒钟
            }, error: function (response) {
                shr.showError({
                    message: response.summary,
                    hideAfter: 2
                });
            }
        });
    },
    /**
    *关闭考核
    */
    closeCheckAction() {
        var _self = this;
        var $grid = $(this.gridId);
        var selectedIds = $grid.jqGrid("getSelectedRows");
        if (selectedIds.length > 0) {
            shr.showConfirm("是否确定关闭考核，重新执行流程", function () {
                _self.remoteCall({
                    method: 'closeCheck',
                    param: {
                        entryIds: selectedIds + "",
                    },
                    success: function (data) {
                        shr.showInfo({
                            message: "关闭考核成功",
                            hideAfter: 3
                        });
                        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
            });
        }
    },
})