printModal.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589
  1. <template>
  2. <BasicModal
  3. v-bind="$attrs"
  4. @register="registerModal"
  5. destroyOnClose
  6. :title="isEditCard ? '编辑装运单' : '装运单打印'"
  7. :height="400"
  8. :width="800"
  9. :ok-text="isEditCard ? '确认' : '打印'"
  10. @ok="onPrint"
  11. >
  12. <section ref="print" style="padding: 10px 10px 0; position: relative; border: 1px solid #c5c5c5; background: beige; width: 98%" id="printContent">
  13. <span style="position: absolute; right: 20px; top: 10px; font-size: 16px; font-weight: bold; cursor: pointer" @click="changeBtype">
  14. {{ info.ccmNo }}#机 / {{ info.btype === '1' ? '冷' : info.btype === '0' ? '热' : '' }}
  15. </span>
  16. <div class="ticket next-ticket">
  17. <div style="text-align: center">
  18. <p style="font-size: 24px; font-weight: 800; display: inline-block; border-bottom: 2px solid #000; margin-bottom: 16px; line-height: 30px">
  19. 龙钢公司钢坯装运单
  20. </p>
  21. </div>
  22. <div class="flex" style="line-height: 24px">
  23. <div class="flex-1">
  24. 库名:
  25. <span v-if="isEditCard">{{ info.destination }}</span>
  26. <JSearchSelect
  27. v-else
  28. type="list"
  29. style="width: 120px"
  30. :bordered="false"
  31. v-model:value="info.typeConfigId"
  32. :options="destinationOptions[info.ccmNo]"
  33. placeholder="请选择"
  34. allowClear
  35. @change="(v) => handleDestinationIdChange(v)"
  36. />
  37. </div>
  38. <div class="flex-1" style="text-align: center; font-size: 13px">
  39. <a-date-picker
  40. class="lgprint-date-picker"
  41. v-model:value="info.arrivalTimeDay"
  42. format="YYYY 年 MM 月 DD 日 HH 时 mm 分"
  43. showTime
  44. :bordered="false"
  45. />
  46. <!-- <a-input v-model:value="info.arrivalTimeDay" class="lgprint-date-picker" :bordered="false" /> -->
  47. </div>
  48. <div class="flex-1" style="text-align: right; font-size: 14px">
  49. <!-- <a-input v-model:value="info.classes" style="font-size: 14px; padding: 0; width: 100%; text-align: right" :bordered="false" /> -->
  50. <JSearchSelect
  51. type="list"
  52. :bordered="false"
  53. v-model:value="info.shift"
  54. dict="lg_bb"
  55. style="width: 60px; font-size: 14px; text-align: right"
  56. placeholder="班别"
  57. />
  58. /
  59. <JSearchSelect
  60. type="list"
  61. :bordered="false"
  62. v-model:value="info.shiftGroup"
  63. dict="lg_bz"
  64. style="width: 50px; font-size: 14px; text-align: left"
  65. placeholder="班组"
  66. />
  67. </div>
  68. </div>
  69. <a-descriptions style="margin-top: 6px; margin-bottom: 4px" layout="vertical" bordered :column="8" size="small">
  70. <a-descriptions-item style="border: 1px solid #bfbfbf; font-size: 14px; padding: 4px; text-align: center; height: 36px" label="序号">
  71. <div style="min-height: 80px; display: flex; align-items: center; justify-content: center" @click="numberEdit.value.focus()">
  72. <a-input
  73. ref="numberEdit"
  74. v-model:value="info.number"
  75. style="font-size: 14px; padding: 0; width: 28px; text-align: center"
  76. :bordered="false"
  77. />
  78. </div>
  79. </a-descriptions-item>
  80. <a-descriptions-item style="border: 1px solid #bfbfbf; font-size: 14px; padding: 4px; text-align: center; height: 36px" label="车号">
  81. <!-- {{ info.licensePlate }} -->
  82. <JSearchSelect
  83. type="list"
  84. :bordered="false"
  85. v-model:value="info.licensePlate"
  86. dict="lg_car"
  87. style="width: 110px; font-size: 14px"
  88. placeholder="请选择"
  89. allowClear
  90. />
  91. </a-descriptions-item>
  92. <a-descriptions-item style="border: 1px solid #bfbfbf; font-size: 14px; padding: 4px; text-align: center; height: 36px" label="牌号">
  93. <!-- <component :is="renderDictTag(info.brandNum, 'billet_spec')" /> -->
  94. <JSearchSelect
  95. type="list"
  96. style="width: 110px; font-size: 14px"
  97. :bordered="false"
  98. v-model:value="info.brandNum"
  99. dict="billet_spec"
  100. placeholder="请选择"
  101. allowClear
  102. />
  103. </a-descriptions-item>
  104. <a-descriptions-item
  105. class="heat-wrapper"
  106. style="border: 1px solid #bfbfbf; font-size: 14px; padding: 4px; text-align: center; height: 36px; position: relative"
  107. label="炉号"
  108. >
  109. <div style="min-width: 120px">
  110. <div class="heatNo-item" v-for="(item, sindex) in headDtl" :key="item.id">
  111. {{ item.heatNo }} - {{ item.heatNum ? item.heatNum : item.billetNos.length }}
  112. <div class="op jian" @click="deleteHeatDtl(sindex)"><Icon icon="ant-design:delete-outlined" /></div>
  113. <div class="op add" @click="editHeatDtl(sindex)">
  114. <Icon icon="ant-design:edit-outlined" />
  115. </div>
  116. </div>
  117. </div>
  118. <div class="add-heatNo" @click="addHeatDtl">+</div>
  119. </a-descriptions-item>
  120. <a-descriptions-item style="border: 1px solid #bfbfbf; font-size: 14px; padding: 4px; text-align: center; height: 36px" label="规格">
  121. <div style="min-width: 120px">
  122. <span> 170 /</span>
  123. <!-- {{ sizeInfo.join(',') }} -->
  124. <span v-if="isEditCard">{{ info.size }}</span>
  125. <!-- <JSelectMultiple type="list" :bordered="false" v-model:value="info.size" dictCode="lg_dcgg" placeholder="请选择" allowClear /> -->
  126. <a-input v-else v-model:value="info.size" :bordered="false" style="width: 80px; padding: 0; font-size: 14px; display: inline-block" />
  127. </div>
  128. </a-descriptions-item>
  129. <a-descriptions-item style="border: 1px solid #bfbfbf; font-size: 14px; padding: 4px; text-align: center; height: 36px" label="名称">
  130. <div style="min-width: 40px"> 方坯 </div>
  131. </a-descriptions-item>
  132. <a-descriptions-item style="border: 1px solid #bfbfbf; font-size: 14px; padding: 4px; text-align: center; height: 36px" label="支数">
  133. <span v-if="isEditCard">{{ info.amountTotal }}</span>
  134. <!-- {{ info.amountTotal }} -->
  135. <a-input-number
  136. v-else
  137. :bordered="false"
  138. style="min-width: 50px; width: 50px; font-size: 14px; text-align: center"
  139. v-model:value="info.amountTotal"
  140. :min="0"
  141. :max="99"
  142. :precision="0"
  143. :controls="false"
  144. />
  145. </a-descriptions-item>
  146. <!-- <a-descriptions-item style="border: 1px solid #bfbfbf; font-size: 14px; padding: 4px; text-align: center; height: 36px" label="重量">
  147. <a-input-number
  148. :bordered="false"
  149. style="min-width: 80px; width: 80px; font-size: 14px; text-align: center"
  150. v-model:value="info.weight"
  151. :min="0"
  152. :max="99"
  153. :precision="4"
  154. />
  155. </a-descriptions-item> -->
  156. </a-descriptions>
  157. <a-descriptions style="padding: 0 30px" size="small" v-if="!isEditCard">
  158. <a-descriptions-item label="储运中心"> </a-descriptions-item>
  159. <a-descriptions-item label="轧钢厂"> </a-descriptions-item>
  160. <a-descriptions-item label="炼钢厂"> </a-descriptions-item>
  161. </a-descriptions>
  162. </div>
  163. </section>
  164. <div v-if="!isCanEdit" class="mask-disabled-edit"></div>
  165. <div class="add-heat" v-if="showAddHeat" style="margin: 20px">
  166. <a-input-group size="large">
  167. <a-row :gutter="8">
  168. <a-col :span="6">
  169. <a-input-number placeholder="请输入炉号" style="min-width: 180px" size="large" v-model:value="headValue" :precision="0" />
  170. </a-col>
  171. <a-col :span="4">
  172. <a-input-number placeholder="请输入支数" v-model:value="heatNum" size="large" :precision="0" />
  173. </a-col>
  174. <a-button type="primary" @click="confirmAddHeatDtl">添加</a-button>
  175. </a-row>
  176. </a-input-group>
  177. </div>
  178. <div style="position: absolute; left: -1000px">{{ getAllAmount }}</div>
  179. </BasicModal>
  180. </template>
  181. <script lang="ts" setup>
  182. import { computed, ref } from 'vue';
  183. import { BasicModal, useModalInner } from '/@/components/Modal';
  184. import dayjs from 'dayjs';
  185. // import { render } from '/@/utils/common/renderUtils';
  186. import { printJS } from '/@/hooks/web/usePrintJS';
  187. import { listShippingBill, saveBeforePrint, getByStorageBillId, list } from '../shippingBill.api';
  188. import JSearchSelect from '/@/components/Form/src/jeecg/components/JSearchSelect.vue';
  189. // import JSelectMultiple from '/@/components/Form/src/jeecg/components/JSelectMultiple.vue';
  190. import { useMessage } from '/@/hooks/web/useMessage';
  191. import { destinationOptions } from '../../hotDelivery/common.data';
  192. import { useUserStore } from '/@/store/modules/user';
  193. const userStore = useUserStore();
  194. const { createMessage } = useMessage();
  195. const props = defineProps({
  196. api: {
  197. type: Function as PropType<(params: any) => Promise<any>>,
  198. default: listShippingBill,
  199. },
  200. });
  201. const emits = defineEmits(['success', 'register']);
  202. const info = ref<any>({});
  203. const headDtl = ref<any[]>([]);
  204. const weight = ref<number>(0);
  205. const sizeInfo = ref<string[]>([]);
  206. const numberEdit = ref();
  207. const isEditCard = ref(false);
  208. //表单赋值
  209. const [registerModal, { changeLoading, changeOkLoading, closeModal }] = useModalInner(async (data) => {
  210. const { record, type, isEdit } = data;
  211. if (record) {
  212. // 如果是单纯的编辑,就只能编辑部分,棒三,二,上若 可以部分编辑
  213. isEditCard.value = isEdit === true;
  214. let newRecord = record;
  215. // 重新获取数据
  216. const res = await list({
  217. id: record.id,
  218. });
  219. if (res.records && res.records.length > 0) {
  220. newRecord = res.records[0];
  221. }
  222. headDtl.value = [];
  223. info.value = {
  224. ...newRecord,
  225. arrivalTimeDay: dayjs(record.arrivalTime),
  226. number: record.carAllNum || record.number,
  227. classes:
  228. isEdit === true
  229. ? record.classes
  230. : // dayjs(record.arrivalTime).format('YYYYMMDDHHmmss') +
  231. // '/' +
  232. // record.carNum +
  233. // '/' +
  234. // record.carAllNum +
  235. // '/' +
  236. record.shift_dictText + '/' + record.shiftGroup_dictText,
  237. };
  238. // 如果只是纯纯的编辑
  239. // if (isEdit === true) {
  240. // } else {
  241. // await getTableList();
  242. // }
  243. if (type === 'offline') {
  244. getOfflineBill();
  245. }
  246. editDtl.value = {};
  247. } else {
  248. info.value = {};
  249. }
  250. });
  251. // 是否可编辑 轧钢确认后,除了gp账号其他的都不能编辑
  252. const isCanEdit = computed(() => {
  253. return !info.value.confirmTime || (info.value.confirmTime && userStore.userInfo && userStore.userInfo.username === 'gp');
  254. });
  255. // 渲染字典标签
  256. // const renderDictTag = (value: string, dictCode: string) => {
  257. // return render.renderDict(value, dictCode);
  258. // };
  259. const getAllAmount = computed(() => {
  260. const allNum = headDtl.value.reduce((acc, cur) => {
  261. return acc + Number(cur.heatNum ? cur.heatNum : cur.billetNos.length);
  262. }, 0);
  263. info.value.amountTotal = allNum;
  264. return allNum;
  265. });
  266. const getTableList = async () => {
  267. try {
  268. changeLoading(true);
  269. changeOkLoading(true);
  270. const { id, ccmNo, heatNo, typeConfigId } = info.value;
  271. const data = await props.api({
  272. id,
  273. ccmNo,
  274. heatNo,
  275. typeConfigId: !typeConfigId ? '1024' : typeConfigId,
  276. });
  277. let newArr: any[] = [];
  278. if (Array.isArray(data)) {
  279. newArr = data;
  280. } else {
  281. for (let item in data) {
  282. if (data[item] && data[item].length > 0) {
  283. newArr = newArr.concat(data[item]);
  284. }
  285. }
  286. }
  287. let allWeight = 0;
  288. let sizeArr: string[] = [];
  289. // 数据结果按组批号分组
  290. newArr = newArr.reduce((acc, cur) => {
  291. const index = acc.findIndex((item) => cur.heatNo && item.heatNo === cur.heatNo);
  292. if (index === -1) {
  293. acc.push({
  294. ...cur,
  295. billetNos: [...cur.billetNo.split(',')],
  296. });
  297. } else {
  298. acc[index].billetNos = acc[index].billetNos.concat(cur.billetNo.split(','));
  299. }
  300. if (cur.blankOutput) {
  301. allWeight += Number(cur.blankOutput);
  302. }
  303. if (sizeArr.indexOf(cur.size) === -1) {
  304. sizeArr.push(cur.size);
  305. }
  306. return acc;
  307. }, []);
  308. headDtl.value = newArr;
  309. weight.value = allWeight;
  310. sizeInfo.value = sizeArr;
  311. info.value.weight = allWeight;
  312. } catch (error) {
  313. console.log(error);
  314. } finally {
  315. changeLoading(false);
  316. changeOkLoading(false);
  317. }
  318. };
  319. // 获取线下票据数据
  320. const getOfflineBill = async () => {
  321. try {
  322. changeLoading(true);
  323. changeOkLoading(true);
  324. getByStorageBillId({ storageBillId: info.value.id }).then((res) => {
  325. if (res) {
  326. const shiftObj = res.classes.split('/');
  327. let shift = '';
  328. let shiftGroup = '';
  329. if (shiftObj.length === 2) {
  330. shift = shiftObj[0];
  331. shiftGroup = shiftObj[1];
  332. } else {
  333. shift = info.value.shift;
  334. shiftGroup = info.value.shiftGroup;
  335. }
  336. const destinationInfo = (destinationOptions[info.value.ccmNo] || []).find((item) => item.label === res.destination);
  337. info.value = {
  338. ...info.value,
  339. ...res,
  340. shift,
  341. shiftGroup,
  342. arrivalTimeDay: dayjs(res.arrivalTime),
  343. destination: res.destination,
  344. typeConfigId: destinationInfo ? destinationInfo.value : '',
  345. };
  346. headDtl.value = Object.keys(res.heatNo).map((item) => ({
  347. heatNo: item,
  348. heatNum: res.heatNo[item],
  349. }));
  350. }
  351. });
  352. } catch (error) {
  353. console.log(error);
  354. } finally {
  355. changeLoading(false);
  356. changeOkLoading(false);
  357. }
  358. };
  359. const deleteHeatDtl = (index: number) => {
  360. headDtl.value.splice(index, 1);
  361. };
  362. const editHeatDtl = (index: number) => {
  363. const { heatNo, heatNum: orgHeatNum, billetNos } = headDtl.value[index];
  364. headValue.value = heatNo;
  365. heatNum.value = orgHeatNum ? orgHeatNum : billetNos.length;
  366. showAddHeat.value = true;
  367. editDtl.value = headDtl.value[index];
  368. };
  369. const headValue = ref<number | null>();
  370. const heatNum = ref<number | null>();
  371. const showAddHeat = ref(false);
  372. const editDtl = ref();
  373. const addHeatDtl = () => {
  374. headValue.value = null;
  375. heatNum.value = null;
  376. showAddHeat.value = true;
  377. };
  378. const confirmAddHeatDtl = () => {
  379. if (headValue.value && heatNum.value) {
  380. if (editDtl.value && editDtl.value.heatNo) {
  381. const index = headDtl.value.findIndex((item) => item.heatNo === editDtl.value.heatNo);
  382. headDtl.value[index] = {
  383. ...headDtl.value[index],
  384. heatNo: headValue.value,
  385. heatNum: heatNum.value,
  386. };
  387. editDtl.value = {};
  388. } else {
  389. headDtl.value.push({
  390. id: headValue.value + '-' + heatNum.value,
  391. heatNo: headValue.value,
  392. heatNum: heatNum.value,
  393. });
  394. }
  395. showAddHeat.value = false;
  396. } else {
  397. createMessage.warning('请填写炉号和支数');
  398. }
  399. };
  400. const changeBtype = () => {
  401. info.value.btype = info.value.btype == '1' ? '0' : '1';
  402. };
  403. // 修改目的地
  404. function handleDestinationIdChange(v) {
  405. if (v) {
  406. const cur = destinationOptions[info.value.ccmNo].find((item) => item.value === v);
  407. info.value.destination = cur.label;
  408. } else {
  409. info.value.destination = '';
  410. }
  411. }
  412. function onPrint() {
  413. changeOkLoading(true);
  414. if (!info.value.destination || !info.value.typeConfigId || info.value.typeConfigId === '1024') {
  415. createMessage.error('请选择目的地!');
  416. return;
  417. }
  418. let headDtlObj = {};
  419. headDtl.value.forEach((item) => {
  420. headDtlObj[item.heatNo] = item.heatNum ? item.heatNum : item.billetNos.length;
  421. });
  422. if (isCanEdit) {
  423. saveBeforePrint({
  424. amountTotal: info.value.amountTotal,
  425. arrivalTime: info.value.arrivalTimeDay.format('YYYY-MM-DD HH:mm:ss'),
  426. brandNum: info.value.brandNum,
  427. destination: info.value.destination,
  428. heatNo: headDtlObj,
  429. licensePlate: info.value.licensePlate,
  430. name: '方坯',
  431. size: info.value.size,
  432. storageBillId: info.value.id,
  433. weight: info.value.weight,
  434. number: info.value.number,
  435. classes: info.value.shift + '/' + info.value.shiftGroup,
  436. btype: info.value.btype,
  437. ccmNo: info.value.ccmNo,
  438. }).then((res) => {
  439. emits('success', res);
  440. closeModal();
  441. });
  442. }
  443. if (isEditCard.value !== true) {
  444. printJS({
  445. printable: '#printContent',
  446. type: 'html',
  447. });
  448. }
  449. setTimeout(() => {
  450. changeOkLoading(false);
  451. }, 1000);
  452. }
  453. </script>
  454. <style lang="less">
  455. #printContent {
  456. .lgprint-date-picker {
  457. font-size: 14px;
  458. padding: 0;
  459. .ant-picker-input > input {
  460. font-size: 14px;
  461. text-align: center;
  462. }
  463. .ant-picker-suffix {
  464. display: none;
  465. }
  466. }
  467. .ant-select {
  468. &.ant-select-single .ant-select-selector {
  469. font-size: 14px;
  470. padding: 0;
  471. }
  472. .ant-select-selection-item {
  473. padding-inline-end: 0;
  474. }
  475. .ant-select-arrow {
  476. display: none;
  477. }
  478. }
  479. .heatNo-item {
  480. position: relative;
  481. min-width: 100px;
  482. .op {
  483. position: absolute;
  484. right: 0;
  485. top: 0;
  486. font-size: 18px;
  487. cursor: pointer;
  488. width: 18px;
  489. height: 18px;
  490. line-height: 12px;
  491. border-radius: 18px;
  492. text-align: center;
  493. background: #f5f5f5;
  494. border: 1px solid #625dfa;
  495. display: none;
  496. }
  497. .jian {
  498. right: 25px;
  499. background-color: rgb(255, 205, 205);
  500. border: 1 solid #fa5d5d;
  501. }
  502. &:hover {
  503. .op {
  504. display: block;
  505. }
  506. }
  507. }
  508. .add-heatNo {
  509. position: absolute;
  510. right: 0;
  511. top: 0;
  512. font-size: 18px;
  513. cursor: pointer;
  514. width: 18px;
  515. height: 18px;
  516. line-height: 12px;
  517. border-radius: 18px;
  518. text-align: center;
  519. background: #f5f5f5;
  520. border: 1px solid #625dfa;
  521. display: none;
  522. }
  523. .heat-wrapper {
  524. &:hover {
  525. .add-heatNo {
  526. display: block;
  527. }
  528. }
  529. }
  530. }
  531. .mask-disabled-edit {
  532. position: absolute;
  533. left: 0;
  534. right: 0;
  535. top: 0;
  536. bottom: 0;
  537. z-index: 10;
  538. }
  539. @media print {
  540. header,
  541. footer,
  542. .noprint {
  543. display: none;
  544. }
  545. @page :first {
  546. margin-top: 10px; /* 第一页的页眉距离顶部为0 */
  547. margin-bottom: 0; /* 第一页的页脚距离底部为0 */
  548. }
  549. }
  550. </style>