salesToProductionNew.vue 36 KB

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