NeedPrint.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. <template>
  2. <div>
  3. <Navbar title="待打印" :is-go-back="true" />
  4. <PrintWidget
  5. ref="printWidget" :printer-localstorage-id="'#InventoryPrinterPrinter'"
  6. @selected-printer-name="getPrintName"
  7. />
  8. <a-form :colon="false">
  9. <a-row :gutter="[8, 0]" justify="space-start">
  10. <a-col>
  11. <a-form-item label="采购订单号" :label-col="{ style: 'width: 80px' }" class="horizontal-form-item">
  12. <a-input v-model:value="documentNo" placeholder="输入采购订单号" />
  13. </a-form-item>
  14. </a-col>
  15. <a-col>
  16. <a-form-item label="存货名称" :label-col="{ style: 'width: 80px' }" class="horizontal-form-item">
  17. <a-input v-model:value="inventoryName" placeholder="输入存货档案名称" class="w-full" />
  18. </a-form-item>
  19. </a-col>
  20. <a-col>
  21. <a-form-item label="存货编码" :label-col="{ style: 'width: 80px' }" class="horizontal-form-item">
  22. <a-input v-model:value="inventoryCode" placeholder="输入存货档案编码" class="w-full" />
  23. </a-form-item>
  24. </a-col>
  25. <a-col>
  26. <a-form-item label="规格型号" :label-col="{ style: 'width: 80px' }" class="horizontal-form-item">
  27. <a-input v-model:value="inventoryType" placeholder="输入规格型号" class="w-full" />
  28. </a-form-item>
  29. </a-col>
  30. <a-col>
  31. <a-form-item>
  32. <a-button type="primary" @click="loadNeedPrintInventoryInstance">查询</a-button>
  33. <a-button style="margin-left: 10px;" type="primary" @click="printBarCode">打印条码</a-button>
  34. </a-form-item>
  35. </a-col>
  36. </a-row>
  37. </a-form>
  38. <div>
  39. <CommonTable :total="pagination.total" :columns="columns" :data-source="inventoryInstances" :is-select="true" @get-selected="getSelected">
  40. <template #bodyCell="{ column, record, index }">
  41. <template v-if="column.dataIndex === 'index'">{{ index + 1 }}</template>
  42. <template v-if="column.dataIndex === 'printStatus'">待打印</template>
  43. <template v-else>{{ record[column.dataIndex] }}</template>
  44. </template>
  45. </CommonTable>
  46. </div>
  47. <Modal v-model:show="modal">
  48. <ProcessReportResult :process-report-result="processReportResult" />
  49. <template #header>执行结果</template>
  50. </Modal>
  51. <Loading v-if="loading" />
  52. </div>
  53. </template>
  54. <script>
  55. import Common from '../common/Common.js';
  56. import { PrintUtil } from 'pc-component-v3';
  57. import CommonTable from '../common/CommonTable.vue';
  58. import InventoryInstancePrintResource from '../api/wms/InventoryInstancePrintResource.js';
  59. import { Form, Input, Button, Table, Checkbox } from 'ant-design-vue';
  60. export default {
  61. components: {
  62. [Form.name]: Form,
  63. [Form.Item.name]: Form.Item,
  64. [Input.name]: Input,
  65. [Button.name]: Button,
  66. [Table.name]: Table,
  67. [Checkbox.name]: Checkbox,
  68. CommonTable,
  69. },
  70. data: function () {
  71. return {
  72. inventoryName: '',
  73. inventoryCode: '',
  74. inventoryType: '',
  75. documentNo: '',
  76. inventoryInstances: [],
  77. checkboxModel: [],
  78. checkAll: false,
  79. reportResult: {},
  80. processReportResult: {},
  81. pagination: {
  82. total: 0,
  83. pageSize: 30,
  84. current: 1,
  85. },
  86. loading: false,
  87. modal: false,
  88. selectedPrinterTitle: '',
  89. indeterminate: false,
  90. };
  91. },
  92. computed: {
  93. columns: function () {
  94. return [
  95. {
  96. title: '序号',
  97. dataIndex: 'index',
  98. },
  99. {
  100. title: '订单编号',
  101. dataIndex: 'purchaseOrderDocumentNo',
  102. },
  103. {
  104. title: '存货名称',
  105. dataIndex: 'inventoryName',
  106. },
  107. {
  108. title: '存货编码',
  109. dataIndex: 'inventoryCode',
  110. },
  111. {
  112. title: '规格型号',
  113. dataIndex: 'inventoryType',
  114. },
  115. {
  116. title: '创建日期',
  117. dataIndex: 'createDate',
  118. },
  119. {
  120. title: '包装内物料数量',
  121. dataIndex: 'printQuantity',
  122. },
  123. {
  124. title: '订单数量',
  125. dataIndex: 'quantity',
  126. },
  127. {
  128. title: '打印状态',
  129. dataIndex: 'printStatus',
  130. },
  131. ];
  132. },
  133. rowSelection() {
  134. return {
  135. selectedRowKeys: this.checkboxModel.map(item => item.id),
  136. onChange: (selectedRowKeys, selectedRows) => {
  137. this.checkboxModel = selectedRows;
  138. },
  139. getCheckboxProps: record => ({
  140. disabled: false, // 可根据需要设置禁用状态
  141. }),
  142. };
  143. },
  144. },
  145. watch: {
  146. checkboxModel: {
  147. handler(newVal) {
  148. this.indeterminate = !!newVal.length && newVal.length < this.inventoryInstances.length;
  149. this.checkAll = newVal.length === this.inventoryInstances.length;
  150. },
  151. deep: true,
  152. },
  153. },
  154. mounted: function () {
  155. this.loadNeedPrintInventoryInstance();
  156. this.keydown();
  157. },
  158. methods: {
  159. getSelected: function (selectedRows) {
  160. this.checkboxModel = selectedRows.selectedRows;
  161. },
  162. getPrintName: function (value) {
  163. this.selectedPrinterTitle = value;
  164. },
  165. loadNeedPrintInventoryInstance: function () {
  166. var _self = this;
  167. const documentNo = _self.documentNo;
  168. const inventoryName = _self.inventoryName;
  169. const inventoryCode = _self.inventoryCode;
  170. const inventoryType = _self.inventoryType;
  171. _self.loading = true;
  172. InventoryInstancePrintResource.queryInventoryInstancePrint(
  173. false,
  174. documentNo,
  175. inventoryName,
  176. inventoryCode,
  177. inventoryType,
  178. ).then(
  179. data => {
  180. if (data) {
  181. _self.inventoryInstances = data.inventoryInstancePrintDtos.map(item => ({
  182. ...item,
  183. checked: false,
  184. }));
  185. _self.pagination.total = data.totalCount;
  186. }
  187. _self.loading = false;
  188. },
  189. errorData => {
  190. _self.loading = false;
  191. Common.processException(errorData);
  192. },
  193. );
  194. },
  195. printBarCode: function () {
  196. if (this.checkboxModel.length === 0) {
  197. Notify.notice('提示', '请至少选择一项打印', false);
  198. } else if (!this.selectedPrinterTitle) {
  199. Notify.error('提示', '请先选择打印机。', false);
  200. return;
  201. }
  202. this.loading = true;
  203. const inventoryIds = this.checkboxModel.map(item => item.inventoryInstanceId);
  204. InventoryInstancePrintResource.print(inventoryIds).then(
  205. baseListResponse => {
  206. if (baseListResponse.errorCode === 0) {
  207. this.loading = false;
  208. const contents = [];
  209. baseListResponse.datas.forEach(item => {
  210. const printItem = {
  211. id: null,
  212. name: null,
  213. content: item,
  214. };
  215. if (
  216. !printItem.content ||
  217. !printItem.content.printItems ||
  218. printItem.content.printItems.length === 0
  219. ) {
  220. Notify.error('错误', '打印模板无数据,不能打印。');
  221. return;
  222. }
  223. const content = JSON.stringify(printItem.content);
  224. if (!content || content === '{}') {
  225. Notify.error('错误', '请先选择模板,再点击下载。');
  226. return;
  227. }
  228. contents.push(printItem.content);
  229. });
  230. PrintUtil.printPrintPages(contents, this.selectedPrinterTitle);
  231. }
  232. },
  233. errorData => {
  234. this.loading = false;
  235. Common.processException(errorData);
  236. },
  237. );
  238. setTimeout(() => {
  239. this.loadNeedPrintInventoryInstance();
  240. this.checkboxModel = [];
  241. }, 2000);
  242. },
  243. printPdf: function () {
  244. if (this.checkboxModel.length === 0) {
  245. Notify.notice('提示', '请至少选择一项打印', false);
  246. return;
  247. }
  248. this.loading = true;
  249. },
  250. keydown: function () {
  251. document.addEventListener('keydown', event => {
  252. if (event.key === 'Enter') {
  253. event.preventDefault();
  254. this.loadNeedPrintInventoryInstance();
  255. }
  256. });
  257. },
  258. },
  259. };
  260. </script>
  261. <style scoped>
  262. .ant-form-item {
  263. margin-bottom: 0px;
  264. }
  265. .horizontal-form-item {
  266. display: flex;
  267. align-items: center;
  268. gap: 8px;
  269. }
  270. .w-full {
  271. width: 160px;
  272. }
  273. :deep(.ant-form-item) {
  274. margin-bottom: 10px !important;
  275. }
  276. :deep(.ant-form-item-label > label) {
  277. font-size: 14px !important;
  278. font-weight: 600 !important;
  279. }
  280. </style>