CategroyEditForm.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <template>
  2. <el-dialog
  3. width="500px"
  4. :title="title"
  5. class="bs-dialog-wrap dialogClass bs-el-dialog"
  6. :visible.sync="dialogFormVisible"
  7. :append-to-body="true"
  8. :before-close="handleClose"
  9. >
  10. <div style="margin: 20px;">
  11. <el-form
  12. ref="ruleForm"
  13. :model="dataForm"
  14. :rules="rules"
  15. label-position="left"
  16. label-width="90px"
  17. class="bs-el-form"
  18. >
  19. <el-form-item
  20. label="分组名称"
  21. prop="name"
  22. >
  23. <el-input
  24. v-model.trim="dataForm.name"
  25. class="bs-el-input"
  26. clearable
  27. />
  28. </el-form-item>
  29. </el-form>
  30. </div>
  31. <span
  32. slot="footer"
  33. class="dialog-footer"
  34. >
  35. <el-button
  36. class="bs-el-button-default"
  37. @click="cancel"
  38. >
  39. 取消
  40. </el-button>
  41. <el-button
  42. type="primary"
  43. @click="submitForm('ruleForm')"
  44. >
  45. 确定
  46. </el-button>
  47. </span>
  48. </el-dialog>
  49. </template>
  50. <script>
  51. import { categoryAdd, categoryUpdate } from 'data-room-ui/js/utils/datasetConfigService'
  52. export default {
  53. name: 'CategroyEditForm',
  54. props: {
  55. appCode: {
  56. type: String,
  57. default: ''
  58. }
  59. },
  60. data () {
  61. return {
  62. type: 'dataset',
  63. dataForm: {
  64. id: '',
  65. name: '',
  66. parentId: ''
  67. },
  68. title: '',
  69. dialogFormVisible: false,
  70. radio: 0,
  71. nodeFlag: false,
  72. rules: {
  73. name: [
  74. { required: true, message: '分组名称不能为空', trigger: 'blur' }
  75. ]
  76. },
  77. nodeData: {}
  78. }
  79. },
  80. watch: {
  81. dialogFormVisible (val) {
  82. if (!val) {
  83. this.dataForm = {
  84. id: '',
  85. name: '',
  86. parentId: ''
  87. }
  88. }
  89. }
  90. },
  91. methods: {
  92. init (row, flag) {
  93. this.nodeFlag = flag
  94. this.nodeData = row
  95. if (!flag) {
  96. this.dataForm.name = row.name
  97. this.dataForm.id = row.id
  98. }
  99. },
  100. cancel () {
  101. this.dialogFormVisible = false
  102. this.$nextTick(() => {
  103. this.$parent.addOrUpdateTreeVisible = false
  104. })
  105. },
  106. handleClose () {
  107. this.dialogFormVisible = false
  108. this.$parent.addOrUpdateTreeVisible = false
  109. },
  110. submitForm (formName) {
  111. this.$refs[formName].validate((valid) => {
  112. if (valid) {
  113. let id = ''
  114. let parentId = ''
  115. if (this.nodeFlag) {
  116. // 新增节点
  117. if (this.radio === 0) {
  118. // 新增同级
  119. parentId = this.nodeData.parentId
  120. } else {
  121. // 新增子级
  122. parentId = this.nodeData.id
  123. }
  124. } else {
  125. // 修改节点
  126. id = this.dataForm.id
  127. parentId = this.nodeData.parentId
  128. }
  129. const params = {
  130. id: id,
  131. name: this.dataForm.name,
  132. parentId: parentId,
  133. type: this.type,
  134. moduleCode: this.appCode
  135. }
  136. if (id) {
  137. categoryUpdate(params).then((r) => {
  138. params.id = r
  139. this.$message.success('保存成功')
  140. this.cancel()
  141. try {
  142. this.$emit('addOrUpdateNode', params, this.nodeFlag)
  143. } catch (error) {
  144. this.$parent.initLazyDatasetTypeTree()
  145. }
  146. })
  147. } else {
  148. categoryAdd(params).then((r) => {
  149. params.id = r
  150. this.$message.success('保存成功')
  151. this.cancel()
  152. try {
  153. this.$emit('addOrUpdateNode', params, this.nodeFlag)
  154. } catch (error) {
  155. this.$parent.initLazyDatasetTypeTree()
  156. }
  157. })
  158. }
  159. } else {
  160. return false
  161. }
  162. })
  163. }
  164. }
  165. }
  166. </script>