<%@ 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"/>
    <link rel="stylesheet" type="text/css" href="${ctxPlugin}/lib/font/iconfont.css"/>

</head>
<body>

<div class="layui-fluid">
    <form class="layui-form layui-card" id="searchForm">
        <div class="layui-tab layui-tab-brief">
            <ul class="layui-tab-title">
                <sfTags:pagePermission authFlag="JXSDDGL_THDD_THDD_T" html='<<a href="${ctx}/material/return/returnOrder"><li class="layui-this">退货订单</li></a>'/>
                <button class="layui-btn f-r mt-10 mr-15 pl-10 pr-10 " type="reset">
                    <i class="layui-icon fs-12">&#xe9aa;</i>
                    重置
                </button>
                <button type="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">
            <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="number" 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="status">
                            <option value="">请选择</option>
                            <option value="1">待发货单位入库</option>
                            <option value="2">入库驳回</option>
                            <option value="3">已完成</option>
                        </select>
                    </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="relationNumber" 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="returnRemark" 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="traderId">
                            <option value="">请选择</option>
                            <c:forEach items="${traderList}" var="trader">
                                <option value="${trader.columns.id}">${trader.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">
                        <input type="text" name="expressNo" 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-col-xs5">
                            <input type="text" name="createTimeMin" class="layui-input" id="createTimeMin"
                                   placeholder="开始日期">
                        </div>
                        <div class="layui-col-xs2 text-c lh-30">
                            —
                        </div>
                        <div class="layui-col-xs5">
                            <input type="text" name="createTimeMax" class="layui-input" id="createTimeMax"
                                   placeholder="结束日期">
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </form>
    <div class="layui-card">
        <div class="layui-card-body">
            <table class="layui-hide" lay-skin="row" id="test" lay-filter="test"></table>
        </div>
    </div>
</div>
<script type="text/html" id="toolbarDemo">
    <sfTags:pagePermission authFlag='JXSDDGL_THDD_THDD_TH_B' html='
    <button class="layui-btn layui-btn-sm" lay-event="add"><i class="layui-icon layui-icon-add-1"></i>退货</button>'/>
    <button class="layui-btn layui-btn-sm" id="exportBtn" lay-event="export" ><i class="layui-icon layui-icon-export"></i>导出列表</button>
</script>
<script src="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/layui/layui.js"></script>
<script src="${ctxPlugin}/lib/xm-select.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.$;
        tableExt = layui.tableExt;
        layer = layui.layer;
        laypage = layui.laypage;
        laydate = layui.laydate;
        form = layui.form;
        table = tableExt.getLayTable();
        //匹配
        var ppBtn = ${fns:checkPagePermission(request, 'JXSDDGL_THDD_THDD_RK_B') eq '0'};

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

        window.searchOrder = function () {
            render();
        };

        render();

        function render() {
            tableExt.render({
                elem: '#test'
                , height: 'full-180'
                , toolbar: '#toolbarDemo'
                , defaultToolbar: false
                , limits: [20, 50, 100]
                , limit: 20
                , page: true //开启分页
                , url: '${ctx}/material/return/ajaxForRetenOrderList'
                , where: _serializeJson($("#searchForm"))
                , cols: [[
                    {type: 'numbers', fixed: 'left', title: '序号'},
                    {type: 'checkbox', fixed: 'left', title: '选择'}
                    , {
                        field: 'id', title: '操作', minWidth: 100, fixed: 'left', sort: false, align: 'center', templet: function (d) {
                            if (ppBtn && d.status === '1') {
                                if(d.type =='3'){
                                    return "<a href=\"#\" class=\"layui-table-link layui-icon   \" style='font-size:14px;' onclick=\"confirmOrder('" + d.id + "')\">供应商签收</a>";
                                }
                                return "<a href=\"#\" class=\"layui-table-link layui-icon   \" style='font-size:14px;' onclick=\"confirmOrder('" + d.id + "')\">入库</a>";
                            }
                            return '——';
                        }
                    }
                    , {
                        field: 'trader_name',
                        title: '代理商名称',
                        sort: false,
                        align: 'center',
                        exportable: true,
                        minWidth: 150
                    }
                    , {
                        field: 'type',
                        title: '订单类型',
                        minWidth: 150,
                        sort: false,
                        align: 'center',
                        exportable: true,
                        templet: function (d) {
                            return transType(d.type);
                        },
                        expFormat: function (d) {
                            return transType(d.type);
                        }
                    }
                    , {
                        field: 'supplierName',
                        title: '供应商名称',
                        sort: false,
                        align: 'center',
                        exportable: true,
                        minWidth: 150
                    }
                    , {
                        field: 'materialList',
                        title: '物料清单',
                        minWidth: 150,
                        sort: false,
                        align: 'center',
                        templet: function (d) {
                            return "<a href=\"#\" class=\"layui-table-link layui-icon   \" style='font-size:14px;' onclick=\"materialDetail('" + d.id + "')\">查看</a>&nbsp;&nbsp;";
                        }
                    }
                    , {
                        field: 'number',
                        title: '退货单号',
                        minWidth: 200,
                        sort: false,
                        align: 'center',
                        exportable: true,
                        templet: function (d) {
                            return "<a href=\"#\" class=\"layui-table-link \" style='font-size:14px;' onclick=\"showDetail('" + d.id + "')\">" + d.number + "</a>";
                        }
                    }
                    , {
                        field: 'return_method_name',
                        title: '退货方式',
                        minWidth: 150,
                        sort: false,
                        align: 'center',
                        exportable: true
                    }
                    , {
                        field: 'express_no',
                        title: '物流单号',
                        sort: false,
                        align: 'center',
                        exportable: true,
                        minWidth: 180
                    }
                    , {
                        field: 'return_driver',
                        title: '司机',
                        sort: false,
                        align: 'center',
                        exportable: true,
                        minWidth: 200
                    }
                    , {
                        field: 'return_mobile',
                        title: '联系方式',
                        sort: false,
                        align: 'center',
                        exportable: true,
                        minWidth: 200
                    }
                    , {
                        field: 'return_car_num',
                        title: '车牌号',
                        sort: false,
                        align: 'center',
                        exportable: true,
                        minWidth: 200
                    }
                    , {
                        field: 'return_remark',
                        title: '退货备注',
                        sort: false,
                        align: 'center',
                        exportable: true,
                        minWidth: 200
                    }
                    , {
                        field: 'status',
                        title: '退货状态',
                        minWidth: 150,
                        sort: false,
                        align: 'center',
                        exportable: true,
                        templet: function (d) {
                            return transStatus(d.status);
                        },
                        expFormat: function (d) {
                            return transStatus(d.status);
                        }
                    }

                    , {
                        field: 'relation_number',
                        title: '关联订单编号',
                        minWidth: 200,
                        sort: false,
                        align: 'center',
                        exportable: true,
                        templet: function (d) {
                            return "<a href=\"#\" class=\"layui-table-link \" style='font-size:14px;' onclick=\"deliverOrderDetail('" + d.relation_id + "','"+d.type+"')\">" + d.relation_number + "</a>";
                        }
                    }
                    , {
                        field: 'create_time',
                        title: '退货时间',
                        sort: false,
                        align: 'center',
                        exportable: true,
                        minWidth: 200
                    }
                ]]
                , exportOpt: {                           //导出选项配置
                    ele: '#exportBtn',                   //导出的Dom元素
                    headerTitle: '退货订单',             //excel表格的标题
                    pageData: false,                     //true:导出的数据为页面数据，false:最大导出maxAmount条数据
                    maxAmount: 5000,                    //当pageData为false生效
                    fileName: '退货订单',
                    where: function () {                 //当pageData为false时生效，过滤的条件
                        return _serializeJson($("#searchForm"));
                    }
                }
            });
        }


        function transStatus(status) {
            switch (status) {
                case '1':
                    return '待发货单位入库';
                case '2':
                    return '入库驳回';
                case '3':
                    return '已完成';
                default:
                    return '';
            }
        }

        function transType(type) {
            switch (type) {
                case '3':
                    return '平台退货';
                default:
                    return '代理商退货';
            }
        }


        //头工具栏事件
        table.on('toolbar(test)', function (obj) {
            if (obj.event === 'add') {
                layer.open({
                    title:'退货',
                    type: 2,
                    area: ['80%', '80%'],
                    fixed: false,
                    content: '${ctx}/material/return/addReturnOrder',
                    success: function (layero, index) {
                        childWin = window[layero.find('iframe')[0]['name']];
                    }
                })
            }
        });

        //监听行单击事件
        table.on('row(test)', function (obj) {


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

        $('input').on('keydown', function(event){
            if(event.keyCode == 13){
                //执行相关操作
                $("#searchBtn").click();
            }
        });

    });


    function showDetail(id) {
        layer.open({
            type: 2,
            title: "查看",
            resize: false,
            area: ['80%', '80%'],
            content: '${ctx}/material/return/showDetail?id=' + id,
        });

    }

    function deliverOrderDetail(deliverOrderId,type) {
        if (type === '2') {
            layer.open({
                type: 2,
                title: "订单/电站详情",
                resize: false,
                area: ['80%', '80%'],
                content: '${ctx}/material/return/toPSPage?id=' + deliverOrderId,
            });
        } else {
            layer.open({
                type: 2,
                title: "订单/电站详情",
                resize: false,
                area: ['80%', '80%'],
                content: '${ctx}/material/return/toDeliverPage?id=' + deliverOrderId,
            });
        }

    }

    //发货单物料清单
    function materialDetail(returnId) {
        layer.open({
            type: 2,
            title: "查看",
            resize: false,
            area: ['80%', '70%'],
            content: '${ctx}/material/return/materialList?id=' + returnId
        });
    }

    function isBlank(val) {
        if (val == null || val == '' || val == undefined) {
            return true;
        }
        return false;
    }

    function confirmOrder(id) {
        layer.open({
            type: 2,
            title: "入库",
            resize: false,
            area: ['80%', '80%'],
            content: '${ctx}/material/return/confirmOrder?source=1&id=' + id,
        });

    }

    function reload(){
        table.reload('test', {
            page:{
                curr:1
            }
        });
    }
</script>
</body>
</html>

