<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('订单列表')"/>
    <th:block th:include="include :: layout-latest-css"/>
    <th:block th:include="include :: ztree-css"/>
    <th:block th:include="include :: datetimepicker-css" />

    <style>
        #orderSearchBtnGroup {
            margin-top: 10px;
        }

        #allOrServing {
            width: 70px;
            padding: 6px 9px;
            height: 33px;
            font-size: 14px;
            border: 1px solid #e5e6e7;
            background: #fff none;
            border-radius: 4px;
            vertical-align: middle;
        }

        .flex-board {
            display: flex;
            flex-wrap: wrap;
            justify-content: flex-start;
            align-items: center;
        }

        .flex-board-no-wrap {
            display: flex;
            justify-content: flex-start;
            align-items: center;
        }

        .cx-select-input {
            width: 100px;
        }

        .normal-select-input {
            width: 100px;
        }

        .normal-input {
            width: 100px;
        }

        .long-input {
            width: 400px;
        }

        .active-condition-btn {
            background-color: #1c84c6;
            border-color: #1c84c6;
            color: #fff;
        }
    </style>
</head>
<body class="gray-bg">

<div class="ui-layout-center">
    <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="order-form" class="m">
                    <input type="hidden" id="deptId" name="deptId">
                    <input type="hidden" id="parentId" name="parentId">
                    <input type="hidden" id="orderStatus" name="orderStatus"/>
                    <div class="condition-btn">
                        <select id="allOrServing">
                            <option value="">全部</option>
                            <option value="">在途</option>
                        </select>
                        <a class="btn btn-default btn-outline" onclick="selectConditionBtn(this, {orderStatusName : '待付款', sysPayStatus: 0})">
                            待付款
                            (<span id="nonPaidOrderNum">0</span>)
                        </a>
                        <a class="btn btn-default btn-outline" onclick="selectConditionBtn(this, {orderStatusName : '待约单', orderStatus: 1, isCall : '01'})">
                            待约单
                            (<span id="notCallOrderNum">0</span>)
                        </a>
                        <a class="btn btn-default btn-outline" onclick="selectConditionBtn(this, {orderStatusName : '待排期', orderStatus: 1, isCall : '02'})">
                            待排期
                            (<span id="notSetTimeOrderNum">0</span>)
                        </a>
                        <a class="btn btn-default btn-outline" onclick="selectConditionBtn(this, {orderStatusName : '待上门', orderStatus: 2})">
                            待上门
                            (<span id="waitForDoorOrderNum">0</span>)
                        </a>
                        <a class="btn btn-default btn-outline" onclick="selectConditionBtn(this, {orderStatusName : '进行中', orderStatus: 3})">
                            进行中
                            (<span id="servingOrderNum">0</span>)
                        </a>
                        <a class="btn btn-default btn-outline" onclick="selectConditionBtn(this, {orderStatusName : '确认审核', orderStatus: 4})">
                            确认审核
                            (<span class="confirmingOrderNum">0</span>)
                        </a>
                        <a class="btn btn-default btn-outline" onclick="selectConditionBtn(this, {orderStatusName : '完成', orderStatus: 5})">
                            完成
                            (<span id="finishedOrderNum">0</span>)
                        </a>
                        <a class="btn btn-default btn-outline" onclick="selectConditionBtn(this, {orderStatusName : '关闭', orderStatus: 6})">
                            关闭
                            (<span id="canceledOrderNum">0</span>)
                        </a>
                        <a class="btn btn-default btn-outline" onclick="selectOnDoorOrderToday(this)">
                            今日待上门
                            (<span id="todayOrderNum">0</span>)
                        </a>
                        <a class="btn btn-default btn-outline" onclick="selectOnDoorOrderTomorrow(this)">
                            明日待上门
                            (<span id="tomorrowOrderNum">0</span>)
                        </a>
                        <a class="btn btn-default btn-outline" onclick="selectConditionBtn(this, {orderStatusName : '售后', searchAfterList: true})">
                            售后
                            (<span id="afterServiceOrderNum">0</span>)
                        </a>
                        <a class="btn btn-default btn-outline" onclick="selectConditionBtn(this, {orderStatusName : '急报中', orderStatus: -1})">
                            急报中
                            (<span>0</span>)
                        </a>
                        <a class="btn btn-default btn-outline" onclick="selectConditionBtn(this, {orderStatusName : '退单', orderStatus: -1})">
                            退单
                            (<span>0</span>)
                        </a>
                        <a class="btn btn-default btn-outline" onclick="selectConditionBtn(this, {orderStatusName : '售后纠纷', orderStatus: -1})">
                            售后纠纷
                            (<span>0</span>)
                        </a>
                    </div>
                    <div class="flex-board">
                        <div class="flex-board m-t">
                            区域筛选：
                            <div id="areaCxSelect" class="flex-board-no-wrap">
                                <select class="province form-control cx-select-input m-r" name="province" id="province" data-first-title="选择省" onchange="selectRegion('province', 'city')"></select>
                                <select class="city form-control cx-select-input m-r" name="city" id="city" data-first-title="选择市" onchange="selectRegion('city', 'district')"></select>
                                <select class="district form-control cx-select-input m-r" name="district" id="district" data-first-title="选择区" onchange="selectRegion('district', 'street')"></select>
                                <select class="street form-control cx-select-input m-r" name="streetId" id="streetId" data-first-title="选择街道" ></select>
                            </div>
                        </div>
                        <div class="flex-board m-t">
                            创建时间：
                            <div class="input-group date">
                                <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                                <input id="createTimeStart" type="text" class="form-control date-input" placeholder="开始日期" readonly>
                            </div>
                            至
                            <div class="input-group date m-r">
                                <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                                <input id="createTimeEnd" type="text" class="form-control date-input" placeholder="结束日期" readonly>
                            </div>
                        </div>
                        <div class="flex-board m-t">
                            服务时间：
                            <div class="input-group date">
                                <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                                <input id="workBeginTimeStart" type="text" class="form-control date-input" placeholder="开始日期" readonly>
                            </div>
                            至
                            <div class="input-group date m-r">
                                <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                                <input id="workBeginTimeEnd" type="text" class="form-control date-input" placeholder="结束日期" readonly>
                            </div>
                        </div>
                        <div class="flex-board m-t">
                            完成时间：
                            <div class="input-group date">
                                <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                                <input id="workFinishTimeStart" type="text" class="form-control date-input" placeholder="开始日期" readonly>
                            </div>
                            至
                            <div class="input-group date m-r">
                                <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                                <input id="workFinishTimeEnd" type="text" class="form-control date-input" placeholder="结束日期" readonly>
                            </div>
                        </div>
                        <div class="flex-board m-t">
                            类别筛选：
                            <div id="categoryCxSelect" class="flex-board-no-wrap">
                                <select class="category1 form-control cx-select-input m-r" name="category1" id="category1" data-first-title="选择一类"></select>
                                <select class="category2 form-control cx-select-input m-r" name="category2" id="category2" data-first-title="选择二类"></select>
                                <select class="category3 form-control cx-select-input m-r" name="category3" id="category3" data-first-title="选择三类"></select>
                                <select class="category4 form-control cx-select-input m-r" name="category4" id="category4" data-first-title="选择四类" ></select>
                            </div>
                        </div>
