AutoGenerateInventoryClassSafeStock.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. <template>
  2. <div class="container-fluid">
  3. <Navbar title="自动生成存货分类安全库存" :is-go-back="true" />
  4. <div class="form-inline">
  5. <div class="form-group">
  6. <label> 步骤1:仓库: </label>
  7. <!-- <input autocomplete="off" type="text" name=""> -->
  8. <div class="input-group">
  9. <v-select v-model="warehouse" label="name" :options="warehouses" />
  10. </div>
  11. </div>
  12. </div>
  13. <h4 />
  14. <div class="form-inline">
  15. <div class="form-group">
  16. <label> 步骤2:类别名称: </label>
  17. <input
  18. v-model.trim="className"
  19. autocomplete="off"
  20. type="text"
  21. class="form-control"
  22. @keyup.enter="reQuery"
  23. />
  24. </div>
  25. <div class="form-group">
  26. <label> 类别编号: </label>
  27. <input
  28. v-model.trim="classNo"
  29. autocomplete="off"
  30. type="text"
  31. class="form-control"
  32. @keyup.enter="reQuery"
  33. />
  34. </div>
  35. <button type="button" class="btn btn-primary" @click="reQuery">
  36. 查询
  37. </button>
  38. </div>
  39. <h4 />
  40. <div class="form-inline">
  41. <div class="form-group">
  42. <label> 步骤3: </label>
  43. <div class="input-group">
  44. <button type="button" class="btn btn-primary" @click="save">
  45. 生成物料类别安全库存
  46. </button>
  47. </div>
  48. </div>
  49. </div>
  50. <h4 />
  51. <table class="table table-bordered">
  52. <thead>
  53. <tr>
  54. <th>序号</th>
  55. <th>类别名称</th>
  56. <th>类别编号</th>
  57. <th>最小库存</th>
  58. <th>最大库存</th>
  59. <th>已生成</th>
  60. </tr>
  61. </thead>
  62. <tbody>
  63. <tr v-for="(data, index) in inventoryClasses" :key="data.id">
  64. <td>
  65. <span v-if="data.hasSafeStock">
  66. <input
  67. v-model="dataIdsForSafeStock"
  68. autocomplete="off"
  69. type="checkbox"
  70. :value="data.id"
  71. disabled
  72. />
  73. </span>
  74. <span v-else>
  75. <input
  76. v-model="dataIdsForSafeStock"
  77. autocomplete="off"
  78. type="checkbox"
  79. :value="data.id"
  80. />
  81. </span>
  82. {{ index + 1 }}
  83. </td>
  84. <td>{{ data.className }}</td>
  85. <td>{{ data.classNo }}</td>
  86. <td v-if="data.hasSafeStock">{{ data.minimumStock }}</td>
  87. <td v-else>
  88. <input
  89. :key="data.id"
  90. v-model.trim="data.minimumStock"
  91. autocomplete="off"
  92. type="number"
  93. class="form-control"
  94. />
  95. </td>
  96. <td v-if="data.hasSafeStock">{{ data.maximumStock }}</td>
  97. <td v-else>
  98. <input
  99. v-model.trim="data.maximumStock"
  100. autocomplete="off"
  101. type="number"
  102. class="form-control"
  103. />
  104. </td>
  105. <td>{{ data.hasSafeStock ? "是" : "否" }}</td>
  106. </tr>
  107. </tbody>
  108. </table>
  109. <VueBootstrapPagination
  110. v-if="inventoryClasses.length > 0"
  111. :pagination="pagination"
  112. :callback="queryInventoryClasses"
  113. />
  114. <Loading v-if="loading" />
  115. </div>
  116. </template>
  117. <script>
  118. import Common from '../common/Common.js';
  119. import InventoryClassResource from '../api/common/InventoryClassResource.js';
  120. import vSelect from 'vue-select';
  121. import 'vue-select/dist/vue-select.css';
  122. export default {
  123. components: {
  124. vSelect,
  125. },
  126. data: function () {
  127. return {
  128. warehouses: [],
  129. warehouse: null,
  130. inventoryClasses: [],
  131. className: '',
  132. classNo: '',
  133. dataIdsForSafeStock: [],
  134. pagination: {
  135. total: 0,
  136. per_page: 10,
  137. current_page: 1,
  138. last_page: 10,
  139. },
  140. loading: false,
  141. };
  142. },
  143. watch: {
  144. warehouse: {
  145. handler: function (to, from) {
  146. if (to) {
  147. this.reQuery();
  148. }
  149. },
  150. deep: true,
  151. },
  152. },
  153. mounted: function () {
  154. this.queryAllWarehouses();
  155. },
  156. methods: {
  157. queryAllWarehouses: function () {
  158. var _self = this;
  159. _self.loading=true;
  160. $.ajax({
  161. type: 'get',
  162. url: Common.getApiURL('WarehouseResource/all'),
  163. beforeSend: function (request) {
  164. Common.addTokenToRequest(request);
  165. },
  166. success: function (data) {
  167. _self.warehouses = data;
  168. _self.loading=false;
  169. },
  170. error: function (XMLHttpRequest, textStatus, errorThrown) {
  171. _self.loading=false;
  172. Common.processException(XMLHttpRequest, textStatus, errorThrown);
  173. },
  174. });
  175. },
  176. reQuery: function () {
  177. this.pagination.current_page = 1;
  178. this.queryInventoryClasses();
  179. },
  180. queryInventoryClasses: function () {
  181. var _self = this;
  182. if (!this.warehouse) {
  183. Notify.notice('提示', '请选择仓库', false);
  184. return;
  185. }
  186. _self.inventoryClasses = [];
  187. _self.dataIdsForSafeStock = [];
  188. let inventoryClassQueryConditionDto = {
  189. name: _self.className,
  190. no: _self.classNo,
  191. start: (_self.pagination.current_page - 1) * _self.pagination.per_page,
  192. length: _self.pagination.per_page,
  193. };
  194. InventoryClassResource.findByQueryCondition(
  195. inventoryClassQueryConditionDto,
  196. ).then(
  197. successData => {
  198. if (successData.dataList != null && successData.dataList.length > 0) {
  199. _self.checkSafeStock(successData.dataList);
  200. _self.pagination.total = successData.totalSize;
  201. _self.pagination.last_page =
  202. successData.totalSize % _self.pagination.per_page == 0
  203. ? successData.totalSize / _self.pagination.per_page
  204. : Math.floor(
  205. successData.totalSize / _self.pagination.per_page,
  206. ) + 1;
  207. }
  208. },
  209. errorData => {
  210. Common.processException(errorData);
  211. },
  212. );
  213. },
  214. checkSafeStock: function (inventoryClasses) {
  215. var _self = this;
  216. $.ajax({
  217. type: 'post',
  218. dataType: 'json',
  219. url:
  220. Common.getApiURL(
  221. 'inventoryClassSafeStockResource/checkInventoryClass',
  222. ) +
  223. '/' +
  224. _self.warehouse.id,
  225. data: JSON.stringify(inventoryClasses),
  226. contentType: 'application/json',
  227. beforeSend: function (request) {
  228. Common.addTokenToRequest(request);
  229. },
  230. success: function (data) {
  231. _self.inventoryClasses = data;
  232. },
  233. error: function (XMLHttpRequest, textStatus, errorThrown) {
  234. Common.processException(XMLHttpRequest, textStatus, errorThrown);
  235. },
  236. });
  237. },
  238. save: function () {
  239. var _self = this;
  240. if (this.dataIdsForSafeStock.length == 0) {
  241. Notify.notice('提示', '您还没有勾选任何数据。', false);
  242. return;
  243. }
  244. var datasForSafeStock = [];
  245. for (var i = 0; i < this.dataIdsForSafeStock.length; i++) {
  246. for (var j = 0; j < this.inventoryClasses.length; j++) {
  247. if (this.inventoryClasses[j].id == this.dataIdsForSafeStock[i]) {
  248. var dataForSafeStock = {};
  249. dataForSafeStock.inventoryClassId = this.inventoryClasses[j].id;
  250. if (this.inventoryClasses[j].minimumStock) {
  251. dataForSafeStock.minimumStock =
  252. this.inventoryClasses[j].minimumStock;
  253. } else {
  254. dataForSafeStock.minimumStock = null;
  255. }
  256. if (this.inventoryClasses[j].maximumStock) {
  257. dataForSafeStock.maximumStock =
  258. this.inventoryClasses[j].maximumStock;
  259. } else {
  260. dataForSafeStock.maximumStock = null;
  261. }
  262. datasForSafeStock.push(dataForSafeStock);
  263. break;
  264. }
  265. }
  266. }
  267. $.ajax({
  268. type: 'post',
  269. dataType: 'json',
  270. url:
  271. Common.getApiURL('inventoryClassSafeStockResource/save') +
  272. '/' +
  273. _self.warehouse.id,
  274. data: JSON.stringify(datasForSafeStock),
  275. contentType: 'application/json',
  276. beforeSend: function (request) {
  277. Common.addTokenToRequest(request);
  278. },
  279. success: function (data) {
  280. _self.queryInventoryClasses();
  281. },
  282. error: function (XMLHttpRequest, textStatus, errorThrown) {
  283. Common.processException(XMLHttpRequest, textStatus, errorThrown);
  284. },
  285. });
  286. },
  287. },
  288. };
  289. </script>