选择日期,刷新页面,计算保存

60 篇文章 0 订阅
38 篇文章 1 订阅

在这里插入图片描述
控制器:RyhAttendanceController……

class RyhAttendanceController extends AdminController
{
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = '考勤汇总';

    protected $description  =  [
        'index'     =>'列表',
        'create'    =>'新增',
        'edit'      =>'修改',
        'view'      =>'考勤明细',

    ];

    /**
     * 列表
     */
    public function index(Content $content)
    {
        $content->header($this->title)
            ->description($this->description['index'])
            ->breadcrumb(
                ['text' => $this->title, 'url' => '/attendance']
            )
            ->row($this->grid());
        return $content;
    }

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new PubFactory());
        /**
         * 屏蔽控件
         */
        $grid->disableExport();         //屏蔽导出
        $grid->disableRowSelector();    //屏蔽多选
        $grid->disableColumnSelector(); //屏蔽字段筛选
        $grid->disableCreateButton();   //屏蔽初始创建按钮
        $grid->disableFilter();         //屏蔽查询
        $grid->fixColumns(4, -1);  //固定显示列    head- 前几列  tail-后几列

        $grid->column('plant_no', __('工厂编号'));
        $grid->column('abbr', __('工厂简称'));
        $grid->column('name', __('工厂全称'));
        $grid->model()->where('type','0');
        $grid->model()->orderBy('plant_no','asc');

        /**
         * 列表行操作按钮
         */
        $grid->actions(function ($actions){
            $actions->disableView();
            $actions->disableDelete();
            $actions->disableEdit();
            $actions->append('<a href="/admin/attendance/'.$actions->getkey().'/detail" class="btn btn-sm btn-default" style="margin-right: 5px" >查看</a>');
        });

        return $grid;
    }

    /**
     * 查看
     * @param $id
     * @param Content $content
     * @return Content
     */
    public function detail($id,Content $content){
        $attendate = date("Y-m-d");
        $data = RyhAttendance::where(['factory_id'=>$id,'attendate'=>$attendate])->get();
        if (count($data)<1) {
            $factory_group =PubFactoryGroup::getGroupIDOptions(['factory_id'=>$id]);
            if (count($factory_group)<1) {
                admin_toastr(trans('admin.select_factroy_failed'));
                return redirect('/admin/attendance');
            }
            else {
                foreach($factory_group as $k => $v){;
                    DB::table('ryh_attendances')->insertGetId(
                        ['factory_id' => $id,'group_id'=>$k, 'attendate' => $attendate,'hr_id'=>getAdminID(),'created_at'=>date("Y-m-d H:i:s")]
                    );
                }
            }
          $data = RyhAttendance::where(['factory_id'=>$id,'attendate'=>$attendate])->get();
        }
        $return =[
            'factory_id'=> $id,
            'attendate' => $attendate,
            'status'    => $data[0]->status,
            'data'      => $data,
        ];
        $content
            ->header($this->title)
            ->description($this->description['view'])
            ->breadcrumb(
                ['text'=>$this->title,'url'=>'/attendance'],
                ['text'=>$this->description['view']]
            )->row(view('tpl.attendance.create',$return));
        return $content;
    }

    /**
     * 获取日期 工厂班组日期考勤信息
     * @param Request $request
     * @return array
     */
    public function getGroup(Request $request){
        $ymd = date("Y-m-d",strtotime($request->attendate));
        $data = RyhAttendance::where(['factory_id'=>$request->factory_id,'attendate'=>$ymd])->with('factory_group')->get();
        $return = [
            'list'   => $data,
            'status' => $data[0]->status,
            'total'  => count($data),
        ];
        return $return;
    }

    public function att_store(Request $request){
        //dd($request->all());
        DB::beginTransaction();
        try{
            // 获取考勤数据
            $attendate = date("Y-m-d",strtotime($request->attendate));
            $factory_id = $request->factory_id;
            //组装 班组考勤数据
            foreach (array_values($request->extra) as $k => $v){
                $group_data = [
                    'group_id'      => $v['groupid'],
                    'num_onjob'     => $v['numonjob'],
                    'num_new'       => $v['numnew'],
                    'num_leave'     => $v['numleave'],
                    'num_offjob'    => $v['numoffjob'],
                    'num_slow'      => $v['numslow'],
                    'num_quit'      => $v['numquit'],
                    'num_atte'      => $v['numatte'],
                    'dep_notes'     => $v['depnotes'],
                    'attend_notes'  => $v['attendnotes'],
                    'status'        => $request->status,
                    'updated_at'    => date("Y-m-d H:i:s"),
                ];
                //修改各班组考勤数据
                if(isset($v['id'])){
                    DB::table('ryh_attendances')->where('id',$v['id'])->update($group_data);
                }

            }
            DB::commit();
            admin_toastr(trans('admin.save_succeeded'));
        } catch (\Exception $e) {
            DB::rollBack();
            admin_toastr(trans('admin.actions_failed'));
        }
        return redirect('/admin/attendance/'.$factory_id.'/detail');
    }
}

