org-add-or-update.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <template>
  2. <el-dialog
  3. :title="!dataForm.id ? '新增' : '修改'"
  4. :close-on-click-modal="false"
  5. :visible.sync="visible">
  6. <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
  7. <el-form-item label="机构名称" prop="name">
  8. <el-input v-model="dataForm.name" placeholder="机构名称"></el-input>
  9. </el-form-item>
  10. <el-form-item label="上级机构" prop="parentName">
  11. <el-popover
  12. ref="menuListPopover"
  13. placement="bottom-start"
  14. trigger="click">
  15. <el-tree
  16. :data="orgList"
  17. :props="menuListTreeProps"
  18. node-key="menuId"
  19. ref="menuListTree"
  20. @current-change="menuListTreeCurrentChangeHandle"
  21. :default-expand-all="true"
  22. :highlight-current="true"
  23. :expand-on-click-node="false">
  24. </el-tree>
  25. </el-popover>
  26. <el-input v-model="dataForm.parentName" v-popover:menuListPopover :readonly="true" placeholder="点击选择上级机构" class="menu-list__input"></el-input>
  27. </el-form-item>
  28. <!-- <el-form-item label="状态" size="mini" prop="orgType">
  29. <el-radio-group v-model="dataForm.orgType">
  30. <el-radio :label="0">非运输公司</el-radio>
  31. <el-radio :label="1">运输公司</el-radio>
  32. </el-radio-group>
  33. </el-form-item> -->
  34. <el-form-item label="排序" prop="orderNum">
  35. <el-input-number v-model="dataForm.orderNum" controls-position="right" :min="0" label="排序"></el-input-number>
  36. </el-form-item>
  37. </el-form>
  38. <span slot="footer" class="dialog-footer">
  39. <el-button @click="visible = false">取消</el-button>
  40. <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
  41. </span>
  42. </el-dialog>
  43. </template>
  44. <script>
  45. export default {
  46. data () {
  47. return {
  48. visible: false,
  49. orgList: [],
  50. dataForm: {
  51. id: 0,
  52. name: '',
  53. parentId: '',
  54. parentName: '',
  55. orderNum: '',
  56. orgType: ''
  57. },
  58. dataRule: {
  59. name: [
  60. { required: true, message: '机构名称不能为空', trigger: 'blur' }
  61. ],
  62. parentName: [
  63. { required: true, message: '上级机构不能为空', trigger: 'change' }
  64. ]
  65. },
  66. menuListTreeProps: {
  67. label: 'name',
  68. children: 'children'
  69. }
  70. }
  71. },
  72. methods: {
  73. async init (id) {
  74. this.dataForm.id = id || 0
  75. this.$http({
  76. url: this.$http.adornUrl(`/user-service/org/queryTree`),
  77. method: 'get',
  78. params: this.$http.adornParams()
  79. }).then(({data}) => {
  80. this.orgList = data && data.code === '200' ? data.data : []
  81. }).then(() => {
  82. this.visible = true
  83. this.$nextTick(() => {
  84. this.$refs['dataForm'].resetFields()
  85. })
  86. }).then(() => {
  87. if (this.dataForm.id) {
  88. this.$http({
  89. url: this.$http.adornUrl(`/user-service/org/info/${this.dataForm.id}`),
  90. method: 'get',
  91. params: this.$http.adornParams()
  92. }).then(({data}) => {
  93. if (data && data.code === 0) {
  94. this.dataForm.userName = data.user.username
  95. this.dataForm.salt = data.user.salt
  96. this.dataForm.email = data.user.email
  97. this.dataForm.mobile = data.user.mobile
  98. this.dataForm.roleIdList = data.user.roleIdList
  99. this.dataForm.status = data.user.status
  100. }
  101. })
  102. }
  103. })
  104. },
  105. menuListTreeCurrentChangeHandle (data, node) {
  106. this.dataForm.parentId = data.orgId
  107. this.dataForm.parentName = data.name
  108. },
  109. // 表单提交
  110. dataFormSubmit () {
  111. this.$refs['dataForm'].validate((valid) => {
  112. if (valid) {
  113. const params = { ...this.dataForm }
  114. if (this.dataForm.id) params.orgId = this.dataForm.id
  115. this.$http({
  116. url: this.$http.adornUrl(`/user-service/org/save`),
  117. method: this.dataForm.id ? 'put' : 'post',
  118. data: this.$http.adornData(params)
  119. }).then(({data}) => {
  120. if (data && data.code === '200') {
  121. this.$message({
  122. message: '操作成功',
  123. type: 'success',
  124. duration: 1500,
  125. onClose: () => {
  126. this.visible = false
  127. this.$emit('refreshDataList')
  128. }
  129. })
  130. } else {
  131. this.$message.error(data.msg)
  132. }
  133. })
  134. }
  135. })
  136. }
  137. }
  138. }
  139. </script>