salesToProduction.vue 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091
  1. <template>
  2. <div class="ele-body">
  3. <el-card shadow="never">
  4. <div class="body-title">
  5. <div class="title-left">{{type == 'edit' ? '计划修改' : '销售订单转生产计划'}}</div>
  6. <div class="title-right">
  7. <el-button @click="cancel">取消</el-button>
  8. <el-button type="primary" @click="toSubmit" :loading="loading">
  9. 提交计划
  10. </el-button>
  11. </div>
  12. </div>
  13. <el-form
  14. ref="form"
  15. :model="form"
  16. :rules="rules"
  17. label-width="90px"
  18. class="formbox"
  19. >
  20. <el-row :gutter="24">
  21. <el-col v-bind="styleResponsive ? { lg: 4, md: 8 } : { span: 4 }">
  22. <el-form-item label="计划类型:">
  23. <DictSelection
  24. dictName="订单计划类型"
  25. clearable
  26. v-model="form.planType"
  27. disabled
  28. >
  29. </DictSelection>
  30. </el-form-item>
  31. </el-col>
  32. <el-col v-bind="styleResponsive ? { lg: 4, md: 8 } : { span: 4 }">
  33. <el-form-item label="生产方式:" prop="produceType">
  34. <el-select v-model="form.produceType" style="width: 100%" >
  35. <el-option
  36. @click.native="changeProduceType"
  37. v-for="item of producedList"
  38. :key="item.code"
  39. :label="item.name"
  40. :value="item.code"
  41. ></el-option>
  42. </el-select>
  43. </el-form-item>
  44. </el-col>
  45. <el-col v-bind="styleResponsive ? { lg: 5, md: 10 } : { span: 5 }">
  46. <el-form-item label="工艺路线:" prop="produceRoutingId">
  47. <!-- @click.native="openVersion" -->
  48. <el-select v-model="form.produceRoutingId" style="width: 100%" @change="changeRoute">
  49. <el-option
  50. v-for="item of routingList"
  51. :key="item.id"
  52. :label="item.name"
  53. :value="item.id"
  54. ></el-option>
  55. </el-select>
  56. </el-form-item>
  57. </el-col>
  58. <!-- <el-col v-bind="styleResponsive ? { lg: 3, md: 6 } : { span: 3 }">
  59. <el-form-item label="使用改型:" prop="modification">
  60. <el-checkbox
  61. v-model="form.modification"
  62. :true-label="1"
  63. :false-label="0"
  64. ></el-checkbox>
  65. </el-form-item>
  66. </el-col> -->
  67. <el-col v-bind="styleResponsive ? { lg: 4, md: 8 } : { span: 4 }">
  68. <el-form-item label="余量系数:" prop="marginCoefficient">
  69. <el-select
  70. v-model="form.marginCoefficient"
  71. filterable
  72. allow-create
  73. @change="itemChange"
  74. >
  75. <el-option
  76. v-for="(item, index) in marginList"
  77. :key="index"
  78. :label="item.name"
  79. :value="item.value"
  80. />
  81. </el-select>
  82. </el-form-item>
  83. </el-col>
  84. <el-col v-bind="styleResponsive ? { lg: 4, md: 8 } : { span: 4 }">
  85. <el-form-item label="批次号:" prop="batchNo">
  86. <el-input
  87. placeholder="请输入批次号"
  88. v-model="form.batchNo"
  89. ></el-input>
  90. </el-form-item>
  91. </el-col>
  92. </el-row>
  93. <el-row :gutter="24" class="row-intro">
  94. <el-col v-bind="styleResponsive ? { lg: 3, md: 12 } : { span: 3 }">
  95. <el-form-item label="销售单数量:">{{ form.codeNum }}</el-form-item>
  96. </el-col>
  97. <el-col v-bind="styleResponsive ? { lg: 3, md: 12 } : { span: 3 }">
  98. <el-form-item label="订单总数量:">{{
  99. form.contractNum
  100. }}</el-form-item>
  101. </el-col>
  102. <el-col v-bind="styleResponsive ? { lg: 3, md: 12 } : { span: 4 }">
  103. <el-form-item label="订单总重量:">{{
  104. form.sumOrderWeight
  105. }}</el-form-item>
  106. </el-col>
  107. <el-col v-bind="styleResponsive ? { lg: 3, md: 12 } : { span: 3 }">
  108. <el-form-item label="产品编码:">{{
  109. form.productCode
  110. }}</el-form-item>
  111. </el-col>
  112. <el-col v-bind="styleResponsive ? { lg: 3, md: 12 } : { span: 3 }">
  113. <el-form-item label="牌号:">{{ form.brandNo }}</el-form-item>
  114. </el-col>
  115. <el-col v-bind="styleResponsive ? { lg: 4, md: 12 } : { span: 5 }">
  116. <el-form-item label="型号:">{{ form.model }}</el-form-item>
  117. </el-col>
  118. <el-col v-bind="styleResponsive ? { lg: 4, md: 12 } : { span: 3 }">
  119. <el-form-item label="规格:">{{ form.specification }}</el-form-item>
  120. </el-col>
  121. <!--
  122. <el-col v-bind="styleResponsive ? { lg: 3, md: 12 } : { span: 3 }">
  123. <el-form-item label="库存数量:">{{
  124. form.stockCountBase
  125. }}</el-form-item>
  126. </el-col> -->
  127. </el-row>
  128. <el-table :data="form.salesOrders" border>
  129. <el-table-column label="序号" align="center" width="60">
  130. <template slot-scope="scope">
  131. <span>{{ scope.$index + 1 }}</span>
  132. </template>
  133. </el-table-column>
  134. <el-table-column
  135. label="销售订单号"
  136. align="center"
  137. prop="code"
  138. width="120"
  139. sortable
  140. >
  141. </el-table-column>
  142. <el-table-column
  143. label="产品名称"
  144. align="center"
  145. prop="productName"
  146. width="120"
  147. >
  148. </el-table-column>
  149. <el-table-column label="行号" align="center" prop="lineNumber">
  150. </el-table-column>
  151. <el-table-column
  152. :label="'订单数量' + (clientEnvironmentId == '4' ? '(方)' : '')"
  153. align="center"
  154. prop="contractNum"
  155. width="120"
  156. >
  157. <template slot-scope="scope">
  158. {{ scope.row.contractNum }} {{scope.row.measuringUnit }}
  159. </template>
  160. </el-table-column>
  161. <el-table-column
  162. label="订单重量"
  163. align="center"
  164. prop="productSumWeight"
  165. width="120"
  166. >
  167. <template slot-scope="scope">
  168. {{ scope.row.productSumWeight }} {{ form.weightUnit }}
  169. </template>
  170. </el-table-column>
  171. <el-table-column label="规格" align="center" prop="specification">
  172. </el-table-column>
  173. <el-table-column
  174. :label="'欠交数量' + (clientEnvironmentId == '4' ? '(方)' : '')"
  175. align="center"
  176. prop="lackNum"
  177. >
  178. </el-table-column>
  179. <el-table-column
  180. :label="'计划生产数量' + (clientEnvironmentId == '4' ? '(方)' : '')"
  181. align="center"
  182. prop="planProductNum"
  183. width="140"
  184. >
  185. <template slot-scope="scope">
  186. <el-form-item
  187. label-width="0px"
  188. :prop="'salesOrders.' + scope.$index + '.planProductNum'"
  189. :rules="{
  190. required: true,
  191. message: '请输入计划生产数量',
  192. trigger: 'blur'
  193. }"
  194. class="table-item"
  195. >
  196. <el-input
  197. v-model.number="scope.row.planProductNum"
  198. size="small"
  199. oninput="value=value.replace(/[^\d]/g,'')"
  200. style="width: 100%"
  201. @input="
  202. tableHandleKeyUp(scope.row, scope.$index, $event, 'sum')
  203. "
  204. placeholder="输入数量"
  205. ></el-input>
  206. </el-form-item>
  207. </template>
  208. </el-table-column>
  209. <el-table-column
  210. :label="'要求生产数量' + (clientEnvironmentId == '4' ? '(方)' : '')"
  211. align="center"
  212. prop="requiredFormingNum"
  213. width="120"
  214. >
  215. <template slot-scope="scope">
  216. <el-form-item
  217. label-width="0px"
  218. :prop="'salesOrders.' + scope.$index + '.requiredFormingNum'"
  219. :rules="{
  220. required: true,
  221. message: '请输入要求生产数量',
  222. trigger: 'blur'
  223. }"
  224. class="table-item"
  225. >
  226. <el-input
  227. v-model.number="scope.row.requiredFormingNum"
  228. size="small"
  229. disabled
  230. oninput="value=value.replace(/[^\d]/g,'')"
  231. style="width: 100%"
  232. placeholder="输入数量"
  233. ></el-input>
  234. </el-form-item>
  235. </template>
  236. </el-table-column>
  237. <el-table-column
  238. label="模数"
  239. align="center"
  240. width="100"
  241. v-if="clientEnvironmentId == '4'"
  242. >
  243. <template slot-scope="scope">
  244. <div>
  245. <el-input
  246. style="width: 100%"
  247. size="small"
  248. v-model="scope.row.moCount"
  249. oninput="value=value.replace(/[^0-9.]/g,'')"
  250. @input="
  251. tableHandleKeyUp(scope.row, scope.$index, $event, 'moCount')
  252. "
  253. placeholder="请输入"
  254. >
  255. </el-input>
  256. </div>
  257. </template>
  258. </el-table-column>
  259. <el-table-column
  260. align="center"
  261. width="100"
  262. v-if="clientEnvironmentId == '4'"
  263. >
  264. <template slot="header">
  265. <span style="color: red">*</span>
  266. <span>块数</span>
  267. </template>
  268. <template slot-scope="scope">
  269. <div>
  270. <el-input
  271. size="small"
  272. style="width: 100%"
  273. oninput="value=value.replace(/[^0-9.]/g,'')"
  274. @input="
  275. tableHandleKeyUp(
  276. scope.row,
  277. scope.$index,
  278. $event,
  279. 'blockCount'
  280. )
  281. "
  282. v-model="scope.row.blockCount"
  283. placeholder="请输入"
  284. ></el-input>
  285. </div>
  286. </template>
  287. </el-table-column>
  288. <el-table-column
  289. label="权重等级"
  290. align="center"
  291. width="120"
  292. v-if="clientEnvironmentId == '4'"
  293. >
  294. <template slot-scope="scope">
  295. <div>
  296. <el-select v-model="scope.row.weight" style="width: 100%">
  297. <el-option
  298. v-for="item of weightList"
  299. :key="item.code"
  300. :label="item.name"
  301. :value="item.code"
  302. ></el-option>
  303. </el-select>
  304. </div>
  305. </template>
  306. </el-table-column>
  307. <el-table-column
  308. align="center"
  309. width="120"
  310. label="是否开槽"
  311. v-if="clientEnvironmentId == '4'"
  312. >
  313. <template slot-scope="scope">
  314. <div>
  315. <el-select
  316. style="width: 100%"
  317. v-model="scope.row.isSlotting"
  318. placeholder="请选择"
  319. >
  320. <el-option
  321. v-for="item of isSlotting"
  322. :key="item.code"
  323. :label="item.name"
  324. :value="item.code"
  325. />
  326. </el-select>
  327. </div>
  328. </template>
  329. </el-table-column>
  330. <el-table-column
  331. align="center"
  332. width="120"
  333. label="开槽类型"
  334. v-if="clientEnvironmentId == '4'"
  335. >
  336. <template slot-scope="scope">
  337. <DictSelection
  338. dictName="开槽类型"
  339. v-model="scope.row.slottingType"
  340. v-if="scope.row.isSlotting == 1"
  341. >
  342. </DictSelection>
  343. </template>
  344. </el-table-column>
  345. <el-table-column
  346. label="按单按库"
  347. align="center"
  348. prop="orderLibraryType"
  349. >
  350. <template slot-scope="{ row }">
  351. {{ getDictValue('按单按库', row.orderLibraryType) }}
  352. </template>
  353. </el-table-column>
  354. <el-table-column label="订单类型" align="center" prop="orderType">
  355. <template slot-scope="{ row }">
  356. {{ getDictValue('订单类型', row.orderType) }}
  357. </template>
  358. </el-table-column>
  359. <el-table-column
  360. label="交付日期"
  361. align="center"
  362. prop="deliveryTime"
  363. width="160"
  364. >
  365. </el-table-column>
  366. <el-table-column
  367. label="要求生产日期"
  368. align="center"
  369. prop="reqMoldTime"
  370. width="180"
  371. >
  372. <template slot-scope="scope">
  373. <el-form-item
  374. label-width="0px"
  375. :prop="'salesOrders.' + scope.$index + '.reqMoldTime'"
  376. :rules="{
  377. required: true,
  378. message: '请选择要求生产日期',
  379. trigger: 'blur'
  380. }"
  381. class="table-item"
  382. >
  383. <el-date-picker
  384. style="width: 100%"
  385. v-model="scope.row.reqMoldTime"
  386. :pickerOptions="{
  387. disabledDate: (time) =>
  388. time.getTime() <
  389. new Date(new Date().setHours(0, 0, 0, 0)).getTime()
  390. }"
  391. type="date"
  392. placeholder="选择日期"
  393. value-format="yyyy-MM-dd"
  394. >
  395. </el-date-picker>
  396. </el-form-item>
  397. </template>
  398. </el-table-column>
  399. <el-table-column label="客户名称" align="center" prop="customerName">
  400. </el-table-column>
  401. <el-table-column label="业务员" align="center" prop="salesman">
  402. </el-table-column>
  403. <el-table-column
  404. label="交付要求"
  405. align="center"
  406. prop="deliveryRequirements"
  407. >
  408. <template slot-scope="{ row }">
  409. {{ getDictValue('交付要求', row.deliveryRequirements) }}
  410. </template>
  411. </el-table-column>
  412. <el-table-column
  413. prop="priority"
  414. label="优先级"
  415. width="100"
  416. align="center"
  417. >
  418. <template slot-scope="{ row, $index }">
  419. <div style="display: flex">
  420. <el-input
  421. v-if="$index == 0"
  422. v-model="row.priority"
  423. type="number"
  424. size="mini"
  425. :min="0"
  426. :max="10"
  427. @change="priorityChange(row)"
  428. style="width: 80px"
  429. ></el-input>
  430. <el-popover
  431. v-if="$index == 0"
  432. placement="right"
  433. width="200"
  434. trigger="hover"
  435. content="数值越大优先级越高(0-3普通, 4-6优先, 7-10紧急)"
  436. >
  437. <div class="sort-wrap" slot="reference">
  438. <i class="el-icon-caret-top" @click="sortTop(row)"></i>
  439. <i class="el-icon-caret-bottom" @click="sortBottom(row)"></i>
  440. </div>
  441. </el-popover>
  442. </div>
  443. </template>
  444. </el-table-column>
  445. <el-table-column label="操作" align="center" width="70" fixed="right">
  446. <template slot-scope="scope">
  447. <el-button type="text" @click="handleDeleteItem(scope.$index)" v-if="type != 'edit'"
  448. >删除</el-button
  449. >
  450. </template>
  451. </el-table-column>
  452. </el-table>
  453. <div class="add-product" @click="addEquipment" v-if="type != 'edit'">
  454. <i class="el-icon-circle-plus-outline"></i>
  455. </div>
  456. <el-row :gutter="24">
  457. <el-col v-bind="styleResponsive ? { lg: 24, md: 24 } : { span: 24 }">
  458. <el-form-item label="计划备注:">
  459. <el-input
  460. type="textarea"
  461. :rows="4"
  462. v-model="form.notes"
  463. resize="none"
  464. ></el-input>
  465. </el-form-item>
  466. </el-col>
  467. </el-row>
  468. </el-form>
  469. <AdditionalOrder
  470. ref="additionalRefs"
  471. :productCode="form.productCode"
  472. :selectList="form.salesOrders"
  473. @choose="confirmChoose"
  474. ></AdditionalOrder>
  475. <ProductionVersion
  476. ref="versionRefs"
  477. @changeProduct="changeProduct"
  478. ></ProductionVersion>
  479. <PlanSubmit
  480. ref="submitRefs"
  481. :type="$route.query.type"
  482. :info="form"
  483. @publish="publishData"
  484. ></PlanSubmit>
  485. </el-card>
  486. </div>
  487. </template>
  488. <script>
  489. import AdditionalOrder from './components/AdditionalOrder.vue';
  490. import PlanSubmit from './components/plan-submit.vue';
  491. import ProductionVersion from '@/components/CreatePlan/ProductionVersion2.vue';
  492. import {
  493. productionToPlan,
  494. saveSaleToPlan,
  495. updateSaleToPlan,
  496. releaseSave,
  497. getInventory,
  498. getUpdateInfoById,
  499. getProductVersion,
  500. productionPlanRouting
  501. } from '@/api/saleOrder';
  502. import { getByCode } from '@/api/system/dictionary-data';
  503. import dictMixins from '@/mixins/dictMixins';
  504. import { deepClone } from '@/utils/index';
  505. import { getRouteTabKey, removePageTab } from '@/utils/page-tab-util';
  506. import { getCode } from '@/api/codeManagement';
  507. import dayjs from 'dayjs';
  508. import { debounce } from 'lodash';
  509. export default {
  510. mixins: [dictMixins],
  511. components: {
  512. AdditionalOrder,
  513. ProductionVersion,
  514. PlanSubmit
  515. },
  516. data() {
  517. return {
  518. type: this.$route.query.type,
  519. weightList: [
  520. { code: 1, name: 'A' },
  521. { code: 2, name: 'B' },
  522. { code: 3, name: 'C' }
  523. ],
  524. isSlotting: [
  525. { code: 1, name: '是' },
  526. { code: 2, name: '否' }
  527. ], //是否开槽
  528. producedList: [
  529. { code: 2, name: '加工' },
  530. { code: 3, name: '装配' }
  531. ],
  532. form: {
  533. planType: 1,
  534. produceRoutingId: '',
  535. stockCountBase: '',
  536. salesOrders: [],
  537. produceRoutingName: '',
  538. marginCoefficient: '1.0',
  539. batchNo: null,
  540. produceType: ''
  541. },
  542. marginList: [],
  543. routingList: [],
  544. // 表单验证规则
  545. rules: {
  546. produceRoutingId: [
  547. { required: true, message: '请选择工艺路线', trigger: 'blur' }
  548. ],
  549. produceType: [
  550. { required: true, message: '请选择生产类型', trigger: 'blur' }
  551. ]
  552. },
  553. // selection: [],
  554. loading: false
  555. };
  556. },
  557. computed: {
  558. clientEnvironmentId() {
  559. return this.$store.state.user.info.clientEnvironmentId;
  560. },
  561. // 是否开启响应式布局
  562. styleResponsive() {
  563. return this.$store.state.theme.styleResponsive;
  564. }
  565. },
  566. created() {
  567. this.requestDict('按单按库');
  568. this.requestDict('订单类型');
  569. this.requestDict('交付要求');
  570. this.getByCodeFn();
  571. if (this.type == 'edit') {
  572. this.getPlanInfo(this.$route.query.id);
  573. } else {
  574. this.getSaleInfo();
  575. this.getPlanRouting();
  576. }
  577. },
  578. methods: {
  579. async getPlanInfo(id) {
  580. const data = await getUpdateInfoById(id);
  581. this.form = data;
  582. },
  583. async _getInventory() {
  584. const res = await getInventory(this.form.productCode, this.form.planType);
  585. this.form.stockCountBase = res;
  586. },
  587. getByCodeFn() {
  588. getByCode('margin_code').then((res) => {
  589. let _arr = [];
  590. res.data.map((item) => {
  591. const key = Object.keys(item)[0];
  592. const value = item[key];
  593. _arr.push({ name: key, value: value });
  594. });
  595. this.marginList = _arr;
  596. });
  597. },
  598. getPlanRouting() {
  599. let params = {
  600. ids: JSON.parse(this.$route.query.selection),
  601. produceType: this.form.produceType
  602. }
  603. productionPlanRouting(params).then((res) => {
  604. this.routingList = res || []
  605. if( this.routingList.length == 1) {
  606. this.$set(this.form, 'produceRoutingId', this.routingList[0].id);
  607. this.$set(this.form, 'produceRoutingName', this.routingList[0].name);
  608. this.$set(this.form, 'produceVersionName',this.routingList[0].version);
  609. }
  610. })
  611. },
  612. changeProduceType() {
  613. this.form.produceRoutingId = ''
  614. this.form.produceRoutingName = ''
  615. this.form.produceVersionName = ''
  616. this.getPlanRouting()
  617. },
  618. changeRoute() {
  619. this.routingList.forEach((f) => {
  620. if(f.id == this.form.produceRoutingId) {
  621. this.$set(this.form, 'produceRoutingName', f.name);
  622. this.$set(this.form, 'produceVersionName', f.version);
  623. }
  624. })
  625. },
  626. getSaleInfo() {
  627. let params = JSON.parse(this.$route.query.selection);
  628. productionToPlan(params).then((res) => {
  629. console.log(res);
  630. this.form = deepClone(res);
  631. this.form.produceRoutingName =
  632. res.produceRoutingName || this.$route.query.produceRoutingName;
  633. this.form.produceRoutingId =
  634. res.produceRoutingId || this.$route.query.produceRoutingId;
  635. this.form.salesOrders.map((item, index) => {
  636. if (this.clientEnvironmentId == '4') {
  637. this.tableHandleKeyUp(item, '', item.lackNum, 'sum');
  638. } else {
  639. item.planProductNum = item.lackNum;
  640. item.requiredFormingNum = item.lackNum;
  641. }
  642. item.slottingType = item.slottingType && item.slottingType + '';
  643. item.priority = index + 1;
  644. item.reqMoldTime = dayjs(
  645. new Date(item.deliveryTime).getTime() - 3600 * 1000 * 24 * 10
  646. ).format('YYYY-MM-DD');
  647. });
  648. if (this.form.salesOrders.every((itm) => itm.orderType == 2)) {
  649. this.form.planType = 2;
  650. } else if (this.form.salesOrders.every((itm) => itm.orderType == 1)) {
  651. this.form.planType = 1;
  652. } else {
  653. this.form.planType = 3;
  654. }
  655. this._getInventory();
  656. });
  657. this.$forceUpdate();
  658. },
  659. itemChange() {
  660. this.form.salesOrders.map((item, index) => {
  661. this.$set(
  662. item,
  663. 'requiredFormingNum',
  664. item.planProductNum * (this.form.marginCoefficient || 1)
  665. );
  666. });
  667. },
  668. toInt(planProductNum) {
  669. return planProductNum * (this.form.marginCoefficient || 1);
  670. },
  671. cancel() {
  672. const key = getRouteTabKey();
  673. this.$router.go(-1);
  674. removePageTab({ key });
  675. },
  676. toSubmit() {
  677. this.$refs.form.validate((valid) => {
  678. if (valid) {
  679. this.mapList();
  680. this.$refs.submitRefs.open();
  681. }
  682. });
  683. },
  684. // 对比日期,计算要求生产重量
  685. mapList() {
  686. var _sumOrderWeight = 0;
  687. var requiredFormingNum = 0;
  688. var productNum = 0;
  689. this.form.salesOrders.map((item, index) => {
  690. requiredFormingNum =
  691. Number(requiredFormingNum) + Number(item.requiredFormingNum);
  692. if (
  693. this.form.weightUnit == 'G' ||
  694. this.form.weightUnit == 'g' ||
  695. this.form.weightUnit == '克'
  696. ) {
  697. this.form.newWeightUnit = 'kg';
  698. _sumOrderWeight =
  699. (this.form.sumOrderWeight *
  700. Number(this.form.marginCoefficient || 1)) /
  701. 1000;
  702. } else {
  703. this.form.newWeightUnit = this.form.weightUnit;
  704. _sumOrderWeight =
  705. this.form.sumOrderWeight * Number(this.form.marginCoefficient || 1);
  706. }
  707. productNum += Number(item.planProductNum);
  708. });
  709. this.form.productNum = productNum;
  710. this.form.productUnitWeight = this.form.salesOrders[0]?.productUnitWeight;
  711. this.form.newSumOrderWeight = _sumOrderWeight.toFixed(2);
  712. this.form.requiredFormingNum = requiredFormingNum;
  713. const collection = deepClone(this.form.salesOrders);
  714. const sortedCollection = collection.sort(
  715. (a, b) => new Date(b.reqMoldTime) - new Date(a.reqMoldTime)
  716. );
  717. let latestData = {};
  718. for (let i = 0; i < sortedCollection.length; i++) {
  719. const data = sortedCollection[i];
  720. if (
  721. !latestData.reqMoldTime ||
  722. new Date(data.reqMoldTime) >= new Date(latestData.reqMoldTime)
  723. ) {
  724. latestData = data;
  725. }
  726. }
  727. this.form.reqMoldTime = latestData.reqMoldTime;
  728. },
  729. sortTop(row) {
  730. row.priority = Number(row.priority) + 1;
  731. this.priorityChange(row);
  732. },
  733. sortBottom(row) {
  734. if (row.priority <= 1) {
  735. return;
  736. }
  737. row.priority = Number(row.priority) - 1;
  738. this.priorityChange(row);
  739. },
  740. priorityChange(row) {
  741. if (row.priority > 10) {
  742. row.priority = 10; // 如果大于 10,则设置为 10
  743. } else if (row.priority < 0) {
  744. row.priority = 0; // 如果小于 0,则设置为 0
  745. }
  746. this.priorityFn(row);
  747. },
  748. priorityFn: debounce(function (row) {}, 800),
  749. // 删除产品
  750. handleDeleteItem(index) {
  751. this.form.salesOrders.splice(index, 1);
  752. },
  753. addEquipment() {
  754. this.$refs.additionalRefs.open(this.form.planType);
  755. },
  756. openVersion() {
  757. this.$refs.versionRefs.open();
  758. },
  759. changeProduct(data) {
  760. this.$set(this.form, 'produceRoutingName', data.name);
  761. this.$set(this.form, 'produceRoutingId', data.id);
  762. this.$set(this.form, 'produceVersionName', data.produceVersionName);
  763. },
  764. // 表格:模数、数量(方)、块数输入框 输入事件
  765. tableHandleKeyUp(row, index, e, name) {
  766. if (row.specification && this.clientEnvironmentId == '4') {
  767. let modelArr = row.specification.split('*');
  768. let modelLong = modelArr[0]; // model规格长度
  769. let modeWide = modelArr[1]; // model规格宽度
  770. let modeHight = modelArr[2].substr(0, modelArr[2].indexOf('cm')); // model规格高度
  771. modeHight = Number(modeHight);
  772. if (name === 'moCount') {
  773. // 模数
  774. row.moCount = e;
  775. // 计算块数的公式:
  776. // (一模6米长度 / model规格长度) * (一模1.2米宽度 / model规格宽度) = 每一模的块数
  777. // 每一模的块数*模数moCount = 总块数
  778. if (row.productName.includes('板材')) {
  779. row.blockCount =
  780. Math.floor(600 / modelLong) *
  781. Math.floor(120 / modeHight) *
  782. Math.floor(60 / modeWide) *
  783. row.moCount;
  784. } else if (row.productName.includes('砌块')) {
  785. let modelLongFixed = (600 / modelLong).toFixed(2);
  786. modelLongFixed = modelLongFixed.substring(
  787. 0,
  788. modelLongFixed.length - 1
  789. );
  790. let modeWideFixed = (120 / modeWide).toFixed(2);
  791. modeWideFixed = modeWideFixed.substring(
  792. 0,
  793. modeWideFixed.length - 1
  794. );
  795. let modeHightFixed = (60 / modeHight).toFixed(2);
  796. modeHightFixed = modeHightFixed.substring(
  797. 0,
  798. modeHightFixed.length - 1
  799. );
  800. row.blockCount =
  801. Math.floor(modelLongFixed * modeWideFixed * modeHightFixed) *
  802. row.moCount;
  803. }
  804. row.planProductNum =
  805. Nu((modelLong * modeWide * modeHight) / 1000000).toFixed(5) *
  806. row.blockCount;
  807. } else if (name === 'sum') {
  808. //方数
  809. row.planProductNum = e;
  810. row.blockCount = Math.floor(
  811. e / ((modelLong * modeWide * modeHight) / 1000000)
  812. );
  813. if (row.productName.includes('板材')) {
  814. row.moCount = Math.ceil(
  815. row.blockCount /
  816. (Math.floor(600 / modelLong) *
  817. Math.floor(120 / modeHight) *
  818. Math.floor(60 / modeWide))
  819. );
  820. } else if (row.productName.includes('砌块')) {
  821. row.moCount = Math.ceil(
  822. row.blockCount /
  823. Math.floor(
  824. (600 / modelLong) * (120 / modeHight) * (60 / modeWide)
  825. )
  826. );
  827. }
  828. } else if (name === 'blockCount') {
  829. //块数
  830. row.blockCount = e;
  831. if (row.productName.includes('板材')) {
  832. row.moCount = Math.ceil(
  833. row.blockCount /
  834. (Math.floor(600 / modelLong) *
  835. Math.floor(120 / modeHight) *
  836. Math.floor(60 / modeWide))
  837. );
  838. } else if (row.productName.includes('砌块')) {
  839. row.moCount = Math.ceil(
  840. row.blockCount /
  841. Math.floor(
  842. (600 / modelLong) * (120 / modeHight) * (60 / modeWide)
  843. )
  844. );
  845. }
  846. row.planProductNum =
  847. (Number(e) * modelLong * modeWide * modeHight) / 1000000;
  848. }
  849. }
  850. row.requiredFormingNum =Number(row.planProductNum * (this.form.marginCoefficient || 1)).toFixed(5);
  851. },
  852. confirmChoose(list) {
  853. // 取出在弹窗中选中并且不在表格中的数据
  854. const result = list.filter(
  855. (i) => this.form.salesOrders.findIndex((p) => p.id === i.id) === -1
  856. );
  857. // 取出在表格中并且不在弹窗中选中的数据 即取消选中的数据
  858. const del = this.form.salesOrders.filter(
  859. (i) => list.findIndex((p) => p.id === i.id) === -1
  860. );
  861. for (let i = this.form.salesOrders.length - 1; i >= 0; i--) {
  862. for (let j in del) {
  863. if (this.form.salesOrders[i].id === del[j].id) {
  864. this.form.salesOrders.splice(i, 1);
  865. }
  866. }
  867. }
  868. let priority =
  869. this.form.salesOrders[this.form.salesOrders.length - 1]?.priority || 0;
  870. this.form.salesOrders = this.form.salesOrders.concat(
  871. result.map((item, index) => {
  872. item.priority = ++priority;
  873. item.planProductNum = item.lackNum;
  874. item.requiredFormingNum = item.lackNum;
  875. item.reqMoldTime = dayjs(
  876. new Date(item.deliveryTime).getTime() - 3600 * 1000 * 24 * 10
  877. ).format('YYYY-MM-DD');
  878. return item;
  879. })
  880. );
  881. this.changeData();
  882. },
  883. changeData() {
  884. var planProductNum = 0;
  885. var productWeight = 0;
  886. this.form.salesOrders.map((item, index) => {
  887. item.priority = index + 1;
  888. planProductNum = planProductNum + item.requiredFormingNum;
  889. productWeight = productWeight + Number(item.productSumWeight);
  890. });
  891. this.$set(this.form, 'codeNum', this.form.salesOrders.length);
  892. this.$set(this.form, 'contractNum', planProductNum);
  893. this.$set(this.form, 'sumOrderWeight', productWeight.toFixed(2));
  894. },
  895. async publishData(type) {
  896. const key = getRouteTabKey();
  897. let params = deepClone(this.form);
  898. params.categoryId = params.salesOrders[0]?.categoryId;
  899. if (this.$route.query.type != 'edit') {
  900. delete params.id;
  901. }
  902. if (type === 2) {
  903. this.$confirm('发布工单后不可撤回,确定发布吗?', '发布确认').then(
  904. async () => {
  905. const loading = this.$loading({
  906. lock: true,
  907. fullscreen: true,
  908. text: '工单发布中...'
  909. });
  910. try {
  911. const code = await getCode('product_order_code');
  912. const data = {
  913. productionPlan: params,
  914. workOrder: {
  915. productionPlanCode: params.code,
  916. code: code,
  917. // formingNum: params.contractNum,
  918. formingNum: this.form.requiredFormingNum,
  919. formingWeight: params.sumOrderWeight,
  920. produceRoutingId: params.produceRoutingId,
  921. status: 4,
  922. model: params.model,
  923. brandNo: params.brandNo,
  924. categoryId: params.categoryId,
  925. productCode: params.productCode,
  926. productName: params.productName,
  927. newWeightUnit: this.form.newWeightUnit,
  928. newSumOrderWeight: this.form.newSumOrderWeight
  929. }
  930. };
  931. if (this.$route.query.type == 'edit') {
  932. data.workOrder.productionPlanId = params.id;
  933. }
  934. await releaseSave(data)
  935. .then((res) => {
  936. if (res === 1) {
  937. this.$message.success('工单已发布!');
  938. this.$router.push({
  939. path: '/productionPlan'
  940. });
  941. } else {
  942. this.$confirm(
  943. '生产计划创建成功,但工单发布失败。请前往【生产计划】列表【重新发布】工单',
  944. '提示',
  945. {
  946. confirmButtonText: '返回',
  947. cancelButtonText: '立即前往',
  948. type: 'warning'
  949. }
  950. )
  951. .then(() => {
  952. this.$router.push({
  953. path: '/productionPlan'
  954. });
  955. })
  956. .catch(() => {
  957. this.$router.go(-1);
  958. });
  959. }
  960. removePageTab({ key });
  961. })
  962. .catch(() => {
  963. this.$message.error('发布失败,请重新发布!');
  964. });
  965. } catch (error) {}
  966. loading.close();
  967. }
  968. );
  969. } else {
  970. let request =
  971. this.$route.query.type == 'edit' ? updateSaleToPlan : saveSaleToPlan;
  972. request(params)
  973. .then(async (res) => {
  974. // 提交
  975. this.$router.push({
  976. path: '/productionPlan'
  977. });
  978. removePageTab({ key });
  979. })
  980. .catch(() => {
  981. this.$message.error('提交失败,请重新提交!');
  982. });
  983. }
  984. }
  985. }
  986. };
  987. </script>
  988. <style lang="scss" scoped>
  989. .ele-body {
  990. background: #fff;
  991. }
  992. .body-title {
  993. width: 100%;
  994. display: flex;
  995. align-items: center;
  996. justify-content: space-between;
  997. }
  998. .title-left {
  999. font-size: 20px;
  1000. color: #333;
  1001. }
  1002. .formbox {
  1003. margin: 20px auto;
  1004. }
  1005. .row-intro {
  1006. border-bottom: 1px dashed #ccc;
  1007. margin-bottom: 20px;
  1008. }
  1009. .add-product {
  1010. width: 100%;
  1011. display: flex;
  1012. align-items: center;
  1013. justify-content: flex-end;
  1014. font-size: 30px;
  1015. color: #1890ff;
  1016. margin: 10px 0;
  1017. cursor: pointer;
  1018. }
  1019. .table-item {
  1020. margin-bottom: 0;
  1021. }
  1022. </style>