<%@ page contentType="text/html; charset=utf-8"
         pageEncoding="utf-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<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"/>
    <style>
        .layui-form-select {
            width: 182px;
        }

        .layui-input-block {
            width: 55%;
        }

        .refund-status {
            display: none;
        }
        /*layui-table 表格内容允许换行*/
        .layui-table-cell {
            height: auto !important;
            white-space: normal;
        }
        .ellipsis{
            width: 100px;
            white-space:nowrap;
            overflow:hidden;
            text-overflow:ellipsis;
        }
        .layui-btn+.layui-btn {
            margin-left: 0px;
        }
    </style>
</head>
<body>
<div class="row animated fadeInRight" style="margin: 0;">
    <div class="wrapper wrapper-content mt5 right-content ml5 mr5">
        <div class="toolbar-panel bdd">
            <div class="toolbar-box">
                <div class="toolbar-head clearfix lgraybg pt5 pl10 bdbd">
                    <!-- 顶部按钮 -->
                    <div class="fl">
                        查询条件
                    </div>
                    <div class="tools fr">
                        <a href="javascript:void(0);" class="collapse dblock f14 dgray mr5">
                            <i class="fa-2x fa fa-angle-double-up"></i>
                        </a>
                    </div>
                </div>
            </div>
            <!--搜索条件 -->
            <div class="toolbar-body">
                <form class="layui-form" id="form1" action="" style="margin-top: 10px;">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">用户ID</label>
                            <div class="layui-input-block">
                                <input type="text" name="userId" id="userId" placeholder="请输入用户ID"
                                       autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">用户角色</label>
                            <div class="layui-input-block">
                                <select id="roleCode" name="roleCode">
                                    <option value="">请选择</option>
                                    <option value="SV2">官方</option>
                                    <option value="ZY_BST">倍斯特</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">商品名称</label>
                            <div class="layui-input-block">
                                <input type="text" name="name" 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="orderNo" 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="merchant.alias" 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="order.receiver" 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="order.phone" 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="expressNo" placeholder="请输入快递单号"
                                       autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">订单状态</label>
                            <div class="layui-input-block">
                                <select id="status" name="status">
                                    <option value="">请选择</option>
                                    <option value="00">待支付</option>
                                    <option value="01">已支付</option>
                                    <option value="02">发起退货</option>
                                    <option value="12">已同意退款</option>

                                    <option value="13">等待退款中</option>
                                    <option value="03">退款成功</option>
                                    <option value="04">退款失败</option>
                                    <option value="05">待收货</option>
                                    <option value="06">已完成</option>
                                    <option value="07">部分退款</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">物流状态</label>
                            <div class="layui-input-block">
                                <select id="expressStatus" name="expressStatus">
                                    <option value="">请选择</option>
                                    <option value="00">待发货</option>
                                    <option value="10">已发货</option>
                                </select>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
    <div class="mb50 mt10">
        <div class="whitebg pl10 pr10">
            <table class="layui-hide" id="mercOrderDetailTab" lay-filter="mercOrderDetailTab"></table>
        </div>
    </div>
</div>

