MaterialModal.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523
  1. <template>
  2. <ele-modal width="1260px" :visible="visible" v-if="visible" :append-to-body="true" :close-on-click-modal="false"
  3. custom-class="ele-dialog-form" title="选择物料" @update:visible="updateVisible">
  4. <header-title title="基本信息"></header-title>
  5. <el-form ref="form" :model="form" :rules="rules" label-width="120px">
  6. <el-row>
  7. <el-col :span="8">
  8. <el-form-item label="产品名称:" prop="name">
  9. <el-input disabled v-model="form.name" readonly />
  10. </el-form-item>
  11. </el-col>
  12. <el-col :span="8">
  13. <el-form-item label="产品编码:" prop="code">
  14. <el-input disabled v-model="form.code" placeholder="自动带入" />
  15. </el-form-item>
  16. </el-col>
  17. <el-col :span="8">
  18. <el-form-item label="型号:" prop="modelType">
  19. <el-input disabled v-model="form.modelType" placeholder="自动带入" />
  20. </el-form-item>
  21. </el-col>
  22. <el-col :span="8">
  23. <el-form-item label="牌号:" prop="brandNum">
  24. <el-input disabled v-model="form.brandNum" placeholder="自动带入" />
  25. </el-form-item>
  26. </el-col>
  27. <el-col :span="8">
  28. <el-form-item label="规格:" prop="specification">
  29. <el-input disabled v-model="form.specification" placeholder="自动带入" />
  30. </el-form-item>
  31. </el-col>
  32. <el-col :span="8">
  33. <el-form-item label="计量单位:" prop="measuringUnit">
  34. <el-input disabled v-model="form.measuringUnit" placeholder="自动带入" />
  35. </el-form-item>
  36. </el-col>
  37. </el-row>
  38. <el-button type="primary" size="small" style="margin-bottom: 10px;" @click="handleAddTab">添加工序</el-button>
  39. <el-tabs v-model="tabsValue" type="card" closable @tab-click="handleTab" @tab-remove="removeTab">
  40. <el-tab-pane v-for="(item, index) in tabsList" :key="item.id + index" :label="item.name" :name="item.id">
  41. <header-title title="物料BOM" style="margin-top: 10px">
  42. <div>
  43. <el-button size="small" icon="el-icon-plus" class="ele-btn-icon" type="primary"
  44. @click="handleAdd(item.id)">新增</el-button>
  45. </div>
  46. </header-title>
  47. <el-card v-for="(bomItem, index) in form.bomList" :key="index">
  48. <el-row>
  49. <el-col :span="8">
  50. <el-form-item label="BOM编码:">
  51. {{ bomItem.code }}
  52. </el-form-item>
  53. </el-col>
  54. <el-col :span="8">
  55. <el-form-item label="BOM名称:" prop="name">
  56. {{ bomItem.name }}
  57. </el-form-item>
  58. </el-col>
  59. <el-col :span="8">
  60. <el-form-item label="版本号:" prop="version">
  61. {{ bomItem.version }}
  62. </el-form-item>
  63. </el-col>
  64. <el-col :span="8">
  65. <el-form-item label="状态:" prop="status">
  66. <el-select v-model="bomItem.status" placeholder="" filterable disabled>
  67. <el-option v-for="item in statusList" :key="item.value" :label="item.label"
  68. :value="item.value">
  69. </el-option>
  70. </el-select>
  71. </el-form-item>
  72. </el-col>
  73. <el-col :span="8">
  74. <el-form-item label="所属工厂:" prop="factoryId">
  75. <factorySelect v-model="bomItem.factoryId" disabled />
  76. </el-form-item>
  77. </el-col>
  78. <el-col :span="8">
  79. <el-form-item label="基本数量:" prop="baseCount">
  80. <el-row>
  81. <el-col :span="12">
  82. {{ bomItem.baseCount }}
  83. </el-col>
  84. <el-col :span="2">&nbsp;</el-col>
  85. <el-col :span="10">
  86. <DictSelection disabled dictName="计量单位:" v-model="bomItem.baseCountUnit" />
  87. </el-col>
  88. </el-row>
  89. </el-form-item>
  90. </el-col>
  91. </el-row>
  92. <el-row>
  93. <div class="ele-body">
  94. <ele-pro-table ref="table" :columns="columns" :need-page="false" row-key="id"
  95. :datasource="bomItem.subDetailList" min-height="200px">
  96. <template v-slot:isReworkBom="{ row }">
  97. {{ row.isReworkBom ? '是' : '否' }}
  98. </template>
  99. <template v-slot:bomArtFiles="{ row }">
  100. <div v-if="row.bomArtFiles && row.bomArtFiles?.length">
  101. <el-link v-for="link in row.bomArtFiles" :key="link.id" type="primary"
  102. :underline="false" @click="downloadFile(link)">
  103. {{ link.name }}</el-link>
  104. </div>
  105. </template>
  106. <template v-slot:toolbar>
  107. <el-button type="primary" size="small" @click="openEdit(index)">编辑</el-button>
  108. <el-popconfirm class="ele-action" title="确定要删除此物料BOM?" @confirm="remove(bomItem)">
  109. <template v-slot:reference>
  110. <el-button type="danger" size="small" icon="el-icon-delete">
  111. 删除
  112. </el-button>
  113. </template>
  114. </el-popconfirm>
  115. </template>
  116. </ele-pro-table>
  117. </div>
  118. </el-row>
  119. </el-card>
  120. </el-tab-pane>
  121. </el-tabs>
  122. </el-form>
  123. <!-- 物料Bom -->
  124. <MaterialAdd :visible.sync="materialShow" :taskId="taskId" :data="current" :categoryId="categoryId" @done="done"
  125. ref="materialAddRef">
  126. </MaterialAdd>
  127. <!-- 添加工序 -->
  128. <ele-modal width="1720px" :visible="addDialog" :append-to-body="true" :close-on-click-modal="false"
  129. @update:visible="closeAdd">
  130. <Production :tableData="tableData" ref="ProductionCom" />
  131. <template v-slot:footer>
  132. <el-button @click="closeAdd">取消</el-button>
  133. <el-button type="primary" @click="addParamrter">
  134. 添加
  135. </el-button>
  136. </template>
  137. </ele-modal>
  138. </ele-modal>
  139. </template>
  140. <script>
  141. import MaterialAdd from './MaterialAdd.vue';
  142. import { pageList } from '@/api/technology/version/version.js';
  143. import { getCategoryBom } from '@/api/material/product';
  144. import { bomDelete, saveBatch, bomTaskList, bomTaskDelete, getByTaskId } from '@/api/material/BOM';
  145. import factorySelect from '@/components/CommomSelect/factory-select.vue';
  146. import Production from '@/views/technology/route/components/production/index.vue'
  147. import { getFile } from "@/api/system/file";
  148. export default {
  149. components: {
  150. MaterialAdd,
  151. factorySelect,
  152. Production
  153. },
  154. props: {
  155. // 弹窗是否打开
  156. visible: Boolean,
  157. // 修改回显的数据
  158. data: Object
  159. },
  160. data() {
  161. const defaultForm = {
  162. id: null,
  163. code: '',
  164. name: '',
  165. modelType: '',
  166. brandNum: '',
  167. specification: '',
  168. measuringUnit: '',
  169. bomList: []
  170. };
  171. return {
  172. defaultForm,
  173. // 表单数据
  174. form: {
  175. ...defaultForm
  176. },
  177. versionList: [],
  178. // 表单验证规则
  179. rules: {
  180. categoryName: [
  181. { required: true, message: '请输入产品名称', trigger: 'blur' }
  182. ]
  183. },
  184. columns: [
  185. {
  186. type: 'index',
  187. width: 55,
  188. align: 'center'
  189. },
  190. {
  191. label: '子项编号',
  192. prop: 'subCode',
  193. action: 'subCode'
  194. },
  195. {
  196. label: '物料名称',
  197. prop: 'categoryName',
  198. action: 'categoryName'
  199. },
  200. {
  201. label: '是否回收料',
  202. prop: 'isReworkBom',
  203. action: 'isReworkBom',
  204. slot: 'isReworkBom',
  205. width: 95,
  206. },
  207. {
  208. label: '物料编码',
  209. prop: 'categoryCode'
  210. },
  211. {
  212. label: '牌号',
  213. prop: 'brandNum'
  214. },
  215. {
  216. label: '型号',
  217. prop: 'modelType'
  218. },
  219. {
  220. label: '数量',
  221. prop: 'count'
  222. },
  223. {
  224. label: '计量单位',
  225. prop: 'unit'
  226. },
  227. {
  228. label: '附件',
  229. slot: 'bomArtFiles',
  230. action: 'bomArtFiles',
  231. minWidth: 100,
  232. },
  233. {
  234. label: '单位',
  235. prop: 'weightUnit'
  236. },
  237. {
  238. label: '备注',
  239. prop: 'remark',
  240. },
  241. ],
  242. statusList: [
  243. { label: '草稿', value: -1 },
  244. { label: '失效', value: 0 },
  245. { label: '生效', value: 1 }
  246. ],
  247. // 提交状态
  248. loading: false,
  249. categoryId: null,
  250. current: null,
  251. materialShow: false,
  252. tabsList: [],
  253. tableData: [],
  254. taskId: null,
  255. addDialog: false,
  256. tabsValue: null
  257. };
  258. },
  259. computed: {
  260. // 是否开启响应式布局
  261. styleResponsive() {
  262. return this.$store.state.theme.styleResponsive;
  263. }
  264. },
  265. methods: {
  266. downloadFile(file) {
  267. getFile({ objectName: file.storePath }, file.name);
  268. },
  269. openEdit(index) {
  270. this.current = this.form.bomList[index];
  271. this.materialShow = true;
  272. },
  273. /* 表格数据源 */
  274. datasource({ page, limit, where }) {
  275. return [];
  276. },
  277. async getVersionList() {
  278. const res = await pageList({
  279. pageNum: 1,
  280. size: 100
  281. });
  282. this.versionList = res.list;
  283. },
  284. handleAdd(id) {
  285. this.taskId = id
  286. this.current = null;
  287. this.materialShow = true;
  288. },
  289. /* 更新visible */
  290. updateVisible(value) {
  291. this.$emit('update:visible', value);
  292. },
  293. async getCategoryBomFn(taskId) {
  294. const res = await getByTaskId(this.categoryId, taskId);
  295. this.form.bomList = res;
  296. },
  297. remove(row) {
  298. bomDelete([row.id])
  299. .then((message) => {
  300. this.$message.success(message);
  301. this.getCategoryBomFn();
  302. })
  303. .catch((e) => {
  304. this.$message.error(e.message);
  305. });
  306. },
  307. done(taskId) {
  308. this.materialShow = false
  309. this.getCategoryBomFn(taskId);
  310. },
  311. handleAddTab() {
  312. this.tableData = this.tabsList
  313. this.addDialog = true;
  314. },
  315. handleTab(e) {
  316. this.getCategoryBomFn(e.name);
  317. },
  318. removeTab(targetName) {
  319. this.$confirm('是否删除当前工序?', '提示', {
  320. confirmButtonText: '确定',
  321. cancelButtonText: '取消',
  322. type: 'warning'
  323. })
  324. .then(() => {
  325. this.tabsList.forEach(e => {
  326. if (e.id == targetName) {
  327. bomTaskDelete([e.oldId]).then(res => {
  328. this.taskListHead()
  329. })
  330. }
  331. })
  332. })
  333. .catch(() => { });
  334. },
  335. /*关闭选择参数*/
  336. closeAdd() {
  337. this.$refs.ProductionCom.$refs.table.setSelectedRows([]);
  338. this.addDialog = false;
  339. },
  340. addParamrter() {
  341. let arr = [];
  342. arr = this.$refs.ProductionCom.selection.map(m => {
  343. return {
  344. sourceTaskId: m.id,
  345. ...m
  346. }
  347. })
  348. if (arr.length == 0) {
  349. this.addDialog = false;
  350. return false
  351. }
  352. this.tabsList = arr
  353. this.addDialog = false;
  354. this.$refs.ProductionCom.$refs.table.setSelectedRows([]);
  355. if (this.tabsList.length > 0) {
  356. this.tabsValue = this.tabsList[0].id
  357. this.saveBatchFn()
  358. }
  359. },
  360. // 保存
  361. saveBatchFn() {
  362. let arr = [];
  363. arr = this.tabsList.map(m => {
  364. return {
  365. taskId: m.id,
  366. sort: m.sort,
  367. categoryId: this.categoryId
  368. }
  369. })
  370. saveBatch(arr).then(res => {
  371. this.taskListHead()
  372. })
  373. },
  374. taskListHead(isFirst) {
  375. console.log(isFirst)
  376. bomTaskList(this.categoryId).then(res => {
  377. let arr = []
  378. arr = res.map(m => {
  379. return {
  380. oldId: m.id,
  381. sourceTaskId: m.id,
  382. id: m.taskId,
  383. name: m.taskName
  384. }
  385. })
  386. this.tabsList = arr
  387. if (isFirst && this.tabsList.length > 0) {
  388. this.tabsValue = this.tabsList[0].id
  389. this.getCategoryBomFn(this.tabsList[0].id);
  390. }
  391. })
  392. },
  393. },
  394. watch: {
  395. async visible(visible) {
  396. if (visible) {
  397. this.getVersionList();
  398. if (this.data) {
  399. this.categoryId = this.data.id;
  400. this.$util.assignObject(this.form, {
  401. ...this.data
  402. });
  403. } else {
  404. }
  405. this.taskListHead(true)
  406. } else {
  407. this.$refs.form.clearValidate();
  408. this.form = { ...this.defaultForm };
  409. }
  410. }
  411. }
  412. };
  413. </script>
  414. <style lang="scss" scoped></style>