baseInfoSave.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. <template>
  2. <el-dialog
  3. :title="title"
  4. v-if="visible"
  5. :visible.sync="visible"
  6. :before-close="handleClose"
  7. :close-on-click-modal="false"
  8. :close-on-press-escape="false"
  9. append-to-body
  10. width="700px"
  11. >
  12. <el-form
  13. ref="form"
  14. label-width="100px"
  15. :rules="rules"
  16. :inline="true"
  17. :model="formData"
  18. >
  19. <el-form-item label="BOM编码:" prop="code">
  20. <el-input
  21. size="mini"
  22. placeholder="BOM编码"
  23. v-model="formData.code"
  24. ></el-input>
  25. </el-form-item>
  26. <el-form-item label="BOM名称:" prop="name">
  27. <el-input
  28. size="mini"
  29. placeholder="BOM名称"
  30. v-model="formData.name"
  31. ></el-input>
  32. </el-form-item>
  33. <el-form-item label="版本号:" prop="versions">
  34. <el-input
  35. size="mini"
  36. disabled
  37. placeholder="版本号"
  38. v-model="formData.versions"
  39. ></el-input>
  40. </el-form-item>
  41. <el-form-item label="状态:" prop="status">
  42. <el-select
  43. size="mini"
  44. style="width: 100%"
  45. disabled
  46. v-model="formData.status"
  47. placeholder="请选择"
  48. >
  49. <el-option
  50. v-for="item in statusOptions"
  51. :label="item.label"
  52. :value="item.value"
  53. :key="item.value"
  54. >
  55. </el-option>
  56. </el-select>
  57. </el-form-item>
  58. </el-form>
  59. <div slot="footer" class="dialog-footer">
  60. <el-button size="small" @click="handleClose">关 闭</el-button>
  61. <el-button size="small" type="primary" @click="handleSave"
  62. >确 认</el-button
  63. >
  64. </div>
  65. </el-dialog>
  66. </template>
  67. <script>
  68. import {
  69. saveBomTreeList,
  70. bomCategoryUpdate,
  71. hasNewVersion
  72. } from '@/api/material/BOM.js';
  73. import { getCode } from '@/api/codeManagement/index.js';
  74. export default {
  75. data() {
  76. return {
  77. visible: true,
  78. statusOptions: [
  79. {
  80. label: '已停用',
  81. value: '2'
  82. },
  83. {
  84. label: '已发布',
  85. value: '1'
  86. },
  87. {
  88. label: '草稿',
  89. value: '0'
  90. }
  91. ],
  92. formData: {
  93. code: '',
  94. name: '',
  95. versions: '',
  96. status: '0'
  97. },
  98. title: '新建BOM',
  99. rules: {
  100. name: [
  101. {
  102. required: true,
  103. message: '请输入BOM名称',
  104. trigger: 'blur'
  105. }
  106. ],
  107. code: [
  108. {
  109. required: true,
  110. message: '请输入BOM编码',
  111. trigger: 'blur'
  112. }
  113. ]
  114. }
  115. };
  116. },
  117. props: {
  118. categoryObj: {
  119. type: Object,
  120. default() {
  121. return {};
  122. }
  123. },
  124. categoryId: {
  125. type: String,
  126. default: ''
  127. },
  128. categoryName: {
  129. type: String,
  130. default: ''
  131. },
  132. isEdit: {
  133. type: Boolean,
  134. default: false
  135. }
  136. },
  137. async created() {
  138. if (this.isEdit) {
  139. this.title = '编辑BOM';
  140. this.formData = {
  141. code: this.categoryObj.code,
  142. name: this.categoryObj.name,
  143. versions: 'V' + this.categoryObj.versions + '.0',
  144. status: this.categoryObj.status,
  145. id: this.categoryObj.id
  146. };
  147. } else {
  148. this.title = '新建BOM';
  149. this.formData = {
  150. code: await getCode('bom_add_code'),
  151. name: this.categoryName || '',
  152. versions: '',
  153. status: '0'
  154. };
  155. }
  156. },
  157. methods: {
  158. handleClose() {
  159. this.$emit('close');
  160. },
  161. handleSave() {
  162. this.$refs.form.validate(async (valid) => {
  163. if (valid) {
  164. if (!this.isEdit) {
  165. let isHas = await this.hasVersionFn();
  166. if (!isHas) return;
  167. }
  168. let param = {
  169. ...this.formData,
  170. categoryId: this.categoryId,
  171. bomType: this.categoryObj.bomType
  172. };
  173. let URL = this.isEdit ? bomCategoryUpdate : saveBomTreeList;
  174. URL(param).then((res) => {
  175. this.$message.success(this.isEdit ? '修改成功' : '保存成功');
  176. this.$emit('close', this.formData);
  177. // this.handleClose();
  178. });
  179. } else {
  180. return false;
  181. }
  182. });
  183. },
  184. hasVersionFn() {
  185. return new Promise((resolve) => {
  186. let param = {
  187. categoryId: this.categoryId,
  188. bomType: this.categoryObj.bomType
  189. };
  190. hasNewVersion(param).then((res) => {
  191. if (res.data == 1) {
  192. this.$confirm('已经草稿版本存在,是否覆盖?', '提示', {
  193. confirmButtonText: '覆盖',
  194. cancelButtonText: '取消',
  195. type: 'warning'
  196. })
  197. .then(() => {
  198. resolve(true);
  199. })
  200. .catch(() => {
  201. resolve(false);
  202. });
  203. } else {
  204. resolve(true);
  205. }
  206. });
  207. });
  208. }
  209. }
  210. };
  211. </script>
  212. <style lang="scss" scoped></style>