<!DOCTYPE html>
<!--[if IE 8]>
<html lang="en" class="ie8 no-js"> <![endif]-->
<!--[if IE 9]>
<html lang="en" class="ie9 no-js"> <![endif]-->
<!--[if !IE]><!-->
<html>
<!--<![endif]-->
<!-- BEGIN HEAD -->
<head>
    <base href="#springUrl('/assets/adminlte/')"/>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>工作台</title>
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <!-- Bootstrap 3.3.5 -->
    <link rel="stylesheet" href="bootstrap/css/bootstrap.min.css">
    <!-- Font Awesome -->
    <link rel="stylesheet" href="plugins/font-awesome/css/font-awesome.min.css">
    <!-- Ionicons -->
    <link rel="stylesheet" href="plugins/ionicons/css/ionicons.min.css">

    <!-- DataTables -->
    <link rel="stylesheet" href="plugins/datatables/dataTables.bootstrap.css">

    <!-- Theme style -->
    <link rel="stylesheet" href="dist/css/AdminLTE.min.css">
    <!-- AdminLTE Skins. Choose a skin from the css/skins
         folder instead of downloading all of them to reduce the load. -->
    <link rel="stylesheet" href="dist/css/skins/_all-skins.min.css">
    <!-- iCheck -->
    <link rel="stylesheet" href="plugins/iCheck/flat/blue.css">
    <!-- Date Picker -->
    <link rel="stylesheet" href="plugins/datepicker/datepicker3.css">
    <!-- Daterange picker -->
    <link rel="stylesheet" href="plugins/daterangepicker/daterangepicker-bs3.css">
    <!-- bootstrap wysihtml5 - text editor -->
    <link rel="stylesheet" href="plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.min.css">
    <!--validate css-->
    <link rel="stylesheet" href="plugins/jquery-validation/css/validate.css">

    <!--fileinput css-->
    <link rel="stylesheet" href="plugins/bootstrap-fileinput/bootstrap-fileinput.css">

    <link rel="stylesheet" href="plugins/bootstrap-star-rating/css/star-rating.min.css">
    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
    <style>
        td {
            padding: 5px;
        }
        .title-pan{
            font-weight: bold;padding-top:10px;border-top: #cccccc dashed 1px;
            margin-top:5px;
            clear: both;
        }
        .radio{
          margin-top:0px !important;
          margin-left:5px;
          float: left;
        }
        .borderRed{
            border: red 1px solid;
        }
        .grantTable textarea{
            width: 95%;
        }
        .rating-container .filled-stars{
            color: green;
            border:0px;
            -webkit-text-stroke: 0px;
        }
    </style>
</head>
<!-- END HEAD -->
<body class="hold-transition skin-blue sidebar-mini">

