form.vue 32 KB

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