<!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 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">
                            <input name="id" value="$!{data.id}" 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>
                                    #if($!data.status=='0')待接单#end
                                    #if($!data.status=='1')待确认#end
                                    #if($!data.status=='2')待审批#end
                                    #if($!data.status=='3')审批通过#end
                                    #if($!data.status=='4')关闭#end
                                    #if($!data.status=='5')已完成#end
                                    #if($!data.status=='6')已取消#end
                                </div>

                                #if($!data.distributionClass=='0')
                                <p class="title-pan">拟交付信息：</p>
                                <table id="form-table-other" style="width: 100%;">
                                    <tr>
                                        <td>申请分配类类别</td>
                                        <td>
                                            <input type="text" class="form-control"
                                                   name="form-appTime" readonly
                                                   value="仅设计">
                                        </td>
                                        <td>设计人员</td>
                                        <td>
                                            <input type="text" class="form-control"
                                                   name="form-name" readonly value="$!{data.empName}">
                                        </td>
                                        <td>预估工作量</td>
                                        <td>
                                            <input type="text" class="form-control"
                                                   name="form-name" readonly value="$!{data.estimatedWorkload}">
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>工时</td>
                                        <td><input type="text" class="form-control"
                                                   name="form-E-mail" readonly
                                                   value="$!{data.manHour}"></td>

                                        <td>设计师联系方式</td>
                                        <td><input type="text" class="form-control"
                                                   name="form-name" readonly value="$!{data.contactEmpName}"></td>
                                        <td>拟交付日期</td>
                                        <td><input type="text" class="form-control"
                                                   name="form-name" readonly
                                                   value="$!date.format('yyyy-MM-dd',$!data.intendedDeliveryDate)"></td>
                                    </tr>
                                </table>
                                #end
                                #if($!data.distributionClass=='1')
                                <p class="title-pan">拟交付信息：</p>
                                <table id="form-table-other" style="width: 100%;">
                                    <tr>
                                        <td>申请分配类类别</td>
                                        <td>
                                            <input type="text" class="form-control"
                                                   name="form-appTime" readonly
                                                   value="仅制作">
                                        </td>
                                        <td>制作供应商</td>
                                        <td>
                                            <input type="text" class="form-control"
                                                   name="form-name" readonly value="$!{data.supplierName}">
                                        </td>
                                        <td>预估外部费用</td>
                                        <td>
                                            <input type="text" class="form-control"
                                                   name="form-name" readonly value="$!{data.estimateExternalCosts}">
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>设计师联系方式</td>
                                        <td><input type="text" class="form-control"
                                                   name="form-name" readonly value="$!{data.contactEmpName}"></td>
                                        <td>拟交付日期</td>
                                        <td><input type="text" class="form-control"
                                                   name="form-name" readonly
                                                   value="$!date.format('yyyy-MM-dd',$!data.intendedDeliveryDate)"></td>
                                    </tr>
                                </table>
                                #end

                                #if($!data.distributionClass=='2')
                                <p class="title-pan">拟交付信息：</p>
                                <table id="form-table-other" style="width: 100%;">
                                    <tr>
                                        <td>申请分配类类别</td>
                                        <td>
                                            <input type="text" class="form-control"
                                                   name="form-appTime" readonly
                                                   value="设计和制作">
                                        </td>
                                        <td>设计人员</td>
                                        <td>
                                            <input type="text" class="form-control"
                                                   name="form-name" readonly value="$!{data.empName}">
                                        </td>
                                        <td>预估工作量</td>
                                        <td>
                                            <input type="text" class="form-control"
                                                   name="form-name" readonly value="$!{data.estimatedWorkload}">
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>工时</td>
                                        <td><input type="text" class="form-control"
                                                   name="form-E-mail" readonly
                                                   value="$!{data.manHour}"></td>
                                        <td>制作供应商</td>
                                        <td>
                                            <input type="text" class="form-control"
                                                   name="form-name" readonly value="$!{data.supplierName}">
                                        </td>
                                        <td>预估外部费用</td>
                                        <td>
                                            <input type="text" class="form-control"
                                                   name="form-name" readonly value="$!{data.estimateExternalCosts}">
                                        </td>

                                    </tr>
                                    <tr>
                                        <td>设计师联系方式</td>
                                        <td><input type="text" class="form-control"
                                                   name="form-name" readonly value="$!{data.contactEmpName}"></td>
                                        <td>拟交付日期</td>
                                        <td><input type="text" class="form-control"
                                                   name="form-name" readonly
                                                   value="$!date.format('yyyy-MM-dd',$!data.intendedDeliveryDate)"></td>
                                    </tr>
                                </table>
                                #end

                                #if($!data.status=='4')
                                <p class="title-pan">关闭订单理由：</p>
                                <div>$!{data.closeReason}</div>
                                #end

                                #if($!data.status=='5')
                                <p class="title-pan">交付信息：</p>
                                <table id="form-table-completed" style="width: 100%;">
                                    <tr>
                                        <td>实际交付日期</td>
                                        <td>
                                            <input type="text" class="form-control"
                                                   name="form-name" readonly
                                                   value="$!date.format('yyyy-MM-dd',$!data.actualDeliveryDate)">
                                        </td>
                                        <td>内部费用</td>
                                        <td>
                                            <input type="text" class="form-control"
                                                   name="form-appTime" readonly
                                                   value="$!{actInnerCost}">
                                        </td>
                                        <td>外部费用</td>
                                        <td>
                                            <input type="text" class="form-control"
                                                   name="form-name" readonly value="$!{data.outerCost}">
                                        </td>
                                    </tr>
                                </table>
                                <p class="title-pan">管理员评分：</p>
                                <table id="form-table-evaluate-m" style="width: 100%;">
                                    <tr>
                                        <td>设计质量</td>
                                        <td>
                                            <input type="text" class="form-control"
                                                   name="form-name" readonly value="$!{data.designQuanlityScore}">
                                        </td>
                                        <td>制作质量</td>
                                        <td>
                                            <input type="text" class="form-control"
                                                   name="form-appTime" readonly
                                                   value="$!{data.makeQuanlityScore}">
                                        </td>
                                        <td>意见反馈</td>
                                        <td>
                                            <input type="text" class="form-control"
                                                   name="form-name" readonly value="$!{data.managerFeedback}">
                                        </td>
                                    </tr>
                                </table>
                                #if($!data.isScore=='1')
                                <p class="title-pan">申请人评分：</p>
                                <table id="form-table-evaluate-a" style="width: 100%;">
                                    <tr>
                                        <td>服务评分</td>
                                        <td>
                                            <input type="text" class="form-control"
                                                   name="form-name" readonly value="$!{data.serviceScore}">
                                        </td>
                                        <td>意见反馈</td>
                                        <td>
                                            <input type="text" class="form-control"
                                                   name="form-name" readonly value="$!{data.feedback}">
                                        </td>
                                    </tr>
                                </table>
                                #end
                                #end
                                #if($!data.productName)
                                <p class="title-pan">成品详情：</p>
                                <div>
                                    <p class="title-child-pan">成品名称：</p>
                                    <div class="title-child-div">$!{data.productName}</div>
                                    <p class="title-child-pan">部门盘链接：</p>
                                    <div class="title-child-div">$!{data.filePrefix}</div>
                                    <p class="title-child-pan">成品文件：</p>
                                    <table id="productInfo"
                                           style="border: #d2d6de 1px solid;width: 100%;margin-left: 10px">
                                        <thead style="    background: #F0F0F0;border-bottom: #d2d6de solid 1px;font-weight: bold;">
                                        <td width="60%">名称</td>
                                        <td width="20%">类型</td>
                                        <td width="20%">操作</td>
                                        </thead>
                                        <tbody>
                                        #foreach( $item in $brandApplyProducts )
                                        <tr style='border-bottom: #d2d6de solid 1px;'>
                                            <td>${item.name}<img src="${item.fileUrl}" style="display: none;"></td>
                                            <td>${item.format}</td>
                                            <td><a href="javascript:void(0);" data-src="${item.fileUrl}"
                                                   data-id="${item.id}"
                                                   onclick="downloadFile(this)">下载</a></td>
                                        </tr>
                                        #end
                                        </tbody>
                                    </table>
                                    <p class="title-pan">成品类型：</p>
                                    <div class="title-child-div">$!{data.productFormat}</div>
                                    <p class="title-pan">成品标签：</p>
                                    <div class="title-child-div">$!{data.productLabel}</div>
                                </div>
                                #end
                            </div>
                            <!--<div class="box-footer">-->
                            <!--#if($shiro.hasPermission("qy:brandApply:edit"))-->
                            <!--<input class="btn btn-primary" id="save" value="保存" type="submit">-->
                            <!--#end-->
                            <!--<a href="#springUrl('/a/brandApply/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>
