@extends('layouts.app')
@section('title')问题件-查询@endsection

@section('content')
    @component("order.issue.menu")@endcomponent
    <div class="container-fluid" id="issue_div">
        <div style="min-width: 2000px;">
            <div id="list" class="d-none" style="min-width: 5000px">
                <div id="form_div" style="min-width: 2250px;" class="bg-white"></div>
                <div class="form-inline mt-1">
                    <span class="dropdown">
                        <button type="button" class="btn btn-outline-dark btn-sm form-control-sm dropdown-toggle tooltipTarget" :class="[checkData.length>0?'btn-dark text-light':'']"
                                data-toggle="dropdown" title="导出所有页将会以搜索条件得到的过滤结果，将其全部记录（每一页）导出">导出Excel
                        </button>
                        <div class="dropdown-menu">
                            <a class="dropdown-item" @click="orderIssueExport(false)" href="javascript:">导出勾选内容</a>
                            <a class="dropdown-item" @click="orderIssueExport(true)" href="javascript:">导出所有页</a>
                        </div>
                    </span>
                    <span class="ml-1">
                        <button type="button" class="btn btn-outline-dark btn-sm form-control-sm  tooltipTarget" @click="endOrderIssue()" :class="[checkData.length>0?'btn-dark text-light':'']">完结</button>
                    </span>
                    <span class="ml-1">
                        <button type="button" class="btn btn-outline-dark btn-sm form-control-sm  tooltipTarget" @click="copyOrderNo()" >复制快递单号</button>
                    </span>
                </div>
                <table class="table table-sm  table-bordered table-hover card-body "
                       style="background: #fff;">
                    <tr class="tr-yellow">
                        <th class="bg-white font-weight-bolder " colspan="6"></th>
                        <th class="td-yellow text-center font-weight-bolder original-class table-head-warning " colspan="16" >原始运单号</th>
{{--                        <th class=" text-center font-weight-bolder" colspan="3">原始商品明细</th><th class=" text-center font-weight-bolder" colspan="5">返回商品明细</th>--}}
                        <th class="bg-white text-center font-weight-bolder"  @cannot('客户不可见')colspan="22"@else colspan="23" @endcannot>情况说明</th>
                        <th></th>
                    </tr>

                    <tr class="tr-yellow">
                        <th  rowspan="2" class="align-middle">
                            <label for="all">
                                <input id="all" type="checkbox" @click="checkAll($event)"/>
                            </label>
                        </th>
                        <th class="text-center align-middle" rowspan="2">序号</th>
                        <th class="text-center align-middle" rowspan="2">ID</th>
                        <th class="text-center align-middle" rowspan="2">退件</th>
                        @can("订单管理-问题件-置顶")
                            <th class="text-center align-middle" style="width: 60px"  rowspan="2">置顶</th>
                        @endcan
                        <th class="text-center align-middle" rowspan="2">处理状态</th>
                        <th class="text-center align-middle td-yellow" rowspan="2">登记日期</th>
                        <th class="text-center align-middle td-yellow" rowspan="2">订单日期</th>
                        <th class="text-center align-middle td-yellow" rowspan="2">客户</th>
                        <th class="text-center align-middle td-yellow" rowspan="2">店铺</th>
                        <th class="text-center align-middle td-yellow" rowspan="2">原始订单号</th>
                        <th class="text-center align-middle td-yellow" rowspan="2">原始承运商</th>
                        <th class="text-center align-middle td-yellow" rowspan="2">原始运单号</th>
                        <th class="text-center align-middle td-yellow" rowspan="2" style="min-width: 90px">收货人名称</th>
                        <th class="text-center align-middle td-yellow" rowspan="2">收货人电话</th>
                        <th class="text-center align-middle td-yellow" rowspan="2" style="min-width: 70px">省</th>
                        <th class="text-center align-middle td-yellow" rowspan="2" style="min-width: 70px">市</th>
                        <th class="text-center align-middle td-yellow" rowspan="2" style="min-width: 70px">区</th>
                        <th class="text-center align-middle td-yellow" rowspan="2">收货人地址</th>
                        <th class="text-center align-middle text-center td-yellow" colspan="3">原始商品明细</th>
{{--                        <th class="">条码</th><th class="">商品名</th><th class="">数量</th>--}}
                        <th class="bg-white text-center align-middle" colspan="5">返回商品明细</th>
{{--                        <th class="">条码</th><th class="">商品名</th><th class="">数量</th><th class="">是否正品</th><th class="">备注</th>--}}
                        <th class="bg-white text-center align-middle" rowspan="2">退单状态</th>
                        <th class="bg-whit text-center align-middle" colspan="3">情况说明</th>
                        <th class="bg-white text-center align-middle" rowspan="2">问题类别</th>
                        <th class="bg-white text-center align-middle" rowspan="2">处理结果说明</th>
                        <th class="bg-white text-center align-middle" rowspan="2">二次订单号</th>
                        <th class="bg-white text-center align-middle" rowspan="2">二次承运商</th>
                        <th class="bg-white text-center align-middle" rowspan="2">二次运单号</th>
                        <th class="bg-white text-center" colspan="3">二次商品明细</th>
                        <th class="bg-white text-center align-middle" rowspan="2">最终转态</th>
                        @cannot('客户不可见')
                        <th class="bg-white text-center align-middle" rowspan="2">承运商赔偿金额</th>
                        @endcannot
                        <th class="bg-white text-center align-middle" rowspan="2">承运商快递减免</th>
                        <th class="bg-white text-center align-middle" rowspan="2">宝石赔偿金额</th>
                        <th class="bg-white text-center align-middle" rowspan="2">宝石快递减免</th>
                        <th class="bg-white text-center align-middle" rowspan="2">事故责任方</th>
                        <th class="text-center align-middle" rowspan="2">操作</th>
                    </tr>
                    <tr class="tr-yellow">
                        <th>条码</th><th>商品名</th><th>数量</th>
                        <th class="">条码</th><th>商品名</th><th>数量</th><th>是否正品</th><th>备注</th>
                        <th>操作类型</th><th>说明</th><th>操作者</th>
                        <th>条码</th><th>商品名</th><th>数量</th>
                    </tr>
                    <tr class="tr-yellow"
                        v-for="(orderIssue,index) in orderIssues"
                        @click="selectedColor(orderIssue.id)"
                        v-if="orderIssues"
                        :class="orderIssue.remark ? 'tr_top':''"
                        @click="selectedColor(waybill.id)"
                        v-on:mouseover="hidetop($event)" v-on:mouseleave="showtop($event)"
                        :style="[{'font-weight': orderIssue.id==selectedStyle?'bold':''}]">
                        <td >
                            <div class="m-0 p-0 " :style="[{'min-height':orderIssue.remark ?'72px':'45px'}]"><input class="checkItem" type="checkbox" :value="orderIssue.id" v-model="checkData"></div>
                        </td>
                        <td class="">@{{index+1}}</td>
                        <td class="">@{{ orderIssue.id }}</td>
                        <td class=" text-center">
                            @can('订单管理-问题件-编辑')
                                <button type="button" class="btn btn-sm btn-outline-secondary" @click="disposeOrderIssue($event)" :data-value="orderIssue.id" v-if="orderIssue.is_new_rejecting == '有'">有</button>
                                <span v-else>@{{ orderIssue.is_new_rejecting }}</span>
                            @else
                                <span v-if="orderIssue.is_new_rejecting">@{{ orderIssue.is_new_rejecting }}</span>
                            @endcan
                        </td>
                         @can("订单管理-问题件-置顶")
                        <td class=" text-muted text-center"  >
                            <button type="button" class="btn btn-sm btn-outline-danger "
                                    @click="cancelOnTop($event)" :data-value="orderIssue.top.id" style="opacity: 0.75" v-if="orderIssue.top">取消
                            </button>
                            <button type="button" class="btn btn-sm btn-outline-secondary"
                                    @click="OrderIssueOnTop($event)" :data-value="orderIssue.id" style="opacity: 0.75"  v-else>置顶
                            </button>
                        </td>
                        @endcan
                        </td>
                        <td class=" text-center">@{{ orderIssue.handle_status }}</td>
                        <td class="toptd td-yellow text-center" >
                            <div v-if="orderIssue.remark" class="bg-light-yellow  text-danger top text-left"  data-toggle="tooltip" style="opacity: 0.1;position: absolute;z-index: 1">置顶备注：@{{  orderIssue.remark }}</div>
                            @{{ orderIssue.created_at }}</td>
                        <td class="td-yellow text-center" >
                            @{{ orderIssue.order.created_at }}</td>
                        <td class="td-yellow text-center">
                            <span v-if='orderIssue.order.owner'>@{{ orderIssue.order.owner.name }}</span>
                        </td>
                        <td class="td-yellow text-center"><template v-if="orderIssue.order.shop">@{{ orderIssue.order.shop.name }}</template> </td>
                        <td class="td-yellow text-center">@{{ orderIssue.order.code }} </td>
                        <td class="td-yellow text-center">
                            <span v-if='orderIssue.order.logistic'>@{{ orderIssue.order.logistic.name }}</span>
                        </td>

                        <td class=" hide-content p-0 td-yellow text-center" :id="orderIssue.id+'logisticNumbers'" valign="middle" align="center">
                            <div class="collapse hide" :id="'logisticNumbers'+orderIssue.id">
                                <p v-for="logisticNumber in orderIssue.order.logisticNumbers" class="m-0 p-0 text-center text-muted ">@{{ logisticNumber }}</p>
                            </div>
                            <button v-if="orderIssue.order.logisticNumbers.length > 1" type="button"
                                    class="btn btn-sm btn-outline-primary  text-center align-middle mt-1"
                                    :id="'logisticNumbersBtn'+orderIssue.id"
                                    data-toggle="collapse"
                                    :data-target="'#logisticNumbers'+orderIssue.id"
                                    aria-expanded="false"
                                    :aria-controls="'logisticNumbers'+orderIssue.id"
                                    @click="toggleLogisticNumbers(orderIssue.id,orderIssue.order.logisticNumbers.length)">
                                分箱@{{ orderIssue.order.logisticNumbers.length }}件,点击展开
                            </button>
                        </td>
                        <td class="td-yellow text-center">@{{ orderIssue.order.consignee_name }}</td>
                        <td class="td-yellow text-center">@{{ orderIssue.order.consignee_phone }}</td>
                        <td class="td-yellow text-center">@{{ orderIssue.order.province }}</td>
                        <td class="td-yellow text-center">@{{ orderIssue.order.city }}</td>
                        <td class="td-yellow text-center">@{{ orderIssue.order.district }}</td>
                        <td class="td-yellow" style="width: 400px"><span class="text-wrap m-0 p-0 text-center" style="width: 400px">@{{ orderIssue.order.address }}</span></td>
                        <td class="td-yellow p-0" :id="orderIssue.id+'items'"  valign="middle" align="center" colspan="3">
                            <div v-if="orderIssue.order">
                                <table v-if="orderIssue.order.packages" class="table table-sm  m-0"  :class="orderIssue.order.packages.length > 1?'collapse':''"  :id="'order'+orderIssue.id" >
                                    <template v-for="packages in orderIssue.order.packages" >
                                        <tr v-for="item in packages.commodities">
                                            <td>@{{ item.commodity.sku }}</td>
                                            <td>@{{ item.commodity.name }}</td>
                                            <td>@{{ item.amount }}</td>
                                        </tr>
                                    </template>
                                </table>
                            <button v-if="orderIssue.order.packages.length > 1" type="button"
                                    class="btn btn-sm btn-outline-primary  text-center align-middle mt-1"
                                    :id="'orderBtn'+orderIssue.id"
                                    data-toggle="collapse"
                                    :data-target="'#order'+orderIssue.id"
                                    aria-expanded="false"
                                    :aria-controls="'order'+orderIssue.id"
                                    @click="toggleOrder(orderIssue.id,orderIssue.order.amount)" >商品@{{ orderIssue.order.amount }}件,点击展开
                            </button>
                            </div>
                        </td>
                        <td class="p-0" :id="orderIssue.id+'rejectedBill'"  valign="middle" align="center" colspan="5">
                            <div v-if="orderIssue.rejected_bill" class="m-0 p-0">
                                <table v-if="orderIssue.rejected_bill.items" class="table table-sm  m-0" :class="orderIssue.rejected_bill.items.length > 1?'collapse':''"  :id="'rejectedBill'+orderIssue.id">
                                    <tr v-for="item in orderIssue.rejected_bill.items" :data-value="orderIssue.rejected_bill.sum += item.amount">
                                        <td>@{{ item.barcode_goods }}</td>
                                        <td>@{{ item.name_goods }}</td>
                                        <td>@{{ item.amount }}</td>
                                        <td>@{{ item.validity_at }}</td>
                                        <td>@{{ item.remark }}</td>
                                    </tr>
                                </table>
                                <button v-if="orderIssue.rejected_bill.items > 1" type="button"
                                        class="btn btn-sm btn-outline-primary  text-center align-middle mt-1"
                                        :id="'rejectedBillBtn'+orderIssue.id"
                                        data-toggle="collapse"
                                        :data-target="'#rejectedBill'+orderIssue.id"
                                        aria-expanded="false"
                                        :aria-controls="'rejectedBill'+orderIssue.id"
                                        @click="toggleRejectedBill(orderIssue.id,orderIssue.logs.length)">
                                    商品@{{ orderIssue.logs.length }}件,点击展开</button>
                            </div>
                        </td>
                        <td class="bg-white text-center">@{{ orderIssue.rejecting_status }}</td>
                        <td class="bg-white m-0 p-0 log-td text-center" valign="middle" align="center" v-on:mouseover="showAddBtn($event)" v-on:mouseleave="hideAddBtn($event)"  colspan="3">

                            <div class="addLogDiv row m-0 p-0" :id="'AddLog_'+orderIssue.id" style="display: none">
                                <input type="hidden" name="id" :value="orderIssue.id" >
                                <div class="form-group m-2">
                                    <input type="text"  name="content" class="form-control" required>
                                </div>
                                <button type="btn" class="btn btn-primary m-2 " @click="addOrderIssueLog('AddLog_'+orderIssue.id)">添加</button>
                            </div>

                            <div  style="position: absolute;display: none;margin-left: -40px" class="add-btn">
                                <button type="button" class="btn  btn-outline-primary " @click="showAddDiv('AddLog_'+orderIssue.id)">新</button>
                            </div>

                            <template v-if="orderIssue.logs" class="p-0 m-0 ">
                                <table class="table table-sm p-0 m-0 " :id="'logs'+orderIssue.id" :class="orderIssue.logs.length > 1?'collapse':''">
                                    <tr v-for="log in orderIssue.logs" v-on:mouseover="showDelBtn($event)" v-on:mouseleave="hideDelBtn($event)" class="del-tr" style="position:static">
                                        <td>@{{ log.type }}</td>
                                        <td><p class="text-wrap mb-0" style="max-width: 200px">@{{ log.content }}</p> </td>
                                        <td>@{{ log.user.name }}</td>
                                        <td style="position: absolute;display: none;border: 0;" class="m-0 p-0 del-btn border-0" >
                                            <button type="button" class="btn btn-sm btn-outline-danger m-0 " @click="deleteOrderIssueLog(log.id,orderIssue.id)" >删</button>
                                        </td>
                                    </tr>
                                </table>
                                <button v-if="orderIssue.logs.length > 1" type="button"
                                        class="btn btn-sm btn-outline-primary  text-center align-middle mt-1"
                                        :id="'logsBtn'+orderIssue.id"
                                        data-toggle="collapse"
                                        :data-target="'#logs'+orderIssue.id"
                                        aria-expanded="false"
                                        :aria-controls="'logs'+orderIssue.id"
                                        @click="toggleLogs(orderIssue.id,orderIssue.logs.length)">
                                    记录共@{{ orderIssue.logs.length }}条,点击展开
                                </button>
                            </template>
                            </template>
                        </td>
                        <td class="bg-white">
                            <span v-if="orderIssue.issue_type">@{{ orderIssue.issue_type.name}}</span>
                        </td>
                        <td class="bg-white p-0 m-0">
                            @{{ orderIssue.result_explain}}
                        </td>
                        <td class="bg-white"><span v-if="orderIssue.second_order" class="p-0"> @{{ orderIssue.second_order.code }}</span></td>
                        <td class="bg-white"><span v-if="orderIssue.second_order" class="p-0"> @{{ orderIssue.second_order.logistic_id }}</span></td>
                        <td class="bg-white p-0" valign="middle" align="center">
                            <template v-if="orderIssue.second_order">
                                <div class="collapse hide m-0" :id="'secondOrderNumbers'+orderIssue.id">
                                    <p v-for="logisticNumber in orderIssue.second_order.logisticNumbers" class="m-0 p-0 text-center text-muted ">@{{ logisticNumber }}</p>
                                </div>
                                <button v-if="orderIssue.second_order.logisticNumbers.length > 1" type="button"
                                        class="btn btn-sm btn-outline-primary  text-center align-middle mt-1"
                                        :id="'secondOrderNumbersBtn'+orderIssue.id"
                                        data-toggle="collapse"
                                        :data-target="'#secondOrderNumbers'+orderIssue.id"
                                        aria-expanded="false"
                                        :aria-controls="'secondOrderNumbers'+orderIssue.id"
                                        @click="toggleseCondOrderNumbers(orderIssue.id,orderIssue.second_order.logisticNumbers.length)">
                                    分箱@{{ orderIssue.order.logisticNumbers.length }}件,点击展开
                                </button>
                            </template>
{{--                            <p v-if="orderIssue.second_order">@{{ orderIssue.second_order.logisticNumbers}}</p>--}}
                        </td>
                        <td class="bg-white p-0" colspan="3" valign="middle" align="center">
                            <template  v-if="orderIssue.second_order" class="text-center p-0">
                                <table  class="table table-sm  m-0 "
                                        v-if="orderIssue.second_order"
                                        :class="orderIssue.second_order.amount>1?'collapse':''"
                                        :id="'secondOrder'+orderIssue.id">
                                    <template v-for="packages in orderIssue.second_order.packages">
                                        <tr v-for="item in packages.commodities">
                                            <td>@{{ item.commodity.sku }}</td>
                                            <td>@{{ item.commodity.name }}</td>
                                            <td>@{{ item.amount }}</td>
                                        </tr>
                                    </template>
                                </table>
                                <button class="btn btn-sm btn-outline-primary  text-center align-middle mt-1"
                                        v-if="orderIssue.second_order.amount > 1" type="button"
                                        :id="'secondOrderBtn'+orderIssue.id"
                                        data-toggle="collapse"
                                        :data-target="'#secondOrder'+orderIssue.id"
                                        aria-expanded="false"
                                        :aria-controls="'secondOrder'+orderIssue.id"
                                        @click="toggleSecond(orderIssue.id,orderIssue.second_order.amount)">商品共@{{ orderIssue.second_order.amount }}件,点击展开
                                </button>
                            </template>
                        </td>
                        <td class="bg-white">@{{ orderIssue.final_status }}</td>
                        <td class="bg-white">@{{ orderIssue.logistic_indemnity_money }}</td>
                        <td class="bg-white">@{{ orderIssue.logistic_express_remission }}</td>
                        @cannot('客户不可见')
                        <td class="bg-white">@{{ orderIssue.baoshi_indemnity_money }}</td>
                        @endcannot
                        <td class="bg-white">@{{ orderIssue.baoshi_express_remission }}</td>
                        <td class="bg-white"><span v-if="orderIssue.user_work_group">@{{ orderIssue.user_work_group.name }}</span></td>
                        <td>
                            <button type="button" class="btn btn-sm btn-outline-primary" @click="editOrderIssue($event)" :data-value="orderIssue.id">改</button>
                            <button type="button" class="btn btn-sm btn-outline-danger" @click="deleteOrderIssue($event)" :data-value="orderIssue.id">删</button>
                        </td>
                    </tr>
                </table>
                <a :href="page.prevPageUrl" class="btn btn-sm" :class="page.curPage === 1 ?'':'btn-outline-primary'"  :disabled="page.curPage === 1">上一页</a>
                <a :href="page.nextPageUrl" class="btn btn-sm" :class="page.curPage === page.lastPage ?'':'btn-outline-primary'"  :disabled="page.curPage === page.lastPage" >下一页</a>
                <input @keyup.enter="pageTurning($event)" class="form-control-sm ml-3 tooltipTarget" :placeholder="'当前页数：'+page.curPage+'/'+page.lastPage" title="去往指定页">
                <span class="text-muted m-1">共 @{{page.total}} 条 </span>
            </div>
        </div>
{{--deleteOrderIssue--}}
        <div class="modal fade" id="alertModal" tabindex="-1" role="dialog"  aria-labelledby="alertModalLabel" aria-hidden="true">
            <div class="modal-dialog  modal-dialog-centered">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title" id="exampleModalLabel">提示</h5>
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close" @click="changeDeleteId">
                            <span aria-hidden="true">&times;</span>
                        </button>
                    </div>
                    <div class="modal-body">
                        <p>是否删除当前订单问题件?</p>
                        <input type="hidden" id = "deleteId"  class="form-control" />
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-secondary" data-dismiss="modal" @click="changeDeleteId">取消</button>
                        <button type="button" class="btn btn-primary" data-dismiss="modal" @click="deleteOrderIssueById">确认</button>
                    </div>
                </div>
            </div>
        </div>
{{--OrderIssue On Top--}}
        <div class="modal fade " id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
            <div class="modal-dialog modal-dialog-centered">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title" id="exampleModalLabel">请输入置顶备注</h5>
                        <button type="button" class="close"  data-dismiss="modal" aria-label="Close" @click="changeRemark">
                            <span aria-hidden="true">&times;</span>
                        </button>
                    </div>
                    <div class="modal-body">
                        <input type="hidden" class="form-control" id="onTopId">
                        <textarea type="text" class="form-control"  required id="remark" @change="changeRemark"  ></textarea>
                        <div class="invalid-feedback">
                            备注信息不能为空
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-sm btn-secondary" data-dismiss="modal" @click="changeRemark" >关闭</button>
                        <button type="button" class="btn btn-sm btn-primary" @click="submitOnTop">提交</button>
                    </div>
                </div>
            </div>
        </div>
    </div>

