<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>备件返厂页面</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <meta name="decorator" content="base" />
    <link rel="stylesheet" type="text/css" href="${ctxPlugin}/static/css/reset.css" />
</head>
<body>

<div class="layui-fluid">
    <div class="layui-form  layui-card">
        <div class="layui-tab layui-tab-brief" >
            <ul class="layui-tab-title">
                <sfTags:pagePermission authFlag="SIT_BJGL_BJFC_BJFC_T" html='<a href="${ctx}/service/fitting/fittingBackPage"><li class="layui-this">旧件信息</li></a>'/>
                <button class="layui-btn f-r mt-10 mr-15 pl-10 pr-10"  lay-submit lay-filter="resetButton" >
                    <i class="layui-icon fs-12">&#xe615;</i>
                    重置
                </button>
                <button class="layui-btn f-r mt-10 mr-15 pl-10 pr-10" id="searchBtn" lay-submit lay-filter="LAY-user-back-search"><i class="layui-icon fs-12">&#xe615;</i>查询</button>
            </ul>
        </div>
        <div class="layui-card-body layuiadmin-card-header-auto" >
            <form class="layui-form layui-card" action="" id="searchForm">
            <div class="layui-form-item">
                <div class="layui-col-lg2 layui-col-sm3">
                    <label class="layui-form-label">物料号：</label>
                    <div class="layui-input-block">
                        <input type="text" name="fittingCode" class="layui-input" >
                    </div>
                </div>
                <div class="layui-col-lg2 layui-col-sm3">
                    <label class="layui-form-label">旧件名称：</label>
                    <div class="layui-input-block">
                        <input type="text" name="fittingName" class="layui-input" >
                    </div>
                </div>
                <div class="layui-col-lg2 layui-col-sm3">
                    <label class="layui-form-label">旧件型号：</label>
                    <div class="layui-input-block">
                        <input type="text" name="fittingVersion" class="layui-input" >
                    </div>
                </div>

                <div class="layui-col-lg2 layui-col-sm3">
                    <label class="layui-form-label">工单编号：</label>
                    <div class="layui-input-block">
                        <input type="text" name="orderNumber" class="layui-input" >
                    </div>
                </div>
                <div class="layui-col-lg2 layui-col-sm3">
                    <label class="layui-form-label">电站名称：</label>
                    <div class="layui-input-block">
                        <input type="text" name="powerStationName" class="layui-input" >
                    </div>
                </div>

                <%--<div class="layui-col-lg2 layui-col-sm3">
                    <label class="layui-form-label">是否原配：</label>
                    <div class="layui-input-block">
                        <select name="fittingType">
                            <option value="">请选择</option>
                            <option value="0">是</option>
                            <option value="1">否</option>
                        </select>
                    </div>
                </div>--%>
                <div class="layui-col-lg2 layui-col-sm3">
                    <label class="layui-form-label">服务工程师：</label>
                    <div class="layui-input-block">
                        <select name="employeId">
                            <option value="">请选择</option>
                            <c:forEach items="${employees}" var="emp">
                                <option value="${emp.columns.id}">${emp.columns.name}</option>
                            </c:forEach>
                        </select>
                    </div>
                </div>
                <div class="layui-col-lg2 layui-col-sm3">
                    <label class="layui-form-label">保修类型：</label>
                    <div class="layui-input-block" >
                        <select name="warrantyType">
                            <option value="">请选择</option>
                            <option value="1">保内</option>
                            <option value="2">保外</option>
                        </select>
                    </div>
                </div>
                <div class="layui-col-lg2 layui-col-sm3">
                    <label class="layui-form-label">旧件状态：</label>
                    <div class="layui-input-block" >
                        <select name="status">
                            <option value="">请选择</option>
                            <option value="0">待返厂</option>
                            <option value="1">未到厂</option>
                            <option value="2">已到厂</option>
                        </select>
                    </div>
                </div>
                <div class="layui-col-lg4 layui-col-sm6">
                <label class="layui-form-label">登记时间：</label>
                <div class="layui-input-block">
                    <div class="layui-col-xs5">
                        <input type="text" name="applyTimeSta" class="layui-input" id="startTime" placeholder="开始日期">
                    </div>
                    <div class="layui-col-xs2 text-c lh-30">
                        —
                    </div>
                    <div class="layui-col-xs5">
                        <input type="text" name="applyTimeEnd" class="layui-input" id="endTime" placeholder="结束日期">
                    </div>
                </div>
            </div>
                <div class="layui-col-lg4 layui-col-sm6">
                    <label class="layui-form-label">返厂时间：</label>
                    <div class="layui-input-block">
                        <div class="layui-col-xs5">
                            <input type="text" name="startBackTime" class="layui-input" id="startBackTime" placeholder="开始日期">
                        </div>
                        <div class="layui-col-xs2 text-c lh-30">
                            —
                        </div>
                        <div class="layui-col-xs5">
                            <input type="text" name="endBackTime" class="layui-input" id="endBackTime" placeholder="结束日期">
                        </div>
                    </div>
                </div>
                <div class="layui-col-lg4 layui-col-sm6">
                    <label class="layui-form-label">到厂时间：</label>
                    <div class="layui-input-block">
                        <div class="layui-col-xs5">
                            <input type="text" name="startArriveTime" class="layui-input" id="startArriveTime" placeholder="开始日期">
                        </div>
                        <div class="layui-col-xs2 text-c lh-30">
                            —
                        </div>
                        <div class="layui-col-xs5">
                            <input type="text" name="endArriveTime" class="layui-input" id="endArriveTime" placeholder="结束日期">
                        </div>
                    </div>
                </div>
            </div>
            </form>
        </div>
    </div>
    <div class="layui-card">
        <div class="layui-card-body">
            <table class="layui-hide" lay-skin="row" id="test" lay-filter="test"></table>
            <script type="text/html" id="toolbarDemo">
                <div class="layui-btn-container">
                    <button class="layui-btn layui-btn-sm" lay-event="backFac"><i class="layui-icon layui-icon-edit"></i>返厂</button>
                    <button class="layui-btn layui-btn-sm" lay-event="withdraw"><i class="layui-icon layui-icon-edit"></i>撤回</button>
                    <button class="layui-btn layui-btn-sm" id="exportBtn" lay-event="exports"><i class="layui-icon layui-icon-export"></i>导出</button>
                </div>
            </script>
        </div>
    </div>
