index.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667
  1. <template>
  2. <!-- :close-on-click-modal="false" -->
  3. <ele-modal width="70vw" :visible.sync="visible" custom-class="ele-dialog-form" :title="title" :maxable="true">
  4. <div class="form-wrapper">
  5. <el-form ref="form" :model="form" :rules="rules" label-width="90px" class="formbox">
  6. <el-row :gutter="24">
  7. <el-col :span="6">
  8. <el-form-item label="产品名称:" prop="productName">
  9. <el-input @click.native="handleAdd" placeholder="请选择物料" v-model="form.productName" size="mini"></el-input>
  10. </el-form-item>
  11. </el-col>
  12. <el-col :span="6">
  13. <el-form-item label="编码:" prop="productCode">
  14. <el-input placeholder="" size="mini" disabled v-model="form.productCode"></el-input>
  15. </el-form-item>
  16. </el-col>
  17. <el-col :span="6">
  18. <el-form-item label="牌号:" prop="brandNum">
  19. <el-input placeholder="" size="mini" disabled v-model="form.brandNum"></el-input>
  20. </el-form-item>
  21. </el-col>
  22. <el-col :span="6">
  23. <el-form-item label="型号:" prop="modelType">
  24. <el-input placeholder="" size="mini" disabled v-model="form.modelType"></el-input>
  25. </el-form-item>
  26. </el-col>
  27. </el-row>
  28. <el-row :gutter="24">
  29. <el-col :span="6">
  30. <el-form-item label="规格:" prop="specification">
  31. <el-input placeholder="" size="mini" disabled v-model="form.specification"></el-input>
  32. </el-form-item>
  33. </el-col>
  34. </el-row>
  35. <headerTitle title="计划信息"> </headerTitle>
  36. <el-row :gutter="24">
  37. <el-col :span="6">
  38. <el-form-item label="加工方式:" prop="produceType">
  39. <el-select v-model="form.produceType" style="width: 100%" @change="changeProduceType" size="mini">
  40. <el-option v-for="item of producedList" :key="item.code" :label="item.name"
  41. :value="item.code"></el-option>
  42. </el-select>
  43. </el-form-item>
  44. </el-col>
  45. <el-col :span="6">
  46. <el-form-item label="BOM版本:" prop="bomCategoryId" v-if="clientEnvironmentId != 4">
  47. <el-select v-model="form.bomCategoryId" style="width: 100%" @change="changeBomId" size="mini">
  48. <el-option v-for="item of bomVersionList" :key="item.id"
  49. :label="item.name + '(V' + item.versions + '.0)'" :value="item.id"></el-option>
  50. </el-select>
  51. </el-form-item>
  52. </el-col>
  53. <el-col :span="6">
  54. <el-form-item label="工艺路线:" prop="produceRoutingId" v-if="clientEnvironmentId !== 4">
  55. <el-select v-model="form.produceRoutingId" style="width: 100%" @change="changeRoute" size="mini">
  56. <el-option v-for="item of routingList" :key="item.id" :label="item.name" :value="item.id">
  57. </el-option>
  58. </el-select>
  59. </el-form-item>
  60. </el-col>
  61. <el-col :span="6">
  62. <el-form-item label="工艺路线:" prop="produceRoutingId" v-if="clientEnvironmentId == 4">
  63. <el-input v-model="form.produceRoutingName" style="width: 100%" readonly size="mini"></el-input>
  64. </el-form-item>
  65. </el-col>
  66. <el-col :span="6">
  67. <el-form-item label="生产数量:" prop="requiredFormingNum">
  68. <el-input v-model.number="form.requiredFormingNum" @input="tableHandleKeyUp(form, 'sum')" size="mini"
  69. oninput="value=value.replace(/[^\d]/g,'')" style="width: 100%" placeholder="输入数量">
  70. <template slot="append">{{ form.measuringUnit }} </template>
  71. </el-input>
  72. </el-form-item>
  73. </el-col>
  74. </el-row>
  75. <el-row :gutter="24">
  76. <div v-if="clientEnvironmentId==4">
  77. <el-col :span="6">
  78. <el-form-item label="模数:" prop="requiredFormingNum">
  79. <el-input v-model.number="form.moCount" @input="tableHandleKeyUp(form, 'moCount')" size="mini"
  80. oninput="value=value.replace(/[^\d]/g,'')" style="width: 100%" placeholder="输入模数">
  81. <!-- <template slot="append">{{ form.measuringUnit }} </template> -->
  82. </el-input>
  83. </el-form-item>
  84. </el-col>
  85. <el-col :span="6">
  86. <el-form-item label="块数:" prop="requiredFormingNum">
  87. <el-input v-model.number="form.blockCount" @input="tableHandleKeyUp(form, 'blockCount')" size="mini"
  88. oninput="value=value.replace(/[^\d]/g,'')" style="width: 100%" placeholder="输入块数">
  89. <!-- <template slot="append">{{ form.measuringUnit }} </template> -->
  90. </el-input>
  91. </el-form-item>
  92. </el-col>
  93. <el-col :span="6">
  94. <el-form-item label="权重等级:" prop="weight">
  95. <el-select v-model="form.weight" style="width: 100%" @change="changeProduceType" size="mini">
  96. <el-option v-for="item of weightList" :key="item.code" :label="item.name"
  97. :value="item.code"></el-option>
  98. </el-select>
  99. </el-form-item>
  100. </el-col>
  101. <el-col :span="6">
  102. <el-form-item label="是否开槽:" prop="isSlotting">
  103. <el-select v-model="form.isSlotting" style="width: 100%" @change="changeProduceType" size="mini">
  104. <el-option v-for="item of isSlotting" :key="item.code" :label="item.name"
  105. :value="item.code"></el-option>
  106. </el-select>
  107. </el-form-item>
  108. </el-col>
  109. <el-col :span="6" v-if="form.isSlotting == 1">
  110. <el-form-item label="开槽类型:" prop="slottingType">
  111. <DictSelection
  112. dictName="开槽类型"
  113. v-model="form.slottingType"
  114. size="mini"
  115. >
  116. </DictSelection>
  117. </el-form-item>
  118. </el-col>
  119. </div>
  120. <el-col :span="6">
  121. <el-form-item label="批次号:" prop="batchNo">
  122. <el-input v-model="form.batchNo" size="mini" style="width: 100%" placeholder="输入批次号"></el-input>
  123. </el-form-item>
  124. </el-col>
  125. <el-col :span="6">
  126. <el-form-item label="要求完成日期:" label-width="110px" prop="reqMoldTime">
  127. <el-date-picker style="width: 100%" size="mini" v-model="form.reqMoldTime" :pickerOptions="{
  128. disabledDate: (time) =>
  129. time.getTime() <
  130. new Date(new Date().setHours(0, 0, 0, 0)).getTime()
  131. }" type="date" placeholder="选择日期" value-format="yyyy-MM-dd">
  132. </el-date-picker>
  133. </el-form-item>
  134. </el-col>
  135. </el-row>
  136. <el-row :gutter="24">
  137. <el-col :span="6">
  138. <el-form-item label="计划开始日期:" label-width="110px" prop="startTime">
  139. <el-date-picker style="width: 100%" size="mini" v-model="form.startTime" :pickerOptions="{
  140. disabledDate: (time) =>
  141. time.getTime() <
  142. new Date(new Date().setHours(0, 0, 0, 0)).getTime()
  143. }" type="date" placeholder="选择日期" value-format="yyyy-MM-dd">
  144. </el-date-picker>
  145. </el-form-item>
  146. </el-col>
  147. <el-col :span="6">
  148. <el-form-item label="计划结束日期:" label-width="110px" prop="endTime">
  149. <el-date-picker style="width: 100%" size="mini" v-model="form.endTime" :pickerOptions="{
  150. disabledDate: (time) =>
  151. time.getTime() <
  152. new Date(new Date().setHours(0, 0, 0, 0)).getTime()
  153. }" type="date" placeholder="选择日期" value-format="yyyy-MM-dd">
  154. </el-date-picker>
  155. </el-form-item>
  156. </el-col>
  157. </el-row>
  158. </el-form>
  159. <!-- 选择产品 -->
  160. <EquipmentDialog ref="equipmentRefs" @choose="confirmChoose" :selectList="[]">
  161. </EquipmentDialog>
  162. </div>
  163. <template v-slot:footer>
  164. <el-button @click="cancel">取消</el-button>
  165. <el-button type="primary" @click="save" :loading="loading">
  166. 确定
  167. </el-button>
  168. </template>
  169. </ele-modal>
  170. </template>
  171. <script>
  172. import EquipmentDialog from '@/views/saleOrder/components/EquipmentDialog';
  173. import { getCode } from '@/api/codeManagement';
  174. import {
  175. bomRoutingList,
  176. bomListByPlan,
  177. saveSaleToPlan,
  178. temporarilyUpdate
  179. } from '@/api/saleOrder';
  180. export default {
  181. components: {
  182. EquipmentDialog
  183. },
  184. props: {
  185. factoryType: {
  186. type: Number,
  187. default: 3
  188. },
  189. factoryObj: {
  190. type: Object,
  191. default: () => { }
  192. }
  193. },
  194. watch: {
  195. factoryObj: {
  196. immediate: true,
  197. deep: true,
  198. handler(val) {
  199. // this.type = val;
  200. this.title = !val.id ? '新增临时计划' : '编辑临时计划';
  201. // this.form = this.factoryObj;
  202. this.form = val;
  203. // 修改
  204. this.$nextTick(() => {
  205. if (val.id) {
  206. this.bomListVersion();
  207. if (val.bomCategoryId) {
  208. this.getPlanRouting();
  209. }
  210. }
  211. });
  212. }
  213. }
  214. },
  215. computed: {
  216. clientEnvironmentId() {
  217. return this.$store.state.user.info.clientEnvironmentId;
  218. },
  219. },
  220. data() {
  221. return {
  222. visible: false,
  223. title: '',
  224. type: 3,
  225. weightList: [
  226. { code: 1, name: 'A' },
  227. { code: 2, name: 'B' },
  228. { code: 3, name: 'C' }
  229. ],
  230. isSlotting: [
  231. { code: 1, name: '是' },
  232. { code: 2, name: '否' }
  233. ], //是否开槽
  234. loading: false,
  235. form: {
  236. timeDimensionPlanType: 3,
  237. categoryId: '',
  238. productName: '',
  239. planType: 1,
  240. moCount: '', // 模具数量
  241. blockCount: 0, // 块数
  242. noWordCount: '',// 无字数量
  243. weight:'',
  244. isSlotting:'',//是否开槽
  245. slottingType:'',//开槽类型
  246. id: '',
  247. produceType: 2,
  248. bomCategoryId: '',
  249. produceRoutingId: '',
  250. requiredFormingNum: ''
  251. },
  252. bomVersionList: [],
  253. routingList: [],
  254. rules: {
  255. productName: [
  256. { required: true, message: '请选择名称', trigger: 'change' }
  257. ],
  258. bomCategoryId: [
  259. { required: true, message: '请选择BOM版本', trigger: 'blur' }
  260. ],
  261. produceType: [
  262. { required: true, message: '请选择工艺路线', trigger: 'blur' }
  263. ],
  264. produceRoutingId: [
  265. { required: true, message: '请选择工艺路线', trigger: 'blur' }
  266. ],
  267. reqMoldTime: [
  268. { required: true, message: '请选择要求完成日期', trigger: 'blur' }
  269. ],
  270. requiredFormingNum: [
  271. { required: true, message: '请输入生产数量', trigger: 'blur' }
  272. ]
  273. },
  274. producedList: [
  275. { code: 2, name: '加工(MBOM)' },
  276. { code: 3, name: '装配(ABOM)' }
  277. ]
  278. };
  279. },
  280. computed: {
  281. clientEnvironmentId() {
  282. return this.$store.state.user.info.clientEnvironmentId;
  283. }
  284. },
  285. methods: {
  286. open() {
  287. this.visible = true;
  288. //this.clientEnvironmentId 环境判断 宝悦环境
  289. if (this.clientEnvironmentId == 4) {
  290. this.getPlanRoutingNew();
  291. }
  292. // this.getPlanRoutingNew();
  293. },
  294. handleAdd() {
  295. this.$refs.equipmentRefs.open();
  296. },
  297. confirmChoose(list) {
  298. if (this.clientEnvironmentId == 4) {
  299. let data = {};
  300. if (list[0].name.includes('板材')) {
  301. data = {
  302. id: '1856970794952372226',
  303. name: '板材',
  304. produceVersionName: '板材'
  305. };
  306. } else {
  307. data = {
  308. id: '1857313733642596353',
  309. name: '砌块',
  310. produceVersionName: '砌块'
  311. };
  312. }
  313. this.$set(this.form, 'produceRoutingName', data.name);
  314. this.$set(this.form, 'produceRoutingId', data.id);
  315. this.$set(this.form, 'produceVersionName', data.produceVersionName);
  316. }
  317. this.$set(this.form, 'categoryId', list[0].id);
  318. this.$set(this.form, 'productName', list[0].name);
  319. this.$set(this.form, 'productCode', list[0].code);
  320. this.$set(this.form, 'specification', list[0].specification);
  321. this.$set(this.form, 'brandNum', list[0].brandNum);
  322. this.$set(this.form, 'modelType', list[0].modelType);
  323. this.$set(this.form, 'measuringUnit', list[0].measuringUnit);
  324. //重置
  325. this.$set(this.form, 'produceType', '');
  326. this.$set(this.form, 'bomCategoryId', '');
  327. this.$set(this.form, 'produceRoutingId', '');
  328. this.bomListVersion();
  329. },
  330. handleDeleteItem(index) {
  331. this.form.salesOrders.splice(index, 1);
  332. },
  333. async getPlanCode() {
  334. this.loading = true;
  335. try {
  336. const code = await getCode('product_code');
  337. this.$set(this.form, 'code', code);
  338. } catch (err) { }
  339. },
  340. initForm() {
  341. this.form = {
  342. timeDimensionPlanType: 3,
  343. categoryId: '',
  344. productName: '',
  345. planType: 1,
  346. moCount: '', // 模具数量
  347. blockCount: 0, // 块数
  348. noWordCount: '',// 无字数量
  349. weight:'',
  350. isSlotting:'',//是否开槽
  351. slottingType:'',//开槽类型
  352. id: '',
  353. produceType: 2,
  354. bomCategoryId: '',
  355. produceRoutingId: '',
  356. requiredFormingNum: ''
  357. };
  358. },
  359. save() {
  360. this.$refs.form.validate(async (valid) => {
  361. if (!valid) {
  362. return false;
  363. }
  364. if (!this.form.id) {
  365. this.form.timeDimensionPlanType = this.type;
  366. await this.getPlanCode();
  367. this.loading = true;
  368. saveSaleToPlan(this.form)
  369. .then((res) => {
  370. this.$message.success('新增成功!');
  371. this.visible = false;
  372. this.initForm();
  373. this.$emit('close', true);
  374. })
  375. .finally(() => {
  376. this.loading = false;
  377. });
  378. } else {
  379. this.loading = true;
  380. temporarilyUpdate(this.form)
  381. .then((res) => {
  382. this.$message.success('修改成功!');
  383. this.visible = false;
  384. this.initForm();
  385. this.$emit('close', true);
  386. })
  387. .finally(() => {
  388. this.loading = false;
  389. });
  390. }
  391. });
  392. },
  393. bomListVersion() {
  394. let param = {
  395. bomType: this.form.produceType,
  396. categoryId: this.form.categoryId
  397. };
  398. bomListByPlan(param).then((res) => {
  399. this.bomVersionList = res || [];
  400. });
  401. },
  402. // 工艺路线
  403. getPlanRouting() {
  404. bomRoutingList(this.form.bomCategoryId).then((res) => {
  405. this.routingList = res || [];
  406. });
  407. },
  408. // 宝悦 工艺路线
  409. getPlanRoutingNew() {
  410. // bomRoutingList(this.form.bomCategoryId).then((res) => {
  411. // this.routingList = res || []
  412. // })
  413. },
  414. tableHandleKeyUp(row, name) {
  415. // return
  416. // , index, e, name
  417. if (this.form.specification && this.clientEnvironmentId == 4) {
  418. let modelArr = this.form.specification.split('*');
  419. let modelLong = modelArr[0]; // model规格长度
  420. let modeWide = modelArr[1]; // model规格宽度
  421. let modeHight = modelArr[2].substr(0, modelArr[2].indexOf('cm')); // model规格高度
  422. modeHight = Number(modeHight);
  423. if (name === 'moCount') {
  424. // 模数
  425. this.$set(this.form, 'moCount', row.moCount);
  426. // 计算块数的公式:
  427. // (一模6米长度 / model规格长度) * (一模1.2米宽度 / model规格宽度) = 每一模的块数
  428. // 每一模的块数*模数moCount = 总块数
  429. if (row.productName.includes('板材')) {
  430. // 块数
  431. let blockCount =
  432. Math.floor(600 / modelLong) *
  433. Math.floor(120 / modeHight) *
  434. Math.floor(60 / modeWide) *
  435. row.moCount;
  436. this.$set(this.form, 'blockCount', blockCount);
  437. } else if (row.productName.includes('砌块')) {
  438. console.log(1);
  439. let modelLongFixed = (600 / modelLong).toFixed(2);
  440. modelLongFixed = modelLongFixed.substring(
  441. 0,
  442. modelLongFixed.length - 1
  443. );
  444. let modeWideFixed = (120 / modeWide).toFixed(2);
  445. modeWideFixed = modeWideFixed.substring(
  446. 0,
  447. modeWideFixed.length - 1
  448. );
  449. let modeHightFixed = (60 / modeHight).toFixed(2);
  450. modeHightFixed = modeHightFixed.substring(
  451. 0,
  452. modeHightFixed.length - 1
  453. );
  454. let num =
  455. Math.floor(modelLongFixed * modeWideFixed * modeHightFixed) *
  456. row.moCount;
  457. this.$set(this.form, 'blockCount', num);
  458. }
  459. let numNew =
  460. (Number((modelLong * modeWide * modeHight) / 1000000).toFixed(5) *
  461. row.blockCount).toFixed(5);
  462. this.$set(this.form, 'requiredFormingNum', numNew);
  463. } else if (name === 'sum') {
  464. let e = this.form.requiredFormingNum
  465. console.log('方数');
  466. //方数
  467. this.form.planProductNum = e;
  468. this.form.blockCount = Math.floor(
  469. e / ((modelLong * modeWide * modeHight) / 1000000)
  470. );
  471. if (this.form.productName.includes('板材')) {
  472. let num = Math.ceil(
  473. this.form.blockCount /
  474. (Math.floor(600 / modelLong) *
  475. Math.floor(120 / modeHight) *
  476. Math.floor(60 / modeWide))
  477. );
  478. // 48 480 4807 480
  479. this.$set(this.form, 'moCount', num)
  480. } else if (row.productName.includes('砌块')) {
  481. row.moCount = Math.ceil(
  482. row.blockCount /
  483. Math.floor(
  484. (600 / modelLong) * (120 / modeHight) * (60 / modeWide)
  485. )
  486. );
  487. }
  488. } else if (name === 'blockCount') {
  489. //块数
  490. // row.blockCount = row.moCount;
  491. this.$set(this.form, 'blockCount', row.blockCount);
  492. if (row.productName.includes('板材')) {
  493. let moCount = Math.ceil(
  494. row.blockCount /
  495. (Math.floor(600 / modelLong) *
  496. Math.floor(120 / modeHight) *
  497. Math.floor(60 / modeWide))
  498. );
  499. this.$set(this.form, 'moCount', moCount);
  500. } else if (row.productName.includes('砌块')) {
  501. let moCount = Math.ceil(
  502. row.blockCount /
  503. Math.floor(
  504. (600 / modelLong) * (120 / modeHight) * (60 / modeWide)
  505. )
  506. );
  507. this.$set(this.form, 'moCount', moCount);
  508. }
  509. let a =
  510. ((Number(this.form.blockCount) * modelLong * modeWide * modeHight) / 1000000).toFixed(5);
  511. this.$set(this.form, 'requiredFormingNum', a);
  512. }
  513. }
  514. },
  515. changeProduceType() {
  516. if (this.clientEnvironmentId !== 4) {
  517. this.form.bomCategoryId = '';
  518. this.form['bomCategoryName'] = '';
  519. this.form['bomCategoryVersions'] = '';
  520. this.bomVersionList = [];
  521. this.routingList = [];
  522. this.form.produceRoutingId = '';
  523. this.form.produceRoutingName = '';
  524. this.form.produceVersionName = '';
  525. this.bomListVersion();
  526. }
  527. },
  528. changeBomId() {
  529. this.routingList = [];
  530. this.form.produceRoutingId = '';
  531. this.form.produceRoutingName = '';
  532. this.form.produceVersionName = '';
  533. this.bomVersionList.forEach((f) => {
  534. if (f.id == this.form.bomCategoryId) {
  535. this.$set(this.form, 'bomCategoryName', f.name);
  536. this.$set(this.form, 'bomCategoryVersions', f.versions);
  537. }
  538. });
  539. this.getPlanRouting();
  540. },
  541. changeRoute() {
  542. console.log(this.routingList, this.form.produceRoutingId);
  543. this.$forceUpdate()
  544. this.routingList.forEach((f) => {
  545. if (f.id == this.form.produceRoutingId) {
  546. this.$set(this.form, 'produceRoutingId', f.id);
  547. this.$set(this.form, 'produceRoutingName', f.name);
  548. this.$set(this.form, 'produceVersionName', f.version);
  549. }
  550. });
  551. },
  552. cancel() {
  553. console.log('取消');
  554. this.visible = false;
  555. this.$emit('close');
  556. }
  557. }
  558. };
  559. </script>
  560. <style lang="scss" scoped>
  561. .el-form-item {
  562. margin-bottom: 14px !important;
  563. }
  564. </style>