<!--                        <div class="flex-board-no-wrap m-t">-->
<!--                            <label class="form-control-label">后台人员：</label>-->
<!--                            <input type="text" class="form-control normal-input m-r">-->
<!--                        </div>-->
                        <div class="flex-board-no-wrap m-t">
                            <label class="form-control-label">商家名称：</label>
                            <input id="storeName" type="text" class="form-control normal-input m-r">
                        </div>
                        <div class="flex-board-no-wrap m-t">
                            <label class="form-control-label">商家电话：</label>
                            <input id="storePhone" type="text" class="form-control normal-input m-r">
                        </div>
                        <div class="flex-board-no-wrap m-t">
                            <label class="form-control-label">接单师傅名称：</label>
                            <input id="workerName" type="text" class="form-control normal-input m-r">
                        </div>
                        <div class="flex-board-no-wrap m-t">
                            <label class="form-control-label">接单师傅电话：</label>
                            <input id="workerPhone" type="text" class="form-control normal-input m-r">
                        </div>
<!--                        <div class="flex-board-no-wrap m-t">-->
<!--                            <label class="form-control-label">师傅类型：</label>-->
<!--                            <select class="form-control normal-select-input m-r">-->
<!--                                <option value="">全部</option>-->
<!--                                <option value="">大师傅</option>-->
<!--                                <option value="">小师傅</option>-->
<!--                            </select>-->
<!--                            <input type="text" class="form-control normal-input m-r" placeholder="师傅姓名电话">-->
<!--                        </div>-->
                        <div class="flex-board-no-wrap m-t">
                            <label class="form-control-label">订单模式：</label>
                            <select id="orderMode" class="form-control normal-select-input m-r" onchange="changeOrderMode(this.options[this.options.selectedIndex].value)">
                                <option value="0">全部</option>
                                <option value="B2B">B2B</option>
                                <option value="B2C">B2C</option>
                            </select>
                            <select id="B2BOptions" class="form-control normal-select-input m-r">
                                <option value="">全部</option>
                                <option value="">常规单</option>
                                <option value="">赠送单</option>
                                <option value="">合规单</option>
                            </select>
                            <select id="B2COptions" class="form-control normal-select-input m-r">
                                <option value="">全部</option>
                                <option value="">商品配件类目</option>
                                <option value="">服务类目</option>
                                <option value="">社区类目</option>
                            </select>
                        </div>
                        <div class="flex-board-no-wrap m-t">
                            <label class="form-control-label">订单标签：</label>
                            <select class="form-control normal-select-input m-r">
                                <option value="">全部</option>
                            </select>
                        </div>
                        <div class="flex-board-no-wrap m-t">
                            <label class="form-control-label">订单查询：</label>
                            <input id="keyWords" type="text" class="form-control long-input m-r" placeholder="请输入订单号、姓名、电话或地址、品牌、规格">
                        </div>
                        <div class="m-t">
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="searchByForm()"><i
                                class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="resetForm()"><i
                                class="fa fa-refresh"></i>&nbsp;重置</a>
                        </div>
                    </div>
                    <div class="m-t condition-btn">
                        <a class="btn btn-default btn-outline" onclick="selectConditionBtn(this, {orderStatus: 0})">
                            新订单
                            (<span id="newOrderNum">0</span>)
                        </a>
                        <a class="btn btn-default btn-outline" onclick="selectConditionBtn(this, {timeout: 1, orderStatus: 0})">
                            接单超时
                            (<span id="newTimeoutOrderNum">0</span>)
                        </a>
                        <a class="btn btn-default btn-outline" onclick="selectConditionBtn(this, {timeout: 1, orderStatus: 1, isCall: '01'})">
                            约单超时
                            (<span id="acceptedTimeoutOrderNum">0</span>)
                        </a>
                        <a class="btn btn-default btn-outline" onclick="selectConditionBtn(this, {timeout: 1, orderStatus: 1, isCall: '02'})">
                            排单超时
                            (<span id="plainTimeoutOrderNum">0</span>)
                        </a>
                        <a class="btn btn-default btn-outline" onclick="selectConditionBtn(this, {orderStatus: -1})">
                            无法排单
                            (<span>0</span>)
                        </a>
                        <a class="btn btn-default btn-outline" onclick="selectConditionBtn(this, {timeout: 1, orderStatus: 2})">
                            待上门超时
                            (<span id="waitForDoorTimeoutOrderNum">0</span>)
                        </a>
                        <a class="btn btn-default btn-outline" onclick="selectConditionBtn(this, {timeout: 1, orderStatus: 3})">
                            进行超时
                            (<span id="servingTimeoutOrderNum">0</span>)
                        </a>
                        <a class="btn btn-default btn-outline" onclick="selectConditionBtn(this, {orderStatus: -1})">
                            售后超时
                            (<span>0</span>)
                        </a>
                        <a class="btn btn-default btn-outline" onclick="selectConditionBtn(this, {orderStatus: -1})">
                            客诉中
                            (<span>0</span>)
                        </a>
                        <a class="btn btn-default btn-outline" onclick="selectConditionBtn(this, {orderStatus: 4})">
                            审核中
                            (<span class="confirmingOrderNum">0</span>)
                        </a>
                        <a class="btn btn-default btn-outline" onclick="selectConditionBtn(this, {orderStatus: -1})">
                            一票价未改价
                            (<span>0</span>)
                        </a>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <div class="btn-group-sm" role="group">
                    <a class="btn btn-warning" onclick="$.table.exportExcel()"
                       shiro:hasPermission="order:order:export">
                        <i class="fa fa-download"></i> 导出
                    </a>
