powerSet.vue 6.5 KB

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