var id = helper.request.queryString("id");
$(document).ready(function () {
    getReactionCategory();
    $(".addBtn").click(function () {
        saveCon();
    });

    //获取知识库详情
    if (id) {
        $.ajax({
            type: "get",
            url: huayi.config.callcenter_url + "Achievements/GetModel",
            async: true,
            dataType: "json",
            data: {
                token: $.cookie("token"),
                id: id,
            },
            success: function (result) {
                if (result.state.toLowerCase() == "success") {
                    var data = result.data;
                    $("#workOrderId").val(data.F_WorkOrderId);
                    $("#PID").val(data.F_Deptid);
                    $(".inps").val(data.F_DeptName);
                    $("#evaluation option:selected").text(data.F_Evaluation);
                    $("#evaluation option:selected").val(data.F_Evaluation);
                    $("#bonusitems option:selected").text(data.F_Bonusitems);
                    $("#bonusitems option:selected").val(data.F_Bonusitems);
                    $("#remark").val(data.F_Remarks);
                }
            },
        });
    }
});

//保存
function saveCon() {
    $.ajax({
        type: "post",
        url: huayi.config.callcenter_url + "Achievements/AddAchievements",
        async: true,
        dataType: "json",
        data: {
            token: $.cookie("token"),
            F_ID: id,
            F_Type: 0, // 0减分项，1加分项
            F_WorkOrderId: $("#workOrderId").val(), // 工单编号
            F_Deptid: $("#PID").val(), // 部门id
            F_DeptName: $(".inps").val(), // 部门名称
            F_Evaluation: $("#evaluation option:selected").text(), // 考评内容
            F_Bonusitems: $("#bonusitems option:selected").text(), // 二级考评内容
            F_Remarks: $("#remark").val(), // 备注
        },
        success: function (data) {
            if (data.state.toLowerCase() == "success") {
                var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                parent.layer.close(index); //再执行关闭
                parent.layer.msg(data.message); //再执行关闭
                parent.$("#tableList").bootstrapTable("refresh"); //再执行关闭
            }
        },
    });
}

//获取考评内容
function getReactionCategory(pid = 2509) {
    $.ajax({
        type: "get",
        url: huayi.config.callcenter_url + "Dictionary/GetDicValueListById",
        async: false,
        dataType: "json",
        data: {
            token: $.cookie("token"),
            id: pid,
        },
        success: function (result) {
            if (result.state.toLowerCase() == "success") {
                var content = result.data;
                $("#evaluation").empty();
                $("#evaluation").append("<option value=''>请选择</option>");
                $(content).each(function (i, e) {
                    $("#evaluation").append(
                        "<option value='" +
                            e.F_ValueId +
                            "'>" +
                            e.F_Value +
                            "</option>"
                    );
                });
            }
        },
    });
}

// $("#evaluation").change(function () {
//     var pid = $("#evaluation").val();
//     var type = 1;
//     getReactionCategory(pid, type);
// });
