douyingmou1389 2018-05-22 11:21
浏览 49

如何从动态组合框中显示表格?

I have the form below, with 4 comboboxes "Metier=profession" "tache=task" "tacrification=pricing" and "technicien=technician", I select a Metier and a tache, after this I want that a popup box appears and show me a table that contains all the "techniciens" and their "tarification" (of course only the "techniciens" that are related with the "tache" already selected).

Please see the second form. After this I select a "technician" from that table a now the form is completely filled with the "technician" and it's "pricing".

i have this :enter image description here

What I'm trying to do: enter image description here

intervention

Schema::create('interventions', function (Blueprint $table) {
    $table->increments('id');
    $table->date('date_intervention')->nullable();
    $table->string('description');
    $table->dateTime('duree_prevu');
    $table->boolean('statut');
    $table->integer('technicien_id')->unsigned();
    $table->foreign('technicien_id')->references('id')- 
    >on('techniciens');
    $table->integer('tarification_id')->unsigned();
    $table->foreign('tarification_id')->references('id')- 
    >on('tarificationtaches');
    $table->integer('client_id')->unsigned();
    $table->foreign('client_id')->references('id')->on('Clients');


    $table->timestamps();
});

tarificationtache

 Schema::create('tarificationtaches', function (Blueprint $table) {
     $table->increments('id');
     $table->float('tarif', 8,2);
     $table->integer('tache_id')->unsigned();
     $table->foreign('tache_id')->references('id')->on('taches');
     $table->datetime('deleted_at')->nullable();
     $table->timestamps();
 });

Intervention class

class Intervention extends Model
{
    protected $fillable = [ ];
    protected $guarded = [];

    public function avisintervention()
    {
        return $this->hasMany(AvisIntervention::class);
    }

    public function technicien()
    {
        return $this->belongsTo(technicien::class);
    }

    public function client()
    {
        return $this->belongsTo(Client::class);
    }

    public function tarificationtache()
    {
        return $this->belongsTo('App\Tarificationtache','tarification_id');
    }

tache class

class tache extends Model
{
    use SoftDeletes;
    protected $guarded = [];
    protected $dates = ['deleted_at'];

    public function metier()
    {
        return $this->belongsTo(Metier::class);
    }

    public function tarificationtache()
    {
        return $this->hasMany(Tarificationtache::class);
    }
}

metier class

class metier extends Model 
{
    use SoftDeletes;
    protected $guarded = [];
    protected $dates = ['deleted_at'];

    public function taches()
    {
      return $this->hasMany(Tache::class);
    }

    public function techniciens()
    {
      return $this->belongsToMany('App\technicien','technicien_zone','metier_id','technicien_id');
    }
}

tarificationtache class

class tarificationtache extends Model
{
    use SoftDeletes;
    protected $guarded = [];
    protected $dates = ['deleted_at'];

    public function tache()
    {
        return $this->belongsTo(Tache::class);
    }


    public function techniciens()
    {
        return $this->belongsToMany('App\technicien','technicien_tarificationtache','tarificationtache_id','technicien_id');
    }

    public function intervention() 
    {
      return $this->hasMany(intervention::class);
    }
}

intervention controller

public function create()
{
    $client = client::orderBy('id', 'asc')->get();
    $metiers = metier::orderBy('id', 'asc')->get();
    $technicien = Technicien::orderBy('id', 'desc')->get();
    $tarifications = tarificationtache::orderBy('id', 'desc')->get();

    return view('intervention.create')->with('technicien',$technicien)->with('client',$client)->with('metiers',$metiers)->with('tarifications',$tarifications);
}

**
* Store a newly created resource in storage.
*
* @param  \Illuminate\Http\Request  $request
* @return \Illuminate\Http\Response
*/
public function store(InterventionRequest $request)
{
    $intervention = new Intervention();

    $intervention->description =$request->input('description');
    $intervention->duree_prevu =$request->input('duree_prevu');


    if($request->has('statut')){
        $intervention->statut = $request->input('statut');
    }else{
        $intervention->statut = 0;
    }

    $intervention->technicien_id = $request->input('technicien_id');
    $intervention->client_id = $request->input('client_id');
    $intervention->tarification_id = $request->tarificationtache_id;
    $intervention->save();
    return redirect('intervention');

}

create.blade.php

@extends('Layouts/app')
@extends('Layouts/master')
@section('content')
<!--  jQuery -->
<script 
src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"> 
</script>
<script type="text/javascript">
 var getTachesByMetierUrl = "{{url('/tachesbymetier')}}";
    var getAdresseByClientUrl = "{{url('/adressebyclient')}}";
    var getTarificationsByTacheUrl = "{{url('/tarificationsbytache')}}";
    var getTechniciensByTarificationtacheUrl = " 
 {{url('/techniciensbytarificationtache')}}";



    function getAdresseByClient(val) {
        if(val.length>0) {
            var client_id = val;
            $.get(getAdresseByClientUrl+'/'+client_id,function(res) {
                var html = '<option value="">-Select-</option>' ;
                $.each(res.adresses,function(index,item) {
                    html+='<option 
  value="'+item.id+'">'+item.code_postal+'</option>';
                });
                $('#adresses').html(html);

            });
        }
    }