<div class="wrapper">
    <div class="content-wrapper" style="margin-left:0;">

        <section class="content-header">
            <h1>
                促销品申请单管理
                <small>促销品申请单</small>
            </h1>
            <ol class="breadcrumb">
                <li><a href="#"><i class="fa fa-dashboard"></i>首页</a></li>
                <li><a class="active">促销品申请单</a></li>
            </ol>
        </section>


        <!-- Main content -->
        <section class="content">
            <div class="row">
                <div class="col-xs-12">
                    <!-- general form elements disabled -->
                    <div class="box box-primary">
                        <form role="form" id="myForm">
                            <div class="box-body">
                                <input name="form-id" style="display: none;" value="$!{data.id}">
                                <p class="title-pan">基本信息：</p>
                                <table id="form-table" style="width: 100%;">
                                    <tr>
                                        <!--<td style="display: none;">所属单据</td>-->
                                        <!--<td><input style="display: none;" type="text" class="form-control"-->
                                                   <!--name="typeformName" readonly value="$!{data.typeformName}"></td>-->
                                        <td>申请人</td>
                                        <td><input type="text" class="form-control"
                                                   name="form-name" readonly value="$!{data.name}"></td>
                                        <td>职能部门</td>
                                        <td><input type="text" class="form-control"
                                                   name="form-departmentName" readonly value="$!{data.dname}">
                                        </td>
                                        <td>申请用途</td>
                                        <td><input type="text" class="form-control"
                                                   name="form-departmentName" readonly value="$!{data.uname}">
                                        </td>

                                    </tr>
                                    <tr>
                                        <td>申请单号</td>
                                        <td><input type="text" class="form-control"
                                                   name="form-number" readonly value="$!{data.number}"></td>
                                        <td>申请时间</td>
                                        <td><input type="text" class="form-control"
                                                   name="form-appTime" readonly
                                                   value="$!date.format('yyyy-MM-dd HH:mm',$!data.createTime)"></td>
                                        <td>审批人</td>
                                        <td><input type="text" class="form-control"
                                                   name="form-appTime" readonly
                                                   value="$!{data.aname}"></td>


                                    </tr>
                                    <tr>
                                        <td>审批状态</td>
                                        <td><input type="text" class="form-control"
                                                   name="form-status" readonly value="$!{data.statusName}"></td>
                                        <td>发放状态</td>
                                        <td><input type="text" class="form-control"
                                                   name="form-issuingStateName" readonly
                                                   value="$!{data.issuingStateName}"></td>
                                        <td>申请人ORG</td>
                                        <td><input type="text" class="form-control"
                                                   name="form-appTime" readonly
                                                   value="$!{data.org}"></td>

                                    </tr>
                                    <tr>
                                        <td>成本中心</td>
                                        <td><input type="text" class="form-control"
                                                   name="form-costCenter" readonly value="$!{data.costCenter}"></td>
                                        <td>收货信息</td>
                                        <td><input type="text" class="form-control"
                                                   name="form-address" readonly
                                                   value="$!{data.address}"></td>
                                        <td class="showManager">是否有退库</td>
                                        <td class="showManager">
                                            #if($data.isCancel == '0')
                                            #set($isCancelName ='否')
                                            #else
                                            #set($isCancelName ='是')
                                            #end
                                            <input type="text" class="form-control"
                                                   name="form-isCancel" readonly
                                                   value="${isCancelName}">
                                            </td>
                                    </tr>
                                </table>
                                <p class="title-pan">发货渠道：</p>
                                <div id="grantSourceName"></div>
                                <p class="title-pan" >促销品明细：</p>
                                <table id="appitems" style="border: #d2d6de 1px solid;width: 100%;">
                                    <thead style="    background: #F0F0F0;border-bottom: #d2d6de solid 1px;font-weight: bold;">
                                    <td width="20%">物品名称</td>
                                    <td width="20%">物品规格</td>
                                    <td width="5%">申请数量</td>
                                    <td width="5%">单价</td>
<!--                                    <td width="5%" class="showManager">管理员剩余库存</td>-->
<!--                                    <td width="5%">供应商剩余货量</td>-->
                                    <td width="10%">实际发货数量</td>
                                    <td width="15%" class="managerGrantCount showManager">管理员发货数量</td>
                                    <td width="15%" class="disGrantCount">供应商发货数量</td>
                                    </thead>
                                    <tbody>
                                    #foreach( $item in $items )
                                    <tr style='border-bottom: #d2d6de solid 1px;'
                                        data-price='${item.price}'
                                        data-id='${item.id}'
                                        data-appitem='${item.appitem}'
                                        data-num="${item.appCount}"
                                        data-itemname="${item.itemname}"
                                        data-authenticStock="${item.authenticStock}"
                                        data-disStock = "${item.disStock}"
                                    >
                                        <td>${item.itemname}</td>
                                        <td>${item.specifications}</td>
                                        <td>${item.appCount}</td>
                                        <td>${item.price}</td>
