AddRole.vue 5.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. <template>
  2. <el-dialog
  3. title="新增用户"
  4. width="660px"
  5. :visible.sync="visible"
  6. :before-close="_close"
  7. >
  8. <el-form :model="form" :rules="rules" ref="form" label-width="90px">
  9. <el-form-item label="角色名称 : " prop="name">
  10. <el-input v-model="form.name" placeholder="" maxlength="30"></el-input>
  11. </el-form-item>
  12. <el-form-item label="角色描述 : " >
  13. <el-input type="textarea" v-model="form.intro" placeholder="" resize="none" rows="4"></el-input>
  14. </el-form-item>
  15. </el-form>
  16. <div slot="footer" class="dialog-footer">
  17. <el-button @click="hide">取 消</el-button>
  18. <el-button type="primary" @click="submitAction()">保 存</el-button>
  19. </div>
  20. </el-dialog>
  21. </template>
  22. <script>
  23. import { addRole, modifyRole } from '@/api/role/role'
  24. export default {
  25. name: 'AddRole',
  26. data() {
  27. return {
  28. form: {
  29. id: 0,
  30. name: '',
  31. intro: ''
  32. },
  33. visible: false,
  34. rules: {
  35. name: [
  36. { required: true, message: '请输入角色名称', trigger: 'blur' },
  37. { max: 10, message: '10个字以内', trigger: 'blur' }
  38. ],
  39. // intro: [{ required: true, message: '请输入角色说明', trigger: 'blur' }]
  40. },
  41. //
  42. checked: '1',
  43. checkAll: false,
  44. checkedCities: [],
  45. cities: ['上海', '北京', '广州', '深圳'],
  46. isIndeterminate: true,
  47. ruleForm: {
  48. name: '',
  49. phone: '',
  50. position: ''
  51. },
  52. newrules: {
  53. name: [
  54. { required: true, message: '请输入角色名称', trigger: 'blur' },
  55. { max: 10, message: '10个字以内', trigger: 'blur' }
  56. ],
  57. phone: [{ required: true, message: '请输入手机号', trigger: 'blur' }]
  58. }
  59. }
  60. },
  61. methods: {
  62. _close: function(done) {
  63. this.clear()
  64. done()
  65. },
  66. clear: function() {
  67. this.form.id = 0
  68. this.form.name = ''
  69. this.form.intro = ''
  70. },
  71. show() {
  72. this.clear()
  73. this.visible = true
  74. },
  75. hide() {
  76. this.clear()
  77. this.visible = false
  78. },
  79. modify(id, name, intro) {
  80. this.form.id = id
  81. this.form.name = name
  82. this.form.intro = intro
  83. this.visible = true
  84. },
  85. submitAction() {
  86. this.$refs.form.validate(valid => {
  87. if (valid) {
  88. // 验证通过
  89. if (this.form.id === 0) {
  90. // 新增 role
  91. addRole(this.form.name, this.form.intro)
  92. .then(rs => {
  93. var resp = rs.data
  94. if (resp.state === 1) {
  95. var new_id = resp.data.id
  96. var new_name = resp.data.name
  97. var new_intro = resp.data.intro
  98. var new_status = resp.data.status
  99. var staff_number = 0
  100. this.$emit(
  101. 'did-add-role',
  102. new_id,
  103. new_name,
  104. new_intro,
  105. new_status,
  106. staff_number
  107. )
  108. this.hide()
  109. } else {
  110. this.$message.error(resp.msg)
  111. }
  112. })
  113. .catch(err => {
  114. this.$message.error(err)
  115. })
  116. } else {
  117. // 修改 role
  118. modifyRole(this.form.id, this.form.name, this.form.intro)
  119. .then(rs => {
  120. var resp = rs.data
  121. if (resp.state === 1) {
  122. this.$emit(
  123. 'did-edit-role',
  124. this.form.id,
  125. this.form.name,
  126. this.form.intro
  127. )
  128. this.hide()
  129. } else {
  130. this.$message.error(resp.msg)
  131. }
  132. })
  133. .catch(err => {
  134. this.$message.error(err)
  135. })
  136. }
  137. } else {
  138. // 验证失败
  139. return false
  140. }
  141. })
  142. },
  143. handleCheckAllChange(val) {
  144. this.checkedCities = val ? this.cities : []
  145. this.isIndeterminate = false
  146. },
  147. handleCheckedCitiesChange(value) {
  148. let checkedCount = value.length
  149. this.checkAll = checkedCount === this.cities.length
  150. this.isIndeterminate =
  151. checkedCount > 0 && checkedCount < this.cities.length
  152. }
  153. }
  154. }
  155. </script>
  156. <style lang="scss" scoped>
  157. .roleContent {
  158. margin-top: 20px;
  159. display: flex;
  160. justify-content: space-between;
  161. .roleContentLeft {
  162. .chooseBox {
  163. width: 280px;
  164. height: 320px;
  165. overflow-y: auto;
  166. border: 1px solid rgba(235, 238, 240, 1);
  167. margin-top: 26px;
  168. padding: 20px;
  169. .checkone {
  170. display: flex;
  171. align-items: center;
  172. height: 50px;
  173. }
  174. .el-checkbox__label {
  175. display: flex;
  176. align-items: center;
  177. img {
  178. width: 30px;
  179. height: 30px;
  180. margin-right: 10px;
  181. }
  182. }
  183. }
  184. }
  185. .roleContentRight {
  186. .chooseBox {
  187. width: 280px;
  188. height: 320px;
  189. overflow-y: auto;
  190. border: 1px solid rgba(235, 238, 240, 1);
  191. margin-top: 26px;
  192. padding: 20px;
  193. .hasChoosedOne {
  194. display: flex;
  195. align-items: center;
  196. height: 50px;
  197. img {
  198. width: 30px;
  199. height: 30px;
  200. margin-right: 10px;
  201. }
  202. }
  203. }
  204. }
  205. }
  206. .newStaff {
  207. margin-top: 26px;
  208. .newItem {
  209. display: flex;
  210. align-items: center;
  211. }
  212. }
  213. </style>
  214. <style lang="scss">
  215. .roleContent {
  216. .roleContentLeft {
  217. .chooseBox {
  218. .el-checkbox {
  219. display: flex;
  220. align-items: center;
  221. }
  222. .el-checkbox__label {
  223. display: flex;
  224. align-items: center;
  225. }
  226. }
  227. }
  228. }
  229. </style>