</div>

<script src="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/layui/layui.js"></script>
<script>
    layui.config({
        base: '${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'tableExt', 'jquery', 'layer','laypage','laydate','form'], function(){
        //layui.use(['table','layer','laypage','laydate','form'], function(){
        $ = layui.$;
        tableExt = layui.tableExt;
        layer = layui.layer;
        laypage = layui.laypage;
        laydate = layui.laydate;
        form = layui.form;

        var table = tableExt.getLayTable();

        //开始日期
        var insStart = laydate.render({
            elem: '#startTime'
            ,done: function(value, date){
                //更新结束日期的最小日期
                insEnd.config.min = lay.extend({}, date, {
                    month: date.month - 1
                });

                //自动弹出结束日期的选择器
             /*   insEnd.config.elem[0].focus();*/
            }
        });
        //结束日期
        var insEnd = laydate.render({
            elem: '#endTime'
            ,done: function(value, date){
                //更新开始日期的最大日期
                insStart.config.max = lay.extend({}, date, {
                    month: date.month - 1
                });
            }
        });

        //开始日期
        var startBackTime = laydate.render({
            elem: '#startBackTime'
            ,done: function(value, date){
                //更新结束日期的最小日期
                endBackTime.config.min = lay.extend({}, date, {
                    month: date.month - 1
                });
                //自动弹出结束日期的选择器
             /*   endBackTime.config.elem[0].focus();*/
            }
        });
        //结束日期
        var endBackTime = laydate.render({
            elem: '#endBackTime'
            ,done: function(value, date){
                //更新开始日期的最大日期
                startBackTime.config.max = lay.extend({}, date, {
                    month: date.month - 1
                });
            }
        });
        var startArriveTime = laydate.render({
            elem: '#startArriveTime'
            ,done: function(value, date){
                //更新结束日期的最小日期
                endArriveTime.config.min = lay.extend({}, date, {
                    month: date.month - 1
                });
                //自动弹出结束日期的选择器
                /*   endArriveTime.config.elem[0].focus();*/
            }
        });
        //结束日期
        var endArriveTime = laydate.render({
            elem: '#endArriveTime'
            ,done: function(value, date){
                //更新开始日期的最大日期
                startArriveTime.config.max = lay.extend({}, date, {
                    month: date.month - 1
                });
            }
        });

        var fitTag = '${fns:checkPagePermission(request, "SIT_BJGL_BJFC_BJMC_B")}';
        tableExt.render({
            elem: '#test'
            , height: 'full-240'
            , toolbar: '#toolbarDemo'
            , defaultToolbar: false
            , limits : [ 20, 50, 100 ]
            , limit:20
            , page : true //开启分页
            , url: '${ctx}/service/fitting/getOldFittingList'
            , cols: [[
                {type: 'numbers',fixed:true,title:'序号'}
                , {field: 'id', type: 'checkbox',fixed: 'left'}
                , {field: 'fitting_code', title: '物料号',minWidth:'120',fixed: 'left', sort: false, align: 'center', exportable:true
                    ,templet:function(d){
                        if(fitTag=='0'){return '<a class="layui-table-opt-link" href="javascript:fittingDetail(\''+d.id+'\');">'+d.fitting_code+'</a>'}else{return d.fitting_name}
                    }
                }
                , {field: 'status', title: '返厂状态',minWidth:'100',fixed: 'left', sort: false, align: 'center', exportable:true
                    ,templet:function(d){
                    var status=d.status;
                       if(status==0){
                           return "待返厂";
                       }else if(status==1){
                           return "未到厂";
                       }else{
                           return "已到厂";
                       }
                    }
                    , expFormat: function (d) {
                            var status=d.status;
                            if(status==0){
                                return "待返厂";
                            }else if(status==1){
                                return "未到厂";
                            }else{
                                return "已到厂";
                            }
                        }
                }
                , {field: 'fitting_name', title: '旧件名称',minWidth:'150', sort: false, align: 'center', exportable:true}
                , {field: 'fitting_version', title: '旧件型号',minWidth:'150', sort: false, align: 'center', exportable:true}
                , {field: 'refund_num', title: '返厂数量',minWidth:'100', sort: false, align: 'center', exportable:true}
                , {field: 'send_time', title: '返厂时间',minWidth:'180', sort: false, align: 'center', exportable:true}
                , {field: 'back_name', title: '返厂人',minWidth:'180', sort: false, align: 'center', exportable:true}
                , {field: 'end_time', title: '到厂时间',minWidth:'180', sort: false, align: 'center', exportable:true}
                , {field: 'employe_name', title: '服务工程师',minWidth:'180', sort: false, align: 'center', exportable:true}
              /*  , {field: 'fitting_type', title: '是否原配',minWidth:'180', sort: false, align: 'center', exportable:true
                        ,templet:function(d){
                            if(d.fitting_type==0){
                                return "是";
                            }else if(d.fitting_type==1){
                               return "否";
                           }else{
                                return " ";
                            }
                        }
                        , expFormat: function (d) {
                            if(d.fitting_type==0){
                                return "是";
                            }else if(d.fitting_type==1){
                                return "否";
                            }else{
                                return " ";
                            }
                        }
                }*/
                , {field: 'orderNumber', title: '工单编号',minWidth:'180', sort: false, align: 'center', exportable:true}
                , {field: 'power_station_name', title: '电站名称',minWidth:'150', sort: false, align: 'center', exportable:true}
                , {field: 'warranty_type', title: '保修类型',minWidth:'150', sort: false, align: 'center', exportable:true
                ,templet:function(d){
                    if(d.warranty_type ==1){
                        return "保内";
                    }else if(d.warranty_type ==2){
                        return "保外";
                    }else{
                         return "";
                    }
                    }
                    , expFormat:function(d){
                        if(d.warranty_type ==1){
                            return "保内";
                        }else if(d.warranty_type ==2){
                            return "保外";
                        }else{
                            return "";
                        }
                    }
                }
                , {field: 'customer_name', title: '用户姓名',minWidth:'100', sort: false, align: 'center', exportable:true}
                , {field: 'customer_mobile', title: '用户电话',minWidth:'180', sort: false, align: 'center', exportable:true}
                , {field: 'customer_address', title: '用户地址',minWidth:'300', sort: false, align: 'center', exportable:true
                ,templet:function(d){
                    return d.province+d.city+d.area+d.customer_address
                    }
                    , expFormat:function(d){
                        return d.province+d.city+d.area+d.customer_address
                    }
                }
                , {field: 'create_time', title: '登记时间',minWidth:'180', sort: false, align: 'center', exportable:true}
                , {field: 'creator', title: '登记人',minWidth:'180', sort: false, align: 'center', exportable:true}
            ]]
            ,exportOpt:{                           //导出选项配置
                ele:'#exportBtn',                   //导出的Dom元素
                headerTitle: '旧件信息',             //excel表格的标题
                pageData:false,                     //true:导出的数据为页面数据，false:最大导出maxAmount条数据
                maxAmount: 1000,                    //当pageData为false生效
                fileName: '旧件信息',
                where: function (){                 //当pageData为false时生效，过滤的条件
                    return _serializeJson($("#searchForm"));
                }
            }
        });

          //监听行单击事件
        table.on('row(test)', function(obj){
            var data = obj.data;
            var oldData = table.cache["test"];
            var checkCell=obj.tr.find(".layui-form-checkbox");
            var CHECKED;
            if(obj.tr.hasClass("xuanzhong-special")){
                CHECKED = false;
                obj.tr.removeAttr("style");
                obj.tr.removeClass("xuanzhong-special");
                obj.tr.removeClass('layui-table-click');
                checkCell.removeClass('layui-form-checked');
            }else{
                CHECKED=true
                $(obj.tr).css('background-color','#CCEAEA');
                $(obj.tr).addClass("xuanzhong-special");
                obj.tr.addClass('layui-table-click');
                checkCell.addClass('layui-form-checked');
            }
            $.each(oldData,function(i,val){
                if(val.id == data.id){
                    oldData[i].LAY_CHECKED=CHECKED
                }
            })

        });

        //头工具栏事件
        table.on('toolbar(test)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
            switch(obj.event){
                case 'backFac':
                    var data = checkStatus.data;
                    if (data.length < 1) {
                        layer.msg("请先选择数据",{icon:5,anim:6});
                        return;
                    }
                    var ids="";
                    for(var i=0;i<data.length;i++){
                        if(data[i].status!='0'){
                            layer.msg("有旧件状态不能进行操作返厂!",{icon:5,anim:6});
                            return;
                        }
                        ids+=data[i].id+",";
                    }
                    var indexla = layer.confirm('您确定要将'+data.length+'条旧件返厂吗？', {
                        icon: 3,
                        btn: ['确定', '取消'] //按钮
                    }, function () {
                        $.ajax({
                            type: "POST",
                            url: "${ctx}/service/fitting/backOldFitting",
                            data: {
                                ids: ids
                            },
                            success: function (result) {
                                if(result.code=='200'){
                                    layer.msg('返厂成功！', {icon: 1, time: 1000}, function () {
                                        table.reload('test'); //数据刷新
                                    });
                                }else if(result.code=='205'){
                                    layer.msg('有旧件状态不能操作返厂！', {icon: 2});
                                }else{
                                    layer.msg('删除失败！', {icon: 2});
                                }
                            },
                            error:{

                            }
                        })
                    }, function () {
                        layer.close(indexla);
                    });
                    break;
                case 'withdraw':
                    var data = checkStatus.data;
                    if (data.length < 1) {
                        layer.msg("请先选择数据",{icon:5,anim:6});
                        return;
                    }
                    var ids="";
                    for(var i=0;i<data.length;i++){
                        if(data[i].status!='1'){
                            layer.msg("有旧件信息不能操作撤回!",{icon:5,anim:6});
                            return;
                        }
                        ids+=data[i].id+",";
                    }
                    var indexla = layer.confirm('您确定要将'+data.length+'条旧件撤回返厂吗？', {
                        icon: 3,
                        btn: ['确定', '取消'] //按钮
                    }, function () {
                        $.ajax({
                            type: "POST",
                            url: "${ctx}/service/fitting/withdrawFitting",
                            data: {
                                ids: ids
                            },
                            success: function (result) {
                                if(result.code=='200'){
                                    layer.msg('撤回成功！', {icon: 1, time: 1000}, function () {
                                        table.reload('test'); //数据刷新
                                    });
                                }else if(result.code=='205'){
                                    layer.msg('有旧件状态不能操作撤回！', {icon: 2});
                                }else{
                                    layer.msg('操作失败！', {icon: 2});
                                }
                            },
                            error:{

                            }
                        })
                    }, function () {
                        layer.close(indexla);
                    });
                    break;
            };
        });

        //监听搜索
        form.on('submit(LAY-user-back-search)', function(data){
            var field = data.field;
            //执行重载
            tableExt.reload('test', {
                where: field,
                page: {
                    curr: 1
                }
            });
        });

        //重置
        form.on('submit(resetButton)', function(data){
            $("#searchForm")[0].reset();
            layui.form.render();

        });

    });


    /*工单详情*/
    function orderDetail(data) {

    }

    //查询物流信息
    function searchLogisticInfo(number, name) {
        layer.open({
            type: 2
            , title: '物流信息'
            , content: '${ctx}/platform/fitting/searchLogisticInfo?number=' + number + "&name=" + name
            , area: ['700px', '60%']
            , yes: function(index, layero){

            }
        });
    }

    function fittingDetail(id){
        var index=layer.open({
            type: 2
            , title: '旧件信息'
            , content: '${ctx}/platform/fittingRefund/goFitRefundDetail?id='+ id
            , area: ['800px', '500px']
            , yes: function(index, layero){
                layer.close(index);
            }
        });
    }

    function oldRefund(d){
        if(d.fitting_type=='0'){
            return "旧件返厂"
        }else if(d.fitting_type=='1'){
            return "新件返厂"
        }else{
            return ""
        }
    }
    function facStatus(d){
        if(d.status=='1'){
            return "未到厂"
        }else if(d.status=='2'){
            return "已到厂"
        }else{
            return ""
        }
    }
    function postageType(d){
        console.log(d);
        if(d.postage_type=='0'){
            return "厂商到付"
        }else if(d.postage_type=='1'){
            return "服务商现付"
        }else{
            return "--"
        }
    }
    function reset(){
        $("#searchForm").find("select").val("");
        $("#searchForm").find("input").val("");
    }

    function isBlank(val) {
        if (val == null || val == '' || val == undefined) {
            return true;
        }
        return false;
    }
</script>
</body>
</html>

