role-switching.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. <template>
  2. <view class="role-page">
  3. <view class="row-box">
  4. <view class="role-list" v-for="(item,index) in permissionList" :key="index">
  5. <text class="role-name">{{item.label}}</text>
  6. <view class="radio-item" @click="toggleSelect(item)">
  7. <image class="icon" :src="`/static/${item.isChecked ? 'check-radio' : 'check-no'}.png`"></image>
  8. </view>
  9. <text class="nowrole" v-show="item.isNowRole" >当前角色</text>
  10. <text class="task-msg">{{item.todoNum}}</text>
  11. </view>
  12. </view>
  13. <view class="btn-confirm" @click="saveChange">
  14. <text class="btn-text">确定</text>
  15. </view>
  16. </view>
  17. </template>
  18. /**
  19. * 角色切换
  20. */
  21. <script>
  22. const roleList = [
  23. {permission: 1, name: '管理员', msg: '个改善任务待处理'},
  24. {permission: 2, name: '查核组长', msg: '个情境待分配'},
  25. {permission: 3, name: '查核组员', msg: '个单位待查核'},
  26. {permission: 4, name: '单位负责人', msg: '个改善任务待处理'},
  27. {permission: 5, name: '改善者', msg: '个改善任务待处理'},
  28. {permission: 6, name: '职能科室负责人', msg: '个改善任务待处理'},
  29. {permission: 7, name: '职能科室普通人员', msg: '个改善任务待处理'},
  30. {permission: 8, name: '自查人', msg: '个改善任务待处理'},
  31. ];
  32. export default {
  33. data() {
  34. return {
  35. permissionList:[],//权限列表
  36. nowPermission:'',//当前权限
  37. oldPermission:'',//初始化选中的权限
  38. }
  39. },
  40. created() {
  41. let permissions=uni.getStorageSync('permissions');
  42. this.nowPermission=uni.getStorageSync('nowPermission');
  43. this.permissionList = permissions.map((item,index)=>{
  44. let match = roleList.find(i => i.permission == item.permission);
  45. if(match) {
  46. return {
  47. value: match.permission,
  48. label: match.name,
  49. todoNum: item.todoNum > 0
  50. ? (match.permission === 3 ? '今日':'') + item.todoNum + match.msg
  51. : '暂无待处理',
  52. isNowRole:this.nowPermission==match.permission?true:false,
  53. isChecked:this.nowPermission==match.permission?true:false,
  54. }
  55. }
  56. });
  57. let obj = this.permissionList.find((item)=>item.isChecked);
  58. this.oldPermission = obj ? obj.value : '';
  59. },
  60. methods: {
  61. toggleSelect(item) {
  62. this.permissionList.map((ntem,n)=>{
  63. ntem.isChecked = ntem.value === item.value ? true : false;
  64. });
  65. // this.permissionList[item.value-1].isChecked=true;
  66. },
  67. saveChange(){
  68. let obj = this.permissionList.find((item)=>item.isChecked);
  69. if(obj) {
  70. if(obj.value === this.oldPermission) {
  71. uni.navigateTo({url: '/pages/home/home'});
  72. return;
  73. };
  74. this.$store.dispatch({
  75. type: 'roleSwitching/commActions',
  76. payload: {
  77. key: 'updatePermission',
  78. data: {
  79. permission: obj.value,
  80. }
  81. }
  82. }).then((data)=>{
  83. if(data){
  84. uni.navigateTo({url: '/pages/home/home'});
  85. }
  86. });
  87. }
  88. }
  89. },
  90. }
  91. </script>
  92. <style lang="less">
  93. .role-page {
  94. height: 100%;
  95. .row-box {
  96. .role-list {
  97. height: 107.5rpx;
  98. width: 750rpx;
  99. background: #FFFFFF;
  100. border-bottom: 0.62rpx solid #DADEE6;
  101. position: relative;
  102. .role-name {
  103. font-size: 22.5rpx;
  104. font-family: SourceHanSansCN-Bold, SourceHanSansCN;
  105. font-weight: bold;
  106. color: #292C33;
  107. float: left;
  108. margin-left: 25rpx;
  109. margin-top: 25rpx;
  110. }
  111. .nowrole {
  112. float: right;
  113. font-size: 22.5rpx;
  114. font-family: SourceHanSansCN-Normal, SourceHanSansCN;
  115. font-weight: 400;
  116. color: #7A8599;
  117. margin-top: 42.5rpx;
  118. margin-right: 25rpx;
  119. }
  120. .radio-item {
  121. float: right;
  122. margin-right: 25rpx;
  123. margin-top: 41.25rpx;
  124. .icon {
  125. width: 25rpx;
  126. height: 25rpx;
  127. }
  128. }
  129. .task-msg {
  130. font-size: 20rpx;
  131. font-family: SourceHanSansCN-Normal, SourceHanSansCN;
  132. font-weight: 400;
  133. color: #7A8599;
  134. position: absolute;
  135. top: 62.5rpx;
  136. left: 25rpx;
  137. }
  138. }
  139. }
  140. .btn-confirm {
  141. width: 750rpx;
  142. height: 75rpx;
  143. background: #3377FF;
  144. position: absolute;
  145. bottom: 0rpx;
  146. .btn-text {
  147. font-size: 22.5rpx;
  148. font-family: SourceHanSansCN-Normal, SourceHanSansCN;
  149. font-weight: 400;
  150. color: #FFFFFF;
  151. line-height: 75rpx;
  152. margin-left: 352.5rpx;
  153. }
  154. }
  155. }
  156. </style>