project-select-form.blade.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. ?>
  3. <style type="text/css">
  4. </style>
  5. <div class="layui-form-item {{ $errors->has('project_id') ? 'has-error' : '' }}">
  6. <label class="layui-form-label" style="padding: 0px;">在用项目</label>
  7. <div class="layui-input-block">
  8. <select name="project_id" lay-filter="project_id">
  9. @foreach($options as $option)
  10. <option value="{{$option->id}}" {{$option->id == $project_id ? 'selected' : ''}}>{{$option->name}}</option>
  11. @endforeach
  12. </select>
  13. @if($errors->has('project_id'))
  14. <span class="help-block">{{ $errors->first('project_id') }}</span>
  15. @endif
  16. </div>
  17. @if($errors->has('project_id'))
  18. <span class="help-block">{{ $errors->first('project_id') }}</span>
  19. @endif
  20. </div>
  21. <script>
  22. $(function() {
  23. layui.use(['form'], function() {
  24. let form = layui.form;
  25. let projects = JSON.parse('{!! $options !!}');
  26. let work_points = [];
  27. let project_id = '{{ $project_id }}';
  28. {{--let work_point_id = '{{ $work_point_id }}';--}}
  29. {{--let hide_spec = '{{ isset($hide_spec) ? "yes" : "no" }}';--}}
  30. // console.log(hide_spec)
  31. // form.on('select(project_id)', function(data) {
  32. // project_id = data.value;
  33. // work_point_id = '';
  34. // updateWorkPoint()
  35. // });
  36. // updateWorkPoint();
  37. //
  38. // function updateWorkPoint() {
  39. // let name_index = getIndex(projects, project_id);
  40. // work_points = projects[name_index].work_points;
  41. // let options = '';
  42. // for(let i = 0; i < work_points.length; ++i) {
  43. // options += '<option value=' + work_points[i].value + (parseInt(work_points[i].value) === parseInt(work_point_id) ? ' selected' : '') + '>' + work_points[i].text + '</option>'
  44. // }
  45. // $("select[name='work_point_id']").html(options);
  46. // form.render('select');
  47. // }
  48. // function getIndex(list, id) {
  49. // id = parseInt(id);
  50. // for(var i = 0; i < list.length; ++i) {
  51. // if(list[i].value === id) return i;
  52. // }
  53. // return 0;
  54. // }
  55. })
  56. })
  57. </script>