<%@ 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="BJGL_KCGL_KCGL_T" html='<a href="${ctx}/platform/fiting/pageList"><li class="layui-this">库存管理</li></a>'/>
                  <sfTags:pagePermission authFlag="BJGL_KCGL_FWSKC_T" html='<a href="${ctx}/site/fitting/siteFitting"><li>服务商库存</li></a>'/>
                  <button class="layui-btn f-r mt-10 mr-15 pl-10 pr-10 " type="reset"  onclick="reset()" >
                      <i class="layui-icon fs-12">&#xe9aa;</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" 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="suitPrinter" 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="remarks" class="layui-input" >
                      </div>
                  </div>
                <div class="layui-col-lg4 layui-col-sm6">
                    <label class="layui-form-label">库存量：</label>
                    <div class="layui-input-block">
                        <div class="layui-input-inline" style="width: 100px;">
                            <input type="text" name="warningMin"  autocomplete="off" class="layui-input">
                        </div>
                        <div class="layui-form-mid">—</div>
                        <div class="layui-input-inline" style="width: 100px;">
                            <input type="text" name="warningMax"  autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
              </div>
        </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">
                    <sfTags:pagePermission authFlag="KCGL_KCGL_XZ_B" html='<button class="layui-btn layui-btn-sm" id="searchBtn"  lay-event="addfitting"><i class="layui-icon layui-icon-add-1"></i>新增</button>'/>
                    <sfTags:pagePermission authFlag="KCGL_KCGL_SDRK_B" html='<button class="layui-btn layui-btn-sm " id="searchBtn" lay-event="manualAdd"><i class="layui-icon layui-icon-add-circle"></i>手动入库</button>'/>
                    <%--<sfTags:pagePermission authFlag="KCGL_KCGL_SC_B" html='--%><button class="layui-btn layui-btn-sm" id="deleteBtn" lay-event="delete"><i class="layui-icon layui-icon-delete"></i>删除</button><%--'/>--%>
                    <sfTags:pagePermission authFlag="KCGL_KCGL_DC_B" html='<button class="layui-btn layui-btn-sm" id="exportBtn" lay-event="export"><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;
        table = tableExt.getLayTable();

        var fitTag = '${fns:checkPagePermission(request, "KCGL_KCGL_BJXQ_B")}';
        var XGTag = '${fns:checkPagePermission(request, "KCGL_KCGL_XG_B")}';
        var PDTag = '${fns:checkPagePermission(request, "KCGL_KCGL_PD_B")}';
        tableExt.render({
            elem: '#test'
            , title:'备件库存'
            , height: 'full-240'
            , toolbar: '#toolbarDemo'
            , defaultToolbar: false
            , limits : [ 20, 50, 100 ]
            , limit:20
            , page : true //开启分页
            , url: '${ctx}/platform/fiting/getPlatformFittingData'
            , cols: [[
                {type: 'numbers',fixed:'left',title:'序号'}
                , {field: 'id', type: 'checkbox',fixed: 'left'}
                , {field: 'id', title: '操作', fixed:'left', minWidth:'130', sort: false, align: 'center', templet:function(d){
                    var html="";
                    if(XGTag=='0'){
                        html+='<a class="layui-table-opt-link" href="javascript:updatefitting(\''+d.id+'\');" ><i class="layui-icon layui-icon-edit"></i>编辑</a>';
                    }
                    if(PDTag=='0'){
                       html+='&nbsp;&nbsp; <a class="layui-table-opt-link" href="javascript:modifyFitting(\''+d.id+'\');"><i class="layui-icon layui-icon-survey"></i>盘点</a>';
                    }
                     /*   return '<a style="color:#D9B589" href="javascript:updatefitting(\''+d.id+'\');" ><i class="layui-icon layui-icon-edit"></i>编辑</a> &nbsp;&nbsp; <a style="color:#D9B589" href="javascript:modifyFitting(\''+d.id+'\');"><i class="layui-icon layui-icon-survey"></i>盘点</a>'
*/                   if(isBlank(html)){
                      html='--';
                    }
                    return html;
                }}
                , {field: 'code', title: '物料号', fixed:'left', minWidth:'150', 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.code+'</a>'}else{return d.code}
                }}
                , {field: 'name', title: '备件名称',minWidth:'100', sort: false, align: 'center', exportable:true}
                , {field: 'version', title: '备件型号',minWidth:'150', sort: false, align: 'center', exportable:true}
                , {field: 'suit_printer', title: '适用机型',minWidth:'100', sort: false, align: 'center', exportable:true}
                , {field: 'warning', title: '库存数量',minWidth:'100', sort: false, align: 'center',exportable:true}
                , {field: 'storehouse', title: '库位',minWidth:'100', sort: false, align: 'center',exportable:true}
                , {field: 'unit', title: '计量单位',minWidth:'150', sort: false, align: 'center',exportable:true}
                , {field: 'site_price', title: '服务商价格',minWidth:'150', sort: false, align: 'center',exportable:true}
                , {field: 'customer_price', title: '零售价格',minWidth:'150', sort: false, align: 'center',exportable:true}
               /* , {field: 'refund_old_flag', title: '返还旧件',minWidth:'100', sort: false, align: 'center', exportable:true
                    ,templet:function(d){
                        if (d.refund_old_flag == '0') {
                            return "不需要返还"
                        } else if (d.refund_old_flag == '1') {
                            return "需要返还"
                        } else {
                            return "";
                        }
                    }
                    , expFormat: function (d) {
                        if (d.refund_old_flag == '0') {
                            return "不需要返还"
                        } else if (d.refund_old_flag == '1') {
                            return "需要返还"
                        } else {
                            return "";
                        }
                    }
                }*/
                , {field: 'remarks', title: '备件描述',minWidth:'200', sort: false, align: 'center', exportable:true}
                , {field: 'newest_storage_time', 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"));
                }
            }
        });


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


        //头工具栏事件
        table.on('toolbar(test)', function(obj){
            switch(obj.event){
                case 'addfitting':

                    layer.open({
                        type: 2,
                        content: "${ctx}/platform/fiting/addPlatformFitting" //这里content是一个DOM，注意：最好该元素要存放在body最外层，否则可能被其它的相对元素所影响
                        ,title: "新增"
                        ,area:["800px","500px"],
                        end:function(){
                            //刷新表格
                        }

                    });
                    break;
                case 'manualAdd':
                    var checkStatus = table.checkStatus(obj.config.id);
                    var data = checkStatus.data;
                    var ids=[];
                    if (data.length < 1) {
                        layer.msg("请选择一条数据",{icon:5,anim:6});
                        return;
                    }
                    $.each(data, function(i, d) {
                        ids.push(d.id);
                    });

                    layer.open({
                        type: 2,
                        content: "${ctx}/platform/fiting/getbatchWarehousing?ids="+ids.join(",")  //这里content是一个DOM，注意：最好该元素要存放在body最外层，否则可能被其它的相对元素所影响
                        ,title: "手动入库"
                        ,area:["1200px","370px"],
                        end:function(){
                            //刷新表格
                          //  searchOrder(orderId)
                        }

                    });
                    break;
                case 'delete':
                    var checkStatus = table.checkStatus(obj.config.id);
                    var data = checkStatus.data;

                    if (data.length != 1) {
                        layer.msg("请选择一条数据",{icon:5,anim:6});
                        return;
                    }
                        var ids = data[0].id
                    var indexla = layer.confirm('删除备件将无法恢复，您确定要删除备件吗？', {
                        icon: 3,
                        btn: ['确定', '取消'] //按钮
                    }, function () {
                        $.ajax({
                            type: "POST",
                            url: "${ctx}/platform/fiting/PlatformfittingDelete",
                            data: {
                                ids: ids
                            },
                            success: function (result) {
                                if(result.code=='200'){
                                    layer.msg('删除成功！', {icon: 1, time: 1000}, function () {
                                        window.location.reload();
                                    });
                                }else if(result.code == '203'){
                                    console.log(result)
                                    layer.msg(result.errMsg, {icon: 2});
                                }else{
                                    layer.msg('删除失败！', {icon: 2});
                                }
                            },
                            error:{

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

                    break;
            }
        })

        //申请开始日期
        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 insShipS = laydate.render({
            elem: '#shipStart'
            ,done: function(value, date){
                //更新结束日期的最小日期
                insShipE.config.min = lay.extend({}, date, {
                    month: date.month - 1
                });

                //自动弹出结束日期的选择器
                insShipE.config.elem[0].focus();
            }
        });

        //发货结束日期
        var insShipE = laydate.render({
            elem: '#shipEnd'
            ,done: function(value, date){
                //更新结束日期的最小日期
                insShipS.config.min = lay.extend({}, date, {
                    month: date.month - 1
                });
            }
        });

    });

    function searchOrder() {
        //执行重载
        table.reload('test', {
            page: {
                curr: 1
            }
        });
    }

    //查看详情
    function fittingDetail(id){
        layer.open({
            type: 2
            , title: '查看详情'
            , content: '${ctx}/site/fitting/toPlatformFittingDetail?id=' + id
            , area: ['800px', '500px']
            , yes: function(index, layero){

            }
        });
    }
    //盘点
    function modifyFitting(id){
        layer.open({
            type: 2
            , title: '盘点库存'
            , content: '${ctx}/platform/fiting/modifyFitting?id=' + id +"&type=1"
            , area: ['800px', '500px']
            , yes: function(index, layero){

            }
        });
    }
    //编辑
    function updatefitting(id){
        layer.open({
            type: 2
            , title: '编辑备件'
            , content: '${ctx}/platform/fiting/modifyFitting?id=' + id
            , area: ['800px', '500px']
            , yes: function(index, layero){

            }
        });
    }

    /*function refundOld(d){
        if(d.refund_old_flag=='0'){return "不需要返还"}else if(d.refund_old_flag=='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;
    }

    function reset(){
        layui.form.render();
        $("#searchForm").find("select").val("");
        $("#searchForm").find("input").val("");
    }
</script>
</body>
</html>

