add.vue 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <template>
  2. <div class="subPage">
  3. <form class="mainForm">
  4. <ul>
  5. <li class="flex-h">
  6. <span>角色名称:<em>*</em></span>
  7. <div class="flex-item">
  8. <div style="width:50%">
  9. <el-input
  10. placeholder="请输入角色名称"
  11. v-model="detail.RoleName"
  12. maxlength="10"
  13. clearable>
  14. </el-input>
  15. </div>
  16. </div>
  17. </li>
  18. <li class="flex-h">
  19. <span>备注:</span>
  20. <div class="flex-item">
  21. <div>
  22. <el-input
  23. placeholder="请输入备注"
  24. type="textarea"
  25. :autosize="{ minRows: 3, maxRows: 5}"
  26. v-model="detail.Remark"
  27. clearable>
  28. </el-input>
  29. </div>
  30. </div>
  31. </li>
  32. <li style="text-align:center">
  33. <el-button type="primary" size="mini" @click='submit'>保存</el-button>
  34. <el-button type="danger" size="mini" @click="cancel">取消</el-button>
  35. </li>
  36. </ul>
  37. </form>
  38. </div>
  39. </template>
  40. <script>
  41. import { createNamespacedHelpers, mapState } from 'vuex'
  42. const { mapState: mapRoleState, mapActions: mapRoleActions } = createNamespacedHelpers('role')
  43. export default {
  44. name: '',
  45. data () {
  46. return {}
  47. },
  48. components: {},
  49. computed: {
  50. ...mapRoleState({
  51. detail: x => x.roleInfo,
  52. }),
  53. ...mapState({
  54. caseid: x => x.app.cases.default,
  55. orgid: x => x.app.user.OrgId,
  56. })
  57. },
  58. methods: {
  59. ...mapRoleActions([
  60. 'GetRoleByID',
  61. 'AddRole',
  62. 'UpdateRole',
  63. 'SetRoleNull',
  64. ]),
  65. submit () {
  66. if (!this.detail.RoleName || this.detail.RoleName === '') {
  67. this.$message({
  68. type: 'error',
  69. message: '角色名称不允许为空!'
  70. })
  71. return false
  72. }
  73. if ((this.detail.RoleId || '') === '') {
  74. this.detail.CaseId = this.caseid
  75. this.detail.OrgId = this.orgid
  76. this.AddRole({...this.detail, callback: this.afterSave})
  77. } else {
  78. this.UpdateRole({...this.detail, callback: this.afterSave})
  79. }
  80. },
  81. afterSave () {
  82. this.$message({
  83. type: 'success',
  84. message: '操作成功'
  85. })
  86. this.$router.push({ name: 'roleManager' })
  87. },
  88. cancel () {
  89. this.$router.go(-1)
  90. }
  91. },
  92. beforeMount () {
  93. const { id } = this.$route.query
  94. if (id && id !== '') {
  95. this.GetRoleByID({ roleid: id })
  96. } else {
  97. this.SetRoleNull()
  98. }
  99. }
  100. }
  101. </script>
  102. <!-- Add "scoped" attribute to limit CSS to this component only -->
  103. <style lang="scss" scoped>
  104. </style>