InventoryPrintOld.vue 20 KB

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