form.vue 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150
  1. <template>
  2. <el-drawer
  3. title="外协单信息"
  4. :with-header="false"
  5. v-model="visible"
  6. direction="rtl"
  7. size="100%"
  8. >
  9. <div class="form-container column-container">
  10. <div class="form-btns-container">
  11. <span class="title-label">
  12. <el-icon>
  13. <Document />
  14. </el-icon>
  15. <span>外协单信息</span>
  16. </span>
  17. <el-button
  18. v-show="editStatus && form.isSubmit == 1"
  19. type="primary"
  20. icon="Download"
  21. @click="handleExport"
  22. v-hasPermi="['business:outsource:export']"
  23. >导出</el-button
  24. >
  25. <el-button
  26. v-show="editStatus && form.isSubmit == 1"
  27. type="warning"
  28. icon="Download"
  29. @click="handlePrint"
  30. v-hasPermi="['business:outsource:export']"
  31. >
  32. 打印
  33. </el-button>
  34. <el-button
  35. v-if="editStatus"
  36. type="primary"
  37. icon="Finished"
  38. @click="handleSubmit"
  39. >保存</el-button
  40. >
  41. <el-button
  42. v-if="editStatus && form.isSubmit == 1"
  43. type="info"
  44. icon="Calendar"
  45. @click="handleViewRecords"
  46. >历史记录</el-button
  47. >
  48. <div class="close-btn" @click="cancel">
  49. <i class="fa fa-times" aria-hidden="true" />
  50. <!-- <span>关闭</span> -->
  51. </div>
  52. </div>
  53. <el-form
  54. ref="formRef"
  55. class="master-container"
  56. :model="form"
  57. v-loading="loading"
  58. :rules="rules"
  59. label-width="120px"
  60. >
  61. <el-row :gutter="20">
  62. <el-col :span="6">
  63. <el-form-item label="单据号" prop="formCode">
  64. <el-input
  65. v-if="editStatus"
  66. v-model="form.formCode"
  67. disabled
  68. placeholder="系统自动生成"
  69. />
  70. <span v-else>{{ form.formCode }}</span>
  71. </el-form-item>
  72. </el-col>
  73. <el-col :span="6">
  74. <el-form-item label="表单日期" prop="formDate">
  75. <el-date-picker
  76. v-if="editStatus && hasReturnReceiptDetailFlag"
  77. :clearable="false"
  78. v-model="form.formDate"
  79. type="date"
  80. value-format="YYYY-MM-DD"
  81. placeholder="请选择表单日期"
  82. style="width: 100%"
  83. >
  84. </el-date-picker>
  85. <span v-else>{{ parseTime(form.formDate, "{y}-{m}-{d}") }}</span>
  86. </el-form-item>
  87. </el-col>
  88. <el-col :span="6">
  89. <el-form-item label="外协工段" prop="outsourceDeptId">
  90. <el-select
  91. v-if="editStatus &&form.isSubmit ==0"
  92. v-model="form.outsourceDeptId "
  93. placeholder="请选择"
  94. @change="handleChangeDept"
  95. >
  96. <el-option
  97. v-for="dict in outsourceDeptList"
  98. :key="dict.value"
  99. :label="dict.label"
  100. :value="dict.value"
  101. />
  102. </el-select>
  103. <span v-else>{{ form.outsourceDeptName }}</span>
  104. </el-form-item>
  105. </el-col>
  106. <el-col :span="6">
  107. <el-form-item label="外协商名称" prop="supplierName">
  108. <el-input
  109. v-if="editStatus"
  110. v-model="form.supplierName"
  111. disabled
  112. />
  113. <span v-else >{{ form.supplierName }}</span>
  114. </el-form-item>
  115. </el-col>
  116. <el-col :span="6" v-if="false">
  117. <el-form-item label="运费单价" prop="freightPrice">
  118. <el-input-number
  119. v-if="editStatus && hasReturnReceiptDetailFlag"
  120. v-model="form.freightPrice"
  121. :min="0"
  122. :precision="2"
  123. controls-position="right"
  124. />
  125. <span v-else>{{ form.freightPrice }}</span>
  126. </el-form-item>
  127. </el-col>
  128. <el-col :span="6" v-if="false">
  129. <el-form-item label="运费总价" prop="freightAmount">
  130. <el-input-number
  131. v-if="editStatus && hasReturnReceiptDetailFlag"
  132. v-model="form.freightAmount"
  133. :min="0"
  134. :precision="2"
  135. controls-position="right"
  136. />
  137. <span v-else>{{ form.freightAmount }}</span>
  138. </el-form-item>
  139. </el-col>
  140. <el-col :span="6">
  141. <el-form-item label="送货方式" prop="deliveryMethod">
  142. <el-select
  143. v-if="editStatus && hasReturnReceiptDetailFlag"
  144. v-model="form.deliveryMethod"
  145. placeholder="请选择"
  146. @change="handleChangeDeliveryMethod"
  147. >
  148. <el-option
  149. v-for="dict in deliveryMethod"
  150. :key="dict.value"
  151. :label="dict.label"
  152. :value="dict.value"
  153. />
  154. </el-select>
  155. <span v-else>{{
  156. selectText(form.deliveryMethod, deliveryMethod)
  157. }}</span>
  158. </el-form-item>
  159. </el-col>
  160. <el-col :span="6">
  161. <el-form-item label="带箱方式" prop="packagingMethod">
  162. <el-select
  163. v-if="editStatus && hasReturnReceiptDetailFlag"
  164. v-model="form.packagingMethod"
  165. placeholder="请选择"
  166. @change="handleChangePackagingMethod"
  167. >
  168. <el-option
  169. v-for="dict in packagingMethod"
  170. :key="dict.value"
  171. :label="dict.label"
  172. :value="dict.value"
  173. />
  174. </el-select>
  175. <span v-else>{{
  176. selectText(form.packagingMethod, packagingMethod)
  177. }}</span>
  178. </el-form-item>
  179. </el-col>
  180. <el-col :span="6">
  181. <el-form-item label="结算方式" prop="settlementType">
  182. <el-select
  183. v-if="editStatus && hasReturnReceiptDetailFlag"
  184. v-model="form.settlementType"
  185. placeholder="请选择"
  186. >
  187. <el-option
  188. v-for="dict in settlementType"
  189. :key="dict.value"
  190. :label="dict.label"
  191. :value="dict.value"
  192. />
  193. </el-select>
  194. <span v-else>{{
  195. selectText(form.settlementType, settlementType)
  196. }}</span>
  197. </el-form-item>
  198. </el-col>
  199. <el-col :span="6">
  200. <el-form-item label="备注" prop="remark">
  201. <el-input
  202. v-if="editStatus"
  203. v-model.trim="form.remark"
  204. placeholder="请输入备注"
  205. />
  206. <span v-else>{{ form.remark }}</span>
  207. </el-form-item>
  208. </el-col>
  209. <el-col :span="6">
  210. <el-form-item label="总箱数" prop="remark">
  211. <span>{{ totalCarriersNum }}</span>
  212. </el-form-item>
  213. </el-col>
  214. </el-row>
  215. </el-form>
  216. <!-- 渲染数据区 -->
  217. <div class="form-details-btns-container">
  218. <el-button
  219. v-show="editStatus"
  220. type="primary"
  221. icon="Plus"
  222. @click="handleShowDialogProducts"
  223. v-hasPermi="['business:innerOutsource:add']"
  224. >
  225. 添加外协产品明细
  226. </el-button>
  227. <el-button
  228. v-show="editStatus"
  229. type="success"
  230. icon="Check"
  231. :disabled="form.details.length === 0"
  232. @click="handleCheckPackage"
  233. v-hasPermi="['business:innerOutsource:add']"
  234. >
  235. 一键包装签票
  236. </el-button>
  237. </div>
  238. <div class="el-table-container">
  239. <div class="el-table-inner-container">
  240. <el-table
  241. v-loading="loading"
  242. :data="form.details"
  243. size="small"
  244. border
  245. height="100%"
  246. >
  247. <el-table-column
  248. label="行号"
  249. type="index"
  250. align="center"
  251. width="48"
  252. />
  253. <el-table-column
  254. label="批次号"
  255. align="center"
  256. prop="lotCode"
  257. width="104"
  258. />
  259. <el-table-column
  260. label="产品描述"
  261. align="center"
  262. prop="productDescription"
  263. width="300"
  264. />
  265. <el-table-column
  266. label="产品数"
  267. align="center"
  268. width="160"
  269. prop="productNum"
  270. >
  271. <template #default="scope">
  272. <el-input-number
  273. v-if="editStatus && !scope.row.hasNextInfo"
  274. :min="0"
  275. v-model="scope.row.productNum"
  276. placeholder="产品数"
  277. :controls="false"
  278. />
  279. <span v-else>{{ scope.row.productNum }}</span>
  280. </template>
  281. </el-table-column>
  282. <el-table-column
  283. label="箱数"
  284. align="center"
  285. prop="carrierNum"
  286. width="50"
  287. />
  288. <el-table-column
  289. :label="form.packagingMethod === '0' ? '箱号' : '原箱号'"
  290. align="center"
  291. prop="originalCarrier"
  292. width="320"
  293. />
  294. <el-table-column
  295. label="新箱号"
  296. align="center"
  297. prop="newCarrier"
  298. width="320"
  299. >
  300. <template #default="scope">
  301. <el-button
  302. link
  303. type="primary"
  304. icon="Refresh"
  305. v-if="!scope.row.editStatus && editStatus"
  306. @click="handleChangeCarrier(scope.row)"
  307. >换箱</el-button
  308. >
  309. <el-select
  310. v-if="
  311. editStatus &&
  312. scope.row.editStatus &&
  313. !scope.row.hasNextInfo
  314. "
  315. v-model="scope.row.carrierIds"
  316. multiple
  317. filterable
  318. remote
  319. reserve-keyword
  320. placeholder="请选择箱号"
  321. :remote-method="
  322. (arg) =>
  323. remoteCarriers(arg, scope.row.newCarriers, scope.row)
  324. "
  325. :loading="loadingCarrier"
  326. @change="(arg) => handleCarrierChange(arg, scope.row)"
  327. >
  328. <el-option
  329. v-for="item in scope.row.carriers"
  330. :key="item.value"
  331. :label="item.label"
  332. :value="item.value"
  333. />
  334. </el-select>
  335. <span v-if="!editStatus">{{ scope.row.newCarrier }}</span>
  336. </template>
  337. </el-table-column>
  338. <el-table-column
  339. label="外协工序"
  340. align="center"
  341. prop="processNames"
  342. width="320"
  343. >
  344. <template #default="scope">
  345. <el-input
  346. v-if="editStatus && !scope.row.hasNextInfo"
  347. v-model="scope.row.processNames"
  348. readonly
  349. placeholder="请选择工序"
  350. >
  351. <template #append>
  352. <el-button
  353. icon="Search"
  354. @click="handleShowDialogProcesses(scope.row)"
  355. />
  356. </template>
  357. </el-input>
  358. <span v-else>{{ scope.row.processNames }}</span>
  359. </template>
  360. </el-table-column>
  361. <el-table-column label="是否包装签票" align="center" prop="isPackage" >
  362. <template #default="scope">
  363. <el-switch :disabled="!editStatus || scope.row.hasNextInfo" v-model="scope.row.isPackage" style="
  364. --el-switch-on-color: #13ce66;
  365. --el-switch-off-color: #ff4949;
  366. " :active-value="1" :inactive-value="0" active-text="是" inactive-text="否" />
  367. </template>
  368. </el-table-column>
  369. <el-table-column label="备注" align="center" prop="remark">
  370. <template #default="scope">
  371. <el-input
  372. v-if="editStatus && !scope.row.hasNextInfo"
  373. v-model="scope.row.remark"
  374. placeholder="备注"
  375. />
  376. <span v-else>{{ scope.row.remark }}</span>
  377. </template>
  378. </el-table-column>
  379. <el-table-column
  380. v-if="editStatus"
  381. label="操作"
  382. align="center"
  383. class-name="small-padding fixed-width"
  384. width="64"
  385. >
  386. <template #default="scope">
  387. <el-button
  388. circle
  389. type="danger"
  390. v-if="editStatus && !scope.row.hasNextInfo"
  391. icon="Delete"
  392. @click="handleDelete(scope.$index)"
  393. v-hasPermi="['business:outsource:remove']"
  394. />
  395. </template>
  396. </el-table-column>
  397. </el-table>
  398. </div>
  399. </div>
  400. </div>
  401. <!-- 外协商选择 -->
  402. <dialog-suppliers
  403. ref="dialogSuppliersRef"
  404. :single-selected="handleSingleSelectedSupplier"
  405. />
  406. <!-- 产品选择 -->
  407. <dialog-products
  408. ref="dialogProductsRef"
  409. :supplier-id="form.supplierId"
  410. :multiple-selected="handleMultipleSelectedProducts"
  411. />
  412. <!-- 工序选择 -->
  413. <dialog-processes
  414. ref="dialogProcessesRef"
  415. :multiple-selected="handleMultipleSelectedProcesses"
  416. />
  417. <!-- 新箱号选择 -->
  418. <dialog-carrier
  419. ref="dialogCarrierRef"
  420. :multiple-selected="handleMultipleSelectedOutsourceCarriers"
  421. />
  422. <!-- 历史记录弹窗 -->
  423. <dialog-outsourced-records ref="dialogOutsourcedRecordsRef" />
  424. </el-drawer>
  425. </template>
  426. <script setup>
  427. import {
  428. getInnerOrder,
  429. saveOrder,
  430. carrierForOutsource,
  431. submitOrder,
  432. exportOutsource,
  433. printOutsource,
  434. submitInnerDetails,
  435. } from "@/api/business/outsourcedOrder";
  436. import {
  437. listOutsourceDeptList
  438. } from "@/api/business/supplier"
  439. import dialogCarrier from "./DialogCarrier";
  440. import dialogSuppliers from "./DialogSuppliers";
  441. import dialogProducts from "./DialogProducts";
  442. import dialogProcesses from "./DialogProcesses";
  443. import dialogOutsourcedRecords from "./DialogOutsourcedRecords";
  444. // import FormDetailsRecycling from "./detailsRecyclingForm";
  445. const { proxy } = getCurrentInstance();
  446. /** 父组件传参 */
  447. const props = defineProps({
  448. getList: {
  449. type: Function,
  450. default: () => {},
  451. },
  452. deliveryMethod: {
  453. type: Array,
  454. default: [],
  455. },
  456. settlementType: {
  457. type: Array,
  458. default: [],
  459. },
  460. packagingMethod: {
  461. type: Array,
  462. default: [],
  463. },
  464. });
  465. const { getList, deliveryMethod, packagingMethod, settlementType } =
  466. toRefs(props);
  467. /** 字典数组区 */
  468. /** 表单抽屉 页变量 */
  469. const loading = ref(false);
  470. const multiple = ref(true);
  471. const visible = ref(false);
  472. const editStatus = ref(true);
  473. const hasReturnReceiptDetailFlag = ref(true);
  474. const totalCarriersNum = ref(0);
  475. const detailInfo = ref({});
  476. const loadingCarrier = ref(false);
  477. const carriers = ref([]);
  478. const details = ref([]);
  479. const form = ref({});
  480. const outsourceDeptList = ref([])
  481. const deptList = ref([])
  482. // const formatDetails = ref([])
  483. const currentDetail = ref({});
  484. const rules = {
  485. supplierName: [
  486. { required: true, message: "外协商名称不能为空", trigger:"" },
  487. ],
  488. };
  489. /*********************** 方法区 ****************************/
  490. /** 导出按钮操作 */
  491. function handleExport() {
  492. exportOutsource({ id: form.value.id });
  493. }
  494. /** 打印按钮操作 */
  495. function handlePrint() {
  496. printOutsource({ id: form.value.id });
  497. }
  498. /** 打开抽屉 */
  499. function open(row) {
  500. reset();
  501. totalCarriersNum.value = 0;
  502. getOutsorceDeptList()
  503. visible.value = true;
  504. if (row) {
  505. console.log(row);
  506. detailInfo.value = row;
  507. form.value.id = row.id;
  508. getForm();
  509. } else {
  510. editStatus.value = true;
  511. hasReturnReceiptDetailFlag.value = true;
  512. }
  513. }
  514. /** 查询表单信息 */
  515. function getForm() {
  516. loading.value = true;
  517. getInnerOrder({id:form.value.id}).then((response) => {
  518. form.value = response.data;
  519. details.value = proxy.deepClone(response.data.details);
  520. console.log(details.value);
  521. //如果发出单明细里收回单,主表除了备注之外不能编辑
  522. form.value.details.forEach((item) => {
  523. item.hasReturnReceiptDetailFlag = true;
  524. if (
  525. item.returnReceiptDetailList &&
  526. item.returnReceiptDetailList.length > 0
  527. ) {
  528. hasReturnReceiptDetailFlag.value = false;
  529. }
  530. if (
  531. item.returnReceiptDetailList &&
  532. item.returnReceiptDetailList.length > 0 &&
  533. item.returnReceiptDetailList[0].status == 1
  534. ) {
  535. item.hasReturnReceiptDetailFlag = false;
  536. }
  537. });
  538. form.value.details.forEach((item) => {
  539. item.editStatus = false;
  540. if (!form.value.id) {
  541. item.carrierNum = item.originalCarrier.split(",").length;
  542. } else {
  543. if (item.newCarrier != null) {
  544. item.carrierNum = item.newCarrier.split(",").length;
  545. } else {
  546. item.carrierNum = item.originalCarrier.split(",").length;
  547. }
  548. }
  549. totalCarriersNum.value += item.carrierNum;
  550. });
  551. editStatus.value = form.value.isSubmit == 1;
  552. if (!detailInfo.value.flag) {
  553. editStatus.value = false;
  554. console.log(editStatus.value);
  555. }
  556. console.log(hasReturnReceiptDetailFlag.value);
  557. loading.value = false;
  558. });
  559. }
  560. //改变带箱方式
  561. function handleChangePackagingMethod() {
  562. totalCarriersNum.value = 0;
  563. if (!editStatus) {
  564. if (form.value.packagingMethod == 1 && form.value.details.length > 0) {
  565. form.value.details.forEach((item) => {
  566. item.newCarriers = [];
  567. item.carrierIds = [];
  568. item.carriers = carriers.value;
  569. });
  570. }
  571. if (form.value.packagingMethod == 0 && form.value.details.length > 0) {
  572. form.value.details.forEach((item) => {
  573. item.carriers = carriers.value;
  574. item.newCarriers = [];
  575. item.carrierIds = [];
  576. item.newCarriers.push(
  577. ...item.originalCarrierList.map((v) => ({
  578. id: v.carrierId,
  579. code: v.carrierCode,
  580. }))
  581. );
  582. item.carriers.push(
  583. ...item.originalCarrierList.map((v) => ({
  584. value: v.carrierId,
  585. label: v.carrierCode,
  586. }))
  587. );
  588. item.carrierIds = item.originalCarrierList.map((info) => {
  589. return info.carrierId;
  590. });
  591. });
  592. }
  593. } else {
  594. form.value.details.forEach((item) => {
  595. console.log(item.editStatus);
  596. if (item.editStatus) {
  597. item.newCarriers = [];
  598. item.carrierIds = [];
  599. item.carriers = carriers.value;
  600. }
  601. });
  602. }
  603. console.log(form.value.details);
  604. for (let i = 0; i < form.value.details.length; i++) {
  605. if (form.value.packagingMethod == 1) {
  606. form.value.details[i].carrierNum = form.value.details[i].newCarriers
  607. ? form.value.details[i].newCarriers.length
  608. : 0;
  609. } else {
  610. form.value.details[i].carrierNum =
  611. form.value.details[i].newCarriers &&
  612. form.value.details[i].newCarriers.length > 0
  613. ? form.value.details[i].newCarriers.length
  614. : form.value.details[i].originalCarrier.split(",").length;
  615. }
  616. console.log(form.value.details);
  617. totalCarriersNum.value += form.value.details[i].carrierNum;
  618. }
  619. }
  620. //改变送货方式
  621. function handleChangeDeliveryMethod() {
  622. if (form.value.deliveryMethod == 1) {
  623. form.value.freightAmount = form.value.freightPrice * totalCarriersNum.value;
  624. } else {
  625. form.value.freightAmount = 0.0;
  626. }
  627. }
  628. //外协工段
  629. function getOutsorceDeptList() {
  630. listOutsourceDeptList({}).then((response) => {
  631. if(response.data && response.data.length > 0) {
  632. deptList.value = response.data
  633. outsourceDeptList.value = response.data.map(item => {
  634. return {
  635. value: item.outsourceDeptId,
  636. label: item.outsourceDeptName
  637. }
  638. })
  639. }
  640. form.value.outsourceDeptList = response.data;
  641. });
  642. }
  643. //外协工段选择事件
  644. function handleChangeDept(){
  645. let data = deptList.value.filter(item => item.outsourceDeptId == form.value.outsourceDeptId)[0]
  646. form.value.isInnerOutsource = 1
  647. form.value.outsourceDeptName = data.outsourceDeptName
  648. form.value.supplierName = data.supplierName
  649. form.value.supplierId = data.id;
  650. form.value.lossLimit = data.lossLimit;
  651. form.value.supplierName = data.name;
  652. form.value.supplierCode = data.mnemonicCode;
  653. form.value.deliveryMethod = data.deliveryMethod;
  654. form.value.freightPrice = data.freightPrice;
  655. form.value.settlementType = data.settlementType;
  656. }
  657. //一键包装签票
  658. function handleCheckPackage(){
  659. form.value.details.forEach((item) => {
  660. if(!item.hasNextInfo){
  661. item.isPackage = 1
  662. }
  663. })
  664. }
  665. //打开历史记录弹窗
  666. function handleViewRecords() {
  667. proxy.$refs.dialogOutsourcedRecordsRef.open(form.value.id);
  668. }
  669. function selectText(value, data) {
  670. if (value) {
  671. return data.filter((item) => item.value == value)[0].label;
  672. }
  673. }
  674. /** 取消按钮 */
  675. function cancel() {
  676. visible.value = false;
  677. // reset();
  678. }
  679. const handleDelete = (index) => {
  680. totalCarriersNum.value -= form.value.details[index].carrierNum;
  681. if (form.value.deliveryMethod == 1) {
  682. form.value.freightAmount = form.value.freightPrice * totalCarriersNum.value;
  683. } else {
  684. form.value.freightAmount = 0.0;
  685. }
  686. form.value.details.splice(index, 1);
  687. };
  688. /** 表单重置 */
  689. function reset() {
  690. // console.log(proxy.parseTime(new Date(), "{y}-{m}-{d}"))
  691. form.value = {
  692. id: null,
  693. tenantId: null,
  694. formCode: null,
  695. formDate: proxy.parseTime(new Date(), "{y}-{m}-{d}"),
  696. supplierId: "0",
  697. supplierName: "",
  698. deliveryMethod: "0",
  699. freightPrice: 0.0,
  700. freightAmount: 0.0,
  701. packagingMethod: "0",
  702. remark: null,
  703. details: [],
  704. isSubmit: 0,
  705. };
  706. proxy.resetForm("formRef");
  707. }
  708. /** 保存 */
  709. function saveFrom() {
  710. if (!form.value.details || form.value.details.length == 0) {
  711. proxy.$modal.msgError("请添加产品明细");
  712. return;
  713. }
  714. proxy.$refs["formRef"].validate((valid) => {
  715. for (const item of form.value.details) {
  716. if (!item.processNames) {
  717. proxy.$modal.msgError("请选择" + item.lotCode + "批次的工序");
  718. return;
  719. }
  720. }
  721. if (form.value.packagingMethod == 1) {
  722. console.log("form.value.details", form.value.details);
  723. for (const item of form.value.details) {
  724. if (item.newCarriers.length == 0) {
  725. proxy.$modal.msgError("请选择" + item.lotCode + "批次的新箱号");
  726. return;
  727. }
  728. }
  729. }
  730. if (valid) {
  731. saveOrder(form.value).then((response) => {
  732. if (response.code == 200) {
  733. proxy.$modal.msgSuccess("保存成功");
  734. visible.value = false;
  735. getList.value();
  736. }
  737. });
  738. }
  739. });
  740. }
  741. /** 保存并提交 */
  742. function submitFrom() {
  743. console.log("from", form.value);
  744. proxy.$modal
  745. .confirm("是否确定提交,提交后不可修改,删除")
  746. .then(function () {
  747. return;
  748. })
  749. .then(() => {
  750. if (!form.value.details || form.value.details.length == 0) {
  751. proxy.$modal.msgError("请添加产品明细");
  752. return;
  753. }
  754. proxy.$refs["formRef"].validate((valid) => {
  755. for (const item of form.value.details) {
  756. if (!item.processNames) {
  757. proxy.$modal.msgError("请选择" + item.lotCode + "批次的工序");
  758. return;
  759. }
  760. }
  761. if (form.value.packagingMethod == 1) {
  762. console.log("form.value.details", form.value.details);
  763. for (const item of form.value.details) {
  764. if (item.newCarriers.length == 0) {
  765. proxy.$modal.msgError("请选择" + item.lotCode + "批次的新箱号");
  766. return;
  767. }
  768. }
  769. }
  770. if (valid) {
  771. console.log(form.value);
  772. submitOrder(form.value).then((response) => {
  773. proxy.$modal.msgSuccess("提交成功");
  774. visible.value = false;
  775. getList.value();
  776. });
  777. }
  778. });
  779. })
  780. .catch(() => {});
  781. }
  782. //5.29保存
  783. function handleSubmit() {
  784. if (form.value.isSubmit == 0) {
  785. proxy.$modal
  786. .confirm("是否确定保存,保存后外协商不可编辑!")
  787. .then(function () {
  788. return;
  789. })
  790. .then(() => {
  791. if (!form.value.details || form.value.details.length == 0) {
  792. proxy.$modal.msgError("请添加产品明细");
  793. return;
  794. }
  795. if (form.value.supplierName == "") {
  796. proxy.$modal.msgError("外协商名称不能为空");
  797. return;
  798. }
  799. proxy.$refs["formRef"].validate((valid) => {
  800. for (const item of form.value.details) {
  801. if (!item.processNames) {
  802. proxy.$modal.msgError("请选择" + item.lotCode + "批次的工序");
  803. return;
  804. }
  805. }
  806. if (form.value.packagingMethod == 1) {
  807. console.log("form.value.details", form.value.details);
  808. for (const item of form.value.details) {
  809. if (item.newCarriers.length == 0) {
  810. proxy.$modal.msgError("请选择" + item.lotCode + "批次的新箱号");
  811. return;
  812. }
  813. }
  814. }
  815. if (valid) {
  816. console.log(form.value);
  817. submitInnerDetails(form.value).then((response) => {
  818. proxy.$modal.msgSuccess("提交成功");
  819. visible.value = false;
  820. getList.value();
  821. });
  822. }
  823. });
  824. });
  825. } else {
  826. if (!form.value.details || form.value.details.length == 0) {
  827. proxy.$modal.msgError("请添加产品明细");
  828. return;
  829. }
  830. proxy.$refs["formRef"].validate((valid) => {
  831. for (const item of form.value.details) {
  832. if (!item.processNames) {
  833. proxy.$modal.msgError("请选择" + item.lotCode + "批次的工序");
  834. return;
  835. }
  836. }
  837. if (form.value.packagingMethod == 1) {
  838. console.log("form.value.details", form.value.details);
  839. for (const item of form.value.details) {
  840. if (item.newCarriers.length == 0) {
  841. proxy.$modal.msgError("请选择" + item.lotCode + "批次的新箱号");
  842. return;
  843. }
  844. }
  845. }
  846. if (valid) {
  847. console.log(form.value);
  848. submitInnerDetails(form.value).then((response) => {
  849. proxy.$modal.msgSuccess("提交成功");
  850. visible.value = false;
  851. getList.value();
  852. });
  853. }
  854. });
  855. }
  856. }
  857. /***************************** 外协商对话框相关 *****************************/
  858. // 打开外协商选择对话框
  859. const handleShowDialogSuppliers = () => {
  860. proxy.$refs.dialogSuppliersRef.open();
  861. };
  862. // 外协商选择带回
  863. const handleSingleSelectedSupplier = (data) => {
  864. console.log(data);
  865. form.value.supplierId = data.id;
  866. form.value.lossLimit = data.lossLimit;
  867. form.value.supplierName = data.name;
  868. form.value.supplierCode = data.mnemonicCode;
  869. form.value.deliveryMethod = data.deliveryMethod;
  870. form.value.freightPrice = data.freightPrice;
  871. form.value.settlementType = data.settlementType;
  872. if (form.value.deliveryMethod == 1) {
  873. form.value.freightAmount = form.value.freightPrice * totalCarriersNum.value;
  874. } else {
  875. form.value.freightAmount = 0.0;
  876. }
  877. };
  878. /***************************** 外协收回明细相关 *****************************/
  879. //打开收回明细表单
  880. function handleDetailsRecycling() {
  881. proxy.$refs.formDetailsRecyclingRef.open(row);
  882. }
  883. function handleSingleSelectedRecycling() {}
  884. /***************************** 产品对话框相关 *****************************/
  885. // 打开产品选择对话框
  886. const handleShowDialogProducts = () => {
  887. const dayworkIds = form.value.details.map((item) => item.dayworkId);
  888. // console.log(dayworkIds);
  889. proxy.$refs.dialogProductsRef.open(dayworkIds);
  890. };
  891. // 产品选择带回
  892. const handleMultipleSelectedProducts = (selection) => {
  893. selection.forEach((item) => {
  894. const newDetail = {
  895. lotId: item.lotId,
  896. lotCode: item.lotCode,
  897. dayworkId: item.id,
  898. productId: item.productId,
  899. productDescription: item.productDescription,
  900. technologicalProcessId: item.technologicalProcessId,
  901. technologicalProcessDetailId: item.lastDayworkItem.technologicalProcessDetailId,
  902. productionPlanDetailId: item.lastDayworkItem.productionPlanDetailId,
  903. processId: item.lastDayworkItem.processId,
  904. processAlias:item.lastDayworkItem.processAlias,
  905. dayworkItemId: item.lastDayworkItem.id,
  906. technologyVersion: item.technologyVersion,
  907. productionPlanDetailId: item.productionPlanDetailId,
  908. productionPlanNo: item.productionPlanNo,
  909. lineNumber:item.lineNumber,
  910. originalCarrier: item.originalCarrier,
  911. originalCarrierCount: item.originalCarrier.split(",").length,
  912. carrierNum: item.originalCarrier.split(",").length,
  913. originalCarrierList: item.originalCarrierList,
  914. productNum: item.productNum,
  915. productCode: item.productCode,
  916. newCarrier: "",
  917. carriers: [],
  918. newCarrierCount: 0,
  919. newCarriers: [],
  920. processNames: "",
  921. remark: item.remark,
  922. processes: [],
  923. hasReturnReceiptDetailFlag: true,
  924. };
  925. form.value.details.push(newDetail);
  926. console.log(newDetail);
  927. totalCarriersNum.value += newDetail.originalCarrierCount;
  928. if (form.value.deliveryMethod == 1) {
  929. form.value.freightAmount =
  930. form.value.freightPrice * totalCarriersNum.value;
  931. } else {
  932. form.value.freightAmount = 0.0;
  933. }
  934. // console.log("form.value.details", form.value.details);
  935. });
  936. };
  937. /***************************** 外协箱子对话框相关 *****************************/
  938. // 打开外协箱子选择对话框
  939. const handleShowDialogOutsourceCarriers = (row) => {};
  940. function remoteCarriers(code, newCarrier, row) {
  941. loadingCarrier.value = true;
  942. // console.log(row, carriers.value)
  943. console.log("row", row);
  944. // if (true) {
  945. // carriers.value = [{ value: '"1747500987856662535"', label: '000319' }]
  946. // return
  947. // }
  948. let categoryId;
  949. if (form.value.packagingMethod == 1) {
  950. categoryId = "1783783697558847489";
  951. } else {
  952. categoryId = "2";
  953. }
  954. if (code == "") {
  955. return;
  956. }
  957. carrierForOutsource({
  958. categoryId: categoryId,
  959. code: code,
  960. dayworkId: row.dayworkId,
  961. }).then((res) => {
  962. if (res.code === 200) {
  963. carriers.value = res.rows.map((v) => ({ value: v.id, label: v.code }));
  964. row.carriers = res.rows.map((v) => ({ value: v.id, label: v.code }));
  965. if (Array.isArray(newCarrier)) {
  966. // 安全地更新 carriers
  967. row.carriers.push(
  968. ...newCarrier
  969. .filter((v) => !row.carriers.map((e) => e.value).includes(v.id))
  970. .map((v) => ({ value: v.id, label: v.code }))
  971. );
  972. }
  973. } else {
  974. row.carriers = [];
  975. row.carriers.push(...newCarrier);
  976. }
  977. loadingCarrier.value = false;
  978. });
  979. }
  980. //换箱
  981. function handleChangeCarrier(row) {
  982. console.log(row);
  983. if (editStatus.value && !form.value.id) {
  984. if (form.value.packagingMethod == 0) {
  985. row.newCarriers.push(
  986. ...row.originalCarrierList.map((v) => ({
  987. id: v.carrierId,
  988. code: v.carrierCode,
  989. }))
  990. );
  991. row.carriers.push(
  992. ...row.originalCarrierList.map((v) => ({
  993. value: v.carrierId,
  994. label: v.carrierCode,
  995. }))
  996. );
  997. row.carrierIds = row.originalCarrierList.map((info) => {
  998. return info.carrierId;
  999. });
  1000. } else {
  1001. row.newCarriers = null;
  1002. }
  1003. }
  1004. if (editStatus.value && form.value.id) {
  1005. row.carriers = [];
  1006. row.newCarriers.map((v) => ({ id: v.value, code: v.label }));
  1007. console.log(row.newCarriers);
  1008. row.carriers = row.newCarriers.map((v) => ({ value: v.id, label: v.code }));
  1009. row.carrierIds = row.newCarriers.map((info) => {
  1010. return info.id;
  1011. });
  1012. console.log(row);
  1013. }
  1014. row.editStatus = true;
  1015. }
  1016. function handleCarrierChange(arg, item) {
  1017. totalCarriersNum.value = 0;
  1018. item.newCarriers = item.carriers
  1019. .filter((v) => arg.includes(v.value))
  1020. .map((v) => ({ id: v.value, code: v.label }));
  1021. console.log(item.newCarriers);
  1022. item.carrierNum = item.newCarriers.length;
  1023. for (let i = 0; i < form.value.details.length; i++) {
  1024. if (form.value.packagingMethod == 1) {
  1025. form.value.details[i].carrierNum = form.value.details[i].newCarriers
  1026. ? form.value.details[i].newCarriers.length
  1027. : 0;
  1028. } else {
  1029. //原厂蓝箱
  1030. form.value.details[i].carrierNum = form.value.details[i].newCarriers
  1031. ? form.value.details[i].newCarriers.length
  1032. : form.value.details[i].originalCarrier.split(",").length;
  1033. }
  1034. console.log(form.value.details);
  1035. totalCarriersNum.value += form.value.details[i].carrierNum;
  1036. }
  1037. if (form.value.deliveryMethod == 1) {
  1038. form.value.freightAmount = form.value.freightPrice * totalCarriersNum.value;
  1039. } else {
  1040. form.value.freightAmount = 0.0;
  1041. }
  1042. }
  1043. /** 使用新方式 */
  1044. // const handleShowDialogOutsourceCarriers = (row) => {
  1045. // // 确保 form.details 存在且不是 undefined
  1046. // let allNewCarriers;
  1047. // if (form.value && form.value.details && Array.isArray(form.value.details)) {
  1048. // allNewCarriers = form.value.details
  1049. // .flatMap((detail) =>
  1050. // detail.newCarriers ? detail.newCarriers.filter((item) => item) : []
  1051. // )
  1052. // .filter(Boolean);
  1053. // // 现在 allNewCarriers 包含了所有非空的 newCarriers 数组的元素
  1054. // }
  1055. // // form.value.details.newCarriers
  1056. // // const allNewCarriers = form.details.flatMap((detail) => detail.newCarriers);
  1057. // console.log("allNewCarriers", allNewCarriers);
  1058. // proxy.$refs.dialogCarrierRef.open(row.lotId, from.value.deliveryMethod);
  1059. // };
  1060. // 箱子选择带回
  1061. const handleMultipleSelectedOutsourceCarriers = (selection, lotId) => {
  1062. const carrierNames = selection.map((item) => item.code);
  1063. let carrierNamesString = carrierNames.join(",");
  1064. form.value.details.map((item) => {
  1065. if (item.lotId == lotId) {
  1066. item.newCarrier = carrierNamesString;
  1067. item.newCarrierCount = selection.length;
  1068. item.newCarriers = selection;
  1069. }
  1070. });
  1071. };
  1072. /***************************** 外协工序对话框相关 *****************************/
  1073. // 打开外协工序选择对话框
  1074. const handleShowDialogProcesses = (row) => {
  1075. currentDetail.value = row;
  1076. proxy.$refs.dialogProcessesRef.open(row);
  1077. };
  1078. // 工序选择带回
  1079. const handleMultipleSelectedProcesses = (selection) => {
  1080. let currentOriginal = details.value.filter(
  1081. (item) => (item.id = currentDetail.value.id)
  1082. );
  1083. let flag = true;
  1084. if (
  1085. currentDetail.value.returnReceiptDetailList &&
  1086. currentDetail.value.returnReceiptDetailList.length > 0
  1087. ) {
  1088. selection.forEach((item) => {
  1089. if (
  1090. currentOriginal[0].processes.findIndex(
  1091. (info) => info.processStepNumber == item.processStepNumber
  1092. ) < 0
  1093. ) {
  1094. flag = false;
  1095. }
  1096. });
  1097. }
  1098. if (flag) {
  1099. const processNames = selection
  1100. .sort((a, b) => a.processStepNumber - b.processStepNumber)
  1101. .map((item) => item.processAlias);
  1102. // 使用join方法将数组转换为以逗号分隔的字符串
  1103. let commaSeparatedString = processNames.join(",");
  1104. currentDetail.value.processes = [];
  1105. currentDetail.value.processNames = commaSeparatedString;
  1106. selection.forEach((item) => {
  1107. const newProcess = {
  1108. processId: item.processId,
  1109. processCode: item.processCode,
  1110. processAlias: item.processAlias,
  1111. processStepNumber: item.processStepNumber,
  1112. technologicalProcessDetailId: item.id,
  1113. };
  1114. currentDetail.value.processes.push(newProcess);
  1115. });
  1116. } else {
  1117. proxy.$modal.msgError("外协厂/德迈仕已收回,不可添加新工序");
  1118. }
  1119. };
  1120. /** 暴露给父组件的方法 */
  1121. defineExpose({
  1122. open,
  1123. });
  1124. </script>