@extends('layouts.app')
@section('title')查询-订单管理@endsection

@section('content')
    @component('order.index.menu')@endcomponent
    <div class="container-fluid">
        <div style="min-width: 4120px;">{{--4070--}}
            <div id="list" class="d-none">
                <div id="form_div"></div>
                <div class="ml-3 form-inline" id="btn">
                    <div class="dropdown">
                        <button type="button" class="btn btn-outline-dark btn-sm form-control-sm dropdown-toggle tooltipTarget"
                                data-toggle="dropdown" title="导出所有页将会以搜索条件得到的筛选结果，将其全部记录（每一页）导出">
                            导出Excel
                        </button>
                        <div class="dropdown-menu">
                            <a class="dropdown-item" @click="orderExport(false)" href="javascript:">导出勾选内容</a>
                            <a class="dropdown-item" @click="orderExport(true)" href="javascript:">导出所有页</a>
                        </div>
                    </div>
                    <div class="custom-control custom-checkbox ml-1">
                        <input type="checkbox" class="custom-control-input" id="customCheck" name="is_merge" v-model="is_merge">
                        <label class="custom-control-label" for="customCheck">导出是否格式化</label>
                    </div>
                    @can('订单管理-批量备注')<button @click="modal()" type="button" class="btn btn-sm ml-2 btn-outline-primary">批量备注追加</button>@endcan
                    @can('订单管理-编辑')
                        <span class="btn btn-sm btn-outline-dark tooltipTarget ml-1"  @click="freezeAll" style="cursor: pointer" title="订单的冻结条件要只局限在“创建订单”,“分配完成”,“拣货完成”,“播种完成”">冻结</span>
                        <button type="button" @click="thaw(null,true)" class="btn btn-sm btn-outline-danger tooltipTarget ml-1" title="解除已冻结订单" style="opacity: 0.7">解冻</button>
                        <span class="btn btn-sm btn-outline-dark tooltipTarget ml-1" @click="deAllocationAll" style="cursor: pointer"  title="订单的取消分配条件要只局限在“分配完成”或“部分分配”">取消分配</span>
                        <button type="button" @click="resetLogisticsGetMark()" class="btn btn-sm ml-1 btn-outline-success">重置快递获取标记</button>
                        <button type="button" @click="resetInterfaceReturnMark()" class="btn btn-sm ml-1 btn-outline-secondary">重置接口回传标记</button>
                    @endcan
                    @can('订单管理-订单-生成问题件')<button  @click="orderIssueTag()" type="button" class="btn btn-sm ml-1 btn-outline-primary">标记问题件</button>@endcan
                    @can('订单管理-订单-生成退货单')
                        <button class="btn btn-sm btn-outline-dark ml-1"@click="isRejectedBillExist()"
                            style="opacity: 0.7">生成退货单</button>
                    @endcan
                    <button class="btn btn-sm ml-1 btn-primary" @click="copyLogisticNumber()">复制快递单号</button>
                </div>
                <div class="modal fade " style="top: 20%" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                    <div class="modal-dialog">
                        <div class="modal-content">
                            <div class="modal-header">
                                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                            </div>
                            <div class="modal-body">
                                <input class="form-control" v-model="content" placeholder="注释内容">
                            </div>
                            <div class="modal-footer">
                                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                                <button type="button" @click="batchComments()" class="btn btn-primary">批量备注追加</button>
                            </div>
                        </div><!-- /.modal-content -->
                    </div><!-- /.modal -->
                </div>
                <table class="table table-striped table-bordered table-hover card-body td-min-width-80" id="table">
                    <tr v-for="(order,i) in orders" @click="selectedColor(order.orderno)" :style="{'background-color': order.orderno==selectedStyle?'#aac7ea':''}">
                        <td>
                            <input class="checkItem" type="checkbox" :value="order.orderno">
                        </td>
                        <td class="text-nowrap">
                            <span>@{{ i+1 }}</span><span v-if="orderIssueNos.includes(order.orderno)" class="badge badge-pill badge-danger">问题件</span>
                        </td>
                        <td class="text-dark font-weight-bold text-nowrap"><span>@{{ order.orderno }}</span></td>
                        <td class="text-muted text-nowrap"><span>@{{ order.ordercodename }}</span></td>
                        <td class="text-nowrap"><span>@{{ order.addtime }}</span></td>
                        <td class="text-nowrap"><span>@{{ order.issuepartyname }}</span></td>
                        <td class="text-nowrap"><span>@{{ order.customer_descr_c }}</span></td>
                        <td class="text-nowrap"><span>@{{ order.soreference1 }}</span></td>
                        <td class="text-muted text-nowrap"><span>@{{ order.carriername }}</span></td>
                        <td class="text-nowrap">
                            <div v-if="picktotraceidMap[order.orderno] && picktotraceidMap[order.orderno].length>1" class="text-center">
                                <span v-for="picktotraceid in picktotraceidMap[order.orderno]" v-if="order.is_unfold">
                                    @{{ picktotraceid }}<br>
                                </span>
                                <button class="btn btn-sm btn-outline-info" :style="order.is_unfold ? 'opacity:0.7' : ''" @click="isUnfold(order)">
                                    <span v-if="order.is_unfold" class="mt-1">收起</span>
                                    <span v-else>分箱 @{{ picktotraceidMap[order.orderno].length }} 件,展开单号</span>
                                </button>
                            </div>
                            <span v-else>@{{ order.soreference5 }}</span>
                        </td>
                        <td class="text-muted text-wrap text-letter">
                            <div class="text-overflow-warp-200 warp-min-200">@{{ order.c_contact }}</div>
                        </td>
                        <td class="text-muted text-wrap text-letter">
                            <div class="text-overflow-warp-200 warp-min-200">@{{ order.c_tel2?order.c_tel2:order.c_tel1 }}</div>
                        </td>
                        <td class="text-nowrap"><span> @{{ order.c_province }}</span></td>
                        <td class="text-nowrap"><span> @{{ order.c_city }}</span></td>
                        <td class="text-nowrap"><div class="text-overflow-warp-200 warp-min-200">@{{ order.c_district }}</div></td>
                        <td class="text-muted text-wrap text-letter"><div class="text-overflow-warp-200 warp-min-200"><span>@{{ order.c_address1 }}</span></div></td>
                        <td class="text-nowrap"><span>@{{ order.waveno }}</span></td>
                        <td class="text-nowrap"><span> @{{ order.warehouseid }}</span></td>
                        <td class="text-nowrap"><span v-if="order.edisendflag2=='Y'">是</span><span v-if="order.edisendflag2=='N'">否</span><span v-if="order.edisendflag2=='W'">错误</span></td>
                        <td class="text-nowrap"><span>@{{ order.edisendtime2 }}</span></td>
                        <td class="text-center" style="min-width: 900px">
                            <div :class="commodities[order.orderno]&&commodities[order.orderno].length==1 ? '' : 'up'" :id="'order-'+i">
                                <div v-for="oracleDOCOrderDetail in commodities[order.orderno]" class="row">
                                    <div class="col-2 border border-1">@{{ oracleDOCOrderDetail.sku }}</div>
                                    <div class="col-2 border border-1">@{{ oracleDOCOrderDetail.alternate_sku1 }}</div>
                                    <div class="col-2 border border-1" @dblclick.stop="replaceText(i)">
                                        <div class="w-100" :class="order.replaceText ? 'text-overflow-warp-100' : 'text-overflow-replace-100 cursor-pointer'">@{{ oracleDOCOrderDetail.descr_c  }}</div>
                                    </div>
                                    <div class="col-1 border border-1">@{{ oracleDOCOrderDetail.qtyordered }}</div>
                                    <div class="col-2 border border-1">@{{ oracleDOCOrderDetail.lotnum }}</div>
                                    <div class="col-1 m-0 p-0 border border-1">@{{ oracleDOCOrderDetail.orderdetailcodename }}</div>
                                    <div class="col-2 border border-1">@{{ oracleDOCOrderDetail.checktime }}</div>
                                </div>
                            </div>
                            <div class="row text-center cursor-pointer" v-if="commodities[order.orderno]&&commodities[order.orderno].length>1">
                                <b @click="unfold(i)" class="col-12 cursor-pointer" v-if="!upList[i]">共有 @{{ commodities[order.orderno].length }}  件商品，点击展开</b>
                                <b class="col-12" @click="unfold(i)" v-else>点击收起明细</b>
                            </div>
                        </td>
                        <td><span>@{{ order.notes }}</span></td>
                        <td><span>@{{ order.erpcancelflag }}</span></td>
                        <td><span>@{{ order.picking_print_flag }}</span></td>
                        <td><span>@{{ order.edisendflag }}</span></td>
                        <td><span>@{{ order.ediremarks2}}</span></td>
                        <td>
                            @can('订单管理-编辑')
                                <button v-if="order.releasestatus!=='H'" @click="freeze(order.orderno,order.waveno)" class="btn btn-sm btn-outline-dark text-nowrap"
                                        :disabled="!(order.ordercodename==='创建订单'||order.ordercodename==='分配完成'||order.ordercodename==='拣货完成'||order.ordercodename==='播种完成')">冻结</button>
                                <button v-else @click="thaw(order.orderno,false,order)" class="btn btn-sm btn-outline-danger text-nowrap"
                                        :disabled="!(order.ordercodename==='创建订单'||order.ordercodename==='分配完成'||order.ordercodename==='拣货完成'||order.ordercodename==='播种完成')">解冻</button>
                            @else
                                <span>@{{ order.releasestatus }}</span>
                            @endcan
                        </td>
                        <td>
                            @can('订单管理-编辑')
                                <button v-if="order.sostatus=='40'||'30'"  @click="deAllocation(order.orderno,order.waveno)" class="btn btn-sm btn-outline-dark text-nowrap"
                                        :disabled="!(order.sostatus==='40'|| order.sostatus==='30')">取消分配</button>
                            @else
                                <span>@{{ order.sostatus }}</span>
                            @endcan
                        </td>
                    </tr>
                </table>
                <button type="button" @click="pageUp()" :readonly="page>1?false:true" class="btn btn-sm " :class="page>1?'btn-outline-info':''">上一页</button>
                <button type="button" @click="pageDown()" :readonly="maxPage == 0 ? false : (page<maxPage?false:true)" class="btn btn-sm m-3" :class="maxPage == 0 ? 'btn-outline-info' : (page<maxPage?'btn-outline-info':'')">下一页</button>
                <input  @keyup.enter="pageSkip($event)" class="form-control-sm ml-3 tooltipTarget" :placeholder="pagePlaceholder" title="去往指定页">
                <span class="text-muted m-1" v-if="maxPage != 0">共 @{{ sum }} 条</span>


                <div class="modal fade " id="checkModal" tabindex="-1" role="dialog" aria-labelledby="checkModalLabel" aria-hidden="true">
                    <div class="modal-dialog modal-dialog-centered">
                        <div class="modal-content">
                            <div class="modal-header">
                                <h5 class="modal-title" id="checkModalLabel">标记问题件提示</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">
                                <div class="alert" id="alert-message">
                                    @{{ message.checkOrderIssueMessage }}
                                </div>
                            </div>
                            <div class="modal-footer">
                                <button type="button" class="btn btn-secondary" data-dismiss="modal"
                                        @click="message.checkOrderIssueMessage=''">关闭
                                </button>
                            </div>
                        </div>
                    </div>
                </div>


                <div class="modal fade " id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel"
                     aria-hidden="true">
                    <div class="modal-dialog modal-dialog-centered modal-xl">
                        <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">
                                <div class="form-group row m-0 p-0">
                                    <label class="col-md-1 col-sm-2 text-right">问题类别</label>
                                    <select name="order_issues_type_id" v-model="typeId" class="form-control col-4" id="orderIssueType" @focus="focusOnModal($event)" >
                                        <option value></option>
                                        <option v-for="type in orderIssueType" :value="type.id">@{{ type.name }}</option>
                                    </select>
                                    <label class="col-md-1 col-sm-2 text-right">
                                        快递
                                    </label>
                                    <div class="col-4">
                                        <textarea  class="form-control m-0">@{{ tagOrder.logisticInfo }}</textarea>
                                        <button type="button" class="btn btn-sm btn-outline-primary" @click="copyLogisticInfo">复制</button>
                                    </div>
                                </div>
                                <div class="form-group row m-0">
                                    <label class="col-md-1 col-sm-2 text-right">情况说明</label>
                                    <label for="result_explain"></label>
                                    <textarea name="result_explain" v-model="result_explain" class="form-control col-4" id="result_explain" ></textarea>
                                    <label class="col-md-1 col-sm-2 text-right">
                                        商家
                                    </label>
                                    <div class="col-4">
                                        <textarea  class="form-control m-0 row">@{{ tagOrder.merchantInfo }}</textarea>
                                        <button type="button" class="btn btn-sm btn-outline-primary" @click="copyMerchantInfo">复制</button>
                                    </div>
                                </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="orderIssueTagSubmit">提交</button>
                            </div>
                        </div>
                    </div>
                </div>
                <textarea  id="clipboardDiv" style="opacity:0"></textarea>
            </div>
        </div>
    </div>
