InventoryPrintScan.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694
  1. /**
  2. * 存货打印
  3. */
  4. <template>
  5. <div class="container-fluid">
  6. <Navbar
  7. title="扫描入库打印"
  8. :is-go-back="false"
  9. />
  10. <div
  11. class="flex-container"
  12. style="margin-top: 10px;"
  13. >
  14. <div class="flex-header">
  15. <div>
  16. <div
  17. class="form-inline"
  18. role="form"
  19. >
  20. <PrintWidget
  21. ref="printWidget"
  22. :printer-localstorage-id="'#InventoryPrinterPrinter'"
  23. @selected-printer-name="getPrintName"
  24. />
  25. <div class="form-group">
  26. <input
  27. v-model="message"
  28. autocomplete="off"
  29. type="text"
  30. class="form-control"
  31. placeholder="请输入要打印存货的名称或编码"
  32. aria-describedby="basic-addon"
  33. style="width:350px;"
  34. @keyup.enter="queryInventory"
  35. />
  36. </div>
  37. <div class="form-group">
  38. <button
  39. class="btn btn-default"
  40. @click="queryInventory"
  41. >
  42. 查询
  43. </button>
  44. <button
  45. class="btn btn-default"
  46. @click="$refs.printEpc.show()"
  47. >
  48. 再次打印
  49. </button>
  50. </div>
  51. </div>
  52. </div>
  53. </div>
  54. <div
  55. class="flex-content"
  56. style="margin-top: 10px;"
  57. >
  58. <table class="fixed-table table-striped table-bordered">
  59. <thead>
  60. <tr>
  61. <th style="width: 50px;">
  62. 序号
  63. </th>
  64. <th style="width: 50px;">
  65. 图片
  66. </th>
  67. <th style="width: 150px;">
  68. 存货名称
  69. </th>
  70. <th style="width: 150px;">
  71. 存货编号
  72. </th>
  73. <th style="width: 150px;">
  74. 规格型号
  75. </th>
  76. <th style="width: 60px;">
  77. 计量单位
  78. </th>
  79. <th style="width: 60px;">
  80. 采购订单编号
  81. </th>
  82. <th style="width: 100px;">
  83. 批号
  84. </th>
  85. <th style="width: 80px;">
  86. 标签个数
  87. </th>
  88. <th style="width: 80px;">
  89. 标签代表数量
  90. </th>
  91. <th style="width: 150px;">
  92. 供应商
  93. </th>
  94. <th style="width: 150px;">
  95. 放置货位
  96. </th>
  97. <th style="width: 60px;">
  98. <button
  99. type="button"
  100. class="btn btn-default"
  101. style="width: 100%"
  102. @click="generateAllPack()"
  103. >
  104. 打印
  105. </button>
  106. </th>
  107. <th style="width: 100px;">
  108. <button
  109. type="button"
  110. class="btn btn-default"
  111. style="width: 100%"
  112. @click="generateAllRepeatPack()"
  113. >
  114. 重复打印全部
  115. </button>
  116. </th>
  117. </tr>
  118. </thead>
  119. <tbody class="table1">
  120. <tr v-for="(inventoryInstance, index) in inventoryInstanceDatas" :key="inventoryInstance.id">
  121. <td>
  122. {{ index + 1 + (pagination.current_page-1) * pagination.per_page }}
  123. </td>
  124. <td @click="showBigImage(index)">
  125. <img
  126. :src="Common.getThumbnailImageSrc(className, inventoryInstance.imageNames)"
  127. class="image"
  128. @click="$refs.imagePreview.preview(className, inventoryInstance.imageNames)"
  129. />
  130. </td>
  131. <td>
  132. {{ inventoryInstance.inventoryName }}
  133. </td>
  134. <td>
  135. {{ inventoryInstance.inventoryCode }}
  136. </td>
  137. <td>
  138. {{ inventoryInstance.type }}
  139. </td>
  140. <td>
  141. {{ inventoryInstance.computationUnit }}
  142. </td>
  143. <td>
  144. <input
  145. v-model="inventoryInstance.purchaseOrderNo"
  146. autocomplete="off"
  147. type="text"
  148. class="form-control"
  149. style="width: 100%"
  150. />
  151. </td>
  152. <td>
  153. <input
  154. v-model="inventoryInstance.batchNo"
  155. autocomplete="off"
  156. type="text"
  157. class="form-control"
  158. style="width: 100%"
  159. />
  160. </td>
  161. <td>
  162. <input
  163. v-model="inventoryInstance.packageCount"
  164. autocomplete="off"
  165. type="number"
  166. class="form-control"
  167. style="width: 100%"
  168. />
  169. </td>
  170. <td>
  171. <input
  172. v-model="inventoryInstance.quantity"
  173. autocomplete="off"
  174. type="text"
  175. style="width: 100%"
  176. class="form-control"
  177. />
  178. </td>
  179. <td>
  180. <SearchWidget
  181. :info-window-no="infoWindowNo1"
  182. :field-value="getFieldValue1(inventoryInstance)"
  183. :display-name="'v.name'"
  184. :where-clause-source="whereClauseSource"
  185. @value-changed="valueChanged1($event,inventoryInstance)"
  186. />
  187. </td>
  188. <td>
  189. <SearchWidget
  190. :info-window-no="infoWindowNo2"
  191. :field-value="getFieldValue2(inventoryInstance)"
  192. :display-name="'p.barCode'"
  193. :where-clause-source="whereClauseSource"
  194. @value-changed="valueChanged2($event,inventoryInstance)"
  195. />
  196. </td>
  197. <td>
  198. <button
  199. type="button"
  200. class="btn btn-default"
  201. style="width: 100%"
  202. @click="generatePack(inventoryInstance)"
  203. >
  204. 打印
  205. </button>
  206. </td>
  207. <td>
  208. <button
  209. type="button"
  210. class="btn btn-default"
  211. style="width: 100%"
  212. @click="generateRepeatPack(inventoryInstance)"
  213. >
  214. 重复打印
  215. </button>
  216. </td>
  217. </tr>
  218. </tbody>
  219. </table>
  220. </div>
  221. <div class="flex-footer">
  222. <div>
  223. <div class="form-group">
  224. <div class="pull-left">
  225. 共查询到<b>{{ pagination.total }}</b>条数据
  226. </div>
  227. <div class="pull-right">
  228. <VueBootstrapPagination
  229. v-if="pagination.last_page > 0"
  230. :pagination="pagination"
  231. :callback="queryInventory"
  232. />
  233. </div>
  234. </div>
  235. </div>
  236. </div>
  237. </div>
  238. <PrintEpc ref="printEpc" :printer-name="printerName" />
  239. <ImagePreview ref="imagePreview" />
  240. <Loading v-if="loading" />
  241. </div>
  242. </template>
  243. <script>
  244. import Common from '../common/Common.js';
  245. import InventoryResource from '../api/common/InventoryResource.js';
  246. import InventoryInstancePrintResource from '../api/wms/InventoryInstancePrintResource.js';
  247. import { PrintUtil,PrintWidget } from 'pc-component-v3';
  248. export default {
  249. components: {
  250. PrintWidget,
  251. },
  252. data: function () {
  253. this.Common = Common;
  254. return {
  255. message: '',
  256. inventoryInstanceDatas: [],
  257. recordIds: [],
  258. infoWindowNo1: 283036,
  259. infoWindowNo2: 283920,
  260. whereClauseSource: {
  261. customerDataDimensions:[{
  262. fieldName: 'organization.id',
  263. dataDimensionTypeNo: '202201191700',
  264. defaultDataDimensionTypeValueNo: '1',
  265. }],
  266. },
  267. pagination: {
  268. total: 0,
  269. per_page: Common.pageSize, // required
  270. current_page: 1, // required
  271. last_page: 0, // required
  272. },
  273. isUpdatePage: true,
  274. className: 'com.leanwo.prodog.model.common.Inventory',
  275. allRepeatPack: [], //重复打印全部的id
  276. printType: 1,//类型 0:采购入库打印/1:扫描入库打印
  277. printerName: '',
  278. loading: false,
  279. selectedPrinterTitle:'',
  280. };
  281. },
  282. mounted: function () {
  283. var _self = this;
  284. _self.queryInventory();
  285. $('.fixed-table').tableFixer({
  286. 'left': 3,
  287. 'head': true,
  288. });
  289. $('.fixed-table').colResizable({
  290. resizeMode: 'overflow',
  291. partialRefresh: true,
  292. });
  293. },
  294. methods: {
  295. getPrintName:function(value){
  296. this.selectedPrinterTitle = value;
  297. },
  298. getFieldValue1: function (item) {
  299. var fieldValue1 = {
  300. id: item.vendorId,
  301. displayValue: [item.vendorName],
  302. fieldType: 'Key',
  303. };
  304. return fieldValue1;
  305. },
  306. getFieldValue2: function (item) {
  307. var fieldValue2 = {
  308. id: item.positionId,
  309. displayValue: [item.savePositionName],
  310. fieldType: 'Key',
  311. };
  312. return fieldValue2;
  313. },
  314. // 用户选择框change事件
  315. valueChanged1: function (newFieldValue, item) {
  316. item.vendorId = newFieldValue.id;
  317. item.vendorName = newFieldValue.displayValue[0];
  318. },
  319. // 用户选择框change事件
  320. valueChanged2: function (newFieldValue, item) {
  321. item.positionId = newFieldValue.id;
  322. item.savePositionName = newFieldValue.displayValue[0];
  323. },
  324. /**
  325. * 打印选择的全部存货
  326. */
  327. generateAllPack: function () {
  328. var _self = this;
  329. var quantityFilled = true;
  330. this.inventoryInstanceDatas.forEach(function (item) {
  331. if (!item.quantity) {
  332. quantityFilled = false;
  333. }
  334. });
  335. if (!quantityFilled) {
  336. Notify.error('提示', '请填写数量', false);
  337. return;
  338. }
  339. var correctQuantity = true;
  340. this.inventoryInstanceDatas.forEach(function (item) {
  341. if (parseInt(item.quantity) != item.quantity || item.quantity <= 0) {
  342. correctQuantity = false;
  343. }
  344. });
  345. if (!correctQuantity) {
  346. Notify.error('提示', '请输入正整数', false);
  347. return;
  348. }
  349. let selectedPrinter = this.selectedPrinterTitle;
  350. if (selectedPrinter == null || selectedPrinter.length == 0) {
  351. Notify.error('提示', '请先选择打印机。', false);
  352. return;
  353. }
  354. $.ajax({
  355. url: Common.getApiURL('InventoryInstanceResource/generateInventoryInstances?type=' + _self.printType),
  356. dataType: 'json',
  357. type: 'post',
  358. contentType: 'application/json',
  359. data: JSON.stringify(_self.inventoryInstanceDatas),
  360. beforeSend: function (request) {
  361. Common.addTokenToRequest(request);
  362. },
  363. success: function (successData) {
  364. var ids = [];
  365. if(successData.errorCode == 0) {
  366. if(successData.datas.length > 0) {
  367. successData.datas.forEach(function (item) {
  368. ids.push(item.id);
  369. });
  370. _self.print(ids);
  371. //更新全部重复打印数据
  372. _self.allRepeatPack = successData.datas;
  373. }
  374. } else {
  375. Notify.error('提示', successData.errorMessage, false);
  376. }
  377. },
  378. error: function (XMLHttpRequest, textStatus, errorThrown) {
  379. Common.processException(XMLHttpRequest, textStatus, errorThrown);
  380. },
  381. });
  382. },
  383. /**
  384. * 重复打印全部
  385. */
  386. generateAllRepeatPack: function () {
  387. var _self = this;
  388. if (_self.allRepeatPack == null || _self.allRepeatPack.length == 0) {
  389. Notify.error('提示', '请先点击【打印】按钮,然后再点击【重复打印全部】按钮。', false);
  390. return;
  391. } else {
  392. var ids = [];
  393. _self.allRepeatPack.forEach(function (item) {
  394. ids.push(item.id);
  395. });
  396. _self.print(ids);
  397. }
  398. },
  399. /**
  400. * 打印单个存货
  401. */
  402. generatePack: function (inventoryInstance) {
  403. var _self = this;
  404. if (!inventoryInstance.quantity) {
  405. Notify.error('提示', '请填写数量。', false);
  406. return;
  407. }
  408. if (parseInt(inventoryInstance.quantity) != inventoryInstance.quantity || inventoryInstance.quantity <= 0) {
  409. Notify.error('提示', '请输入正整数。', false);
  410. return;
  411. }
  412. let selectedPrinter = this.selectedPrinterTitle;
  413. if (selectedPrinter == null || selectedPrinter.length == 0) {
  414. Notify.error('提示', '请先选择打印机。', false);
  415. return;
  416. }
  417. var datas = [];
  418. datas.push(inventoryInstance);
  419. $.ajax({
  420. url: Common.getApiURL('InventoryInstanceResource/generateInventoryInstances?type=' + _self.printType),
  421. dataType: 'json',
  422. type: 'post',
  423. contentType: 'application/json',
  424. data: JSON.stringify(datas),
  425. beforeSend: function (request) {
  426. Common.addTokenToRequest(request);
  427. _self.loading=true;
  428. },
  429. success: function (successData) {
  430. _self.loading=false;
  431. var ids = [];
  432. if(successData.errorCode == 0) {
  433. if(successData.datas.length > 0) {
  434. successData.datas.forEach(function (item) {
  435. ids.push(item.id);
  436. });
  437. _self.print(ids);
  438. //更新全部重复打印数据
  439. _self.allRepeatPack = successData.datas;
  440. }
  441. } else {
  442. Notify.error('提示', successData.errorMessage, false);
  443. }
  444. },
  445. error: function (XMLHttpRequest, textStatus, errorThrown) {
  446. _self.loading=false;
  447. Common.processException(XMLHttpRequest, textStatus, errorThrown);
  448. },
  449. });
  450. },
  451. /**
  452. * 重复打印其中一种
  453. * @param {Object} inventoryInstance
  454. */
  455. generateRepeatPack: function (inventoryInstance) {
  456. var _self = this;
  457. var printIds = [];
  458. _self.allRepeatPack.forEach(function (item) {
  459. if (item.inventoryId == inventoryInstance.inventoryId) {
  460. printIds.push(item.id);
  461. }
  462. });
  463. if (printIds == null || printIds.length == 0) {
  464. Notify.error('提示', '请先点击【打印】按钮,然后再点击【重复打印】按钮。', false);
  465. return;
  466. } else {
  467. _self.print(printIds);
  468. }
  469. },
  470. /**
  471. * 根据物料名称或者编号查询数据
  472. */
  473. queryInventory: function () {
  474. var _self = this;
  475. var message = $.trim(this.message);
  476. if (_self.message.length > 0 && !_self.isUpdatePage) {
  477. _self.pagination.current_page = 1;
  478. _self.isUpdatePage = true;
  479. } else if (_self.message.length <= 0) {
  480. _self.isUpdatePage = false;
  481. }
  482. _self.inventoryInstanceDatas.splice(0, _self.inventoryInstanceDatas.length);
  483. let inventoryQueryConditionRequest = {
  484. 'name': message,
  485. 'no': message,
  486. 'type': message,
  487. 'range': {
  488. 'start': (_self.pagination.current_page - 1) * _self.pagination.per_page,
  489. 'length': _self.pagination.per_page,
  490. },
  491. };
  492. _self.loading=true;
  493. InventoryResource.findByQueryCodition(inventoryQueryConditionRequest).then(baseRangeResponse => {
  494. _self.loading=false;
  495. if (baseRangeResponse.errorCode == 0) {
  496. baseRangeResponse.datas.forEach(function (item) {
  497. var newInventoryInstance = {
  498. 'inventoryName': item.name,
  499. 'inventoryCode': item.no,
  500. 'quantity': '',
  501. 'batchNo': '',
  502. 'savePositionName': item.savePositionName,
  503. 'computationUnit': item.computationUnit,
  504. 'type': item.type,
  505. 'inventoryId': item.id,
  506. 'vendorId': item.vendorId,
  507. 'positionId': item.positionId,
  508. 'vendorName': item.vendorName,
  509. 'imageNames': item.imageNames,
  510. 'purchaseOrderNo': item.purchaseOrderNo,
  511. };
  512. _self.inventoryInstanceDatas.push(newInventoryInstance);
  513. });
  514. _self.pagination.total = baseRangeResponse.total;
  515. _self.pagination.last_page = Math.ceil(_self.pagination.total / _self.pagination.per_page);
  516. }
  517. //查询清空上一次的打印数据
  518. _self.allRepeatPack = [];
  519. _self.fixedTableHeader();
  520. }, errorData => {
  521. _self.loading=false;
  522. Common.processException(errorData);
  523. });
  524. },
  525. /**
  526. * 打印文件
  527. */
  528. print: function (recordIds) {
  529. var _self = this;
  530. var printData = [];
  531. _self.loading=true;
  532. InventoryInstancePrintResource.print(recordIds).then(baseListResponse => {
  533. _self.loading=false;
  534. if (baseListResponse.errorCode == 0) {
  535. let selectedPrinter = this.selectedPrinterTitle;
  536. let selectedPrinterType = _self.$refs.printWidget.getSelectedPrinterTypeTitle();
  537. _self.printerName = selectedPrinter;
  538. if (selectedPrinterType == '发卡机') {
  539. _self.$nextTick(function(){
  540. _self.$refs.printEpc.printPrintPages(baseListResponse.datas);
  541. });
  542. } else {
  543. var contents = [];
  544. baseListResponse.datas.forEach(function (item) {
  545. var printItem = {
  546. id: null,
  547. name: null,
  548. content: item,
  549. };
  550. console.log(printItem);
  551. if (printItem.content == null || printItem.content.printItems == null || printItem.content.printItems.length ==
  552. 0) {
  553. Notify.error('错误', '打印模板无数据,不能打印。');
  554. return;
  555. }
  556. var content = JSON.stringify(printItem.content);
  557. if (content == null || content == '' || content == '{}') {
  558. Notify.error('错误', '请先选择模板,再点击下载。');
  559. return;
  560. }
  561. contents.push(printItem.content);
  562. });
  563. PrintUtil.printPrintPages(contents, selectedPrinter);
  564. }
  565. }
  566. }, errorData => {
  567. _self.loading=false;
  568. Common.processException(errorData);
  569. });
  570. },
  571. /**
  572. * 冻结表头
  573. */
  574. fixedTableHeader: function () {
  575. let _self = this;
  576. _self.$nextTick(function () {
  577. $('.fixed-table').tableFixer({
  578. 'left': 3,
  579. 'head': true,
  580. });
  581. });
  582. },
  583. },
  584. };
  585. </script>
  586. <style scoped>
  587. .flex-container {
  588. display: flex;
  589. /* 垂直*/
  590. flex-direction: column;
  591. width: 100%;
  592. /*视口被均分为100单位的vh 占据整个窗口,扣掉顶部topNav的距离后,计算得到container的高度*/
  593. height: calc(100vh - 140px);
  594. }
  595. .flex-header {
  596. /*放大缩小比例为0 */
  597. flex: 0 0 35px;
  598. }
  599. .flex-footer {
  600. height: 45px;
  601. /*放大缩小比例为0 */
  602. flex: 0 0 45px;
  603. }
  604. .flex-content {
  605. flex: 1;
  606. overflow: scroll;
  607. width: 100%;
  608. }
  609. .fixed-table {
  610. table-layout: fixed;
  611. word-wrap: break-word;
  612. word-break: break-all;
  613. }
  614. </style>
  615. <style scoped>
  616. .fixed-table {
  617. table-layout: fixed;
  618. width: 800px !important;
  619. min-width: 800px !important;
  620. }
  621. table.fixed-table tr {
  622. height: 40px;
  623. }
  624. table.fixed-table th,
  625. table.fixed-table td {
  626. overflow: hidden;
  627. white-space: nowrap;
  628. text-overflow: ellipsis;
  629. }
  630. .image {
  631. width: 40px;
  632. height: 40px;
  633. }
  634. .modal-img-box {
  635. width: 100%;
  636. text-align: center;
  637. overflow: auto;
  638. }
  639. .m-img {
  640. width: 100%;
  641. }
  642. </style>