<!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">
    <!-- 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%;
        }
    </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>
                                    </tr>
                                </table>
                                <p class="title-pan">发货渠道：</p>
                                <div id="grantSourceName">
                                    #if($data.grantSource =='0')
                                    仅供应商
                                    #end
                                    #if($data.grantSource =='1')
                                    仅管理员
                                    #end
                                    #if($data.grantSource =='2')
                                    管理员+供应商
                                    #end
                                </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" style="display: none;">管理员发货数量</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 readonly  class='form-control sumGrantCount' value="$!{item.realityGrantCount}" onblur="fun.countBlur(this,1)"  type="number"  min="0"/></td>
                                        <td style="display: none;" class="managerGrantCount">
                                            <input readonly class='form-control managerGrantCountInput' value="$!{item.managerGrantCount}" onblur="fun.countBlur(this,2)" type="number" min="0"/>
                                        </td>
                                        <td class="disGrantCount">
                                            <input rel="" class='form-control disGrantCountInput' value="$!{item.disGrantCount}" readonly="true"/>
                                        </td>
                                    </tr>
                                    #end
                                    </tbody>
                                </table>
                                <p class="title-pan" >管理员录入备注：</p>
                                <textarea placeholder="录入发货量备注" readonly id="managerSubmitRemarks"
                                          style="width: 50%;margin-top: 15px;">$!{data.managerSubmitRemarks}</textarea>
                                <table class="grantTable disGrantTable" style="width: 100%;">
                                    <p class="title-pan" >供应商发货信息：</p>
                                    <tr>
                                        <td>物流单号(多个逗号请使用分割)</td>
                                        <td style="display: none;">发货备注</td>
                                    </tr>
                                    <tr>
                                        <td><textarea placeholder="物流单号,多个请用逗号分割" id="disLogisticsOrderInfo"
                                                      style="">$!{data.disLogisticsOrderInfo}</textarea></td>
                                        <td style="display: none;"><textarea placeholder="发货备注" id="disGrantRemarks"
                                                      style="">$!{data.disGrantRemarks}</textarea></td>
                                    </tr>
                                </table>
                                <table class="grantTable" style="width: 100%;">
                                    <tr>
                                        <td>物流总价</td>
                                        <td></td>
                                    </tr>
                                    <tr>
                                        <td><input placeholder="物流总价" id="disLogisticsPrice" value="$!{data.disLogisticsPrice}" type="number" class="form-control"/></td>
                                    </tr>
                                </table>
                            </div>
                            <div class="box-footer">
                                #if($type == 0)
                                <a href="javascript:void(0)"  onclick="grantSubmit()" class="btn btn-primary">提交</a>
                                #end
                                #if($type == 1 || $type == 2)
                                <a href="javascript:void(0)" onclick="grantConfirmSubmit()" class="btn btn-primary">确认发货</a>
                                #end
                                <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>
<!-- END PAGE LEVEL PLUGINS -->
<script>
    var csrfheader = {name: '_csrf_header', value: '${_csrf.headerName}'};
    var csrftoken = {name: '_csrf', value: '${_csrf.token}'};
</script>
<script>
    $().ready(function () {
        Cfapp.init();
        recdTypeAdd.init();
    });
    var StringUtils = {
        isNotBlank:function(value){
            if(value && value!=null && value!='' && value!='undefined'){
                return true;
            }
            return false;
        }
    }
    function grantConfirmSubmit(){
        var disLogisticsPrice = $("#disLogisticsPrice").val();

        if(!StringUtils.isNotBlank(disLogisticsPrice)){
            Cfapp.alert({
                message: "请输入物流金额",
                btntext: "确定",
                success: function () {
                }
            });
            return false;
        }
        var disLogisticsOrderInfo = $("#disLogisticsOrderInfo").val();
        if(!StringUtils.isNotBlank(disLogisticsOrderInfo)){
            Cfapp.alert({
                message: "请输入物流单号信息",
                btntext: "确定",
                success: function () {
                }
            });
            return false;
        }
        var formData = {
            _csrf_header: csrfheader.value,
            _csrf: csrftoken.value,
            id: $("input[name='form-id']").val(),
            disGrantRemarks:$("#disGrantRemarks").val(),
            disLogisticsOrderInfo:disLogisticsOrderInfo,
            disLogisticsPrice:disLogisticsPrice,
            source:2
        }
        $.ajax({
            type: "post",
            url: "#springUrl('/a/typeAppForm/grantSubmit')",
            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 () {
            }
        })
    }



</script>
</body>
<!-- END BODY -->
</html>