create.php

<section class="content">
    <div class="row">
        <div class="col-md-12">
            <div class="box box-info">
                <div class="box-header with-border">
                    <div class="box-tools">
                        <div class="btn-group pull-right" style="margin-right: 5px">
                            <a href="/admin/attendance" class="btn btn-sm btn-default" title="列表"><i class="fa fa-list"></i><span class="hidden-xs">&nbsp;列表</span></a>
                        </div>
                    </div>
                </div>
                <!-- /.box-header -->
                <!-- form start -->
                <form action="/admin/attendance/att_store" method="post" accept-charset="UTF-8" class="form-horizontal" pjax-container>
                    <div class="box-body">
                        <div class="fields-group">
                            <div class="col-md-12">
                                <style>
                                    td .form-group {
                                        margin-bottom: 0 !important;
                                    }
                                </style>
                                {{-- 第一行  考勤日期--}}
                                <div class="row" style="padding-bottom: 10px">
                                    <div class="col-md-3">
                                        <label for="set_group_num" class=" control-label col-sm-3"  style="text-align: right">选择日期</label>
                                        <div class="col-sm-6">
                                            <input type="text" id="attendate" name="attendate" class="form-control attendate" required="1" placeholder="必填项" />
                                        </div>
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="col-sm-12" style="padding-left: 30px">
                                        <div id="has-many-extra" style="margin-top: 15px;">
                                            <table class="table table-has-many has-many-extra">
                                                <thead>
                                                    <tr>
{{--                                                        <th>类别</th>--}}
                                                        <th width="10%">班组</th>
                                                        <th width="10%">班长</th>
                                                        <th width="6%">编制人数</th>
{{--                                                        <th>上年底在职人数</th>--}}
                                                        <th width="6%">在职人数</th>
                                                        <th width="6%">当天入职人数</th>
                                                        <th width="6%">当天请假人数</th>
                                                        <th width="6%">当天调休人数</th>
                                                        <th width="6%">当天待工人数</th>
                                                        <th width="6%">当天离职人数</th>
                                                        <th width="6%">当天出勤人数</th>
                                                        <th width="12%">部门人员说明</th>
                                                        <th width="12%">考勤请假说明</th>
                                                    </tr>
                                                </thead>
                                                <tbody class="has-many-extra-forms">


                                                </tbody>
                                            </table>
                                            <template class="extra-tpl">
                                                <tr class="has-many-extra-form fields-group">
                                                    <td>
                                                        <div class="form-group">
                                                            <label for="group_id" class="col-sm-0 hidden control-label">班组</label>
                                                            <div class="col-sm-12">
                                                                <input type="hidden" id="id" name="extra[new___LA_KEY__][id]" value="" class="form-control extra  ids_key" />
                                                                <input type="hidden" id="group_id" name="extra[new___LA_KEY__][groupid]" value="" class="form-control extra  group_id"/>
                                                                <input type="text" id="group_name" name="extra[new___LA_KEY__][groupname]" value="" class="form-control extra  group_name" placeholder="班组名称" readonly/>
                                                            </div>
                                                        </div>
                                                    </td>
                                                    <td>
                                                        <div class="form-group">
                                                            <label for="monitor" class="col-sm-0 hidden control-label">班长</label>
                                                            <div class="col-sm-12">
                                                                <input type="text" id="monitor" name="extra[new___LA_KEY__][groupleader]" value="" class="form-control extra  monitor" placeholder="班长名称" readonly/>
                                                            </div>
                                                        </div>
                                                    </td>

                                                    <td>
                                                        <div class="form-group">
                                                            <label for="turner_num" class="col-sm-0 hidden control-label">编制人数</label>
                                                            <div class="col-sm-12">
                                                                <input type="text" id="turner_num" name="extra[new___LA_KEY__][turnernum]" value="" class="form-control extra turner_num" placeholder="编制人数" readonly/>
                                                            </div>
                                                        </div>
                                                    </td>
                                                    <td>
                                                        <div class="form-group">
                                                            <label for="num_onjob" class="col-sm-0 hidden control-label">在职人数</label>
                                                            <div class="col-sm-12">
                                                                <input type="text" id="num_onjob" name="extra[new___LA_KEY__][numonjob]" value="0" class="form-control extra num_onjob" placeholder="在职人数" readonly/>
                                                            </div>
                                                        </div>
                                                    </td>
                                                    <td>
                                                        <div class="form-group">
                                                            <label for="num_new" class="col-sm-0 hidden control-label">当天入职人数</label>
                                                            <div class="col-sm-12">
                                                                <input type="text" id="num_new" name="extra[new___LA_KEY__][numnew]" onkeyup="validationNumber(this,1,500,id_key)" class="form-control num_new extra new_num" value="0" placeholder="输入 入职人数" />
                                                            </div>
                                                        </div>
                                                    </td>
                                                    <td>
                                                        <div class="form-group">
                                                            <label for="num_leave" class="col-sm-0 hidden control-label">当天请假人数</label>
                                                            <div class="col-sm-12">
                                                                <input type="text" id="num_leave" name="extra[new___LA_KEY__][numleave]" onkeyup="validationNumber(this,1,500,id_key)" class="form-control num_leave extra leave_num" value="0" placeholder="输入 请假人数" />
                                                            </div>
                                                        </div>
                                                    </td>
                                                    <td>
                                                        <div class="form-group">
                                                            <label for="num_offjob" class="col-sm-0 hidden control-label">当天调休人数</label>
                                                            <div class="col-sm-12">
                                                                <input type="text" id="num_offjob" name="extra[new___LA_KEY__][numoffjob]" onkeyup="validationNumber(this,1,500,id_key)" class="form-control num_offjob extra offjob_num" value="0"  placeholder="输入 调休人数" />
                                                            </div>
                                                        </div>
                                                    </td>
                                                    <td>
                                                        <div class="form-group">
                                                            <label for="num_slow" class="col-sm-0 hidden control-label">当天待工人数</label>
                                                            <div class="col-sm-12">
                                                                <input type="text" id="num_slow" name="extra[new___LA_KEY__][numslow]" onkeyup="validationNumber(this,1,500,id_key)" class="form-control num_slow extra slow_num" value="0" placeholder="输入 待工人数" />
                                                            </div>
                                                        </div>
                                                    </td>
                                                    <td>
                                                        <div class="form-group">
                                                            <label for="num_quit" class="col-sm-0 hidden control-label">当天离职人数</label>
                                                            <div class="col-sm-12">
                                                                <input type="text" id="num_quit" name="extra[new___LA_KEY__][numquit]" onkeyup="validationNumber(this,1,500,id_key)" class="form-control num_quit extra quit_num" value="0" placeholder="输入 离职人数" />
                                                            </div>
                                                        </div>
                                                    </td>
                                                    <td>
                                                        <div class="form-group">
                                                            <label for="num_atte" class="col-sm-0 hidden control-label">当天出勤人数</label>
                                                            <div class="col-sm-12">
                                                                <input type="text" id="num_atte" name="extra[new___LA_KEY__][numatte]" onkeyup="validationNumber(this,1,500,id_key)" value="0" class="form-control num_atte extra atte_num" placeholder="出勤人数" />
                                                            </div>
                                                        </div>
                                                    </td>
                                                    <td>
                                                        <div class="form-group">
                                                            <label for="dep_notes" class="col-sm-0 hidden control-label">人员说明</label>
                                                            <div class="col-sm-12">
                                                                <input type="text" id="dep_notes" name="extra[new___LA_KEY__][depnotes]" class="form-control dep_notes extra dep_notes" value="" placeholder="人员说明" />
                                                            </div>
                                                        </div>
                                                    </td>
                                                    <td>
                                                        <div class="form-group">
                                                            <label for="attend_notes" class="col-sm-0 hidden control-label">请假说明</label>
                                                            <div class="col-sm-12">
                                                                <input type="text" id="attend_notes" name="extra[new___LA_KEY__][attendnotes]" class="form-control attend_notes extra attend_notes" placeholder="请假说明" />
                                                            </div>
                                                        </div>
                                                    </td>
                                                </tr>
                                            </template>
                                        </div>
                                    </div>
                                </div>
                                {{-- 全厂--}}
                                <div class="row">
                                    <div class="form-group">
                                         {{--全厂总人数--}}
                                        <div class="col-md-3">
                                            <label class="control-label col-sm-5">全厂总人数:</label>
                                            <div class="col-sm-7">
                                                <input type="text" class="form-control sum_num_onjob" id="sum_num_onjob" name="sum_num_onjob" value="@if(old('sum_num_onjob')){{ old('sum_num_onjob') }} @endif" readonly/>
                                            </div>
                                        </div>
                                        {{--出勤总人数--}}
                                        <div class="col-md-3">
                                            <label class="control-label col-sm-5">出勤总人数:</label>
                                            <div class="col-sm-7">
                                                <input type="text" class="form-control sum_num_atte" id="sum_num_atte" name="sum_num_atte" value="@if(old('sum_num_atte')){{ old('sum_num_atte') }} @endif" readonly/>
                                            </div>
                                        </div>
                                        {{--缺勤总人数--}}
                                        <div class="col-md-3">
                                            <label class="control-label col-sm-5">缺勤总人数:</label>
                                            <div class="col-sm-7">
                                                <input type="text" class="form-control sum_num_absence" id="sum_num_absence" name="sum_num_absence" style="color: red" value="@if(old('sum_num_absence')){{ old('sum_num_absence') }} @endif" readonly/>
                                            </div>
                                        </div>
                                        {{--当日出勤率--}}
                                        <div class="col-md-3">
                                            <label for="tailor_sam" class="asterisk control-label col-sm-5" title="当日出勤率">当日出勤率:</label>
                                            <div class="col-sm-7">
                                                <div class="input-group">
                                                    <input type="text" class="form-control att_rate" id="att_rate" name="att_rate" value="@if(old('att_rate')){{ old('att_rate') }} @endif" readonly/>
                                                    <span class="input-group-addon clearfix">%</span>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <!-- /.box-body -->
                    <div class="box-footer">
                        <input type="hidden" name="_token" value="{{ csrf_token() }}" id="_token">
                        <div class="col-md-2">
                            <input type="hidden" name="factory_id" value="{{$factory_id }}" id="factory_id">
                            <input type="hidden" value="{{$status }}" class="status" name="status">
                        </div>
                        <div class="col-md-8">
                            <div class="group_status">
                                <div class="btn-group pull-left" style="margin-right: 10px">
                                    <button type="submit" class="btn btn-primary submit" value="1" >保存</button>
                                </div>
                                <div class="btn-group pull-left" style="margin-right: 10px">
                                    <button type="submit" class="btn btn-primary submit" value="2" >提交</button>
                                </div>
                            </div>
                            <div class="btn-group pull-aright"  style="margin-right: 10px">
                                <a href="/admin/attendance"><button class="btn btn-primary">返回</button></a>
                            </div>
                        </div>
                    </div>
                    <!-- /.box-footer -->
                </form>
            </div>
        </div>
    </div>

