authorizeForm.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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="creatAuthorize" class="handle-custom">确认授权</u-button>
  18. <u-button type="error" shape="circle" :ripple="true" @click="modalShow1 = 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.allRoleInfos.map(stie => {
  52. return site.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. this.$refs.uTips.show({
  64. title: error.data.msg,
  65. type: 'warning',
  66. })
  67. })
  68. },
  69. methods: {
  70. // 设置授权用户权限
  71. setAuthorize() {
  72. NET.request(API.setAuthorize + this.userInfo.userId, {
  73. roleInfos: this.checkList.filter(site => site.check).map(site => {
  74. return {
  75. roleName: site.roleName,
  76. roleId: site.roleId,
  77. }
  78. })
  79. }, 'POST').then(res => {
  80. this.modalShow1 = false
  81. this.$refs.uTips.show({
  82. title: '授权户成功',
  83. type: 'success',
  84. })
  85. setTimeout(() => {
  86. uni.navigateBack()
  87. }, 1000)
  88. }).catch(error => {
  89. this.modalShow1 = false
  90. this.$refs.uTips.show({
  91. title: error.data.msg,
  92. type: 'warning',
  93. })
  94. })
  95. },
  96. // 删除授权用户
  97. deleteAuthorize() {
  98. NET.request(API.deleteAuthorizeUser + this.userInfo.userId, {}, 'DELETE').then(res => {
  99. this.modalShow2 = false
  100. this.$refs.uTips.show({
  101. title: '删除授权用户成功',
  102. type: 'success',
  103. })
  104. setTimeout(() => {
  105. uni.navigateBack()
  106. }, 1000)
  107. }).catch(error => {
  108. this.modalShow2 = false
  109. this.$refs.uTips.show({
  110. title: error.data.msg,
  111. type: 'warning',
  112. })
  113. })
  114. },
  115. },
  116. }
  117. </script>
  118. <style lang="less" scoped>
  119. page {
  120. width: 100%;
  121. height: 100%;
  122. }
  123. .container {
  124. width: 100%;
  125. height: 100%;
  126. float: left;
  127. position: absolute;
  128. .authorize-head {
  129. width: 100%;
  130. height: 120px;
  131. float: left;
  132. background: #52A63A;
  133. box-sizing: border-box;
  134. padding: 15px;
  135. .authorize-image {
  136. width: 66px;
  137. height: 66px;
  138. float: left;
  139. border-radius: 50%;
  140. overflow: hidden;
  141. }
  142. .authorize-info {
  143. width: calc(100% - 82px);
  144. height: 66px;
  145. float: left;
  146. margin-left: 15px;
  147. .authorize-name {
  148. width: 100%;
  149. height: 42px;
  150. float: left;
  151. font-size: 18px;
  152. font-family: PingFang SC;
  153. color: #333333;
  154. line-height: 42px;
  155. }
  156. .authorize-phone {
  157. width: 100%;
  158. height: 24px;
  159. float: left;
  160. font-size: 15px;
  161. font-family: PingFang SC;
  162. color: #666666;
  163. line-height: 24px;
  164. }
  165. }
  166. }
  167. .authorize-box {
  168. width: 100%;
  169. height: calc(100% - 220px);
  170. float: left;
  171. box-sizing: border-box;
  172. padding: 15px;
  173. margin-top: -25px;
  174. background: #FFFFFF;
  175. border-radius: 10px 10px 0px 0px;
  176. overflow-y: auto;
  177. /deep/.u-checkbox-group {
  178. float: left;
  179. }
  180. /deep/.u-checkbox {
  181. padding: 8px 0;
  182. }
  183. /deep/.u-checkbox__label {
  184. margin-left: 10px;
  185. }
  186. }
  187. .form-handle {
  188. width: 100%;
  189. height: 120px;
  190. box-sizing: border-box;
  191. padding: 10px 15px;
  192. float: left;
  193. .handle-custom {
  194. background-color: #51A539;
  195. margin-bottom: 15px;
  196. }
  197. }
  198. }
  199. </style>