printModal.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588
  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']);
  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. info.value = {
  223. ...newRecord,
  224. arrivalTimeDay: dayjs(record.arrivalTime),
  225. number: record.carAllNum || record.number,
  226. classes:
  227. isEdit === true
  228. ? record.classes
  229. : // dayjs(record.arrivalTime).format('YYYYMMDDHHmmss') +
  230. // '/' +
  231. // record.carNum +
  232. // '/' +
  233. // record.carAllNum +
  234. // '/' +
  235. record.shift_dictText + '/' + record.shiftGroup_dictText,
  236. };
  237. // 如果只是纯纯的编辑
  238. // if (isEdit === true) {
  239. // } else {
  240. // await getTableList();
  241. // }
  242. if (type === 'offline') {
  243. getOfflineBill();
  244. }
  245. editDtl.value = {};
  246. } else {
  247. info.value = {};
  248. }
  249. });
  250. // 是否可编辑 轧钢确认后,除了gp账号其他的都不能编辑
  251. const isCanEdit = computed(() => {
  252. return !info.value.confirmTime || (info.value.confirmTime && userStore.userInfo && userStore.userInfo.username === 'gp');
  253. });
  254. // 渲染字典标签
  255. // const renderDictTag = (value: string, dictCode: string) => {
  256. // return render.renderDict(value, dictCode);
  257. // };
  258. const getAllAmount = computed(() => {
  259. const allNum = headDtl.value.reduce((acc, cur) => {
  260. return acc + Number(cur.heatNum ? cur.heatNum : cur.billetNos.length);
  261. }, 0);
  262. info.value.amountTotal = allNum;
  263. return allNum;
  264. });
  265. const getTableList = async () => {
  266. try {
  267. changeLoading(true);
  268. changeOkLoading(true);
  269. const { id, ccmNo, heatNo, typeConfigId } = info.value;
  270. const data = await props.api({
  271. id,
  272. ccmNo,
  273. heatNo,
  274. typeConfigId: !typeConfigId ? '1024' : typeConfigId,
  275. });
  276. let newArr: any[] = [];
  277. if (Array.isArray(data)) {
  278. newArr = data;
  279. } else {
  280. for (let item in data) {
  281. if (data[item] && data[item].length > 0) {
  282. newArr = newArr.concat(data[item]);
  283. }
  284. }
  285. }
  286. let allWeight = 0;
  287. let sizeArr: string[] = [];
  288. // 数据结果按组批号分组
  289. newArr = newArr.reduce((acc, cur) => {
  290. const index = acc.findIndex((item) => cur.heatNo && item.heatNo === cur.heatNo);
  291. if (index === -1) {
  292. acc.push({
  293. ...cur,
  294. billetNos: [...cur.billetNo.split(',')],
  295. });
  296. } else {
  297. acc[index].billetNos = acc[index].billetNos.concat(cur.billetNo.split(','));
  298. }
  299. if (cur.blankOutput) {
  300. allWeight += Number(cur.blankOutput);
  301. }
  302. if (sizeArr.indexOf(cur.size) === -1) {
  303. sizeArr.push(cur.size);
  304. }
  305. return acc;
  306. }, []);
  307. headDtl.value = newArr;
  308. weight.value = allWeight;
  309. sizeInfo.value = sizeArr;
  310. info.value.weight = allWeight;
  311. } catch (error) {
  312. console.log(error);
  313. } finally {
  314. changeLoading(false);
  315. changeOkLoading(false);
  316. }
  317. };
  318. // 获取线下票据数据
  319. const getOfflineBill = async () => {
  320. try {
  321. changeLoading(true);
  322. changeOkLoading(true);
  323. getByStorageBillId({ storageBillId: info.value.id }).then((res) => {
  324. if (res) {
  325. const shiftObj = res.classes.split('/');
  326. let shift = '';
  327. let shiftGroup = '';
  328. if (shiftObj.length === 2) {
  329. shift = shiftObj[0];
  330. shiftGroup = shiftObj[1];
  331. } else {
  332. shift = info.value.shift;
  333. shiftGroup = info.value.shiftGroup;
  334. }
  335. const destinationInfo = (destinationOptions[info.value.ccmNo] || []).find((item) => item.label === res.destination);
  336. info.value = {
  337. ...info.value,
  338. ...res,
  339. shift,
  340. shiftGroup,
  341. arrivalTimeDay: dayjs(res.arrivalTime),
  342. destination: res.destination,
  343. typeConfigId: destinationInfo ? destinationInfo.value : '',
  344. };
  345. headDtl.value = Object.keys(res.heatNo).map((item) => ({
  346. heatNo: item,
  347. heatNum: res.heatNo[item],
  348. }));
  349. }
  350. });
  351. } catch (error) {
  352. console.log(error);
  353. } finally {
  354. changeLoading(false);
  355. changeOkLoading(false);
  356. }
  357. };
  358. const deleteHeatDtl = (index: number) => {
  359. headDtl.value.splice(index, 1);
  360. };
  361. const editHeatDtl = (index: number) => {
  362. const { heatNo, heatNum: orgHeatNum, billetNos } = headDtl.value[index];
  363. headValue.value = heatNo;
  364. heatNum.value = orgHeatNum ? orgHeatNum : billetNos.length;
  365. showAddHeat.value = true;
  366. editDtl.value = headDtl.value[index];
  367. };
  368. const headValue = ref<number | null>();
  369. const heatNum = ref<number | null>();
  370. const showAddHeat = ref(false);
  371. const editDtl = ref();
  372. const addHeatDtl = () => {
  373. headValue.value = null;
  374. heatNum.value = null;
  375. showAddHeat.value = true;
  376. };
  377. const confirmAddHeatDtl = () => {
  378. if (headValue.value && heatNum.value) {
  379. if (editDtl.value && editDtl.value.heatNo) {
  380. const index = headDtl.value.findIndex((item) => item.heatNo === editDtl.value.heatNo);
  381. headDtl.value[index] = {
  382. ...headDtl.value[index],
  383. heatNo: headValue.value,
  384. heatNum: heatNum.value,
  385. };
  386. editDtl.value = {};
  387. } else {
  388. headDtl.value.push({
  389. id: headValue.value + '-' + heatNum.value,
  390. heatNo: headValue.value,
  391. heatNum: heatNum.value,
  392. });
  393. }
  394. showAddHeat.value = false;
  395. } else {
  396. createMessage.warning('请填写炉号和支数');
  397. }
  398. };
  399. const changeBtype = () => {
  400. info.value.btype = info.value.btype == '1' ? '0' : '1';
  401. };
  402. // 修改目的地
  403. function handleDestinationIdChange(v) {
  404. if (v) {
  405. const cur = destinationOptions[info.value.ccmNo].find((item) => item.value === v);
  406. info.value.destination = cur.label;
  407. } else {
  408. info.value.destination = '';
  409. }
  410. }
  411. function onPrint() {
  412. changeOkLoading(true);
  413. if (!info.value.destination || !info.value.typeConfigId || info.value.typeConfigId === '1024') {
  414. createMessage.error('请选择目的地!');
  415. return;
  416. }
  417. let headDtlObj = {};
  418. headDtl.value.forEach((item) => {
  419. headDtlObj[item.heatNo] = item.heatNum ? item.heatNum : item.billetNos.length;
  420. });
  421. if (isCanEdit) {
  422. saveBeforePrint({
  423. amountTotal: info.value.amountTotal,
  424. arrivalTime: info.value.arrivalTimeDay.format('YYYY-MM-DD HH:mm:ss'),
  425. brandNum: info.value.brandNum,
  426. destination: info.value.destination,
  427. heatNo: headDtlObj,
  428. licensePlate: info.value.licensePlate,
  429. name: '方坯',
  430. size: info.value.size,
  431. storageBillId: info.value.id,
  432. weight: info.value.weight,
  433. number: info.value.number,
  434. classes: info.value.shift + '/' + info.value.shiftGroup,
  435. btype: info.value.btype,
  436. ccmNo: info.value.ccmNo,
  437. }).then((res) => {
  438. emits('success', res);
  439. closeModal();
  440. });
  441. }
  442. if (isEditCard.value !== true) {
  443. printJS({
  444. printable: '#printContent',
  445. type: 'html',
  446. });
  447. }
  448. setTimeout(() => {
  449. changeOkLoading(false);
  450. }, 1000);
  451. }
  452. </script>
  453. <style lang="less">
  454. #printContent {
  455. .lgprint-date-picker {
  456. font-size: 14px;
  457. padding: 0;
  458. .ant-picker-input > input {
  459. font-size: 14px;
  460. text-align: center;
  461. }
  462. .ant-picker-suffix {
  463. display: none;
  464. }
  465. }
  466. .ant-select {
  467. &.ant-select-single .ant-select-selector {
  468. font-size: 14px;
  469. padding: 0;
  470. }
  471. .ant-select-selection-item {
  472. padding-inline-end: 0;
  473. }
  474. .ant-select-arrow {
  475. display: none;
  476. }
  477. }
  478. .heatNo-item {
  479. position: relative;
  480. min-width: 100px;
  481. .op {
  482. position: absolute;
  483. right: 0;
  484. top: 0;
  485. font-size: 18px;
  486. cursor: pointer;
  487. width: 18px;
  488. height: 18px;
  489. line-height: 12px;
  490. border-radius: 18px;
  491. text-align: center;
  492. background: #f5f5f5;
  493. border: 1px solid #625dfa;
  494. display: none;
  495. }
  496. .jian {
  497. right: 25px;
  498. background-color: rgb(255, 205, 205);
  499. border: 1 solid #fa5d5d;
  500. }
  501. &:hover {
  502. .op {
  503. display: block;
  504. }
  505. }
  506. }
  507. .add-heatNo {
  508. position: absolute;
  509. right: 0;
  510. top: 0;
  511. font-size: 18px;
  512. cursor: pointer;
  513. width: 18px;
  514. height: 18px;
  515. line-height: 12px;
  516. border-radius: 18px;
  517. text-align: center;
  518. background: #f5f5f5;
  519. border: 1px solid #625dfa;
  520. display: none;
  521. }
  522. .heat-wrapper {
  523. &:hover {
  524. .add-heatNo {
  525. display: block;
  526. }
  527. }
  528. }
  529. }
  530. .mask-disabled-edit {
  531. position: absolute;
  532. left: 0;
  533. right: 0;
  534. top: 0;
  535. bottom: 0;
  536. z-index: 10;
  537. }
  538. @media print {
  539. header,
  540. footer,
  541. .noprint {
  542. display: none;
  543. }
  544. @page :first {
  545. margin-top: 10px; /* 第一页的页眉距离顶部为0 */
  546. margin-bottom: 0; /* 第一页的页脚距离底部为0 */
  547. }
  548. }
  549. </style>