salesToProductionNewTwo.vue 62 KB

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