authorizeForm.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. <template>
  2. <view class="container">
  3. <view class="authorize-head">
  4. <cover-image class="authorize-image" :src="userInfo.merchantImg"></cover-image>
  5. <view class="authorize-info">
  6. <view class="authorize-name">{{userInfo.merchantNickname}}</view>
  7. <view class="authorize-phone">{{userInfo.merchantPhone}}</view>
  8. </view>
  9. </view>
  10. <view class="authorize-box">
  11. <u-checkbox-group wrap>
  12. <u-checkbox v-model="item.checked" v-for="(item, index) in checkList" :key="index" :name="item.roleId" shape="circle"
  13. active-color="#52A63A">{{item.roleName}}</u-checkbox>
  14. </u-checkbox-group>
  15. </view>
  16. <view class="form-handle">
  17. <u-button type="success" shape="circle" :ripple="true" @click="setAuthorize" class="handle-custom">确认授权</u-button>
  18. <u-button type="error" shape="circle" :ripple="true" @click="modalShow2 = true" class="handle-custom2">删除该授权用户</u-button>
  19. </view>
  20. <u-modal v-model="modalShow1" content="是否确认授予该授权用户对应权限" @confirm="setAuthorize" :async-close="true"
  21. :show-cancel-button="true"></u-modal>
  22. <u-modal v-model="modalShow2" content="是否删除该授权用户" @confirm="deleteAuthorize" :async-close="true" :show-cancel-button="true"></u-modal>
  23. <u-top-tips ref="uTips"></u-top-tips>
  24. </view>
  25. </template>
  26. <script>
  27. const NET = require('@/utils/request')
  28. const API = require('@/config/api')
  29. export default {
  30. data() {
  31. return {
  32. modalShow1: false,
  33. modalShow2: false,
  34. userInfo: {
  35. userId: '',
  36. merchantImg: '',
  37. merchantNickname: '',
  38. merchantPhone: '',
  39. },
  40. checkList: [],
  41. }
  42. },
  43. onLoad(options) {
  44. NET.request(API.getAuthorizeDetail + options.id, {}, 'GET').then(res => {
  45. this.userInfo = {
  46. userId: res.data.userId,
  47. merchantImg: res.data.merchantImg,
  48. merchantNickname: res.data.merchantNickname,
  49. merchantPhone: res.data.merchantPhone,
  50. }
  51. let role = res.data.roleInfos.map(stie => {
  52. return stie.roleId
  53. }).join(',')
  54. this.checkList = res.data.allRoleInfos.map(stie => {
  55. return {
  56. roleName: stie.roleName,
  57. roleId: stie.roleId,
  58. checked: role.indexOf(stie.roleId) != -1,
  59. disabled: false
  60. }
  61. })
  62. }).catch(error => {
  63. console.log(error)
  64. this.$refs.uTips.show({
  65. title: error.msg,
  66. type: 'warning',
  67. })
  68. })
  69. },
  70. methods: {
  71. // 设置授权用户权限
  72. setAuthorize() {
  73. NET.request(API.setAuthorize + this.userInfo.userId, {
  74. roleInfos: this.checkList.filter(site => site.checked).map(site => {
  75. return {
  76. roleName: site.roleName,
  77. roleId: site.roleId,
  78. }
  79. })
  80. }, 'POST').then(res => {
  81. this.modalShow1 = false
  82. this.$refs.uTips.show({
  83. title: '授权户成功',
  84. type: 'success',
  85. })
  86. setTimeout(() => {
  87. uni.navigateBack()
  88. }, 1000)
  89. }).catch(error => {
  90. this.modalShow1 = false
  91. this.$refs.uTips.show({
  92. title: error.data.msg,
  93. type: 'warning',
  94. })
  95. })
  96. },
  97. // 删除授权用户
  98. deleteAuthorize() {
  99. NET.request(API.deleteAuthorizeUser + this.userInfo.userId, {}, 'DELETE').then(res => {
  100. this.modalShow2 = false
  101. this.$refs.uTips.show({
  102. title: '删除授权用户成功',
  103. type: 'success',
  104. })
  105. setTimeout(() => {
  106. uni.navigateBack()
  107. }, 1000)
  108. }).catch(error => {
  109. this.modalShow2 = false
  110. this.$refs.uTips.show({
  111. title: error.data.msg,
  112. type: 'warning',
  113. })
  114. })
  115. },
  116. },
  117. }
  118. </script>
  119. <style lang="less" scoped>
  120. page {
  121. width: 100%;
  122. height: 100%;
  123. }
  124. .container {
  125. width: 100%;
  126. height: 100%;
  127. float: left;
  128. position: absolute;
  129. .authorize-head {
  130. width: 100%;
  131. height: 120px;
  132. float: left;
  133. background: #52A63A;
  134. box-sizing: border-box;
  135. padding: 15px;
  136. .authorize-image {
  137. width: 66px;
  138. height: 66px;
  139. float: left;
  140. border-radius: 50%;
  141. overflow: hidden;
  142. }
  143. .authorize-info {
  144. width: calc(100% - 82px);
  145. height: 66px;
  146. float: left;
  147. margin-left: 15px;
  148. .authorize-name {
  149. width: 100%;
  150. height: 42px;
  151. float: left;
  152. font-size: 18px;
  153. font-family: PingFang SC;
  154. color: #333333;
  155. line-height: 42px;
  156. }
  157. .authorize-phone {
  158. width: 100%;
  159. height: 24px;
  160. float: left;
  161. font-size: 15px;
  162. font-family: PingFang SC;
  163. color: #666666;
  164. line-height: 24px;
  165. }
  166. }
  167. }
  168. .authorize-box {
  169. width: 100%;
  170. height: calc(100% - 220px);
  171. float: left;
  172. box-sizing: border-box;
  173. padding: 15px;
  174. margin-top: -25px;
  175. background: #FFFFFF;
  176. border-radius: 10px 10px 0px 0px;
  177. overflow-y: auto;
  178. /deep/.u-checkbox-group {
  179. float: left;
  180. }
  181. /deep/.u-checkbox {
  182. padding: 8px 0;
  183. }
  184. /deep/.u-checkbox__label {
  185. margin-left: 10px;
  186. }
  187. }
  188. .form-handle {
  189. width: 100%;
  190. height: 120px;
  191. box-sizing: border-box;
  192. padding: 10px 15px;
  193. float: left;
  194. .handle-custom {
  195. background-color: #51A539;
  196. margin-bottom: 15px;
  197. }
  198. }
  199. }
  200. </style>