powerSet.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. <template>
  2. <view class="container">
  3. <!-- 头部分段选择器区域 -->
  4. <view class="control">
  5. <uni-segmented-control :current="current" :values="items" styleType="text" @clickItem="onClickItem"
  6. activeColor="#0082FC"></uni-segmented-control>
  7. </view>
  8. <!-- 搜索栏区域 -->
  9. <view class="search">
  10. <uni-search-bar bgColor="#fff" placeholder="请输入姓名" cancelButton="none" v-model="searchValue" @clear="clear"
  11. @input="getSearchData">
  12. </uni-search-bar>
  13. </view>
  14. <!-- 权限人物区域 -->
  15. <view class="choose" v-if="chooseList.length">
  16. <view class="box" v-for="item in chooseList" :key="item.id">
  17. <view class="name">
  18. {{item.name}}
  19. </view>
  20. <view class="icon" @click="handleDelete(item)">
  21. <img src="../../static/close.png">
  22. </view>
  23. </view>
  24. </view>
  25. <!-- 搜索人员展示区域 -->
  26. <view class="list" v-if="list.length">
  27. <!-- 每一个人员区域 -->
  28. <view class="item" v-for="item in list" :key="item.id" @click="handleAdd(item)">
  29. {{item.name}} -- {{item.identityType}} -- {{item.idCard}}
  30. </view>
  31. </view>
  32. </view>
  33. </template>
  34. <script>
  35. export default {
  36. data() {
  37. return {
  38. items: ['管理员', '子管理员'],
  39. current: 0,
  40. searchValue: "",
  41. roleId: 2,
  42. list: [],
  43. chooseList: [],
  44. typeValue: "管理员"
  45. };
  46. },
  47. onLoad() {
  48. this.getData()
  49. },
  50. methods: {
  51. // 获取权限列表数据
  52. async getData() {
  53. let res = await this.$myRequest({
  54. url: "/attendance/api/system/user/list",
  55. data: {
  56. roleId: this.roleId,
  57. size: 9999
  58. }
  59. })
  60. // console.log(res);
  61. if (res.code == 200) {
  62. this.chooseList = res.data.list
  63. }
  64. },
  65. // 获取搜索列表的数据
  66. async getSearchData() {
  67. if (this.searchValue) {
  68. let res = await this.$myRequest({
  69. url: "/attendance/api/system/user/list",
  70. data: {
  71. name: this.searchValue,
  72. size: 9999
  73. }
  74. })
  75. // console.log(res);
  76. if (res.code == 200) {
  77. this.list = res.data.list
  78. this.list.forEach((ele) => {
  79. if (ele.identityType == 0) {
  80. ele.identityType = "其他"
  81. } else if (ele.identityType == 1) {
  82. ele.identityType = "学生"
  83. } else if (ele.identityType == 4) {
  84. ele.identityType = "教职工"
  85. } else if (ele.identityType == 5) {
  86. ele.identityType = "校友"
  87. } else if (ele.identityType == 6) {
  88. ele.identityType = "访客"
  89. } else if (ele.identityType == 7) {
  90. ele.identityType = "临时人员"
  91. }
  92. })
  93. }
  94. }
  95. },
  96. // 清空搜索框回调
  97. clear() {
  98. this.list = []
  99. },
  100. // 分段器点击回调
  101. onClickItem(e) {
  102. this.list = []
  103. this.searchValue = ""
  104. // console.log(e.currentIndex);
  105. if (e.currentIndex == 0) {
  106. this.roleId = 2
  107. this.typeValue = "管理员"
  108. } else {
  109. this.roleId = 3
  110. this.typeValue = "子管理员"
  111. }
  112. this.getData()
  113. },
  114. // × 图标点击回调
  115. handleDelete(item) {
  116. uni.showModal({
  117. title: '提示',
  118. content: `确定将 ${item.name} 从${this.typeValue}列表中删除吗?`,
  119. success: async (res) => {
  120. if (res.confirm) {
  121. let res = await this.$myRequest({
  122. url: "/attendance/api/system/role/update/user",
  123. method: "put",
  124. header: {
  125. 'Authorization': uni.getStorageSync("token") ||
  126. 'eyJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjo1MDQ2LCJ1c2VyX3V1aWQiOjEzNDc3NzE0NzM1NTY5NzE1MiwibmJmIjoxNjcxMTU1ODQzfQ.u4-N762Ijfb9RkuuFOFkeMiJQI9uCi0IaheJlGwi5Ms'
  127. },
  128. data: {
  129. id: this.roleId,
  130. addIds: [],
  131. removeIds: [item.id]
  132. }
  133. })
  134. // console.log(res);
  135. if (res.code == 200 && res.data) {
  136. uni.showToast({
  137. title: "删除成功",
  138. icon: 'success'
  139. })
  140. setTimeout(() => {
  141. this.searchValue = ""
  142. this.list = []
  143. this.getData()
  144. }, 1500)
  145. }
  146. } else if (res.cancel) {}
  147. }
  148. });
  149. },
  150. // 点击添加回调
  151. handleAdd(item) {
  152. // 判断当前用户是否已经拥有该权限
  153. let temList = []
  154. this.chooseList.forEach((ele) => {
  155. temList.push(ele.id)
  156. })
  157. let flag = temList.includes(item.id)
  158. if (flag) {
  159. uni.showModal({
  160. title: '提示',
  161. content: `当前用户已经是${this.typeValue},请勿重复设置`,
  162. showCancel: false
  163. });
  164. } else {
  165. uni.showModal({
  166. title: '提示',
  167. content: `确定将 ${item.name} 设置成${this.typeValue}吗?`,
  168. success: async (res) => {
  169. if (res.confirm) {
  170. let res = await this.$myRequest({
  171. url: "/attendance/api/system/role/update/user",
  172. method: "put",
  173. header: {
  174. 'Authorization': uni.getStorageSync("token") ||
  175. 'eyJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjo1MDQ2LCJ1c2VyX3V1aWQiOjEzNDc3NzE0NzM1NTY5NzE1MiwibmJmIjoxNjcxMTU1ODQzfQ.u4-N762Ijfb9RkuuFOFkeMiJQI9uCi0IaheJlGwi5Ms'
  176. },
  177. data: {
  178. id: this.roleId,
  179. addIds: [item.id],
  180. removeIds: []
  181. }
  182. })
  183. // console.log(res);
  184. if (res.code == 200 && res.data) {
  185. uni.showToast({
  186. title: "添加成功",
  187. icon: 'success'
  188. })
  189. setTimeout(() => {
  190. this.searchValue = ""
  191. this.list = []
  192. this.getData()
  193. }, 1500)
  194. }
  195. } else if (res.cancel) {}
  196. }
  197. });
  198. }
  199. }
  200. }
  201. }
  202. </script>
  203. <style lang="scss" scoped>
  204. .container {
  205. padding-top: 20rpx;
  206. .control {
  207. display: flex;
  208. flex-direction: column;
  209. justify-content: center;
  210. width: 750rpx;
  211. height: 86rpx;
  212. background-color: #fff;
  213. }
  214. .search {
  215. box-sizing: border-box;
  216. margin-top: 20rpx;
  217. padding: 0 30rpx;
  218. width: 750rpx;
  219. height: 90rpx;
  220. border-radius: 170rpx;
  221. background-color: #fff;
  222. }
  223. .choose {
  224. display: flex;
  225. flex-wrap: wrap;
  226. justify-content: space-evenly;
  227. align-items: center;
  228. margin-top: 20rpx;
  229. padding: 30rpx;
  230. width: 690rpx;
  231. border-bottom: 1rpx solid #E5E5E5;
  232. background-color: #fff;
  233. .box {
  234. display: flex;
  235. align-items: center;
  236. width: 150rpx;
  237. height: 60rpx;
  238. .name {
  239. flex: 2;
  240. text-align: center;
  241. font-size: 28rpx;
  242. }
  243. .icon {
  244. flex: 1;
  245. display: flex;
  246. align-items: center;
  247. height: 50rpx;
  248. img {
  249. width: 30rpx;
  250. height: 30rpx;
  251. }
  252. }
  253. }
  254. }
  255. .list {
  256. display: flex;
  257. flex-direction: column;
  258. justify-content: space-evenly;
  259. padding-top: 22rpx;
  260. width: 750rpx;
  261. border-bottom: 1rpx solid #E5E5E5;
  262. background-color: #fff;
  263. .item {
  264. margin-bottom: 30rpx;
  265. margin-left: 65rpx;
  266. height: 41rpx;
  267. font-size: 28rpx;
  268. }
  269. }
  270. }
  271. // 解决输入框不居中问题
  272. ::v-deep .uni-searchbar {
  273. padding: 10rpx;
  274. }
  275. </style>