authorizeForm.vue 5.2 KB

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