index.blade.php 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. @extends('layouts.app')
  2. @section('title')料箱型号@endsection
  3. @section('content')
  4. <div class="container-fluid card" id="container">
  5. @include("maintenance.materialBoxModel._modal")
  6. <div class="card-body">
  7. <button class="btn btn-outline-info mb-1 mr-3" @click="openModal()"><span class="fa fa-plus"></span>&nbsp;新&nbsp;&nbsp;增</button>
  8. <table class="table table-bordered table-striped">
  9. <tr>
  10. <th>编码</th>
  11. <th>说明</th>
  12. <th>最大商品种类</th>
  13. <th>操作</th>
  14. </tr>
  15. <tr v-for="model in models">
  16. <td>@{{ model.code }}</td>
  17. <td>@{{ model.description }}</td>
  18. <td>@{{ model.maximum_kind }}</td>
  19. <td>
  20. <button class="btn btn-sm btn-outline-primary" @click="openModal(model)">改</button>
  21. <button class="btn btn-sm btn-outline-dark" @click="destroy(model)">删</button>
  22. </td>
  23. </tr>
  24. </table>
  25. </div>
  26. </div>
  27. @endsection
  28. @section('lastScript')
  29. <script>
  30. new Vue({
  31. el:"#container",
  32. data:{
  33. models:[@foreach($models as $model)@json($model),@endforeach],
  34. model:{},
  35. errors:{},
  36. },
  37. methods:{
  38. openModal(model=null){
  39. if (model) this.model = Object.assign({},model);
  40. else this.model = {maximum_kind:1};
  41. $("#modal").modal("show");
  42. },
  43. submitModel(){
  44. window.tempTip.postBasicRequest("{{url('maintenance/materialBoxModel/save')}}",this.model,res=>{
  45. if (res.errors){
  46. this.errors = res.errors;
  47. return;
  48. }
  49. if (!this.model.id){
  50. this.models.unshift(res);
  51. }else this.models.some((model,index)=>{
  52. if (model.id===res.id){
  53. this.$set(this.models,index,res);
  54. return true;
  55. }
  56. });
  57. $("#modal").modal("hide");
  58. return this.model.id ? "修改成功" : '新增成功';
  59. },true);
  60. },
  61. destroy(model){
  62. window.tempTip.confirm("确定要剔除此模型记录吗?",()=>{
  63. window.tempTip.postBasicRequest("{{url('maintenance/materialBoxModel/destroy')}}",{id:model.id},()=>{
  64. this.models.some((m,index)=> {
  65. if (m.id === model.id) {
  66. this.$delete(this.models, index);
  67. return true;
  68. }
  69. });
  70. return "删除成功";
  71. });
  72. })
  73. },
  74. }
  75. });
  76. </script>
  77. @endsection