@endsection
@section('lastScript')
    <style type="text/css">

        @keyframes anima
        {
            from {
                opacity:0.1;
            }
            to{
                opacity:1;
            }
        }
        @-webkit-keyframes anima
        {
            from {
                opacity:0.75;
            }
            to{
                opacity:0.1;
            }
        }
        .tr_top{
            min-height: 75px;
        }
        .bg-light-yellow{
            background: #fffff8;
        }
        .top{
            padding-top: 0px;
            padding-left: 10px;
            margin-top: -4px;
            margin-left: -5px;
            line-height: 75px;
            position: absolute;
            animation: anima;
            animation-duration: 3s;
            animation-timing-function: cubic-bezier(0,0,1,1);
            animation-direction: alternate;
            animation-play-state: running;

            -webkit-animation-name: anima;
            -webkit-animation-duration: 3s;
            -webkit-animation-timing-function:  cubic-bezier(0,0,1,1);
            -webkit-animation-iteration-count: infinite;
            -webkit-animation-direction: alternate;
            -webkit-animation-play-state: running;
        }

    </style>
    <script type="text/javascript" src="{{asset('js/queryForm/queryForm.js')}}"></script>
    <script type="text/javascript" src="{{asset('js/queryForm/export.js')}}"></script>
    <script>
        let listVue = new Vue({
            el: '#issue_div ',
            data: {
                orderIssues: {!!  $orderIssues->toJson() !!}['data'],
                owners: [
                    @foreach($owners as $owner)
                    {name: '{{ $owner->id }}', value: '{{ $owner->name}}'},
                    @endforeach
                ],
                checkData: [],
                from: '',
                finalStatus: [{name: '0', value: '已解决'}, {name: '1', value: '待退回'}, {name: '2', value: '退回中'}],
                selectedStyle: '',
                deleteId:'',
                page:{
                    lastPage:{!! $orderIssues->toJson() !!}['last_page'],
                    curPage:{!!  $orderIssues->toJson() !!}['current_page'],
                    total:{!!  $orderIssues->toJson() !!}['total'],
                    nextPageUrl:{!!  $orderIssues->toJson() !!}['next_page_url'],
                    prevPageUrl:{!! $orderIssues->toJson()  !!}['prev_page_url'],
                    lastPageUrl:{!!  $orderIssues->toJson() !!}['last_page_url'],
                },
            },
            mounted: function () {

                console.log(this.orderIssues);

                $('.tooltipTarget').tooltip({'trigger': 'hover'});
                $('#list').removeClass("d-none");
                let _this = this;
                let final_status = [{name:'0',value:'已解决'},{name:'1',value:'待退回'},{name:'2',value:'退回中'}];
                let data = [[
                    {name: 'created_at_start', type: 'dataTime', tip: '订单开始日期'},
                    {name: 'owner_id',type: 'select_multiple_select',tip: ['输入关键词快速定位下拉列表，回车确定','选择要显示的客户'], placeholder:['货主','定位或多选货主'],data: _this.owners},
                    {name: 'final_status', type: 'select', tip: '问题件的最终状态', placeholder: '最终状态', data: final_status},
                    {name: 'handle_status', type: 'checkbox', tip: '是否已完结', data: [{name: '2', value: '已完结'}]},
                ], [
                        {name: 'created_at_end', type: 'dataTime', tip: '订单结束日期'},
                        {name: 'logistic_indemnity_money', type: 'input', tip: '承运商赔偿金额', placeholder: '承运商赔偿金额'},
                        @can('客户不可见')
                        {name: 'baoshi_express_remission', type: 'input', tip: '宝时赔偿金额', placeholder: '宝时赔偿金额'},
                        @endcan
                    ]];
                this.form = new query({
                    el: '#form_div',
                    condition: data,
                })
                this.form.init();
                let order =  $('.table-head-warning')[0];
                $('.top').css('min-width', $(order).outerWidth(true));
            },
            watch:{
                checkData:{
                    handler(){
                        if (this.checkData.length === this.orderIssues.length){
                            document.querySelector('#all').checked = true;
                        }else {
                            document.querySelector('#all').checked = false;
                        }
                    },
                    deep:true
                },
            },
            methods: {
                selectedColor(orderno) {
                    if (orderno === this.selectedStyle) {
                        this.selectedStyle = '';
                        return;
                    }
                    this.selectedStyle = orderno;
                },
                editOrderIssue($event){
                    let id = $($event.target).attr('data-value');
                    window.open("{{url('order/issue/edit')}}"+'/'+id);
                },
                deleteOrderIssue($event){
                    let id = $($event.target).attr('data-value');
                    $('#deleteId').val(id);
                    $('#alertModal').modal('show');
                },
                deleteOrderIssueById(){
                    let _this = this;
                    tempTip.setDuration(99999)
                    tempTip.waitingTip('删除中,请稍候')
                    let id =  $('#deleteId').val();
                    let data = {id:id};
                    axios.post('{{url('apiLocal/order/issue/destroy')}}',data).then(function(res){
                        tempTip.setDuration(5000)
                        tempTip.cancelWaitingTip();
                        if(res.data.success){
                            for(let i = 0;i< _this.orderIssues.length;i++){
                                let data = _this.orderIssues[i];
                                if(data.id == id){
                                    _this.orderIssues.splice(i,1);
                                    _this.deleteId = 0;
                                    break;
                                }
                            }
                            tempTip.setDuration(2000);
                            tempTip.showSuccess('问题件删除成功');
                        }else{
                            tempTip.setDuration(2500);
                            tempTip.show('标记勾选内容删除失败,错误：' + res.data.fail_info);
                        }
                    }).catch(function(err){
                        tempTip.setDuration(4000);
                        tempTip.cancelWaitingTip();
                        tempTip.show('网络错误：' + err);
                    });
                },
                changeDeleteId(){
                    $('#deleteId').val('');
                },
                cancelOnTop(event){
                    let id =$(event.target).attr('data-value')
                    let data = {id:id};
                    if(data === '' || data === null){
                        return ;
                    }
                    axios.post('{{url('apiLocal/order/issue/onTop/cancelTop')}}',data).then(function(res){
                        if(res.data.success){
                            tempTip.setDuration(2000);
                            tempTip.showSuccess('订单问题件取消置顶成功！');
                            window.location.reload();
                        }else{
                            tempTip.setDuration(2500);
                            tempTip.show(res.data.fail_info);
                        }
                    }).catch(function(err){
                        tempTip.setDuration(4000);
                        tempTip.show('网络错误：' + err);
                    });
                },
                changeRemark(){
                    $('#remark').removeClass('is-invalid');
                },
                OrderIssueOnTop(event){
                    let id = $(event.target).attr('data-value');
                    $("#onTopId").val(id);
                    $("#exampleModal").modal('show');
                },
                submitOnTop(){
                    let _this = this;
                    let remark =  $("#remark").val();
                    let id = $("#onTopId").val();
                    if(remark === '' || remark == null) {
                        $("#remark").focus();
                        $('#remark').addClass('is-invalid');
                    }else{
                        let data = {id:id,remark:remark};
                        axios.post('{{url('apiLocal/order/issue/onTop/store')}}',data).then(function(res){
                            $("#exampleModal").modal('hide');
                            if(res.data.success){
                                _this.orderIssues.forEach(function(orderIssue){
                                    if(orderIssue.id == id){
                                        if(orderIssue.top == null){
                                            orderIssue.top = {};
                                        }
                                        orderIssue.top.remark = 'remark';
                                    }
                                })
                                tempTip.setDuration(2500);
                                tempTip.showSuccess('置顶成功');
                                window.location.href=window.location.href;
                            } else {
                                tempTip.setDuration(2500);
                                tempTip.show( res.data.fail_info);
                            }
                        }).catch(function(err){
                            $("#exampleModal").modal('hide');
                            tempTip.setDuration(4000);
                            tempTip.show('网络错误：' + err);
                        });

                    }
                },
                pageTurning(event){
                    let page = $(event.target).val();
                    if (page>this.page.lastPage) {
                        return;
                    }
                    window.location = this.form.goPage(page);
                },
                orderIssueExport(sign){
// 导出
                    let url = '{{url('order/issue/export')}}';
                    let token='{{ csrf_token() }}';
                    if(sign){
                        // 所有页
                        excelExport(true,this.checkData,url,this.page.total,token);
                    }else{
                        // 选中
                        excelExport(false,this.checkData,url,null,token);
                    }
                },
                copyOrderNo(){
// 复制快递单号
                    let _this =this;
                    if(this.checkData.length === 0){
                        tempTip.show('没有勾选订单');
                    }else{
                        let orderNos = [];
                        this.orderIssues.forEach(function(item){
                            if(_this.checkData.includes(item.id)){
                               let logisticNumbers =  item.order.logisticNumbers;
                               if(logisticNumbers.length>0){
                                    orderNos.push(logisticNumbers);
                               }
                            }
                        })
                        let p =$('<input id="coty" value="'+orderNos.join(',')+'"/>');
                        p.attr('opacity',0);
                        $('body').append(p);
                        let p_ele = document.getElementById('coty');
                        p_ele.select();
                        document.execCommand("Copy");
                        p.remove();
                    }
                },
                checkAll(e){
                    if (e.target.checked){
                        this.orderIssues.forEach((el,i)=>{
                            if (this.checkData.indexOf(el.id) == '-1'){
                                this.checkData.push(el.id);
                            }
                        });
                    }else {
                        this.checkData = [];
                    }
                },
                endOrderIssue(){
// 完结
                    if(this.checkData.length === 0){
                        tempTip.show('没有勾选订单');
                        return ;
                    }
                    let _this = this;
                    let data = {ids:this.checkData};
                    axios.post('{{url('apiLocal/order/issue/endOrderIssue')}}',data).then(function(res){
                        if(res.data.success){
                            _this.orderIssues.forEach(function(item){
                                if(_this.checkData.includes(item.id)){
                                    item.handle_status = '已完结';
                                }
                            })
                            tempTip.setDuration(2000);
                            tempTip.showSuccess('勾选订单已变为已完结');
                        }else{
                            tempTip.setDuration(3000);
                            tempTip.show(res.data.fail_info);
                        }
                    }).catch(function(err){
                        tempTip.setDuration(4000);
                        tempTip.show('网络异常:'+err);
                    })
                },
                disposeOrderIssue(e){
// 处理订单
                    let _this = this;
                    let id = $(e.target).attr('data-value');
                    let data = {id:id};
                    axios.post('{{url('apiLocal/order/issue/disposeOrderIssue')}}',data).then(function(res){
                        if(res.data.success){
                            _this.orderIssues.forEach(function (orderIssue) {
                                if(orderIssue.id == data.id){
                                    orderIssue.is_new_rejecting = '已处理';
                                }
                            })
                            tempTip.setDuration(3000);
                            tempTip.showSuccess('订单已处理');
                        }else{
                            tempTip.setDuration(3000);
                            tempTip.show(res.data.fail_info);
                        }
                    }).catch(function(err){
                        tempTip.setDuration(4000);
                        tempTip.show('网路链接异常'+err);
                    });
                },
                addOrderIssueLog(id){
// 添加日志
                    let idInput = $('#'+id+' :input[name="id"]');
                    let contentInput = $('#'+id+' :input[name="content"]');
                    if(!contentInput.val()){
                        contentInput.addClass('is-invalid').focus();
                        return ;
                    }
                    contentInput.removeClass('is-invalid')
                    let _this = this;
                    let data= {id:idInput.val(),content:contentInput.val()};
                    axios.post('{{url('apiLocal/order/issue/log/store')}}',data).then(function(res){
                        if(res.data.success){
                            _this.orderIssues.forEach( function(orderIssue){
                                if(orderIssue.id == data.id){
                                    orderIssue.logs.unshift(res.data.data);
                                    contentInput.val('');
                                    $('#'+id).hide();
                                }
                            })
                            tempTip.setDuration(2000);
                            tempTip.showSuccess('添加成功');
                        } else {
                            tempTip.setDuration(3000);
                            tempTip.show(res.data.fail_info);
                        }
                    }).catch(function(err){
                        tempTip.setDuration(4000);
                        tempTip.show('网络异常:'+err);
                    });
                },
                deleteOrderIssueLog(id,OrderIssueId){
// 删除orderIssueLog
                    let _this = this;
                    axios.post("{{url('apiLoacl/order/issue/log/destroy')}}",{id:id}).then(function(res){
                        if(res.data.success){
                            _this.orderIssues.forEach(function (orderIssue) {
                                if(orderIssue.id == OrderIssueId){
                                    let logs = orderIssue.logs;
                                    logs.forEach(function(item,index){
                                        if(item.id == id){
                                            logs.splice(index,1);
                                        }
                                   });
                                }
                            })
                            tempTip.setDuration(2000);
                            tempTip.showSuccess('删除成功');
                        }else{
                            tempTip.setDuration(2000);
                            tempTip.show('删除失败：'+res.data.fail_info);
                        }
                    }).catch(function(err){
                        tempTip.setDuration(4000);
                        tempTip.show('网络异常:'+err);
                    });
                },
                hidetop:function(e) {
                    let target = $(e.target);
                    let top = target.parent().find('.top');
                    let tip = target.parent().find('.toptd');
                    top.hide();
                    tip.tooltip('show');
                },
                showtop:function(e){
                    let target = $(e.target);
                    let top = target.parent().find('.top');
                    let tip = target.parent().find('.toptd');
                    top.show();
                    tip.tooltip('hide');
                },
                showDelBtn(e){
                    let domObj = $(e.target).parent();
                    if(domObj.hasClass('del-tr')){
                        domObj.find('.del-btn').show();
                    }
                },
                hideDelBtn(e){
                    let domObj = $(e.target);
                    if(domObj.hasClass('del-tr')){
                        domObj.find('.del-btn').hide();
                    }
                },
                showAddBtn(e){
                    let domObj = $(e.target).parents('.log-td');
                    if(domObj.hasClass('log-td')){
                        domObj.find('.add-btn').show();
                    }
                },
                hideAddBtn(e){
                    let domObj = $(e.target);
                    if(domObj.hasClass('log-td')){
                        domObj.find('.add-btn').hide();
                    }
                },
                showAddDiv(id){
                    let div = $('#'+id);
                    if(div.is(":hidden")){
                        div.show();
                    }else{
                        div.hide();
                    }
                },
                toggleLogisticNumbers(id,length){
                    let collapse = $('#logisticNumbers'+id);
                    let button = $("#logisticNumbersBtn"+id);
                    let isShow =  button.attr('aria-expanded');
                    if(isShow==='false'){button.text('点击收起');}else{button.text("分箱"+length+"件,点击展开");}
                },
                toggleLogs(id,length){
                    let button = $("#logsBtn"+id);
                    let isShow =  button.attr('aria-expanded');
                    if(isShow==='false'){button.text('点击收起');}else{button.text("记录共"+length+"条,点击展开");}
                },
                toggleOrder(id,length){
                    let button = $("#orderBtn"+id);
                    let isShow =  button.attr('aria-expanded');
                    if(isShow==='false'){
                        button.text('点击收起');
                    }else{
                        button.text("商品"+length+"件,点击展开");
                    }
                },
                toggleSecond(id,length){
                        let button = $("#secondOrderBtn"+id);
                    let isShow =  button.attr('aria-expanded');
                    if(isShow==='false'){
                        button.text('点击收起');
                    }else{
                        button.text("商品共"+length+"件,点击展开");
                    }
                },
                toggleRejectedBill(id,length){
                    let button = $("#rejectedBillBtn"+id);
                    let isShow =  button.attr('aria-expanded');
                    if(isShow ==='false'){
                        button.text('点击收起');
                    }else{
                        button.text("商品"+length+"件,点击展开");
                    }
                },
                toggleseCondOrderNumbers(id,length){
                    let button = $("#secondOrderNumbersBtn"+id);
                    let isShow =  button.attr('aria-expanded');
                    if(isShow ==='false'){
                        button.text('点击收起');
                    }else{
                        button.text("商品"+length+"件,点击展开");
                    }
                },

            }
        })
        // modal 隐藏时修改 input 为空
        $("#exampleModal").on('hide.bs.modal',function(e){
            $('#remark').val('');
        });

    </script>
@endsection




