<!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">
    <!-- Morris chart -->
    <link rel="stylesheet" href="plugins/morris/morris.css">
    <!-- jvectormap -->
    <link rel="stylesheet" href="plugins/jvectormap/jquery-jvectormap-1.2.2.css">
    <!-- Date Picker -->
    <link rel="stylesheet" href="plugins/datepicker/datepicker3.css">
    <!-- Daterange picker -->
    <link rel="stylesheet" href="plugins/daterangepicker/daterangepicker-bs3.css">
    <link rel="stylesheet"
          href="plugins\bootstrap-fileinput\fileinput.min.css">
    <!-- bootstrap wysihtml5 - text editor -->
    <link rel="stylesheet" href="plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.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]-->
</head>
<body class="hold-transition skin-blue sidebar-mini">


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

        <!-- 当前选中框id -->
        <input type="hidden" id="orderId">

        <div class="modal fade" id="remindExampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <h4 class="modal-title" id="remindExampleModalLabel" style="font-weight: 700;">设置订单提醒</h4>
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                            <span aria-hidden="true">&times;</span>
                        </button>
                    </div>
                    <div class="modal-body">
                        <form style="height: 80px;">
                            <div class="col-xs-6">
                                <select  id="remind" name="remind" class="form-control required">
                                    <option value="0">请选择提醒周期</option>
                                    <option value="1">7天前</option>
                                    <option value="2">当日</option>
                                    <option value="3">7天后</option>
                                    <option value="0">关闭提醒</option>
                                </select>
                            </div>
                        </form>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
                        <button type="button" class="btn btn-primary" onclick="submitRemind()">提交</button>
                    </div>
                </div>
            </div>
        </div>

        <div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <h4 class="modal-title" id="exampleModalLabel" style="font-weight: 700;">订单关闭原由</h4>
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                            <span aria-hidden="true">&times;</span>
                        </button>
                    </div>
                    <div class="modal-body">
                        <form>
                            <div class="form-group">
                                <label for="message-text" class="col-form-label">请输入关闭原由:</label>
                                <textarea class="form-control" rows="3" id="js-textarea"></textarea>
                            </div>
                        </form>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
                        <button type="button" class="btn btn-primary" onclick="review()">提交</button>
                    </div>
                </div>
            </div>
        </div>

        <div id="importExcelDiv"></div>

        <section class="content-header">
            <h1>
                需求清单管理
                <small>需求清单管理</small>
            </h1>
            <ol class="breadcrumb">
                <li><a><i class="fa fa-dashboard"></i>首页</a></li>
                <li><a class="active">需求清单管理列表</a></li>
            </ol>
        </section>

        <!-- 设置开发票推送的邮箱 -->
        <div id="peakButtom" class="modal fade" >
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title">请填写邮箱</h4>
                    </div>

                    <!-- dialog body -->
                    <div class="modal-body">
                        <input type="text" class="form-control" id="email" name="email" ></input>
                    </div>
                    <div style="text-align: center;padding-bottom: 20px;">
                        <button style="width: 100px;" type="button" class="btn btn-primary" onclick="exportInvoice()">确定</button>
                        <button style="width: 100px;" type="button"  class="btn btn-default" data-dismiss="modal" aria-label="Close">取消</button>
                    </div>
                    <!-- dialog buttons -->
                </div>
            </div>
        </div>


        <!-- Main content -->
        <section class="content">
            <div class="row">
                <div class="col-xs-12">
                    <div class="box">
                        <div class="box-header">
                            <form id="seachTableForm" action="#springUrl('/a/order/exportExcel')" method="get">
                                <div class="col-xs-2">
                                    <input type="text" class="form-control"
                                           name="number" value="" placeholder="订单编号">
                                </div>
                                <div class="col-xs-2">
                                    <input type="text" class="form-control"
                                           name="consultCode" placeholder="咨询单编码">
                                </div>
                                <div class="col-xs-2">
                                    <input type="text" class="form-control"
                                           name="productNameTmp" placeholder="产品名称">
                                </div>
                                <div class="col-xs-2">
                                    <input type="text" class="form-control"
                                           name="courierNumber" placeholder="顺丰运单号">
                                </div>
                                <div class="col-xs-2">
                                    <input type="text" class="form-control"
                                           name="startOrderAmount" placeholder="订单金额开始区间">
                                </div>
                                <div class="col-xs-2">
                                    <input type="text" class="form-control"
                                           name="endOrderAmount" placeholder="订单金额结束区间">
                                </div>
                                <div class="col-xs-2">
                                    <input type="text" class="form-control"
                                           name="startPayAmount" placeholder="付款金额开始区间">
                                </div>
                                <div class="col-xs-2">
                                    <input type="text" class="form-control"
                                           name="endPayAmount" placeholder="付款金额结束区间">
                                </div>
                                <div class="col-xs-2">
                                    <select  id="status" name="status" class="form-control required">
                                        <option value="">请选择订单状态</option>
                                        <option value="0">待确认</option>
                                        <option value="1">待付款</option>
                                        <option value="2">待发货</option>
                                        <option value="3">待收货</option>
                                        <option value="4">已完成</option>
                                        <option value="5">已取消</option>
                                    </select>
                                </div>

                                <div class="col-xs-2">
                                    <select  id="isBill" name="isBill" class="form-control required">
                                        <option value="">请选择是否开票</option>
                                        <option value="0">是</option>
                                        <option value="1">否</option>
                                    </select>
                                </div>

                                <div class="col-xs-2">
                                    <div class="input-group date">
                                        <div class="input-group-addon">
                                            <i class="fa fa-calendar"></i>
                                        </div>
                                        <input type="text" class="form-control pull-right datepicker"
                                               name="orderStartTime" placeholder="订单开始时间"
                                               readonly="readonly">
                                    </div>
                                </div>

                                <div class="col-xs-2">
                                    <div class="input-group date">
                                        <div class="input-group-addon">
                                            <i class="fa fa-calendar"></i>
                                        </div>
                                        <input type="text"
                                               class="form-control pull-right  datepicker"
                                               name="orderEndTime" placeholder="订单结束时间"
                                               readonly="readonly">
                                    </div>
                                </div>

                                <button type="button" class="search btn btn-primary">搜索</button>
                                <button type="button" class="btn btn-info" onclick="clearSearch()">重置</button>
                                #if($shiro.hasPermission("qy:order:edit"))
                                <!--                                    <a href="#springUrl('/a/order/form')" class="btn btn-primary">新增</a>-->
                                <button type="submit" class="btn btn-primary">导出</button>
                                <button type="button" class="abc btn btn-primary">开发票</button>
                                #end
                                <!--                                        <a onclick="importExcel();" class="btn btn-primary">导入</a>-->


                            </form>
                        </div><!-- /.box-header -->
                        <div class="box-body">
                            <table id="table" class="table table-bordered table-striped">
                                <thead>
                                <tr>
                                    <!--<th><input hidden class='checkQyCode1' type="checkBox"></th>-->
                                    <th><input class='checkQyCode' type="checkBox"></th>
                                    <th>订单编码</th>
                                    <th>咨询单编码</th>
                                    <th>产品名称</th>
                                    <th>订单金额</th>
                                    <th>付款金额</th>
                                    <th>昵称</th>
                                    <th>openid</th>
                                    <th>顺丰运单号</th>
                                    <th>订单状态</th>
                                    <th>支付交易号</th>
                                    <th>是否开票</th>
                                    <th>创建时间</th>
                                    <th>确认时间</th>
                                    <th>付款时间</th>
                                    <th>发货时间</th>
                                    <th>签收时间</th>
                                    <th>取消时间</th>
                                    <th>操作</th>
                                </tr>
                                </thead>
                                <tbody id="tablebody">
                                </tbody>

                            </table>
                        </div><!-- /.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 -->
