@extends('layouts.app')
@section('title')编辑-临时工@endsection

@section('content')
    <span id="nav2">
        @component('maintenance.menu')@endcomponent
    </span>

    <div class="card col-md-8 offset-md-2 mt-5" id="edit">
        <div class="card-body">
            <form method="POST" action="{{url("maintenance/userLabor/{$userLabor->user_id}")}}">
                @csrf
                @method('PUT')
                <div class="form-group row pt-0">
                    <label for="full_name" class="form-check-label col-3 pull-left">姓名：</label>
                    <input name="full_name" :value="userLabor.full_name" id="full_name" class="@error('full_name') is-invalid @enderror col-7 form-control" type="text">
                    @error('full_name')
                    <span class="invalid-feedback col-7 offset-3 mt-0" role="alert">
                    <strong>{{ $errors->first('full_name') }}</strong>
                    </span>
                    @enderror
                </div>
                <div class="form-group row">
                    <label for="mobile_phone" class="form-check-label col-3 pull-left">电话：</label>
                    <input name="mobile_phone" :value="userLabor.mobile_phone"  id="mobile_phone" class="@error('mobile_phone') is-invalid @enderror col-7 form-control" type="text">
                    @error('mobile_phone')
                    <span class="invalid-feedback col-7 offset-3 mt-0" role="alert">
                    <strong>{{ $errors->first('mobile_phone') }}</strong>
                    </span>
                    @enderror
                </div>
                <div class="form-group row">
                    <label for="gender" class="form-check-label col-3 pull-left">性别：</label>
                    <div class="custom-control custom-radio col-4">
                        <input v-if="userLabor.gender=='男'" checked name="gender" value="男"  type="radio" id="boy" class=" custom-control-input" >
                        <input v-else name="gender" value="男"  type="radio" id="boy" class=" custom-control-input" >
                        <label class="custom-control-label" for="boy">男</label>
                    </div>
                    <div class="custom-control custom-radio col-4">
                        <input v-if="userLabor.gender=='女'" checked name="gender" value="女"  type="radio" id="girl" class=" custom-control-input" >
                        <input v-else name="gender" value="女"  type="radio" id="girl" class=" custom-control-input" >
                        <label  class="custom-control-label" for="girl">女</label>
                    </div>
                    @error('gender')
                    <span class="invalid-feedback col-7 offset-3 mt-0" role="alert">
                    <strong>{{ $errors->first('gender') }}</strong>
                    </span>
                    @enderror
                </div>
                <div class="form-group row">
                    <label for="identity_number"  class="@error('identity_number') is-invalid @enderror form-check-label col-3 pull-left">身份证号：</label>
                    <input name="identity_number" :value="userLabor.identity_number" id="identity_number" class="col-7 form-control" type="text">
                    @error('identity_number')
                    <span class="invalid-feedback col-7 offset-3 mt-0" role="alert">
                    <strong>{{ $errors->first('identity_number') }}</strong>
                    </span>
                    @enderror
                </div>
                <div class="form-group row">
                    <label for="default_hour_price" class="form-check-label col-3 pull-left">默认计时单价/小时：</label>
                    <input name="default_hour_price" :value="userLabor.default_hour_price" id="default_hour_price" class="@error('default_hour_price') is-invalid @enderror col-7 form-control" type="text">
                    @error('default_hour_price')
                    <span class="invalid-feedback col-7 offset-3 mt-0" role="alert">
                    <strong>{{ $errors->first('default_hour_price') }}</strong>
                    </span>
                    @enderror
                </div>
                <div class="form-group row">
                    <label for="name" class="form-check-label col-3 pull-left">劳务所：</label>
{{--                    <input name="id" :value="userLabor.laborCompanyName" id="id" class="@error('id') is-invalid @enderror col-7 form-control" type="text">--}}
                    <select name="name" id="name" class="@error('name') is-invalid @enderror col-7 form-control" type="text" >
                        <option selected>@{{ userLabor.laborCompanyName }}</option>
                        <option v-for="laborCompany in laborCompanies" >@{{ laborCompany.name }}</option>
                    </select>
                    @error('name')
                    <span class="invalid-feedback col-7 offset-3 mt-0" role="alert">
                    <strong>{{ $errors->first('name') }}</strong>
                    </span>
                    @enderror
                </div>
                <div class="form-group row pt-3">
                    <button type="submit" class="col-7 offset-3 btn btn-success">提交更改</button>
                </div>
            </form>
        </div>
    </div>
@endsection

@section('lastScript')
    <script>
        new Vue({
            el:"#edit",
            data:{
                userLabor:{full_name:"{{old('full_name')??$userLabor->userDetail->full_name}}",
                    mobile_phone:'{{old('mobile_phone')??$userLabor->userDetail->mobile_phone}}',
                    gender:'{{old('gender')??$userLabor->userDetail->gender}}',
                    identity_number:'{{old('identity_number')??$userLabor->userDetail->identity_number}}',
                    default_hour_price:'{{old('default_hour_price')??$userLabor->default_hour_price}}',
                    laborCompanyName:'{{old('name')??$userLabor->laborCompany->name}}'},
                laborCompanies:[
                        @foreach( $laborCompanies as $laborCompany )
                        {id:'{{$laborCompany->id}}',name:'{{$laborCompany->name}}',},
                        @endforeach
                ],

            },
        });
    </script>
@endsection
