edit-dialog.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  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-row>
  76. </el-form>
  77. <ele-pro-table ref="table" :columns="columns" :datasource="tableData" height="calc(100vh - 550px)" :need-page="false">
  78. <!-- 表头工具栏 -->
  79. <template v-slot:toolbar>
  80. <el-button type="primary" @click="add">添加</el-button>
  81. </template>
  82. <template v-slot:action="{ row, $index }">
  83. <el-link type="primary" @click="handleDel(row, $index)">删除</el-link>
  84. </template>
  85. <template v-slot:subCode="{ row }">
  86. <el-input v-model="row.subCode" placeholder="请输入"></el-input>
  87. </template>
  88. <template v-slot:unit="{ row }">
  89. <DictSelection dictName="计量单位" v-model="row.unit"></DictSelection>
  90. </template>
  91. <template v-slot:count="{ row }">
  92. <el-input v-model="row.count" placeholder="请输入" @input="(value) =>
  93. (row.count = value.replace(
  94. /^(-)*(\d+)\.(\d\d\d\d\d\d).*$/,
  95. '$1$2.$3'
  96. ))
  97. "></el-input>
  98. </template>
  99. <template v-slot:categoryName="{ row, $index }">
  100. <el-input :value="row.categoryName" placeholder="请选择" @click.native="categorySelect(row, $index)"></el-input>
  101. </template>
  102. </ele-pro-table>
  103. <div slot="footer" class="footer">
  104. <el-button type="primary" @click="save">保存</el-button>
  105. <el-button @click="cancel">返回</el-button>
  106. </div>
  107. <ProductModal ref="productRefs" @changeProduct='determineChoose' />
  108. </ele-modal>
  109. </template>
  110. <script>
  111. import ProductModal from '@/views/technology/productParam/components/ProductModal.vue'
  112. import factorySelect from '@/components/CommomSelect/factory-select.vue';
  113. import { getCode } from '@/api/codeManagement/index.js';
  114. import { getVersionCode, bomSave, bomUpdate, getById, detailPage } from '@/api/material/BOM';
  115. import { pageList } from '@/api/technology/version/version.js';
  116. export default {
  117. components: { ProductModal, factorySelect },
  118. props: {
  119. statusOpt: Object
  120. },
  121. data() {
  122. var baseCountVa = (rule, value, callback) => {
  123. if (value == '') {
  124. callback(new Error('请输入基本数量'));
  125. } else if (this.form.baseCountUnit == '') {
  126. callback(new Error('请选择基本数量单位'));
  127. } else {
  128. callback();
  129. }
  130. };
  131. return {
  132. visible: false,
  133. title: '',
  134. row: {},
  135. form: {
  136. code: '',
  137. name: '',
  138. type: 0,
  139. factoryId: '',
  140. categoryCode: '',
  141. categoryId: '',
  142. categoryName: '',
  143. version: '',
  144. categoryType: '',
  145. baseCount: '',
  146. baseCountUnit: '',
  147. status: '-1',
  148. },
  149. removeSubBomIdList: [],
  150. categoryList: [
  151. {
  152. value: 1,
  153. label: '产品'
  154. },
  155. {
  156. value: 2,
  157. label: '部件'
  158. },
  159. {
  160. value: 3,
  161. label: '零件'
  162. }
  163. ],
  164. tableData: [],
  165. versionList: [],
  166. columns: [
  167. {
  168. type: 'index',
  169. width: 55,
  170. align: 'center'
  171. },
  172. {
  173. label: '子项编号',
  174. prop: 'subCode',
  175. slot: 'subCode',
  176. action: 'subCode'
  177. },
  178. {
  179. label: '物料名称',
  180. prop: 'categoryName',
  181. slot: 'categoryName',
  182. action: 'categoryName'
  183. },
  184. {
  185. label: '物料编码',
  186. prop: 'categoryCode'
  187. },
  188. {
  189. label: '牌号',
  190. prop: 'brandNum'
  191. },
  192. {
  193. label: '型号',
  194. prop: 'modelType'
  195. },
  196. {
  197. label: '净重',
  198. slot: 'count',
  199. action: 'count'
  200. },
  201. {
  202. label: '重量单位',
  203. slot: 'unit',
  204. action: 'unit'
  205. },
  206. {
  207. action: 'action',
  208. slot: 'action',
  209. label: '操作'
  210. }
  211. ],
  212. rules: {
  213. name: [
  214. { required: true, message: '请输入BOM名称', trigger: 'blur' }
  215. ],
  216. factoryId: [
  217. { required: true, message: '请输入所属工厂', trigger: 'change' }
  218. ],
  219. categoryCode: [
  220. { required: true, message: '请输入产品编码', trigger: 'blur' }
  221. ],
  222. baseCount: [
  223. { validator: baseCountVa, trigger: 'blur' }
  224. ]
  225. },
  226. // 提交状态
  227. loading: false,
  228. // 是否是修改
  229. isUpdate: false,
  230. };
  231. },
  232. methods: {
  233. async open(type, row) {
  234. this.title = type;
  235. this.row = row;
  236. this.getVersionList()
  237. this.visible = true;
  238. if (type == '新建') {
  239. this._getCode();
  240. } else {
  241. this.isUpdate = true
  242. this._getById(row.id);
  243. const res = await detailPage({ pageNum: 1, size: -1, bomId: row.id })
  244. this.tableData = res.list
  245. }
  246. },
  247. add() {
  248. let subCode = '0010';
  249. if (this.tableData.length) {
  250. let max = Math.max(...this.tableData.map((i) => i.subCode)) + 10 + '';
  251. if (max.length < 4) {
  252. max = new Array(4 - max.length).fill('0').join('') + max;
  253. }
  254. subCode = max.substring(0, max.length - 1) + '0';
  255. }
  256. this.tableData.push({
  257. subCode,
  258. categoryId: '',
  259. categoryName: '',
  260. brandNum: '',
  261. count: '',
  262. modelType: '',
  263. unit: ''
  264. });
  265. },
  266. async _getCode() {
  267. const code = await getCode('bom_code');
  268. this.form.code = code;
  269. },
  270. selectProd() {
  271. this.$refs.productRefs.open(this.form, '选择产品', '9')
  272. },
  273. categorySelect(row, idx) {
  274. this.$refs.productRefs.open(row, '选择物料', '1', idx)
  275. },
  276. determineChoose(title, row, idx) {
  277. if (title == '选择产品') {
  278. this.$set(this.form, 'categoryName', row.name)
  279. this.$set(this.form, 'categoryId', row.id)
  280. this.$set(this.form, 'categoryCode', row.code)
  281. this.getVersion()
  282. }
  283. else if (title == '选择物料') {
  284. this.$set(this.tableData[idx], 'categoryName', row.name)
  285. this.$set(this.tableData[idx], 'categoryId', row.id)
  286. this.$set(this.tableData[idx], 'categoryCode', row.code)
  287. this.$set(this.tableData[idx], 'unit', row.measuringUnit)
  288. this.$set(this.tableData[idx], 'brandNum', row.brandNum)
  289. this.$set(this.tableData[idx], 'modelType', row.modelType)
  290. }
  291. },
  292. async getVersion() {
  293. const res = await getVersionCode(this.form.categoryId);
  294. this.form.version = res
  295. },
  296. async getVersionList() {
  297. const res = await pageList({
  298. pageNum: 1,
  299. size: 100
  300. });
  301. this.versionList = res.list
  302. },
  303. save() {
  304. this.$refs.form.validate((valid) => {
  305. if (!valid) {
  306. return false;
  307. }
  308. this.loading = true;
  309. if (!this.isUpdate) {
  310. delete this.form.id;
  311. } else {
  312. this.form.removeSubBomIdList = this.removeSubBomIdList
  313. }
  314. const data = {
  315. ...this.form,
  316. subDetailList: this.tableData
  317. };
  318. const saveOrUpdate = this.isUpdate ? bomUpdate : bomSave;
  319. saveOrUpdate(data)
  320. .then((msg) => {
  321. this.loading = false;
  322. this.$message.success(msg);
  323. this.cancel()
  324. this.$emit('done');
  325. })
  326. .catch((e) => {
  327. this.loading = false;
  328. });
  329. });
  330. },
  331. handleDel(row, index) {
  332. this.tableData.splice(index, 1);
  333. if (row?.id) {
  334. this.removeSubBomIdList.push(row.id)
  335. }
  336. },
  337. cancel() {
  338. this.visible = false
  339. },
  340. async _getById(id) {
  341. const data = await getById(id);
  342. this.form = data;
  343. this.form.status = this.form.status + ''
  344. },
  345. }
  346. };
  347. </script>