index.blade.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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" @click="selectTr===i+1?selectTr=0:selectTr=i+1" :class="selectTr===i+1?'focusing' : ''">
  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. selectTr:0
  58. },
  59. methods:{
  60. _dataReady(){
  61. if (this.carTypes === null){
  62. window.axios.post("{{url('maintenance/carType/get')}}")
  63. .then(res=>{
  64. this.carTypes = res.data;
  65. this.$forceUpdate();
  66. }).catch(err=>{
  67. window.tempTip.setDuration(3000);
  68. window.tempTip.setIndex(1099);
  69. window.tempTip.show("网络错误:"+err);
  70. });
  71. }
  72. },
  73. showDetailModal(model,index){
  74. this._dataReady();
  75. this.index = index;
  76. if (this.details[model.id]){
  77. $("#detailModal").modal("show");
  78. return;
  79. }
  80. window.axios.post("{{url('maintenance/priceModel/directLogistic/getDetail')}}", {id:model.id})
  81. .then(res=>{
  82. if (res.data.success){
  83. this.details[model.id] = res.data.data;
  84. this.$forceUpdate();
  85. $("#detailModal").modal("show");
  86. return;
  87. }
  88. window.tempTip.setDuration(3000);
  89. window.tempTip.show(res.data.data);
  90. }).catch(err=>{
  91. window.tempTip.setDuration(3000);
  92. window.tempTip.show("网络错误:"+err);
  93. });
  94. },
  95. edit(id){
  96. window.location.href = "{{url('maintenance/priceModel/directLogistic')}}/"+id+"/edit";
  97. },
  98. deleteModel(model,index){
  99. window.tempTip.confirm("确定要删除“"+model.name+"”吗?",()=>{
  100. window.axios.delete('{{url('maintenance/priceModel/directLogistic')}}/'+model.id)
  101. .then(res=>{
  102. if (res.data.success){
  103. this.$delete(this.models,index);
  104. tempTip.setDuration(2000);
  105. tempTip.showSuccess("删除"+model.name+"成功");
  106. return;
  107. }
  108. tempTip.setDuration(3000);
  109. tempTip.show(res.data.data);
  110. }).catch(err=> {
  111. tempTip.setDuration(3000);
  112. tempTip.show("网络错误:"+err);
  113. })
  114. });
  115. },
  116. selectFile(){
  117. $("#file").click();
  118. },
  119. importDetail(e){
  120. let file=e.target.files[0];
  121. if (!file){
  122. tempTip.setDuration(3000);
  123. tempTip.setIndex(1099);
  124. tempTip.show("未选择文件");
  125. return;
  126. }
  127. let id = this.models[this.index].id;
  128. let formData = new FormData();
  129. formData.append("file",file);
  130. formData.append("id",id);
  131. window.tempTip.setIndex(1099);
  132. window.tempTip.setDuration(9999);
  133. window.tempTip.waitingTip("执行中,请耐心等候......");
  134. axios.post('{{url('maintenance/priceModel/directLogistic/import')}}',formData,{
  135. 'Content-Type':'multipart/form-data'
  136. })
  137. .then(res=>{
  138. if (res.data.success) {
  139. this.details[id] = res.data.data;
  140. this.errors = res.data.errors;
  141. tempTip.cancelWaitingTip();
  142. tempTip.setDuration(2000);
  143. tempTip.showSuccess("导入成功!");
  144. return;
  145. }
  146. tempTip.cancelWaitingTip();
  147. tempTip.setDuration(3000);
  148. tempTip.show(res.data.data);
  149. }).catch(err=> {
  150. tempTip.cancelWaitingTip();
  151. tempTip.setDuration(3000);
  152. tempTip.show("网络错误:"+err);
  153. })
  154. },
  155. addDetail(){
  156. this._dataReady();
  157. this.details[this.models[this.index].id].unshift({
  158. "id" : "",
  159. "car_type_id" : "",
  160. "base_fee" : "",
  161. "additional_fee" : "",
  162. "edit" : true,
  163. });
  164. this.$forceUpdate();
  165. },
  166. delDetail(detail,index){
  167. if (detail.id){
  168. detail.base_fee = $("#base_fee-"+detail.id).attr('data');
  169. detail.additional_fee = $("#additional_fee-"+detail.id).attr('data');
  170. detail.edit = false;
  171. }else{
  172. this.$delete(this.details[this.models[this.index].id],index);
  173. }
  174. this.$forceUpdate();
  175. },
  176. updateDetail(detail){
  177. detail["edit"] = true;
  178. this.$forceUpdate();
  179. },
  180. submitDetail(detail){
  181. tempTip.setIndex(1099);
  182. window.axios.post('{{url('maintenance/priceModel/directLogistic/updateDetail')}}',{id:this.models[this.index].id,detail:detail})
  183. .then(res=>{
  184. if (res.data.success) {
  185. tempTip.setDuration(2000);
  186. if (detail.id){
  187. tempTip.showSuccess("修改成功");
  188. }else{
  189. detail.id = res.data.data.id;
  190. detail.car_type = res.data.data.car_type;
  191. tempTip.showSuccess("新增成功");
  192. }
  193. detail.edit = false;
  194. this.$forceUpdate();
  195. return;
  196. }
  197. tempTip.setDuration(3000);
  198. tempTip.show(res.data.data);
  199. }).catch(err=> {
  200. tempTip.setDuration(3000);
  201. tempTip.setIndex(1099);
  202. tempTip.show("网络错误:"+err);
  203. })
  204. },
  205. deletePriceModel(id,index){
  206. window.tempTip.setIndex(1099);
  207. window.tempTip.confirm("确定要删除该车型计费模型吗?",()=>{
  208. window.axios.post('{{url('maintenance/priceModel/directLogistic/destroyDetail')}}',{id:id})
  209. .then(res=>{
  210. if (res.data.success){
  211. this.$delete(this.details[this.models[this.index].id],index);
  212. tempTip.setDuration(2000);
  213. tempTip.showSuccess("删除成功");
  214. this.$forceUpdate();
  215. return;
  216. }
  217. tempTip.setDuration(3000);
  218. tempTip.show(res.data.data);
  219. }).catch(err=> {
  220. tempTip.setDuration(3000);
  221. tempTip.setIndex(1099);
  222. tempTip.show("网络错误:"+err);
  223. })
  224. });
  225. },
  226. },
  227. });
  228. </script>
  229. @stop