info.js 2.72 KB

'use strict';
var $ = require('jquery');
require('../util/jquery.gritter');

exports.cmd=function(jsonparam,callback){
    //提交操作
    function __ajax(options,callback){
        $.ajax({
            type: 'POST',
            url: options.url,
            dataType: 'json',
            data:options.data||{},
            success: function(res) {
                res=res.data;
                if (res.code === 200) {
                    $.gritter.add({
                        title: options.msg,
                        class_name: 'growl-success',
                        sticky: false,
                        time: '1000',
                        after_open: function() {
                            callback&&callback();
                        }
                     });
                } else {
                    $.gritter.add({
                        title: '提交失败',
                        class_name: 'growl-danger',
                        sticky: false,
                        time: '1000'
                     });
                }
            }
        });
    }

    //提交操作
    $(document).on('click', '.btn-submit', function() {
        var that = this;
        jsonparam.status=300;
        __ajax({
            url:'/supplier/index/status',
            data:jsonparam,
            msg:'提交成功'
        },function(){
            callback&&callback();
        });
    });

    //提交驳回
    $(document).on('click', '.btn-return', function() {
        var that = this;
        jsonparam.status=400;
        __ajax({
            url:'/supplier/index/status',
            data:jsonparam,
            msg:'提交成功'
        },function(){
            callback&&callback();
        });
    });

    //冻结操作
    $(document).on('click', '.btn-freeze', function() {
        var that = this;
        jsonparam.isFreeze="Y";
        __ajax({
            url:'/supplier/index/status',
            data:jsonparam,
            msg:'提交成功'
        },function(){
            callback&&callback();
        });
    });

    //解冻操作
    $(document).on('click', '.btn-recovery', function() {
        var that = this;
        jsonparam.isFreeze="N";
        __ajax({
            url:'/supplier/index/status',
            data:jsonparam,
            msg:'提交成功'
        },function(){
            callback&&callback();
        });
    });

}

exports.init = function() {
    if($("#status").val()==="200"){
        $(".btn-return").add(".btn-submit").show();
    }else{
        $(".btn-return").add(".btn-submit").remove();
    }
    var Json={
        id:$("#id").val(),
        status:$("#status").val(),
        operations:$("#operations").val()
    }
    exports.cmd(Json,function(){
        history.go(-1);
    });
}