StockOutPrepateTemplate.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475
  1. <template>
  2. <div>
  3. <div class="flex-container">
  4. <!-- 头部搜索区域 -->
  5. <div class="flex-header">
  6. <StockOutPrepareTemplateHeader active-index="1" />
  7. <a-form layout="inline" class="search-form">
  8. <a-form-item label="项目事件">
  9. <a-select
  10. v-model:value="projectItemId"
  11. style="width: 220px"
  12. show-search
  13. allow-clear
  14. @change="handleProjectItemChange"
  15. >
  16. <a-select-option
  17. v-for="item in projectItems"
  18. :key="item.id"
  19. :value="item.id"
  20. >
  21. {{ item.name }}
  22. </a-select-option>
  23. </a-select>
  24. </a-form-item>
  25. <a-form-item label="仓库">
  26. <a-select
  27. v-model:value="warehouseId"
  28. style="width: 220px"
  29. allow-clear
  30. @change="handleWarehouseChange"
  31. >
  32. <a-select-option
  33. v-for="item in warehouses"
  34. :key="item.id"
  35. :value="item.id"
  36. >
  37. {{ item.name }}
  38. </a-select-option>
  39. </a-select>
  40. </a-form-item>
  41. <a-form-item label="需求模板">
  42. <a-select
  43. v-model:value="stockOutPrepateTemplateId"
  44. style="width: 220px"
  45. show-search
  46. allow-clear
  47. @change="handleTemplateChange"
  48. >
  49. <a-select-option
  50. v-for="item in stockOutPrepateTemplateNames"
  51. :key="item.id"
  52. :value="item.id"
  53. >
  54. {{ item.name }}
  55. </a-select-option>
  56. </a-select>
  57. </a-form-item>
  58. <a-form-item>
  59. <a-button @click="queryLines">查询</a-button>
  60. <a-button @click="clear">清空</a-button>
  61. <a-button type="primary" @click="save">确定领料</a-button>
  62. </a-form-item>
  63. </a-form>
  64. </div>
  65. <!-- 表格区域 -->
  66. <div class="flex-content">
  67. <a-table
  68. :columns="columns"
  69. :data-source="pageStockOutPrepateTemplates"
  70. :pagination="pagination"
  71. :loading="loading"
  72. @change="handleTableChange"
  73. >
  74. <template #bodyCell="{ column, record }">
  75. <template v-if="column.dataIndex === 'pickQuantity'">
  76. <a-input-number
  77. v-model:value="record.pickQuantity"
  78. :min="0"
  79. :max="record.currentStockCanPickQuantity"
  80. @change="handlePickQuantityChange(record)"
  81. />
  82. </template>
  83. </template>
  84. </a-table>
  85. </div>
  86. <!-- 分页信息区域 -->
  87. <div class="flex-footer">
  88. <div class="pull-left">
  89. <span>
  90. 第{{ (pagination.current - 1) * pagination.pageSize + 1 }}-{{ pagination.current * pagination.pageSize }}条,
  91. 共计{{ pagination.total }}条,
  92. 每页显示
  93. </span>
  94. <a-select
  95. v-model:value="pagination.pageSize"
  96. style="width: 80px"
  97. @change="gridSizeSelect"
  98. >
  99. <a-select-option value="10">10</a-select-option>
  100. <a-select-option value="20">20</a-select-option>
  101. <a-select-option value="50">50</a-select-option>
  102. </a-select>
  103. <span>条</span>
  104. </div>
  105. <div class="pull-right">
  106. <a-pagination
  107. v-if="pagination.total > 0"
  108. :current="pagination.current"
  109. :page-size="pagination.pageSize"
  110. :total="pagination.total"
  111. @change="getDatas"
  112. />
  113. </div>
  114. </div>
  115. </div>
  116. <!-- 加载状态 -->
  117. <div>
  118. <a-spin v-if="loading" />
  119. </div>
  120. </div>
  121. </template>
  122. <script>
  123. import Common from '../common/Common.js';
  124. import StockOutPrepareResource from '../api/wms/StockOutPrepareResource.js';
  125. import StockOutPrepateTemplateResource from '../api/wms/StockOutPrepateTemplateResource.js';
  126. import StockOutPrepareTemplateHeader from './StockOutPrepareTemplateHeader.vue';
  127. export default {
  128. components: {
  129. StockOutPrepareTemplateHeader,
  130. },
  131. data() {
  132. return {
  133. stockOutPrepateTemplates: [],
  134. pageStockOutPrepateTemplates: [],
  135. stockOutPrepateTemplateId: undefined,
  136. warehouseId: undefined,
  137. projectItemId: undefined,
  138. pagination: {
  139. total: 0,
  140. pageSize: Common.pageSize,
  141. current: 1,
  142. },
  143. projectItems: [],
  144. warehouses: [],
  145. stockOutPrepateTemplateNames: [],
  146. loading: false,
  147. };
  148. },
  149. computed: {
  150. columns() {
  151. return [
  152. {
  153. dataIndex: 'inventoryNo',
  154. title: '物料编码',
  155. },
  156. {
  157. dataIndex: 'inventoryName',
  158. title: '物料名称',
  159. },
  160. {
  161. dataIndex: 'inventoryType',
  162. title: '规格型号',
  163. },
  164. {
  165. dataIndex: 'currentStockQuantity',
  166. title: '库存数量',
  167. },
  168. {
  169. dataIndex: 'currentStockOutQuantity',
  170. title: '待出库数量',
  171. },
  172. {
  173. dataIndex: 'currentStockCanPickQuantity',
  174. title: '可领用数量',
  175. },
  176. {
  177. dataIndex: 'quantity',
  178. title: '需求数量',
  179. },
  180. {
  181. dataIndex: 'pickQuantity',
  182. title: '领用数量',
  183. },
  184. ];
  185. },
  186. },
  187. watch: {
  188. 'pagination.pageSize': function (curVal, oldVal) {
  189. if (curVal !== undefined) {
  190. this.getDatas();
  191. }
  192. },
  193. },
  194. created() {
  195. if (!window.localStorage) {
  196. alert('浏览器不支持localstorage');
  197. } else {
  198. const storage = window.localStorage;
  199. this.warehouseId = storage.getItem('warehouseId');
  200. this.warehouseName = storage.getItem('warehouseName');
  201. this.projectItemId = storage.getItem('projectItemId');
  202. this.projectItemName = storage.getItem('projectItemName');
  203. this.stockOutPrepateTemplateId = storage.getItem('stockOutPrepateTemplateId');
  204. this.stockOutPrepateTemplateName = storage.getItem('stockOutPrepateTemplateName');
  205. }
  206. },
  207. mounted() {
  208. this.loadSelectProjectItem();
  209. this.loadSelectWarehouse();
  210. this.loadSelectTemplate();
  211. },
  212. methods: {
  213. // 加载项目事件选项
  214. loadSelectProjectItem() {
  215. const _self = this;
  216. $.ajax({
  217. url: Common.getApiURL('ProjectItemResource/queryByCondition'),
  218. dataType: 'json',
  219. type: 'get',
  220. data: { name: '' },
  221. beforeSend: Common.addTokenToRequest,
  222. success(data) {
  223. if (data.errorCode === 0) {
  224. _self.projectItems = data.datas;
  225. }
  226. },
  227. error(errorData) {
  228. Common.processException(errorData);
  229. },
  230. });
  231. },
  232. // 加载仓库选项
  233. loadSelectWarehouse() {
  234. const _self = this;
  235. $.ajax({
  236. url: Common.getApiURL('WarehouseResource/queryByCondition'),
  237. dataType: 'json',
  238. type: 'get',
  239. data: { name: '' },
  240. beforeSend: Common.addTokenToRequest,
  241. success(data) {
  242. if (data.errorCode === 0) {
  243. _self.warehouses = data.datas;
  244. }
  245. },
  246. error(errorData) {
  247. Common.processException(errorData);
  248. },
  249. });
  250. },
  251. // 加载需求模板选项
  252. loadSelectTemplate() {
  253. const _self = this;
  254. $.ajax({
  255. url: Common.getApiURL('StockOutPrepateTemplateResource/queryByCondition'),
  256. dataType: 'json',
  257. type: 'get',
  258. data: { name: '' },
  259. beforeSend: Common.addTokenToRequest,
  260. success(data) {
  261. if (data.errorCode === 0) {
  262. _self.stockOutPrepateTemplateNames = data.datas;
  263. }
  264. },
  265. error(errorData) {
  266. Common.processException(errorData);
  267. },
  268. });
  269. },
  270. // 修改每页显示数量
  271. gridSizeSelect(newPageSize) {
  272. this.pagination.pageSize = newPageSize;
  273. this.pagination.current = 1;
  274. this.pageStockOutPrepateTemplates = [];
  275. this.stockOutPrepateTemplates = [];
  276. this.queryLines();
  277. },
  278. // 查询领料模板详情
  279. queryLines() {
  280. if (!this.projectItemId) {
  281. Common.showDialog('提示', '请选择项目事件', 'error');
  282. return;
  283. }
  284. if (!this.warehouseId) {
  285. Common.showDialog('提示', '请选择仓库', 'error');
  286. return;
  287. }
  288. if (!this.stockOutPrepateTemplateId) {
  289. Common.showDialog('提示', '请选择需求模板', 'error');
  290. return;
  291. }
  292. const param = {
  293. warehouseId: this.warehouseId,
  294. projectItemId: this.projectItemId,
  295. stockOutPrepateTemplateDtoId: this.stockOutPrepateTemplateId,
  296. };
  297. this.loading = true;
  298. this.pageStockOutPrepateTemplates = [];
  299. StockOutPrepateTemplateResource.queryStockOutPrepateTemplateDto(param)
  300. .then(successData => {
  301. if (successData.errorCode === 0) {
  302. this.pagination.total = successData.data.stockOutPrepateTemplateLineDtos.length;
  303. this.stockOutPrepateTemplates = successData.data.stockOutPrepateTemplateLineDtos;
  304. this.getDatas();
  305. } else {
  306. Notify.error('提示', successData.errorMessage, false);
  307. }
  308. })
  309. .catch(errorData => {
  310. Common.processException(errorData);
  311. })
  312. .finally(() => {
  313. this.loading = false;
  314. });
  315. },
  316. // 获取分页数据
  317. getDatas() {
  318. const start = (this.pagination.current - 1) * this.pagination.pageSize;
  319. const end = start + this.pagination.pageSize;
  320. if (this.pageStockOutPrepateTemplates.length > 0) {
  321. this.pageStockOutPrepateTemplates.forEach(item => {
  322. this.stockOutPrepateTemplates[item.index].pickQuantity = item.pickQuantity;
  323. });
  324. }
  325. this.pageStockOutPrepateTemplates = [];
  326. for (let i = 0; i < this.stockOutPrepateTemplates.length; i++) {
  327. if (i >= start && i < end) {
  328. const obj = {
  329. ...this.stockOutPrepateTemplates[i],
  330. index: i,
  331. };
  332. this.pageStockOutPrepateTemplates.push(obj);
  333. }
  334. }
  335. },
  336. // 清空数据
  337. clear() {
  338. this.pageStockOutPrepateTemplates = [];
  339. this.stockOutPrepateTemplates = [];
  340. },
  341. // 提交领料数据
  342. save() {
  343. const currentStock = [];
  344. let num = 0;
  345. let num3 = 0;
  346. let num5 = 0;
  347. this.getDatas();
  348. this.stockOutPrepateTemplates.forEach(item => {
  349. if (item.pickQuantity === undefined || item.pickQuantity === '') {
  350. num++;
  351. }
  352. if (item.pickQuantity <= 0 && item.currentStockCanPickQuantity > 0) {
  353. num5++;
  354. }
  355. if (item.pickQuantity > item.currentStockCanPickQuantity) {
  356. num3++;
  357. } else {
  358. currentStock.push(item);
  359. }
  360. });
  361. if (!this.projectItemId) {
  362. Common.showDialog('提示', '请选择项目事件', 'error');
  363. return;
  364. }
  365. if (!this.warehouseId) {
  366. Common.showDialog('提示', '请选择仓库', 'error');
  367. return;
  368. }
  369. if (!this.stockOutPrepateTemplateId) {
  370. Common.showDialog('提示', '请选择需求模板', 'error');
  371. return;
  372. }
  373. if (num > 0) {
  374. Common.showDialog('提示', '请填写领用数量', 'error');
  375. return;
  376. }
  377. if (num3 > 0) {
  378. Common.showDialog('提示', '领用数量大于可领数量', 'error');
  379. return;
  380. }
  381. if (num5 > 0) {
  382. Common.showDialog('提示', '填写的领用数量必须大于零', 'error');
  383. return;
  384. }
  385. const param = {
  386. projectItemId: this.projectItemId,
  387. warehouseId: this.warehouseId,
  388. stockOutPrepateTemplateId: this.stockOutPrepateTemplateId,
  389. pickingCarDtoList: currentStock,
  390. };
  391. this.loading = true;
  392. if (currentStock.length > 0) {
  393. StockOutPrepareResource.saveByTemplate(param)
  394. .then(successData => {
  395. if (successData.errorCode === 0) {
  396. Notify.success('成功', '领料成功', 4000);
  397. this.pageStockOutPrepateTemplates = [];
  398. this.stockOutPrepateTemplates = [];
  399. } else {
  400. Notify.error('提示', successData.errorMessage, false);
  401. }
  402. })
  403. .catch(errorData => {
  404. Common.processException(errorData);
  405. })
  406. .finally(() => {
  407. this.loading = false;
  408. });
  409. } else {
  410. this.loading = false;
  411. Common.showDialog('提示', '请选择要提交的内容', 'error');
  412. }
  413. },
  414. // 表格分页变化处理
  415. handleTableChange(pagination) {
  416. this.pagination.current = pagination.current;
  417. this.getDatas();
  418. },
  419. // 项目事件选择变化处理
  420. handleProjectItemChange(value) {
  421. this.projectItemId = value;
  422. this.clear();
  423. },
  424. // 仓库选择变化处理
  425. handleWarehouseChange(value) {
  426. this.warehouseId = value;
  427. this.clear();
  428. },
  429. // 需求模板选择变化处理
  430. handleTemplateChange(value) {
  431. this.stockOutPrepateTemplateId = value;
  432. this.clear();
  433. },
  434. // 领用数量变化处理
  435. handlePickQuantityChange(record) {
  436. // 可根据需求添加额外逻辑
  437. },
  438. },
  439. };
  440. </script>
  441. <style scoped>
  442. .flex-container {
  443. display: flex;
  444. flex-direction: column;
  445. width: 100%;
  446. height: calc(100vh - 85px);
  447. }
  448. .flex-header {
  449. flex: 0 0 100px;
  450. }
  451. .flex-footer {
  452. margin-top: 0.8em;
  453. flex: 0 0 35px;
  454. }
  455. .flex-content {
  456. margin-top: 0.8em;
  457. flex: 1;
  458. overflow: auto;
  459. width: 100%;
  460. }
  461. .pull-left {
  462. float: left;
  463. }
  464. .pull-right {
  465. float: right;
  466. }
  467. </style>