create.blade.php 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. @extends('layouts.app')
  2. @section('title')KPI-日报表@endsection
  3. @section('content')
  4. <div class="d-none" id="list">
  5. <div class="mt-5 ml-5">
  6. <div class="row mb-5">
  7. <select
  8. v-model="formData.ownerId"
  9. class="selectpicker form-control col-2" title="选择货主"
  10. data-actions-box="true"
  11. data-live-search="true"
  12. data-live-search-placeholder="搜索"
  13. data-style="btn-primary"
  14. >
  15. <option v-for="(v,k) of owners" :value="v.id" :key="v.id">@{{ v.name }}</option>
  16. </select>
  17. <select
  18. v-model="formData.workCoefficientTypeId"
  19. class="selectpicker form-control col-2 ml-5" title="选择分类"
  20. data-actions-box="true"
  21. data-live-search="true"
  22. data-live-search-placeholder="搜索"
  23. data-style="btn-primary"
  24. >
  25. <option v-for="(v,k) of workTypes" :value="v.id" :key="v.id">@{{ v.name }}</option>
  26. </select>
  27. <button class="btn btn-success col-1 ml-5" @click="submitForm()">提交</button>
  28. </div>
  29. <div class="row">
  30. <div class="form-group col-4 mt-2" v-for="(v,k) of submitData">
  31. <h3 v-if="v.name">@{{ v.name }}</h3>
  32. <h3 v-else>@{{ v.workCoefficientTypeDetailName }}</h3>
  33. <div class="row mt-2">
  34. <label for="v.name+库存组" class="control-label col-4">库存组</label>
  35. <input id="v.name+库存组" type="number" class="form-control col-6" v-model="v.inventoryCoef">
  36. </div>
  37. <div class="row mt-2">
  38. <label for="v.name+退货组" class="control-label col-4">退货组</label>
  39. <input id="v.name+退货组" type="number" class="form-control col-6" v-model="v.returnCoef">
  40. </div>
  41. <div class="row mt-2">
  42. <label for="v.name+收货组" class="control-label col-4">收货组</label>
  43. <input id="v.name+收货组" type="number" class="form-control col-6" v-model="v.receiveCoef">
  44. </div>
  45. <div class="row mt-2">
  46. <label for="v.name+发货组" class="control-label col-4">发货组</label>
  47. <input id="v.name+发货组" type="number" class="form-control col-6" v-model="v.deliverCoef">
  48. </div>
  49. <div class="row mt-2">
  50. <label for="v.name+加工组" class="control-label col-4">加工组</label>
  51. <input id="v.name+加工组" type="number" class="form-control col-6" v-model="v.processCoef">
  52. </div>
  53. </div>
  54. </div>
  55. </div>
  56. </div>
  57. @endsection
  58. @section('lastScript')
  59. <script>
  60. let vue = new Vue({
  61. el: "#list",
  62. data: {
  63. cnt: 0,
  64. owners: [
  65. @foreach($owners as $owner)
  66. {
  67. name: '{{$owner->name}}', id: '{{$owner->id}}'
  68. },
  69. @endforeach
  70. ],
  71. workTypes: [],
  72. workTypeDetails: [],
  73. currentWorkTypeDetails: [],
  74. formData: {
  75. ownerId: null,
  76. workCoefficientTypeId: null
  77. },
  78. submitData: []
  79. },
  80. created() {
  81. this.initData();
  82. },
  83. mounted: function () {
  84. },
  85. watch: {
  86. //大类型变更后获取指定类型是否已经有数据
  87. "formData.workCoefficientTypeId": function (n, o) {
  88. if (this.formData.ownerId === null) {
  89. tempTip.show("未选择货主!")
  90. return;
  91. }
  92. this.setCurrentWorkTypeDetails(n);
  93. },
  94. //货主变更后获取指定类型是否已经有数据
  95. "formData.ownerId": function (n, o) {
  96. this.setCurrentWorkTypeDetails(this.formData.workCoefficientTypeId);
  97. }
  98. },
  99. computed: {},
  100. methods: {
  101. //初始化数据 大类型和小类型的初始化,完成后才可以渲染页面
  102. initData() {
  103. let names = ['workCoefficientType', 'workCoefficientTypeDetail'];
  104. let requests = names.map(name => axios.get(this.getBaseUrl() + "/api/" + name + "/listAll"));
  105. Promise.all(requests).then(resList => {
  106. for (let res of resList) {
  107. if ((res.config.url + '').endsWith('workCoefficientType/listAll')) {
  108. this.workTypes = res.data.data;
  109. }
  110. if ((res.config.url + '').endsWith('workCoefficientTypeDetail/listAll')) {
  111. this.workTypeDetails = res.data.data;
  112. }
  113. }
  114. setTimeout(() => {
  115. $(".selectpicker").selectpicker('refresh');
  116. $('#list').removeClass('d-none');
  117. }, 50);
  118. });
  119. },
  120. //根据环境获取不同的url
  121. getBaseUrl() {
  122. let url = '';
  123. let env = "{{ config('app.env') }}";
  124. if (env === 'local') {
  125. url = 'http://127.0.0.1:8111'
  126. } else if (env === 'production') {
  127. url = 'https://stat.baoshi56.com'
  128. }
  129. return url;
  130. },
  131. //提交请求
  132. submitForm() {
  133. if (this.formData.ownerId === null || this.formData.workCoefficientTypeId === null) {
  134. tempTip.show("输入参数缺少!")
  135. return;
  136. }
  137. if (!confirm('是否确认当前数据!')) return;
  138. let postData = this.submitData;
  139. if (postData[0].id !== undefined) {//更新
  140. axios.post(this.getBaseUrl() + "/api/ownerWorkCoefficient/updateBatch", postData).then(res => {
  141. if (res.data.code === 200) {
  142. tempTip.showSuccess("更新成功");
  143. }
  144. });
  145. } else {//新增
  146. axios.post(this.getBaseUrl() + "/api/ownerWorkCoefficient/createBatch", postData).then(res => {
  147. tempTip.showSuccess("新增成功");
  148. });
  149. }
  150. },
  151. //根据条件获取工作系数
  152. async getOwnerWorkCoefficients(params) {
  153. let url = this.getBaseUrl() + "/api/ownerWorkCoefficient/list"
  154. return await axios.get(url, {params});
  155. },
  156. //设置当前类型下的工作系数
  157. setCurrentWorkTypeDetails(o) {
  158. this.submitData = [];
  159. this.getOwnerWorkCoefficients({
  160. ownerId: this.formData.ownerId,
  161. workCoefficientTypeId: this.formData.workCoefficientTypeId
  162. }).then(res => {
  163. if (res.data.data.length > 0) {
  164. this.submitData = res.data.data;
  165. } else {
  166. this.currentWorkTypeDetails = this.workTypeDetails.filter(i => i.workCoefficientTypeId === o)
  167. this.currentWorkTypeDetails.forEach(i => {
  168. this.submitData.push({
  169. ownerId: this.formData.ownerId,
  170. name: i.name,
  171. workCoefficientTypeId: i.workCoefficientTypeId,
  172. workCoefficientTypeDetailId: i.id,
  173. inventoryCoef: null,
  174. returnCoef: null,
  175. receiveCoef: null,
  176. deliverCoef: null,
  177. processCoef: null,
  178. });
  179. });
  180. }
  181. }).catch(err => {
  182. })
  183. }
  184. },
  185. });
  186. </script>
  187. @endsection