MaterialModal.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401
  1. <template>
  2. <ele-modal width="1160px" :visible="visible" v-if="visible" :append-to-body="true" :close-on-click-modal="true"
  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. <header-title title="物料BOM">
  39. <div>
  40. <el-button size="small" icon="el-icon-plus" class="ele-btn-icon" type="primary"
  41. @click="handleAdd">新增</el-button>
  42. </div>
  43. </header-title>
  44. <el-card v-for="(bomItem, index) in form.list" :key="index">
  45. <el-row>
  46. <el-col :span="8">
  47. <el-form-item label="BOM编码:">
  48. {{ bomItem.code }}
  49. </el-form-item>
  50. </el-col>
  51. <el-col :span="8">
  52. <el-form-item label="BOM名称:" prop="name">
  53. {{ bomItem.name }}
  54. </el-form-item>
  55. </el-col>
  56. <el-col :span="8">
  57. <el-form-item label="版本号:" prop="version">
  58. {{ bomItem.version }}
  59. </el-form-item>
  60. </el-col>
  61. <el-col :span="8">
  62. <el-form-item label="状态:" prop="status">
  63. <el-select v-model="bomItem.status" placeholder="" filterable disabled>
  64. <el-option v-for="item in statusList" :key="item.value" :label="item.label"
  65. :value="item.value">
  66. </el-option>
  67. </el-select>
  68. </el-form-item>
  69. </el-col>
  70. <el-col :span="8">
  71. <el-form-item label="生产版本:" prop="produceVersionId">
  72. <el-select v-model="bomItem.produceVersionId" filterable placeholder="清选择" disabled
  73. :style="{ width: '100%' }">
  74. <el-option v-for="item in versionList" :key="item.code" :label="item.code + '-' + item.name"
  75. :value="item.id">
  76. </el-option>
  77. </el-select>
  78. </el-form-item>
  79. </el-col>
  80. <el-col :span="8">
  81. <el-form-item label="所属工厂:" prop="factoryId">
  82. <factorySelect v-model="bomItem.factoryId" disabled />
  83. </el-form-item>
  84. </el-col>
  85. <el-col :span="8">
  86. <el-form-item label="基本数量:" prop="baseCount">
  87. <el-row>
  88. <el-col :span="12">
  89. {{ bomItem.baseCount }}
  90. </el-col>
  91. <el-col :span="2">&nbsp;</el-col>
  92. <el-col :span="10">
  93. <DictSelection disabled dictName="计量单位:" v-model="bomItem.baseCountUnit" />
  94. </el-col>
  95. </el-row>
  96. </el-form-item>
  97. </el-col>
  98. </el-row>
  99. <el-row>
  100. <div class="ele-body">
  101. <ele-pro-table ref="table" :datasource="bomItem.materialList" row-key="id" :columns="columns">
  102. <!-- 表头工具栏 -->
  103. <template v-slot:toolbar>
  104. <el-button size="small" icon="el-icon-plus" class="ele-btn-icon" type="primary"
  105. @click.native="openParam(index)">添加物料</el-button>
  106. <el-button size="small" type="danger" icon="el-icon-delete"
  107. @click="removeBom(index)">删除</el-button>
  108. </template>
  109. <!-- 操作列 -->
  110. <template v-slot:action="{ row }">
  111. <el-popconfirm class="ele-action" title="确定要删除当前物料吗?" @confirm="remove(index, row)">
  112. <template v-slot:reference>
  113. <el-link type="danger" :underline="false" icon="el-icon-delete">
  114. 删除
  115. </el-link>
  116. </template>
  117. </el-popconfirm>
  118. </template>
  119. </ele-pro-table>
  120. </div>
  121. </el-row>
  122. </el-card>
  123. </el-form>
  124. <!-- 选择物料弹窗 -->
  125. <materialDialog ref="materiaRef" @chooseModal="chooseModal"></materialDialog>
  126. <!-- 物料Bom -->
  127. <MaterialAdd :visible.sync="materialShow" :categoryId="categoryId" ref="materialAddRef"></MaterialAdd>
  128. </ele-modal>
  129. </template>
  130. <script>
  131. import materialDialog from '@/components/material'
  132. import MaterialAdd from './MaterialAdd.vue'
  133. import { pageList } from '@/api/technology/version/version.js';
  134. import { getCategoryBom } from '@/api/material/product'
  135. import factorySelect from '@/components/CommomSelect/factory-select.vue';
  136. export default {
  137. components: {
  138. materialDialog,
  139. MaterialAdd,
  140. factorySelect
  141. },
  142. props: {
  143. // 弹窗是否打开
  144. visible: Boolean,
  145. // 修改回显的数据
  146. data: Object
  147. },
  148. data() {
  149. const defaultForm = {
  150. id: null,
  151. code: '',
  152. name: '',
  153. modelType: '',
  154. brandNum: '',
  155. specification: '',
  156. measuringUnit: '',
  157. list: [
  158. ]
  159. };
  160. return {
  161. defaultForm,
  162. // 表单数据
  163. form: {
  164. ...defaultForm,
  165. },
  166. versionList: [],
  167. // 表单验证规则
  168. rules: {
  169. categoryName: [
  170. { required: true, message: '请输入产品名称', trigger: 'blur' }
  171. ],
  172. },
  173. columns: [
  174. {
  175. prop: 'code',
  176. label: '编码'
  177. },
  178. {
  179. prop: 'name',
  180. label: '名称',
  181. showOverflowTooltip: true
  182. },
  183. {
  184. prop: 'brandNum',
  185. label: '牌号'
  186. },
  187. {
  188. prop: 'modelType',
  189. label: '型号'
  190. },
  191. {
  192. prop: 'weightUnit',
  193. label: '重量单位'
  194. },
  195. {
  196. prop: 'netWeight',
  197. label: '净重'
  198. },
  199. {
  200. columnKey: 'action',
  201. label: '操作',
  202. align: 'center',
  203. resizable: false,
  204. slot: 'action',
  205. showOverflowTooltip: true
  206. }
  207. ],
  208. statusList: [
  209. { label: '草稿', value: -1 },
  210. { label: '失效', value: 0 },
  211. { label: '生效', value: 1 }
  212. ],
  213. // 提交状态
  214. loading: false,
  215. categoryId: null,
  216. tableData: [],
  217. materialShow: false
  218. };
  219. },
  220. computed: {
  221. // 是否开启响应式布局
  222. styleResponsive() {
  223. return this.$store.state.theme.styleResponsive;
  224. }
  225. },
  226. methods: {
  227. openParam(index) {
  228. this.tableData = this.form.list[index].materialList
  229. this.$refs.materiaRef.open(this.tableData, '选择物料', '1', index)
  230. },
  231. chooseModal(data, id, idx) {
  232. this.$set(this.form.list[idx], 'materialList', data)
  233. },
  234. /* 删除 */
  235. remove(index, row) {
  236. console.log(row)
  237. this.form.list[index].materialList = this.form.list[index].materialList.filter((d) => d.id !== row.id)
  238. },
  239. /* 表格数据源 */
  240. datasource({ page, limit, where }) {
  241. return []
  242. },
  243. async getVersionList() {
  244. const res = await pageList({
  245. pageNum: 1,
  246. size: 100
  247. });
  248. this.versionList = res.list
  249. },
  250. handleAdd() {
  251. this.materialShow = true
  252. },
  253. removeBom(index) {
  254. this.form.list.splice(index, 1)
  255. },
  256. /* 更新visible */
  257. updateVisible(value) {
  258. this.$emit('update:visible', value);
  259. },
  260. async getCategoryBomFn() {
  261. const res = await getCategoryBom(this.categoryId)
  262. this.form.list = res.bomList
  263. console.log(res)
  264. },
  265. },
  266. watch: {
  267. async visible(visible) {
  268. if (visible) {
  269. this.getVersionList()
  270. if (this.data) {
  271. this.categoryId = this.data.id
  272. this.getCategoryBomFn()
  273. this.$util.assignObject(this.form, {
  274. ...this.data
  275. });
  276. } else {
  277. }
  278. } else {
  279. this.$refs.form.clearValidate();
  280. this.form = { ...this.defaultForm };
  281. }
  282. }
  283. }
  284. };
  285. </script>