MaterialAdd.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481
  1. <template>
  2. <ele-modal
  3. width="1160px"
  4. :visible="visible"
  5. v-if="visible"
  6. :append-to-body="true"
  7. :close-on-click-modal="false"
  8. custom-class="ele-dialog-form"
  9. title="物料BOM"
  10. @update:visible="updateVisible"
  11. :maxable="true"
  12. >
  13. <el-form ref="form" :model="form" :rules="rules" label-width="120px">
  14. <header-title title="物料BOM"> </header-title>
  15. <el-row>
  16. <el-col :span="8">
  17. <el-form-item label="BOM编码:" prop="code">
  18. <el-input v-model="form.code" disabled />
  19. </el-form-item>
  20. </el-col>
  21. <el-col :span="8">
  22. <el-form-item label="BOM名称:" prop="name">
  23. <el-input placeholder="请输入BOM名称" v-model="form.name" />
  24. </el-form-item>
  25. </el-col>
  26. <el-col :span="8">
  27. <el-form-item label="版本号:" prop="version">
  28. <el-input placeholder="请输入BOM版本号" v-model="form.version" />
  29. </el-form-item>
  30. </el-col>
  31. <el-col :span="8">
  32. <el-form-item label="状态:" prop="status">
  33. <el-select v-model="form.status" placeholder="" filterable>
  34. <el-option
  35. v-for="item in statusList"
  36. :key="item.value"
  37. :label="item.label"
  38. :value="item.value"
  39. >
  40. </el-option>
  41. </el-select>
  42. </el-form-item>
  43. </el-col>
  44. <el-col :span="8">
  45. <el-form-item label="所属工厂" prop="factoryId">
  46. <factorySelect v-model="form.factoryId" />
  47. </el-form-item>
  48. </el-col>
  49. <el-col :span="8">
  50. <el-form-item label="基本数量" prop="baseCount">
  51. <el-row>
  52. <el-col :span="12">
  53. <el-input placeholder="请输入" v-model.number="form.baseCount">
  54. </el-input
  55. ></el-col>
  56. <el-col :span="2">&nbsp;</el-col>
  57. <el-col :span="10">
  58. <DictSelection
  59. dictName="计量单位"
  60. v-model="form.baseCountUnit"
  61. />
  62. </el-col>
  63. </el-row>
  64. </el-form-item>
  65. </el-col>
  66. </el-row>
  67. <el-row>
  68. <div class="ele-body">
  69. <ele-pro-table
  70. ref="table"
  71. :columns="columns"
  72. :datasource="tableData"
  73. height="calc(100vh - 550px)"
  74. :need-page="false"
  75. >
  76. <!-- 表头工具栏 -->
  77. <template v-slot:toolbar>
  78. <el-button type="primary" @click="add">添加</el-button>
  79. </template>
  80. <template v-slot:action="{ row, $index }">
  81. <el-link type="primary" @click="handleDel(row, $index)"
  82. >删除</el-link
  83. >
  84. </template>
  85. <template v-slot:subCode="{ row }">
  86. <el-input v-model="row.subCode" placeholder="请输入"></el-input>
  87. </template>
  88. <template v-slot:isReworkBom="{ row }">
  89. <el-select v-model="row.isReworkBom">
  90. <el-option
  91. v-for="item in isReworkBomList"
  92. :key="item.value"
  93. :label="item.label"
  94. :value="item.value"
  95. >
  96. </el-option>
  97. </el-select>
  98. </template>
  99. <template v-slot:unit="{ row }">
  100. <DictSelection
  101. dictName="计量单位"
  102. v-model="row.unit"
  103. ></DictSelection>
  104. </template>
  105. <template v-slot:count="{ row }">
  106. <el-input
  107. v-model="row.count"
  108. placeholder="请输入"
  109. @input="
  110. (value) =>
  111. (row.count = value.replace(
  112. /^(-)*(\d+)\.(\d\d\d\d\d\d).*$/,
  113. '$1$2.$3'
  114. ))
  115. "
  116. ></el-input>
  117. </template>
  118. <template v-slot:categoryName="{ row, $index }">
  119. <el-input
  120. :value="row.categoryName"
  121. placeholder="请选择"
  122. @click.native="categorySelect(row, $index)"
  123. ></el-input>
  124. </template>
  125. <template v-slot:bomArtFiles="{ row }">
  126. <fileUpload
  127. v-model="row.bomArtFiles"
  128. module="main"
  129. :showLib="false"
  130. :limit="5"
  131. />
  132. <div v-if="row.bomArtFiles && row.bomArtFiles?.length">
  133. <el-link
  134. v-for="link in row.bomArtFiles"
  135. :key="link.id"
  136. type="primary"
  137. :underline="false"
  138. @click="downloadFile(link)"
  139. >
  140. {{ link.name }}</el-link
  141. >
  142. </div>
  143. </template>
  144. <template v-slot:remark="{ row }">
  145. <el-input v-model="row.remark" placeholder="请输入"></el-input>
  146. </template>
  147. </ele-pro-table>
  148. </div>
  149. </el-row>
  150. <el-row class="rx-cc">
  151. <el-button
  152. type="primary"
  153. size="small"
  154. class="ele-btn-icon"
  155. @click="save"
  156. >
  157. 保存
  158. </el-button>
  159. </el-row>
  160. </el-form>
  161. <ProductModal ref="productRefs" @changeProduct="determineChoose" />
  162. </ele-modal>
  163. </template>
  164. <script>
  165. import factorySelect from '@/components/CommomSelect/factory-select.vue';
  166. import { pageList } from '@/api/technology/version/version.js';
  167. import { getCode } from '@/api/codeManagement/index.js';
  168. import { bomSave, bomUpdate } from '@/api/material/BOM';
  169. import ProductModal from '@/components/select/bom/ProductModal.vue';
  170. import fileUpload from '@/components/upload/fileUpload';
  171. import { getFile } from '@/api/system/file';
  172. export default {
  173. components: {
  174. factorySelect,
  175. ProductModal,
  176. fileUpload
  177. },
  178. props: {
  179. // 弹窗是否打开
  180. visible: Boolean,
  181. // 修改回显的数据
  182. categoryId: [String, Number],
  183. data: Object,
  184. taskId: [String, Number]
  185. },
  186. data() {
  187. var baseCountVa = (rule, value, callback) => {
  188. if (value == '') {
  189. callback(new Error('请输入基本数量'));
  190. } else if (this.form.baseCountUnit == '') {
  191. callback(new Error('请选择基本数量单位'));
  192. } else {
  193. callback();
  194. }
  195. };
  196. const defaultForm = {
  197. id: null,
  198. code: '',
  199. name: '',
  200. version: '1.0',
  201. factoryId: '',
  202. type: 0,
  203. status: '',
  204. isReworkBom: 0,
  205. baseCount: '',
  206. baseCountUnit: '',
  207. taskId: ''
  208. };
  209. return {
  210. defaultForm,
  211. // 表单数据
  212. form: {
  213. ...defaultForm
  214. },
  215. removeSubBomIdList: [],
  216. versionList: [],
  217. // 表单验证规则
  218. rules: {
  219. code: [{ required: true, message: '请输入BOM编码', trigger: 'blur' }],
  220. name: [{ required: true, message: '请输入BOM名称', trigger: 'blur' }],
  221. version: [
  222. { required: true, message: '请输入BOM版本号', trigger: 'blur' }
  223. ],
  224. status: [
  225. { required: true, message: '请选择状态', trigger: 'change' }
  226. ],
  227. factoryId: [
  228. { required: true, message: '请输入所属工厂', trigger: 'change' }
  229. ],
  230. baseCount: [{ validator: baseCountVa, trigger: 'blur' }]
  231. },
  232. columns: [
  233. {
  234. type: 'index',
  235. width: 55,
  236. align: 'center'
  237. },
  238. {
  239. label: '子项编号',
  240. prop: 'subCode',
  241. slot: 'subCode',
  242. action: 'subCode'
  243. },
  244. {
  245. label: '物料名称',
  246. prop: 'categoryName',
  247. slot: 'categoryName',
  248. action: 'categoryName'
  249. },
  250. {
  251. label: '是否回收料',
  252. prop: 'isReworkBom',
  253. slot: 'isReworkBom',
  254. action: 'isReworkBom'
  255. },
  256. {
  257. label: '物料编码',
  258. prop: 'categoryCode'
  259. },
  260. {
  261. label: '牌号',
  262. prop: 'brandNum'
  263. },
  264. {
  265. label: '型号',
  266. prop: 'modelType'
  267. },
  268. {
  269. label: '数量',
  270. slot: 'count',
  271. action: 'count'
  272. },
  273. {
  274. label: '单位',
  275. slot: 'unit',
  276. action: 'unit'
  277. },
  278. {
  279. label: '附件',
  280. slot: 'bomArtFiles',
  281. action: 'bomArtFiles',
  282. minWidth: 100
  283. },
  284. {
  285. label: '备注',
  286. slot: 'remark',
  287. action: 'remark'
  288. },
  289. {
  290. action: 'action',
  291. slot: 'action',
  292. label: '操作'
  293. }
  294. ],
  295. tableData: [],
  296. statusList: [
  297. { label: '草稿', value: -1 },
  298. { label: '失效', value: 0 },
  299. { label: '生效', value: 1 }
  300. ],
  301. isReworkBomList: [
  302. { label: '否', value: 0 },
  303. { label: '是', value: 1 }
  304. ],
  305. // 提交状态
  306. loading: false,
  307. // 是否是修改
  308. isUpdate: false
  309. };
  310. },
  311. computed: {
  312. // 是否开启响应式布局
  313. styleResponsive() {
  314. return this.$store.state.theme.styleResponsive;
  315. }
  316. },
  317. methods: {
  318. downloadFile(file) {
  319. getFile({ objectName: file.storePath }, file.name);
  320. },
  321. handleDel(row, index) {
  322. this.tableData.splice(index, 1);
  323. if (row?.id) {
  324. this.removeSubBomIdList.push(row.id);
  325. }
  326. },
  327. add() {
  328. let subCode = '0010';
  329. if (this.tableData.length) {
  330. let max = Math.max(...this.tableData.map((i) => i.subCode)) + 10 + '';
  331. if (max.length < 4) {
  332. max = new Array(4 - max.length).fill('0').join('') + max;
  333. }
  334. subCode = max.substring(0, max.length - 1) + '0';
  335. }
  336. this.tableData.push({
  337. subCode,
  338. categoryId: '',
  339. categoryName: '',
  340. isReworkBom: 0,
  341. brandNum: '',
  342. count: '',
  343. modelType: '',
  344. unit: '',
  345. netWeight: '',
  346. weightUnit: ''
  347. });
  348. },
  349. async _getCode() {
  350. const code = await getCode('bom_code');
  351. this.form.code = code;
  352. },
  353. /* 保存编辑 */
  354. save() {
  355. this.$refs.form.validate((valid) => {
  356. if (!valid) {
  357. return false;
  358. }
  359. if (this.tableData.length == 0) {
  360. this.$message.error('请至少添加一条物料');
  361. return;
  362. }
  363. let boolen = this.tableData.every((item) => item.categoryName);
  364. if (!boolen) {
  365. this.$message.error('请完善物料名称!');
  366. return false;
  367. }
  368. if (!this.isUpdate) {
  369. delete this.form.id;
  370. this.form['taskId'] = this.taskId;
  371. }
  372. const data = {
  373. ...this.form,
  374. removeSubBomIdList: this.removeSubBomIdList,
  375. subDetailList: this.tableData,
  376. categoryId: this.categoryId
  377. };
  378. this.loading = true;
  379. const saveOrUpdate = this.isUpdate ? bomUpdate : bomSave;
  380. saveOrUpdate(data)
  381. .then((msg) => {
  382. this.loading = false;
  383. this.$message.success(msg);
  384. this.$emit('done', this.form['taskId']);
  385. this.visible = false;
  386. })
  387. .catch((e) => {
  388. this.loading = false;
  389. });
  390. });
  391. },
  392. categorySelect(row, idx) {
  393. // 3 type: 物料组
  394. this.$refs.productRefs.open(row, '选择物料', 3, idx);
  395. },
  396. determineChoose(title, row, idx) {
  397. if (title == '选择物料') {
  398. this.$set(this.tableData[idx], 'categoryName', row.name);
  399. this.$set(this.tableData[idx], 'categoryId', row.id);
  400. this.$set(this.tableData[idx], 'categoryCode', row.code);
  401. this.$set(this.tableData[idx], 'unit', row.measuringUnit);
  402. this.$set(this.tableData[idx], 'weightUnit', row.weightUnit);
  403. this.$set(this.tableData[idx], 'brandNum', row.brandNum);
  404. this.$set(this.tableData[idx], 'modelType', row.modelType);
  405. }
  406. },
  407. /* 更新visible */
  408. updateVisible(value) {
  409. this.$emit('update:visible', value);
  410. }
  411. },
  412. watch: {
  413. async visible(visible) {
  414. if (visible) {
  415. this._getCode();
  416. this.removeSubBomIdList = [];
  417. if (this.data) {
  418. this.tableData = this.data.subDetailList;
  419. this.$util.assignObject(this.form, {
  420. ...this.data
  421. });
  422. this.isUpdate = true;
  423. } else {
  424. this.tableData = [];
  425. this.isUpdate = false;
  426. }
  427. } else {
  428. this.$refs.form.clearValidate();
  429. this.form = { ...this.defaultForm };
  430. }
  431. }
  432. }
  433. };
  434. </script>