index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464
  1. <template>
  2. <!-- :close-on-click-modal="false" -->
  3. <ele-modal width="80vw" :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="8">
  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="8">
  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="8">
  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-row>
  23. <el-row :gutter="24">
  24. <el-col :span="8">
  25. <el-form-item label="型号:" prop="modelType">
  26. <el-input placeholder="" size="mini" disabled v-model="form.modelType"></el-input>
  27. </el-form-item>
  28. </el-col>
  29. <el-col :span="8">
  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="8">
  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="8">
  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="8">
  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="8">
  62. <el-form-item label="工艺路线:" prop="produceRoutingId" v-if="clientEnvironmentId == 4">
  63. <el-input v-model="form.produceRoutingName" style="width: 100%" readonly></el-input>
  64. </el-form-item>
  65. </el-col>
  66. </el-row>
  67. <el-row :gutter="24">
  68. <el-col :span="8">
  69. <el-form-item label="生产数量:" prop="requiredFormingNum">
  70. <el-input v-model.number="form.requiredFormingNum" size="mini" oninput="value=value.replace(/[^\d]/g,'')"
  71. style="width: 100%" placeholder="输入数量">
  72. <template slot="append">{{ form.measuringUnit }} </template>
  73. </el-input>
  74. </el-form-item>
  75. </el-col>
  76. <el-col :span="8">
  77. <el-form-item label="批次号:" prop="batchNo">
  78. <el-input v-model="form.batchNo" size="mini" style="width: 100%" placeholder="输入批次号"></el-input>
  79. </el-form-item>
  80. </el-col>
  81. <el-col :span="8">
  82. <el-form-item label="要求完成日期:" label-width="110px" prop="reqMoldTime">
  83. <el-date-picker style="width: 100%" size="mini" v-model="form.reqMoldTime" :pickerOptions="{
  84. disabledDate: (time) =>
  85. time.getTime() <
  86. new Date(new Date().setHours(0, 0, 0, 0)).getTime()
  87. }" type="date" placeholder="选择日期" value-format="yyyy-MM-dd">
  88. </el-date-picker>
  89. </el-form-item>
  90. </el-col>
  91. </el-row>
  92. <el-row :gutter="24">
  93. <el-col :span="8">
  94. <el-form-item label="计划开始日期:" label-width="110px" prop="startTime">
  95. <el-date-picker style="width: 100%" size="mini" v-model="form.startTime" :pickerOptions="{
  96. disabledDate: (time) =>
  97. time.getTime() <
  98. new Date(new Date().setHours(0, 0, 0, 0)).getTime()
  99. }" type="date" placeholder="选择日期" value-format="yyyy-MM-dd">
  100. </el-date-picker>
  101. </el-form-item>
  102. </el-col>
  103. <el-col :span="8">
  104. <el-form-item label="计划结束日期:" label-width="110px" prop="endTime">
  105. <el-date-picker style="width: 100%" size="mini" v-model="form.endTime" :pickerOptions="{
  106. disabledDate: (time) =>
  107. time.getTime() <
  108. new Date(new Date().setHours(0, 0, 0, 0)).getTime()
  109. }" type="date" placeholder="选择日期" value-format="yyyy-MM-dd">
  110. </el-date-picker>
  111. </el-form-item>
  112. </el-col>
  113. </el-row>
  114. </el-form>
  115. <!-- 选择产品 -->
  116. <EquipmentDialog ref="equipmentRefs" @choose="confirmChoose" :selectList="[]">
  117. </EquipmentDialog>
  118. </div>
  119. <template v-slot:footer>
  120. <el-button @click="cancel">取消</el-button>
  121. <el-button type="primary" @click="save" :loading="loading">
  122. 确定
  123. </el-button>
  124. </template>
  125. </ele-modal>
  126. </template>
  127. <script>
  128. import EquipmentDialog from '@/views/saleOrder/components/EquipmentDialog';
  129. import { getCode } from '@/api/codeManagement';
  130. import {
  131. bomRoutingList,
  132. bomListByPlan,
  133. saveSaleToPlan,
  134. temporarilyUpdate
  135. } from '@/api/saleOrder';
  136. export default {
  137. components: {
  138. EquipmentDialog
  139. },
  140. props: {
  141. factoryType: {
  142. type: Number,
  143. default: 3
  144. },
  145. factoryObj: {
  146. type: Object,
  147. default: () => { }
  148. }
  149. },
  150. watch: {
  151. factoryObj: {
  152. immediate: true,
  153. deep: true,
  154. handler(val) {
  155. // this.type = val;
  156. this.title = !val.id ? '新增临时计划' : '编辑临时计划';
  157. // this.form = this.factoryObj;
  158. this.form = val;
  159. // 修改
  160. this.$nextTick(() => {
  161. if (val.id) {
  162. this.bomListVersion();
  163. if (val.bomCategoryId) {
  164. this.getPlanRouting();
  165. }
  166. }
  167. });
  168. }
  169. }
  170. },
  171. computed: {
  172. clientEnvironmentId() {
  173. return this.$store.state.user.info.clientEnvironmentId;
  174. },
  175. },
  176. data() {
  177. return {
  178. visible: false,
  179. title: '',
  180. type: 3,
  181. loading: false,
  182. form: {
  183. timeDimensionPlanType: 3,
  184. categoryId: '',
  185. productName: '',
  186. planType: 1,
  187. id: '',
  188. produceType: 2,
  189. bomCategoryId: '',
  190. produceRoutingId: '',
  191. requiredFormingNum: ''
  192. },
  193. bomVersionList: [],
  194. routingList: [],
  195. rules: {
  196. productName: [
  197. { required: true, message: '请选择名称', trigger: 'change' }
  198. ],
  199. bomCategoryId: [
  200. { required: true, message: '请选择BOM版本', trigger: 'blur' }
  201. ],
  202. produceType: [
  203. { required: true, message: '请选择工艺路线', trigger: 'blur' }
  204. ],
  205. produceRoutingId: [
  206. { required: true, message: '请选择工艺路线', trigger: 'blur' }
  207. ],
  208. reqMoldTime: [
  209. { required: true, message: '请选择要求完成日期', trigger: 'blur' }
  210. ],
  211. requiredFormingNum: [
  212. { required: true, message: '请输入生产数量', trigger: 'blur' }
  213. ]
  214. },
  215. producedList: [
  216. { code: 2, name: '加工(MBOM)' },
  217. { code: 3, name: '装配(ABOM)' }
  218. ]
  219. };
  220. },
  221. computed: {
  222. clientEnvironmentId() {
  223. return this.$store.state.user.info.clientEnvironmentId;
  224. }
  225. },
  226. methods: {
  227. open() {
  228. this.visible = true;
  229. console.log(this.clientEnvironmentId, '999999999');
  230. //this.clientEnvironmentId 环境判断 宝悦环境
  231. if (this.clientEnvironmentId == 4) {
  232. this.getPlanRoutingNew();
  233. }
  234. // this.getPlanRoutingNew();
  235. },
  236. handleAdd() {
  237. this.$refs.equipmentRefs.open();
  238. },
  239. confirmChoose(list) {
  240. console.log(list, '6666666666666666');
  241. if (this.clientEnvironmentId == '4') {
  242. let data = {};
  243. if (list[0].name.includes('板材')) {
  244. data = {
  245. id: '1856970794952372226',
  246. name: '板材',
  247. produceVersionName: '板材'
  248. };
  249. } else {
  250. data = {
  251. id: '1857313733642596353',
  252. name: '砌块',
  253. produceVersionName: '砌块'
  254. };
  255. }
  256. this.$set(this.form, 'produceRoutingName', data.name);
  257. this.$set(this.form, 'produceRoutingId', data.id);
  258. this.$set(this.form, 'produceVersionName', data.produceVersionName);
  259. }
  260. this.$set(this.form, 'categoryId', list[0].id);
  261. this.$set(this.form, 'productName', list[0].name);
  262. this.$set(this.form, 'productCode', list[0].code);
  263. this.$set(this.form, 'specification', list[0].specification);
  264. this.$set(this.form, 'brandNum', list[0].brandNum);
  265. this.$set(this.form, 'modelType', list[0].modelType);
  266. this.$set(this.form, 'measuringUnit', list[0].measuringUnit);
  267. this.bomListVersion();
  268. },
  269. handleDeleteItem(index) {
  270. this.form.salesOrders.splice(index, 1);
  271. },
  272. async getPlanCode() {
  273. this.loading = true;
  274. try {
  275. const code = await getCode('product_code');
  276. this.$set(this.form, 'code', code);
  277. } catch (err) { }
  278. },
  279. initForm() {
  280. this.form = {
  281. timeDimensionPlanType: 3,
  282. categoryId: '',
  283. productName: '',
  284. planType: 1,
  285. id: '',
  286. produceType: 2,
  287. bomCategoryId: '',
  288. produceRoutingId: '',
  289. requiredFormingNum: ''
  290. };
  291. },
  292. save() {
  293. this.$refs.form.validate(async (valid) => {
  294. if (!valid) {
  295. return false;
  296. }
  297. //
  298. console.log(this.form.id, 'this.form.idthis.form.idthis.form.idthis.form.id');
  299. if (!this.form.id) {
  300. this.form.timeDimensionPlanType = this.type;
  301. await this.getPlanCode();
  302. this.loading = true;
  303. saveSaleToPlan(this.form)
  304. .then((res) => {
  305. this.$message.success('新增成功!');
  306. this.visible = false;
  307. this.initForm();
  308. this.$emit('close', true);
  309. })
  310. .finally(() => {
  311. this.loading = false;
  312. });
  313. } else {
  314. this.loading = true;
  315. temporarilyUpdate(this.form)
  316. .then((res) => {
  317. this.$message.success('修改成功!');
  318. this.visible = false;
  319. this.initForm();
  320. this.$emit('close', true);
  321. })
  322. .finally(() => {
  323. this.loading = false;
  324. });
  325. }
  326. });
  327. },
  328. bomListVersion() {
  329. let param = {
  330. bomType: this.form.produceType,
  331. categoryId: this.form.categoryId
  332. };
  333. bomListByPlan(param).then((res) => {
  334. this.bomVersionList = res || [];
  335. });
  336. },
  337. // 工艺路线
  338. getPlanRouting() {
  339. bomRoutingList(this.form.bomCategoryId).then((res) => {
  340. this.routingList = res || [];
  341. });
  342. },
  343. // 宝悦 工艺路线
  344. getPlanRoutingNew() {
  345. // bomRoutingList(this.form.bomCategoryId).then((res) => {
  346. // this.routingList = res || []
  347. // })
  348. },
  349. changeProduceType() {
  350. this.form.bomCategoryId = '';
  351. this.form['bomCategoryName'] = '';
  352. this.form['bomCategoryVersions'] = '';
  353. this.bomVersionList = [];
  354. this.routingList = [];
  355. this.form.produceRoutingId = '';
  356. this.form.produceRoutingName = '';
  357. this.form.produceVersionName = '';
  358. this.bomListVersion();
  359. },
  360. changeBomId() {
  361. this.routingList = [];
  362. this.form.produceRoutingId = '';
  363. this.form.produceRoutingName = '';
  364. this.form.produceVersionName = '';
  365. this.bomVersionList.forEach((f) => {
  366. if (f.id == this.form.bomCategoryId) {
  367. this.$set(this.form, 'bomCategoryName', f.name);
  368. this.$set(this.form, 'bomCategoryVersions', f.versions);
  369. }
  370. });
  371. this.getPlanRouting();
  372. },
  373. changeRoute() {
  374. console.log(this.routingList, this.form.produceRoutingId);
  375. this.$forceUpdate()
  376. this.routingList.forEach((f) => {
  377. if (f.id == this.form.produceRoutingId) {
  378. this.$set(this.form, 'produceRoutingId', f.id);
  379. this.$set(this.form, 'produceRoutingName', f.name);
  380. this.$set(this.form, 'produceVersionName', f.version);
  381. }
  382. });
  383. },
  384. cancel() {
  385. console.log('取消');
  386. this.visible = false;
  387. this.$emit('close');
  388. }
  389. }
  390. };
  391. </script>
  392. <style lang="scss" scoped>
  393. .el-form-item {
  394. margin-bottom: 14px !important;
  395. }
  396. </style>