edit-dialog.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469
  1. <template>
  2. <ele-modal custom-class="ele-dialog-form" :visible.sync="visible" v-if="visible" :title="title" width="80%"
  3. @close="cancel">
  4. <headerTitle title="基本信息"></headerTitle>
  5. <el-form label-width="100px" ref="form" :model="form" :rules="rules">
  6. <el-row>
  7. <el-col :span="8" label-width="100px">
  8. <el-form-item label="BOM编码" prop="code">
  9. <el-input placeholder="自动生成" disabled v-model="form.code"></el-input>
  10. </el-form-item>
  11. </el-col>
  12. <el-col :span="8">
  13. <el-form-item label="BOM名称" prop="name">
  14. <el-input placeholder="请输入" v-model="form.name"></el-input>
  15. </el-form-item>
  16. </el-col>
  17. <el-col :span="8">
  18. <el-form-item label="所属工厂" prop="factoryId">
  19. <factorySelect v-model="form.factoryId" />
  20. </el-form-item>
  21. </el-col>
  22. <el-col :span="8">
  23. <el-form-item label="产品编码" prop="categoryCode">
  24. <el-input placeholder="请输入" v-model="form.categoryCode" @click.native="selectProd"></el-input>
  25. </el-form-item>
  26. </el-col>
  27. <el-col :span="8">
  28. <el-form-item label="产品名称" prop="categoryName">
  29. <el-input placeholder="请选择" disabled v-model="form.categoryName"></el-input>
  30. </el-form-item>
  31. </el-col>
  32. <el-col :span="8">
  33. <el-form-item label="版本号" prop="version">
  34. <el-input placeholder="请选择" disabled v-model="form.version"></el-input>
  35. </el-form-item>
  36. </el-col>
  37. <!--
  38. <el-col :span="8">
  39. <el-form-item label="分类层级" prop="categoryType">
  40. <el-select v-model="form.categoryType" placeholder="请选择" class="w100">
  41. <el-option v-for="item in categoryList" :key="item.value" :label="item.label"
  42. :value="item.value"></el-option>
  43. </el-select>
  44. </el-form-item>
  45. </el-col> -->
  46. <!-- <el-col :span="8">
  47. <el-form-item label="生产版本:" prop="produceVersionId">
  48. <el-select v-model="form.produceVersionId" filterable placeholder="请选择" :style="{ width: '100%' }">
  49. <el-option v-for="item in versionList" :key="item.id" :label="item.code + '-' + item.name" :value="item.id">
  50. </el-option>
  51. </el-select>
  52. </el-form-item>
  53. </el-col> -->
  54. <el-col :span="8">
  55. <el-form-item label="基本数量" prop="baseCount">
  56. <el-row>
  57. <el-col :span="16">
  58. <el-input placeholder="请输入" v-model.number="form.baseCount">
  59. </el-input></el-col>
  60. <el-col :span="2">&nbsp;</el-col>
  61. <el-col :span="6">
  62. <DictSelection dictName="计量单位" v-model="form.baseCountUnit" />
  63. </el-col>
  64. </el-row>
  65. </el-form-item>
  66. </el-col>
  67. <el-col :span="8">
  68. <el-form-item label="状态" prop="status">
  69. <el-select :disabled="title == '新建'" clearable v-model="form.status" placeholder="请选择" class="w100">
  70. <el-option v-for="item in Object.entries(statusOpt)" :key="item[0]" :label="item[1]"
  71. :value="item[0]"></el-option>
  72. </el-select>
  73. </el-form-item>
  74. </el-col>
  75. <el-col :span="8">
  76. <el-form-item label="工序" prop="taskId">
  77. <el-input placeholder="请选择" @click.native="openTask" readonly v-model="form.taskName"></el-input>
  78. </el-form-item>
  79. </el-col>
  80. </el-row>
  81. </el-form>
  82. <ele-pro-table ref="table" :columns="columns" :datasource="tableData" height="calc(100vh - 550px)" :need-page="false">
  83. <!-- 表头工具栏 -->
  84. <template v-slot:toolbar>
  85. <el-button type="primary" @click="add">添加</el-button>
  86. </template>
  87. <template v-slot:action="{ row, $index }">
  88. <el-link type="primary" @click="handleDel(row, $index)">删除</el-link>
  89. </template>
  90. <template v-slot:subCode="{ row }">
  91. <el-input v-model="row.subCode" placeholder="请输入"></el-input>
  92. </template>
  93. <template v-slot:isReworkBom="{ row }">
  94. <el-select v-model="row.isReworkBom">
  95. <el-option v-for="item in isReworkBomList" :key="item.value" :label="item.label" :value="item.value">
  96. </el-option>
  97. </el-select>
  98. </template>
  99. <template v-slot:unit="{ row }">
  100. <DictSelection dictName="重量单位" v-model="row.unit"></DictSelection>
  101. </template>
  102. <template v-slot:count="{ row }">
  103. <el-input v-model="row.count" placeholder="请输入" @input="(value) =>
  104. (row.count = value.replace(
  105. /^(-)*(\d+)\.(\d\d\d\d\d\d).*$/,
  106. '$1$2.$3'
  107. ))
  108. "></el-input>
  109. </template>
  110. <template v-slot:categoryName="{ row, $index }">
  111. <el-input :value="row.categoryName" placeholder="请选择" @click.native="categorySelect(row, $index)"></el-input>
  112. </template>
  113. </ele-pro-table>
  114. <div slot="footer" class="footer">
  115. <el-button type="primary" @click="save">保存</el-button>
  116. <el-button @click="cancel">返回</el-button>
  117. </div>
  118. <ProductModal ref="productRefs" @changeProduct='determineChoose' />
  119. <!-- 添加工序 -->
  120. <ele-modal width="1720px" :visible="addDialog" :append-to-body="true" :close-on-click-modal="true"
  121. @update:visible="closeAdd">
  122. <Production :tableData="productionList" ref="ProductionCom" :isRadio="true" />
  123. <template v-slot:footer>
  124. <el-button @click="closeAdd">取消</el-button>
  125. <el-button type="primary" @click="addParamrter">
  126. 添加
  127. </el-button>
  128. </template>
  129. </ele-modal>
  130. </ele-modal>
  131. </template>
  132. <script>
  133. import ProductModal from '@/views/technology/productParam/components/ProductModal.vue'
  134. import factorySelect from '@/components/CommomSelect/factory-select.vue';
  135. import { getCode } from '@/api/codeManagement/index.js';
  136. import { getVersionCode, bomSave, bomUpdate, getById, detailPage } from '@/api/material/BOM';
  137. import { pageList } from '@/api/technology/version/version.js';
  138. import Production from '@/views/technology/route/components/production/index.vue'
  139. export default {
  140. components: { ProductModal, factorySelect, Production },
  141. props: {
  142. statusOpt: Object
  143. },
  144. data() {
  145. var baseCountVa = (rule, value, callback) => {
  146. if (value == '') {
  147. callback(new Error('请输入基本数量'));
  148. } else if (this.form.baseCountUnit == '') {
  149. callback(new Error('请选择基本数量单位'));
  150. } else {
  151. callback();
  152. }
  153. };
  154. return {
  155. visible: false,
  156. title: '',
  157. row: {},
  158. form: {
  159. code: '',
  160. name: '',
  161. type: 0,
  162. factoryId: '',
  163. categoryCode: '',
  164. categoryId: '',
  165. categoryName: '',
  166. isReworkBom: 0,
  167. version: '',
  168. categoryType: '',
  169. baseCount: '',
  170. baseCountUnit: '',
  171. status: '-1',
  172. taskId: ''
  173. },
  174. removeSubBomIdList: [],
  175. categoryList: [
  176. {
  177. value: 1,
  178. label: '产品'
  179. },
  180. {
  181. value: 2,
  182. label: '部件'
  183. },
  184. {
  185. value: 3,
  186. label: '零件'
  187. }
  188. ],
  189. tableData: [],
  190. // versionList: [],
  191. productionList: [],
  192. addDialog: false,
  193. columns: [
  194. {
  195. type: 'index',
  196. width: 55,
  197. align: 'center'
  198. },
  199. {
  200. label: '子项编号',
  201. prop: 'subCode',
  202. slot: 'subCode',
  203. action: 'subCode'
  204. },
  205. {
  206. label: '物料名称',
  207. prop: 'categoryName',
  208. slot: 'categoryName',
  209. action: 'categoryName'
  210. },
  211. {
  212. label: '是否回收料',
  213. prop: 'isReworkBom',
  214. slot: 'isReworkBom',
  215. action: 'isReworkBom'
  216. },
  217. {
  218. label: '物料编码',
  219. prop: 'categoryCode'
  220. },
  221. {
  222. label: '牌号',
  223. prop: 'brandNum'
  224. },
  225. {
  226. label: '型号',
  227. prop: 'modelType'
  228. },
  229. {
  230. label: '数量',
  231. slot: 'count',
  232. action: 'count'
  233. },
  234. {
  235. label: '单位',
  236. slot: 'unit',
  237. action: 'unit'
  238. },
  239. {
  240. action: 'action',
  241. slot: 'action',
  242. label: '操作'
  243. }
  244. ],
  245. rules: {
  246. name: [
  247. { required: true, message: '请输入BOM名称', trigger: 'blur' }
  248. ],
  249. factoryId: [
  250. { required: true, message: '请输入所属工厂', trigger: 'change' }
  251. ],
  252. categoryCode: [
  253. { required: true, message: '请输入产品编码', trigger: 'blur' }
  254. ],
  255. baseCount: [
  256. { validator: baseCountVa, trigger: 'blur' }
  257. ],
  258. taskId: [
  259. { required: true, message: '请选择工序', trigger: 'blur' }
  260. ]
  261. },
  262. // 提交状态
  263. loading: false,
  264. // 是否是修改
  265. isUpdate: false,
  266. isReworkBomList: [
  267. { label: '否', value: 0 },
  268. { label: '是', value: 1 }
  269. ],
  270. };
  271. },
  272. methods: {
  273. async open(type, row) {
  274. this.title = type;
  275. this.row = row;
  276. // this.getVersionList()
  277. this.visible = true;
  278. if (type == '新建') {
  279. this._getCode();
  280. } else {
  281. this.isUpdate = true
  282. this._getById(row.id);
  283. const res = await detailPage({ pageNum: 1, size: -1, bomId: row.id })
  284. this.tableData = res.list
  285. }
  286. },
  287. add() {
  288. let subCode = '0010';
  289. if (this.tableData.length) {
  290. let max = Math.max(...this.tableData.map((i) => i.subCode)) + 10 + '';
  291. if (max.length < 4) {
  292. max = new Array(4 - max.length).fill('0').join('') + max;
  293. }
  294. subCode = max.substring(0, max.length - 1) + '0';
  295. }
  296. this.tableData.push({
  297. subCode,
  298. categoryId: '',
  299. categoryName: '',
  300. isReworkBom: 0,
  301. brandNum: '',
  302. count: '',
  303. modelType: '',
  304. unit: ''
  305. });
  306. },
  307. async _getCode() {
  308. const code = await getCode('bom_code');
  309. this.form.code = code;
  310. },
  311. selectProd() {
  312. this.$refs.productRefs.open(this.form, '选择产品', '9')
  313. },
  314. categorySelect(row, idx) {
  315. this.$refs.productRefs.open(row, '选择物料', '1', idx)
  316. },
  317. determineChoose(title, row, idx) {
  318. if (title == '选择产品') {
  319. this.$set(this.form, 'categoryName', row.name)
  320. this.$set(this.form, 'categoryId', row.id)
  321. this.$set(this.form, 'categoryCode', row.code)
  322. this.getVersion()
  323. }
  324. else if (title == '选择物料') {
  325. this.$set(this.tableData[idx], 'categoryName', row.name)
  326. this.$set(this.tableData[idx], 'categoryId', row.id)
  327. this.$set(this.tableData[idx], 'categoryCode', row.code)
  328. this.$set(this.tableData[idx], 'unit', row.measuringUnit)
  329. this.$set(this.tableData[idx], 'brandNum', row.brandNum)
  330. this.$set(this.tableData[idx], 'modelType', row.modelType)
  331. }
  332. },
  333. async getVersion() {
  334. const res = await getVersionCode(this.form.categoryId);
  335. this.form.version = res
  336. },
  337. async getVersionList() {
  338. const res = await pageList({
  339. pageNum: 1,
  340. size: 100
  341. });
  342. this.versionList = res.list
  343. },
  344. save() {
  345. this.$refs.form.validate((valid) => {
  346. if (!valid) {
  347. return false;
  348. }
  349. this.loading = true;
  350. if (!this.isUpdate) {
  351. delete this.form.id;
  352. } else {
  353. this.form.removeSubBomIdList = this.removeSubBomIdList
  354. }
  355. const data = {
  356. ...this.form,
  357. subDetailList: this.tableData
  358. };
  359. const saveOrUpdate = this.isUpdate ? bomUpdate : bomSave;
  360. saveOrUpdate(data)
  361. .then((msg) => {
  362. this.loading = false;
  363. this.$message.success(msg);
  364. this.cancel()
  365. this.$emit('done');
  366. })
  367. .catch((e) => {
  368. this.loading = false;
  369. });
  370. });
  371. },
  372. handleDel(row, index) {
  373. this.tableData.splice(index, 1);
  374. if (row?.id) {
  375. this.removeSubBomIdList.push(row.id)
  376. }
  377. },
  378. cancel() {
  379. this.visible = false
  380. },
  381. async _getById(id) {
  382. const data = await getById(id);
  383. this.form = data;
  384. this.productionList = [{ id: this.form.taskId, name: this.form.taskName }]
  385. this.form.status = this.form.status + ''
  386. },
  387. openTask() {
  388. this.addDialog = true
  389. },
  390. /*关闭选择参数*/
  391. closeAdd() {
  392. // this.$refs.ProductionCom.$refs.table.setSelectedRows([]);
  393. this.addDialog = false;
  394. },
  395. addParamrter() {
  396. let arr = this.$refs.ProductionCom.getRowData();
  397. this.productionList = [arr]
  398. this.form['taskId'] = arr.id
  399. this.form['taskName'] = arr.name
  400. this.addDialog = false;
  401. }
  402. }
  403. };
  404. </script>