<script type="text/template" id="refund">
    <form class="layui-form" id="form2" style="margin-top: 1rem;">
        <input name="id" id="id" hidden>
        <div class="layui-form-item" style="width: 350px;">
            <label class="layui-form-label">退款金额</label>
            <div class="layui-input-block">
                <input type="number" id="refundAmt" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item" style="width: 350px;">
            <label class="layui-form-label">退款原因</label>
            <div class="layui-input-block">
                <textarea placeholder="退款原因" id="refundReason" autocomplete="off" class="layui-textarea"></textarea>
            </div>
        </div>
        <div class="layui-form-item" style="width: 350px;">
            <label class="layui-form-label">审核</label>
            <div class="layui-input-block">
                <select class="layui-select" id="refundStatus" name="status" lay-filter="refundStatus">
                    <option value="">请选择</option>
                    <option value="1">通过</option>
                    <option value="2">驳回</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item refund-status refund-status-2" style="width: 350px;">
            <label class="layui-form-label">驳回原因</label>
            <div class="layui-input-block">
                <textarea placeholder="请输入驳回原因" name="rejectRemark" id="rejectRemark" autocomplete="off"
                          class="layui-textarea"></textarea>
            </div>
        </div>
        <div class="layui-form-item refund-status refund-status-1" style="width: 350px;">
            <label class="layui-form-label">手机号</label>
            <div class="layui-input-block">
                <select class="layui-select" id="phone" name="phone" lay-filter="phone">
                    <option value="">请选择</option>
                    <c:forEach items="${phoneList}" var="p">
                        <option value="${p.phone}">${p.phone}(${p.name})</option>
                    </c:forEach>
                </select>
            </div>
        </div>
        <div class="layui-form-item refund-status refund-status-1" style="width: 350px;">
            <label class="layui-form-label">验证码</label>
            <div class="layui-input-block" style="display: flex;justify-content: flex-start">
                <input type="text" id="verifyCode" autocomplete="off" class="layui-input">
                <button type="button" class="layui-btn" onclick="getVerifyCode()">发送</button>
            </div>
        </div>
        <div class="layui-form-item" style="width: 350px;">
            <label class="layui-form-label">备注</label>
            <div class="layui-input-block">
                <span style="color: red">审核通过会发起退款请求，交易金额会原路退回，请仔细核对后再确认</span>
            </div>
        </div>
    </form>
</script>

<script type="text/html" id="leftBar">
    <a class="layui-btn layui-btn-sm" lay-event="print">
        <i class="layui-icon layui-icon-print"></i>打印单号
    </a>
    <a class="layui-btn layui-btn-sm layui-btn-normal" lay-event="inputExpressNo">
        <i class="layui-icon layui-icon-edit"></i>填写单号
    </a>
    <a class="layui-btn layui-btn-sm" lay-event="search">
        <i class="layui-icon layui-icon-search"></i>查询
    </a>
</script>

<script type="text/template" id="refundDetail">
    <form class="layui-form" id="form3" style="margin-top: 1rem;">
        <div class="layui-form-item" style="width: 350px;">
            <label class="layui-form-label">退款单号</label>
            <div class="layui-input-block">
                <input type="text" id="refundNo" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item" style="width: 350px;">
            <label class="layui-form-label">退款快递号</label>
            <div class="layui-input-block">
                <input type="text" id="refundExpressNo" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item" style="width: 350px;">
            <label class="layui-form-label">退款金额</label>
            <div class="layui-input-block">
                <input type="number" id="showRefundAmt" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item" style="width: 350px;">
            <label class="layui-form-label">退款时间</label>
            <div class="layui-input-block">
                <input type="text" id="showRefundTime" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item" style="width: 350px;">
            <label class="layui-form-label">退款原因</label>
            <div class="layui-input-block">
                <textarea placeholder="退款原因" id="showRefundReason" autocomplete="off" class="layui-textarea"></textarea>
            </div>
        </div>
        <div class="layui-form-item" style="width: 350px;">
            <label class="layui-form-label">退款备注</label>
            <div class="layui-input-block">
                <textarea placeholder="退款备注" id="refundRemark" autocomplete="off" class="layui-textarea"></textarea>
            </div>
        </div>
    </form>
</script>

<script type="text/template" id="inputExpressNo">
    <form class="layui-form" id="form4" style="margin-top: 1rem;">
        <div class="layui-form-item" style="width: 350px;">
            <label class="layui-form-label">快递单号</label>
            <div class="layui-input-block">
                <input type="text" id="expressNo" autocomplete="off" class="layui-input">
            </div>
        </div>
    </form>
</script>

<script type="text/template" id="appointDevice">
    <form class="layui-form" id="form5" style="margin-top: 1rem;">
        <div class="layui-form-item" style="width: 500px;">
            <label class="layui-form-label">设备名称</label>
            <div class="layui-input-block">
                <input type="text" id="name" autocomplete="off" class="layui-input" readonly>
            </div>
        </div>
        <div class="layui-form-item" style="width: 500px;">
            <label class="layui-form-label">设备数量</label>
            <div class="layui-input-block">
                <input type="text" id="num" autocomplete="off" class="layui-input" readonly>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">设备SN号</label>
            <div class="layui-input-inline">
                <input type="text" id="startSnNo" autocomplete="off" class="layui-input">
            </div>
            <div class="layui-input-inline">
                <input type="text" id="endSnNo" autocomplete="off" class="layui-input">
            </div>
        </div>
    </form>