<!--                    <a class="btn btn-default" onclick="$.table.exportExcel()">-->
<!--                        <i class="fa fa-download"></i> 指派-->
<!--                    </a>-->
                </div>
            </div>

            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
</div>

<th:block th:include="include :: footer"/>
<th:block th:include="include :: layout-latest-js"/>
<th:block th:include="include :: ztree-js"/>
<th:block th:include="include :: jquery-cxselect-js" />
<th:block th:include="include :: datetimepicker-js" />
<script th:inline="javascript">
    var payTypes = [[${@dict.getType('pay_type')}]];
    var orderTypes = [[${@dict.getType('goods_category_type')}]];
    var payStatus = [[${@dict.getType('pay_status')}]];
    var orderStatus = [[${@dict.getType('order_status')}]];

    var editFlag = [[${@permission.hasPermi('order:order:edit')}]];
    var prefix = ctx + "order/detail";
    var customParams = {};

    $(function () {
        var panehHidden = false;
        if ($(this).width() < 769) {
            panehHidden = true;
        }
        $('body').layout({initClosed: panehHidden, west__size: 185});
        // 回到顶部绑定
        if ($.fn.toTop !== undefined) {
            var opt = {
                win: $('.ui-layout-center'),
                doc: $('.ui-layout-center')
            };
            $('#scroll-up').toTop(opt);
        }
        queryOrderList();

        $.ajax({
            type: "POST",
            dataType:"json",
            url: ctx + "system/area/list",
            success: function (result) {
                if (result.code == web_status.SUCCESS) {
                    $('#areaCxSelect').cxSelect({
                        selects: ['province', 'city', 'district', 'street'],
                        jsonValue: 'areaId',
                        jsonName: 'areaName',
                        data: result.data
                    });
                } else {
                    $.modal.msgError("数据加载错误，请重试！")
                }
            }
        })

        $(".date-input").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        $.ajax({
            type: "POST",
            dataType:"json",
            url: ctx + "goods/deptcategory/app/list",
            data: JSON.stringify({deptId: 101, goodsCategoryId: 1}),
            contentType: 'application/json',
            success: function (result) {
                if (result.code == web_status.SUCCESS) {
                    $('#categoryCxSelect').cxSelect({
                        selects: ['category1', 'category2', 'category3', 'category4'],
                        jsonValue: 'deptGoodsCategoryId',
                        jsonName: 'goodsCategoryName',
                        jsonSub: 'child',
                        data: result.data
                    });
                } else {
                    $.modal.msgError("数据加载错误，请重试！")
                }
            }
        })

        changeOrderMode();

        <!-- 不同状态订单数量统计-->
        $.ajax({
            type: "GET",
            dataType:"json",
            url: prefix + '/differentStatus/count',
            success: function (result) {
                if (result.code == web_status.SUCCESS) {
                    $('#newOrderNum').text(result.data.newOrderNum);
                    $('#acceptedOrderNum').text(result.data.acceptedOrderNum);
                    $('#canceledOrderNum').text(result.data.canceledOrderNum);
                    $('.confirmingOrderNum').text(result.data.confirmingOrderNum);
                    $('#finishedOrderNum').text(result.data.finishedOrderNum);
                    $('#servingOrderNum').text(result.data.servingOrderNum);
                    $('#waitForDoorOrderNum').text(result.data.waitForDoorOrderNum);
                } else {
                    $.modal.msgError("数据加载错误，请重试！")
                }
            }
        })


        $.ajax({
            type: "GET",
            dataType:"json",
            data: {isCall: '01'},
            url: prefix + '/differentStatus/count',
            success: function (result) {
                if (result.code == web_status.SUCCESS) {
                    $('#notCallOrderNum').text(result.data.acceptedOrderNum);
                } else {
                    $.modal.msgError("数据加载错误，请重试！")
                }
            }
        })

        $.ajax({
            type: "GET",
            dataType:"json",
            data: {isCall: '02'},
            url: prefix + '/differentStatus/count',
            success: function (result) {
                if (result.code == web_status.SUCCESS) {
                    $('#notSetTimeOrderNum').text(result.data.acceptedOrderNum);
                } else {
                    $.modal.msgError("数据加载错误，请重试！")
                }
            }
        })


        $.ajax({
            type: "GET",
            dataType:"json",
            url: prefix + '/differentStatus/count',
            data: {timeout: 1},
            success: function (result) {
                if (result.code == web_status.SUCCESS) {
                    $('#newTimeoutOrderNum').text(result.data.newOrderNum);
                    $('#servingTimeoutOrderNum').text(result.data.servingOrderNum);
                    $('#waitForDoorTimeoutOrderNum').text(result.data.waitForDoorOrderNum);
                } else {
                    $.modal.msgError("数据加载错误，请重试！")
                }
            }
        })

        $.ajax({
            type: "GET",
            dataType:"json",
            url: prefix + '/differentStatus/count',
            data: {timeout: 1, isCall : '01'},
            success: function (result) {
                if (result.code == web_status.SUCCESS) {
                    $('#acceptedTimeoutOrderNum').text(result.data.acceptedOrderNum);
                } else {
                    $.modal.msgError("数据加载错误，请重试！")
                }
            }
        })

        $.ajax({
            type: "GET",
            dataType:"json",
            url: prefix + '/differentStatus/count',
            data: {timeout: 1, isCall : '02'},
            success: function (result) {
                if (result.code == web_status.SUCCESS) {
                    $('#plainTimeoutOrderNum').text(result.data.acceptedOrderNum);
                } else {
                    $.modal.msgError("数据加载错误，请重试！")
                }
            }
        })

        $.ajax({
            type: "GET",
            dataType:"json",
            url: prefix + '/count',
            data: {sysPayStatus: 0},
            success: function (result) {
                if (result.code == web_status.SUCCESS) {
                    $('#nonPaidOrderNum').text(result.data);
                } else {
                    $.modal.msgError("数据加载错误，请重试！")
                }
            }
        })

        var date = new Date();
        $.ajax({
            type: "GET",
            dataType:"json",
            url: prefix + '/count',
            data: {
                orderStatus: 2,
                expectTimeStart: date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate() + " 00:00:00",
                expectTimeEnd: date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate() + " 23:59:59"
            },
            success: function (result) {
                if (result.code == web_status.SUCCESS) {
                    $('#todayOrderNum').text(result.data);
                } else {
                    $.modal.msgError("数据加载错误，请重试！")
                }
            }
        })
        $.ajax({
            type: "GET",
            dataType:"json",
            url: prefix + '/count',
            data: {
                orderStatus: 2,
                expectTimeStart: date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + (date.getDate() + 1) + " 00:00:00",
                expectTimeEnd: date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + (date.getDate() + 1) + " 23:59:59"
            },
            success: function (result) {
                if (result.code == web_status.SUCCESS) {
                    $('#tomorrowOrderNum').text(result.data);
                } else {
                    $.modal.msgError("数据加载错误，请重试！")
                }
            }
        })

        $.ajax({
            type: "GET",
            dataType:"json",
            url: prefix + '/after/count',
            success: function (result) {
                if (result.code == web_status.SUCCESS) {
                    $('#afterServiceOrderNum').text(result.data);
                } else {
                    $.modal.msgError("数据加载错误，请重试！")
                }
            }
        })
    });

    function changeOrderMode(orderMode) {
        if (orderMode === 'B2B') {
            $("#B2BOptions").show();
            $("#B2COptions").hide();
        } else if (orderMode === 'B2C') {
            $("#B2BOptions").hide();
            $("#B2COptions").show();
        } else {
            $("#B2BOptions").hide();
            $("#B2COptions").hide();
        }
    }

    function showOrderWorker(id) {
        var url = "order/detail/orderWorker/" + id;
        $.modal.open("指派师傅", url, '800', '300');
    }

    function selectRegion(regionLevelName, nextRegionLevelName) {
        var regionId = $("#" + regionLevelName).val();
        if ($.common.isEmpty(regionId)) {
            return;
        }

        //Ajax调用处理
        $.ajax({
            type: "POST",
            dataType:"json",
            url: ctx + "system/area/list",
            data: {parentCode: regionId},
            success: function (result) {
                if (result.code == web_status.SUCCESS) {
                    $('#areaCxSelect').cxSelect({
                        selects: [nextRegionLevelName],
                        jsonValue: 'areaId',
                        jsonName: 'areaName',
                        data: result.data
                    });
                } else {
                    $.modal.msgError("数据加载错误，请重试！")
                }
            }
        })
    }

    function queryOrderList() {
        var options = {
            url: prefix + "/list",
            exportUrl: prefix + "/export",
            queryParams: queryParams,
            sortName: "createTime",
            sortOrder: "desc",
            modalName: "订单",
            columns: [
                {
                    checkbox: true
                },
                {
                    title: "序号",
                    formatter: function (value, row, index) {
                        return $.table.serialNumber(index);
                    }
                },
                {
                    field: 'id',
                    title: '订单ID',
                    visible: false
                },
                {
                    field: 'goods',
                    title: '订单信息',
                    formatter: function (value, row) {
                        return '<div style="display:flex;justify-content: center;align-items: center;">'
                            + '<img decoding="async" src="' + value.goodsImgUrl + '" width="100" height="100" />'
                            + '<div>'
                            + '<p> ' + row.code + '<p/>'
                            + '<p> ' + row.consoleGoodsName + '<p/>'
                            + '<p> 联系人：' + row.addressName + '</p>'
                            + '<p> 联系电话：' + row.addressPhone + '</p>'
                            + '<p> 联系地址：' + row.address + '</p>'
                            + '<p> 下单时间：' + row.createTime + '</p>'
                            + '<p> 预约时间：' + row.mixExpectTime + '</p>'
                            + '<p> 总金额：' + row.financialMasterMoney + '元    应得金额：' + row.financialDetailMoney + '元</p>'
                            + '</div>'
                            + '</div>';
                    }
                },
                {
                    field: 'orderStatus',
                    title: '订单状态',
                    align: 'center',
                    formatter: function (value, row, index) {
                        if(row.orderStatusName){
                            return row.orderStatusName;
                        }else {
                            return $.table.selectDictLabel(orderStatus, value);
                        }
                    }
                },
                {
                    field: 'goodsWorker',
                    title: '师傅接单信息',
                    formatter: function (value, row, index) {
                        if(value){
                            return '<p>' + value.name + '</p>'
                                + '<p>' + value.phone + '</p>';
                        }
                    }
                },
                {
                    field: 'worker',
                    title: '师傅做单信息',
                    formatter: function (value, row, index) {
                        if(value){
                            return '<p>' + value.name + value.phone + '</p>'
                                + '<p>接单时间：' + value.createTime + '</p>';
                        }
                    }
                },
                {
                    field: 'lastCallTime',
                    title: '最近联系时间'
                },
                {
                    title: '操作',
                    align: 'left',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs " href="javascript:void(0)" onclick="detail(\'' + row.id + '\')"><i class="fa fa-info"></i>查看</a> ');
                        actions.push('<a class="btn btn-success btn-xs " href="javascript:void(0)" onclick="callDetail(\'' + row.orderMasterId + '\')"><i class="fa fa-info"></i>拨号详情</a> ');
                        actions.push('<a class="btn btn-success btn-xs " href="javascript:void(0)" onclick="orderDetailReject(\'' + row.id + '\')"></i>师傅退单</a> ');
                        // actions.push('<a class="btn btn-success btn-xs " href="javascript:void(0)" onclick="orderMasterReject(\'' + row.orderMasterId + '\')"></i>商家退单</a> ');
<!--                        actions.push('<a class="btn btn-success btn-xs " href="javascript:void(0)" onclick="showOrderWorker(\'' + row.id + '\')"></i>指派</a> ');-->
                        if (row.payStatus == 0) {
                            actions.push('<a class="btn btn-success btn-xs " href="javascript:void(0)" onclick="showPayQrcode(\'' + row.id + '\')"></i>付款</a> ');
                        }
                        return actions.join('');
                    }
                },
                {
                    field: 'changeMoney',
                    title: '商家追加金额',
                    align: 'center'
                },
                {
                    field: 'orderImgs',
                    title: '完单图片'
                },
                {
                    field: 'orderType',
                    title: '订单类型',
                    align: 'center',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(orderTypes, value);
                    }
                },
                {
                    field: 'payType',
                    title: '付款类型',
                    align: 'center',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(payTypes, value);
                    }
                },
                {
                    field: 'payStatus',
                    title: '付款状态',
                    align: 'center',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(payStatus, value);
                    }
                },
                {
                    field: 'payTime',
                    title: '付款时间'
                }]
        };
        $.table.init(options);
    }

    function queryParams(params) {
        var search = $.table.queryParams(params);
        Object.assign(search, customParams)
        return search;
    }

    function detail(id) {
        var url = "order/goods?orderId=" + id;
        $.modal.open("商品信息", url);
    }

    function callDetail(id) {
        var url = "order/record?orderId=" + id;
        $.modal.open("拨号记录", url);
    }

    function orderDetailReject(id) {
        $.modal.confirm("确定要退单吗？", function() {
            const url = "detail/reject";
            const data = { "id": id };
            $.operate.post(url, data);
        });
    }
    function orderMasterReject(id) {
        $.modal.confirm("确定要退单吗？", function() {
            const url = "master/reject";
            const data = { "id": id };
            $.operate.post(url, data);
        });
    }

    function changeConditionBtnChosenStyle(e) {
        $('.condition-btn .btn').removeClass('active-condition-btn');
        if (e) {
            $(e).addClass('active-condition-btn');
        }
    }

    function selectConditionBtn(e, params = {}) {
        changeConditionBtnChosenStyle(e);
        searchOrderList(params)
    }

    function selectOnDoorOrderToday(e) {
        changeConditionBtnChosenStyle(e);
        var date = new Date();
        selectConditionBtn(e, {
            orderStatus: 2,
            expectTimeStart: date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate() + " 00:00:00",
            expectTimeEnd: date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate() + " 23:59:59"
        })
    }

    function selectOnDoorOrderTomorrow(e) {
        changeConditionBtnChosenStyle(e);
        var date = new Date();
        selectConditionBtn(e, {
            orderStatus: 2,
            expectTimeStart: date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + (date.getDate() + 1) + " 00:00:00",
            expectTimeEnd: date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + (date.getDate() + 1) + " 23:59:59"
        })
    }

    function searchOrderList(params) {
        customParams = params;
        $.table.search();
    }

    function searchByForm() {
        let params = {
            createTimeStart: $('#createTimeStart').val() ? $('#createTimeStart').val() + " 00:00:00" : undefined,
            createTimeEnd: $('#createTimeEnd').val() ? $('#createTimeEnd').val() + " 23:59:59" : undefined,
            workBeginTimeStart: $('#workBeginTimeStart').val(),
            workBeginTimeEnd: $('#workBeginTimeEnd').val() ? $('#workBeginTimeEnd').val() + " 23:59:59" : undefined,
            workFinishTimeStart: $('#workFinishTimeStart').val(),
            workFinishTimeEnd: $('#workFinishTimeEnd').val() ? $('#workFinishTimeEnd').val() + " 23:59:59" : undefined,
            storeName: $('#storeName').val(),
            storePhone: $('#storePhone').val(),
            workerName: $('#workerName').val(),
            workerPhone: $('#workerPhone').val(),
            keyWords: $('#keyWords').val()
        }

        customParams = Object.assign(customParams, params);
        $.table.search();
    }

    function resetForm() {
        $.form.reset();
        customParams = {};
        changeConditionBtnChosenStyle();
        $.table.search();
    }

    function showPayQrcode(id) {
        var url = "detail/payQrcode/" + id;
<!--        $.modal.open("支付二维码", url, 290, 360);-->
        layer.open({
            type: 2,
            area: ['290px', '360px'],
            fix: false,
            //不固定
            maxmin: true,
            shade: 0.3,
            title: '支付二维码',
            content: url,
            btn: ['关闭'],
            // 弹层外区域关闭
            shadeClose: true,
            cancel: function(index) {
                return true;
            }
        });
    }

    // 子订单全部
    var orderDetailsAfterUrl = "";
    // 子订单新订单
    var orderDetailsAfterSalesDisputeUrl = "";

    //请求接口加载页面输入框值
    function globalConfiginit(){
        $.ajax({
            type: "GET",
            dataType:"json",
            url: "/config/globalConfig/search/type/1001",
            data: { },
            success: function (data) {
                var response = JSON.parse(data.data.content);
                orderDetailsAfterUrl = response.orderDetailsAfterUrl;
                orderDetailsAfterSalesDisputeUrl = response.orderDetailsAfterSalesDisputeUrl;
            }
        })
    }

    //页面加载
    window.onload = function () {
        //请求接口加载页面输入框值
        globalConfiginit();
    }

    // 定义一个要延迟执行的函数
    function delayedFunction() {
        console.log("");
    }

    var totalOrderNumber = 0;
    var inServiceNumber = 0;
    var lastTotalOrderNumber = 0;
    var lastInServiceNumber = 0;

    function fetchData() {
        $.ajax({
            type: "GET",
            dataType: "json",
            url: "/order/detail/statistics/now",
            data: {},
            success: function (data) {
                // 更新当前值
                totalOrderNumber = data.data.totalOrderNumber;
                inServiceNumber = data.data.inServiceNumber;
                console.log(totalOrderNumber+"-----"+lastTotalOrderNumber );
                // 检查新值是否大于旧值
                if (totalOrderNumber > lastTotalOrderNumber) {
                    console.log("收到新子订单数据，开始播放。播放通知音频：" + orderDetailsAfterUrl);
                    // 获取source元素
                    var source = document.getElementById('myAudio');
                    // 设置新的音频文件路径
                    source.src = orderDetailsAfterUrl;
                    var audio = document.getElementById('myAudio');
                    audio.play().catch(function(error) {
                        console.log('播放失败：', error);
                    });
                }

                // 设置延迟时间为2000毫秒（2秒）
                setTimeout(delayedFunction, 2000);

                if (inServiceNumber > lastInServiceNumber) {
                    console.log("收到新子单数据，开始播放。播放通知音频：" + orderDetailsAfterSalesDisputeUrl);
                    // 获取source元素
                    var source = document.getElementById('myAudio');
                    // 设置新的音频文件路径
                    source.src = orderDetailsAfterSalesDisputeUrl;
                    var audio = document.getElementById('myAudio');
                    audio.play().catch(function(error) {
                        console.log('播放失败：', error);
                    });
                }

                // 更新上一次的值
                lastTotalOrderNumber = totalOrderNumber;
                lastInServiceNumber = inServiceNumber;
            }
        });
    }




    // 设置定时器，每隔一分钟执行一次 fetchData 函数
    setInterval(fetchData, 60000);


</script>
</body>

</html>
