
@extends('layouts.app')
@section('title')临时工报表@endsection

@section('content')
    <div id="nav2">
        @component('personnel.menu')@endcomponent
    </div>
    <div class="d-none container-fluid" id="list">
        <div id="form_div"></div>
        <span class="dropdown">
                <button class="btn btn-outline-dark btn-sm form-control-sm dropdown-toggle tooltipTarget mt-1 mb-1" :class="[checkData.length>0?'btn-dark text-light':'']"
                        data-toggle="dropdown" title="导出所有页将会以搜索条件得到的过滤结果，将其全部记录（每一页）导出">
                    导出Excel
                </button>
                <div class="dropdown-menu">
                    <a class="dropdown-item" @click="laborReportExport(false)" href="javascript:">导出勾选内容</a>
                    <a class="dropdown-item" @click="laborReportExport(true)" href="javascript:">导出所有页</a>
                </div>
            </span>
        <label for="all" class="d-none" id="cloneCheckAll">
            <input id="all" type="checkbox" @click="checkAll($event)">全选
        </label>
        <table class="table table-sm table-bordered d-none text-nowrap " id="headerRoll">
        <table class="table table-sm table-hover table-striped d-none d-xl-block p-0 text-nowrap table-bordered" id="headerParent">
            <tr class="text-center" id="header"></tr>
            <tr v-for="(laborReport,i) in laborReports"  @click="selectedColor(laborReport.id)" :style="{'font-weight': laborReport.id==selectedStyle?'bold':''}">
                <td>
                    <input class="checkItem" type="checkbox" :value="laborReport.id" v-model="checkData" />
                </td>
                <td>@{{ i+1  }}</td>
                <td >
                    @can('人事管理-门卫审核')
                        <span >
                        <span v-if="laborReport.userDutyCheckVerifyUserId&&laborReport.amountOfJoined==1"  class="text-success">已审核</span>
                        <span v-else-if="laborReport.userDutyCheckVerifyUserId&&laborReport.amountOfJoined&&laborReport.sequence"  class="text-black">&nbsp;&nbsp;&nbsp;@{{laborReport.sequence}}/@{{laborReport.amountOfJoined}}</span>
                        <button v-else class="btn btn-sm btn-outline-secondary"  @click="guardClockAudit(laborReport.id,laborReport.user_duty_check_id)">门卫审核</button>
                        </span>
                    @else
                        <span v-if="laborReport.userDutyCheckVerifyUserId&&laborReport.amountOfJoined==1"  class="text-success">已审核</span>
                        <span v-else-if="laborReport.userDutyCheckVerifyUserId&&laborReport.amountOfJoined&&laborReport.sequence"  class="text-black">&nbsp;&nbsp;&nbsp;@{{ laborReport.sequence }}/@{{ laborReport.amountOfJoined }}</span>
                        <span v-else class="text-center"><b class="text-danger">门卫未审核</b></span>
                    @endcan
                    &nbsp;&nbsp;&nbsp;&nbsp;
                    @can('人事管理-组长审核')
                        <span>
                        <button v-if="laborReport.groupUserId&&!laborReport.is_exportGroup" @click="groupExport(laborReport.id,laborReport.name)" class="btn btn-sm btn-outline-danger">退组</button>
                        <span v-else-if="laborReport.groupUserId&&laborReport.is_exportGroup&&!laborReport.is_export" class="text-info">已退组</span>
                            <span v-else-if="laborReport.is_export" class="text-black">已退场</span>
                        <button v-else-if="laborReport.user_workgroup_id" @click="groupClockAudit(laborReport.id,laborReport.userWorkgroupNeedRemark)" class="btn btn-sm btn-outline-primary">组长审核</button>
                        </span>
                    @else
                        <span  v-if="laborReport.groupUserId&&!laborReport.is_exportGroup"><b class="text-success">在组</b></span>
                        <span v-else-if="laborReport.groupUserId&&laborReport.is_exportGroup&&!laborReport.is_export" class="text-info">已退组</span>
                        <span v-else-if="laborReport.is_export" class="text-black">已退场</span>
                        <span v-else-if="laborReport.user_workgroup_id" class="text-center"><b class="text-danger">组长未审核</b></span>
                    @endcan
                </td>
                <td class="text-muted">@{{laborReport.enter_number}}</td>
                <td>@{{laborReport.userWorkGroupName}}</td>
                <td >@{{laborReport.name}}</td>
                <td class="text-muted">@{{laborReport.mobile_phone}}</td>
                <td class="text-muted">@{{laborReport.identity_number}}</td>
                <td class="text-muted">@{{laborReport.labor_company}}</td>
                <td class="text-muted">@{{laborReport.enter_at}}</td>
                <td>@{{laborReport.checkInAt}}</td>
                <td class="text-muted">@{{laborReport.checkOutAt}}</td>
                <td >@{{ laborReport.exit_at }}</td>
                <td class="text-muted">@{{laborReport.verifyAt}}</td>
                <td class="text-muted"><span v-if="laborReport.verifyPerson">@{{laborReport.verifyPerson}}</span></td>
                <td class="text-muted"><span v-if="laborReport.relax_time">@{{laborReport.relax_time}}</span></td>
                {{--                        <td class="text-muted"><span v-if="laborReport.onlineDuration">@{{laborReport.onlineDuration}}</span></td>--}}
                <td class="text-muted"><span v-if="laborReport.thisRecordOnlineTime">@{{laborReport.thisRecordOnlineTime}}</span></td>
                <td><span v-if="laborReport.thisRecordWorkingTime">@{{laborReport.thisRecordWorkingTime}}</span></td>
                {{--                        <td><span v-if="laborReport.workingDuration">@{{laborReport.workingDuration}}</span></td>--}}
                <td><span v-if="laborReport.remark">@{{laborReport.remark}}</span></td>
            </tr>
        </table>
        <table class="table table-striped table-bordered table-hover p-0 d-table  d-xl-none" style="background: rgb(255, 255, 255);">
            <tr v-for="laborReport in laborReports">
                <td style="filter:grayscale(30%);">
                    <div  class="pl-3 mt-1">
                        <div style="transform:scale(1)" class="pl-0">
                                        <span class="mr-3 text-nowrap">
                                            <span >操作：</span>
                                            <span >
                                                @can('人事管理-门卫审核')
                                                    <span >
                                <b v-if="laborReport.userDutyCheckVerifyUserId&&laborReport.amountOfJoined==1"   class="text-success">已审核</b>
                                <b v-else-if="laborReport.userDutyCheckVerifyUserId&&laborReport.amountOfJoined&&laborReport.sequence"  class="text-black">&nbsp;&nbsp;&nbsp;@{{laborReport.sequence}}/@{{laborReport.amountOfJoined}}</b>
                                <button v-else style="transform:scale(1.1)" class="btn btn-lg btn-outline-secondary"  @click="guardClockAudit(laborReport.id,laborReport.user_duty_check_id)">门卫审核</button>
                                </span>
                                                @else
                                                    <b v-if="laborReport.userDutyCheckVerifyUserId&&laborReport.amountOfJoined==1"  class="text-success">已审核</b>
                                                    <b v-else-if="laborReport.userDutyCheckVerifyUserId&&laborReport.amountOfJoined&&laborReport.sequence"  class="text-black">&nbsp;&nbsp;&nbsp;@{{ laborReport.sequence }}/@{{ laborReport.amountOfJoined }}</b>
                                                    <span v-else class="text-center"><b class="text-danger">门卫未审核</b></span>
                                                @endcan
                                    &nbsp;&nbsp;&nbsp;&nbsp;
                                @can('人事管理-组长审核')
                                                    <span>
                                <button v-if="laborReport.groupUserId&&!laborReport.is_exportGroup" @click="groupExport(laborReport.id,laborReport.name)" style="transform:scale(1.1)" class="btn btn-lg btn-danger">退组</button>
                                <b v-else-if="laborReport.groupUserId&&laborReport.is_exportGroup&&!laborReport.is_export" class="text-info">已退组</b>
                                    <b v-else-if="laborReport.is_export" class="text-black">已退场</b>
                                <button v-else-if="laborReport.user_workgroup_id" @click="groupClockAudit(laborReport.id,laborReport.userWorkgroupNeedRemark)" class="btn btn-lg btn-outline-primary" style="transform:scale(1.1)" >组长审核</button>
                                </span>
                                                @else
                                                    <span  v-if="laborReport.groupUserId&&!laborReport.is_exportGroup"><b class="text-success">在组</b></span>
                                                    <b v-else-if="laborReport.groupUserId&&laborReport.is_exportGroup&&!laborReport.is_export" class="text-info">已退组</b>
                                                    <b v-else-if="laborReport.is_export" class="text-black">已退场</b>
                                                    <span v-else-if="laborReport.user_workgroup_id" class="text-center"><b class="text-danger">组长未审核</b></span>
                                                @endcan
                                            </span>
                                        </span>
                            <span class="mr-3   text-nowrap"><span class="text-black">进场时间：</span><span class="text-black-50">@{{laborReport.enter_at  }}</span></span>
                            <span class="mr-3 text-nowrap"><span class="text-muted">退组时间：</span><span style="color:#af7651" v-if="">@{{ laborReport.checkOutAt }} </span></span>
                            <span class="mr-3 text-nowrap"><span class="text-black">退场时间：</span><span style="color:#af7651">@{{ laborReport.exit_at }}</span></span>
                            {{--                                    <span class="mr-3 text-nowrap"><span class="text-black">进场编号：</span><span style="color:#af7651">@{{ laborReport.enter_number }}</span></span>--}}
                            <span class="mr-3  text-nowrap"><span class="text-black">小组：</span><span class="text-black-50">@{{laborReport.userWorkGroupName  }}</span></span>
                            <span class="mr-3   text-nowrap"><span class="text-black">临时工：</span><span class="text-black-50">@{{ laborReport.name }} </span></span>
                            {{--                                    <span class="mr-3 text-nowrap"><span class="text-black">电话：</span><span style="color:#af7651" v-if="">@{{ laborReport.mobile_phone }} </span></span>--}}
                            {{--                                    <span class="mr-3 text-nowrap"><span class="text-black">身份证号：</span><span style="color:#af7651" v-if="">@{{ laborReport.identity_number }} </span></span>--}}
                            {{--                                    <span class="mr-3 text-nowrap"><span class="text-black">劳务所：</span><span style="color:#af7651" v-if="">@{{ laborReport.labor_company }} </span></span>--}}
                            {{--                                    <span class="mr-3 text-nowrap"><span class="text-black">进组时间：</span><span style="color:#af7651" v-if="">@{{ laborReport.checkInAt }} </span></span>--}}
                            {{--                                    <span class="mr-3 text-nowrap"><span class="text-black">审核时间：</span><span style="color:#af7651" v-if="">@{{ laborReport.verifyAt }} </span></span>--}}
                            {{--                                    <span class="mr-3 text-nowrap"><span class="text-black">审核人：</span><span style="color:#af7651" v-if="">@{{ laborReport.verifyPerson }} </span></span>--}}
                            {{--                                    <span class="mr-3 text-nowrap"><span class="text-black">晚饭打卡(分)：</span><span style="color:#af7651" v-if="">@{{ laborReport.relax_time }} </span></span>--}}
                            {{--                                    <span class="mr-3 text-nowrap"><span class="text-black">在线时长：</span><span style="color:#af7651" v-if="">@{{ laborReport.onlineDuration }} </span></span>--}}
                            {{--                                    <span class="mr-3 text-nowrap"><span class="text-black">本次工作时长：</span><span style="color:#af7651" v-if="">@{{ laborReport.workingDuration }} </span></span>--}}
                        </div>
                    </div>
                </td>
            </tr>
        </table>
        <div class="text-info h5 btn btn">{{$laborReports->count()}}/@{{ sum }}</div>
        <div>{{$laborReports->appends($paginateParams)->links()}}</div>
        {{--      选择晚饭时长弹框      --}}
        <div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <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">
                            <span aria-hidden="true">&times;</span>
                        </button>
                    </div>
                    <div class="modal-body">
                        <form>
                            <div class="form-group">
                                <label for="relax_time" class="col-form-label">选择晚饭时长:</label>
                                <select class="form-control" id="relax_time" v-model="relax_time">
                                    <option value="30">30分</option>
                                    <option value="60">60分</option>
                                </select>
                            </div>
                        </form>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                            <span class="btn btn-block" aria-hidden="true">取消</span>
                        </button>
                        <button type="button" class="btn btn-primary" data-dismiss="modal" @click="makeSureRelax_time">确定</button>
                    </div>
                </div>
            </div>
        </div>
        {{--      特定组需要添加备注      --}}
        <div class="modal fade" id="remarkModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <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">
                            <span aria-hidden="true">&times;</span>
                        </button>
                    </div>
                    <div class="modal-body">
                        <form>
                            <div class="form-group">
                                <label for="remark" class="col-form-label">备注:</label>
                                <textarea class="form-control" id="remark"></textarea>
                            </div>
                        </form>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                            <span class="btn btn-block" aria-hidden="true">取消</span>
                        </button>
                        <button type="button" class="btn btn-primary" data-dismiss="modal" @click="addRemarkAndGroupClock">确定</button>
                    </div>
                </div>
            </div>
        </div>
        <!-- 是否晚餐弹框 -->
        <div class="modal fade" id="dinnerModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" >
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-body">
                        <b class="font-weight-bold">是否晚餐？</b>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                            <span class="btn btn-block" @click="noDinner">否</span>
                        </button>
                        <button  type="button" class="btn btn-primary" data-dismiss="modal" @click="haveDinner">是</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