    function getTachesByMetier(val) {
        if(val.length>0) {
            var metier_id = val;
            $.get(getTachesByMetierUrl+'/'+metier_id,function(res) {
                var html = '<option value="">-Select-</option>' ;
                $.each(res.taches,function(index,item) {
                    html+='<option 
  value="'+item.id+'">'+item.libelle_tache+'</option>';
                });
                $('#taches').html(html);

            });
        }
    }

     function getTechniciensByTache(val) {
        if(val.length>0) {
            var tache_id = val;

 $.get(getTechniciensByTacheUrl+'/'+tarificationtache_id,function(res) {
                var html = '<option value="">-Select-</option>' ;
                $.each(res.techniciens,function(index,item) {
                    html+='<option 
 value="'+item.id+'">'+item.id.nom+'</option>';
                });
                $('#techniciens').html(html);

            });
        }
    }
  function getTarificationsByTache(val) {

        if(val.length>0) {
            var tache_id = val;
            $.get(getTarificationsByTacheUrl+'/'+tache_id,function(res) {
                var html = '<option value="">-Select-</option>' ;
                $.each(res.tarifications,function(index,item) {
                    html+='<option 
 value="'+item.id+'">'+item.tarif+'</option>';
                });
                $('#tarifications').html(html);

            });
        }
    }

    function getTechniciensByTarificationtache(val) {
        if(val.length>0) {
            var tarificationtache_id = val;
  $.get(getTechniciensByTarificationtacheUrl+'/'+tarificationtache_id, 
  function(res ) {
                var html = '<option value="">-Select-</option>' ;
                $.each(res.techniciens,function(index,item) {
                    html+='<option 
 value="'+item.id+'">'+item.id.nom+'</option>';
                });
                $('#techniciens').html(html);

            });
        }
    }
</script>
@if(count($errors))
    <div class="alert alert-danger" role="alert">
        <ul>
            @foreach($errors ->all() as $message)
                <li>{{$message}}</li>
            @endforeach
        </ul>
    </div>
@endif
<div class="container">
    <div class="row"></div>
    <div class="col-md-10">
        <h1>Ajout Intervention</h1>
        <form action=" {{url ('intervention')  }}" method="post">
            {{csrf_field()}}
            <div class="form-group">
                <label for="client">Client</label>
                <select onchange="getAdresseByClient(this.value)" 
 name="client_id" id="client" class="form-control">
                    <option value="">-Select-</option>
                    @foreach($client as $t)
                        <option value="{{$t->id }}">
                            {{$t->user->nom}}
                        </option>
                    @endforeach
                </select>
            </div>
            <div class="form-group">
                <label for="">date et heure </label>
                <input class="form-control" type="datetime-local"  name 
  ="duree_prevu" value="{{old('duree_prevu')}}">
            </div>

            <div class="form-group">
                <label for="">description</label>
                <input type="text"  name ="description" class="form- 
 control"value="{{old('description')}}">
            </div>

    <div class="form-group">
                <div class="col-md-12">
                <div class="col-md-4">
                <label>Metier: </label>
                <select onchange="getTachesByMetier(this.value)" 
 style="width: 200px" class="productm form-control" id="metiers">
               <option value="">-Select-</option>
                    @foreach($metiers as $t)
                        <option value="{{$t->id }}">
                            {{$t->libelle_metier}}
                        </option>
                    @endforeach
                </select>
            </div>

            <div class="col-md-4">
                <label>tache: </label>
                <select onchange="getTarificationsByTache(this.value)" 
 style="width: 200px" class="productname form-control" name="tache" 
 id="taches">
                <option value="">-Select-</option>
                </select>
            </div>
            <div class="col-md-4">
                <label>tarification: </label>
                <select 
onchange="getTechniciensByTarificationtache(this.value)" style="width: 
200px" 
class="productname form-control" name="tarificationtache_id" 
id="tarifications">
                <option value="">-Select-</option>
                </select>
            </div>

            <div class="col-md-4">
                        <label>technicien: </label>
                        <select style="width: 200px" class="productname 
 form-control" name="technicien_id" id="technicien">
                            <option value="">-Select-</option>
                        </select>
                    </div>



</div>

            <div class="form-group">
                <div class="form-group">
                <label for="">statut    :   </label>
                <input type="checkbox"  name ="statut" value="1" required 
 autofocus>
            </div>
            <div class="form-group">
                <label for="">payement</label>
                <input type="checkbox"  name ="payement" value="">
            </div>
            <div class="form-group">

                <input type="submit" value = "enregistrer" class="form- 
control btn btn-primary">
            </div>
</div>
</div>
</div>


<link 
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" 
 rel="stylesheet">

<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap- 
datepicker/1.5.0/css/bootstrap-datepicker.css" rel="stylesheet">

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.js"> 
</script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap- 
datepicker/1.5.0/js/bootstrap-datepicker.js"></script>

@endsection
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
    • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
    • ¥15 CSAPPattacklab
    • ¥15 一直显示正在等待HID—ISP
    • ¥15 Python turtle 画图
    • ¥15 关于大棚监测的pcb板设计
    • ¥15 stm32开发clion时遇到的编译问题
    • ¥15 lna设计 源简并电感型共源放大器
    • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
    • ¥15 Vue3地图和异步函数使用