index.vue 62 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990
  1. <template>
  2. <!-- :close-on-click-modal="false" -->
  3. <ele-modal
  4. width="80vw"
  5. :visible.sync="visible"
  6. custom-class="ele-dialog-form"
  7. :before-close="cancel"
  8. :title="title"
  9. :maxable="true"
  10. >
  11. <div class="form-wrapper">
  12. <el-form
  13. ref="form"
  14. :model="form"
  15. :rules="rules"
  16. label-width="110px"
  17. class="formbox"
  18. >
  19. <headerTitle title="基本信息"> </headerTitle>
  20. <el-row :gutter="10">
  21. <el-col :span="6">
  22. <el-form-item label="计划编号:" prop="code">
  23. <el-input
  24. placeholder="计划编号"
  25. size="mini"
  26. disabled
  27. v-model="form.code"
  28. ></el-input>
  29. </el-form-item>
  30. </el-col>
  31. <el-col :span="6">
  32. <el-form-item label="计划类型:" prop="planType">
  33. <el-select
  34. v-model="form.planType"
  35. style="width: 100%"
  36. @change="changeProduceType"
  37. size="mini"
  38. >
  39. <el-option
  40. v-for="item of planTypeList"
  41. :key="item.value"
  42. :label="item.label"
  43. :value="item.value"
  44. ></el-option>
  45. </el-select>
  46. </el-form-item>
  47. </el-col>
  48. <el-col :span="6">
  49. <el-form-item label="批次号:" prop="batchNo">
  50. <el-input
  51. placeholder="输入批次号"
  52. size="mini"
  53. v-model="form.batchNo"
  54. ></el-input>
  55. </el-form-item>
  56. </el-col>
  57. <el-col :span="6">
  58. <el-form-item label="客户名称:">
  59. <el-input
  60. clearable
  61. v-model="form.customerName"
  62. style="width: calc(100% - 80px)"
  63. />
  64. <contactDialog
  65. style="margin-left: 3px"
  66. @changeParent="contactDialogSuccess"
  67. ></contactDialog>
  68. </el-form-item>
  69. </el-col>
  70. </el-row>
  71. <el-row :gutter="24">
  72. <el-col :span="6" v-if="isSaleOrder">
  73. <el-form-item label="销售订单号:" prop="saleOrder">
  74. <div class="sale-order-select">
  75. <el-input
  76. v-model="form.saleOrder"
  77. size="mini"
  78. type="text"
  79. style="width: calc(100% - 54px)"
  80. placeholder="请选择销售订单号"
  81. readonly
  82. ></el-input>
  83. <el-button
  84. size="mini"
  85. type="primary"
  86. @click="openSaleOrderDialog"
  87. >
  88. 选择
  89. </el-button>
  90. </div>
  91. </el-form-item>
  92. </el-col>
  93. <el-col :span="6">
  94. <el-form-item
  95. label="生产编号:"
  96. label-width="110px"
  97. prop="productionCodes"
  98. >
  99. <el-input
  100. v-model="form.productionCodes"
  101. size="mini"
  102. type="text"
  103. style="width: 100%"
  104. placeholder=" "
  105. ></el-input>
  106. </el-form-item>
  107. </el-col>
  108. <el-col :span="6">
  109. <el-form-item
  110. label="计划开始日期:"
  111. label-width="110px"
  112. prop="startTime"
  113. >
  114. <el-date-picker
  115. style="width: 100%"
  116. size="mini"
  117. v-model="form.startTime"
  118. @change="handleStartTimeChange(form)"
  119. type="datetime"
  120. placeholder="选择日期"
  121. value-format="yyyy-MM-dd HH:mm:ss"
  122. >
  123. </el-date-picker>
  124. </el-form-item>
  125. </el-col>
  126. <el-col :span="6">
  127. <el-form-item
  128. label="计划结束日期:"
  129. label-width="110px"
  130. prop="endTime"
  131. >
  132. <el-date-picker
  133. style="width: 100%"
  134. size="mini"
  135. v-model="form.endTime"
  136. @change="handleEndTimeChange(form)"
  137. type="datetime"
  138. placeholder="选择日期"
  139. value-format="yyyy-MM-dd HH:mm:ss"
  140. >
  141. </el-date-picker>
  142. </el-form-item>
  143. </el-col>
  144. <el-col :span="6">
  145. <el-form-item
  146. label="要求完成日期:"
  147. label-width="110px"
  148. prop="reqMoldTime"
  149. >
  150. <el-date-picker
  151. style="width: 100%"
  152. size="mini"
  153. v-model="form.reqMoldTime"
  154. type="datetime"
  155. placeholder="选择日期"
  156. value-format="yyyy-MM-dd HH:mm:ss"
  157. >
  158. </el-date-picker>
  159. </el-form-item>
  160. </el-col>
  161. </el-row>
  162. <!-- <el-row :gutter="24">
  163. <el-col :span="6">
  164. <el-form-item
  165. label="要求完成日期:"
  166. label-width="110px"
  167. prop="reqMoldTime"
  168. >
  169. <el-date-picker
  170. style="width: 100%"
  171. size="mini"
  172. v-model="form.reqMoldTime"
  173. type="datetime"
  174. placeholder="选择日期"
  175. value-format="yyyy-MM-dd HH:mm:ss"
  176. >
  177. </el-date-picker>
  178. </el-form-item>
  179. </el-col>
  180. </el-row> -->
  181. <headerTitle title="产品信息"> </headerTitle>
  182. <el-row :gutter="24">
  183. <ele-pro-table
  184. ref="tableRef"
  185. :columns="columns"
  186. row-key="code"
  187. :cache-key="cacheKeyUrl"
  188. :datasource="form.productInfoList"
  189. border
  190. height="40vh"
  191. key="id"
  192. @columns-change="handleColumnChange"
  193. >
  194. <template v-slot:modelKey="{ row, $index }">
  195. <el-select
  196. clearable
  197. v-model="row.modelKey"
  198. filterable
  199. allow-create
  200. default-first-option
  201. >
  202. <el-option
  203. v-for="item in row.modelList"
  204. :key="item"
  205. :value="item"
  206. :label="item"
  207. >
  208. </el-option>
  209. </el-select>
  210. </template>
  211. <template v-slot:colorKey="{ row, $index }">
  212. <el-select
  213. clearable
  214. v-model="row.colorKey"
  215. filterable
  216. allow-create
  217. default-first-option
  218. >
  219. <el-option
  220. v-for="item in row.colorList"
  221. :key="item"
  222. :value="item"
  223. :label="item"
  224. >
  225. </el-option>
  226. </el-select>
  227. </template>
  228. <template v-slot:requiredFormingNum="{ row, $index }">
  229. <el-input
  230. v-model="row.requiredFormingNum"
  231. size="small"
  232. type="text"
  233. style="width: 100%"
  234. placeholder="输入要求生产数量"
  235. @input="(e) => handleQuantityInput(e, row)"
  236. ></el-input>
  237. <!-- placeholder="输入要求生产数量" @input="tableHandleKeyUp(row, 'sum')"></el-input> -->
  238. </template>
  239. <!-- <template v-slot:productionCodes="{ row, $index }">
  240. <el-input
  241. v-model="row.productionCodes"
  242. size="small"
  243. type="text"
  244. style="width: 100%"
  245. placeholder=" "
  246. ></el-input>
  247. </template> -->
  248. <template v-slot:productType="{ row, $index }">
  249. <el-select
  250. v-model="row.productType"
  251. @change="changeProductType(row, $index)"
  252. :key="$index"
  253. >
  254. <el-option
  255. v-for="item of row.producedList"
  256. :key="$index + item.code"
  257. :label="item.name"
  258. :value="item.code"
  259. ></el-option>
  260. </el-select>
  261. </template>
  262. <template v-slot:bomCategoryId="{ row, $index }">
  263. <el-select v-model="row.bomCategoryId">
  264. <el-option
  265. v-for="item of row.bomVersionList"
  266. :key="item.id"
  267. :label="item.name + '(V' + item.versions + '.0)'"
  268. :value="item.id"
  269. @click.native="changeBomId(row, $index, item)"
  270. ></el-option>
  271. </el-select>
  272. </template>
  273. <!-- //权重等级 -->
  274. <template
  275. v-slot:weight="{ row, $index }"
  276. v-if="clientEnvironmentId == 4"
  277. >
  278. <el-select
  279. v-model="row.weight"
  280. style="width: 100%"
  281. @change="changeProduceType"
  282. size="mini"
  283. >
  284. <el-option
  285. v-for="item of weightList"
  286. :key="item.code"
  287. :label="item.name"
  288. :value="item.code"
  289. ></el-option>
  290. </el-select>
  291. </template>
  292. <!-- 是否开槽 -->
  293. <template
  294. v-slot:isSlotting="{ row, $index }"
  295. v-if="clientEnvironmentId == 4"
  296. >
  297. <el-select
  298. v-model="row.isSlotting"
  299. style="width: 100%"
  300. @change="changeProduceType"
  301. size="mini"
  302. >
  303. <el-option
  304. v-for="item of isSlotting"
  305. :key="item.code"
  306. :label="item.name"
  307. :value="item.code"
  308. ></el-option>
  309. </el-select>
  310. </template>
  311. <!-- 开槽类型 -->
  312. <template
  313. v-slot:slottingType="{ row, $index }"
  314. v-if="clientEnvironmentId == 4"
  315. >
  316. <DictSelection
  317. dictName="开槽类型"
  318. v-model="row.slottingType"
  319. size="mini"
  320. >
  321. </DictSelection>
  322. </template>
  323. <!-- 工艺路线 -->
  324. <template
  325. v-slot:produceRoutingId="{ row, $index }"
  326. v-if="clientEnvironmentId != 4"
  327. >
  328. <!-- <el-form-item required> -->
  329. <div style="display: flex">
  330. <el-select
  331. v-model="row.produceRoutingId"
  332. v-show="isRouteSelect(row)"
  333. >
  334. <el-option
  335. v-for="item of row.routingList"
  336. :key="item.id"
  337. :label="item.name"
  338. :value="item.id"
  339. ></el-option>
  340. </el-select>
  341. <div style="display: flex">
  342. <el-input
  343. v-show="!isRouteSelect(row)"
  344. disabled
  345. v-model="row.produceRoutingName"
  346. ></el-input>
  347. <el-button
  348. v-show="isSelectShow"
  349. type="primary"
  350. size="mini"
  351. @click="openDialog($index)"
  352. >选择</el-button
  353. >
  354. </div>
  355. </div>
  356. <!-- </el-form-item> -->
  357. </template>
  358. <template v-slot:produceRoutingId="{ row, $index }" v-else>
  359. <el-input
  360. v-model="row.produceRoutingName"
  361. style="width: 100%"
  362. readonly
  363. ></el-input>
  364. </template>
  365. <template v-slot:factoriesId="{ row, $index }">
  366. <el-select
  367. v-if="!factoriesId"
  368. v-model="row.factoriesId"
  369. :key="row.factoriesId"
  370. @change="(e) => selectFactory(e, row)"
  371. >
  372. <el-option
  373. v-for="item of factoryList"
  374. :key="item.id"
  375. :label="item.name"
  376. :value="item.id"
  377. ></el-option>
  378. </el-select>
  379. <el-input
  380. v-else
  381. :value="factoryLabel(row)"
  382. style="width: 100%"
  383. disabled
  384. ></el-input>
  385. </template>
  386. <!-- <el-table-column label="所属工厂" width="140" align="center" prop="factoriesId">
  387. <template slot-scope="scope">
  388. <el-form-item label-width="0px">
  389. <el-select v-model="scope.row.factoriesId" :key="scope.row.factoriesId">
  390. <el-option v-for="item of factoryList" :key="item.id" :label="item.name"
  391. :value="item.id"></el-option>
  392. </el-select>
  393. </el-form-item>
  394. </template>
  395. </el-table-column> -->
  396. <!-- 模具数量 -->
  397. <template
  398. v-slot:moCount="{ row, $index }"
  399. v-if="clientEnvironmentId == '4'"
  400. >
  401. <div>
  402. <el-input
  403. style="width: 100%"
  404. size="small"
  405. v-model="row.moCount"
  406. oninput="value=value.replace(/[^0-9.]/g,'')"
  407. @input="tableHandleKeyUp(row, 'moCount')"
  408. placeholder="请输入"
  409. >
  410. </el-input>
  411. </div>
  412. </template>
  413. <!-- 块数 -->
  414. <template
  415. v-slot:blockCount="{ row, $index }"
  416. v-if="clientEnvironmentId == '4'"
  417. >
  418. <div>
  419. <el-input
  420. size="small"
  421. style="width: 100%"
  422. @input="tableHandleKeyUp(row, 'blockCount')"
  423. v-model="row.blockCount"
  424. placeholder="请输入"
  425. ></el-input>
  426. </div>
  427. </template>
  428. <!-- <template v-slot:productWeight="{ row, $index }">
  429. <span>{{ row.productWeight ? row.productWeight : '-' }}</span>
  430. </template> -->
  431. <template v-slot:set="{ row, $index }">
  432. <el-button type="text" @click="handleDeleteItem($index)"
  433. >删除</el-button
  434. >
  435. </template>
  436. <template v-slot:headerProduceRoutingId="{ column }">
  437. <div class="header_required"
  438. ><span class="is-required">{{ column.label }}</span></div
  439. >
  440. </template>
  441. <template v-slot:headeRequiredFormingNum="{ column }">
  442. <div class="header_required"
  443. ><span class="is-required">{{ column.label }}</span></div
  444. >
  445. </template>
  446. <template v-slot:headerProcessingBOM="{ column }">
  447. <div :class="isRequired ? 'header_required' : ''"
  448. ><span class="is-required">{{ column.label }}</span></div
  449. >
  450. </template>
  451. </ele-pro-table>
  452. <div class="add-product" @click="addEquipment" v-if="!form.id">
  453. <i class="el-icon-circle-plus-outline"></i>
  454. </div>
  455. </el-row>
  456. </el-form>
  457. <!-- 选择产品 -->
  458. <EquipmentDialog
  459. @choose="confirmChoose"
  460. :treeType="['9']"
  461. :selectList="[]"
  462. ref="equipmentRefs"
  463. >
  464. </EquipmentDialog>
  465. <saleOrderPop
  466. ref="saleOrderRef"
  467. :isMultiple="false"
  468. @chooseOrder="chooseSaleOrder"
  469. />
  470. </div>
  471. <template v-slot:footer>
  472. <el-button @click="cancel">取消</el-button>
  473. <el-button type="primary" @click="save" :loading="loading">
  474. 确定
  475. </el-button>
  476. <el-button
  477. type="primary"
  478. @click="save('sub')"
  479. :loading="loading"
  480. v-if="!isReview"
  481. >
  482. 发布
  483. </el-button>
  484. </template>
  485. <ProcessRoute ref="processRouteRef" @changeParent="changeParent" />
  486. </ele-modal>
  487. </template>
  488. <script>
  489. import { findBomCategoryByCategoryId } from '@/api/productionPlan/index';
  490. import EquipmentDialog from '@/views/saleOrder/components/EquipmentDialog';
  491. import saleOrderPop from './components/saleOrderPop.vue';
  492. import { getCode } from '@/api/codeManagement';
  493. import ProcessRoute from '@/components/selectionDialog/processRoute.vue';
  494. import { parameterGetByCode } from '@/api/mainData/index';
  495. import {
  496. bomRoutingList,
  497. bomListByPlan,
  498. getFactoryList,
  499. saveAndRelease,
  500. temporaryPlanSave,
  501. getUpdateInfoByCode,
  502. getColorModelInfoById
  503. } from '@/api/saleOrder';
  504. import { planIsReview } from '@/api/productionPlan/index';
  505. import contactDialog from '@/components/contactDialog/openContactDialog.vue';
  506. import { deepClone } from '@/utils';
  507. import tableColumnsMixin from '@/mixins/tableColumnsMixin';
  508. export default {
  509. components: {
  510. EquipmentDialog,
  511. saleOrderPop,
  512. ProcessRoute,
  513. contactDialog
  514. },
  515. mixins: [tableColumnsMixin],
  516. props: {
  517. factoryType: {
  518. type: Number,
  519. default: 3
  520. },
  521. factoryObj: {
  522. type: Object,
  523. default: () => {}
  524. },
  525. isAdd: {
  526. type: Boolean,
  527. default: true
  528. }
  529. },
  530. watch: {
  531. // factoryObj: {
  532. // immediate: true,
  533. // deep: true,
  534. // handler(val) {
  535. // // 修改
  536. // // this.$nextTick(() => {
  537. // // if (val.id) {
  538. // // this.bomListVersion();
  539. // // if (val.bomCategoryId) {
  540. // // this.getPlanRouting();
  541. // // }
  542. // // }
  543. // // });
  544. // }
  545. // }
  546. },
  547. computed: {
  548. // 是否必填 字段 ( 首先看计划类型 如果是返工返修)
  549. // 就不是必填 否则就看配置参数
  550. // 必填的时候 不显示选择按钮 跟 展示输入框 只能有下拉选择框 ( 选择了生产类型 带出 BOM 版本 带出 工艺路线 工艺路线不能选择)
  551. // 不必填的时候 显示 选择按钮跟 展示输入框 并且可以存在选择框 一开始默认展示选择框
  552. // 选择按钮选择数据后 隐藏选择框 显示展示框(input) 情况 生产类型 跟 BOM版本
  553. // 选择了生产类型 清空 选择框选择的工艺路线
  554. // 是否必填字段
  555. isRequired() {
  556. if (this.form.planType == 5) {
  557. return false;
  558. }
  559. return this.processingRequired == 1;
  560. },
  561. // 工艺路线 输入框展示跟选择框判断
  562. isRouteSelect() {
  563. return (row) => {
  564. if (this.isRequired) {
  565. return true;
  566. }
  567. if (!row.selectionRowShow) {
  568. return true;
  569. }
  570. return false;
  571. };
  572. },
  573. // 选择按钮的显示
  574. isSelectShow() {
  575. if (this.form.planType == 5) {
  576. return true;
  577. }
  578. return this.processingRequired == 0;
  579. },
  580. // clientEnvironmentId() {
  581. // return this.$store.state.user.info.clientEnvironmentId;
  582. // },
  583. columns() {
  584. // 依赖 columnsVersion,列配置从服务端同步回来后能重新计算并生效
  585. const num = this.columnsVersion;
  586. return [
  587. {
  588. columnKey: 'index',
  589. label: '序号',
  590. type: 'index',
  591. width: 55,
  592. align: 'center',
  593. showOverflowTooltip: true
  594. },
  595. {
  596. slot: 'lineNumber',
  597. prop: 'lineNumber',
  598. label: '行号',
  599. align: 'center',
  600. minWidth: 140
  601. },
  602. {
  603. slot: 'productName',
  604. prop: 'productName',
  605. label: '名称',
  606. align: 'center',
  607. minWidth: 140
  608. },
  609. {
  610. slot: 'productCode',
  611. prop: 'productCode',
  612. label: '编码',
  613. align: 'center',
  614. minWidth: 140
  615. },
  616. {
  617. slot: 'brandNo',
  618. prop: 'brandNo',
  619. label: '牌号',
  620. align: 'center',
  621. minWidth: 140
  622. },
  623. {
  624. slot: 'model',
  625. prop: 'model',
  626. label: '型号',
  627. align: 'center',
  628. minWidth: 140
  629. },
  630. {
  631. slot: 'specification',
  632. prop: 'specification',
  633. label: '规格',
  634. align: 'center',
  635. minWidth: 140
  636. },
  637. {
  638. slot: 'productUnitWeight',
  639. prop: 'productUnitWeight',
  640. label: '单重',
  641. align: 'center',
  642. minWidth: 140
  643. },
  644. {
  645. slot: 'weightUnit',
  646. prop: 'weightUnit',
  647. label: '重量单位',
  648. align: 'center',
  649. minWidth: 140
  650. },
  651. {
  652. slot: 'modelKey',
  653. prop: 'modelKey',
  654. label: '机型',
  655. align: 'center',
  656. minWidth: 240
  657. },
  658. {
  659. slot: 'colorKey',
  660. prop: 'colorKey',
  661. label: '颜色',
  662. align: 'center',
  663. minWidth: 240
  664. },
  665. {
  666. slot: 'requiredFormingNum',
  667. prop: 'requiredFormingNum',
  668. headerSlot: 'headeRequiredFormingNum',
  669. label: '要求生产数量',
  670. align: 'center',
  671. minWidth: 140
  672. },
  673. {
  674. slot: 'measuringUnit',
  675. prop: 'measuringUnit',
  676. label: '计量单位',
  677. align: 'center',
  678. minWidth: 140
  679. },
  680. // {
  681. // slot: 'productionCodes',
  682. // prop: 'productionCodes',
  683. // label: '生产编号',
  684. // align: 'center',
  685. // minWidth: 140
  686. // },
  687. {
  688. slot: 'moCount',
  689. prop: 'moCount',
  690. label: '模数',
  691. headerSlot: 'headeRequiredFormingNum',
  692. align: 'center',
  693. minWidth: 140,
  694. show: this.clientEnvironmentId == 4
  695. },
  696. {
  697. slot: 'blockCount',
  698. prop: 'blockCount',
  699. label: '块数',
  700. headerSlot: 'headeRequiredFormingNum',
  701. align: 'center',
  702. minWidth: 140,
  703. show: this.clientEnvironmentId == 4
  704. },
  705. {
  706. slot: 'productType',
  707. prop: 'productType',
  708. label: '生产类型',
  709. headerSlot: 'headerProcessingBOM',
  710. align: 'center',
  711. minWidth: 180
  712. },
  713. {
  714. slot: 'bomCategoryId',
  715. prop: 'bomCategoryId',
  716. label: 'BOM版本',
  717. headerSlot: 'headerProcessingBOM',
  718. align: 'center',
  719. minWidth: 180,
  720. show: this.clientEnvironmentId !== 4
  721. },
  722. {
  723. slot: 'produceRoutingId',
  724. prop: 'produceRoutingId',
  725. headerSlot: 'headerProduceRoutingId',
  726. label: '工艺路线',
  727. align: 'center',
  728. minWidth: 240
  729. },
  730. {
  731. slot: 'factoriesId',
  732. prop: 'factoriesId',
  733. headerSlot: 'headerProduceRoutingId',
  734. label: '所属工厂',
  735. align: 'center',
  736. minWidth: 140
  737. },
  738. {
  739. slot: 'weight',
  740. prop: 'weight',
  741. label: '权重等级',
  742. align: 'center',
  743. minWidth: 140,
  744. show: this.clientEnvironmentId == 4
  745. },
  746. {
  747. slot: 'isSlotting',
  748. prop: 'isSlotting',
  749. label: '是否开槽',
  750. align: 'center',
  751. minWidth: 140,
  752. show: this.clientEnvironmentId == 4
  753. },
  754. {
  755. slot: 'slottingType',
  756. prop: 'slottingType',
  757. label: '开槽类型',
  758. align: 'center',
  759. minWidth: 140,
  760. show: this.clientEnvironmentId == 4
  761. },
  762. {
  763. slot: 'newSumOrderWeight',
  764. prop: 'newSumOrderWeight',
  765. label: '计划重量',
  766. align: 'center',
  767. minWidth: 140
  768. },
  769. {
  770. slot: 'set',
  771. prop: 'set',
  772. label: '操作',
  773. align: 'center',
  774. minWidth: 140,
  775. fixed: 'right'
  776. }
  777. ];
  778. }
  779. },
  780. data() {
  781. return {
  782. visible: false,
  783. factoriesId: '',
  784. clientEnvironmentId: '',
  785. // 产品信息表格的列配置缓存标识(localStorage 与服务端配置共用),不可与其他表格重复
  786. cacheKeyUrl: 'aps-productionPlan-factoryAdd-productInfo',
  787. columnsVersion: 1,
  788. title: '新增临时生产计划',
  789. type: 3,
  790. weightList: [
  791. { code: 1, name: 'A' },
  792. { code: 2, name: 'B' },
  793. { code: 3, name: 'C' }
  794. ],
  795. factoryList: [],
  796. isSlotting: [
  797. { code: 1, name: '是' },
  798. { code: 2, name: '否' }
  799. ], //是否开槽
  800. planTypeList: [
  801. { label: '内销计划', value: 1 },
  802. { label: '外销计划', value: 2 },
  803. { label: '预制计划', value: 3 },
  804. { label: '改型计划', value: 4 },
  805. { label: '返工返修计划', value: 5 },
  806. { label: '受托计划', value: 6 }
  807. ],
  808. loading: false,
  809. form: {
  810. timeDimensionPlanType: 3,
  811. categoryId: '',
  812. productName: '',
  813. planType: '',
  814. saleOrder: '',
  815. moCount: '', // 模具数量
  816. blockCount: 0, // 块数
  817. noWordCount: '', // 无字数量
  818. weight: '',
  819. startTime: '',
  820. endTime: '',
  821. isSlotting: '', //是否开槽
  822. slottingType: '', //开槽类型
  823. id: '',
  824. produceType: 2,
  825. bomCategoryId: '',
  826. produceRoutingId: '',
  827. requiredFormingNum: '',
  828. productInfoList: []
  829. },
  830. disabledList: [],
  831. bomVersionList: [],
  832. routingList: [],
  833. rules: {
  834. productName: [
  835. { required: true, message: '请选择名称', trigger: 'change' }
  836. ],
  837. bomCategoryId: [
  838. { required: true, message: '请选择BOM版本', trigger: 'blur' }
  839. ],
  840. planType: [
  841. { required: true, message: '请选择计划类型', trigger: 'blur' }
  842. ],
  843. produceType: [
  844. { required: true, message: '请选择工艺路线', trigger: 'blur' }
  845. ],
  846. produceRoutingId: [
  847. { required: true, message: '请选择工艺路线', trigger: 'blur' }
  848. ],
  849. startTime: [
  850. { required: true, message: '请选择计划开始日期', trigger: 'blur' }
  851. ],
  852. endTime: [
  853. { required: true, message: '请选择计划结束日期', trigger: 'blur' }
  854. ],
  855. // reqMoldTime: [
  856. // { required: true, message: '请选择要求完成日期', trigger: 'blur' }
  857. // ],
  858. requiredFormingNum: [
  859. { required: true, message: '请输入生产数量', trigger: 'blur' }
  860. ],
  861. saleOrder: [
  862. {
  863. validator: (rule, value, callback) => {
  864. if (!this.isSaleOrder) {
  865. callback();
  866. return;
  867. }
  868. if (
  869. value === undefined ||
  870. value === null ||
  871. String(value).trim() === ''
  872. ) {
  873. callback(new Error('请选择销售订单号'));
  874. } else {
  875. callback();
  876. }
  877. },
  878. trigger: ['blur', 'change']
  879. }
  880. ]
  881. },
  882. producedList: [
  883. { code: 2, name: '加工(MBOM)' },
  884. { code: 3, name: '装配(ABOM)' }
  885. ],
  886. selectIndex: 0, // 选择工艺路线的当前数据下标
  887. processingRequired: 0, // 生产类型跟BOM 版本是否必填 1:是 0:否
  888. isReview: false,
  889. isSaleOrder: false
  890. // selectionRowShow: false // 工艺路线输入框展示 状态
  891. };
  892. },
  893. // computed: {
  894. // clientEnvironmentId() {
  895. // return this.$store.state.user.info.clientEnvironmentId;
  896. // }
  897. // },
  898. mounted() {},
  899. methods: {
  900. selectFactory(e, row) {
  901. let data = this.factoryList.find((item) => item.id === e);
  902. this.$set(row, 'factoriesName', data.name);
  903. },
  904. // 所属工厂展示名称,避免下拉匹配不到时露出原始ID
  905. factoryLabel(row) {
  906. if (row.factoriesName) {
  907. return row.factoriesName;
  908. }
  909. // 行上没名字时,从工艺路线列表里取(bomRoutingList 会带回工厂名)
  910. const routing = (row.routingList || []).find(
  911. (item) => String(item.id) === String(row.produceRoutingId)
  912. );
  913. if (
  914. routing &&
  915. routing.factoriesName &&
  916. (!row.factoriesId ||
  917. String(row.factoriesId) === String(routing.factoriesId))
  918. ) {
  919. return routing.factoriesName;
  920. }
  921. const hit = this.factoryList.find(
  922. (item) => String(item.id) === String(row.factoriesId)
  923. );
  924. return hit ? hit.name : row.factoriesId || '';
  925. },
  926. // 工艺路线接口(bomRoutingList)会带回 factoriesId/factoriesName,用它补全所属工厂名称
  927. applyRoutingFactoryName(row, routing) {
  928. if (!row || !routing || !routing.factoriesName) {
  929. return;
  930. }
  931. if (row.factoriesName) {
  932. return;
  933. }
  934. // 行的工厂与工艺路线上的工厂一致时才补,避免显示成别的工厂
  935. if (
  936. row.factoriesId &&
  937. String(row.factoriesId) !== String(routing.factoriesId)
  938. ) {
  939. return;
  940. }
  941. this.$set(row, 'factoriesName', routing.factoriesName);
  942. },
  943. async getPlannedReleaseRequire(code) {
  944. parameterGetByCode({ code }).then((res) => {
  945. if (res) {
  946. this.isReview = res.value == '1' ? true : false;
  947. }
  948. });
  949. },
  950. // 打开工艺路线
  951. openDialog(index) {
  952. this.selectIndex = index;
  953. this.$refs.processRouteRef.open();
  954. },
  955. // 选择工艺路线
  956. changeParent(item) {
  957. let data = this.form.productInfoList[this.selectIndex];
  958. this.$set(data, 'bomVersionList', []);
  959. this.$set(data, 'bomCategoryId', '');
  960. // this.$set(data, 'model', '');
  961. this.$set(data, 'routingList', []);
  962. this.$set(data, 'productType', '');
  963. this.$set(data, 'produceRoutingName', item.name);
  964. this.$set(data, 'produceRoutingId', item.id);
  965. this.applyRoutingFactoryName(data, item);
  966. this.$set(data, 'selectionRowShow', true);
  967. // this.selectionRowShow = true;
  968. },
  969. async getFactoryList() {
  970. this.factoryList = await getFactoryList();
  971. },
  972. async open(val) {
  973. const [processingRes, saleOrderRes] = await Promise.all([
  974. parameterGetByCode({ code: 'production_plan_code' }),
  975. parameterGetByCode({ code: 'create_plan_binding_sale_order' }),
  976. this.getFactoryList(),
  977. this.getPlannedReleaseRequire('planned_release_require')
  978. ]);
  979. if (processingRes) {
  980. this.processingRequired = processingRes.value;
  981. }
  982. this.isSaleOrder = saleOrderRes?.value === '1';
  983. this.clientEnvironmentId =
  984. this.$store.state.user.info.clientEnvironmentId;
  985. this.factoriesId = this.$store.state.user.info.factoryId;
  986. if (!val) {
  987. this.title = '新增临时生产计划';
  988. this.visible = true;
  989. return;
  990. }
  991. if (val.planType == null || val.planType === 'null') {
  992. val.planType = '';
  993. }
  994. this.title = val.id ? '编辑临时生产计划' : '新增临时生产计划';
  995. val.planType = String(val.planType);
  996. this.form = await getUpdateInfoByCode(val.code);
  997. if (this.isSaleOrder) {
  998. const salesCode = this.form.salesCode;
  999. this.$set(
  1000. this.form,
  1001. 'saleOrder',
  1002. Array.isArray(salesCode) ? salesCode.join(',') : salesCode || ''
  1003. );
  1004. }
  1005. if (val.id) {
  1006. await this.initEditProductList(val);
  1007. }
  1008. this.$forceUpdate();
  1009. this.visible = true;
  1010. },
  1011. async initEditProductList(val) {
  1012. const productList = this.form.productInfoList;
  1013. if (Array.isArray(val.productInfoList) && val.productInfoList.length) {
  1014. await Promise.all(
  1015. productList.map(async (v, index) => {
  1016. v.selectionRowShow = !v.bomCategoryId;
  1017. if (!v.bomCategoryId) {
  1018. v.productType = '';
  1019. }
  1020. if (v.productType) {
  1021. this.$set(
  1022. productList[index],
  1023. 'bomVersionList',
  1024. await this.bomListVersionFn(v.productType, v.categoryId)
  1025. );
  1026. }
  1027. if (v.bomCategoryId) {
  1028. this.$set(
  1029. productList[index],
  1030. 'routingList',
  1031. await this.changeBomIdFn(v.bomCategoryId, productList[index])
  1032. );
  1033. }
  1034. })
  1035. );
  1036. }
  1037. const [resAll, infoAll] = await Promise.all([
  1038. Promise.all(
  1039. productList.map((item) =>
  1040. findBomCategoryByCategoryId(item.categoryId)
  1041. )
  1042. ),
  1043. Promise.all(
  1044. productList.map(async (item) => {
  1045. try {
  1046. return (await getColorModelInfoById(item.categoryId)) || {};
  1047. } catch (e) {
  1048. return {};
  1049. }
  1050. })
  1051. )
  1052. ]);
  1053. productList.forEach((item, index) => {
  1054. const info = infoAll[index] || {};
  1055. const colorKey = info.colorKey || '';
  1056. const modelKey = info.modelKey || '';
  1057. this.$set(
  1058. productList[index],
  1059. 'colorList',
  1060. colorKey ? colorKey.split(',') : []
  1061. );
  1062. this.$set(
  1063. productList[index],
  1064. 'modelList',
  1065. modelKey ? modelKey.split(',') : []
  1066. );
  1067. this.$set(
  1068. productList[index],
  1069. 'colorKey',
  1070. item.colorKey || (colorKey ? colorKey.split(',')[0] : '')
  1071. );
  1072. this.$set(
  1073. productList[index],
  1074. 'modelKey',
  1075. item.modelKey || (modelKey ? modelKey.split(',')[0] : '')
  1076. );
  1077. if (!resAll[index]) return;
  1078. const listMap = {};
  1079. resAll[index].forEach((el) => {
  1080. if (el.bomType === '2' || el.bomType === '3') {
  1081. if (!listMap[el.bomType]) listMap[el.bomType] = [];
  1082. listMap[el.bomType].push(el);
  1083. }
  1084. });
  1085. const list = [];
  1086. if (listMap[2]) list.push({ code: 2, name: 'MBOM' });
  1087. if (listMap[3]) list.push({ code: 3, name: 'ABOM' });
  1088. if (!item.factoriesId) {
  1089. this.$set(productList[index], 'factoriesId', this.factoriesId);
  1090. this.$set(
  1091. productList[index],
  1092. 'factoriesName',
  1093. productList[index].factoriesName ||
  1094. this.factoryList?.find(
  1095. (f) => String(f.id) === String(this.factoriesId)
  1096. )?.name
  1097. );
  1098. }
  1099. this.$set(productList[index], 'producedList', list);
  1100. });
  1101. },
  1102. addEquipment() {
  1103. this.$refs.equipmentRefs.open();
  1104. },
  1105. async confirmChoose(data) {
  1106. let list = deepClone(data);
  1107. list.map((el) => (el.selectionRowShow = false));
  1108. if (this.clientEnvironmentId == 4) {
  1109. list.map((v) => {
  1110. if (v.name.includes('板材')) {
  1111. v.produceRoutingId = '1856970794952372226';
  1112. v.produceRoutingName = '板材';
  1113. v.produceVersionName = '板材';
  1114. } else {
  1115. (v.produceRoutingId = '1857313733642596353'),
  1116. (v.produceRoutingName = '砌块'),
  1117. (v.produceVersionName = '砌块');
  1118. }
  1119. });
  1120. }
  1121. let ids = this.form.productInfoList.map((item) => item.categoryId);
  1122. const filtered = list.filter((i) => !ids.includes(i.id));
  1123. let result = await Promise.all(
  1124. filtered.map(async (item) => {
  1125. let info = {};
  1126. try {
  1127. info = (await getColorModelInfoById(item.id)) || {};
  1128. } catch (e) {
  1129. info = {};
  1130. }
  1131. const colorKey = info.colorKey || '';
  1132. const modelKey = info.modelKey || '';
  1133. return {
  1134. categoryId: item.id,
  1135. productCode: item.code,
  1136. productName: item.name,
  1137. productUnitWeight: item.netWeight,
  1138. weightUnit: item.weightUnit,
  1139. model: item.modelType,
  1140. specification: item.specification,
  1141. brandNo: item.brandNum,
  1142. measuringUnit: item.measuringUnit,
  1143. produceRoutingId: item.produceRoutingId,
  1144. produceRoutingName: item.produceRoutingName,
  1145. produceVersionName: item.produceVersionName,
  1146. factoriesId: this.factoriesId,
  1147. colorList: colorKey ? colorKey.split(',') : [],
  1148. modelList: modelKey ? modelKey.split(',') : [],
  1149. colorKey: colorKey ? colorKey.split(',')[0] : '',
  1150. modelKey: modelKey ? modelKey.split(',')[0] : '',
  1151. factoriesName: this.factoryList?.find(
  1152. (factoryData) => factoryData.id === this.factoriesId
  1153. )?.name
  1154. };
  1155. })
  1156. );
  1157. // this.form.productInfoList = [];
  1158. // 取出在弹窗中选中并且不在表格中的数据
  1159. // const result = list.filter(
  1160. // (i) =>
  1161. // this.form.productInfoList.findIndex(
  1162. // (p) => p.productCode === i.productCode
  1163. // ) === -1
  1164. // );
  1165. // // 取出在表格中并且不在弹窗中选中的数据 即取消选中的数据
  1166. // const del = this.form.productInfoList.filter(
  1167. // (i) => list.findIndex((p) => p.productCode === i.productCode) === -1
  1168. // );
  1169. // for (let i = this.form.productInfoList.length - 1; i >= 0; i--) {
  1170. // for (let j in del) {
  1171. // if (
  1172. // this.form.productInfoList[i].productCode === del[j].productCode
  1173. // ) {
  1174. // this.form.productInfoList.splice(i, 1);
  1175. // break;
  1176. // }
  1177. // }
  1178. // }
  1179. let promiseAll = [];
  1180. result.forEach(async (item) => {
  1181. let categoryId = item.categoryId;
  1182. promiseAll.push(findBomCategoryByCategoryId(categoryId));
  1183. });
  1184. const resAll = await Promise.all(promiseAll);
  1185. try {
  1186. await result.forEach(async (item, index) => {
  1187. if (resAll[index]) {
  1188. let listMap = {};
  1189. let list = [];
  1190. let arr = [];
  1191. resAll[index].map((el) => {
  1192. if (el.bomType == '2' || el.bomType == '3') {
  1193. console.log(listMap, 'listMap');
  1194. if (listMap[el.bomType]) {
  1195. listMap[el.bomType].push(el);
  1196. } else {
  1197. listMap[el.bomType] = [el];
  1198. }
  1199. }
  1200. });
  1201. if (listMap[2]) {
  1202. list.push({ code: 2, name: 'MBOM' });
  1203. arr = listMap[2];
  1204. item.productType = 2;
  1205. }
  1206. if (listMap[3]) {
  1207. list.push({ code: 3, name: 'ABOM' });
  1208. if (!listMap[2]) {
  1209. arr = listMap[3];
  1210. item.productType = 3;
  1211. }
  1212. }
  1213. if (arr.length > 0) {
  1214. arr.map((el) => (el.bomCategoryId = el.id));
  1215. item.bomCategoryId = arr[0].id;
  1216. await this.changeBomId(arr[0], 0);
  1217. this.$set(item, 'produceRoutingId', arr[0].produceRoutingId);
  1218. this.$set(
  1219. item,
  1220. 'produceVersionName',
  1221. arr[0].produceVersionName
  1222. );
  1223. this.$set(
  1224. item,
  1225. 'produceRoutingName',
  1226. arr[0].produceRoutingName
  1227. );
  1228. console.log(arr[0], 'arr[0]');
  1229. this.$set(item, 'routingList', arr[0].routingList);
  1230. this.$set(item, 'bomCategoryName', arr[0].name);
  1231. this.$set(item, 'bomCategoryVersions', arr[0].versions);
  1232. }
  1233. item.producedList = list;
  1234. item.bomVersionList = arr;
  1235. return item;
  1236. }
  1237. });
  1238. } catch (err) {}
  1239. console.log(result, 'result');
  1240. // return
  1241. this.form.productInfoList.push(...result);
  1242. this.changeLineNumber();
  1243. console.log(this.form.productInfoList, 'this.form.productInfoList');
  1244. this.$refs.tableRef.setData(this.form.productInfoList);
  1245. // console.log(this.form.productInfoList, 'this.form.productInfoList');
  1246. //重置
  1247. this.$set(this.form, 'produceType', '');
  1248. this.$set(this.form, 'bomCategoryId', '');
  1249. this.$set(this.form, 'produceRoutingId', '');
  1250. },
  1251. changeLineNumber() {
  1252. this.form.productInfoList.forEach((item, index) => {
  1253. let data = this.form.productInfoList[index - 1];
  1254. this.$set(
  1255. this.form.productInfoList[index],
  1256. 'lineNumber',
  1257. data ? data.lineNumber + 10 : 10
  1258. );
  1259. });
  1260. },
  1261. handleDeleteItem(index) {
  1262. this.$confirm('确定删除当前数据?', '提示')
  1263. .then(() => {
  1264. const newArray = this.form.productInfoList.filter(
  1265. (item, i) => i !== index
  1266. );
  1267. this.form.productInfoList = newArray;
  1268. this.$refs.tableRef.setData(newArray);
  1269. })
  1270. .catch(() => {});
  1271. },
  1272. async getPlanCode() {
  1273. this.loading = true;
  1274. try {
  1275. const code = await getCode('product_code');
  1276. this.$set(this.form, 'code', code);
  1277. } catch (err) {}
  1278. },
  1279. initForm() {
  1280. this.form = {
  1281. timeDimensionPlanType: 3,
  1282. categoryId: '',
  1283. productName: '',
  1284. planType: '',
  1285. saleOrder: '',
  1286. moCount: '', // 模具数量
  1287. blockCount: 0, // 块数
  1288. noWordCount: '', // 无字数量
  1289. weight: '',
  1290. isSlotting: '', //是否开槽
  1291. slottingType: '', //开槽类型
  1292. id: '',
  1293. produceType: 2,
  1294. status: 2,
  1295. bomCategoryId: '',
  1296. produceRoutingId: '',
  1297. productInfoList: [],
  1298. requiredFormingNum: ''
  1299. };
  1300. // console.log(this.$refs);
  1301. // this.$refs.tableRef.setData([]);
  1302. },
  1303. changeBomIdFn(bomCategoryId, row) {
  1304. return new Promise((resolve, reject) => {
  1305. bomRoutingList(bomCategoryId).then((res) => {
  1306. let arr = res || [];
  1307. if (arr.length == 0) {
  1308. row.produceRoutingId = '';
  1309. }
  1310. // 编辑回显时后台不会返回所属工厂名称,用工艺路线上的工厂信息补全
  1311. const hit = arr.find(
  1312. (item) => String(item.id) === String(row.produceRoutingId)
  1313. );
  1314. this.applyRoutingFactoryName(row, hit);
  1315. resolve(arr);
  1316. });
  1317. });
  1318. },
  1319. // 选择BOM
  1320. async changeBomId(row, index, bomData, typeChange) {
  1321. if (bomData) {
  1322. row.bomCategoryName = bomData.name;
  1323. row.bomCategoryVersions = bomData.versions;
  1324. }
  1325. // row.routingList = []
  1326. return await bomRoutingList(row.bomCategoryId).then((res) => {
  1327. let arr = res || [];
  1328. if (arr.length > 0) {
  1329. // this.$nextTick(() => {
  1330. row.produceRoutingName = arr[0].name;
  1331. row.produceVersionName = arr[0].version;
  1332. row.produceRoutingId = arr[0].id;
  1333. row.routingList = arr;
  1334. this.applyRoutingFactoryName(row, arr[0]);
  1335. if (typeChange) {
  1336. this.$set(this.form.productInfoList[index], 'routingList', arr);
  1337. this.$set(
  1338. this.form.productInfoList[index],
  1339. 'produceRoutingId',
  1340. arr[0].id
  1341. );
  1342. } else {
  1343. this.$set(row, 'produceRoutingId', arr[0].id);
  1344. this.$set(row, 'routingList', arr);
  1345. }
  1346. row.selectionRowShow = false;
  1347. console.log(row.routingList, 'this.form.productInfoList');
  1348. // });
  1349. }
  1350. this.$forceUpdate();
  1351. });
  1352. },
  1353. contactDialogSuccess(data) {
  1354. console.log(data, 'data 11');
  1355. // serialNo
  1356. this.form.serialNo = data.serialNo;
  1357. this.$set(this.form, 'customerName', data.name);
  1358. },
  1359. openSaleOrderDialog() {
  1360. this.$refs.saleOrderRef.open([]);
  1361. },
  1362. chooseSaleOrder(list) {
  1363. const currentRow = list[0] || {};
  1364. this.$set(this.form, 'saleOrder', currentRow.orderNo || '');
  1365. this.$nextTick(() => {
  1366. this.$refs.form && this.$refs.form.validateField('saleOrder');
  1367. });
  1368. },
  1369. // 清空BOM 跟工艺路线
  1370. wipeData(index) {
  1371. this.$set(this.form.productInfoList[index], 'bomCategoryId', '');
  1372. this.$set(this.form.productInfoList[index], 'routingList', []);
  1373. this.$set(this.form.productInfoList[index], 'bomVersionList', []);
  1374. this.$set(this.form.productInfoList[index], 'produceRoutingId', '');
  1375. this.$set(this.form.productInfoList[index], 'produceRoutingName', '');
  1376. this.$set(this.form.productInfoList[index], 'produceVersionName', '');
  1377. this.$set(this.form.productInfoList[index], 'selectionRowShow', false);
  1378. // this.selectionRowShow = false;
  1379. },
  1380. // 选择生产类型
  1381. changeProductType(row, index) {
  1382. let param = {
  1383. bomType: row.productType,
  1384. categoryId: row.categoryId
  1385. };
  1386. this.wipeData(index);
  1387. // row.bomCategoryId = '';
  1388. // this.form.productInfoList[index].bomVersionList = [];
  1389. bomListByPlan(param).then((res) => {
  1390. let arr = res || [];
  1391. this.$nextTick(() => {
  1392. if (arr.length) {
  1393. row.bomVersionList = arr;
  1394. this.form.productInfoList[index].bomVersionList = arr;
  1395. row.bomCategoryId = arr[0].id;
  1396. this.changeBomId(row, index, arr[0], 'typeChange');
  1397. let arrAll = JSON.parse(JSON.stringify(this.form));
  1398. this.$set(this, 'form', arrAll);
  1399. }
  1400. });
  1401. // this.$set(this.form.productInfoList[index], 'bomVersionList', arr);
  1402. });
  1403. },
  1404. // 参数校验
  1405. parameterVerification() {
  1406. let flag = true;
  1407. this.form.productInfoList.forEach((v) => {
  1408. if (this.isRequired) {
  1409. if (!v.productType) {
  1410. flag = false;
  1411. this.$message.warning('请选择生产类型');
  1412. return;
  1413. }
  1414. if (!v.bomCategoryId) {
  1415. flag = false;
  1416. this.$message.warning('请选择BOM版本');
  1417. return;
  1418. }
  1419. }
  1420. if (!v.produceRoutingId) {
  1421. flag = false;
  1422. this.$message.warning('请选择工艺路线');
  1423. return;
  1424. }
  1425. if (!v.factoriesId) {
  1426. flag = false;
  1427. this.$message.warning('请选择所属工厂');
  1428. return;
  1429. }
  1430. if (v.requiredFormingNum == 0) {
  1431. flag = false;
  1432. this.$message.warning('要求生产数量不能为0');
  1433. return;
  1434. }
  1435. if (!v.requiredFormingNum) {
  1436. flag = false;
  1437. this.$message.warning('请输入要求生产数量');
  1438. return;
  1439. }
  1440. if (!v.moCount && this.clientEnvironmentId == 4) {
  1441. flag = false;
  1442. this.$message.warning('请输入模数');
  1443. return;
  1444. }
  1445. if (!v.blockCount && this.clientEnvironmentId == 4) {
  1446. flag = false;
  1447. this.$message.warning('请输入块数');
  1448. return;
  1449. }
  1450. });
  1451. return flag;
  1452. },
  1453. save(type) {
  1454. this.$refs.form.validate(async (valid) => {
  1455. if (!valid) return;
  1456. if (!this.parameterVerification()) return;
  1457. const isAdd = !this.form.id;
  1458. this.form.productInfoList.forEach((item) => {
  1459. item.colorKey = item.colorKey == null ? '' : String(item.colorKey);
  1460. item.modelKey = item.modelKey == null ? '' : String(item.modelKey);
  1461. if (isAdd) delete item.selectionRowShow;
  1462. });
  1463. if (isAdd) {
  1464. this.form.timeDimensionPlanType = this.type;
  1465. }
  1466. if (this.isSaleOrder) {
  1467. this.form.salesCode = this.form.saleOrder.split(',');
  1468. }
  1469. this.loading = true;
  1470. const api = type === 'sub' ? saveAndRelease : temporaryPlanSave;
  1471. api(this.form)
  1472. .then(() => {
  1473. this.$message.success(isAdd ? '新增成功!' : '修改成功!');
  1474. this.visible = false;
  1475. this.initForm();
  1476. this.$emit('close', true);
  1477. })
  1478. .finally(() => {
  1479. this.loading = false;
  1480. });
  1481. });
  1482. },
  1483. // save(type) {
  1484. // this.$refs.form.validate(async (valid) => {
  1485. // if (!valid) {
  1486. // return false;
  1487. // }
  1488. // let flag = this.parameterVerification();
  1489. // // 必填参数校验
  1490. // if (!flag) return;
  1491. // this.form.productInfoList.forEach((item, index) => {
  1492. // this.$set(
  1493. // this.form.productInfoList[index],
  1494. // 'colorKey',
  1495. // item.colorKey.toString()
  1496. // );
  1497. // this.$set(
  1498. // this.form.productInfoList[index],
  1499. // 'modelKey',
  1500. // item.modelKey.toString()
  1501. // );
  1502. // });
  1503. // // this.
  1504. // if (!this.form.id) {
  1505. // if (this.form.productInfoList.length) {
  1506. // this.form.productInfoList.map((item, index) => {
  1507. // delete item.selectionRowShow;
  1508. // // if (item.bomVersionList && item.bomVersionList.length) {
  1509. // // item.bomCategoryName = item.bomVersionList[0].name;
  1510. // // item.bomCategoryVersions = item.bomVersionList[0].versions;
  1511. // // item.produceRoutingName = item.routingList[0].name;
  1512. // // }
  1513. // });
  1514. // }
  1515. // this.form.timeDimensionPlanType = this.type;
  1516. // if (this.isSaleOrder) {
  1517. // this.form.saleOrder = this.form.saleOrder.split(',');
  1518. // }
  1519. // this.loading = true;
  1520. // let api = type == 'sub' ? saveAndRelease : temporaryPlanSave;
  1521. // api(this.form)
  1522. // .then((res) => {
  1523. // this.$message.success('新增成功!');
  1524. // this.visible = false;
  1525. // this.initForm();
  1526. // this.$emit('close', true);
  1527. // })
  1528. // .finally(() => {
  1529. // this.loading = false;
  1530. // });
  1531. // } else {
  1532. // this.loading = true;
  1533. // let api = type == 'sub' ? saveAndRelease : temporaryPlanSave;
  1534. // if (this.isSaleOrder) {
  1535. // this.form.saleOrder = this.form.saleOrder.split(',');
  1536. // }
  1537. // api(this.form)
  1538. // .then((res) => {
  1539. // this.$message.success('修改成功!');
  1540. // this.visible = false;
  1541. // this.initForm();
  1542. // this.$emit('close', true);
  1543. // })
  1544. // .finally(() => {
  1545. // this.loading = false;
  1546. // });
  1547. // }
  1548. // });
  1549. // },
  1550. bomListVersionFn(produceType, categoryId) {
  1551. return new Promise((resolve, reject) => {
  1552. let param = {
  1553. bomType: produceType,
  1554. categoryId: categoryId
  1555. };
  1556. bomListByPlan(param).then((res) => {
  1557. this.bomVersionList = res || [];
  1558. resolve(res || []);
  1559. });
  1560. });
  1561. },
  1562. bomListVersion() {
  1563. let param = {
  1564. bomType: this.form.produceType,
  1565. categoryId: this.form.categoryId
  1566. };
  1567. bomListByPlan(param).then((res) => {
  1568. this.$nextTick(() => {
  1569. this.bomVersionList = res || [];
  1570. console.log(res, 'res 000');
  1571. });
  1572. });
  1573. },
  1574. // 工艺路线
  1575. getPlanRouting() {
  1576. bomRoutingList(this.form.bomCategoryId).then((res) => {
  1577. this.routingList = res || [];
  1578. });
  1579. },
  1580. // 宝悦 工艺路线
  1581. getPlanRoutingNew() {
  1582. // bomRoutingList(this.form.bomCategoryId).then((res) => {
  1583. // this.routingList = res || []
  1584. // })
  1585. },
  1586. tableHandleKeyUp(row, name) {
  1587. // return
  1588. // , index, e, name
  1589. if (name == 'procut') {
  1590. return;
  1591. }
  1592. if (row.specification && this.clientEnvironmentId == 4) {
  1593. let modelArr = row.specification.split('*');
  1594. let modelLong = modelArr[0]; // model规格长度
  1595. let modeWide = modelArr[1]; // model规格宽度
  1596. let modeHight = modelArr[2].substr(0, modelArr[2].indexOf('cm')); // model规格高度
  1597. modeHight = Number(modeHight);
  1598. if (name === 'moCount') {
  1599. // 模数
  1600. this.$set(row, 'moCount', row.moCount);
  1601. // 计算块数的公式:
  1602. // (一模6米长度 / model规格长度) * (一模1.2米宽度 / model规格宽度) = 每一模的块数
  1603. // 每一模的块数*模数moCount = 总块数
  1604. if (row.productName.includes('板材')) {
  1605. // 块数
  1606. let blockCount =
  1607. Math.floor(600 / modelLong) *
  1608. Math.floor(120 / modeHight) *
  1609. Math.floor(60 / modeWide) *
  1610. row.moCount;
  1611. row['blockCount'] = blockCount;
  1612. // this.$set(row, 'blockCount', blockCount);
  1613. } else if (row.productName.includes('砌块')) {
  1614. let modelLongFixed = (600 / modelLong).toFixed(2);
  1615. modelLongFixed = modelLongFixed.substring(
  1616. 0,
  1617. modelLongFixed.length - 1
  1618. );
  1619. let modeWideFixed = (120 / modeWide).toFixed(2);
  1620. modeWideFixed = modeWideFixed.substring(
  1621. 0,
  1622. modeWideFixed.length - 1
  1623. );
  1624. let modeHightFixed = (60 / modeHight).toFixed(2);
  1625. modeHightFixed = modeHightFixed.substring(
  1626. 0,
  1627. modeHightFixed.length - 1
  1628. );
  1629. let num =
  1630. Math.floor(modelLongFixed * modeWideFixed * modeHightFixed) *
  1631. row.moCount;
  1632. row['blockCount'] = num;
  1633. }
  1634. let numNew = (
  1635. Number((modelLong * modeWide * modeHight) / 1000000).toFixed(5) *
  1636. row.blockCount
  1637. ).toFixed(5);
  1638. row['requiredFormingNum'] = numNew;
  1639. } else if (name === 'sum') {
  1640. let e = row.requiredFormingNum;
  1641. row.blockCount = Math.floor(
  1642. e / ((modelLong * modeWide * modeHight) / 1000000)
  1643. );
  1644. if (row.productName.includes('板材')) {
  1645. let num = Math.ceil(
  1646. row.blockCount /
  1647. (Math.floor(600 / modelLong) *
  1648. Math.floor(120 / modeHight) *
  1649. Math.floor(60 / modeWide))
  1650. );
  1651. // 48 480 4807 480
  1652. row.moCount = num;
  1653. } else if (row.productName.includes('砌块')) {
  1654. row.moCount = Math.ceil(
  1655. row.blockCount /
  1656. Math.floor(
  1657. (600 / modelLong) * (120 / modeHight) * (60 / modeWide)
  1658. )
  1659. );
  1660. }
  1661. } else if (name === 'blockCount') {
  1662. //块数
  1663. // row.blockCount = row.moCount;
  1664. row.blockCount = row.blockCount;
  1665. if (row.productName.includes('板材')) {
  1666. let moCount = Math.ceil(
  1667. row.blockCount /
  1668. (Math.floor(600 / modelLong) *
  1669. Math.floor(120 / modeHight) *
  1670. Math.floor(60 / modeWide))
  1671. );
  1672. row.moCount = moCount;
  1673. } else if (row.productName.includes('砌块')) {
  1674. let moCount = Math.ceil(
  1675. row.blockCount /
  1676. Math.floor(
  1677. (600 / modelLong) * (120 / modeHight) * (60 / modeWide)
  1678. )
  1679. );
  1680. this.$set(this.form, 'moCount', moCount);
  1681. row.moCount = moCount;
  1682. }
  1683. let a = (
  1684. (Number(row.blockCount) * modelLong * modeWide * modeHight) /
  1685. 1000000
  1686. ).toFixed(5);
  1687. row.requiredFormingNum = a;
  1688. }
  1689. }
  1690. },
  1691. // 数量正则 quantity
  1692. handleQuantityInput(e, row) {
  1693. // 过滤非数字字符(包括负号)
  1694. let value = e.replace(/[^\d.]/g, '');
  1695. // value = value.replace(/-/g, '');
  1696. // 限制不能以 0 开头(除非是 0 本身)
  1697. // if (value.startsWith('0') && value.length > 1) {
  1698. // value = value.slice(1);
  1699. // }
  1700. // 更新绑定值
  1701. row.requiredFormingNum = value;
  1702. // if (
  1703. // item.weightUnit == 'G' ||
  1704. // item.weightUnit == 'g' ||
  1705. // item.weightUnit == '克'
  1706. // ) {
  1707. // let total =
  1708. // ((item.requiredFormingNum - 0) * item.productUnitWeight) /
  1709. // 1000;
  1710. // item.newSumOrderWeight = total.toFixed(2);
  1711. // item.newWeightUnit = 'KG';
  1712. // } else {
  1713. // item.newWeightUnit = item.weightUnit;
  1714. // item.newSumOrderWeight = item.requiredFormingNum;
  1715. // }
  1716. row.newWeightUnit = row.weightUnit;
  1717. if (row.weightUnit == row.measuringUnit) {
  1718. row.newSumOrderWeight = row.requiredFormingNum;
  1719. } else if (row.requiredFormingNum && row.productUnitWeight) {
  1720. row.newSumOrderWeight =
  1721. row.requiredFormingNum * row.productUnitWeight;
  1722. } else {
  1723. row.newSumOrderWeight = 0;
  1724. }
  1725. row.productWeight = row.newSumOrderWeight;
  1726. this.tableHandleKeyUp(row, 'sum');
  1727. },
  1728. changeProduceType(e) {
  1729. if (this.clientEnvironmentId !== 4) {
  1730. this.form.bomCategoryId = '';
  1731. this.form['bomCategoryName'] = '';
  1732. this.form['bomCategoryVersions'] = '';
  1733. this.bomVersionList = [];
  1734. this.routingList = [];
  1735. this.form.produceRoutingId = '';
  1736. this.form.produceRoutingName = '';
  1737. this.form.produceVersionName = '';
  1738. this.bomListVersion();
  1739. }
  1740. },
  1741. // changeBomId() {
  1742. // this.routingList = [];
  1743. // this.form.produceRoutingId = '';
  1744. // this.form.produceRoutingName = '';
  1745. // this.form.produceVersionName = '';
  1746. // this.bomVersionList.forEach((f) => {
  1747. // if (f.id == this.form.bomCategoryId) {
  1748. // this.$set(this.form, 'bomCategoryName', f.name);
  1749. // this.$set(this.form, 'bomCategoryVersions', f.versions);
  1750. // }
  1751. // });
  1752. // this.getPlanRouting();
  1753. // },
  1754. changeRoute() {
  1755. this.$forceUpdate();
  1756. this.routingList.forEach((f) => {
  1757. if (f.id == this.form.produceRoutingId) {
  1758. this.$set(this.form, 'produceRoutingId', f.id);
  1759. this.$set(this.form, 'produceRoutingName', f.name);
  1760. this.$set(this.form, 'produceVersionName', f.version);
  1761. }
  1762. });
  1763. },
  1764. cancel() {
  1765. this.visible = false;
  1766. this.initForm();
  1767. this.$emit('close');
  1768. },
  1769. // 【开始时间变化时】触发
  1770. handleStartTimeChange(row) {
  1771. // 校验 是否 大于结束时间 wda
  1772. this.checkEndTimeValid(row);
  1773. },
  1774. // 【结束时间变化时】触发
  1775. handleEndTimeChange(row) {
  1776. // 校验 是否 大于结束时间 wda
  1777. this.checkEndTimeValid(row);
  1778. },
  1779. handleCompleteChange(row) {
  1780. const { reqMoldTime } = row;
  1781. if (!row.startTime) {
  1782. row.reqMoldTime = '';
  1783. return this.$message.warning('请选择计划开始时间');
  1784. }
  1785. this.handleComplete(reqMoldTime, row);
  1786. },
  1787. handleComplete(reqMoldTime, row) {
  1788. const startTime = new Date(row.startTime).getTime();
  1789. const completeTime = new Date(reqMoldTime).getTime();
  1790. if (completeTime < startTime) {
  1791. row.reqMoldTime = ''; // 修正为开始时间
  1792. return this.$message.warning(
  1793. '要求完成时间不能早于计划开始时间, 请重新选择要求完成时间'
  1794. );
  1795. }
  1796. },
  1797. // 时间校验
  1798. checkEndTimeValid(row) {
  1799. const { startTime: start, endTime: end } = row;
  1800. this.handleChange(start, end, row);
  1801. // // if (!start || !end) return; // 开始/结束时间未填,跳过
  1802. // const startTime = new Date(start); // 开始时间
  1803. // const endTime = new Date(end); // 结束时间
  1804. // if (endTime < startTime) {
  1805. // row.endTime = new Date(startTime); // 修正为开始时间
  1806. // this.$message.info('结束时间不能早于开始时间,已自动设为开始时间');
  1807. // }
  1808. },
  1809. handleChange(start, end, row) {
  1810. const startTime = new Date(start).getTime();
  1811. const endTime = new Date(end).getTime();
  1812. if (endTime < startTime) {
  1813. row.endTime = ''; // 修正为开始时间
  1814. return this.$message.warning(
  1815. '计划结束时间不能早于计划开始时间,请重新选择计划结束时间'
  1816. );
  1817. }
  1818. }
  1819. }
  1820. };
  1821. </script>
  1822. <style lang="scss" scoped>
  1823. .el-form-item {
  1824. margin-bottom: 14px !important;
  1825. }
  1826. .sale-order-select {
  1827. display: flex;
  1828. align-items: center;
  1829. gap: 4px;
  1830. }
  1831. .add-product {
  1832. width: 100%;
  1833. display: flex;
  1834. align-items: center;
  1835. justify-content: flex-end;
  1836. font-size: 30px;
  1837. color: #1890ff;
  1838. margin: 10px 0;
  1839. cursor: pointer;
  1840. }
  1841. .header_required {
  1842. .is-required:before {
  1843. content: '*';
  1844. color: #f56c6c;
  1845. margin-right: 4px;
  1846. }
  1847. }
  1848. </style>