

jQuery(function($) {

    //及时设置合同状态
    $(".contract-status-select").on('change', function() {
        var statusId = $(this).find('option:selected').val();
        var url = $(this).data('setUrl');
        url += statusId;
        $.getJSON(url, function(json) {
            if (json.status == 1) {
                $(".contract-status").html(json.status_name);
            }
            else {
                alert(json.info);
            }

        });
    });

    //系统通知点击下拉效果
    $('.message-title').click(function() {
        var dom = $(this);
        var status = dom.data('setStatus');
        dom.next("p").slideToggle(500,
                function() {
                    var liDom = dom.parent("li");
                    var isHas = liDom.hasClass("message-hover");
                    if (isHas) {
                        liDom.removeClass("message-hover");
                        //          liDom.appendTo(liDom.parent("ul"));
                    } else {
                        if (status == 0) {
                            saveRead(dom.data('setUrl'));
                            dom.data('setStatus', '1');
                        }
                        dom.prev(".message-point").attr("src", dom.data('src') + "/images/point-grey.gif");
                        liDom.addClass("message-hover");
                    }
                }
        );
    });


    /**
     * 合同列表页核对状态快捷操作
     */
    $(".set-check").on('click', function() {
        if (!confirm('确定更改数据核对状态？')) {
            return false;
        }
        $.post($(this).data('setUrl'), {}, function(resp) {
            if (resp.status == 1) {
                art.dialog({
                    title: '成功提示',
                    time: 3,
                    icon: 'succeed',
                    content: resp.info,
                });
            } else {
                art.dialog({
                    title: '失败提示',
                    time: 3,
                    icon: 'error',
                    content: resp.info
                });
            }
        });
    });

    /**
     * 点击查看合同的金额
     */
    $(".see-amount").on('click', function() {
        var obj = $(this);
        $.post(obj.data('url'), {}, function(resp) {
            if (resp.status == 1) {
                obj.html(resp.info);
            } else {
                art.dialog({
                    title: '失败提示',
                    time: 3,
                    icon: 'error',
                    content: resp.info
                });
            }
        });
    });

});

function saveRead(url) {
    $.getJSON(url, function(json) {
        if (json.status == '0') {
            alert(json.info);
        }
    });
}
 