<!-- jQuery 2.1.4 -->
<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>
<script src="plugins/datepicker/bootstrap-datepicker.js"></script>
<script src="plugins/datepicker/locales/bootstrap-datepicker.zh-CN.js"></script>
<!-- FastClick -->
<script src="plugins/fastclick/fastclick.min.js"></script>
<!--fileinput js-->
<script src="plugins\bootstrap-fileinput\fileinput.js"></script>
<script src="plugins/bootstrap-fileinput/zh.js"></script>
<script src="plugins/bootstrap-fileinput/zh2.js"></script>
<!-- AdminLTE App -->
<script src="dist/js/app.min.js"></script>
<script type="text/javascript"
        src="plugins/jquery-validation/js/jquery.validate.min.js"></script>
<!-- AdminLTE for demo purposes -->
<script>
    var csrfheader = {name: '_csrf_header', value: '${_csrf.headerName}'};
    var csrftoken = {name: '_csrf', value: '${_csrf.token}'};
</script>
<script src="common/js/cfapp.js"></script>
<script>
    var csrf = '${_csrf.token}';
    var csrf_header = '${_csrf.headerName}';

    //咨询单列表通过订单编码跳转单条订单信息
    var orderCode = `${orderCode}`;
    if (orderCode != null && orderCode != '' && orderCode != "undefined") {
        $('input[name="number"]').val(`${orderCode}`);
    }

    var isCheckedQyCode = new Array();
    var str = 0; //记录当前页面选中个数
    var len = 0; //记录当前显示列表总记录数
    function formatDates(now) {
        var now = new Date(now);
        var year = now.getFullYear();
        var month = now.getMonth() + 1;
        var date = now.getDate();
        var hour = now.getHours();
        var minute = now.getMinutes();
        var second = now.getSeconds();
        return year + "-" + (month <= 9 ? "0" + month : month) + "-" + (date <= 9 ? "0" + date : date) + "   " + (hour <= 9 ? "0" + hour : hour) + ":"
            + (minute <= 9 ? "0" + minute : minute) + ":" + (second <= 9 ? "0" + second : second);
    }

    function seachTable() {
        var sSource = "#springUrl('/a/order/listData')";
        var aoData = {
            iDisplayStart: 1,
            iDosplayLength: 10
        };

        var retrieveData = function (sSource, aoData, fnCallback) {
            $("#seachTableForm input,select").each(function () {
                var params = {
                    name: $(this).attr("name"),
                    value: $(this).val()
                };
                aoData.push(params);
            });

            $.ajax({
                "type": "GET",
                "url": sSource,
                "dataType": "json",
                "data": aoData, //以json格式传递
                "success": fnCallback
            });
        };

        $('#table').DataTable({
            "lengthChange": false,
            "searching": false,
            "ordering": false,
            "bFiltered": false,
            "bStateSave": true, // save datatable state(pagination, sort, etc) in cookie.
            "bProcessing": true,
            "bServerSide": true,
            "sAjaxSource": sSource,
            "fnServerData": retrieveData,
            "pagingType": "full_numbers",
            "aoColumns": [
                {
                    "mData": "id"
                },
                {
                    "mData": "number"
                },
                {
                    "mData": "consultCode"
                },
                {
                    "mData": "productName"
                },
                {
                    "mData": "orderAmount"
                }
                ,
                {
                    "mData": "totalAmount"
                }
                ,
                {
                    "mData": "nickName"
                }
                ,
                {
                    "mData": "openid"
                }
                ,
                {
                    "mData": "courierNumber"
                }
                ,
                {
                    "mData": "status"
                }
                ,
                {
                    "mData": "tradeNo"
                }

                ,
                {
                    "mData": "confirm"
                }
                ,
                {
                    "mData": "createTime"
                }
                ,
                {
                    "mData": "orderTime"
                }
                ,
                {
                    "mData": "payTime"
                }
                ,
                {
                    "mData": "sendExpressDateStr"
                }
                ,
                {
                    "mData": "acceptExpressDateStr"
                }
                ,
                {
                    "mData": "cancelTime"
                }
                ,
                {
                    "mData": "id"
                }

            ],
            "aoColumnDefs": [
                { // set default column settings
                    //'visible': false,
                    'aTargets': [0],
                    "mData":"id",
                    "mRender": function(a, b, c, d){
                        if (c.status == 4){
                            if(isCheckedQyCode.indexOf(a+"")!=-1){
                                return '<input class="isExport" checked value="'+a+'"  type="checkBox">';
                            }else{
                                return '<input class="isExport" value="'+a+'"  type="checkBox">';
                            }
                        }else{
                            return "";
                        }

                    }

                },
                /*{
                 'targets': [1],
                 "mData":"id",
                 "mRender": function(a, b, c, d){
                 if(isCheckedQyCode.indexOf(a+"")!=-1){
                 return '<input class="isExport" checked value="'+a+'"  type="checkBox">';
                 }else{
                 return '<input class="isExport" value="'+a+'"  type="checkBox">';
                 }
                 }
                 },*/
                {
                    "aTargets": [1],
                    "mData": "number",
                    "mRender": function (a, b, c, d) {
                        return a;
                    }
                },
                {
                    "aTargets": [2],
                    "mData": "consultCode",
                    "mRender": function (a, b, c, d) {
                        return a;
                    }
                },

                {
                    "aTargets": [3],
                    "mData": "productName",
                    "mRender": function (a, b, c, d) {
                        return a;
                    }
                }
                ,
                {
                    "aTargets": [4],
                    "mData": "orderAmount",
                    "mRender": function (a, b, c, d) {
                        if (a != null) {
                            return parseInt(a).toFixed(2);
                        }
                        return '';
                    }
                }
                ,
                {
                    "aTargets": [5],
                    "mData": "totalAmount",
                    "mRender": function (a, b, c, d) {
                        if (a != null) {
                            return parseInt(a).toFixed(2);
                        }
                        return '';
                    }
                }
                ,
                {
                    "aTargets": [6],
                    "mData": "nickName",
                    "mRender": function (a, b, c, d) {
                        if (a) {
                            return a;
                        } else {
                            return null;
                        }
                    }
                }
                ,
                {
                    "aTargets": [7],
                    "mData": "openid",
                    "mRender": function (a, b, c, d) {
                        return a;
                    }
                }
                ,
                {
                    "aTargets": [8],
                    "mData": "courierNumber",
                    "mRender": function (a, b, c, d) {
                        return a;
                    }
                }
                ,
                {
                    "aTargets": [9],
                    "mData": "status",
                    "mRender": function (a, b, c, d) {
                        if (a == '0') {
                            return "待确认";
                        } else if (a == '1') {
                            return "待付款";
                        } else if (a == '2') {
                            return "待发货";
                        } else if (a == '3') {
                            return "待收货";
                        } else if (a == '4') {
                            return "已完成";
                        } else if (a == '5') {
                            return "已取消";
                        }
                    }
                },
                {
                    "aTargets": [10],
                    "mData": "tradeNo",
                    "mRender": function (a, b, c, d) {
                        return a;
                    }
                }
                ,
                {
                    "aTargets": [11],
                    "mData": "confirm",
                    "mRender": function (a, b, c, d) {
                        return a == null  ? '否':'是';
                    }
                }
                ,
                {
                    "aTargets": [12],
                    "mData": "createTime",
                    "mRender": function (a, b, c, d) {
                        let time = formatDates(a);
                        if (time.indexOf("1970") != -1) {
                            return '';
                        }
                        return formatDates(a);
                    }
                }
                ,
                {
                    "aTargets": [13],
                    "mData": "orderTime",
                    "mRender": function (a, b, c, d) {
                        let time = formatDates(a);
                        if (time.indexOf("1970") != -1) {
                            return '';
                        }
                        return formatDates(a);
                    }
                }
                ,
                {
                    "aTargets": [14],
                    "mData": "payTime",
                    "mRender": function (a, b, c, d) {
                        let time = formatDates(a);
                        if (time.indexOf("1970") != -1) {
                            return '';
                        }
                        return formatDates(a);
                    }
                }
                ,
                {
                    "aTargets": [15],
                    "mData": "sendExpressDateStr",
                    "mRender": function (a, b, c, d) {
                        return a;
                    }
                }
                ,
                {
                    "aTargets": [16],
                    "mData": "acceptExpressDateStr",
                    "mRender": function (a, b, c, d) {
                        return a;
                    }
                }
                ,
                {
                    "aTargets": [17],
                    "mData": "cancelTime",
                    "mRender": function (a, b, c, d) {
                        let time = formatDates(a);
                        if (time.indexOf("1970") != -1) {
                            return '';
                        }
                        return formatDates(a);
                    }
                }
                ,
                {
                    "aTargets": [18],
                    "mData": "id",
                    "mRender": function (a, b, c, d) {
                        var html = '#if($shiro.hasPermission("qy:order:edit"))';
                        html += '<div class="btn-group" style="min-width: 100px;">\n' +
                            '<button type="button" class="btn btn-success btn-flat">操作</button>\n' +
                            '<button type="button" class="btn btn-success btn-flat dropdown-toggle" data-toggle="dropdown">\n' +
                            '  <span class="caret"></span>\n' +
                            '  <span class="sr-only">Toggle Dropdown</span>\n' +
                            '</button>\n' +
                            '<ul class="dropdown-menu" role="menu" style="min-width: 100px;">\n';
                        html += '<li><a href="#springUrl("/a/order/findorderDetail?id=' + a + '&isDetail=y")">查看清单明细</a></li>';
                        if (c.status == '0') {
                            html += '<li><a href="#springUrl("/a/order/form?pageType=Edit&id=' + a + '")">添加商品</a></li>';
                        }
                        if (c.status != '0') {
                            html += '<li><a href="#springUrl("/a/order/form?pageType=View&id=' + a + '")">查看详情</a></li>';
                        }
                        if (c.status == '1') {
                            html += '<li><a onclick="updateStatusSuccess(' + a + ')">订单付款</a></li>';
                        }
                        if (c.status != '4' && c.status != '5') {
                            html += '<li><a onclick="showModal(' + a + ')">订单关闭</a></li>';
                        }
                        if (c.status == '4') {
                            //需求订单已完成设置提醒
                            html += '<li><a onclick="showRemindModal(' + a + ')">订单提醒</a></li>';
                        }
//                        if (c.status == '2') {//待发货才可以出库操作
//                            html  += '<li><a href="#springUrl("/a/order/sendOut?id=' + a + '")">订单出库</a></li>';
//                        }
                        html += '</ul>';
                        html += '#end';
                        return html;
                    }
                }

            ]
        });
    }
    //123456789
    function changeAllChecked(){
        var flag = true;
        $('#table tbody tr').each(function(){
            if(!$(this).find('td').find('.isExport').is(':checked')){
                //没有选中
                flag = false;
                return false;
            }
        })
        if(flag){
            $('.checkQyCode').prop("checked",true);
        }else{
            $('.checkQyCode').prop("checked",false);
        }
    };

    jQuery(document).ready(function () {

        $('.col-xs-12').on('click', '.paginate_button', function() {
            //console.log('aaaaaaaaaaaaaa');
            setTimeout(function () {
                var flag = true;
                $('#table tbody tr').each(function(){
                    if(!$(this).find('td').find('.isExport').is(':checked')){
                        //没有选中
                        flag = false;
                        return false;
                    }
                })
                if(flag){
                    $('.checkQyCode').prop("checked",true);
                }else{
                    $('.checkQyCode').prop("checked",false);
                }
            },400)

            len = 0;
            str = 0;
        });

        seachTable();
        $('.datepicker').datepicker({
            show: true,
            format: 'yyyy-mm-dd',
            autoclose: true,
            language: 'zh-CN',
            todayBtn: 'linked',
            clearBtn: 'linked'

        });
        $('.search').click(function () {
            $("#table").dataTable().fnClearTable();
        });

        //显示填写邮箱弹框
        $('.abc').click(function(){
            $("#peakButtom").modal('show');
        })


        changeAllChecked();
        $('.checkQyCode').prop("checked",false);
        //单选
        $('#table tbody').on("change","tr td .isExport",function(){
            if($(this).is(':checked')){
                changeAllChecked();
                if(isCheckedQyCode.length == 10){
                    Cfapp.alert({
                        message: "最多只能选中10条",
                        btntext: "确定",
                        success: function () {
                        }
                    })
                    $('.checkQyCode').prop("checked",false);
                    $(this).prop('checked',false);
                }else{
                    isCheckedQyCode.push($(this).val());
                }
            }else{
                isCheckedQyCode.splice($.inArray($(this).val(),isCheckedQyCode),1);
                changeAllChecked();
            }
        })

        //全选
        $('.checkQyCode').change(function(){
            if($(this).is(':checked')){
                $('#table tbody tr').each(function(){
                    if($(this).find("td").find(".isExport").is(':checked')){
                        str++;
                    }
                    len++;
                })
                //全部选中 buhanhan

                $('#table tbody tr').each(function(){

                    if(isCheckedQyCode.length == 10){
                        Cfapp.alert({
                            message: "最多只能选中10条",
                            btntext: "确定",
                            success: function () {
                                if(str != len){
                                    str = 0; len = 0;
                                    $('.checkQyCode').prop("checked",false);
                                }else{
                                    str = 0; len = 0;
                                    $('.checkQyCode').prop("checked",true);
                                }
                            }
                        })

                        return false;
                    }else{
                        if(!$(this).find("td").find('.isExport').is(':checked')){
                            //全选是   若没有选中则添加到数组
                            $(this).find("td").find('.isExport').prop('checked',true);
                            isCheckedQyCode.push($(this).find("td").find(".isExport").val());
                            str ++;
                        }

                    }
                    //alert(isCheckedQyCode)

                })
            }else{
                $('#table tbody tr').each(function(){
                    $(this).find("td").find('.isExport').prop('checked',false);
                    if($.inArray($(this).find("td").find(".isExport").val(),isCheckedQyCode) != -1){
                        isCheckedQyCode.splice($.inArray($(this).find("td").find(".isExport").val(),isCheckedQyCode),1)
                    }
                })
                str = 0; len = 0;
            }
        })

    });

    Cfapp.init();
    function showRemindModal(id) {
        $("#orderId").val(id);
        $('#remindExampleModal').modal('show');
    }

    function submitRemind() {
        let option = $('#remind option:selected') .val();
        if (option == null || option == '') {
            Cfapp.alert({
                message: "请选择对应周期",
                btntext: "确定",
                success: function () {}
            });
            return;
        }
        var url = "#springUrl('/a/order/setOrderRemind')";
        $.ajax({
            url: url,
            type: "GET",
            data: {id: $("#orderId").val(),
                    option: option},
            success: function (rsp) {
                $('#remindExampleModal').modal('hide');
                if (rsp.errorNo == "0") {
                    Cfapp.alert({
                        message: "设置成功",
                        btntext: "确定",
                        success: function () {
                            location.href = "#springUrl('/a/order/list')";
                        }
                    });
                } else {
                    Cfapp.alert({
                        message: "设置失败",
                        btntext: "确定",
                        success: function () {
                            location.href = "#springUrl('/a/order/list')";
                        }
                    });
                }
            }

        });
    }


    function showModal(id) {
        $("#orderId").val(id);
        $('#exampleModal').modal('show');
    }

    function updateStatusSuccess(id) {
        Cfapp.confirm({
            message: "是否确认付款",
            btntext: "确定",
            btncanceltext: "取消",
            success: function () {
                updateStatu(id, 2, null);//付款待发货
            },
            cancel: function () {
                location.href = "#springUrl('/a/order/list')";
            }
        });
    }

    function review() {
        var reason = $("#js-textarea").val();
        var id = $("#orderId").val();
        if (!reason || reason == null) {
            Cfapp.alert({
                message: "请输入关闭原由!",
                btntext: "确定",
                success: function () {}
            });
            return;
        }
        updateStatu(id, 5, reason);
    }


    //开发票
    function exportInvoice(data) {
        var qrCodeIds =  isCheckedQyCode.join(",");
        var email = $("[name='email']").val();
        $('#peakButtom').modal('hide');
        if (qrCodeIds == '' || qrCodeIds == null){
            Cfapp.alert({
                message: "请勾选需求清单",
                btntext: "确定",
                success: function () {
                }
            });
            return;
        }
        if(email == '' || email == null){
            Cfapp.alert({
                message: "请填写邮箱",
                btntext: "确定",
                success: function () {
                }
            });
            return;
        }

        $.ajax({
            type: "POST",
            url: "#springUrl('/a/order/invoice')",
            data: {id: qrCodeIds, _csrfheader: csrfheader.value, _csrf: csrftoken.value, email: email},
            dataType: "json",
            success: function (data) {
                if (data.errorNo == 0) {
                    Cfapp.alert({
                        message: "开票成功",
                        btntext: "确定",
                        success: function () {
                            location.href = "#springUrl('/a/order/list')";
                        }
                    });
                }else{
                    Cfapp.alert({
                        message: "开票失败,失败原因："+data.errorMsg,
                        btntext: "确定",
                        success: function () {
                            location.href = "#springUrl('/a/order/list')";
                        }
                    });
                }
            },
            error: function () {
            }
        })
        /*Cfapp.confirm({
         message: "确定要开发票吗",
         btnoktext: "确定",
         btncanceltext: "取消",
         success: function () {

         },
         cancel: function () {
         $(".modal-backdrop").fadeOut();
         }
         });*/
    }

    function updateStatu(id, status, reason) {
        var url = "#springUrl('/a/order/updateStatus')"
        $.ajax({
            url: url,
            type: "GET",
            data: {id: id,
                orderCancel: reason,
                status: status},
            success: function (rsp) {
                if (status == '5') {
                    $('#exampleModal').modal('hide');
                }
                if (rsp.errorNo == "0") {
                    Cfapp.alert({
                        message: "操作成功",
                        btntext: "确定",
                        success: function () {
                            location.href = "#springUrl('/a/order/list')";
                        }
                    });
                } else {
                    Cfapp.alert({
                        message: "操作失败",
                        btntext: "确定",
                        success: function () {
                            location.href = "#springUrl('/a/order/list')";
                        }
                    });
                }
            }

        });
    }

    function removeData(data) {
        Cfapp.confirm({
            message: "确定要删除吗",
            btnoktext: "确定",
            btncanceltext: "取消",
            success: function () {
                $.ajax({
                    type: "POST",
                    url: "#springUrl('/a/order/delete')",
                    data: {_csrf: csrf, _csrf_header: csrf_header, id: data},
                    dataType: "json",
                    success: function (data) {
                        if (data.errorNo == 0) {
                            Cfapp.alert({
                                message: "删除成功",
                                btntext: "确定",
                                success: function () {
                                    location.href = "#springUrl('/a/order/list')";
                                }
                            });
                        }
                    },
                    error: function () {
                    }
                })
            },
            cancel: function () {
                $(".modal-backdrop").fadeOut();
            }
        });
    }



    function importExcel() {
        var templateExcelUrl = "#springUrl('/a/order/templateExcel')";
        var importExcelUrl = "#springUrl('/a/order/importExcel')";
        Cfapp.importExcel({
            title: '订单管理导入',
            importurl: importExcelUrl,
            templateurl: templateExcelUrl,
            cancel: function () {

            },
            success: function () {

            }
        });
    }

    function clearSearch() {
        $("#seachTableForm input,select").each(function () {
            $(this).val('');
        });
        $("#table").dataTable().fnClearTable();
    }
</script>

</body>
</html>
