<%@ page contentType="text/html; charset=utf-8"
         pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="format-detection" content="telephone=no">
    <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
    <meta name="renderer" content="webkit">
    <!-- 移动设备 viewport -->
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
    <jsp:include page="../../common.jsp" />
</head>
<body>

<form class="layui-form" id="form1" action="" style="margin-top: 30px;margin-left: 50px;">
    <div class="layui-inline">
        <label class="layui-form-label">订单号</label>
        <div class="layui-input-block">
            <input type="text" name="orderNumber" id="orderNumber" placeholder="请输入订单号" autocomplete="off" class="layui-input">
        </div>
    </div>
    <%--<div class="layui-inline">
        <label class="layui-form-label">通道单号</label>
        <div class="layui-input-block">
            <input type="text" name="channelNo"  id="channelNo" placeholder="请输入通道单号" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-inline">
        <label class="layui-form-label">退款单号</label>
        <div class="layui-input-block">
            <input type="text" name="refundNo"  id="refundNo" placeholder="请输入退款单号" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-inline">
        <label class="layui-form-label">商户简称</label>
        <div class="layui-input-block">
            <input type="text" name="alias"  id="alias" placeholder="请输入商户简称" autocomplete="off" class="layui-input">
        </div>
    </div>--%>
    <div class="layui-inline">
        <label class="layui-form-label">订单类型</label>
        <div class="layui-input-block">
            <select name="orderType" class="layui-select">
                <option value="">请选择</option>
                <option value="1">主扫</option>
                <option value="2">被扫</option>
                <option value="3">会员充值</option>
                <option value="4">POS刷卡</option>
                <option value="5">主扫充值</option>
                <option value="6">扫码王</option>
                <option value="7">H5</option>
                <option value="8">升级</option>
                <option value="9">小程序</option>
                <option value="10">线上店</option>
                <option value="99">插件</option>
            </select>
        </div>
    </div>

    <div class="layui-inline">
        <label class="layui-form-label">支付方式</label>
        <div class="layui-input-block">
            <select name="payTypeCode" class="layui-select">
                <option value="">请选择</option>
                <option value="wechatPay|sxfPay1">微信</option>
                <option value="aliPay|sxfPay0">支付宝</option>
                <option value="bank|sxfPay2">银联</option>
            </select>
        </div>
    </div>
</form>
<table class="layui-hide" id="refundOrderTab" lay-filter="refundOrderTab"></table>

<script type="text/html" id="leftBar">
    <button type="button" class="layui-btn" lay-event="search">查询</button>
</script>