<!--                                        <td class="showManager">${item.authenticStock}</td>-->
<!--                                        <td>${item.disStock}</td>-->
<!--                                        #set($fund=${item.authenticStock} + ${item.disStock})-->
                                        <td><input  class='form-control sumGrantCount' value="$!{item.realityGrantCount}" onblur="fun.countBlur(this,1)"  type="number"  min="0"/></td>
                                        <td class="managerGrantCount showManager">
                                            <input class='form-control managerGrantCountInput' value="$!{item.managerGrantCount}" onblur="fun.countBlur(this,2)" type="number" min="0"/>
                                        </td>
                                        <td class="disGrantCount">
                                            <input class='form-control disGrantCountInput' value="$!{item.disGrantCount}" readonly="true"/>
                                        </td>
                                    </tr>
                                    #end
                                    </tbody>
                                </table>
                                <p class="title-pan" >管理员录入备注：</p>
                                <textarea placeholder="录入发货量备注" id="managerSubmitRemarks"
                                          style="width: 50%;margin-top: 15px;">$!{data.managerSubmitRemarks}</textarea>
                                #if(($data.grantSource=='1' || $data.grantSource=='2') && $isManager =='1')
                                <table class="grantTable managerGrantTable" style="width: 100%;">
                                    <p class="title-pan" >管理员发货信息：</p>
                                    <tr>
                                        <td>物流单号(多个逗号请使用分割)</td>
                                        <td style="display: none;">发货备注</td>
                                    </tr>
                                    <tr>
                                        <td><textarea disabled placeholder="物流单号,多个请用逗号分割" id="logisticsOrderInfo"
                                                      style="">$!{data.logisticsOrderInfo}</textarea></td>
                                        <td><textarea disabled placeholder="发货备注" id="grantRemarks"
                                                      style="display: none;">$!{data.grantRemarks}</textarea></td>
                                    </tr>
                                </table>
<!--                                <table class="grantTable" style="width: 100%;display: none">-->
<!--                                    <tr>-->
<!--                                        <td>物流总价</td>-->
<!--                                        <td></td>-->
<!--                                    </tr>-->
<!--                                    <tr>-->
<!--                                        <td><input placeholder="物流总价" disabled value="$!{data.totalLogisticsPrice}" type="number" class="form-control"/></td>-->
<!--                                    </tr>-->
<!--                                </table>-->
                                #end
                                #if($data.grantSource=='0' || $data.grantSource=='2')
                                <table class="grantTable disGrantTable" style="width: 100%;">
                                    <p class="title-pan" >供应商发货信息：</p>
                                    <tr>
                                        <td>物流单号(多个逗号请使用分割)</td>
                                        <td style="display: none;">发货备注</td>
                                    </tr>
                                    <tr>
                                        <td><textarea disabled placeholder="物流单号,多个请用逗号分割" id="disGrantRemarks"
                                                      style="">$!{data.disLogisticsOrderInfo}</textarea></td>
                                        <td style="display:none;"><textarea disabled placeholder="发货备注" id="disLogisticsOrderInfo"
                                                      style="">$!{data.disGrantRemarks}</textarea></td>
                                    </tr>
                                </table>
                                <table class="grantTable" style="width: 100%;">
                                    <tr>
                                        <td>物流总价</td>
                                        <td></td>
                                    </tr>
                                    <tr>
                                        <td><input disabled placeholder="物流总价" value="$!{data.disLogisticsPrice}" type="number" class="form-control"/></td>
                                    </tr>
                                </table>
                                #end

                                #if($isManager =='1')
                                    #if("$!data.managerQualityTime"!="")
                                    <p class="title-pan" >管理员评价信息</p>
                                        <div class="col-xs-12" style="float: none;">
                                            <label>1.整体服务Overall service:</label>
                                            <input id="allEvaluate" showClear="false"
                                                   starCaptions="{1: '不好 poor', 2: '不是很好 below average', 3: '一般 average', 4: '很好above average', 5: '非常好exceptional'}"
                                                   readonly="true" value="$!{data.managerAllEvaluate}"  class="rating" >
                                        </div>
                                        <div class="col-xs-12" style="float: none;">
                                            <label>2.促销品质量Promotional item:</label>
                                            <input id="promotionalItemEvaluate" value="$!{data.managerQualityEvaluate}"  class="rating" >
                                        </div>
                                        <div class="col-xs-12" style="float: none;">
                                            <label>3.物流服务 Logistics service:</label>
                                            <input id="logisticsServiceEvaluate" value="$!{data.managerLogisticsEvaluate}" class="rating" >
                                        </div>
                                        <div class="col-xs-12" style="float: none;">
                                            <label>您的建议或反馈Your suggestions or comments:</label>
                                            <textarea style="width: 100%;" id="managerEvaluateRemarks">$!{data.managerEvaluateRemarks}</textarea>
                                        </div>
                                    #end
                                    <!--申请人评价信息-->
                                    #if("$!data.applyQualityTime" !="")
                                    <p class="title-pan" >申请人评价信息</p>
                                        <div class="col-xs-12" style="float: none;">
                                            <label>1.整体服务Overall service:</label>
                                            <input id="applyEvaluate" value="$!{data.applyAllEvaluate}"  class="rating" >
                                        </div>
                                        <div class="col-xs-12" style="float: none;">
                                            <label>2.促销品质量Promotional item:</label>
                                            <input id="applyPromotionalItemEvaluate" value="$!{data.applyQualityEvaluate}"  class="rating" >
                                        </div>
                                        <div class="col-xs-12" style="float: none;">
                                            <label>3.物流服务 Logistics service:</label>
                                            <input id="applyLogisticsServiceEvaluate" value="$!{data.applyLogisticsEvaluate}"  class="rating" >
                                        </div>
                                        <div class="col-xs-12" style="float: none;">
                                            <label>您的建议或反馈Your suggestions or comments:</label>
                                            <textarea style="width: 100%;" readonly id="applyEvaluateRemarks">$!{data.applyEvaluateRemarks}</textarea>
                                        </div>
                                    #end
                                #end

                            </div>
                        <!--管理员评价信息结束-->

                            <div class="box-footer">
                                <a href="#springUrl('/a/typeAppForm/list')" class="btn btn-default">取消</a>
                            </div>
                        </form>
                        <!-- /.box-body -->
                    </div><!-- /.box -->


                </div><!-- /.col -->
            </div><!-- /.row -->
        </section><!-- /.content -->
    </div><!-- /.content-wrapper -->


    <!-- Add the sidebar's background. This div must be placed
         immediately after the control sidebar -->
    <div class="control-sidebar-bg"></div>
