salesToProductionNewTwo.vue 57 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773
  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="生产类型:"
  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="所属工厂:">
  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 label="批次号" align="center" prop="batchNo">
  363. </el-table-column>
  364. <el-table-column
  365. :label="'计划生产数量' + (clientEnvironmentId == '4' ? '(方)' : '')"
  366. align="center"
  367. prop="planProductNum"
  368. width="140"
  369. >
  370. <template slot-scope="scope">
  371. <el-form-item
  372. label-width="0px"
  373. :prop="'salesOrders.' + scope.$index + '.planProductNum'"
  374. :rules="{
  375. required: true,
  376. message: '请输入计划生产数量',
  377. trigger: 'blur'
  378. }"
  379. class="table-item"
  380. >
  381. <el-input
  382. v-model.number="scope.row.planProductNum"
  383. size="small"
  384. type="number"
  385. style="width: 100%"
  386. @input="
  387. tableHandleKeyUp(scope.row, scope.$index, $event, 'sum')
  388. "
  389. placeholder="输入数量"
  390. ></el-input>
  391. </el-form-item>
  392. </template>
  393. </el-table-column>
  394. <el-table-column
  395. :label="'要求生产数量' + (clientEnvironmentId == '4' ? '(方)' : '')"
  396. align="center"
  397. prop="requiredFormingNum"
  398. width="120"
  399. >
  400. <template slot-scope="scope">
  401. <el-form-item
  402. label-width="0px"
  403. :prop="'salesOrders.' + scope.$index + '.requiredFormingNum'"
  404. :rules="{
  405. required: true,
  406. message: '请输入要求生产数量',
  407. trigger: 'blur'
  408. }"
  409. class="table-item"
  410. >
  411. <el-input
  412. v-model.number="scope.row.requiredFormingNum"
  413. size="small"
  414. disabled
  415. oninput="value=value.replace(/[^\d]/g,'')"
  416. style="width: 100%"
  417. placeholder="输入数量"
  418. ></el-input>
  419. </el-form-item>
  420. </template>
  421. </el-table-column>
  422. <el-table-column
  423. label="模数"
  424. align="center"
  425. width="100"
  426. v-if="clientEnvironmentId == '4'"
  427. >
  428. <template slot-scope="scope">
  429. <div>
  430. <el-input
  431. style="width: 100%"
  432. size="small"
  433. v-model="scope.row.moCount"
  434. oninput="value=value.replace(/[^0-9.]/g,'')"
  435. @input="
  436. tableHandleKeyUp(scope.row, scope.$index, $event, 'moCount')
  437. "
  438. placeholder="请输入"
  439. >
  440. </el-input>
  441. </div>
  442. </template>
  443. </el-table-column>
  444. <el-table-column
  445. align="center"
  446. width="100"
  447. v-if="clientEnvironmentId == '4'"
  448. >
  449. <template slot="header">
  450. <span style="color: red">*</span>
  451. <span>块数</span>
  452. </template>
  453. <template slot-scope="scope">
  454. <div>
  455. <el-input
  456. size="small"
  457. style="width: 100%"
  458. oninput="value=value.replace(/[^0-9.]/g,'')"
  459. @input="
  460. tableHandleKeyUp(
  461. scope.row,
  462. scope.$index,
  463. $event,
  464. 'blockCount'
  465. )
  466. "
  467. v-model="scope.row.blockCount"
  468. placeholder="请输入"
  469. ></el-input>
  470. </div>
  471. </template>
  472. </el-table-column>
  473. <el-table-column
  474. label="权重等级"
  475. align="center"
  476. width="120"
  477. v-if="clientEnvironmentId == '4'"
  478. >
  479. <template slot-scope="scope">
  480. <div>
  481. <el-select v-model="scope.row.weight" style="width: 100%">
  482. <el-option
  483. v-for="item of weightList"
  484. :key="item.code"
  485. :label="item.name"
  486. :value="item.code"
  487. ></el-option>
  488. </el-select>
  489. </div>
  490. </template>
  491. </el-table-column>
  492. <el-table-column
  493. align="center"
  494. width="120"
  495. label="是否开槽"
  496. v-if="clientEnvironmentId == '4'"
  497. >
  498. <template slot-scope="scope">
  499. <div>
  500. <el-select
  501. style="width: 100%"
  502. v-model="scope.row.isSlotting"
  503. placeholder="请选择"
  504. >
  505. <el-option
  506. v-for="item of isSlotting"
  507. :key="item.code"
  508. :label="item.name"
  509. :value="item.code"
  510. />
  511. </el-select>
  512. </div>
  513. </template>
  514. </el-table-column>
  515. <el-table-column
  516. align="center"
  517. width="120"
  518. label="开槽类型"
  519. v-if="clientEnvironmentId == '4'"
  520. >
  521. <template slot-scope="scope">
  522. <DictSelection
  523. dictName="开槽类型"
  524. v-model="scope.row.slottingType"
  525. v-if="scope.row.isSlotting == 1"
  526. >
  527. </DictSelection>
  528. </template>
  529. </el-table-column>
  530. <el-table-column
  531. label="按单按库"
  532. align="center"
  533. prop="orderLibraryType"
  534. >
  535. <template slot-scope="{ row }">
  536. {{ getDictValue('按单按库', row.orderLibraryType) }}
  537. </template>
  538. </el-table-column>
  539. <el-table-column label="订单类型" align="center" prop="orderType">
  540. <template slot-scope="{ row }">
  541. {{ getDictValue('订单类型', row.orderType) }}
  542. </template>
  543. </el-table-column>
  544. <el-table-column
  545. label="客户期望交期"
  546. align="center"
  547. prop="deliveryTime"
  548. width="160"
  549. >
  550. <template slot-scope="scope">
  551. <el-form-item
  552. label-width="0px"
  553. :prop="'salesOrders.' + scope.$index + '.deliveryTime'"
  554. :rules="{
  555. required: true,
  556. message: '请选择客户期望交期',
  557. trigger: 'blur'
  558. }"
  559. class="table-item"
  560. >
  561. <el-date-picker
  562. style="width: 100%"
  563. v-model="scope.row.deliveryTime"
  564. @change="changeDate(scope.row, scope.$index)"
  565. :pickerOptions="{
  566. disabledDate: (time) =>
  567. time.getTime() <
  568. new Date(new Date().setHours(0, 0, 0, 0)).getTime()
  569. }"
  570. type="date"
  571. placeholder="选择日期"
  572. value-format="yyyy-MM-dd"
  573. >
  574. </el-date-picker>
  575. </el-form-item>
  576. </template>
  577. </el-table-column>
  578. <el-table-column label="生产交期" align="center" width="160">
  579. <template slot-scope="scope">
  580. <el-form-item
  581. label-width="0px"
  582. :rules="{
  583. required: true,
  584. message: '请选择生产交期',
  585. trigger: 'blur'
  586. }"
  587. class="table-item"
  588. >
  589. <el-date-picker
  590. style="width: 100%"
  591. v-model="scope.row.produceDeliveryDeadline"
  592. @change="changeDate(scope.row, scope.$index)"
  593. :pickerOptions="{
  594. disabledDate: (time) =>
  595. time.getTime() <
  596. new Date(new Date().setHours(0, 0, 0, 0)).getTime()
  597. }"
  598. type="date"
  599. placeholder="选择日期"
  600. value-format="yyyy-MM-dd"
  601. disabled
  602. >
  603. </el-date-picker>
  604. </el-form-item>
  605. </template>
  606. </el-table-column>
  607. <el-table-column
  608. label="要求完成日期"
  609. align="center"
  610. prop="reqMoldTime"
  611. width="180"
  612. >
  613. <template slot-scope="scope">
  614. <el-form-item
  615. label-width="0px"
  616. :prop="'salesOrders.' + scope.$index + '.reqMoldTime'"
  617. :rules="{
  618. required: true,
  619. message: '请选择要求完成日期',
  620. trigger: 'blur'
  621. }"
  622. class="table-item"
  623. >
  624. <el-date-picker
  625. style="width: 100%"
  626. v-model="scope.row.reqMoldTime"
  627. :pickerOptions="{
  628. disabledDate: (time) =>
  629. time.getTime() <
  630. new Date(new Date().setHours(0, 0, 0, 0)).getTime()
  631. }"
  632. type="date"
  633. disabled
  634. placeholder="选择日期"
  635. value-format="yyyy-MM-dd"
  636. >
  637. </el-date-picker>
  638. </el-form-item>
  639. </template>
  640. </el-table-column>
  641. <el-table-column label="客户名称" align="center" prop="customerName">
  642. </el-table-column>
  643. <el-table-column label="业务员" align="center" prop="salesman">
  644. </el-table-column>
  645. <el-table-column
  646. label="交付要求"
  647. align="center"
  648. prop="deliveryRequirements"
  649. >
  650. <template slot-scope="{ row }">
  651. {{ getDictValue('交付要求', row.deliveryRequirements) }}
  652. </template>
  653. </el-table-column>
  654. <el-table-column
  655. prop="priority"
  656. label="优先级"
  657. width="100"
  658. align="center"
  659. >
  660. <template slot-scope="{ row, $index }">
  661. <div style="display: flex">
  662. <el-input
  663. v-if="$index == 0"
  664. v-model="row.priority"
  665. type="number"
  666. size="mini"
  667. :min="0"
  668. :max="10"
  669. @change="priorityChange(row)"
  670. style="width: 80px"
  671. ></el-input>
  672. <el-popover
  673. v-if="$index == 0"
  674. placement="right"
  675. width="200"
  676. trigger="hover"
  677. content="数值越大优先级越高(0-3普通, 4-6优先, 7-10紧急)"
  678. >
  679. <div class="sort-wrap" slot="reference">
  680. <i class="el-icon-caret-top" @click="sortTop(row)"></i>
  681. <i
  682. class="el-icon-caret-bottom"
  683. @click="sortBottom(row)"
  684. ></i>
  685. </div>
  686. </el-popover>
  687. </div>
  688. </template>
  689. </el-table-column>
  690. <el-table-column label="操作" align="center" width="70" fixed="right">
  691. <template slot-scope="scope">
  692. <el-button
  693. type="text"
  694. @click="handleDeleteItem(scope.$index)"
  695. v-if="type != 'edit'"
  696. >删除</el-button
  697. >
  698. </template>
  699. </el-table-column>
  700. </el-table>
  701. <div class="add-product" @click="addEquipment" v-if="type != 'edit'">
  702. <i class="el-icon-circle-plus-outline"></i>
  703. </div>
  704. <el-row :gutter="24">
  705. <el-col v-bind="styleResponsive ? { lg: 24, md: 24 } : { span: 24 }">
  706. <el-form-item label="计划备注:">
  707. <el-input
  708. type="textarea"
  709. :rows="4"
  710. v-model="form.notes"
  711. resize="none"
  712. ></el-input>
  713. </el-form-item>
  714. </el-col>
  715. </el-row>
  716. </el-form>
  717. <AdditionalOrder
  718. ref="additionalRefs"
  719. :productCode="form.productCode"
  720. :selectList="form.salesOrders"
  721. @choose="confirmChoose"
  722. ></AdditionalOrder>
  723. <ProductionVersion
  724. ref="versionRefs"
  725. @changeProduct="changeProduct"
  726. ></ProductionVersion>
  727. <PlanSubmit
  728. ref="submitRefs"
  729. :type="$route.query.type"
  730. :info="form"
  731. @publish="publishData"
  732. ></PlanSubmit>
  733. <ProcessRoute ref="processRouteRef" @changeParent="changeParent" />
  734. </el-card>
  735. </div>
  736. </template>
  737. <script>
  738. import validDate from '@/utils/date';
  739. import AdditionalOrder from './components/AdditionalOrder.vue';
  740. import PlanSubmit from './components/plan-submit.vue';
  741. import ProductionVersion from '@/components/CreatePlan/ProductionVersion2.vue';
  742. import ProcessRoute from '@/components/selectionDialog/processRoute.vue';
  743. import {
  744. productionToPlan,
  745. saveSaleToPlan,
  746. updateSaleToPlan,
  747. releaseSave,
  748. getInventory,
  749. getUpdateInfoById,
  750. bomRoutingList,
  751. bomListByPlan,
  752. getFactoryList,
  753. getInventoryTotalAPI
  754. } from '@/api/saleOrder';
  755. import { getByCode } from '@/api/system/dictionary-data';
  756. import { parameterGetByCode } from '@/api/mainData/index';
  757. import dictMixins from '@/mixins/dictMixins';
  758. import { deepClone } from '@/utils/index';
  759. import { getRouteTabKey, removePageTab } from '@/utils/page-tab-util';
  760. import { getCode } from '@/api/codeManagement';
  761. import dayjs from 'dayjs';
  762. import { debounce } from 'lodash';
  763. export default {
  764. mixins: [dictMixins],
  765. components: {
  766. AdditionalOrder,
  767. ProductionVersion,
  768. PlanSubmit,
  769. ProcessRoute
  770. },
  771. data() {
  772. return {
  773. type: this.$route.query.type,
  774. weightList: [
  775. { code: 1, name: 'A' },
  776. { code: 2, name: 'B' },
  777. { code: 3, name: 'C' }
  778. ],
  779. isSlotting: [
  780. { code: 1, name: '是' },
  781. { code: 2, name: '否' }
  782. ], //是否开槽
  783. producedList: [
  784. { code: 2, name: '加工(MBOM)' }, //2 待确认
  785. { code: 3, name: '装配(ABOM)' }
  786. ],
  787. form: {
  788. planType: 1,
  789. produceRoutingId: '',
  790. stockCountBase: '',
  791. salesOrders: [],
  792. produceRoutingName: '',
  793. marginCoefficient: '1.0',
  794. batchNo: null,
  795. produceType: '',
  796. bomCategoryId: null,
  797. factoriesId: '',
  798. startTime: '',
  799. endTime: ''
  800. },
  801. marginList: [],
  802. bomVersionList: [],
  803. routingList: [],
  804. init: '1',
  805. factoryList: [],
  806. // 表单验证规则
  807. rules: {
  808. produceRoutingId: [
  809. { required: true, message: '请选择工艺路线', trigger: 'blur' }
  810. ],
  811. // startTime: [
  812. // {
  813. // type: 'date',
  814. // required: true,
  815. // message: '请选择计划开始日期',
  816. // trigger: 'change'
  817. // }
  818. // ],
  819. // endTime: [
  820. // {
  821. // type: 'date',
  822. // required: true,
  823. // message: '请选择计划结束日期',
  824. // trigger: 'change'
  825. // }
  826. // ],
  827. // produceType: [
  828. // { required: true, message: '请选择生产类型', trigger: 'blur' }
  829. // ],
  830. // bomCategoryId: [
  831. // { required: true, message: '请选择BOM版本', trigger: 'blur' }
  832. // ],
  833. factoriesId: [
  834. { required: true, message: '请选择所属工厂', trigger: 'change' }
  835. ]
  836. },
  837. // selection: [],
  838. loading: false,
  839. processingRequired: 0, // 生产类型跟BOM 版本是否必填 1:是 0:否
  840. selectionRowShow: false, // 工艺路线输入框展示 状态
  841. validDate
  842. };
  843. },
  844. props: {
  845. objData: {
  846. type: Object,
  847. default: {}
  848. }
  849. },
  850. watch: {
  851. objData: {
  852. handler(val) {
  853. this.requestDict('按单按库');
  854. this.requestDict('订单类型');
  855. this.requestDict('交付要求');
  856. this.getByCodeFn();
  857. this.getFactoryList();
  858. // 查询库存数量
  859. // this.inventory(val.id);
  860. if (val.type == 'edit') {
  861. this.getPlanInfo(val.id);
  862. } else {
  863. this.getSaleInfo();
  864. }
  865. },
  866. deep: true,
  867. immediate: true
  868. },
  869. 'form.produceType'(newVal, oldVal) {
  870. console.log(newVal, '值');
  871. },
  872. form: {
  873. handler(newVal) {
  874. console.log(newVal, 'newVal 33');
  875. },
  876. deep: true,
  877. immediate: true
  878. }
  879. },
  880. mounted() {
  881. this.mandatoryField();
  882. },
  883. computed: {
  884. clientEnvironmentId() {
  885. return this.$store.state.user.info.clientEnvironmentId;
  886. },
  887. // 是否开启响应式布局
  888. styleResponsive() {
  889. return this.$store.state.theme.styleResponsive;
  890. },
  891. // 是否必填字段
  892. isRequired() {
  893. // if (this.form.planType == 5) {
  894. // return false;
  895. // }
  896. return this.processingRequired == 1;
  897. },
  898. // 工艺路线 输入框展示跟选择框判断
  899. isRouteSelect() {
  900. if (this.isRequired) {
  901. return true;
  902. }
  903. if (!this.selectionRowShow) {
  904. return true;
  905. }
  906. return false;
  907. },
  908. // 选择按钮的显示
  909. isSelectShow() {
  910. // if (this.form.planType == 5) {
  911. // return true;
  912. // }
  913. return this.processingRequired == 0;
  914. }
  915. },
  916. methods: {
  917. // 初始化时间赋值
  918. initTime() {
  919. let data = this.$route.query;
  920. if (data.startTime) {
  921. this.$set(this.form, 'startTime', data.startTime);
  922. }
  923. if (data.endTime) {
  924. this.$set(this.form, 'endTime', data.endTime);
  925. }
  926. },
  927. // 是否必填
  928. mandatoryField() {
  929. parameterGetByCode({
  930. code: 'production_plan_code'
  931. }).then((res) => {
  932. if (res) {
  933. this.processingRequired = res.value;
  934. }
  935. });
  936. },
  937. // 查询库存数量
  938. inventory(id) {},
  939. // 验证时间是否超期
  940. changeDate(item, i) {
  941. if (this.isTimeAGreaterThanB(item.deliveryTime, item.reqMoldTime)) {
  942. this.$message.error('交付时间大于了要求完成日期');
  943. }
  944. },
  945. isTimeAGreaterThanB(timeA, timeB) {
  946. return new Date(timeA) > new Date(timeB);
  947. },
  948. async getFactoryList() {
  949. this.factoryList = await getFactoryList();
  950. this.$nextTick(() => {
  951. this.form.factoriesId = this.factoryList[0].id;
  952. });
  953. },
  954. async getPlanInfo(id) {
  955. const data = await getUpdateInfoById(id);
  956. console.log(data, '订单的data');
  957. console.log(11111111111111111111111111111);
  958. this.form = data;
  959. this.initTime();
  960. // if (data.startTime) {
  961. // this.form.startTime = new Date(data.startTime);
  962. // }
  963. // if (data.endTime) {
  964. // this.form.endTime = new Date(data.endTime);
  965. // }
  966. if (!data.bomCategoryId || data.bomCategoryId == null) {
  967. this.form.produceType = '';
  968. this.selectionRowShow = true;
  969. } else {
  970. this.selectionRowShow = false;
  971. }
  972. if (data.salesOrders && data.salesOrders.length > 0) {
  973. this.form.factoriesId = data.salesOrders[0].factoriesId;
  974. }
  975. // this.form.factoriesId = data.salesOrders
  976. // ? data.salesOrders[0].factoriesId
  977. // : '';
  978. if (this.clientEnvironmentId != 4) {
  979. this.bomListVersion();
  980. // this.getPlanRouting();
  981. }
  982. this._getInventory();
  983. },
  984. async _getInventory() {
  985. let code = [this.form.productCode];
  986. const res = await getInventoryTotalAPI(code);
  987. this.form.stockCountBase = res[0].stockCountBase;
  988. },
  989. getByCodeFn() {
  990. getByCode('margin_code').then((res) => {
  991. let _arr = [];
  992. res.data.map((item) => {
  993. const key = Object.keys(item)[0];
  994. const value = item[key];
  995. _arr.push({ name: key, value: value });
  996. });
  997. this.marginList = _arr;
  998. });
  999. },
  1000. getPlanRouting() {
  1001. if (this.form.bomCategoryId && this.form.bomCategoryId != 'null') {
  1002. bomRoutingList(this.form.bomCategoryId).then((res) => {
  1003. this.routingList = res || [];
  1004. if (res.length) {
  1005. let id = this.$route.query.produceRoutingId
  1006. ? this.$route.query.produceRoutingId
  1007. : res[0].id;
  1008. this.$nextTick(() => {
  1009. let arr = this.routingList.filter((item) => {
  1010. return item.id == id;
  1011. });
  1012. if (arr.length > 0) {
  1013. this.$set(this.form, 'produceRoutingId', id);
  1014. }
  1015. });
  1016. }
  1017. });
  1018. }
  1019. },
  1020. bomListVersion(type) {
  1021. console.log(type,'type 传递的参数 33')
  1022. let categoryId = '';
  1023. if (this.form.salesOrders.length) {
  1024. categoryId = this.form.salesOrders[0].categoryId;
  1025. } else if (this.form.categoryId) {
  1026. categoryId = this.form.categoryId;
  1027. } else {
  1028. new Error('缺少产品信息');
  1029. }
  1030. let param = {
  1031. bomType: this.form.produceType || null,
  1032. categoryId: categoryId
  1033. };
  1034. bomListByPlan(param).then((res) => {
  1035. this.bomVersionList = res || [];
  1036. if (res.length) {
  1037. let o = res[0];
  1038. if (type == 'init') {
  1039. let query = this.$route.query;
  1040. let id = query.bomCategoryId ? query.bomCategoryId : o.id;
  1041. this.$set(this.form, 'bomCategoryId', id);
  1042. } else {
  1043. this.$set(this.form, 'bomCategoryId', o.id);
  1044. }
  1045. this.changeBomId();
  1046. }
  1047. });
  1048. },
  1049. changeProduceType(type) {
  1050. if (this.clientEnvironmentId == 4) {
  1051. return false;
  1052. }
  1053. this.form.bomCategoryId = null;
  1054. this.form['bomCategoryName'] = '';
  1055. this.form['bomCategoryVersions'] = '';
  1056. this.bomVersionList = [];
  1057. this.routingList = [];
  1058. this.form.produceRoutingId = '';
  1059. this.form.produceRoutingName = '';
  1060. this.form.produceVersionName = '';
  1061. this.selectionRowShow = false; // ****
  1062. this.bomListVersion(type);
  1063. },
  1064. changeBomId() {
  1065. this.routingList = [];
  1066. this.form.produceRoutingId = '';
  1067. this.form.produceRoutingName = '';
  1068. this.form.produceVersionName = '';
  1069. if (this.bomVersionList.length == 0) {
  1070. this.form.bomCategoryId = '';
  1071. }
  1072. this.bomVersionList.forEach((f) => {
  1073. if (f.id == this.form.bomCategoryId) {
  1074. this.$set(this.form, 'bomCategoryName', f.name);
  1075. this.$set(this.form, 'bomCategoryVersions', f.versions);
  1076. }
  1077. });
  1078. this.getPlanRouting();
  1079. },
  1080. changeRoute() {
  1081. this.$forceUpdate();
  1082. this.routingList.forEach((f) => {
  1083. if (f.id == this.form.produceRoutingId) {
  1084. this.$set(this.form, 'produceRoutingName', f.name);
  1085. this.$set(this.form, 'produceVersionName', f.version);
  1086. }
  1087. });
  1088. },
  1089. getSaleInfo() {
  1090. let params = JSON.parse(this.$route.query.selection);
  1091. productionToPlan(params).then((res) => {
  1092. console.log(this.$route.query);
  1093. this.form = deepClone(res);
  1094. console.log(222222222222222222222222, '===');
  1095. this.initTime();
  1096. // this.bomListVersion('init');
  1097. this.form.produceRoutingName =
  1098. res.produceRoutingName || this.$route.query.produceRoutingName;
  1099. this.form.produceRoutingId =
  1100. res.produceRoutingId || this.$route.query.produceRoutingId;
  1101. this.form.factoriesId =
  1102. res.factoriesId || this.$route.query.factoriesId;
  1103. // this.form.produceType =
  1104. // res.produceType || this.$route.query.produceType
  1105. // ? parseInt(this.$route.query.produceType)
  1106. // : null;
  1107. this.form.produceType = this.$route.query.produceType
  1108. ? parseInt(this.$route.query.produceType)
  1109. : res.produceType;
  1110. this.changeProduceType('init');
  1111. this.form.bomCategoryId =
  1112. res.bomCategoryId || this.$route.query.bomCategoryId;
  1113. // this.changeBomId();
  1114. if (this.clientEnvironmentId == '4') {
  1115. if (this.form.salesOrders[0].productName.includes('板材')) {
  1116. this.changeProduct({
  1117. id: '1856970794952372226',
  1118. name: '板材',
  1119. produceVersionName: '板材'
  1120. });
  1121. } else {
  1122. this.changeProduct({
  1123. id: '1857313733642596353',
  1124. name: '砌块',
  1125. produceVersionName: '砌块'
  1126. });
  1127. }
  1128. }
  1129. this.form.salesOrders.map((item, index) => {
  1130. if (this.clientEnvironmentId == '4') {
  1131. this.tableHandleKeyUp(item, '', item.lackNum, 'sum');
  1132. } else {
  1133. item.planProductNum = item.lackNum;
  1134. item.requiredFormingNum = item.lackNum;
  1135. }
  1136. item.slottingType = item.slottingType && item.slottingType + '';
  1137. item.priority = index + 1;
  1138. item.reqMoldTime = item.deliveryTime;
  1139. // dayjs(
  1140. // new Date(item.deliveryTime).getTime() - 3600 * 1000 * 24 * 10
  1141. // ).format('YYYY-MM-DD');
  1142. });
  1143. if (this.form.salesOrders.every((itm) => itm.orderType == 2)) {
  1144. this.form.planType = 2;
  1145. } else if (this.form.salesOrders.every((itm) => itm.orderType == 1)) {
  1146. this.form.planType = 1;
  1147. } else {
  1148. this.form.planType = 3;
  1149. }
  1150. this._getInventory();
  1151. });
  1152. this.$forceUpdate();
  1153. },
  1154. itemChange() {
  1155. this.form.salesOrders.map((item, index) => {
  1156. this.$set(
  1157. item,
  1158. 'requiredFormingNum',
  1159. item.planProductNum * (this.form.marginCoefficient || 1)
  1160. );
  1161. });
  1162. },
  1163. factoriesIdFn(e) {
  1164. this.$forceUpdate();
  1165. },
  1166. toInt(planProductNum) {
  1167. return planProductNum * (this.form.marginCoefficient || 1);
  1168. },
  1169. cancel() {
  1170. const key = getRouteTabKey();
  1171. // this.$router.go(-1);
  1172. removePageTab({ key });
  1173. this.$emit('cancel');
  1174. },
  1175. toSubmit() {
  1176. if (!this.form.factoriesId)
  1177. return this.$message.warning('请选择所属工厂');
  1178. this.form.salesOrders.map((v) => {
  1179. let arrTime = v.deliveryTime && v.deliveryTime.split(' ');
  1180. let arrTimeTow =
  1181. v.produceDeliveryDeadline && v.produceDeliveryDeadline.split(' ');
  1182. v.deliveryTime = arrTime && arrTime[0];
  1183. v.produceDeliveryDeadline = arrTimeTow && arrTimeTow[0];
  1184. // if(v.salesOrders)
  1185. });
  1186. if (this.form.produceType) {
  1187. //查询生产类型
  1188. this.form.produceVersionName = this.producedList.find(
  1189. (v) => v.code == this.form.produceType
  1190. )?.name;
  1191. }
  1192. if (this.form.produceRoutingId && !this.form.produceRoutingName) {
  1193. //查询工艺路线
  1194. this.form.produceRoutingName = this.routingList.find(
  1195. (v) => v.id == this.form.produceRoutingId
  1196. ).name;
  1197. }
  1198. if (this.form.factoriesId) {
  1199. //查询工厂名称
  1200. this.form.factoriesIdName = this.factoryList.find(
  1201. (v) => v.id == this.form.factoriesId
  1202. )?.name;
  1203. }
  1204. // let data = this.form.salesOrders[0];
  1205. if (this.form.salesOrders.length > 1) {
  1206. //多条订单时,拼接批次号(订单数量)
  1207. let arr = [];
  1208. this.form.salesOrders.map((v) => {
  1209. if (v.batchNo) {
  1210. arr.push(v.batchNo);
  1211. }
  1212. });
  1213. this.form.batchNo = arr.toString();
  1214. } else {
  1215. // ((data.productSumWeight /contractNum) * data.planProductNum).toFixed(2);
  1216. this.form.batchNo = this.form.salesOrders[0].batchNo;
  1217. }
  1218. let newSumOrderWeight = 0;
  1219. this.form.salesOrders &&
  1220. this.form.salesOrders.map((el) => {
  1221. let total = (
  1222. (el.productSumWeight / el.contractNum) *
  1223. el.planProductNum
  1224. ).toFixed(2);
  1225. newSumOrderWeight = newSumOrderWeight + (total - 0);
  1226. });
  1227. this.form.newSumOrderWeight = newSumOrderWeight;
  1228. let flag = this.parameterVerification();
  1229. // 必填参数校验
  1230. if (!flag) return;
  1231. this.$refs.form.validate((valid) => {
  1232. if (valid) {
  1233. this.mapList();
  1234. this.$refs.submitRefs.open();
  1235. }
  1236. });
  1237. },
  1238. // 参数校验
  1239. parameterVerification() {
  1240. let flag = true;
  1241. if (!this.form.startTime) {
  1242. this.$message.warning('请选择计划开始时间');
  1243. return false;
  1244. }
  1245. if (!this.form.endTime) {
  1246. this.$message.warning('请选择计划结束时间');
  1247. return false;
  1248. }
  1249. if (this.isRequired) {
  1250. if (!this.form.produceType) {
  1251. flag = false;
  1252. this.$message.warning('请选择生产类型');
  1253. return;
  1254. }
  1255. if (!this.form.bomCategoryId) {
  1256. flag = false;
  1257. this.$message.warning('请选择BOM版本');
  1258. return;
  1259. }
  1260. }
  1261. if (!this.form.produceRoutingId) {
  1262. flag = false;
  1263. this.$message.warning('请选择工艺路线');
  1264. return;
  1265. }
  1266. return flag;
  1267. },
  1268. // 对比日期,计算要求生产重量
  1269. mapList() {
  1270. var _sumOrderWeight = 0;
  1271. var requiredFormingNum = 0;
  1272. var productNum = 0;
  1273. this.form.salesOrders.map((item, index) => {
  1274. requiredFormingNum =
  1275. Number(requiredFormingNum) + Number(item.requiredFormingNum);
  1276. if (
  1277. this.form.weightUnit == 'G' ||
  1278. this.form.weightUnit == 'g' ||
  1279. this.form.weightUnit == '克'
  1280. ) {
  1281. this.form.newWeightUnit = 'kg';
  1282. _sumOrderWeight =
  1283. (this.form.salesOrders[0].requiredFormingNum *
  1284. Number(this.form.salesOrders[0].productUnitWeight || 1)) /
  1285. 1000;
  1286. } else {
  1287. this.form.newWeightUnit = this.form.weightUnit;
  1288. _sumOrderWeight =
  1289. this.form.salesOrders[0].requiredFormingNum *
  1290. Number(this.form.salesOrders[0].productUnitWeight || 1);
  1291. }
  1292. productNum += Number(item.planProductNum);
  1293. });
  1294. this.form.productNum = productNum;
  1295. this.form.productUnitWeight =
  1296. this.form.salesOrders[0]?.productUnitWeight;
  1297. // this.form.newSumOrderWeight = _sumOrderWeight.toFixed(2);
  1298. this.form.requiredFormingNum = requiredFormingNum;
  1299. const collection = deepClone(this.form.salesOrders);
  1300. const sortedCollection = collection.sort(
  1301. (a, b) => new Date(b.reqMoldTime) - new Date(a.reqMoldTime)
  1302. );
  1303. let latestData = {};
  1304. for (let i = 0; i < sortedCollection.length; i++) {
  1305. const data = sortedCollection[i];
  1306. if (
  1307. !latestData.reqMoldTime ||
  1308. new Date(data.reqMoldTime) >= new Date(latestData.reqMoldTime)
  1309. ) {
  1310. latestData = data;
  1311. }
  1312. }
  1313. this.form.reqMoldTime = latestData.reqMoldTime;
  1314. },
  1315. sortTop(row) {
  1316. row.priority = Number(row.priority) + 1;
  1317. this.priorityChange(row);
  1318. },
  1319. sortBottom(row) {
  1320. if (row.priority <= 1) {
  1321. return;
  1322. }
  1323. row.priority = Number(row.priority) - 1;
  1324. this.priorityChange(row);
  1325. },
  1326. priorityChange(row) {
  1327. if (row.priority > 10) {
  1328. row.priority = 10; // 如果大于 10,则设置为 10
  1329. } else if (row.priority < 0) {
  1330. row.priority = 0; // 如果小于 0,则设置为 0
  1331. }
  1332. this.priorityFn(row);
  1333. },
  1334. priorityFn: debounce(function (row) {}, 800),
  1335. // 删除产品
  1336. handleDeleteItem(index) {
  1337. this.form.salesOrders.splice(index, 1);
  1338. this.changeData();
  1339. },
  1340. addEquipment() {
  1341. this.$refs.additionalRefs.open(this.form.planType);
  1342. },
  1343. openVersion() {
  1344. this.$refs.versionRefs.open();
  1345. },
  1346. changeProduct(data) {
  1347. this.$set(this.form, 'produceRoutingName', data.name);
  1348. this.$set(this.form, 'produceRoutingId', data.id);
  1349. this.$set(this.form, 'produceVersionName', data.produceVersionName);
  1350. },
  1351. // 表格:模数、数量(方)、块数输入框 输入事件
  1352. tableHandleKeyUp(row, index, e, name) {
  1353. if (row.specification && this.clientEnvironmentId == '4') {
  1354. let modelArr = row.specification.split('*');
  1355. let modelLong = modelArr[0]; // model规格长度
  1356. let modeWide = modelArr[1]; // model规格宽度
  1357. let modeHight = modelArr[2].substr(0, modelArr[2].indexOf('cm')); // model规格高度
  1358. modeHight = Number(modeHight);
  1359. if (name === 'moCount') {
  1360. // 模数
  1361. row.moCount = e;
  1362. // 计算块数的公式:
  1363. // (一模6米长度 / model规格长度) * (一模1.2米宽度 / model规格宽度) = 每一模的块数
  1364. // 每一模的块数*模数moCount = 总块数
  1365. if (row.productName.includes('板材')) {
  1366. row.blockCount =
  1367. Math.floor(600 / modelLong) *
  1368. Math.floor(120 / modeHight) *
  1369. Math.floor(60 / modeWide) *
  1370. row.moCount;
  1371. } else if (row.productName.includes('砌块')) {
  1372. let modelLongFixed = (600 / modelLong).toFixed(2);
  1373. modelLongFixed = modelLongFixed.substring(
  1374. 0,
  1375. modelLongFixed.length - 1
  1376. );
  1377. let modeWideFixed = (120 / modeWide).toFixed(2);
  1378. modeWideFixed = modeWideFixed.substring(
  1379. 0,
  1380. modeWideFixed.length - 1
  1381. );
  1382. let modeHightFixed = (60 / modeHight).toFixed(2);
  1383. modeHightFixed = modeHightFixed.substring(
  1384. 0,
  1385. modeHightFixed.length - 1
  1386. );
  1387. row.blockCount =
  1388. Math.floor(modelLongFixed * modeWideFixed * modeHightFixed) *
  1389. row.moCount;
  1390. }
  1391. row.planProductNum =
  1392. Number((modelLong * modeWide * modeHight) / 1000000).toFixed(5) *
  1393. row.blockCount;
  1394. } else if (name === 'sum') {
  1395. //方数
  1396. row.planProductNum = e;
  1397. row.blockCount = Math.floor(
  1398. e / ((modelLong * modeWide * modeHight) / 1000000)
  1399. );
  1400. if (row.productName.includes('板材')) {
  1401. row.moCount = Math.ceil(
  1402. row.blockCount /
  1403. (Math.floor(600 / modelLong) *
  1404. Math.floor(120 / modeHight) *
  1405. Math.floor(60 / modeWide))
  1406. );
  1407. } else if (row.productName.includes('砌块')) {
  1408. row.moCount = Math.ceil(
  1409. row.blockCount /
  1410. Math.floor(
  1411. (600 / modelLong) * (120 / modeHight) * (60 / modeWide)
  1412. )
  1413. );
  1414. }
  1415. } else if (name === 'blockCount') {
  1416. //块数
  1417. row.blockCount = e;
  1418. if (row.productName.includes('板材')) {
  1419. row.moCount = Math.ceil(
  1420. row.blockCount /
  1421. (Math.floor(600 / modelLong) *
  1422. Math.floor(120 / modeHight) *
  1423. Math.floor(60 / modeWide))
  1424. );
  1425. } else if (row.productName.includes('砌块')) {
  1426. row.moCount = Math.ceil(
  1427. row.blockCount /
  1428. Math.floor(
  1429. (600 / modelLong) * (120 / modeHight) * (60 / modeWide)
  1430. )
  1431. );
  1432. }
  1433. row.planProductNum =
  1434. (Number(e) * modelLong * modeWide * modeHight) / 1000000;
  1435. }
  1436. }
  1437. row.requiredFormingNum = Number(
  1438. row.planProductNum * (this.form.marginCoefficient || 1)
  1439. ).toFixed(5);
  1440. },
  1441. confirmChoose(list) {
  1442. // 取出在弹窗中选中并且不在表格中的数据
  1443. const result = list.filter(
  1444. (i) => this.form.salesOrders.findIndex((p) => p.id === i.id) === -1
  1445. );
  1446. // 取出在表格中并且不在弹窗中选中的数据 即取消选中的数据
  1447. const del = this.form.salesOrders.filter(
  1448. (i) => list.findIndex((p) => p.id === i.id) === -1
  1449. );
  1450. for (let i = this.form.salesOrders.length - 1; i >= 0; i--) {
  1451. for (let j in del) {
  1452. if (this.form.salesOrders[i].id === del[j].id) {
  1453. this.form.salesOrders.splice(i, 1);
  1454. }
  1455. }
  1456. }
  1457. let priority =
  1458. this.form.salesOrders[this.form.salesOrders.length - 1]?.priority ||
  1459. 0;
  1460. this.form.salesOrders = this.form.salesOrders.concat(
  1461. result.map((item, index) => {
  1462. item.priority = ++priority;
  1463. item.planProductNum = item.lackNum;
  1464. item.requiredFormingNum = item.lackNum;
  1465. item.reqMoldTime = dayjs(
  1466. new Date(item.deliveryTime).getTime() - 3600 * 1000 * 24 * 10
  1467. ).format('YYYY-MM-DD');
  1468. return item;
  1469. })
  1470. );
  1471. this.changeData();
  1472. },
  1473. changeData() {
  1474. var planProductNum = 0;
  1475. var productWeight = 0;
  1476. this.form.salesOrders.map((item, index) => {
  1477. item.priority = index + 1;
  1478. planProductNum = planProductNum + item.requiredFormingNum;
  1479. productWeight = productWeight + Number(item.productSumWeight);
  1480. });
  1481. this.$set(this.form, 'codeNum', this.form.salesOrders.length);
  1482. this.$set(this.form, 'contractNum', planProductNum);
  1483. this.$set(this.form, 'sumOrderWeight', productWeight.toFixed(2));
  1484. },
  1485. async publishData(type) {
  1486. const key = getRouteTabKey();
  1487. let params = deepClone(this.form);
  1488. params.categoryId = params.salesOrders[0]?.categoryId;
  1489. if (this.$route.query.type != 'edit') {
  1490. delete params.id;
  1491. }
  1492. if (type === 2) {
  1493. this.$confirm('发布工单后不可撤回,确定发布吗?', '发布确认').then(
  1494. async () => {
  1495. const loading = this.$loading({
  1496. lock: true,
  1497. fullscreen: true,
  1498. text: '工单发布中...'
  1499. });
  1500. try {
  1501. const code = await getCode('product_order_code');
  1502. const data = {
  1503. productionPlan: params,
  1504. workOrder: {
  1505. productionPlanCode: params.code,
  1506. code: code,
  1507. // formingNum: params.contractNum,
  1508. formingNum: this.form.requiredFormingNum,
  1509. formingWeight: params.sumOrderWeight,
  1510. produceRoutingId: params.produceRoutingId,
  1511. status: 4,
  1512. model: params.model,
  1513. brandNo: params.brandNo,
  1514. categoryId: params.categoryId,
  1515. productCode: params.productCode,
  1516. productName: params.productName,
  1517. newWeightUnit: this.form.newWeightUnit,
  1518. newSumOrderWeight: this.form.newSumOrderWeight
  1519. }
  1520. };
  1521. if (this.$route.query.type == 'edit') {
  1522. data.workOrder.productionPlanId = params.id;
  1523. }
  1524. await releaseSave(data)
  1525. .then((res) => {
  1526. if (res === 1) {
  1527. this.$message.success('工单已发布!');
  1528. this.$router.push({
  1529. path: '/productionPlan'
  1530. });
  1531. } else {
  1532. this.$confirm(
  1533. '生产计划创建成功,但工单发布失败。请前往【生产计划】列表【重新发布】工单',
  1534. '提示',
  1535. {
  1536. confirmButtonText: '返回',
  1537. cancelButtonText: '立即前往',
  1538. type: 'warning'
  1539. }
  1540. )
  1541. .then(() => {
  1542. this.$router.push({
  1543. path: '/productionPlan'
  1544. });
  1545. })
  1546. .catch(() => {
  1547. this.$router.go(-1);
  1548. });
  1549. }
  1550. removePageTab({ key });
  1551. })
  1552. .catch(() => {
  1553. this.$message.error('发布失败,请重新发布!');
  1554. });
  1555. } catch (error) {}
  1556. loading.close();
  1557. }
  1558. );
  1559. } else {
  1560. let request =
  1561. this.$route.query.type == 'edit'
  1562. ? updateSaleToPlan
  1563. : saveSaleToPlan;
  1564. request(params)
  1565. .then(async (res) => {
  1566. // 提交
  1567. this.$router.push({
  1568. path: '/productionPlan'
  1569. });
  1570. removePageTab({ key });
  1571. })
  1572. .catch(() => {
  1573. this.$message.error('提交失败,请重新提交!');
  1574. });
  1575. }
  1576. },
  1577. // 打开工艺路线
  1578. openDialog() {
  1579. // this.selectIndex = index;
  1580. this.$refs.processRouteRef.open();
  1581. },
  1582. // 选择工艺路线
  1583. changeParent(item) {
  1584. this.routingList = [];
  1585. this.bomVersionList = [];
  1586. this.$set(this.form, 'bomCategoryId', null);
  1587. this.$set(this.form, 'model', '');
  1588. this.$set(this.form, 'produceType', '');
  1589. this.$set(this.form, 'produceRoutingName', item.name);
  1590. this.$set(this.form, 'produceRoutingId', item.id);
  1591. this.form.bomCategoryName = '';
  1592. this.form.bomCategoryVersions = '';
  1593. this.selectionRowShow = true;
  1594. },
  1595. // 【开始时间变化时】触发
  1596. handleStartTimeChange(row) {
  1597. this.checkEndTimeValid(row);
  1598. },
  1599. // 【结束时间变化时】触发
  1600. handleEndTimeChange(row) {
  1601. this.checkEndTimeValid(row);
  1602. },
  1603. checkEndTimeValid(row) {
  1604. const { startTime: start, endTime: end } = row;
  1605. if (!start || !end) return; // 开始/结束时间未填,跳过
  1606. const startTime = new Date(start);
  1607. const endTime = new Date(end);
  1608. if (endTime < startTime) {
  1609. row.endTime = new Date(startTime); // 修正为开始时间
  1610. this.$message.info('结束时间不能早于开始时间,已自动设为开始时间');
  1611. }
  1612. }
  1613. }
  1614. };
  1615. </script>
  1616. <style lang="scss" scoped>
  1617. .ele-body {
  1618. background: #fff;
  1619. }
  1620. .body-title {
  1621. width: 100%;
  1622. display: flex;
  1623. align-items: center;
  1624. justify-content: space-between;
  1625. }
  1626. .title-left {
  1627. font-size: 20px;
  1628. color: #333;
  1629. }
  1630. .formbox {
  1631. margin: 20px auto;
  1632. }
  1633. .row-intro {
  1634. border-bottom: 1px dashed #ccc;
  1635. margin-bottom: 20px;
  1636. }
  1637. .add-product {
  1638. width: 100%;
  1639. display: flex;
  1640. align-items: center;
  1641. justify-content: flex-end;
  1642. font-size: 30px;
  1643. color: #1890ff;
  1644. margin: 10px 0;
  1645. cursor: pointer;
  1646. }
  1647. .table-item {
  1648. margin-bottom: 0;
  1649. }
  1650. .header_required {
  1651. position: relative;
  1652. }
  1653. .header_required:before {
  1654. content: '*';
  1655. color: #f56c6c;
  1656. position: absolute;
  1657. top: 11px;
  1658. left: 26px;
  1659. }
  1660. .header_time_required {
  1661. position: relative;
  1662. }
  1663. .header_time_required:before {
  1664. content: '*';
  1665. color: #f56c6c;
  1666. position: absolute;
  1667. top: 11px;
  1668. left: 2px;
  1669. }
  1670. ::v-deep .product_info {
  1671. .el-form-item--medium {
  1672. .el-form-item__label {
  1673. line-height: 26px;
  1674. }
  1675. .el-form-item__content {
  1676. line-height: 26px;
  1677. }
  1678. }
  1679. .product_code_name {
  1680. .el-form-item__content {
  1681. white-space: normal;
  1682. word-break: break-all;
  1683. }
  1684. }
  1685. }
  1686. </style>