<!-- END PAGE LEVEL PLUGINS -->
<script>
    $().ready(function () {
        Cfapp.init();
        recdTypeAdd.init();
    });


    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/brandApply/formData')", $("#myForm").serialize(), function (returnobj) {
                            $("#save").attr("disabled", false);
                            if (returnobj.errorNo == 2) {  //保存成功
                                Cfapp.confirm({
                                    message: "添加成功",
                                    btnoktext: "继续添加",
                                    btncanceltext: "关闭",
                                    success: function () {
                                        location.href = "#springUrl('/a/brandApply/form')";
                                    },
                                    cancel: function () {
                                        location.href = "#springUrl('/a/brandApply/list')";
                                    }
                                });
                            } else if (returnobj.errorNo == 0) {  //修改成功
                                Cfapp.alert({
                                    message: "更新成功",
                                    btntext: "确定",
                                    success: function () {
                                        location.href = "#springUrl('/a/brandApply/list')";
                                    }
                                });
                            } else {
                                Cfapp.alert({
                                    message: "创建失败",
                                    btntext: "确定",
                                    success: function () {
                                        location.href = "#springUrl('/a/brandApply/list')";
                                    }
                                });
                            }
                        });
                    }
                })
            }
            initFormCtrl();
        }
        return {
            //main function to initiate the module
            init: function () {
                initForm();
            }
        };
    }();

    downloadFile = function (fileUrl) {
        let filePath = $(fileUrl).data("src");
        // let ext = filePath.substr(filePath.lastIndexOf(".") + 1);
        // if (!isAssetTypeAnImage(ext)) {
        //     window.open(filePath);
        // } else {
        //     let image = new Image();
        //     // 解决跨域 Canvas 污染问题
        //     image.setAttribute("crossOrigin", "anonymous");
        //     image.onload = function () {
        //         let canvas = document.createElement("canvas");
        //         canvas.width = image.width;
        //         canvas.height = image.height;
        //         let context = canvas.getContext("2d");
        //         context.drawImage(image, 0, 0, image.width, image.height);
        //         let url = canvas.toDataURL("image/png"); //得到图片的base64编码数据
        //         let a = document.createElement("a"); // 生成一个a元素
        //         let event = new MouseEvent("click"); // 创建一个单击事件
        //         a.download = "photo"; // 设置图片名称
        //         a.href = url; // 将生成的URL设置为a.href属性
        //         a.dispatchEvent(event); // 触发a的单击事件
        //     };
        //     image.src = filePath;
        // }
        // window.open(fileId)

        let fileId = $(fileUrl).data("id");
        location.href = "#springUrl('/a/brandApplyProduct/fileDownload')?id=" + fileId;
    }

    /**
     * 判断是否为图片类型
     * @param ext
     * @returns {boolean}
     */
    isAssetTypeAnImage = function (ext) {
        return [
            'png', 'jpg', 'jpeg', 'bmp', 'gif', 'webp', 'psd', 'svg', 'tiff', 'pdf'].indexOf(ext.toLowerCase()) !== -1;
    }

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