role-switching.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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,index)">
  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. ];
  29. export default {
  30. data() {
  31. return {
  32. permissionList:[],//权限列表
  33. nowPermission:'',//当前权限
  34. oldPermission:'',//初始化选中的权限
  35. }
  36. },
  37. created() {
  38. let permissions=uni.getStorageSync('permissions');
  39. this.nowPermission=uni.getStorageSync('nowPermission');
  40. this.permissionList = permissions.map((item,index)=>{
  41. let match = roleList.find(i => i.permission == item.permission);
  42. if(match) {
  43. return {
  44. value: match.permission,
  45. label: match.name,
  46. todoNum: item.todoNum > 0
  47. ? (match.permission === 3 ? '今日':'') + item.todoNum + match.msg
  48. : '暂无待处理',
  49. isNowRole:this.nowPermission==match.permission?true:false,
  50. isChecked:this.nowPermission==match.permission?true:false,
  51. }
  52. }
  53. });
  54. let obj = this.permissionList.find((item)=>item.isChecked);
  55. this.oldPermission = obj ? obj.value : '';
  56. },
  57. methods: {
  58. toggleSelect(item,index) {
  59. this.permissionList.map((item,index)=>{
  60. item.isChecked=false;
  61. });
  62. this.permissionList[item.value-1].isChecked=true;
  63. },
  64. saveChange(){
  65. let obj = this.permissionList.find((item)=>item.isChecked);
  66. if(obj) {
  67. if(obj.value === this.oldPermission) {
  68. uni.navigateTo({url: '/pages/home/home'});
  69. return;
  70. };
  71. this.$store.dispatch({
  72. type: 'roleSwitching/commActions',
  73. payload: {
  74. key: 'updatePermission',
  75. data: {
  76. permission: obj.value,
  77. }
  78. }
  79. }).then((data)=>{
  80. if(data){
  81. uni.navigateTo({url: '/pages/home/home'});
  82. }
  83. });
  84. }
  85. }
  86. },
  87. }
  88. </script>
  89. <style lang="less">
  90. .role-page {
  91. height: 100%;
  92. .row-box {
  93. .role-list {
  94. height: 107.5rpx;
  95. width: 750rpx;
  96. background: #FFFFFF;
  97. border-bottom: 0.62rpx solid #DADEE6;
  98. position: relative;
  99. .role-name {
  100. font-size: 22.5rpx;
  101. font-family: SourceHanSansCN-Bold, SourceHanSansCN;
  102. font-weight: bold;
  103. color: #292C33;
  104. float: left;
  105. margin-left: 25rpx;
  106. margin-top: 25rpx;
  107. }
  108. .nowrole {
  109. float: right;
  110. font-size: 22.5rpx;
  111. font-family: SourceHanSansCN-Normal, SourceHanSansCN;
  112. font-weight: 400;
  113. color: #7A8599;
  114. margin-top: 42.5rpx;
  115. margin-right: 25rpx;
  116. }
  117. .radio-item {
  118. float: right;
  119. margin-right: 25rpx;
  120. margin-top: 41.25rpx;
  121. .icon {
  122. width: 25rpx;
  123. height: 25rpx;
  124. }
  125. }
  126. .task-msg {
  127. font-size: 20rpx;
  128. font-family: SourceHanSansCN-Normal, SourceHanSansCN;
  129. font-weight: 400;
  130. color: #7A8599;
  131. position: absolute;
  132. top: 62.5rpx;
  133. left: 25rpx;
  134. }
  135. }
  136. }
  137. .btn-confirm {
  138. width: 750rpx;
  139. height: 75rpx;
  140. background: #3377FF;
  141. position: absolute;
  142. bottom: 0rpx;
  143. .btn-text {
  144. font-size: 22.5rpx;
  145. font-family: SourceHanSansCN-Normal, SourceHanSansCN;
  146. font-weight: 400;
  147. color: #FFFFFF;
  148. line-height: 75rpx;
  149. margin-left: 352.5rpx;
  150. }
  151. }
  152. }
  153. </style>