<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<!DOCTYPE HTML>
<html>
<head>
    <link rel="stylesheet" href="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/style/admin.css" media="all">
    <link rel="stylesheet" href="${ctxPlugin}/static/css/reset.css">
</head>
<body >
<div class="layui-fluid">
    <div class="flower">
        <ul>
            <li>
                <a lay-href="${ctx}/order/getcleanOrder?type=W">
                    <div class="circle"><img src="${ctxPlugin}/static/djximg/wx.png" alt=""></div>
                    <span class="text">上门维修单 </span>
                </a>
            </li>

            <li>
                <a href="#"  class="orderImport"><%--lay-href="${ctx}/order/getcleanOrder?type=4"--%>
                    <div class="circle"><img src="${ctxPlugin}/static/djximg/wxd.png" alt=""></div>
                    <span class="text">批量下单 </span>
                </a>
            </li>
            <li>
                <a lay-href="${ctx}/order/getcleanOrder?type=A">
                    <div class="circle"><img src="${ctxPlugin}/static/djximg/zx.png" alt=""></div>
                    <span class="text">安装单 </span>
                </a>
            </li>

            <li>
                <a lay-href="${ctx}/order/getcleanOrder?type=Q">
                    <div class="circle"><img src="${ctxPlugin}/static/djximg/qx.png" alt=""></div>
                    <span class="text">清洗保养单 </span>
                </a>
            </li>
            <li>
                <a lay-href="${ctx}/order/getcleanOrder?type=S">
                    <div class="circle"><img src="${ctxPlugin}/static/djximg/sx.png" alt=""></div>
                    <span class="text">用户送修单 </span>
                </a>
            </li>

        </ul>


    </div>
</div>

<div class="layui-fluid layui-bg-white over importOrder hide" style="width: 600px;">
    <div class="layui-card-body item-flow pt-50 pb-20 text-c pl-50">
        <div style="height: 40px;line-height: 40px;">下载工单模板</div>
        <img src="${ctxPlugin}/static/img1/smartart.png" alt="" style="width: 40px;height: 40px;">
        <div style="height: 40px;line-height: 40px;">模板中填写相关数据</div>
        <img src="${ctxPlugin}/static/img1/smartart.png" alt="" style="width: 40px;height: 40px;">
        <div style="height: 40px;line-height: 40px;">导入Excel表</div>
    </div>

    <div class="layui-col-xs12">
        <div class="layui-col-xs9" style="position: relative">
            <label class="layui-form-label">Excel文件：</label>
            <div class="layui-input-block pr-30">
                <input type="text" name="fullname" lay-verify="required" class="layui-input" disabled id="fileName" style="width: 85%">
            </div>
            <button class="layui-btn f-r choose-file"  id="uploadBtn" >选择</button>
        </div>
        <p class="layui-col-xs12 pl-45 yellow mt-30 fs-12 mb-10">提示：1.仅允许导入‘xls’或‘xlsx’格式文件，且每次导入不超过100条。</p>
        <p class="layui-col-xs12 pl-45 yellow mb-30 fs-12">提示：2.导入失败的不会显示在工单列表中。</p>

            <div class="layui-form-item ">
                <div class="f-l">
                    <a href="${ctxPlugin}/dl/excel/djy_order_import_template.xlsx" class="layui-btn"  >下载模板</a>
                </div>
                <div class="f-r">
                    <input type="button" class="layui-btn layui-btn-disabled" id="sureSubmit" value="导入" disabled="disabled">
                    <input type="button" class="layui-btn" id="feedSubmit" value="取消">
                </div>

            </div>
    </div>
</div>