@endsection

@section('lastScript')
    <script type="text/javascript" src="{{asset('js/queryForm/export200813b.js')}}"></script>
    <script type="text/javascript" src="{{asset('js/queryForm/queryForm200813b.js')}}"></script>
    <script type="text/javascript" src="{{asset('js/queryForm/header200814.js')}}"></script>
    <script>
        let today=(new Date());
        function isTomorrow(){
            let now=(new Date());
            const dateTime=new Date(now.setDate(now.getDate()+1));
            if(dateTime<=today)return true;
            else return false;
        }
        function reloadOnTomorrow(){
            if(isTomorrow()){
                window.location.reload();
            }
        }
        window.onfocus=reloadOnTomorrow;
        setInterval(reloadOnTomorrow,1000*60*60)
    </script>
    <script>
        @if(isset($request))
        let request={!! json_encode($request) !!};
        @endif
        let vue = new Vue({
            el:"#list",
            data:{
                laborReports:[
                        @foreach($laborReports as $laborReport)
                    {id:'{{$laborReport->id}}',enter_number:'{{$laborReport->enter_number}}'
                        ,@if($laborReport->userWorkgroup)user_workgroup_id:'{{$laborReport->userWorkgroup->id}}',
                        userWorkgroupNeedRemark:'{{$laborReport->userWorkgroup->isNeedRemark}}',
                        userWorkGroupName:'{{$laborReport->userWorkgroup->name}}',@endif
                        userId:'{{$laborReport->user_id}}',name:'{{$laborReport->name}}'
                        ,mobile_phone:'{{$laborReport->mobile_phone}}',identity_number:'{{$laborReport->identity_number}}',labor_company:'{{$laborReport->labor_company}}'
                        ,checkInAt:'{{$laborReport->check_in_at}}', relax_time:'{{$laborReport->relax_time}}',
                        is_exportGroup:'{{$laborReport->is_exportGroup}}',is_export:'{{$laborReport->is_export}}',
                        verifyAt:'{{$laborReport->verify_at}}',groupUserId:'{{$laborReport->group_user_id}}',verifyPerson:'{{$laborReport->user['name']}}',
                        checkOutAt:'{{$laborReport->check_out_at}}',onlineDuration:'{{$laborReport->online_duration}}',
                        workingDuration:'{{$laborReport->working_duration}}', created_at:'{{$laborReport->created_at}}',
                        enter_at:'{{$laborReport->enter_at}}',exit_at:'{{$laborReport->exit_at}}',
                        thisRecordOnlineTime:'{{$laborReport->thisRecordOnlineTime}}',
                        thisRecordWorkingTime:'{{$laborReport->thisRecordWorkingTime}}',
                        sequence:'{{$laborReport->sequence}}',amountOfJoined:'{{$laborReport->amountOfJoined}}',remark:'{{$laborReport->remark}}',
                        @if($laborReport->userDutyCheck)user_duty_check_id:'{{$laborReport->userDutyCheck->id}}', userDutyCheckVerifyUserId:'{{$laborReport->userDutyCheck->verify_user_id}}'
                        ,userDutyCheckType:'{{$laborReport->userDutyCheck->type}}',userDutyCheckAt:'{{$laborReport->userDutyCheck->checked_at}}',@endif},
                    @endforeach
                ],
                i:0,
                userWorkGroups:[
                        @foreach($userWorkGroups as $userWorkGroup)
                    {name:'{{$userWorkGroup->id}}',value:'{{$userWorkGroup->name}}'},
                    @endforeach
                ],
                checkData:[],
                permittingWorkgroups:{!! $permittingWorkgroups !!},
                relax_time:'',dateTime:'',selectedStyle:'',
                sum:{!! $laborReports->total() !!},
            },
            mounted:function(){
                /*initEcho();*/
                let _this=this;
/*                let laborReports=_this.laborReports;
                //进场
                let tokenOfBroadcastEnterAndLeave='{{$tokenOfBroadcastEnterAndLeave}}';
                //console.log(tokenOfBroadcastEnterAndLeave)
                if(tokenOfBroadcastEnterAndLeave){
                    Echo.channel('{{$laravelEchoPrefix}}'+tokenOfBroadcastEnterAndLeave).listen('ImportEvent',(e)=>{
                        let labor=e.laborReport;
                        laborReports.push(labor);
                    });
                }
                //退场
                Echo.channel('{{$laravelEchoPrefix}}laborReport').listen('ExportEvent',(e)=>{
                    let labor=e.laborReport;
                    laborReports.every(function (laborReport) {
                        if (laborReport.id==labor.id){
                            laborReport.thisRecordOnlineTime=labor.thisRecordOnlineTime;
                            laborReport.thisRecordWorkingTime=labor.thisRecordWorkingTime;
                            laborReport.is_export=labor.is_export;
                            laborReport.exit_at=labor.exit_at;
                            return false
                        }
                        return true;
                    });
                });
                //门卫审核
                Echo.channel('{{$laravelEchoPrefix}}userDutyCheck').listen('GuardAuditEvent',(e)=>{
                    let userDutyCheck=e.userDutyCheck;
                    laborReports.every(function (laborReport) {
                        if (laborReport.user_duty_check_id==userDutyCheck.id){
                            laborReport.userDutyCheckVerifyUserId=userDutyCheck.verify_user_id;
                            laborReport.user_duty_check_id=userDutyCheck.id;
                            return false
                        }
                        return true;
                    });
                });
                //组长审核
                Echo.channel('{{$laravelEchoPrefix}}laborReport').listen('TeamAuditEvent',(e)=>{
                    let labor=e.laborReport;
                    laborReports.every(function (laborReport) {
                        if (laborReport.id==labor.id){
                            if(labor.remark){
                                laborReport.remark=labor.remark;
                            }
                            laborReport.verifyAt=labor.verify_at;
                            laborReport.groupUserId=labor.group_user_id;
                            laborReport.verifyPerson=labor.verifyPerson;
                            return false
                        }
                        return true;
                    });
                });
                //进组
                _this.permittingWorkgroups.forEach(function(workgroup){
                    Echo.channel('{{$laravelEchoPrefix}}'+workgroup.token).listen('ClockinEvent',(e)=>{
                        setTimeout(function () {
                            window.location.reload();
                        },500);
                    });
                });
                //退组
                _this.permittingWorkgroups.forEach(function(workgroup){
                    Echo.channel('{{$laravelEchoPrefix}}'+workgroup.token).listen('ClockoutEvent',(e)=>{
                        let labor=e.laborReport;
                        laborReports.every(function (laborReport) {
                            if (laborReport.id==labor.id){
                                laborReport.thisRecordOnlineTime=labor.thisRecordOnlineTime;
                                laborReport.thisRecordWorkingTime=labor.thisRecordWorkingTime;
                                laborReport.is_exportGroup=labor.is_exportGroup;
                                laborReport.checkOutAt=labor.check_out_at;
                                if (labor.relax_time){
                                    laborReport.relax_time=labor.relax_time;
                                }
                                return false
                            }
                            return true;
                        });
                    });
                });*/
                $(".tooltipTarget").tooltip({'trigger':'hover'});
                $('#list').removeClass('d-none');
                let data=[
                    [
                        {name:'created_at_start',type:'dateTime',tip:'选择显示指定日期的起始时间'},
                        {name:'user_workgroup_id',type:'search_select',tip:['',''],placeholder:['小组',''],data:this.userWorkGroups},
                        {name:'enter_number',type:'input',tip:'进场编号:支持15天内模糊搜索，15天外精确搜索',placeholder: '进场编号'},
                        {name:'is_export',type:'checkbox',data:[{name:true,value:'显示已退场'}]},
                    ],
                    [
                        {name:'created_at_end',type:'dateTime',tip:'选择显示指定日期的结束时间'},
                        {name:'mobile_phone',type:'input',tip:'',placeholder: '电话号'},
                        {name:'identity_number',type:'input',tip:'',placeholder: '身份证号'},
                    ],
                ];
                this.form = new query({
                    el:"#form_div",
                    condition:data,
                });
                this.form.init();
                let column = [
                    {name:'cloneCheckAll',customization:true,type:'checkAll',column:'id',
                        dom:$('#cloneCheckAll').removeClass('d-none'), neglect: true},
                    {name:'index',value: '序号', neglect: true},
                    {name:'operation',value: '操作', neglect: true},
                    {name:'enter_number',value: '进厂编号', style:'background-color: rgb(241, 234, 190)'},
                    {name:'userWorkGroupName',value: '小组', style:'background-color: rgb(241, 234, 190)'},
                    {name:'name',value: '临时工', style:'background-color: rgb(241, 234, 190)'},
                    {name:'mobile_phone',value: '电话', style:'background-color: rgb(241, 234, 190)'},
                    {name:'identity_number',value: '身份证号', style:'background-color: rgb(241, 234, 190)'},
                    {name:'labor_company',value: '劳务所', style:'background-color: rgb(241, 234, 190)'},
                    {name:'enter_at',value: '进场时间'},
                    {name:'checkInAt',value: '进组时间'},
                    {name:'checkOutAt',value: '退组时间'},
                    {name:'exit_at',value: '退场时间'},
                    {name:'verifyAt',value: '审核时间'},
                    {name:'verifyPerson',value: '审核人'},
                    {name:'relax_time',value: '晚饭打卡(分)', neglect: true},
                    {name:'thisRecordOnlineTime',value: '在线时长', neglect: true},
                    {name:'thisRecordWorkingTime',value: '本次工作时长', neglect: true},
                    {name:'remark',value: '备注'},
                ];
                setTimeout(function () {
                    let header = new Header({
                        el: "#header",
                        column: column,
                        data: _this.laborReports,
                        restorationColumn: 'id',
                        fixedTop:($('#form_div').height())+2,
                        offset:0.5,
                        vue:vue
                    });
                    header.init();
                },0);
            },
            watch:{
                checkData:{
                    handler(){
                        if (this.checkData.length === this.laborReports.length){
                            document.querySelector('#all').checked = true;
                            document.querySelector('#all_temp').checked = true;
                        }else {
                            document.querySelector('#all').checked = false;
                            document.querySelector('#all_temp').checked = false;
                        }
                    },
                    deep:true
                }
            },
            methods:{
                selectedColor(id){
                    if (id==this.selectedStyle){
                        this.selectedStyle='';
                        return;
                    }
                    this.selectedStyle=id;
                },
                checkAll(e){
                    if (e.target.checked){
                        this.laborReports.forEach((el,i)=>{
                            if (this.checkData.indexOf(el.id) == '-1'){
                                this.checkData.push(el.id);
                            }
                        });
                    }else {
                        this.checkData = [];
                    }
                },
                laborReportExport(checkAllSign){
                    let url = '{{url('laborReport/export')}}';
                    let token='{{ csrf_token() }}';
                    excelExport(checkAllSign,this.checkData,url,this.sum,token);
                },
                //门卫审核
                guardClockAudit(id,user_duty_check_id){
                    let url='{{url("laborReport/guardClockAudit")}}';
                    let _this=this;
                    axios.post(url,{id:id,user_duty_check_id:user_duty_check_id})
                        .then(function (response) {
                            if (!response.data.success){
                                tempTip.setDuration(3000);
                                tempTip.show(response.data.data);
                                return;
                            }
                            _this.laborReports.every(function (laborReport) {
                                if (laborReport.id==id){
                                    laborReport.userDutyCheckVerifyUserId=response.data.data;
                                    tempTip.setDuration(3000);
                                    tempTip.showSuccess('审核通过！');
                                    return false
                                }
                                return true;
                            });
                        }).catch(function (err) {
                        tempTip.setDuration(4000);
                        tempTip.show('审核失败！网络错误：'+err);
                    });
                },
                ////组长打卡审核(特定组添加备注)
                addRemarkAndGroupClock(){
                    let _this=this;
                    let id = getSelectId();
                    let remark=document.getElementById('remark').value;
                    let url='{{url("laborReport/addRemarkAndGroupClock")}}';
                    if (remark==null|| remark=='' || remark=="undefined"){
                        tempTip.setDuration(3000);
                        tempTip.show("您还未添加任何备注");
                        return;
                    }
                    axios.post(url,{id:id,remark:remark})
                        .then(function (response) {
                            if (!response.data.success){
                                tempTip.setDuration(3000);
                                tempTip.show(response.data.data);
                                return;
                            }
                            _this.laborReports.every(function (laborReport) {
                                if (laborReport.id==id){
                                    laborReport.groupUserId=response.data.data.group_user_id;
                                    laborReport.verifyAt=response.data.data.verify_at;
                                    laborReport.verifyPerson=response.data.data.verifyPerson;
                                    laborReport.remark=response.data.data.remark;
                                    tempTip.setDuration(3000);
                                    tempTip.showSuccess('审核通过！');
                                    return false
                                }
                                return true;
                            });
                        }).catch(function (err) {
                        tempTip.setDuration(4000);
                        tempTip.show('审核失败！网络错误：'+err);
                    });

                },
                //组长打卡审核
                groupClockAudit(id,userWorkgroupNeedRemark){
                    let url='{{url("laborReport/groupClockAudit")}}';
                    let _this=this;
                    if (userWorkgroupNeedRemark){
                        $('#remarkModal').modal('show');
                        selectId(id);
                        return;
                    }
                    axios.post(url,{id:id})
                        .then(function (response) {
                            if (!response.data.success){
                                tempTip.setDuration(3000);
                                tempTip.show(response.data.data);
                                return;
                            }
                            _this.laborReports.every(function (laborReport) {
                                if (laborReport.id==id){
                                    laborReport.groupUserId=response.data.data.group_user_id;
                                    laborReport.verifyAt=response.data.data.verify_at;
                                    laborReport.verifyPerson=response.data.data.verifyPerson;
                                    tempTip.setDuration(3000);
                                    tempTip.showSuccess('审核通过！');
                                    return false
                                }
                                return true;
                            });
                        }).catch(function (err) {
                        tempTip.setDuration(4000);
                        tempTip.show('审核失败！网络错误：'+err);
                    });
                },
                //有晚餐
                haveDinner(){
                    $('#exampleModal').modal('show');
                },
                noDinner(){
                    let _this=this;
                    let id = getSelectId();
                    let url='{{url("laborReport/groupExport")}}';
                    axios.post(url,{id:id})
                        .then(function (response) {
                            if (!response.data.success){
                                tempTip.setDuration(3000);
                                tempTip.show(response.data.data);
                                return;
                            }
                            _this.laborReports.every(function (laborReport) {
                                if (laborReport.id==id){
                                    laborReport.checkOutAt=response.data.data.check_out_at;
                                    laborReport.workingDuration=response.data.data.working_duration;
                                    laborReport.is_exportGroup=response.data.data.is_exportGroup;
                                    laborReport.onlineDuration=response.data.data.online_duration;
                                    tempTip.setDuration(3000);
                                    tempTip.showSuccess('退组成功！');
                                    return false
                                }
                                return true;
                            });
                        }).catch(function (err) {
                        tempTip.setDuration(4000);
                        tempTip.show('退组失败！网络错误：'+err);
                    });
                },
                //退场有晚饭时间
                makeSureRelax_time(){
                    let url='{{url("laborReport/groupExportEnsure")}}';
                    let _this=this;
                    let id = getSelectId();
                    axios.post(url,{id:id,relax_time:_this.relax_time})
                        .then(function (response) {
                            if (!response.data.success){
                                tempTip.setDuration(3000);
                                tempTip.show(response.data.data);
                                return;
                            }
                            _this.laborReports.every(function (laborReport) {
                                if (laborReport.id==id){
                                    laborReport.checkOutAt=response.data.data.check_out_at;
                                    laborReport.workingDuration=response.data.data.working_duration;
                                    laborReport.relax_time=response.data.data.relax_time;
                                    laborReport.is_exportGroup=response.data.data.is_exportGroup;
                                    laborReport.onlineDuration=response.data.data.online_duration;
                                    tempTip.setDuration(3000);
                                    tempTip.showSuccess('退组成功！');
                                    return false
                                }
                                return true;
                            });
                        }).catch(function (err) {
                        tempTip.setDuration(4000);
                        tempTip.show('退组失败！网络错误：'+err);
                    });
                },
                //组长点击退组,
                groupExport(id,name){
                    let _this=this;
                    _this.laborReports.every(function (laborReport) {
                        if (laborReport.id==id){
                            _this.dateTime=new Date(new Date(laborReport.created_at).toLocaleDateString());
                            return false;
                        }
                        return true;
                    });
                    const dateTime=new Date(_this.dateTime.setDate(_this.dateTime.getDate()+1));
                    const start = new Date(new Date(new Date().toLocaleDateString()).getTime()+19*60*60*1000);
                    if(!confirm("确定要临时工“"+name+"“退组吗？")){return}
                    if (new Date()>=start || new Date()>dateTime){
                        $('#dinnerModal').modal('show');
                        selectId(id);
                        return;
                    }
                    let url='{{url("laborReport/groupExport")}}';
                    axios.post(url,{id:id})
                        .then(function (response) {
                            if (!response.data.success){
                                tempTip.setDuration(3000);
                                tempTip.show(response.data.data);
                                return;
                            }
                            _this.laborReports.every(function (laborReport) {
                                if (laborReport.id==id){
                                    laborReport.checkOutAt=response.data.data.check_out_at;
                                    laborReport.workingDuration=response.data.data.working_duration;
                                    laborReport.is_exportGroup=response.data.data.is_exportGroup;
                                    laborReport.onlineDuration=response.data.data.online_duration;
                                    tempTip.setDuration(3000);
                                    tempTip.showSuccess('退组成功！');
                                    return false
                                }
                                return true;
                            });
                        }).catch(function (err) {
                        tempTip.setDuration(5000);
                        tempTip.show('退组失败！网络错误：'+err);
                    });
                },
                owner_seek:function (e) {
                    let _this=this;
                    let $val=e.target.value;
                    if($val==='')_this.filterData.user_workgroup_id='';
                    else
                        _this.userWorkGroups.forEach(function (userWorkGroup) {
                            if (userWorkGroup.name.includes($val)){
                                _this.filterData.user_workgroup_id=userWorkGroup.id;
                            }
                        });
                },
            },
        });

        let select_id = 0;
        function selectId(id) {
            select_id = id;
        }
        function getSelectId() {
            return select_id;
        }
    </script>
@endsection