@endsection

@section('lastScript')
    <script type="text/javascript" src="{{mix('js/queryForm/export.js')}}"></script>
    <script type="text/javascript" src="{{mix('js/queryForm/queryForm.js')}}"></script>
    <script type="text/javascript" src="{{mix('js/queryForm/header.js')}}"></script>{{--新版2--}}
    <script>
        let vue=new Vue({
            el:"#list",
            data:{
                page:Number('{{$page}}'),
                paginate:Number('{{$request['paginate'] ?? 50}}'),
                maxPage:1,
                sum:0,
                owners:[
                        @foreach($customers as $customer)
                    { name:'{{$customer->customerid}}',value:'{{$customer->descr_c}}' },
                    @endforeach
                ],
                logistics:[
                        @foreach($logistics as $logistic)
                    { name:'{{$logistic->name}}',value:'{{$logistic->name}}' },
                    @endforeach
                ],
                orders:{!! $orders !!},
                commodities:{!! $commodities !!},
                content:'',
                codes:[
                        @foreach($codes as $code)
                    {name:'{{$code->code}}',value:'{{$code->codename_c}}'},
                    @endforeach
                ],
                selectedStyle:'',
                picktotraceidMap:{!! $picktotraceids !!},
                pagePlaceholder:"",
                typeId:'',
                result_explain:'',
                orderIssueType:{!! $orderIssueType !!},
                is_merge : false,
                message:{
                    checkOrderIssueMessage:'',
                },
                orderIssueNos:{!!  $orderIssueNos!!},
                tagOrders:[],
                tagOrder:{
                    logisticInfo:'',
                    merchantInfo:'',
                },
                upList:{},
            },
            mounted:function () {
                $(".up").slideUp();
                $(".tooltipTarget").tooltip({'trigger':'hover'});
                $("#list").removeClass('d-none');
                if (this.orders.length>0){
                    this.maxPage=Math.ceil(this.orders[0].counted/this.paginate);
                    this.sum=this.orders[0].counted;
                }
                if (this.getQueryVariable('alternate_sku1')){
                    this.maxPage=0;
                    this.pagePlaceholder = '当前页数：'+this.page;
                }else{
                    this.pagePlaceholder = '当前页数：'+this.page+'/'+this.maxPage;
                }
                let data=[
                    [   {name:'codename_c',type:'select',placeholder:'订单状态',data:this.codes},
                        {name:'orderdate_start',type:'time',tip:['选择显示日期的起始时间','选择显示日期的起始时间'],
                            rules:{date_relevance:{date:['orderdate_start','orderdate_end'],relevance:'addtime',killing:'relevance',default:[31,92,183,366]}}},
                        {name:'orderno',type:'input',tip:'可支持多SO号，糊模查找需要在左边打上%符号',placeholder: 'SO号'},
                        // {name:'carriername',type:'input',tip:'可支持多承运人,糊模查找需要在左边打上%符号',placeholder:'承运人'},
                        {name:'carriername',type:'select_multiple_select',tip:['输入关键词快速定位下拉列表，回车确定','选择要显示的承运人'],
                            placeholder:['承运人','定位或多选承运人'],data:this.logistics},
                        {name:['notes','addtime'],type:'input_select',tip:['右侧选择查询范围，默认为一月内','查询范围，范围越短搜索越快'],placeholder: ['备注',''],
                            data:[{name:'31',value:'近一月'},{name:'92',value:'近三月'},{name:'183',value:'近半年'},{name:'366',value:'近一年'},{name:'0',value:'不限'},],
                            rules:{son:{addtime:{default:'31',required_without_all_if:['orderdate_start','orderdate_end']}},
                                date_relevance:{date:['orderdate_start','orderdate_end'],relevance:'addtime',killing:'date',default:[31,92,183,366]}}},
                        {name:'issuepartyname',type:'input',tip:'糊模查找需要在左边打上%符号',placeholder: '店铺名称'},
                        {name:'edisendflag2',type:'select',tip:'快递获取标记',placeholder: '快递获取标记',data:[{name:'Y',value:'是'},{name:'N',value:'否'},{name:'W',value:'错误'},]},
                        {name:'edisendflag',type:'select',tip:'接口回传标记',placeholder: '接口回传标记',data:[{name:'Y',value:'Y'},{name:'N',value:'N'},{name:'W',value:'W'},{name:'R',value:'R'},]}
                    ],
                    [
                        {name:'codename_c_end',type:'select',placeholder:'订单状态范围',data:this.codes},
                        {name:'orderdate_end',type:'time',tip:['选择显示指定日期的结束时间','选择显示指定日期的结束时间'],
                            rules:{date_relevance:{date:['orderdate_start','orderdate_end'],relevance:'addtime',killing:'relevance',default:[31,92,183,366]}}},
                        {name:'customerid',type:'select_multiple_select',tip:['输入关键词快速定位下拉列表，回车确定','选择要显示的客户'],
                            placeholder:['货主','定位或多选货主'],data:this.owners},
                        {name:'soreference5',type:'input',tip:'可支持多快递单号，糊模查找需要在左边打上%符号',placeholder: '多快递单号'},
                        {name:'soreference1',type:'input',tip:'客户订单号，糊模查找需要在左边打上%符号',placeholder: '客户订单号'},
                        {name:'waveno',type:'input',tip:'可支持多波次编号，模糊查找需要在左边打上%的符号',placeholder: '波次编号'},
                        {name:'alternate_sku1',type:'input',tip:'产品条码，模糊查找需要在左边打上%的符号',placeholder: '产品条码'},
                        {name:'c_contact',type:'input',tip:'可支持多收货人名称：15天以内模糊搜索，15天以外精确搜索',placeholder:'收货人名称'},
                    ],
                    [
                        {name:'c_tel2',type:'input',tip:'收货人电话：15天以内模糊搜索，15天以外精确搜索',placeholder:'收货人电话'},
                        {name:'c_province',type:'input',tip:'省：15天以内模糊搜索，15天以外精确搜索',placeholder:'省'},
                        {name:'c_city',type:'input',tip:'市：15天以内模糊搜索，15天以外精确搜索',placeholder:'市'},
                        {name:'c_district',type:'input',tip:'区：15天以内模糊搜索，15天以外精确搜索',placeholder:'区'},
                        {name:'releasestatus',type:'select',tip:'是否冻结冻结',placeholder:'是否冻结',data:[{name:'H',value:'是'},{name:'',value:'否'}]},
                        {name:'checktime_start',type:'time',tip:['选择显示复核时间的起始日期',"选择显示复核时间的起始时间"]},
                        {name:'checktime_end',type:'time',tip:['选择显示复核时间的结束日期','选择显示复核时间的结束时间']},
                        {name: 'is_display_all', type: 'checkbox', tip: '是否隐藏装箱完成以后的状态', data: [{name: 'ture', value: '隐藏完成状态'}]},
                    ],
                ];
                this.form = new query({
                    el:"#form_div",
                    condition:data,
                    appendDom : "btn",
                });
                this.form.init();
                let column = [
                    {name:'index',value: '序号', neglect: true},
                    {name:'orderno',value: '编号'},
                    {name:'ordercodename',value: '订单状态'},
                    {name:'addtime',value: '接口下发时间'},
                    {name:'issuepartyname',value: '店铺名称'},
                    {name:'customer_descr_c',value: '客户'},
                    {name:'soreference1',value: '客户订单号'},
                    {name:'carriername',value: '承运人'},
                    {name:'soreference5',value: '快递单号'},
                    {name:'c_contact',value: '收货人名称'},
                    {name:'c_tel2',value: '收货人电话'},
                    {name:'c_province',value: '省'},
                    {name:'c_city',value: '市'},
                    {name:'c_district',value: '区'},
                    {name:'c_address1',value: '收货人地址'},
                    {name:'waveno',value: '波次编号'},
                    {name:'warehouseid',value: '仓库'},
                    {name:'edisendflag2',value: '快递获取标记'},
                    {name:'edisendtime2',value: '快递获取时间'},
                    {name:"commodity", type:"multi",title:"商品信息",rows:[
                            {value:"商品编码",col:"2"},
                            {value:"商品条码",col:"2"},
                            {value:"商品名称",col:"2"},
                            {value:"订单数量",col:"1"},
                            {value:"批次号",col:"2"},
                            {value:"明细状态",col:"1"},
                            {value:"复核时间",col:"2"}
                        ]},
                    {name:'notes',value: '备注'},
                    {name:'erpcancelflag',value: '接口取消标记'},
                    {name:'picking_print_flag',value: '拣货单打印标记'},
                    {name:'edisendflag',value: '接口回传标记'},
                    {name:'ediremarks2',value: '接口回传异常备注'},
                    {name:'update',value: '订单冻结', neglect: true},
                    {name:'remove',value: '取消分配', neglect: true},
                ];
                new Header({
                    el: "table",
                    name:"order",
                    column: column,
                    data: this.orders,
                    restorationColumn: 'addtime',
                    fixedTop:($('#form_div').height())+($('#btn').height())+1,
                }).init();
            },
            watch:{
                result_explain:function(){
                    this.setLogisticInfo();
                    this.setMerchantInfo();
                }
            },
            methods:{
                getQueryVariable(variable){
                    let query = window.location.search.substring(1);
                    let vars = query.split("&");
                    for (let i=0;i<vars.length;i++) {
                        let pair = vars[i].split("=");
                        if(pair[0] == variable){return pair[1];}
                    }
                    return(false);
                },
                pageUp(){
                    if (this.page<=1)return;
                    this.href(this.page-1);
                },
                pageDown(){
                    if (this.page>=this.maxPage && this.maxPage !== 0)return;
                    this.href(this.page+1);
                },
                pageSkip(e){
                    if (Number(e.target.value)<=0 || Number(e.target.value)>this.maxPage){
                        tempTip.setDuration(2000);
                        tempTip.show('页数不存在！ ');
                        return
                    }
                    this.href(e.target.value);
                },
                href(page){
                    let url = document.URL;
                    if (url.indexOf('page='+this.page) !== -1){
                        url = url.replace("page="+this.page,"page="+page);
                    }else{
                        if (url.indexOf('?') === -1) url += "?page="+page;
                        else url += "&page="+page;
                    }
                    window.location.href=url;
                },
                unfold(index){
                    this.$set(this.upList,index,this.upList[index] ? !this.upList[index] : true);
                    $("#order-"+index).slideToggle();
                },
                orderExport(checkAllSign){
                    let url = '{{url('order/index/export')}}';
                    let token='{{ csrf_token() }}';
                    excelExport(checkAllSign,checkData,url,this.sum,token,{is_merge : this.is_merge});
                },
                modal(){
                    $("#myModal").modal('show');
                },
                //批量冻结
                freezeAll:function(){
                    let _this=this;
                    if(checkData.length===0){
                        tempTip.show('没有勾选记录');
                        return
                    }
                    if(!confirm("确定要标记所有勾选内容为'冻结'吗")){return;}
                    axios.post('{{url('order/freezeAll')}}',{checkData:checkData}).then(function(response){
                        if(response.data.success){
                            _this.orders.forEach(function(order){
                                checkData.forEach(function (checkedId) {
                                    if(order.orderno===checkedId){
                                        order.releasestatus='H';
                                        order.waveno='*';
                                    }
                                });
                            });
                            tempTip.setDuration(1000);
                            tempTip.showSuccess('标记勾选内容为冻结成功');
                        }else{
                            tempTip.setDuration(2500);
                            tempTip.show('标记勾选内容冻结失败，错误：'+response.data.fail_info);
                        }
                    }).catch(function (e) {
                        tempTip.setDuration(2500);
                        tempTip.show('标记勾选内容冻结失败，网络连接错误：'+e);
                    })
                },
                //批量取消分配
                deAllocationAll(){
                    let _this=this;
                    if(checkData.length===0){
                        tempTip.show('没有勾选记录');
                        return
                    }
                    if(!confirm("确定要所有勾选内容'取消分配'吗")){return;}
                    axios.post('{{url('order/deAllocationAll')}}',{checkData:checkData}).then(function(response){
                        if(response.data.success){
                            _this.orders.forEach(function(order){
                                checkData.forEach(function (checkedId) {
                                    if(order.orderno===checkedId){
                                        order.sostatus='00';
                                        order.waveno='*';
                                    }
                                });
                            });
                            tempTip.setDuration(1000);
                            tempTip.showSuccess('标记勾选内容取消分配成功');
                            window.location.reload();
                        }else{
                            tempTip.setDuration(2500);
                            tempTip.show('标记勾选内容取消分配失败，错误：'+response.data.fail_info);
                        }
                    }).catch(function (e) {
                        tempTip.setDuration(2500);
                        tempTip.show('标记勾选内容取消分配失败，网络连接错误：'+e);
                    })
                },
                batchComments(){
                    let _this=this;
                    if (checkData.length<1 || !this.content) {
                        $("#myModal").modal('hide');
                        tempTip.setDuration(3000);
                        if (checkData.length<1) tempTip.showSuccess('没有勾选任何记录');
                        else tempTip.showSuccess('没有输入任何内容');
                        return;
                    }
                    axios.post('{{url('order/create/batchComments')}}',{checkData:checkData,content:this.content})
                        .then(function (response) {
                            let sign=[];
                            _this.orders.every(function (order) {
                                if (sign.length===response.data.length)return false;
                                response.data.every(function (data) {
                                    if (order.orderno===data.orderno){
                                        order.notes=data.notes;
                                        sign.push(order.orderno);
                                        return false;
                                    }
                                    return  true;
                                });
                                return true;
                            });
                            tempTip.setDuration(3000);
                            tempTip.showSuccess('注释完毕！')
                            _this.content='';
                        }).catch(function (err) {
                        tempTip.setDuration(4000);
                        tempTip.show('网络错误：'+err)
                    });
                    $("#myModal").modal('hide');
                },
                selectedColor(orderno){
                    if (orderno==this.selectedStyle) return;
                    this.selectedStyle=orderno;
                },
                freeze(orderno,waveno){
                    if(!confirm('确定要冻结“'+orderno+'”吗？'))return;
                    let _this=this;
                    axios.post('{{url('order/freeze')}}',{orderno:orderno,waveno:waveno})
                        .then(function (response) {
                            if (response.data.success){
                                _this.orders.some(function (order) {
                                    if (order.orderno===orderno){
                                        order.releasestatus='H';
                                        order.waveno='*';
                                        return true;
                                    }
                                });
                                tempTip.setDuration(3000);
                                tempTip.showSuccess('订单已被冻结！');
                            }
                        }).catch(function (err) {
                        tempTip.setDuration(3000);
                        tempTip.show('网络异常：'+err);
                    });
                },
                thaw(orderno = null, is_batch = false, order = null){
                    if (!orderno)orderno = checkData;
                    if(!confirm('确定要解冻“'+orderno+'”吗？'))return;
                    let _this=this;
                    axios.post('{{url('order/thaw')}}',{orderno:orderno})
                        .then(function (response) {
                            if (response.data.success){
                                if (is_batch){
                                    orderno.forEach(order_no =>{
                                        _this.orders.some(function (order) {
                                            if (order.orderno===order_no){
                                                order.releasestatus='N';
                                                return true;
                                            }
                                        });
                                    });
                                }else{
                                    order.releasestatus = 'N';
                                }
                                tempTip.setDuration(3000);
                                tempTip.showSuccess('订单已成功解冻！');
                            }
                        }).catch(function (err) {
                        tempTip.setDuration(3000);
                        tempTip.show('网络异常：'+err);
                    });
                },
                deAllocation(orderno,waveno){
                    if(!confirm('确定要取消分配“'+orderno+'”吗？'))return;
                    let _this=this;
                    axios.post('{{url('order/deAllocation')}}',{orderno:orderno,waveno:waveno})
                        .then(function (response) {
                            if (response.data.success){
                                _this.orders.some(function (order) {
                                    if (order.orderno===orderno){
                                        order.sostatus='00';
                                        order.waveno='*';
                                        return true;
                                    }
                                });
                                tempTip.setDuration(3000);
                                tempTip.showSuccess('订单已被取消分配！');
                                window.location.reload();
                            }
                        }).catch(function (err) {
                        tempTip.setDuration(3000);
                        tempTip.show('网络异常：'+err);
                    });
                },
                isUnfold(order){
                    if (!order.is_unfold){
                        this.$set(order,'is_unfold',true);
                        return;
                    }
                    order.is_unfold=false;
                },
                orderIssueTag(){
                    if( checkData.length === 0){
                        tempTip.setDuration(2000);
                        tempTip.show('没有勾选记录');
                        return;
                    }
                    this.isExistByOrderNos();
                },
                orderIssueTagSubmit(){
                    if(this.typeId === ''){
                        $("#orderIssueType").addClass('is-invalid'); return;
                    }else{
                        $("#result_explain #result_explain").removeClass('is-invalid');
                        $("#exampleModal").modal('hide');
                    }
                    let _this = this;
                    tempTip.setDuration(99999);
                    tempTip.waitingTip('处理中,请稍候');
                    let data = {orderNos:checkData,typeId: this.typeId,result_explain:this.result_explain};
                    axios.post("{{url('apiLocal/order/issue/orderIssueTag')}}",data).then(function(res){
                        tempTip.setDuration(5000);
                        tempTip.cancelWaitingTip();
                        if(res.data.success){
                            tempTip.setDuration(3000);
                            tempTip.showSuccess('已标记为问题件');
                            checkData.forEach(function(orderNo){
                                _this.orderIssueNos.push(orderNo)
                            });
                            checkData = []
                        }else{
                            if(res.data.exitsOrderNos){
                                _this.message.checkOrderIssueMessage = res.data.fail_info+res.data.exitsOrderNos;
                                $("#checkModal").modal('show');
                            }else{
                                tempTip.setDuration(3000);
                                tempTip.show(res.data.fail_info);
                            }
                        }
                    }).catch(function(err){
                        tempTip.setDuration(3000);
                        tempTip.cancelWaitingTip();
                        tempTip.show('网络链接异常'+err);
                    })
                },
                //重置快递获取标记
                resetLogisticsGetMark(){
                    if (checkData.length < 1){
                        tempTip.setDuration(3000);
                        tempTip.showSuccess('未选择任何单号');
                        return
                    }
                    if (!confirm('确定要重置这些单的快递获取标记吗？'))return;
                    let url = '{{url('order/resetLogisticsGetMark')}}';
                    let _this = this;
                    axios.post(url,{orderno : checkData})
                        .then(function (response) {
                            if (response.data.success){
                                checkData.forEach(orderno => {
                                    _this.orders.some(order => {
                                        if (order.orderno === orderno && order.edisendflag2 === 'W'){
                                            order.edisendflag2 = "N";
                                            return true;
                                        }
                                    });
                                });
                                tempTip.setDuration(2000);
                                tempTip.showSuccess('重置快递获取标记成功!');
                            } else{
                                tempTip.setDuration(3000);
                                tempTip.show(response.data.data);
                            }

                        }).catch(function (err) {
                        tempTip.setDuration(3000);
                        tempTip.show("网络错误："+err)
                    })
                },
                resetInterfaceReturnMark(){
                    if (checkData.length < 1){
                        tempTip.setDuration(3000);
                        tempTip.showSuccess('未选择任何单号');
                        return
                    }
                    if (!confirm('确定要重置接口回传标记吗？'))return;
                    let url = '{{url('order/resetInterfaceReturnMark')}}';
                    let _this = this;
                    axios.post(url,{orderno : checkData}).then(function (response) {
                        if (response.data.success){
                            checkData.forEach(orderno => {
                                _this.orders.some(order => {
                                    if (order.orderno === orderno){
                                        order.edisendflag  = "N";
                                        return true;
                                    }
                                });
                            });
                            tempTip.setDuration(2000);
                            tempTip.showSuccess('重置接口回传标记成功!');
                        } else{
                            tempTip.setDuration(5000);
                            tempTip.show(response.data.fail_info);
                        }
                        }).catch(function (err) {
                            tempTip.setDuration(3000);
                            tempTip.show("网络错误："+err)
                       });
                },
                changeRemark(){
                    this.typeId ='';
                    this.result_explain ='';
                },
                focusOnModal(e){
                    $(e.target).removeClass('is-invalid');
                },
                isRejectedBillExist(){
                    if(checkData.length===0){
                        tempTip.show('没有勾选记录');
                        return
                    }
                    tempTip.confirm("是否要生成“"+checkData+"”的退货单？",()=> {
                        let _this = this;
                        let arr = [];
                        window.tempTip.setDuration(9999);
                        window.tempTip.waitingTip("生成中,请稍等......")
                        this.orders.forEach(order=> {
                            if (checkData.includes(order.orderno))arr.push(order.soreference1);
                        });
                        axios.post('{{url('order/isRejectedBillExist')}}',{data:arr})
                            .then(function (response) {
                                if (!response.data.success){
                                    tempTip.confirm(response.data.data+'，已存在，是否仍要生成退货单？',function () {
                                        _this.createRejectedBill();
                                        window.tempTip.cancelWaitingTip();
                                    },function (){
                                        window.tempTip.cancelWaitingTip();
                                    });
                                    return;
                                }
                                _this.createRejectedBill();
                            }).catch(function (error) {
                            tempTip.setDuration(3000);
                            tempTip.cancelWaitingTip();
                            tempTip.show('网络错误：'+error);
                        });
                    });
                },
                createRejectedBill() {
                    let url = '{{url('order/createRejectedBill')}}';
                    axios.post(url,{data:checkData})
                        .then(res=>{
                            if (res.data.success){
                                tempTip.cancelWaitingTip();
                                tempTip.setDuration(2000);
                                tempTip.showSuccess("生成退货单成功！");
                            }else{
                                tempTip.cancelWaitingTip();
                                tempTip.setDuration(3000);
                                tempTip.show(res.data.data);
                            }
                        })
                        .catch(err=>{
                            tempTip.cancelWaitingTip();
                            tempTip.setDuration(3000);
                            tempTip.show('网络错误：'+err);
                        });
                },
                isExistByOrderNos(){
                    let orderNos = checkData;
                    let data = {orderNos:orderNos};
                    let _this = this;
                    axios.post("{{url('apiLocal/order/issue/isExistByOrderNo')}}",data).then(function(res){
                        if(res.data.success){
                            _this.getTagOrder(orderNos);
                            $("#exampleModal").modal('show')
                        }else{
                            _this.message.checkOrderIssueMessage = res.data.fail_info
                            $("#checkModal").modal('show')
                        }
                    }).catch(function(error){
                        tempTip.setDuration(3000)
                        tempTip.show('网络异常:'+error)
                    })
                },
                replaceText(index){
                    this.$set(this.orders[index],"replaceText",true);
                },
                getTagOrder(orderNos){
                    this.tagOrders = [];
                    if(orderNos.length ===  0 ){this.tagOrders =[];return ;}
                    if(this.orders.length === 0 ){this.tagOrders =[];return ;}
                    for (let i = 0; i < this.orders.length; i++) {
                        let order =  this.orders[i];
                        let orderno =order.orderno;
                        if(orderNos.includes(orderno)){
                            this.tagOrders.push(this.orders[i])
                        }
                    }
                    this.setLogisticInfo();
                    this.setMerchantInfo();
                },
                setLogisticInfo(){
                    let content = ''
                    let _this = this
                    this.tagOrders.forEach(order=>{
                        content+=_this.getOrderLogisticNumbers(order);
                        let tel=order.c_tel2?order.c_tel2:order.c_tel1;
                        content+=' '+order.c_contact+tel+order.c_province+order.c_city+' '+order.c_district+order.c_address1+'\n'+_this.result_explain+"\n"
                    })
                    this.tagOrder.logisticInfo = content
                },
                setMerchantInfo(){
                    let content = ''
                    let _this = this
                    this.tagOrders.forEach(order=>{
                        content+=order.issuepartyname+' '+order.customer_descr_c+' '+order.soreference1+' '+_this.getOrderLogisticNumbers(order)
                        content += '\n'+_this.result_explain+ "\n"
                    })
                    this.tagOrder.merchantInfo = content
                },
                copyLogisticInfo(){
                    this.copyText(this.tagOrder.logisticInfo)
                },
                copyLogisticNumber(){
                    let text="";
                    checkData.forEach((code,i)=>{
                        if(this.picktotraceidMap[code] && this.picktotraceidMap[code].length>1){
                            this.picktotraceidMap[code].forEach((number,j)=>{
                                text += number+"\r\n";
                            });
                        }else {
                            this.orders.some(order=>{
                                if (order.orderno == code){
                                    if (order.soreference5) {
                                        text += order.soreference5+"\r\n";
                                    }
                                    return true;
                                }
                            });
                        }
                    });
                    text.substring(0,text.lastIndexOf("\r\n",text));
                    if (!text)text = " ";
                    this.copyText(text)
                },
                copyMerchantInfo(){
                    this.copyText(this.tagOrder.merchantInfo)
                },
                copyText(text){
                    try {
                        $('#clipboardDiv').text(text).select().focus();
                        document.execCommand("Copy");
                        tempTip.setIndex(1052)
                        tempTip.setDuration(2000)
                        tempTip.showSuccess('复制成功')
                    } catch (e) {
                        tempTip.setIndex(1052)
                        tempTip.setDuration(2000)
                        tempTip.showSuccess('复制失败：'+e)
                    }
                },
                getOrderLogisticNumbers(order){
                    let char = '';
                    let picktotraceids = this.picktotraceidMap[order.orderno];
                    if($.type(picktotraceids) ==='array'){
                        picktotraceids.forEach(function(picktotraceid,index,array){
                            if(array.length ===index+1)char+=picktotraceid;
                            else char+=picktotraceid+','
                        });
                    }else {char+=order.soreference5}
                    return char;
                }
            },
        });
    </script>
@endsection
