IndexEdit.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <template>
  2. <div>
  3. <el-dialog
  4. v-loading="loading"
  5. :show-close="false"
  6. :close-on-click-modal="false"
  7. :visible.sync="isShow"
  8. :title="this.curObj && this.curObj.id ? '编辑用户' : '添加用户'"
  9. :fullscreen="false"
  10. width="470px"
  11. custom-class="xl-dialog"
  12. center
  13. >
  14. <base-form ref="ruleForm" :data="formData" :is-inline="false" label-width="110px">
  15. <div slot="footer">
  16. <el-button class="xl-form-btn t2" @click="close">关 闭</el-button>
  17. <el-button class="xl-form-btn t1" @click="close('confirm')">确定</el-button>
  18. </div>
  19. </base-form>
  20. </el-dialog>
  21. </div>
  22. </template>
  23. <script>
  24. export default {
  25. components: {},
  26. mixins: [...mixins],
  27. props: {
  28. isShow: Boolean,
  29. curObj: Object
  30. },
  31. inject: ['parentData'],
  32. data() {
  33. return {
  34. formData: [],
  35. loading: true,
  36. cObj: {},
  37. isShowMap: false
  38. }
  39. },
  40. watch: {
  41. isShow: function(val) {
  42. if (val) {
  43. this.getDef()
  44. }
  45. },
  46. },
  47. methods: {
  48. getDef() {
  49. const params = { ...this.curObj }
  50. const disabled = false
  51. if (!params.is_backend) params.is_backend = '2'
  52. let remoteOptionsRoles = []
  53. if (params.role_arr && params.role_arr.length > 0) {
  54. params.rolesIds = params.role_arr.map(item => {
  55. remoteOptionsRoles.push({ keyRO: item.name, valRO: Number(item.id) })
  56. return Number(item.id)
  57. })
  58. } else {
  59. params.rolesIds = []
  60. }
  61. if (this.curObj.id) {
  62. this.formData = [
  63. // { label: '超级管理员', key: 'is_admin', type: 'select', class: 'c-2', options: this.$dictData.sys_yesno, },
  64. { label: '手机号', key: 'phone', rules: 1 },
  65. { label: '昵称', key: 'nickname', rules: 1 },
  66. { label: '后台登录', rules: 1, key: 'is_backend', type: 'select', class: 'c-2', options: this.$dictData.sys_yesno, },
  67. { label: '系统角色', key: 'rolesIds', type: 'selectRemote', multiple: true,
  68. remoteParams: { skey: 'name', api: `base.admroleslist`, opKey: 'name', opVal: 'id' },
  69. remoteOptions: remoteOptionsRoles
  70. },
  71. { label: '楼盘角色', key: 'manage_type', type: 'select', class: 'c-2', options: this.$dictData.manage_type, },
  72. { label: '关联楼盘', key: 'estate_id', type: 'selectRemote',
  73. remoteParams: { skey: 'estate_name', api: `house.admestatelist`, opKey: 'estate_name', opVal: 'id' },
  74. remoteOptions: [{ keyRO: params.estate_name, valRO: params.estate_id }]
  75. },
  76. ]
  77. } else {
  78. this.formData = [
  79. // { label: '超级管理员', key: 'is_admin', type: 'select', class: 'c-2', options: this.$dictData.sys_yesno, },
  80. { label: '手机号', key: 'phone', rules: 1 },
  81. { label: '昵称', key: 'nickname', rules: 1 },
  82. { label: '密码', key: 'password', rules: 1 },
  83. { label: '后台登录', rules: 1, key: 'is_backend', type: 'select', class: 'c-2', options: this.$dictData.sys_yesno, },
  84. { label: '系统角色', key: 'rolesIds', type: 'selectRemote', multiple: true,
  85. remoteParams: { skey: 'name', api: `base.admroleslist`, opKey: 'name', opVal: 'id' },
  86. remoteOptions: remoteOptionsRoles
  87. },
  88. { label: '楼盘角色', key: 'manage_type', type: 'select', class: 'c-2', options: this.$dictData.manage_type, },
  89. { label: '关联楼盘', key: 'estate_id', type: 'selectRemote',
  90. remoteParams: { skey: 'estate_name', api: `house.admestatelist`, opKey: 'estate_name', opVal: 'id' },
  91. remoteOptions: [{ keyRO: params.estate_name, valRO: params.estate_id }]
  92. },
  93. ]
  94. }
  95. this.setDefaultValue(params)
  96. },
  97. close(str) {
  98. if (str === 'confirm') {
  99. this.$refs['ruleForm'].$refs['baseForm'].validate((valid) => {
  100. if (valid) {
  101. const oldform = this.$refs.ruleForm.baseForm
  102. let newForm = { ...oldform }
  103. newForm.roles = newForm.rolesIds.join(',')
  104. delete newForm.rolesIds
  105. if (this.curObj.id) {
  106. newForm.id = this.curObj.id
  107. newForm.user_type = this.curObj.user_type || 'sys'
  108. } else {
  109. newForm.user_type = 'sys'
  110. }
  111. this.$emit('close', newForm)
  112. }
  113. })
  114. } else {
  115. this.$emit('close')
  116. this.setDefaultValue()
  117. }
  118. },
  119. }
  120. }
  121. </script>
  122. <style lang="scss" scoped>
  123. </style>