form.vue 29 KB

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