formOld.vue 29 KB

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