salesToProductionNew.vue 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101
  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 { getByCode } from '@/api/system/dictionary-data';
  279. import { parameterGetByCode } from '@/api/mainData/index';
  280. import dictMixins from '@/mixins/dictMixins';
  281. import { deepClone } from '@/utils/index';
  282. import { getRouteTabKey, removePageTab } from '@/utils/page-tab-util';
  283. import { getCode } from '@/api/codeManagement';
  284. import dayjs from 'dayjs';
  285. import { debounce } from 'lodash';
  286. import ProcessRoute from '@/components/selectionDialog/processRoute.vue';
  287. export default {
  288. mixins: [dictMixins],
  289. components: {
  290. AdditionalOrder,
  291. ProductionVersion,
  292. PlanSubmit,
  293. ProcessRoute
  294. },
  295. props: {
  296. formData: {
  297. type: Object,
  298. default: {}
  299. }
  300. },
  301. watch: {
  302. formData: {
  303. handler(val) {
  304. Object.assign(this.form, val);
  305. // console.log(this.form,'1111111111122222');
  306. this.$nextTick(() => {
  307. if (val.produceRoutingId) {
  308. this.bomListVersion();
  309. this.changeBomId();
  310. }
  311. this.$set(this.form, 'produceRoutingId', val.produceRoutingId);
  312. });
  313. },
  314. deep: true,
  315. immediate: true
  316. },
  317. selectionRowShow(val) {
  318. console.log(val, 'val ++++++');
  319. this.selectionRowShow = val;
  320. }
  321. },
  322. data() {
  323. return {
  324. type: this.$route.query.type,
  325. weightList: [
  326. { code: 1, name: 'A' },
  327. { code: 2, name: 'B' },
  328. { code: 3, name: 'C' }
  329. ],
  330. isSlotting: [
  331. { code: 1, name: '是' },
  332. { code: 2, name: '否' }
  333. ], //是否开槽
  334. producedList: [
  335. // { code: 2, name: '加工(MBOM)' },
  336. // { code: 3, name: '装配(ABOM)' }
  337. ],
  338. form: {
  339. planType: 1,
  340. produceRoutingId: '',
  341. stockCountBase: '',
  342. salesOrders: [],
  343. produceRoutingName: '',
  344. marginCoefficient: '1.0',
  345. batchNo: null,
  346. produceType: 1,
  347. bomCategoryId: '',
  348. factoriesId: '',
  349. productPlanList: []
  350. },
  351. marginList: [],
  352. bomVersionList: [],
  353. routingList: [],
  354. factoryList: [],
  355. // 表单验证规则
  356. rules: {
  357. produceRoutingId: [
  358. { required: true, message: '请选择工艺路线', trigger: 'blur' }
  359. ]
  360. // factoriesId: [
  361. // { required: true, message: '请选择所属工厂', trigger: 'change' }
  362. // ]
  363. },
  364. // selection: [],
  365. loading: false,
  366. processingRequired: 0, // 生产类型跟BOM 版本是否必填 1:是 0:否
  367. selectionRowShow: false // 工艺路线输入框展示 状态
  368. };
  369. },
  370. computed: {
  371. clientEnvironmentId() {
  372. return this.$store.state.user.info.clientEnvironmentId;
  373. },
  374. // 是否开启响应式布局
  375. styleResponsive() {
  376. return this.$store.state.theme.styleResponsive;
  377. },
  378. // 是否必填字段
  379. isRequired() {
  380. // if (this.form.planType == 5) {
  381. // return false;
  382. // }
  383. return this.processingRequired == 1;
  384. },
  385. // 工艺路线 输入框展示跟选择框判断
  386. isRouteSelect() {
  387. if (this.isRequired) {
  388. return true;
  389. }
  390. if (!this.selectionRowShow) {
  391. return true;
  392. }
  393. return false;
  394. },
  395. // 选择按钮的显示
  396. isSelectShow() {
  397. return this.processingRequired == 0;
  398. }
  399. },
  400. created() {
  401. this.getProducedData();
  402. this.requestDict('按单按库');
  403. this.requestDict('订单类型');
  404. this.requestDict('交付要求');
  405. this.getByCodeFn();
  406. this.getFactoryList();
  407. if (this.type == 'edit') {
  408. this.getPlanInfo(this.$route.query.id);
  409. } else {
  410. this.getSaleInfo();
  411. }
  412. // this.bomListVersion();
  413. this.mandatoryField();
  414. },
  415. methods: {
  416. async getProducedData() {
  417. console.log(3333333333333333333333333);
  418. let query = this.$route.query;
  419. let producedList = query.producedList
  420. ? JSON.parse(query.producedList)
  421. : [];
  422. console.log(query, 'query');
  423. console.log(producedList, 'producedList');
  424. // this.form.produceType = query.produceType || 2;
  425. if (!producedList || producedList.length === 0) {
  426. this.producedList = [
  427. { code: 2, name: 'MBOM' },
  428. { code: 3, name: 'ABOM' }
  429. ];
  430. return;
  431. }
  432. this.producedList = JSON.parse(this.$route.query.producedList);
  433. },
  434. // 是否必填
  435. mandatoryField() {
  436. parameterGetByCode({
  437. code: 'production_plan_code'
  438. }).then((res) => {
  439. if (res) {
  440. this.processingRequired = res.value;
  441. }
  442. });
  443. },
  444. // 验证时间是否超期
  445. changeDate(item, i) {
  446. console.log(
  447. this.isTimeAGreaterThanB(item.deliveryTime, item.reqMoldTime)
  448. );
  449. if (this.isTimeAGreaterThanB(item.deliveryTime, item.reqMoldTime)) {
  450. this.$message.error('交付时间大于了要求完成日期');
  451. }
  452. },
  453. isTimeAGreaterThanB(timeA, timeB) {
  454. return new Date(timeA) > new Date(timeB);
  455. },
  456. async getFactoryList() {
  457. this.factoryList = await getFactoryList();
  458. this.$nextTick(() => {
  459. this.form.factoriesId = this.factoryList[0].id;
  460. });
  461. },
  462. async getPlanInfo(id) {
  463. const data = await getUpdateInfoById(id);
  464. console.log('wwwwwwwwwwww', data);
  465. this.form = data;
  466. if (!data.bomCategoryId || data.bomCategoryId == null) {
  467. this.form.produceType = '';
  468. this.selectionRowShow = true;
  469. } else {
  470. this.selectionRowShow = false;
  471. }
  472. if (this.clientEnvironmentId != 4) {
  473. this.bomListVersion();
  474. // this.getPlanRouting();
  475. }
  476. },
  477. async _getInventory() {
  478. const res = await getInventory(
  479. this.form.productCode,
  480. this.form.planType
  481. );
  482. this.form.stockCountBase = res;
  483. },
  484. getByCodeFn() {
  485. getByCode('margin_code').then((res) => {
  486. let _arr = [];
  487. res.data.map((item) => {
  488. const key = Object.keys(item)[0];
  489. const value = item[key];
  490. _arr.push({ name: key, value: value });
  491. });
  492. this.marginList = _arr;
  493. });
  494. },
  495. getPlanRouting() {
  496. if (this.form.bomCategoryId) {
  497. bomRoutingList(this.form.bomCategoryId).then((res) => {
  498. this.routingList = res || [];
  499. if (res.length) {
  500. this.$nextTick(() => {
  501. this.$set(this.form, 'produceRoutingId', res[0].id);
  502. });
  503. console.log(this.form.produceRoutingId, '222222222');
  504. }
  505. });
  506. }
  507. },
  508. bomListVersion(type) {
  509. let categoryId = '';
  510. if (this.form.salesOrders.length) {
  511. categoryId = this.form.salesOrders[0].categoryId;
  512. } else if (this.form.categoryId) {
  513. categoryId = this.form.categoryId;
  514. } else {
  515. new Error('缺少产品信息');
  516. }
  517. let param = {
  518. bomType: this.form.produceType || null,
  519. categoryId: categoryId
  520. };
  521. bomListByPlan(param).then((res) => {
  522. this.bomVersionList = res || [];
  523. if (res.length) {
  524. let o = res[0];
  525. if (type == 'init') {
  526. let query = this.$route.query;
  527. let id = query.bomCategoryId ? query.bomCategoryId : o.id;
  528. this.$set(this.form, 'bomCategoryId', id);
  529. } else {
  530. this.$set(this.form, 'bomCategoryId', o.id);
  531. }
  532. this.changeBomId();
  533. }
  534. });
  535. },
  536. changeProduceType(type) {
  537. if (this.clientEnvironmentId == 4) {
  538. return false;
  539. }
  540. this.form.bomCategoryId = '';
  541. this.form['bomCategoryName'] = '';
  542. this.form['bomCategoryVersions'] = '';
  543. this.bomVersionList = [];
  544. this.routingList = [];
  545. this.form.produceRoutingId = '';
  546. this.form.produceRoutingName = '';
  547. this.form.produceVersionName = '';
  548. this.selectionRowShow = false; // ****
  549. this.bomListVersion(type);
  550. },
  551. changeBomId() {
  552. this.routingList = [];
  553. this.form.produceRoutingId = '';
  554. this.form.produceRoutingName = '';
  555. this.form.produceVersionName = '';
  556. this.bomVersionList.forEach((f) => {
  557. if (f.id == this.form.bomCategoryId) {
  558. this.$set(this.form, 'bomCategoryName', f.name);
  559. this.$set(this.form, 'bomCategoryVersions', f.versions);
  560. }
  561. });
  562. this.getPlanRouting();
  563. },
  564. changeRoute() {
  565. this.$forceUpdate();
  566. this.routingList.forEach((f) => {
  567. if (f.id == this.form.produceRoutingId) {
  568. this.$set(this.form, 'produceRoutingName', f.name);
  569. this.$set(this.form, 'produceVersionName', f.version);
  570. }
  571. });
  572. },
  573. getSaleInfo() {
  574. let params = JSON.parse(this.$route.query.selection);
  575. productionToPlan(params).then((res) => {
  576. console.log(res, '555555555555555555');
  577. this.form = deepClone(res);
  578. // if (!this.form.produceType) {
  579. // this.form.produceType = 2;
  580. // this.bomListVersion();
  581. // }
  582. // this.bomListVersion();
  583. this.form.produceRoutingName =
  584. res.produceRoutingName || this.$route.query.produceRoutingName;
  585. this.form.produceRoutingId =
  586. res.produceRoutingId || this.$route.query.produceRoutingId;
  587. this.form.factoriesId =
  588. res.factoriesId || this.$route.query.factoriesId;
  589. this.form.bomCategoryId =
  590. res.bomCategoryId || this.$route.query.bomCategoryId;
  591. this.changeProduceType('init');
  592. this.changeBomId();
  593. console.log(this.form.factoriesId, '99999999999999');
  594. if (this.clientEnvironmentId == '4') {
  595. if (this.form.salesOrders[0].productName.includes('板材')) {
  596. this.changeProduct({
  597. id: '1856970794952372226',
  598. name: '板材',
  599. produceVersionName: '板材'
  600. });
  601. } else {
  602. this.changeProduct({
  603. id: '1857313733642596353',
  604. name: '砌块',
  605. produceVersionName: '砌块'
  606. });
  607. }
  608. }
  609. this.form.salesOrders.map((item, index) => {
  610. if (this.clientEnvironmentId == '4') {
  611. this.tableHandleKeyUp(item, '', item.lackNum, 'sum');
  612. } else {
  613. item.planProductNum = item.lackNum;
  614. item.requiredFormingNum = item.lackNum;
  615. }
  616. item.slottingType = item.slottingType && item.slottingType + '';
  617. item.priority = index + 1;
  618. item.reqMoldTime = dayjs(
  619. new Date(item.deliveryTime).getTime() - 3600 * 1000 * 24 * 10
  620. ).format('YYYY-MM-DD');
  621. });
  622. if (this.form.salesOrders.every((itm) => itm.orderType == 2)) {
  623. this.form.planType = 2;
  624. } else if (this.form.salesOrders.every((itm) => itm.orderType == 1)) {
  625. this.form.planType = 1;
  626. } else {
  627. this.form.planType = 3;
  628. }
  629. this._getInventory();
  630. });
  631. this.$forceUpdate();
  632. },
  633. itemChange() {
  634. this.form.salesOrders.map((item, index) => {
  635. this.$set(
  636. item,
  637. 'requiredFormingNum',
  638. item.planProductNum * (this.form.marginCoefficient || 1)
  639. );
  640. });
  641. },
  642. factoriesIdFn(e) {
  643. this.$forceUpdate();
  644. },
  645. toInt(planProductNum) {
  646. return planProductNum * (this.form.marginCoefficient || 1);
  647. },
  648. cancel() {
  649. const key = getRouteTabKey();
  650. // this.$router.go(-1);
  651. removePageTab({ key });
  652. this.$emit('cancel');
  653. },
  654. toSubmit() {
  655. this.$refs.form.validate((valid) => {
  656. if (valid) {
  657. // this.mapList();
  658. this.$refs.submitRefs.open();
  659. }
  660. });
  661. },
  662. // // 对比日期,计算要求生产重量
  663. // mapList() {
  664. // var _sumOrderWeight = 0;
  665. // var requiredFormingNum = 0;
  666. // var productNum = 0;
  667. // this.form.salesOrders.map((item, index) => {
  668. // requiredFormingNum = Number(requiredFormingNum) + Number(item.requiredFormingNum);
  669. // if (this.form.weightUnit == 'G' || this.form.weightUnit == 'g' || this.form.weightUnit == '克') {
  670. // this.form.newWeightUnit = 'kg';
  671. // _sumOrderWeight = (this.form.salesOrders[0].requiredFormingNum * Number(this.form.salesOrders[0].productUnitWeight || 1)) / 1000;
  672. // } else {
  673. // this.form.newWeightUnit = this.form.weightUnit;
  674. // _sumOrderWeight = (this.form.salesOrders[0].requiredFormingNum * Number(this.form.salesOrders[0].productUnitWeight || 1));
  675. // }
  676. // productNum += Number(item.planProductNum);
  677. // });
  678. // this.form.productNum = productNum;
  679. // this.form.productUnitWeight = this.form.salesOrders[0]?.productUnitWeight;
  680. // this.form.newSumOrderWeight = _sumOrderWeight.toFixed(2);
  681. // this.form.requiredFormingNum = requiredFormingNum;
  682. // const collection = deepClone(this.form.salesOrders);
  683. // const sortedCollection = collection.sort(
  684. // (a, b) => new Date(b.reqMoldTime) - new Date(a.reqMoldTime)
  685. // );
  686. // let latestData = {};
  687. // for (let i = 0; i < sortedCollection.length; i++) {
  688. // const data = sortedCollection[i];
  689. // if (
  690. // !latestData.reqMoldTime ||
  691. // new Date(data.reqMoldTime) >= new Date(latestData.reqMoldTime)
  692. // ) {
  693. // latestData = data;
  694. // }
  695. // }
  696. // this.form.reqMoldTime = latestData.reqMoldTime;
  697. // console.log(this.form, '1111111111111');
  698. // },
  699. sortTop(row) {
  700. row.priority = Number(row.priority) + 1;
  701. this.priorityChange(row);
  702. },
  703. sortBottom(row) {
  704. if (row.priority <= 1) {
  705. return;
  706. }
  707. row.priority = Number(row.priority) - 1;
  708. this.priorityChange(row);
  709. },
  710. priorityChange(row) {
  711. if (row.priority > 10) {
  712. row.priority = 10; // 如果大于 10,则设置为 10
  713. } else if (row.priority < 0) {
  714. row.priority = 0; // 如果小于 0,则设置为 0
  715. }
  716. this.priorityFn(row);
  717. },
  718. priorityFn: debounce(function (row) {}, 800),
  719. // 删除产品
  720. handleDeleteItem(index) {
  721. this.form.salesOrders.splice(index, 1);
  722. },
  723. addEquipment() {
  724. this.$refs.additionalRefs.open(this.form.planType);
  725. },
  726. openVersion() {
  727. this.$refs.versionRefs.open();
  728. },
  729. changeProduct(data) {
  730. this.$set(this.form, 'produceRoutingName', data.name);
  731. this.$set(this.form, 'produceRoutingId', data.id);
  732. this.$set(this.form, 'produceVersionName', data.produceVersionName);
  733. },
  734. // 表格:模数、数量(方)、块数输入框 输入事件
  735. tableHandleKeyUp(row, index, e, name) {
  736. if (row.specification && this.clientEnvironmentId == '4') {
  737. let modelArr = row.specification.split('*');
  738. let modelLong = modelArr[0]; // model规格长度
  739. let modeWide = modelArr[1]; // model规格宽度
  740. let modeHight = modelArr[2].substr(0, modelArr[2].indexOf('cm')); // model规格高度
  741. modeHight = Number(modeHight);
  742. if (name === 'moCount') {
  743. // 模数
  744. row.moCount = e;
  745. // 计算块数的公式:
  746. // (一模6米长度 / model规格长度) * (一模1.2米宽度 / model规格宽度) = 每一模的块数
  747. // 每一模的块数*模数moCount = 总块数
  748. if (row.productName.includes('板材')) {
  749. row.blockCount =
  750. Math.floor(600 / modelLong) *
  751. Math.floor(120 / modeHight) *
  752. Math.floor(60 / modeWide) *
  753. row.moCount;
  754. } else if (row.productName.includes('砌块')) {
  755. let modelLongFixed = (600 / modelLong).toFixed(2);
  756. modelLongFixed = modelLongFixed.substring(
  757. 0,
  758. modelLongFixed.length - 1
  759. );
  760. let modeWideFixed = (120 / modeWide).toFixed(2);
  761. modeWideFixed = modeWideFixed.substring(
  762. 0,
  763. modeWideFixed.length - 1
  764. );
  765. let modeHightFixed = (60 / modeHight).toFixed(2);
  766. modeHightFixed = modeHightFixed.substring(
  767. 0,
  768. modeHightFixed.length - 1
  769. );
  770. row.blockCount =
  771. Math.floor(modelLongFixed * modeWideFixed * modeHightFixed) *
  772. row.moCount;
  773. }
  774. row.planProductNum =
  775. Number((modelLong * modeWide * modeHight) / 1000000).toFixed(5) *
  776. row.blockCount;
  777. } else if (name === 'sum') {
  778. //方数
  779. row.planProductNum = e;
  780. row.blockCount = Math.floor(
  781. e / ((modelLong * modeWide * modeHight) / 1000000)
  782. );
  783. if (row.productName.includes('板材')) {
  784. row.moCount = Math.ceil(
  785. row.blockCount /
  786. (Math.floor(600 / modelLong) *
  787. Math.floor(120 / modeHight) *
  788. Math.floor(60 / modeWide))
  789. );
  790. } else if (row.productName.includes('砌块')) {
  791. row.moCount = Math.ceil(
  792. row.blockCount /
  793. Math.floor(
  794. (600 / modelLong) * (120 / modeHight) * (60 / modeWide)
  795. )
  796. );
  797. }
  798. } else if (name === 'blockCount') {
  799. //块数
  800. row.blockCount = e;
  801. if (row.productName.includes('板材')) {
  802. row.moCount = Math.ceil(
  803. row.blockCount /
  804. (Math.floor(600 / modelLong) *
  805. Math.floor(120 / modeHight) *
  806. Math.floor(60 / modeWide))
  807. );
  808. } else if (row.productName.includes('砌块')) {
  809. row.moCount = Math.ceil(
  810. row.blockCount /
  811. Math.floor(
  812. (600 / modelLong) * (120 / modeHight) * (60 / modeWide)
  813. )
  814. );
  815. }
  816. row.planProductNum =
  817. (Number(e) * modelLong * modeWide * modeHight) / 1000000;
  818. }
  819. }
  820. row.requiredFormingNum = Number(
  821. row.planProductNum * (this.form.marginCoefficient || 1)
  822. ).toFixed(5);
  823. },
  824. confirmChoose(list) {
  825. // 取出在弹窗中选中并且不在表格中的数据
  826. const result = list.filter(
  827. (i) => this.form.salesOrders.findIndex((p) => p.id === i.id) === -1
  828. );
  829. // 取出在表格中并且不在弹窗中选中的数据 即取消选中的数据
  830. const del = this.form.salesOrders.filter(
  831. (i) => list.findIndex((p) => p.id === i.id) === -1
  832. );
  833. for (let i = this.form.salesOrders.length - 1; i >= 0; i--) {
  834. for (let j in del) {
  835. if (this.form.salesOrders[i].id === del[j].id) {
  836. this.form.salesOrders.splice(i, 1);
  837. }
  838. }
  839. }
  840. let priority =
  841. this.form.salesOrders[this.form.salesOrders.length - 1]?.priority ||
  842. 0;
  843. this.form.salesOrders = this.form.salesOrders.concat(
  844. result.map((item, index) => {
  845. item.priority = ++priority;
  846. item.planProductNum = item.lackNum;
  847. item.requiredFormingNum = item.lackNum;
  848. item.reqMoldTime = dayjs(
  849. new Date(item.deliveryTime).getTime() - 3600 * 1000 * 24 * 10
  850. ).format('YYYY-MM-DD');
  851. return item;
  852. })
  853. );
  854. this.changeData();
  855. },
  856. changeData() {
  857. var planProductNum = 0;
  858. var productWeight = 0;
  859. this.form.salesOrders.map((item, index) => {
  860. item.priority = index + 1;
  861. planProductNum = planProductNum + item.requiredFormingNum;
  862. productWeight = productWeight + Number(item.productSumWeight);
  863. });
  864. this.$set(this.form, 'codeNum', this.form.salesOrders.length);
  865. this.$set(this.form, 'contractNum', planProductNum);
  866. this.$set(this.form, 'sumOrderWeight', productWeight.toFixed(2));
  867. },
  868. async publishData(type) {
  869. const key = getRouteTabKey();
  870. let params = deepClone(this.form);
  871. params.categoryId = params.salesOrders[0]?.categoryId;
  872. if (this.$route.query.type != 'edit') {
  873. delete params.id;
  874. }
  875. if (type === 2) {
  876. this.$confirm('发布工单后不可撤回,确定发布吗?', '发布确认').then(
  877. async () => {
  878. const loading = this.$loading({
  879. lock: true,
  880. fullscreen: true,
  881. text: '工单发布中...'
  882. });
  883. try {
  884. const code = await getCode('product_order_code');
  885. const data = {
  886. productionPlan: params,
  887. workOrder: {
  888. productionPlanCode: params.code,
  889. code: code,
  890. // formingNum: params.contractNum,
  891. formingNum: this.form.requiredFormingNum,
  892. formingWeight: params.sumOrderWeight,
  893. produceRoutingId: params.produceRoutingId,
  894. status: 4,
  895. model: params.model,
  896. brandNo: params.brandNo,
  897. categoryId: params.categoryId,
  898. productCode: params.productCode,
  899. productName: params.productName,
  900. newWeightUnit: this.form.newWeightUnit,
  901. newSumOrderWeight: this.form.newSumOrderWeight
  902. }
  903. };
  904. if (this.$route.query.type == 'edit') {
  905. data.workOrder.productionPlanId = params.id;
  906. }
  907. console.log(data);
  908. await releaseSave(data)
  909. .then((res) => {
  910. if (res === 1) {
  911. this.$message.success('工单已发布!');
  912. this.$router.push({
  913. path: '/productionPlan'
  914. });
  915. } else {
  916. this.$confirm(
  917. '生产计划创建成功,但工单发布失败。请前往【生产计划】列表【重新发布】工单',
  918. '提示',
  919. {
  920. confirmButtonText: '返回',
  921. cancelButtonText: '立即前往',
  922. type: 'warning'
  923. }
  924. )
  925. .then(() => {
  926. this.$router.push({
  927. path: '/productionPlan'
  928. });
  929. })
  930. .catch(() => {
  931. this.$router.go(-1);
  932. });
  933. }
  934. removePageTab({ key });
  935. })
  936. .catch(() => {
  937. this.$message.error('发布失败,请重新发布!');
  938. });
  939. } catch (error) {}
  940. loading.close();
  941. }
  942. );
  943. } else {
  944. let request =
  945. this.$route.query.type == 'edit'
  946. ? updateSaleToPlan
  947. : saveSaleToPlan;
  948. request(params)
  949. .then(async (res) => {
  950. // 提交
  951. this.$router.push({
  952. path: '/productionPlan'
  953. });
  954. removePageTab({ key });
  955. })
  956. .catch(() => {
  957. this.$message.error('提交失败,请重新提交!');
  958. });
  959. }
  960. },
  961. // 打开工艺路线
  962. openDialog() {
  963. // this.selectIndex = index;
  964. this.$refs.processRouteRef.open();
  965. },
  966. // 选择工艺路线
  967. changeParent(item) {
  968. this.routingList = [];
  969. this.bomVersionList = [];
  970. this.$set(this.form, 'bomCategoryId', null);
  971. this.$set(this.form, 'model', '');
  972. this.$set(this.form, 'produceType', '');
  973. this.$set(this.form, 'produceRoutingName', item.name);
  974. this.$set(this.form, 'produceRoutingId', item.id);
  975. this.form.bomCategoryName = '';
  976. this.form.bomCategoryVersions = '';
  977. this.selectionRowShow = true;
  978. }
  979. }
  980. };
  981. </script>
  982. <style lang="scss" scoped>
  983. .ele-body {
  984. background: #fff;
  985. }
  986. .body-title {
  987. width: 100%;
  988. display: flex;
  989. align-items: center;
  990. justify-content: space-between;
  991. }
  992. .title-left {
  993. font-size: 20px;
  994. color: #333;
  995. }
  996. .formbox {
  997. margin: 20px auto;
  998. }
  999. .row-intro {
  1000. border-bottom: 1px dashed #ccc;
  1001. margin-bottom: 20px;
  1002. }
  1003. .add-product {
  1004. width: 100%;
  1005. display: flex;
  1006. align-items: center;
  1007. justify-content: flex-end;
  1008. font-size: 30px;
  1009. color: #1890ff;
  1010. margin: 10px 0;
  1011. cursor: pointer;
  1012. }
  1013. .table-item {
  1014. margin-bottom: 0;
  1015. }
  1016. .header_required {
  1017. position: relative;
  1018. }
  1019. .header_required:before {
  1020. content: '*';
  1021. color: #f56c6c;
  1022. position: absolute;
  1023. top: 11px;
  1024. left: 15px;
  1025. }
  1026. </style>