<!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;
        }
        .title-child-pan{
            padding-left:10px;border-top: #cccccc dashed 1px;
            margin-top:5px;
            clear: both;
        }
        .title-child-div{
            padding-left: 10px;
        }

        .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 id="selDiv"></div>
<div id="msgDiv"></div>
<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>
        <div id="closeModal" class="modal fade" data-backdrop="static">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                        <h4 class="modal-title">请输入关闭理由</h4>
                    </div>
                    <div class="modal-body">
                        <textarea id="closeReason" style="width: 100%"></textarea>
                    </div>
                    <div class="modal-footer">
                        <a href="javascript:void(0)" data-dismiss="modal" aria-hidden="true" class="btn btn-primary">取消</a>
                        <a href="javascript:void(0)" id="submitRemarks" class="btn btn-primary">确定</a>
                    </div>
                    <!-- dialog buttons -->
                </div>
            </div>
        </div>

        <!-- 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">
                            <input id="id" name="id" value="$!{data.id}" hidden="true"/>
                            <input id="auditId" name="auditId" value="$!{data.auditId}" hidden="true"/>
                            <div class="box-body">
                                <p class="title-pan">申请单号：</p>
                                <div >$!{data.number}</div>
                                <p class="title-pan">申请信息：</p>
                                <table id="form-table" style="width: 100%;">
                                    <tr>
                                        <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-name" readonly value="$!{data.name}"></td>
                                        <td>部门</td>
                                        <td><input type="text" class="form-control"
                                                   name="form-name" readonly value="$!{data.departmentName}"></td>
                                    </tr>
                                    <tr>
                                        <td>E-mail</td>
                                        <td><input type="text" class="form-control"
                                                   name="form-E-mail" readonly
                                                   value="$!{data.email}"></td>

                                        <td>Legal entity</td>
                                        <td><input type="text" class="form-control"
                                                   name="form-name" readonly value="$!{data.legalEntity}"></td>
                                        <td>成本中心</td>
                                        <td><input type="text" class="form-control"
                                                   name="form-name" readonly value="$!{data.costCenter}"></td>
                                    </tr>
                                    <tr>
                                        <td>直属领导姓名</td>
                                        <td><input type="text" class="form-control"
                                                   name="form-E-mail" readonly
                                                   value="$!{data.lineManager}"></td>

                                        <td>直属领导E-mail</td>
                                        <td><input type="text" class="form-control"
                                                   name="form-name" readonly value="$!{data.lineManagerEmail}"></td>
                                    </tr>
                                </table>

                                <!--需求详情-->

                                <p class="title-pan">需求详情：</p>
                                <div>
                                    <p class="title-child-pan">需求类别：</p>
                                    <div class="title-child-div">$!{data.categoryName}</div>

                                    <p class="title-child-pan">子项：</p>
                                    <table id="requireInfo" style="border: #d2d6de 1px solid;width: 100%;margin-left: 10px">

                                        <thead style="    background: #F0F0F0;border-bottom: #d2d6de solid 1px;font-weight: bold;">
                                        <td width="40%">名称</td>
                                        <td width="40%">申请数量</td>
                                        </thead>
                                        <tbody>
                                        #foreach( $item in $details )
                                        <tr style='border-bottom: #d2d6de solid 1px;'
                                        >
                                            <td>${item.materialName}</td>
                                            <td>${item.quantity}</td>
                                        </tr>
                                        #end
                                        </tbody>
                                    </table>

                                    <p class="title-pan">需求说明/用途：</p>
                                    <div >$!{data.requireSpecify}</div>

                                    <p class="title-pan">是否需要制作：</p>
                                    <div >#if($data.isMaterialObject=='1')是#else否#end</div>

                                    <p class="title-pan">期望交付日期：</p>
                                    <div >$!date.format('yyyy-MM-dd',$!data.deliveryDate)</div>

                                    <p class="title-pan">备注：</p>
                                    <div >$!{data.description}</div>
                                </div>
                                <p class="title-pan">申请分配类别：</p>
                                <div class="form-group" id="grantSource">
                                    <div class="radio">
                                        <label>
                                            <input type="radio" name="optionsRadios" id="optionsRadios1" value="0"
                                                   checked
                                            >
                                            仅设计
                                        </label>
                                    </div>
                                    <div class="radio">
                                        <label>
                                            <input type="radio" name="optionsRadios" id="optionsRadios2" value="1"
                                            >
                                            仅制作
                                        </label>
                                    </div>
                                    <div class="radio">
                                        <label>
                                            <input type="radio" name="optionsRadios" id="optionsRadios3" value="2"
                                            >
                                            设计和制作
                                        </label>
                                    </div>
                                </div>

                                <div class="designer" >
                                    <p class="title-pan ">设计人员：</p>
                                    <div class="form-group form-md-line-input " >
                                        <div class="input-group">
                                            <input type="text" name="empId" id="empId"
                                                   value="$!{data.empId}"
                                                   class="form-control" style="display: none">
                                            <input type="text" id="empName"
                                                   name="empName"
                                                   class="form-control" disabled>
                                            <span class="input-group-btn">
                                            <button type="button" id="empSelect"
                                                    class="btn btn-info btn-flat">选择</button>
                                         </span>
                                        </div>
                                    </div>

                                    <p class="title-pan ">预估工作量</p>
                                    <div class="form-group form-md-line-input">
                                        <input type="text"
                                               class="form-control" name="estimateWordload"
                                               id="estimateWordload"
                                               maxlength="50" name="预估工作量"
                                               value="$!{data.estimateWordload}"
                                               required="required"
                                        >
                                    </div>

                                    <p class="title-pan ">工时</p>
                                    <div class="form-group form-md-line-input">
                                        <input type="text"
                                               class="form-control" name="manHour"
                                               id="manHour"
                                               maxlength="50" name="工时"
                                               value="$!{data.manHour}"
                                               required="required"
                                        >
                                    </div>
                                </div>

                                <div class="supplier" style="display: none;">
                                    <p class="title-pan ">制作供应商：</p>
                                    <div class="form-group form-md-line-input ">
                                        <div class="input-group">
                                            <input type="text" name="supplierId" id="supplierId"
                                                   value="$!{data.supplierId}"
                                                   class="form-control" style="display: none">
                                            <input type="text" id="supplierName"
                                                   name="supplierName"
                                                   class="form-control" disabled>
                                            <span class="input-group-btn">
                                            <button type="button" id="supplierSelect"
                                                    class="btn btn-info btn-flat">选择</button>
                                         </span>
                                        </div>
                                    </div>

                                    <p class="title-pan">预估外部费用</p>
                                    <div class="form-group form-md-line-input" >
                                        <input type="text"
                                               class="form-control" name="estimateExternalCosts"
                                               id="estimateExternalCosts"
                                               maxlength="50" name="预估外部费用"
                                               value="$!{data.estimateExternalCosts}"
                                               required="required"
                                        >
                                    </div>
                                </div>


                                <p class="title-pan">设计师联系方式：</p>
                                <div class="form-group form-md-line-input">
                                    <div class="input-group">
                                        <input type="text" name="empId" id="contactEmpId"
                                               value="$!{data.contactEmpId}"
                                               class="form-control" style="display: none">
                                        <input type="text" id="contactEmpName"
                                               name="contactEmpName"
                                               class="form-control" disabled>
                                        <span class="input-group-btn">
                                            <button type="button" id="contactEmpSelect"
                                                    class="btn btn-info btn-flat">选择</button>
                                         </span>
                                    </div>
                                </div>

                                <p class="title-pan">拟交付日期</p>
                                <div class="form-group form-md-line-input">
                                    <input type="text" class="form-control pull-right datepicker" id="intendedDeliveryDate"
                                           required
                                           name="intendedDeliveryDate" placeholder="拟交付日期"
                                           readonly="readonly">
                                </div>

                            </div>
                            <div class="box-footer">
                                #if($data.status=='0')
                                <input class="btn btn-primary" id="agree" value="同意" onclick="submitAgree()" type="button">
                                <input class="btn btn-primary" id="reject" value="关闭" onclick="showCloseModal()" type="button">
                                #end
                            </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 src="plugins/datepicker/bootstrap-datepicker.js"></script>