</script>

<script type="text/html" id="toolBar">
    {{# if (d.status == "02") { }}
    <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="refundReject">
        <i class="layui-icon layui-icon-close-fill"></i>驳回
    </a>
    {{# if (d.expressNo == null || d.expressNo == "") { }}
    <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="refundDirect">
        <i class="layui-icon layui-icon-ok"></i>仅退款
    </a>
    {{# } else if (d.refundExpressNo == null || d.refundExpressNo == ""){ }}
    <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="agreeRefund">
        <i class="layui-icon layui-icon-ok"></i>同意退货
    </a>
    {{# } }}
    {{# } }}
    {{# if (d.status == "13") { }}
    <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="refundReject">
        <i class="layui-icon layui-icon-close-fill"></i>驳回
    </a>
    {{# } }}

    {{# if (d.status != "00" || d.status != "02" || d.status != '03') { }}
    <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="refund">
        <i class="layui-icon layui-icon-ok"></i>退款
    </a>
    {{# } }}

    {{# if (d.status == "03") { }}
    <a class="layui-btn layui-btn-xs" lay-event="refundDetail">
        <i class="layui-icon layui-icon-list"></i>退款详情
    </a>
    {{# } }}
    {{# if (d.status == "05" || d.status == "06") { }}
    <a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="showExpressDetail">
        <i class="layui-icon layui-icon-list"></i>物流详情
    </a>
    {{# } }}
    {{# if ( (d.status == "02" || d.status == "03" || d.status == "04") && d.picList.length > 0) { }}
    <a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="showPicList">
        <i class="layui-icon layui-icon-list"></i>图片
    </a>
    {{# } }}
</script>

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

        let tableIns = table.render({
            elem: '#mercOrderDetailTab'
            , url: ctx + '/mercOrderDetail/pageInfo'
            , id: 'mercOrderDetail'
            , response: {
                statusName: 'code' //数据状态的字段名称，默认：code
                , countName: 'count' //数据总数的字段名称，默认：count
                , dataName: 'data' //默数据列表的字段名称，认：data
                , statusCode: 200
            }
            , parseData: function (res) { //res 即为原始返回的数据
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.message, //解析提示文本
                    "count": res.data.total, //解析数据长度
                    "data": res.data.records //解析数据列表
                };
            }
            ,done: function(res, curr, count){
                $(".layui-table-main tr").each(function (index, val) {
                    $($(".layui-table-fixed-l .layui-table-body tbody tr")[index]).height($(val).height());
                    $($(".layui-table-fixed-r .layui-table-body tbody tr")[index]).height($(val).height());
                })
            }
            , toolbar: '#leftBar' //开启头部工具栏，并为其绑定左侧模板
            , title: '新版订单详情表'
            , cols: [[
                {type: 'checkbox', fixed: 'left', hidden: true}
                , {
                    field: 'userId', title: 'ID/角色', width: 85, templet: function (d) {
                        let userId = d.userId;
                        let roleName = d.roleCode == 'ZY_BST' ? '倍斯特' : '官方';
                        return userId + "<br/>" + roleName;
                    }
                }
                , {field: 'name', title: '规格/商品/订单号', width: 160,templet:function (d){
                    return "<span class='ellipsis'>" +d.specName+ "</span><br/>" +"<span class='ellipsis'>" +d.name+ "</span><br/>" + d.orderNo;
                    }}
                , {
                    title: '总价(含邮费)/邮费', width: 150, templet: function (d) {
                        return (d.price * d.num + d.postage).toFixed(2) + "<br/>" + d.postage.toFixed(2);
                    }
                }
                , {
                    field: 'price', title: '单价/数量', width: 100, templet: function (d) {
                        return d.price.toFixed(2) + "<br/>" + d.num;
                    }
                }
                , {
                    field: 'alias', title: '商户简称', width: 170, templet: function (d) {
                        if(d.merchant && d.merchant.alias){
                            return d.merchant.alias;
                        }
                        return '-';
                    }
                }
                , {
                    field: 'receiver', title: '收货人信息', width: 170, templet: function (d) {
                        return d.order.receiver +"&nbsp;"+ d.order.phone + "<br/><span class='ellipsis'>" +(d.order.areaName.replaceAll('-',''))+d.order.address + "</span>";
                    }
                }
                , {field: 'logistNo', title: '物流/快递单号', width: 150,templet:function (d){
                    let text = "";
                    let flag = false;
                    if(d.logistNo){
                        text += d.logistNo;
                        flag = true;
                    }
                    if(d.expressNo){
                        if(flag){
                            text += "<br/>";
                        }
                        text += d.expressNo;
                    }
                    return text;
                }}
                , {field: 'refundExpressNo', title: '退款快递号', width: 150}
                , {
                    field: 'createTime',
                    title: '时间',
                    width: 150,
                    templet: "<div>{{layui.util.toDateString(d.createTime,'yyyy-MM-dd HH:mm')}}</div>"
                }
                , {field: 'expressStatusDesc', fixed: 'right', width: 100, title: '物流状态'}
                , {
                    field: 'status', title: '订单状态', width: 90, fixed: 'right', templet: function (d) {
                        if (d.status == "00") {
                            return "待支付";
                        }
                        if (d.status == "01") {
                            return "<span style='color: green'>已支付</span>";
                        }
                        if (d.status == "02") {
                            return "<span style='color: #ff4400'>发起退货</span>";
                        }
                        if (d.status == "12") {
                            return "<span style='color: #ff4400'>已同意退款</span>";
                        }
                        if (d.status == "13") {
                            return "<span style='color: #ff4400'>等待退款中</span>";
                        }
                        if (d.status == "03") {
                            return "<span style='color: #0fcff1'>退款成功</span>";
                        }
                        if (d.status == "04") {
                            return "<span style='color: red'>退款失败</span>";
                        }
                        if (d.status == "05") {
                            return "<span style='color: blue'>待收货</span>";
                        }
                        if (d.status == "06") {
                            return "<span style='color: #6ff602'>已完成</span>";
                        }
                        if (d.status == "07") {
                            return "<span style='color: #f14c04'>部分退款</span>";
                        }
                    }
                }
                , {title: '操作', fixed: 'right', width: 120, toolbar: '#toolBar'}
            ]]
            , request: {
                pageName: 'current' //页码的参数名称，默认：page
                , limitName: 'size' //每页数据量的参数名，默认：limit
            }
            , page: true
        });
        form.on('select(refundStatus)', function (data) {
            let value = data.value;
            $(".refund-status").hide();
            $(".refund-status-" + value).show();
        })

        table.on('tool(mercOrderDetailTab)', function (obj) { //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            if (layEvent === 'refundDirect') { //退款
                let index = layer.open({
                    type: 1,
                    title: '仅退款',
                    shade: 0.5,
                    maxmin: true,
                    area: ['400', '550'],
                    btn: ['确认', '取消'],
                    content: $("#refund").html(),
                    success: function (d) {
                        form.render("select");
                        $("#refundAmt").val(data.refundAmt.toFixed(2));
                        $("#refundExpressNo").val(data.refundExpressNo);
                        $("#refundReason").val(data.refundReason);
                        $("#id").val(data.id);
                    },
                    yes: function (index, layero) {
                        let op = $("#refundStatus").val();
                        let mk = $("#rejectRemark").val();
                        let id = data.id;
                        let rm = $("#refundAmt").val();
                        let ph = $("#phone").val();
                        let vc = $("#verifyCode").val();
                        if (!op) {
                            return layer.msg("请先选择审核状态");
                        }
                        if (op == '1') {
                            if (!ph) {
                                return layer.msg("请选择发送验证码的手机号");
                            }
                            if (!vc) {
                                return layer.msg("请输入验证码");
                            }
                        }
                        if (op == '2' && !mk) {
                            return layer.msg("审核驳回，需填写驳回原因");
                        }
                        let d = {
                            id: id,
                            status: op == '1' ? '03' : '04',
                            rejectRemark: mk,
                            refundAmt: rm,
                            phone: ph,
                            verifyCode: vc
                        };
                        refundSubmit(d, index);
                    },
                    btn2: function (index, layero) {
                        layer.close(index);
                    },
                });
            } else if (layEvent === "agreeRefund") {
                // TODO 同意退货
                layer.confirm("同意退货", {icon: 3}, function () {
                    $.ajax({
                        url: ctx + "/mercOrderDetail/refundAgree",
                        type: 'post',
                        data: data,
                        success: (res) => {
                            parent.layer.msg(res.message);
                        }
                    })
                });
            } else if (layEvent === "refund") {
                // TODO 退货退款
                let index = layer.open({
                    type: 1,
                    title: '退货退款',
                    shade: 0.5,
                    maxmin: true,
                    area: ['400px', '550px'],
                    btn: ['确认', '取消'],
                    content: $("#refund").html(),
                    success: function (d) {
                        form.render("select");
                        $("#refundAmt").val(data.refundAmt.toFixed(2));
                        $("#refundExpressNo").val(data.refundExpressNo);
                        $("#refundReason").val(data.refundReason);
                        $("#id").val(data.id);
                    },
                    yes: function (index, layero) {
                        let op = $("#refundStatus").val();
                        let mk = $("#rejectRemark").val();
                        let id = data.id;
                        let rm = $("#refundAmt").val();
                        let ph = $("#phone").val();
                        let vc = $("#verifyCode").val();
                        if (!op) {
                            return layer.msg("请先选择审核状态");
                        }
                        if (op == '1') {
                            if (!ph) {
                                return layer.msg("请选择发送验证码的手机号");
                            }
                            if (!vc) {
                                return layer.msg("请输入验证码");
                            }
                        }
                        if (op == '2' && !mk) {
                            return layer.msg("审核驳回，需填写驳回原因");
                        }
                        let d = {
                            id: id,
                            status: op == '1' ? '03' : '04',
                            rejectRemark: mk,
                            refundAmt: rm,
                            phone: ph,
                            verifyCode: vc
                        };
                        refundSubmit(d, index);
                    },
                    btn2: function (index, layero) {
                        layer.close(index);
                    },
                });
            } else if (layEvent === "refundReject") {
                // TODO 拒绝退款
                layer.open({
                    type: 2,
                    title: '拒绝退款',
                    shade: 0.5,
                    maxmin: true,
                    area: ['400px', '400px'],
                    content: ctx + "/mercOrderDetail/refundReject/" + data.id
                });
            } else if (layEvent === 'refundDetail') {
                let index = layer.open({
                    type: 1,
                    title: '退款详情',
                    shade: 0.5,
                    maxmin: true,
                    area: ['400', '550'],
                    content: $("#refundDetail").html(),
                    success: function (d) {
                        $("#refundNo").val(data.refundNo);
                        $("#showRefundAmt").val(data.refundAmt.toFixed(2));
                        $("#showRefundTime").val(data.refundTime);
                        $("#refundExpressNo").val(data.refundExpressNo);
                        $("#showRefundReason").val(data.refundReason);
                        $("#refundRemark").val(data.refundRemark);
                    },
                });
            } else if (layEvent === 'showPicList') {
                let picList = data.picList;
                let obj = {title: "投诉图片详情", id: 1, start: 0};
                let d = [];
                $.each(picList, function (k, v) {
                    let pd = {"alt": "投诉图片", "pid": k, "src": v};
                    d.push(pd);
                })
                obj.data = d;
                layer.photos({
                    photos: obj
                    , anim: 5 //0-6的选择，指定弹出图片动画类型，默认随机（请注意，3.0之前的版本用shift参数）
                });
            } else if (layEvent === 'showExpressDetail') {
                if (data.expressNo === "" || data.expressNo == null) {
                    layer.msg("暂无物流信息");
                    return;
                }

                let url = ctx + '/mercOrderExpressDetail/index?expressNo=' + data.expressNo;
                let index = layer.open({
                    type: 2,
                    title: '物流详情',
                    shade: 0.5,
                    maxmin: true,
                    area: ['90%', '90%'],
                    content: url
                });
            }
        });

        /**
         * 发起退款操作
         * @param obj
         */
        function refundSubmit(obj, index) {
            var dialog = layer.msg('加载中...', {icon: 16, time: 0, shade: [0.3, '#000', false]});
            let url = ctx + "/mercOrderDetail/auditRefund";
            $.ajax({
                url: url,
                type: 'post',
                data: obj,
                success: (res) => {
                    layer.close(dialog);
                    if (res.code == 200) {
                        layer.close(index);
                        tableIns.reload();
                    }
                    layer.msg(res.message, {
                        icon: res.code == 200 ? 1 : 2
                    });
                }
            })
        }

        //监听头工具栏事件
        table.on('toolbar(mercOrderDetailTab)', function (obj) {
            var checkStatus = table.checkStatus('mercOrderDetail');
            let data = checkStatus.data;
            switch (obj.event) {
                case 'search':
                    var params = serialize($('#form1'));
                    table.reload('mercOrderDetail', {
                        where: params
                        , page: {
                            size: 10
                            , current: 1
                        }
                    });
                    break;
                case 'print':
                    if (data.length == 0) {
                        return layer.msg("至少选中一行数据");
                    }
                    let title = "确定打印物流单号吗？";
                    if (data.length > 1) {
                        title = "选中多条数据时会打印合并成一条快递物流数据,若所选订单中包含收货地址不同的,请勿一起打印！";
                    }
                    let flag = false;
                    let ids = [];
                    $.each(data, function (k, v) {
                        if (v.status != '01') {
                            flag = true;
                            return;
                        }
                        ids.push(v.id);
                    })
                    if (flag) {
                        return layer.msg("只能处理已支付的订单！");
                    }
                    let confirm = layer.confirm(title, {icon: 3}, function (index) {
                        let url = ctx + "/mercOrderDetail/print";
                        var dialog = layer.msg('加载中...', {icon: 16, time: 0, shade: [0.3, '#000', false]});
                        $.post(url, {ids: ids}, function (res) {
                            layer.close(dialog);
                            layer.close(confirm);
                            if (res.code == 200) {
                                tableIns.reload();
                            }
                            layer.msg(res.message, {
                                icon: res.code == 200 ? 1 : 2
                            });
                        })
                    });
                    break;
                case "inputExpressNo":
                    if (data.length == 0) {
                        return layer.msg("至少选中一行数据");
                    }
                    if (data.length >= 2) {
                        return layer.msg("最多选中一行数据");
                    }
                    let id = data[0].id;
                    let index = layer.open({
                        type: 1,
                        title: '填写快递单号',
                        shade: 0.5,
                        maxmin: true,
                        area: ['400', '200'],
                        content: $("#inputExpressNo").html(),
                        btn: ["确认", "取消"],
                        yes: function (res) {
                            var dialog = layer.msg('加载中...', {icon: 16, time: 0, shade: [0.3, '#000', false]});
                            let url = ctx + "/mercOrderDetail/inputExpressNo";
                            let expressNo = $("#expressNo").val();
                            if (!expressNo) {
                                return layer.msg("请输入快递物流单号");
                            }
                            let params = {id: id, expressNo: expressNo};
                            $.ajax({
                                url: url,
                                data: params,
                                type: 'post',
                                success: function (res) {
                                    layer.close(index);
                                    layer.close(dialog);
                                    if (res.code == 200) {
                                        tableIns.reload();
                                    }
                                    layer.msg(res.message, {
                                        icon: res.code == 200 ? 1 : 2
                                    });
                                }
                            })
                        }
                    });
                    break;
            }
        });
    });

    /**
     * 获取验证码
     */
    function getVerifyCode() {
        let phone = $("#phone").val();
        if (!phone) {
            return layer.msg("请先选择发送验证码的手机号")
        }
        let url = ctx + "/mercOrderDetail/getVerifyCode";
        var dialog = layer.msg('加载中...', {icon: 16, time: 0, shade: [0.3, '#000', false]});
        $.post(url, {phone: phone}, function (res) {
            layer.close(dialog);
            layer.msg(res.message, {
                icon: res.code == 200 ? 1 : 2
            });
        })
    }

    function reloadTable() {
        tableIns.reload();
    }
</script>
</body>
</html>
