materialTable.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  1. <template>
  2. <div>
  3. <seek-page :seekList="seekList" @search="search"></seek-page>
  4. <ele-pro-table
  5. ref="table"
  6. row-key="id"
  7. :columns="columns"
  8. :datasource="datasource"
  9. :cache-key="cacheKeyUrl"
  10. :selection.sync="selection"
  11. autoAmendPage
  12. height="calc(86vh - 230px)"
  13. >
  14. <template v-slot:action="{ row }">
  15. <el-link type="primary" :underline="false" @click="goToDetail(row)">
  16. 详情
  17. </el-link>
  18. </template>
  19. <template v-slot:code="{ row }">
  20. <el-link type="primary" @click="goToDetail(row)">{{
  21. row.code
  22. }}</el-link>
  23. </template>
  24. <template v-slot:status="{ row }">
  25. <el-tag
  26. :type="['info', 'success', 'warning', 'danger'][row.status]"
  27. effect="dark"
  28. >{{ statusList[row.status] }}</el-tag
  29. >
  30. </template>
  31. <template v-slot:toolbar>
  32. <exportButton
  33. fileName="领料单"
  34. apiUrl="/mes/pickorder/exportBatchRecordPage"
  35. :params="params"
  36. ></exportButton>
  37. <print-selector :options="printOptions" @select="handlePrint" />
  38. </template>
  39. </ele-pro-table>
  40. <detailed
  41. @detailedClose="detailedClose"
  42. v-if="detailedShow && detailedObj"
  43. :detailedObj="detailedObj"
  44. ></detailed>
  45. <selfDetailed
  46. @detailedClose="detailedClose"
  47. v-if="selfDetailedShow && detailedObj"
  48. :detailedObj="detailedObj"
  49. ></selfDetailed>
  50. <material-requisition ref="materialRequisition" />
  51. <material-requisition-t-r ref="materialRequisitionTR" />
  52. </div>
  53. </template>
  54. <script>
  55. import dictMixins from '@/mixins/dictMixins';
  56. import tableColumnsMixin from '@/mixins/tableColumnsMixin';
  57. import { batchRecordPage, queryPrint } from '@/api/pickorder/index';
  58. import detailed from '@/views/produce/components/picking/detailed.vue';
  59. import selfDetailed from '@/views/pick/pickApply/components/selfDetailed.vue';
  60. import exportButton from '@/components/upload/exportButton.vue';
  61. import { getDetails } from '@/api/pick/pickApply';
  62. import printSelector from '../printSelector.vue';
  63. import materialRequisition from '../../print/electrodeBatchRecord/materialRequisition.vue';
  64. import materialRequisitionTR from '../../print/electrodeBatchRecord/materialRequisitionTR.vue';
  65. export default {
  66. mixins: [dictMixins, tableColumnsMixin],
  67. components: {
  68. detailed,
  69. selfDetailed,
  70. exportButton,
  71. printSelector,
  72. materialRequisition,
  73. materialRequisitionTR
  74. },
  75. props: {
  76. tableQuery: {
  77. type: Object,
  78. default: () => {
  79. return {};
  80. }
  81. }
  82. },
  83. data() {
  84. return {
  85. columns: [
  86. {
  87. width: 45,
  88. type: 'selection',
  89. columnKey: 'selection',
  90. align: 'center',
  91. fixed: 'left'
  92. },
  93. {
  94. width: 50,
  95. type: 'index',
  96. columnKey: 'index',
  97. align: 'center',
  98. label: '序号'
  99. },
  100. {
  101. prop: 'code',
  102. label: '领料单编码',
  103. align: 'center',
  104. minWidth: 110,
  105. showOverflowTooltip: true,
  106. slot: 'code'
  107. },
  108. {
  109. prop: 'workOrderCode',
  110. label: '关联工单编号',
  111. align: 'center',
  112. showOverflowTooltip: true,
  113. minWidth: 150
  114. },
  115. {
  116. prop: 'warehouseName',
  117. label: '领料仓库名称',
  118. align: 'center',
  119. showOverflowTooltip: true,
  120. minWidth: 150
  121. },
  122. {
  123. prop: 'createUserName',
  124. label: '领料人',
  125. align: 'center',
  126. showOverflowTooltip: true,
  127. minWidth: 150
  128. },
  129. {
  130. prop: 'createTime',
  131. label: '领料时间',
  132. align: 'center',
  133. showOverflowTooltip: true,
  134. minWidth: 150
  135. },
  136. {
  137. prop: 'status',
  138. label: '状态',
  139. align: 'center',
  140. showOverflowTooltip: true,
  141. minWidth: 150,
  142. slot: 'status'
  143. },
  144. {
  145. label: '操作',
  146. columnKey: 'action',
  147. slot: 'action',
  148. showOverflowTooltip: true,
  149. minWidth: 110,
  150. align: 'center',
  151. fixed: 'right'
  152. }
  153. ],
  154. cacheKeyUrl: 'mes-259231040-material-table',
  155. detailedShow: false,
  156. selfDetailedShow: false,
  157. detailedObj: null,
  158. statusList: ['未领料', '领料中', '已出库', '已驳回'],
  159. params: {},
  160. tableData: [],
  161. selection: [],
  162. printTypeMap: {
  163. materialRequisition: 'PICK_ORDER',
  164. materialRequisitionTR: 'CHANTIJTONG_PICK_ORDER'
  165. },
  166. printOptions: [
  167. { key: 'materialRequisition', label: '领(退)料单', code: 'CG-015' },
  168. {
  169. key: 'materialRequisitionTR',
  170. label: '领料单(畅捷通)',
  171. code: 'TR.D-015CG'
  172. }
  173. ]
  174. };
  175. },
  176. computed: {
  177. seekList() {
  178. return [
  179. {
  180. label: '工单编码:',
  181. value: 'workOrderCode',
  182. type: 'input',
  183. placeholder: '请输入'
  184. },
  185. {
  186. label: '领料单编码:',
  187. value: 'pickOrderCode',
  188. type: 'input',
  189. placeholder: '请输入',
  190. labelWidth: 110
  191. }
  192. // {
  193. // label: '领料名称:',
  194. // value: 'pickOrderName',
  195. // type: 'input',
  196. // placeholder: '请输入'
  197. // }
  198. ];
  199. }
  200. },
  201. methods: {
  202. // 刷新表格
  203. reload(where = {}) {
  204. this.$refs.table.reload({
  205. where,
  206. ...this.tableQuery
  207. });
  208. },
  209. /* 表格数据源 */
  210. datasource({ page, limit, where, order }) {
  211. // 参数
  212. const body = {
  213. ...where,
  214. ...order,
  215. pageNum: page,
  216. size: limit,
  217. ...this.tableQuery
  218. };
  219. this.params = body;
  220. const res = batchRecordPage(body);
  221. Promise.resolve(res).then((data) => {
  222. this.tableData = data?.list || data?.records || [];
  223. });
  224. return res;
  225. },
  226. search(where) {
  227. this.reload(where);
  228. },
  229. async goToDetail(row) {
  230. const res = await getDetails(row.id);
  231. this.detailedObj = JSON.stringify(res);
  232. this.$nextTick(() => {
  233. if (this.detailedObj.type == 1) {
  234. this.selfDetailedShow = true;
  235. } else {
  236. this.detailedShow = true;
  237. }
  238. });
  239. },
  240. detailedClose() {
  241. this.detailedShow = false;
  242. this.selfDetailedShow = false;
  243. },
  244. async handlePrint(key) {
  245. if (!this.selection.length) {
  246. this.$message.warning('请先勾选要打印的领料单');
  247. return;
  248. }
  249. const printType = this.printTypeMap[key];
  250. if (!printType) {
  251. this.$message.warning('暂不支持该打印单据');
  252. return;
  253. }
  254. try {
  255. const ids = this.selection.map((item) => item.id).filter(Boolean);
  256. const res = await queryPrint({ ids, printType });
  257. const data = this.buildPrintData(res);
  258. if (!data) {
  259. this.$message.warning('未查询到可打印的领料单数据');
  260. return;
  261. }
  262. if (this.$refs[key]) {
  263. this.$refs[key].open(data);
  264. }
  265. } catch (error) {
  266. this.$message.error(error.message || '查询打印数据失败');
  267. }
  268. },
  269. buildPrintData(res) {
  270. const list = Array.isArray(res?.pickOrderList)
  271. ? res.pickOrderList
  272. : Array.isArray(res)
  273. ? res
  274. : [];
  275. const r = list[0];
  276. if (!r) {
  277. return null;
  278. }
  279. const today = this.$util?.toDateString
  280. ? this.$util.toDateString(new Date(), 'yyyy-MM-dd')
  281. : new Date().toISOString().slice(0, 10);
  282. const materialList = list.length
  283. ? list.flatMap((item) => this.buildMaterialList(item))
  284. : this.buildMaterialList(r);
  285. return {
  286. code: r.code || '',
  287. date: r.executorTime || r.createTime || today,
  288. processOrderCode: r.joinWorkOrderCode || r.workOrderCode || '',
  289. processOrderNo: r.joinWorkOrderCode || r.workOrderCode || '',
  290. moCode: r.joinWorkOrderCode || r.workOrderCode || '',
  291. department: r.joinWarehouseName || r.warehouseName || '生产部',
  292. workshop: r.joinWarehouseName || r.warehouseName || '',
  293. applicant: r.executorName || r.createUserName || '',
  294. handler: r.executorName || r.createUserName || '',
  295. warehouseKeeper:
  296. r.warehouseKeeperName ||
  297. r.warehouseLeaderName ||
  298. materialList.find((item) => item.warehouseLeaderName)
  299. ?.warehouseLeaderName ||
  300. '',
  301. reviewer: r.joinReviewerName || r.reviewerName || '',
  302. creator: r.createUserName || r.executorName || '',
  303. batchNo:
  304. r.batchNo ||
  305. materialList.find((item) => item.batchNo)?.batchNo ||
  306. this.tableQuery.batchNo ||
  307. '',
  308. productCode: r.categoryCode || this.tableQuery.productCode || '',
  309. remark: r.remark || '',
  310. materialList
  311. };
  312. },
  313. buildMaterialList(order) {
  314. const detailList = [];
  315. const collectDetail = (item) => {
  316. if (!item) {
  317. return;
  318. }
  319. if (Array.isArray(item.detailList)) {
  320. detailList.push(...item.detailList);
  321. }
  322. if (Array.isArray(item.materialList)) {
  323. detailList.push(...item.materialList);
  324. }
  325. if (Array.isArray(item.orderInfoList)) {
  326. item.orderInfoList.forEach((orderInfo) => {
  327. detailList.push(...(orderInfo.bomDetailDTOS || []));
  328. detailList.push(...(orderInfo.instanceList || []));
  329. });
  330. }
  331. if (Array.isArray(item.childList)) {
  332. item.childList.forEach(collectDetail);
  333. }
  334. };
  335. collectDetail(order);
  336. return detailList.map((item) => ({
  337. ...item,
  338. materialCode: item.materialCode || item.categoryCode || '',
  339. materialName: item.materialName || item.categoryName || '',
  340. specification:
  341. item.specification || item.specifications || item.model || '',
  342. batchNo: item.batchNo || '',
  343. unit: item.unit || '',
  344. quantity:
  345. item.quantity || item.outQuantity || item.demandQuantity || '',
  346. reason: item.reason || '',
  347. purpose: item.purpose || item.taskName || '',
  348. remark: item.remark || '',
  349. warehouseLeaderName: item.warehouseLeaderName || ''
  350. }));
  351. }
  352. }
  353. };
  354. </script>
  355. <style></style>