</section>

<script data-exec-on-popstate>
    var index = 0;
    var tpl = $('template.extra-tpl');
    var initDate = new Date();
    var _token =$('#_token').val();
    var factory_id =$('#factory_id').val();
    var bl_status = 1;
    var att_date = ''
    if($('#attendate').val()){
         att_date = $('#attendate').val();
    }else if({{ $attendate }}){
         att_date = '{{ $attendate }}';
    }


    $(function () {
        $('.btn-primary').click(function (e) {
            var p_submit = $(e.target).attr('value');
            $('.status').val(p_submit)
        });
        $('.attendate').datetimepicker({"format":"YYYY-MM-DD","locale":"zh-CN","allowInputToggle":true,'defaultDate':new Date(), 'maxDate': new Date()});
        $('#attendate').val(att_date)
        init_extra(att_date)
        //日期切换
        $("#attendate").on("dp.change", function () {
            changeDate = $('#attendate').val();
            if(bl_status == 2){
                var title = "确认将放弃未保存信息!\n将要跳转至"+changeDate+"!";
                if(window.confirm(title)){
                    init_extra(changeDate)
                }else{
                    $('#attendate').val(att_date)
                }
            }else{
                init_extra(changeDate)
            }
        });
    });

    function init_extra(att_dates){
        index = 0;
        bl_status = 1;
        $('.has-many-extra-forms').html('');
        $.ajax({
            url:"/admin/attendance/getGroup",
            type:'POST',
            data:{'attendate':att_dates,'factory_id':factory_id,'_token':_token},
            cache:false,
            async:false,
            dataType:'json',
            success:function(data) {
                var $status = data.status;
                if($status == 1){
                    $('.group_status').show();
                }else{
                    $('.group_status').hide();
                }
                all_onjob =0 ;
                all_atte =0 ;
                all_quit =0 ;
                all_abs =0 ;
                all_rate = 100;
                if(data.total > 0 ){
                    for (var i=0;i<data.total;i++) {
                        var param = data.list[i];
                        var all_onjob = all_onjob + param.num_onjob;
                        var all_quit = all_quit + param.num_quit ;
                        var all_atte = all_atte + param.num_atte;
                        addHtml(param.id,param.group_id,param.factory_group['name'],param.factory_group['group_leader'],param.factory_group['turner_num'],param.num_onjob,param.num_new,param.num_leave,param.num_offjob,param.num_slow,param.num_quit,param.num_atte,param.dep_notes,param.attend_notes);
                    }
                    var all_abs = all_onjob - all_atte;
                    var all_rate = ((all_atte/all_onjob) *100).toFixed(2);
                    $("#sum_num_onjob").val(all_onjob);
                    $("#sum_num_quit").val(all_quit);
                    $("#sum_num_atte").val(all_atte);
                    $('#sum_num_absence').val(all_abs);
                    $('#att_rate').val(all_rate);
                }
            },
        });
    }
    function addHtml(id,group_id,group_name,monitor,turner_num,num_onjob,num_new,num_leave,num_offjob,num_slow,num_quit,num_atte,dep_notes,attend_notes){
        index++;
        var template = tpl.html().replace(/__LA_KEY__/g, index).replace(/group_id/g, 'group_id_'+index) //组别
            .replace(/__LA_KEY__/g, index).replace(/id_key/g, index)
            .replace(/__LA_KEY__/g, index).replace(/ids_key/g,'id_key_'+index)
            .replace(/__LA_KEY__/g, index).replace(/group_name/g, 'group_name_'+index)
            .replace(/__LA_KEY__/g, index).replace(/monitor/g, 'monitor_'+index) //班长
            .replace(/__LA_KEY__/g, index).replace(/turner_num/g, 'turner_num_'+index) //编制人数
            .replace(/__LA_KEY__/g, index).replace(/num_onjob/g, 'num_onjob_'+index) //在职人数
            .replace(/__LA_KEY__/g, index).replace(/num_new/g, 'num_new_'+index)     //当天入职人数
            .replace(/__LA_KEY__/g, index).replace(/num_leave/g, 'num_leave_'+index) //当天请假人数
            .replace(/__LA_KEY__/g, index).replace(/num_offjob/g, 'num_offjob_'+index)//当天调休人数
            .replace(/__LA_KEY__/g, index).replace(/num_slow/g, 'num_slow_'+index)//当天待工人数
            .replace(/__LA_KEY__/g, index).replace(/num_quit/g, 'num_quit_'+index)//当天离职人数
            .replace(/__LA_KEY__/g, index).replace(/num_atte/g, 'num_atte_'+index)//当天出勤人数
            .replace(/__LA_KEY__/g, index).replace(/dep_notes/g, 'dep_notes_'+index)//部门人员说明
            .replace(/__LA_KEY__/g, index).replace(/attend_notes/g, 'attend_notes_'+index);//考勤请假说明
        $('.has-many-extra-forms').append(template);
        if(id){
            $('.id_key_'+index).val(id);
        }
        if(group_id){
            $('.group_id_'+index).val(group_id);
        }
        if(group_name){
            $('.group_name_'+index).val(group_name);
        }
        if(monitor){
            $('.monitor_'+index).val(monitor);
        }
        if(turner_num){
            $('.turner_num_'+index).val(turner_num);
        }
        if(num_onjob){
            $('.num_onjob_'+index).val(num_onjob);
        }
        if(num_new){
            $('.num_new_'+index).val(num_new);
        }
        if(num_leave){
            $('.num_leave_'+index).val(num_leave);
        }
        if(num_offjob){
            $('.num_offjob_'+index).val(num_offjob);
        }
        if(num_slow){
            $('.num_slow_'+index).val(num_slow);
        }
        if(num_quit){
            $('.num_quit_'+index).val(num_quit);
        }
        if(num_atte){
            $('.num_atte_'+index).val(num_atte);
        }
        if(num_atte){
            $('.dep_notes'+index).val(dep_notes);
        }
        if(num_atte){
            $('.attend_notes'+index).val(attend_notes);
        }
    }

    //验证数字
    function validationNumber(e, num,maxNum=999,in_key) {
        var regu = /^[0-9]+\.?[0-9]*$/;
        if (e.value != "") {
            if (!regu.test(e.value)) {
                e.value = e.value.substring(0, e.value.length - 1);
                e.focus();
            }else if (e.value>=maxNum){
                e.value = maxNum;
                e.focus();
            }else {
                if (num == 0) {
                    if (e.value.indexOf('.') > -1) {
                        e.value = e.value.substring(0, e.value.length - 1);
                        e.focus();
                    }
                }
                if (e.value.indexOf('.') > -1) {
                    if (e.value.split('.')[1].length > num) {
                        e.value = e.value.substring(0, e.value.length - 1);
                        e.focus();
                    }
                }
            }
        }
        total_people(in_key);
    }
    //计算人数
    function total_people(index) {
        var factory_id = $('#factory_id').val();
        var group_id = $('#group_id_').val();
        var num_new = $('.num_new_'+index).val(); //当天入职人数
        var num_leave = $('.num_leave_'+index).val();//当天请假人数
        var num_offjob = $('.num_offjob_'+index).val();//当天调休人数
        var num_slow = $('.num_slow_'+index).val();//当天待工人数
        var num_quit = $('.num_quit_'+index).val();//当天离职人数
        var num_atte = $('.num_atte_'+index).val();//当天出勤人数
        var snum_onjob = (parseInt(num_atte) + parseInt(num_leave) + parseInt(num_offjob) + parseInt(num_slow));//在职人数

        $('#num_onjob_'+index).val(snum_onjob);
        // if(snum_onjob<0){
        //     sweetAlert('人数超出,请确认重新输入');
        // }

        var sum_num_new = 0;    //合计 当天入职人数列
        $('.new_num').each(function (k,v) {
            sum_num_new += parseInt($(v).val())
        });
        $("#sum_num_new").val(sum_num_new);

        var sum_num_leave = 0;    //合计 当天请假人数列
        $('.leave_num').each(function (k,v) {
            sum_num_leave += parseInt($(v).val())
        });
        $("#sum_num_leave").val(sum_num_leave);

        var sum_num_offjob = 0;    //合计 当天调休人数列
        $('.offjob_num').each(function (k,v) {
            sum_num_offjob += parseInt($(v).val())
        });
        $("#sum_num_offjob").val(sum_num_offjob);

        var sum_num_slow = 0;    //合计 当天待工人数列
        $('.slow_num').each(function (k,v) {
            sum_num_slow += parseInt($(v).val())
        });
        $("#sum_num_slow").val(sum_num_slow);

        var sum_num_quit = 0;    //合计 当天离职人数列
        $('.quit_num').each(function (k,v) {
            sum_num_quit += parseInt($(v).val())
        });
        $("#sum_num_quit").val(sum_num_quit);

        var sum_num_atte = 0;    //合计 当天出勤人数列
        $('.atte_num').each(function (k,v) {
            sum_num_atte += parseInt($(v).val())
        });
        $("#sum_num_atte").val(sum_num_atte);

        // var sum_num_onjob = 0;    //合计 当天在职人数列
        // $('.num_onjob').each(function (k,v) {
        //     sum_num_onjob += parseInt($(v).val())
        // });
        var sum_num_onjob = sum_num_atte+sum_num_leave+sum_num_offjob+sum_num_slow;
        $("#sum_num_onjob").val(sum_num_onjob);

        var sum_num_absence =parseInt(sum_num_leave) + parseInt(sum_num_offjob) + parseInt(sum_num_slow); //当天缺勤人数
        $('#sum_num_absence').val(sum_num_absence);

        var all_rate = (sum_num_atte /sum_num_onjob *100).toFixed(2);
        $("#att_rate").val(all_rate);

        console.log(att_rate)

    }