<script>
    layui.use(['table', 'layer'], function(){
        var table = layui.table;
        var layer = layui.layer;

        var tableIns = table.render({
            elem: '#refundOrderTab'
            ,url:'${ctx}/refundOrder/queryRefundOrderByPage'
            ,response: {
                statusName: 'code' //数据状态的字段名称，默认：code
                ,countName: 'count' //数据总数的字段名称，默认：count
                ,dataName: 'data' //默数据列表的字段名称，认：data
                ,statusCode : 200
            }
            ,id:'refundOrder'
            ,method:'POST'
            ,parseData: function(res){ //res 即为原始返回的数据
                console.log(res);
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.message, //解析提示文本
                    "count": res.data.total, //解析数据长度
                    "data": res.data.records //解析数据列表
                };
            }
            ,toolbar: '#leftBar' //开启头部工具栏，并为其绑定左侧模板
            , defaultToolbar: ['filter']
            ,defaultToolbar: ['filter', 'exports', 'print', { //自定义头部工具栏右侧图标。如无需自定义，去除该参数即可
                title: '提示'
                ,layEvent: 'LAYTABLE_TIPS'
                ,icon: 'layui-icon-tips'
            }]
            ,title: '退款列表'
            ,cols: [[
                {type: 'checkbox', fixed: 'left', hidden: true}
                ,{field:'numbers', title:'序号', fixed: 'left', unresize: true, width:80, type:'numbers'}
                ,{title:'订单号',templet: function (d) {
                        return d.orderNumber;
                    }}
                ,{field:'refundNo', title:'退款单号', sort: true}
                ,{field:'alias', title:'商户简称'}
                ,{field:'orderType', title:'订单类型', templet:function (d) {
                        if(d.orderType === '1'){
                            return "主扫";
                        }else if(d.orderType === '2'){
                            return "被扫";
                        }else if(d.orderType === '3'){
                            return "会员充值";
                        }else if(d.orderType === '4'){
                            return "POS刷卡";
                        }else if(d.orderType === '5'){
                            return "主扫充值";
                        }else if(d.orderType === '6'){
                            return "扫码王";
                        }else if(d.orderType === '7'){
                            return "H5";
                        }else if(d.orderType === '8'){
                            return "升级";
                        }else if(d.orderType === '9'){
                            return "小程序";
                        }else if(d.orderType === '10'){
                            return "线上店";
                        }else{
                            return "插件";
                        }
                    }}
                ,{title:'订单来源',templet:function (d) {
                        if(d.aisleSwitch === '1'){
                            return "乐刷";
                        }else if(d.aisleSwitch === '2'){
                            return "随行付";
                        }else if(d.aisleSwitch === '3'){
                            return "瑞银信";
                        }else if (d.aisleSwitch === '4'){
                            return "银盛";
                        }else{
                            return "未知";
                        }
                    }}
                ,{title:'支付方式', templet:function (d) {
                        if(d.payTypeCode.search('0') != -1 || d.payTypeCode === "aliPay"){
                            return "支付宝";
                        }else if(d.payTypeCode.search('1') != -1 || d.payTypeCode === "wechatPay"){
                            return "微信";
                        }else if(d.payTypeCode.search('2') != -1 || d.payTypeCode === "bank"){
                            return "银联";
                        }else{
                            return "未知";
                        }
                    }}
                ,{field:'payAmt', title:'支付金额(元)', templet:function (d) {
                        return d.payAmt.toFixed(2);
                  }}
                ,{field:'refundAmt', title:'退款金额(元)', templet:function (d) {
                    if(d.refundAmt){
                        return d.refundAmt.toFixed(2);
                    }else{
                        return d.payAmt.toFixed(2);
                    }
                }}
                ,{field: 'payTime', title: '交易时间',width:160,templet : "<div>{{layui.util.toDateString(d.payTime, 'yyyy-MM-dd HH:mm:ss')}}</div>"}
                ,{field: 'refundTime', title: '退款时间',width:160,templet : "<div>{{layui.util.toDateString(d.refundTime, 'yyyy-MM-dd HH:mm:ss')}}</div>"}
                ,{title:'退款状态', templet:function (d) {
                    if(d.status === '1'){
                        return '<span style="color: green;">退款成功</span>';
                    }else if(d.status === '2'){
                        return '<span style="color: blue;">退款中</span>';
                    }else{
                        return '<span style="color: red;">退款失败</span>';
                    }
                }}
                ,{field:'failMsg', title:'备注',width:160,templet:function (d){
                    if(d.refundAmt){
                        if(d.refundAmt === d.payAmt){
                            return d.failMsg + "(全额退款)";
                        }else{
                            return d.failMsg + "(部分退款)";
                        }
                    }else{
                        return d.failMsg + "(全额退款)";
                    }
                }}
            ]]
            ,request: {
                pageName: 'current' //页码的参数名称，默认：page
                ,limitName: 'size' //每页数据量的参数名，默认：limit
            }
            ,page: true
        });
        //监听头工具栏事件
        table.on('toolbar(refundOrderTab)', function (obj) {
            switch (obj.event) {
                case 'search':
                    var params= serialize($('#form1'));
                    table.reload('refundOrder', {
                        where: params
                        , page: {
                            size: 10
                            , current: 1
                        }
                    });
                    break;
            }
        });
    });
</script>
</body>
</html>