<script src="plugins/datepicker/locales/bootstrap-datepicker.zh-CN.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>
<!-- END PAGE LEVEL PLUGINS -->
<script>
    var classType = "0"; //默认仅设计
    $().ready(function () {
        Cfapp.init();
        operate();
        empSel();
        contactEmpSel();
        supplierSel();
        $('.datepicker').datepicker({
            show: true,
            format: 'yyyy-mm-dd',
            autoclose: true,
            language: 'zh-CN',
            todayBtn: 'linked',
            clearBtn: 'linked'
        });
        var operateFlag='$!{status}';
        var dataStatus='$!{data.status}';
        if(operateFlag=='0'&&dataStatus=='0'){
            $("#closeModal").modal("show");
        }
    });

    var supplierSel=function () {
        $("#supplierSelect").click(function () {
            Cfapp.f7({
                dataUrl: "#springUrl('/mp/brandApply/comm/supplierData')",
                container:"selDiv",
                checkType: 'single', // 多选为multi
                title: "选择供应商",
                btnoktext: "确定",
                btncanceltext: "取消",
                columns: ['选择', '名称'],
                isSearch: '0',
                searchColumns: ["name"],//搜索的字段名称
                searchColumnsRemarks: ['名称'],//搜索的字段备注
                aoColumns: [
                    {
                        "mData": "id"
                    },
                    {
                        "mData": "name"
                    }
                ],
                aoColumnDefs: [{
                    "aTargets": [0],
                    "mData": "id",
                    "mRender": function (a, b, c, d) {
                        return '<input type="radio" id="' + c.id + '" name="sel" data-value="' + c.id + '" data-name="' + c.name + '">';
                    }
                }],
                success: function () {
                },
                cancel: function () {

                },
                storeFields: 'supplierId', // 储存的字段
                displayFields: 'supplierName'
            })
        });
    }

    var contactEmpSel=function () {

        $("#contactEmpSelect").click(function () {
            Cfapp.f7({
                dataUrl: "#springUrl('/mp/brandApply/comm/empData')",
                container:"selDiv",
                checkType: 'single', // 多选为multi
                title: "选择联系人",
                btnoktext: "确定",
                btncanceltext: "取消",
                columns: ['选择', '姓名', '联系方式','工时单价'],
                isSearch: '0',
                searchColumns: ["name"],//搜索的字段名称
                searchColumnsRemarks: ['姓名'],//搜索的字段备注
                aoColumns: [{
                    "mData": "id"
                }, {
                    "mData": "name"
                }, {
                    "mData": "contactInformation"
                },{
                    "mData":"unitPrice"
                }],
                aoColumnDefs: [{
                    "aTargets": [0],
                    "mData": "id",
                    "mRender": function (a, b, c, d) {
                        return '<input type="radio" id="' + c.id + '" name="sel" data-value="' + c.id + '" data-name="' + c.name + '">';
                    }
                }],
                success: function () {
                },
                cancel: function () {

                },
                storeFields: 'contactEmpId', // 储存的字段
                displayFields: 'contactEmpName'
            })
        });
    }

    var empSel=function () {

        $("#empSelect").click(function () {
            Cfapp.f7({
                dataUrl: "#springUrl('/mp/brandApply/comm/empData')",
                container:"selDiv",
                checkType: 'single', // 多选为multi
                title: "选择设计人员",
                btnoktext: "确定",
                btncanceltext: "取消",
                columns: ['选择', '姓名', '联系方式','工时单价'],
                isSearch: '0',
                searchColumns: ["name"],//搜索的字段名称
                searchColumnsRemarks: ['姓名'],//搜索的字段备注
                aoColumns: [{
                    "mData": "id"
                }, {
                    "mData": "name"
                }, {
                    "mData": "contactInformation"
                },{
                    "mData":"unitPrice"
                }],
                aoColumnDefs: [{
                    "aTargets": [0],
                    "mData": "id",
                    "mRender": function (a, b, c, d) {
                        return '<input type="radio" id="' + c.id + '" name="sel" data-value="' + c.id + '" data-name="' + c.name + '">';
                    }
                }],
                success: function () {
                },
                cancel: function () {

                },
                storeFields: 'empId', // 储存的字段
                displayFields: 'empName'
            })
        });
    }
    var showCloseModal=function () {
        $("#closeModal").modal("show");
    }
    var operate=function () {
        $("input[name='optionsRadios']").change(function(){
            classType=$(this).val();
            if(classType=='0'){
                $(".designer").show();
                $(".supplier").hide();
            }else if(classType=='1'){
                $(".designer").hide();
                $(".supplier").show();
            }else {
                $(".designer").show();
                $(".supplier").show();
            }
        })

        $("#submitRemarks").click(function(){
            $("#closeModal").modal("hide");
            var text = $("#closeReason").val();
            if(!text){
                Cfapp.alert({
                    container:"selDiv",
                    message: "请填写关闭理由",
                    btntext: "确定",
                    success: function () {
                        location.href = location.href;
                    }
                });
            }
            $("#reject").attr("disabled", false);
            var id = $("#id").val();
            $.ajax({
                type: "POST",
                url: "#springUrl('/mp/brandApply/comm/reject')",
                data: {text: text,id:id},
                dataType: "json",
                success: function (data) {
                    if (data.errorNo == 0) {
                        Cfapp.alert({
                            container:"selDiv",
                            message: "操作成功",
                            btntext: "确定",
                            success: function () {
                                location.href = location.href;
                            }
                        });
                    }
                },
                error: function () {
                }
            })
        })
    }
    function submitAgree() {
        var id=$("#id").val();
        var auditId=$("#auditId").val();
        var empId=$("#empId").val();
        var contactEmpId=$("#contactEmpId").val();
        var supplierId=$("#supplierId").val();
        var manHour=$("#manHour").val();
        var intendedDeliveryDate=$("#intendedDeliveryDate").val();
        var estimatedWorkload=$("#estimateWordload").val();
        var estimateExternalCosts=$("#estimateExternalCosts").val();
        if(classType=='0'){
            if(!empId||!manHour){
                Cfapp.alert({
                    container:"msgDiv",
                    message: "请选择设计师或输入工时",
                    btntext: "确定",
                    success: function () {

                    }
                });
                return;
            }
        }else if(classType=='1'){
            if(!supplierId||!estimateExternalCosts){
                Cfapp.alert({
                    container:"msgDiv",
                    message: "请选择供应商或填写预估外部费用",
                    btntext: "确定",
                    success: function () {

                    }
                });
                return;
            }
        }else if(classType=='2'){
            if(!empId||!manHour||!supplierId||!estimateExternalCosts){
                Cfapp.alert({
                    container:"msgDiv",
                    message: "请正确填写信息",
                    btntext: "确定",
                    success: function () {

                    }
                });
                return;
            }
        }
        $("#agree").attr("disabled", false);
        Cfapp.confirm({
            container:"selDiv",
            message: "确定要同意吗",
            btnoktext: "确定",
            btncanceltext: "取消",
            success: function () {

                var warningMsg = Cfapp.warning({
                    container:"msgDiv",
                    content: '正在提交，请稍后!',  //
                    title: "提示"
                });
                $.ajax({
                    type: "POST",
                    url: "#springUrl('/mp/brandApply/comm/agree')",
                    data: {
                        id: id,
                        auditId:auditId,
                        empId:empId,
                        contactEmpId:contactEmpId,
                        supplierId:supplierId,
                        manHour:manHour,
                        intendedDeliveryDate:intendedDeliveryDate,
                        estimatedWorkload:estimatedWorkload,
                        estimateExternalCosts:estimateExternalCosts,
                        distributionClass:classType
                    },
                    dataType: "json",
                    success: function (data) {
                        warningMsg.destory();
                        if (data.errorNo == 0) {
                            Cfapp.alert({
                                container:"msgDiv",
                                message: "操作成功",
                                btntext: "确定",
                                success: function () {
                                    location.href = location.href;
                                }
                            });
                        }else{
                            if(!data.errorMsg){
                                Cfapp.alert({
                                    container:"msgDiv",
                                    message: "申请单状态不可操作",
                                    btntext: "确定",
                                    success: function () {
                                        location.href = location.href;
                                    }
                                });
                            }
                        }
                    },
                    error: function () {
                    }
                })
            },
            cancel: function () {
                $(".modal-backdrop").fadeOut();
            }
        });
    }



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