index.blade.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. @extends('layouts.app')
  2. @section('title')计费模型-直发车@endsection
  3. @section('content')
  4. <div id="nav2">
  5. @component('maintenance.menu')@endcomponent
  6. @component('maintenance.priceModel.directLogistic.menu')@endcomponent
  7. </div>
  8. <div class="container-fluid mt-2" id="container">
  9. @include("maintenance.priceModel.directLogistic._detailModal")
  10. @if(Session::has('successTip'))
  11. <div class="alert alert-success h1">{{Session::get('successTip')}}</div>
  12. @endif
  13. <table class="table table-hover table-striped text-nowrap">
  14. <tr>
  15. <th>序号</th>
  16. <th>操作</th>
  17. <th>价格名称</th>
  18. <th>项目</th>
  19. <th>起步公里数</th>
  20. <th>录入时间</th>
  21. <th>操作</th>
  22. </tr>
  23. <tr v-for="(model,i) in models">
  24. <td>@{{ i+1 }}</td>
  25. <td>
  26. <button class="btn btn-sm btn-info" @click="showDetailModal(model,i)">维护详情</button>
  27. </td>
  28. <td>@{{ model.name }}</td>
  29. <td>
  30. <small v-for="owner in model.owners" class="font-weight-bold">@{{ owner.name }}<br></small>
  31. </td>
  32. <td>@{{ model.baseKm }}</td>
  33. <td>@{{ model.createdAt }}</td>
  34. <td>
  35. @can("计费模型-直发-编辑")<button type="button" class="btn btn-sm btn-outline-info" @click="edit(model.id)">编辑</button>@endcan
  36. @can("计费模型-直发-删除")<button type="button" class="btn btn-sm btn-outline-danger" @click="deleteModel(model,i)">删除</button>@endcan
  37. </td>
  38. </tr>
  39. </table>
  40. </div>
  41. @stop
  42. @section("lastScript")
  43. <script>
  44. new Vue({
  45. el:"#container",
  46. data:{
  47. models : [
  48. @foreach($models as $model)
  49. {id:"{{$model->id}}",name:"{{$model->name}}",baseKm:"{{$model->base_km}}",createdAt:"{{$model->created_at}}",owners:{!! $model->owners !!}},
  50. @endforeach
  51. ],
  52. index:"",
  53. carTypes : null,
  54. errors:{!! $errors !!},
  55. isShowError : false,
  56. details : [],
  57. },
  58. methods:{
  59. _dataReady(){
  60. if (this.carTypes === null){
  61. window.axios.post("{{url('maintenance/carType/get')}}")
  62. .then(res=>{
  63. this.carTypes = res.data;
  64. this.$forceUpdate();
  65. }).catch(err=>{
  66. window.tempTip.setDuration(3000);
  67. window.tempTip.setIndex(1099);
  68. window.tempTip.show("网络错误:"+err);
  69. });
  70. }
  71. },
  72. showDetailModal(model,index){
  73. this._dataReady();
  74. this.index = index;
  75. if (this.details[model.id]){
  76. $("#detailModal").modal("show");
  77. return;
  78. }
  79. window.axios.post("{{url('maintenance/priceModel/directLogistic/getDetail')}}", {id:model.id})
  80. .then(res=>{
  81. if (res.data.success){
  82. this.details[model.id] = res.data.data;
  83. this.$forceUpdate();
  84. $("#detailModal").modal("show");
  85. return;
  86. }
  87. window.tempTip.setDuration(3000);
  88. window.tempTip.show(res.data.data);
  89. }).catch(err=>{
  90. window.tempTip.setDuration(3000);
  91. window.tempTip.show("网络错误:"+err);
  92. });
  93. },
  94. edit(id){
  95. window.location.href = "{{url('maintenance/priceModel/directLogistic')}}/"+id+"/edit";
  96. },
  97. deleteModel(model,index){
  98. window.tempTip.confirm("确定要删除“"+model.name+"”吗?",()=>{
  99. window.axios.delete('{{url('maintenance/priceModel/directLogistic')}}/'+model.id)
  100. .then(res=>{
  101. if (res.data.success){
  102. this.$delete(this.models,index);
  103. tempTip.setDuration(2000);
  104. tempTip.showSuccess("删除"+model.name+"成功");
  105. return;
  106. }
  107. tempTip.setDuration(3000);
  108. tempTip.show(res.data.data);
  109. }).catch(err=> {
  110. tempTip.setDuration(3000);
  111. tempTip.show("网络错误:"+err);
  112. })
  113. });
  114. },
  115. selectFile(){
  116. $("#file").click();
  117. },
  118. importDetail(e){
  119. let file=e.target.files[0];
  120. if (!file){
  121. tempTip.setDuration(3000);
  122. tempTip.setIndex(1099);
  123. tempTip.show("未选择文件");
  124. return;
  125. }
  126. let id = this.models[this.index].id;
  127. let formData = new FormData();
  128. formData.append("file",file);
  129. formData.append("id",id);
  130. window.tempTip.setIndex(1099);
  131. window.tempTip.setDuration(9999);
  132. window.tempTip.waitingTip("执行中,请耐心等候......");
  133. axios.post('{{url('maintenance/priceModel/directLogistic/import')}}',formData,{
  134. 'Content-Type':'multipart/form-data'
  135. })
  136. .then(res=>{
  137. if (res.data.success) {
  138. this.details[id] = res.data.data;
  139. this.errors = res.data.errors;
  140. tempTip.cancelWaitingTip();
  141. tempTip.setDuration(2000);
  142. tempTip.showSuccess("导入成功!");
  143. return;
  144. }
  145. tempTip.cancelWaitingTip();
  146. tempTip.setDuration(3000);
  147. tempTip.show(res.data.data);
  148. }).catch(err=> {
  149. tempTip.cancelWaitingTip();
  150. tempTip.setDuration(3000);
  151. tempTip.show("网络错误:"+err);
  152. })
  153. },
  154. addDetail(){
  155. this._dataReady();
  156. this.details[this.models[this.index].id].unshift({
  157. "id" : "",
  158. "car_type_id" : "",
  159. "base_fee" : "",
  160. "additional_fee" : "",
  161. "edit" : true,
  162. });
  163. this.$forceUpdate();
  164. },
  165. delDetail(detail,index){
  166. if (detail.id){
  167. detail.base_fee = $("#base_fee-"+detail.id).attr('data');
  168. detail.additional_fee = $("#additional_fee-"+detail.id).attr('data');
  169. detail.edit = false;
  170. }else{
  171. this.$delete(this.details[this.models[this.index].id],index);
  172. }
  173. this.$forceUpdate();
  174. },
  175. updateDetail(detail){
  176. detail["edit"] = true;
  177. this.$forceUpdate();
  178. },
  179. submitDetail(detail){
  180. tempTip.setIndex(1099);
  181. window.axios.post('{{url('maintenance/priceModel/directLogistic/updateDetail')}}',{id:this.models[this.index].id,detail:detail})
  182. .then(res=>{
  183. if (res.data.success) {
  184. tempTip.setDuration(2000);
  185. if (detail.id){
  186. tempTip.showSuccess("修改成功");
  187. }else{
  188. detail.id = res.data.data.id;
  189. detail.car_type = res.data.data.car_type;
  190. tempTip.showSuccess("新增成功");
  191. }
  192. detail.edit = false;
  193. this.$forceUpdate();
  194. return;
  195. }
  196. tempTip.setDuration(3000);
  197. tempTip.show(res.data.data);
  198. }).catch(err=> {
  199. tempTip.setDuration(3000);
  200. tempTip.setIndex(1099);
  201. tempTip.show("网络错误:"+err);
  202. })
  203. },
  204. deletePriceModel(id,index){
  205. window.tempTip.setIndex(1099);
  206. window.tempTip.confirm("确定要删除该车型计费模型吗?",()=>{
  207. window.axios.post('{{url('maintenance/priceModel/directLogistic/destroyDetail')}}',{id:id})
  208. .then(res=>{
  209. if (res.data.success){
  210. this.$delete(this.details[this.models[this.index].id],index);
  211. tempTip.setDuration(2000);
  212. tempTip.showSuccess("删除成功");
  213. this.$forceUpdate();
  214. return;
  215. }
  216. tempTip.setDuration(3000);
  217. tempTip.show(res.data.data);
  218. }).catch(err=> {
  219. tempTip.setDuration(3000);
  220. tempTip.setIndex(1099);
  221. tempTip.show("网络错误:"+err);
  222. })
  223. });
  224. },
  225. },
  226. });
  227. </script>
  228. @stop