</div><!-- ./wrapper -->

<script src="plugins/jQuery/jQuery-2.1.4.min.js"></script>
<!-- Bootstrap 3.3.5 -->
<script src="bootstrap/js/bootstrap.min.js"></script>
<!-- DataTables -->
<script src="plugins/datatables/jquery.dataTables.min.js"></script>
<script src="plugins/datatables/extensions/i18n/lanauage_ch.js"></script>
<script src="plugins/datatables/dataTables.bootstrap.min.js"></script>
<!-- SlimScroll -->
<script src="plugins/slimScroll/jquery.slimscroll.min.js"></script>
<!-- FastClick -->
<script src="plugins/fastclick/fastclick.min.js"></script>
<!--fileinput js-->
<script src="plugins/bootstrap-fileinput/bootstrap-fileinput.js"></script>
<!-- AdminLTE App -->
<script src="dist/js/app.min.js"></script>
<script src="plugins/bootstrap-maxlength/bootstrap-maxlength.min.js" type="text/javascript"></script>
<script src="plugins/security/sha256.js" type="text/javascript"></script>
<script src="plugins/jquery-validation/js/jquery.validate.min.js"></script>
<script src="js/jquery.form.min.js"></script>
<script type="text/javascript" charset="utf-8" src="plugins/ueditor-min-1.4.3/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="plugins/ueditor-min-1.4.3/ueditor.all.js"></script>
<script type="text/javascript" charset="utf-8" src="plugins/ueditor-min-1.4.3/lang/zh-cn/zh-cn.js"></script>
<script src="common/js/cfapp.js"></script>
<script type="text/javascript" charset="utf-8" src="plugins/jquery-validation/js/localization/messages_zh.js"></script>
<script type="text/javascript"
        src="plugins/bootstrap-star-rating/js/star-rating.min.js"></script>