</script>
在Vue中,如果页面刷新时需要提示保存数据,可以使用beforeunload事件来实现。 具体步骤如下: 1. 在Vue的created生命周期钩子函数中,添加对window的beforeunload事件的监听。代码如下: ```javascript created() { window.addEventListener('beforeunload', this.handleBeforeUnload); }, ``` 2. 在Vue的beforeDestroy生命周期钩子函数中,移除beforeunload事件的监听。代码如下: ```javascript beforeDestroy() { window.removeEventListener('beforeunload', this.handleBeforeUnload); }, ``` 3. 定义handleBeforeUnload方法,该方法用于在页面刷新时显示提示信息。代码如下: ```javascript methods: { handleBeforeUnload(event) { const confirmationMessage = '您有未保存数据,确定要离开吗?'; event.returnValue = confirmationMessage; // 兼容Chrome浏览器和新版Firefox浏览器 return confirmationMessage; // 兼容旧版Firefox浏览器 }, }, ``` 通过上述代码,当用户在页面上进行了修改操作但未保存数据时,当用户刷新页面时,会弹出一个提示框,提醒用户是否离开页面。用户可以选择"确定"继续刷新页面,或者选择"取消"留在当前页面进行数据保存。 需要注意的是,这种方式不能完全确保数据保存,因为用户仍然可以选择关闭浏览器或者强制终止进程等方式离开页面,而无法触发beforeunload事件。因此,在实际开发中,最好是通过其他方式实现数据的自动保存,例如在用户操作后自动保存到服务器或者本地存储。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值