roleUser.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <template>
  2. <view class=" uni-container ">
  3. <view class="u-demo-block">
  4. <view class="u-demo-block__content">
  5. <!-- 注意,如果需要兼容微信小程序,最好通过setRules方法设置rules规则 -->
  6. <u--form :model="user" ref="form1" label-width='80'>
  7. <u-form-item label="用户账号" prop="username">
  8. <u--input v-model="user.username" :disabled="true"></u--input>
  9. </u-form-item>
  10. <u-form-item label="用户姓名" prop="nickname">
  11. <u--input v-model="user.nickname" :disabled="true"></u--input>
  12. </u-form-item>
  13. <!-- <u-form-item label="角色" prop="approleIds"
  14. @click="showRole = true; hideKeyboard()">
  15. <u--input v-model="user.approleIds" disabled disabledColor="#ffffff" placeholder="请选择性别"
  16. ></u--input>
  17. <u-icon slot="right" name="arrow-right"></u-icon>
  18. </u-form-item> -->
  19. <u-form-item label="角色" prop="approleIds">
  20. <u-checkbox-group v-model="user.approleIds" placement="column" @change="checkboxChange">
  21. <u-checkbox activeColor="#4CB2B6" :customStyle="{marginBottom: '8px'}" v-for="(item, index) in roleAppOptions"
  22. :key="index" :label="item.roleName" :name="item.id">
  23. </u-checkbox>
  24. </u-checkbox-group>
  25. </u-form-item>
  26. </u--form>
  27. <u-button type="primary" text="提交" customStyle="height: 72rpx;width: 340rpx;margin-top: 100rpx;display: flex;align-items: center;justify-content: center;border-radius: 60rpx;background: #4CB2B6;" @click="submit"></u-button>
  28. <u-action-sheet :show="showRole " :roleAppOptions="roleAppOptions" title="请选择性别" description="如果选择保密会报错"
  29. @close="showRole = false" @select="roleSelect">
  30. </u-action-sheet>
  31. </view>
  32. </view>
  33. </view>
  34. </template>
  35. <script>
  36. import {
  37. listAppUserRoles, // 获得移动端用户分页
  38. assignAppUserRole, // 创建移动端用户角色
  39. getAppRolesPage, // 获得移动端角色分页
  40. } from '@/api/personnel_permissions';
  41. import {
  42. DICT_TYPE,
  43. getDictDatas
  44. } from "@/utils/dict";
  45. let that = null;
  46. export default {
  47. data() {
  48. return {
  49. user: {
  50. id: undefined,
  51. deptId: undefined,
  52. username: undefined,
  53. nickname: undefined,
  54. },
  55. showRole: false,
  56. rules: {
  57. 'username': {
  58. // type: 'string',
  59. required: true,
  60. message: '用户名称不能为空',
  61. trigger: ['blur']
  62. },
  63. // 'nickname': {
  64. // // type: 'string',
  65. // required: true,
  66. // message: '用户昵称不能为空',
  67. // trigger: ['blur']
  68. // },
  69. },
  70. roleAppOptions: []
  71. }
  72. },
  73. onLoad(option) {
  74. that = this
  75. let str = decodeURIComponent(option.val)
  76. if (str != "undefined") {
  77. that.user = JSON.parse(str);
  78. this.getUser(that.user.id);
  79. }
  80. },
  81. onReady() {
  82. // 如果需要兼容微信小程序,并且校验规则中含有方法等,只能通过setRules方法设置规则
  83. this.$refs.form1.setRules(this.rules)
  84. },
  85. onShow() {},
  86. methods: {
  87. sexTrans(val) {
  88. let eduStr = ''
  89. this.roleAppOptions.map(i => {
  90. if (i.value == val) {
  91. eduStr = i.name
  92. }
  93. })
  94. return eduStr
  95. },
  96. async getUser(id) {
  97. // 获得角色列表
  98. getAppRolesPage({
  99. pageNo: 1,
  100. pageSize: 10,
  101. }).then(response => {
  102. // 处理 roleAppOptions 参数
  103. this.roleAppOptions = [];
  104. this.roleAppOptions.push(...response.data.list);
  105. });
  106. // 获得用户拥有的角色集合
  107. await listAppUserRoles({
  108. id: id
  109. }).then(response => {
  110. // 设置选中
  111. this.user.approleIds = []
  112. var approleIds = response.data ? response.data : [];
  113. approleIds.map(i => {
  114. this.user.approleIds.push(i.id)
  115. })
  116. this.$forceUpdate()
  117. })
  118. },
  119. checkboxChange(e) {
  120. this.user.approleIds = e
  121. },
  122. roleSelect(e) {
  123. this.user.approleIds = e.name
  124. this.user.sex = e.id
  125. this.$refs.form1.validateField('userInfo.sex')
  126. },
  127. submit() {
  128. // 如果有错误,会在catch中返回报错信息数组,校验通过则在then中返回true
  129. this.$refs.form1.validate().then(res => {
  130. // uni.$u.toast('校验通过')
  131. if (this.user.id !== undefined) {
  132. assignAppUserRole({
  133. userId: this.user.id,
  134. roleIds: this.user.approleIds,
  135. }).then(response => {
  136. this.$tab.navigateBack('/pagesA/fire/personnel_permissions/index')
  137. });
  138. }
  139. }).catch(errors => {
  140. console.log(errors);
  141. // uni.$u.toast('校验失败')/
  142. })
  143. },
  144. hideKeyboard() {
  145. uni.hideKeyboard()
  146. }
  147. }
  148. }
  149. </script>
  150. <style lang="scss" scoped>
  151. .uni-container {
  152. height: 100%;
  153. padding: 20px;
  154. background: #f5f7f9;
  155. }
  156. page {
  157. height: 100%;
  158. background-color: #f5f7f9;
  159. position: relative;
  160. }
  161. </style>