<script src="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/layui/layui.js"></script>
<script type="text/javascript" src="${ctxPlugin}/lib/socket.io.js"></script>
<script>
    var flower = document.getElementsByTagName('li'),
        circle = document.getElementsByClassName('circle'),
        text = document.getElementsByClassName('text');
    for (var i = 0; i < flower.length; i++) {
        flower[i].style.transform = 'rotate(' + (i * 72 + 42) + 'deg)'
        circle[i].style.transform = 'rotate(-' + (i * 72 + 42) + 'deg)'
        text[i].style.transform = 'rotate(-' + (i * 72 + 42) + 'deg)'
    }
    layui.config({
        base: '${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index',  'jquery', 'layer', 'upload'], function(){
        var upload = layui.upload
                ,$= layui.jquery;



        //执行实例
        var uploadInst = upload.render({
            elem: '#uploadBtn' //绑定元素
            , url: '${ctx}/order/checkHistoryCustomerExcel' //上传接口
            ,size: 5*1024
            ,number: 1
            ,auto:false
            ,bindAction: '#sureSubmit'
            ,accept:'file'
            ,exts: 'xls|xlsx'
            , done: function (res) {
               if(res.operType == "check"){
                   //验证表模板
                   if(res.pass == "y"){
                       layer.msg("验证成功！",{icon:1})
                       this.url ="${ctx}/order/importHistoryCustomerExcel";
                       $("#sureSubmit").removeClass("layui-btn-disabled")
                       $("#sureSubmit").removeAttr("disabled");
                   }else if(res.templateError=="y"){
                       $("#fileName").val("")
                       layer.msg("导入模板错误！",{icon:1})
                   }else if(res.templateError=="y"){
                       $("#fileName").val("")
                       layer.msg("最多一次导入100条数据！",{icon:1})
                   }else if(res.overLimit == "y"){
                       layer.msg(res.errorDetail,{icon:2});
                       $("#fileName").val("")
                       return
                   }
               }else if(res.operType == "import"){
                   if(res.code =="505"){
                       layer.msg("导入失败！数据转换错误")
                       return
                   }else if(res.pass = "y"){
                       layer.msg("导入成功"+res.successCount+"条数据",{icon:1,time:2000},function(){
                           $("#fileName").val("")
                           this.url ="${ctx}/order/checkHistoryCustomerExcel";
                           layer.closeAll()
                           return
                       })

                   }else if(res.code ="506"){
                       layer.msg("厂家金额信息为空！",{icon:1})
                   }else if(res.code ="507"){
                       layer.msg("可用金额不足！",{icon:1})
                   }else if(res.code ="503"){
                       layer.msg("金额不足！",{icon:1})
                   }
               }
                //上传完毕回调
            },before:function (obj){
               var fileName = $("#fileName").val()
                if(fileName == null || fileName ==""){
                    layer.msg("请添加文件")
                    return false
                }

            },choose:function (obj){
                obj.preview(function(index, file, result){
                    $("#fileName").val(file.name)
                    obj.upload(index, file);
                })
            }, error: function () {
                uploadInst.url ="${ctx}/order/checkHistoryCustomerExcel";
                $("#fileName").val("")
                $("#sureSubmit").attr('disabled','disabled');
                $("#sureSubmit").addClass("layui-btn-disabled")
                return layer.msg("上传失败！",{icon:2});

            }
        });

        $("#sureSubmit").click(function () {
            layer.load(); //上传loading
        })
        $("#feedSubmit").click(function () {
            layer.closeAll()
        })

        $('.orderImport').click(function () {
            uploadInst.url ="${ctx}/order/checkHistoryCustomerExcel";
            $("#fileName").val("")
            $("#sureSubmit").attr('disabled','disabled');
            $("#sureSubmit").addClass("layui-btn-disabled")
            layer.open({
                type: 1,
                title:'导入',
                area:['700px','400px'],
                content: $('.importOrder')
            });
        })
    });

    function cnnws(){
        var isFirefox = navigator.userAgent.toUpperCase().indexOf("Firefox") ? true:false;
        var isChrome = window.navigator.userAgent.indexOf("Chrome") !== -1;
        if(isFirefox || isChrome){
            var socket =  io.connect('${websocketUrl}' + "?userId="+userId);
            socket.on('connect', function(data) {
                var jsonObject = {userName: userId, message: "init"};
                socket.emit('initPM', jsonObject);
            });
            socket.on('newMessage', function(data) {
                var obj = eval('('+data.message+')');
                curOrderNums = obj.count;
                refreshPushMsgBox(obj);
            });
        }
    }

</script>
</body>
</html>