<!-- END PAGE LEVEL PLUGINS -->
<script>
    var csrfheader = {name: '_csrf_header', value: '${_csrf.headerName}'};
    var csrftoken = {name: '_csrf', value: '${_csrf.token}'};
</script>
<script>
    var evaliuateText = {1: '不好 poor', 2: '不是很好 below average', 3: '一般 average', 4: '很好above average', 5: '非常好exceptional'};

    var starCaptionClasses={1: 'text-success', 2: 'text-success', 3: 'text-success', 4: 'text-success', 5: 'text-success'};

    $('#allEvaluate,#promotionalItemEvaluate,#logisticsServiceEvaluate,#applyEvaluate,#applyPromotionalItemEvaluate,#applyLogisticsServiceEvaluate').rating({
        step: 1,
        size: 'sm',//星星大小可选lg,sm,xl,xs
        stars:5,
        showClear: false,
        starCaptions: evaliuateText,
        starCaptionClasses:starCaptionClasses,
        readonly:true

    });



    var items = eval(${data.items});

    var grantSource = "0"; //默认仅供应商
    $().ready(function () {
        Cfapp.init();
        recdTypeAdd.init();


        var isManager = "$!{isManager}";
        var type = "$!{type}";
        var grantSource = "$!{data.grantSource}";
        if(isManager=='0'){//隐藏不该供应商看的
            $(".showManager").hide();
        }
        if(type!='0'){//业务操作不是录入数量，则隐藏
            $("#appitems input").attr("readonly","readonly");
            /**
             * 只读管理员录入的备注
             */
            $("#managerSubmitRemarks").attr("readonly","readonly");
            var grantSourceName = "";
            switch (grantSource) {
                case "0":
                    grantSourceName= "仅供应商";
                    break;
                case "1":
                    grantSourceName= "仅管理员";
                    break;
                case "2":
                    grantSourceName= "管理员+供应商";
                    break;

            }
            $("#grantSource").hide();
            $("#grantSourceName").html(grantSourceName);
            $("input[name='optionsRadios']").change();

        }


        /**
         * 控制选择发货渠道时，联动效果
         */
        $("input[name='optionsRadios']").change(function(){
            grantSource = $(this).val();
            $(".sumGrantCount").val('');
            $(".managerGrantCountInput").val('');
            $(".disGrantCountInput").val('');
            if(grantSource=='1'){//仅管理员,不需要显示供应商发货数量
                $(".disGrantCount").hide();//隐藏供应商发货量列
                $(".managerGrantCount").show();//显示管理员发货量列
                $(".managerGrantCount input").attr("readonly","readonly");
            }else if(grantSource=='0'){//仅供应商
                $(".managerGrantCount").hide();//隐藏管理员发货量列
                $(".disGrantCount").show();//显示供应商发货列
                $(".disGrantCount input").attr("readonly","readonly");
            }else{//管理员+供应商
                $(".managerGrantCount").show();
                $(".disGrantCount").show();
                $(".managerGrantCount input").removeAttr("readonly");
            }
        })
    });

    var fun = {
        /**
         * 控制发货量失去焦点时，计算各渠道发货量
         * @param obj
         * @param type
         */
        countBlur:function(obj,type){
            $("input").removeClass("borderRed");
            var val = $(obj).val();
            var tdObject =  $(obj).parent();
            if(!StringUtils.isNotBlank(val)){
                return false;
            }
            //行对象
            var trObject = tdObject.parent();
            //管理员库存数量
            var authenticStock =  trObject.attr("data-authenticStock");
            //供应商供应商货量
            var disStock = trObject.attr("data-disStock");
            //计算总库存量
            var sumStock = 0;
            switch (grantSource) {
                case "1": //仅管理员
                    tdObject.siblings("td").find(".managerGrantCountInput").val(val);
                    break;
                case "0": //仅供应商
                    tdObject.siblings("td").find(".disGrantCountInput").val(val);
                    break;
                case "2": //管理员+供应商,计算得出供应商发货量
                    sumStock = parseInt(authenticStock)+parseInt(disStock);
                    if(type==1){//总计失去焦点回调
                        var managerGrantCountValue =  tdObject.siblings("td").find(".managerGrantCountInput").val();//输入的管理员发货量
                        if(StringUtils.isNotBlank(managerGrantCountValue)){
                            var disGrantCount = parseInt(val)-parseInt(managerGrantCountValue);
                            tdObject.siblings("td").find(".disGrantCountInput").val(disGrantCount);
                        }else{
                            return false;
                        }
                    }else{ //管理员数量失去焦点回调
                        //获取总计发放数量是否已经填写，没填写，无法计算，return false
                        var sumGrantCount =  tdObject.siblings("td").find(".sumGrantCount").val();
                        if(StringUtils.isNotBlank(sumGrantCount)){
                            var disGrantCount = parseInt(sumGrantCount)-parseInt(val)
                            tdObject.siblings("td").find(".disGrantCountInput").val(disGrantCount);
                        }else{
                            return false;
                        }
                    }
                    break;
            }
        },
        customAlert:function(content){
            Cfapp.alert({
                message: content,
                btntext: "确定",
                success: function () {
                }
            });
        },addBorderClass:function(obj){
            obj.addClass("borderRed");
        }
    }

    var StringUtils = {
        isNotBlank:function(value){
            if(value && value!=null && value!='' && value!='undefined'){
                return true;
            }
            return false;
        }
    }




    function grantSubmit() {
        var obj = $("#appitems tbody tr");
        var formData = {
            _csrf_header: csrfheader.value,
            _csrf: csrftoken.value,
            id: $("input[name='form-id']").val(),
            managerSubmitRemarks: $("#managerSubmitRemarks").val(),
            grantSource:$("input[name='optionsRadios']").val()
        }

        const ILLEGAL_SUM_GRANT_COUNT_STR = "存在不合法的实际发放数量，请检查数据!";
        const ILLEGAL_MANAGER_GRANT_COUNT_STR = "存在不合法的管理员发放数量，请检查数据!";

        var array = [];

        outer:for (let i = 0; i < obj.length; i++) {
            for (let k = 0; k < items.length; k++) {
                if (items[k].id == $(obj[i]).attr("data-appitem")) {
                    let o =items[k];
                    let tdObj = $(obj[i]);
                    let stock = tdObj.attr("data-authenticStock");//管理员库存
                    let disStock = tdObj.attr("data-disStock"); //供应商库存
                    let sumStock = parseInt(stock)+parseInt(disStock);
                    o.grantCount = tdObj.find(".sumGrantCount").val();//发放数量
                    o.realityGrantCount = tdObj.find(".sumGrantCount").val();//实际发放数量
                    let managerGrantCount=null;
                    let disGrantCount=null;
                    switch (grantSource) {
                        case "1": //仅管理员
                            if(!StringUtils.isNotBlank(o.grantCount) || parseInt(o.grantCount)>parseInt(stock)){
                                fun.customAlert(ILLEGAL_SUM_GRANT_COUNT_STR);
                                fun.addBorderClass(tdObj.find(".sumGrantCount"));
                                return false;
                            }
                            managerGrantCount=tdObj.find(".managerGrantCountInput").val();
                            break;
                        case "0": //仅供应商
                            if(!StringUtils.isNotBlank(o.grantCount) || parseInt(o.grantCount)>parseInt(disStock)){
                                fun.customAlert(ILLEGAL_SUM_GRANT_COUNT_STR);
                                fun.addBorderClass(tdObj.find(".sumGrantCount"));
                                return false;
                            }
                            disGrantCount=tdObj.find(".disGrantCountInput").val();
                            break;
                        case "2": //管理员+供应商,计算得出供应商发货量
                            sumStock = parseInt(stock)+parseInt(disStock);//总库存
                            managerGrantCount=tdObj.find(".managerGrantCountInput").val();//管理员发货量
                            disGrantCount=tdObj.find(".disGrantCountInput").val();//供应商发货量
                            if(!StringUtils.isNotBlank(o.grantCount)){
                                fun.customAlert(ILLEGAL_SUM_GRANT_COUNT_STR);
                                fun.addBorderClass(tdObj.find(".sumGrantCount"));
                                return false;
                            }
                            if(!StringUtils.isNotBlank(managerGrantCount)){
                                fun.customAlert(ILLEGAL_MANAGER_GRANT_COUNT_STR);
                                fun.addBorderClass(tdObj.find(".managerGrantCountInput"));
                                return false;
                            }
                            if(parseInt(o.grantCount) > sumStock){
                                fun.customAlert(ILLEGAL_SUM_GRANT_COUNT_STR);
                                fun.addBorderClass(tdObj.find(".sumGrantCount"));
                                return false;
                            }
                            if(parseInt(managerGrantCount) > parseInt(stock)){
                                fun.customAlert(ILLEGAL_MANAGER_GRANT_COUNT_STR);
                                fun.addBorderClass(tdObj.find(".managerGrantCountInput"));
                                return false;
                            }
                            break;
                    }
                    o.managerGrantCount = managerGrantCount;//管理员发货数量
                    o.disGrantCount = disGrantCount;//供应商发货数量
                    o.grantId = $(obj[i]).attr("data-id");
                    formData["grantitems[" + i + "].id"] = $(obj[i]).attr("data-id");
                    formData["grantitems[" + i + "].price"] = o.price;
                    formData["grantitems[" + i + "].grantCount"] = o.grantCount;
                    formData["grantitems[" + i + "].appitem"] = o.id;
                    formData["grantitems[" + i + "].realityGrantCount"] = o.realityGrantCount;
                    formData["grantitems[" + i + "].managerGrantCount"] = managerGrantCount;
                    formData["grantitems[" + i + "].disGrantCount"] = disGrantCount;
                    array.push(o);
                }
            }
        }
        formData.items = JSON.stringify(array);
        $.ajax({
            type: "post",
            url: "#springUrl('/a/typeAppForm/submitGrantCount')",
            data: formData,
            dataType: "json",
            success: function (data) {
                if (data.errorNo == 0) {
                    Cfapp.alert({
                        message: "发放成功",
                        btntext: "确定",
                        success: function () {
                            location.href = "#springUrl('/a/typeAppForm/list')";
                        }
                    });
                }
            },
            error: function () {
            }
        })
    }


    var recdTypeAdd = function () {
        var initForm = function () {
            var initFormCtrl = function () {
                bindEvent();
            };
            var bindEvent = function () {

                $("#myForm").validate({
                    rules: {},
                    messages: {},
                    submitHandler: function (form) {
                        $("#save").attr("disabled", true);
                        $.getJSON("#springUrl('/a/typeAppForm/formData')", $("#myForm").serialize(), function (returnobj) {
                            $("#save").attr("disabled", false);
                            if (returnobj.errorNo == 2) {  //保存成功
                                Cfapp.confirm({
                                    message: "添加成功",
                                    btnoktext: "继续添加",
                                    btncanceltext: "关闭",
                                    success: function () {
                                        location.href = "#springUrl('/a/typeAppForm/form')";
                                    },
                                    cancel: function () {
                                        location.href = "#springUrl('/a/typeAppForm/list')";
                                    }
                                });
                            } else if (returnobj.errorNo == 0) {  //修改成功
                                Cfapp.alert({
                                    message: "更新成功",
                                    btntext: "确定",
                                    success: function () {
                                        location.href = "#springUrl('/a/typeAppForm/list')";
                                    }
                                });
                            } else {
                                Cfapp.alert({
                                    message: "创建失败",
                                    btntext: "确定",
                                    success: function () {
                                        location.href = "#springUrl('/a/typeAppForm/list')";
                                    }
                                });
                            }
                        });
                    }
                })
            }
            initFormCtrl();
        }
        return {

            //main function to initiate the module
            init: function () {
                initForm();
            }

        };
    }();
</script>
</body>
<!-- END BODY -->
</html>
