powerSet.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  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. 'platform': 2
  128. },
  129. data: {
  130. id: this.roleId,
  131. addIds: [],
  132. removeIds: [item.id]
  133. }
  134. })
  135. // console.log(res);
  136. if (res.code == 200 && res.data) {
  137. uni.showToast({
  138. title: "删除成功",
  139. icon: 'success'
  140. })
  141. setTimeout(() => {
  142. this.searchValue = ""
  143. this.list = []
  144. this.getData()
  145. }, 1500)
  146. }
  147. } else if (res.cancel) {}
  148. }
  149. });
  150. },
  151. // 点击添加回调
  152. handleAdd(item) {
  153. // 判断当前用户是否已经拥有该权限
  154. let temList = []
  155. this.chooseList.forEach((ele) => {
  156. temList.push(ele.id)
  157. })
  158. let flag = temList.includes(item.id)
  159. if (flag) {
  160. uni.showModal({
  161. title: '提示',
  162. content: `当前用户已经是${this.typeValue},请勿重复设置`,
  163. showCancel: false
  164. });
  165. } else {
  166. uni.showModal({
  167. title: '提示',
  168. content: `确定将 ${item.name} 设置成${this.typeValue}吗?`,
  169. success: async (res) => {
  170. if (res.confirm) {
  171. let res = await this.$myRequest_clockIn({
  172. url: "/attendance/api/system/role/update/user",
  173. method: "put",
  174. header: {
  175. 'Authorization': uni.getStorageSync("token"),
  176. 'platform': 2
  177. },
  178. data: {
  179. id: this.roleId,
  180. addIds: [item.id],
  181. removeIds: []
  182. }
  183. })
  184. // console.log(res);
  185. if (res.code == 200 && res.data) {
  186. uni.showToast({
  187. title: "添加成功",
  188. icon: 'success'
  189. })
  190. setTimeout(() => {
  191. this.searchValue = ""
  192. this.list = []
  193. this.getData()
  194. }, 1500)
  195. }
  196. } else if (res.cancel) {}
  197. }
  198. });
  199. }
  200. }
  201. }
  202. }
  203. </script>
  204. <style lang="scss" scoped>
  205. .container {
  206. min-width: 100vw;
  207. min-height: 100vh;
  208. background-color: #F2F2F2;
  209. .placeholder {
  210. height: 20rpx;
  211. }
  212. .control {
  213. display: flex;
  214. flex-direction: column;
  215. justify-content: center;
  216. width: 750rpx;
  217. height: 86rpx;
  218. background-color: #fff;
  219. }
  220. .search {
  221. box-sizing: border-box;
  222. margin-top: 20rpx;
  223. padding: 0 30rpx;
  224. width: 750rpx;
  225. height: 90rpx;
  226. border-radius: 170rpx;
  227. background-color: #fff;
  228. }
  229. .choose {
  230. display: flex;
  231. flex-wrap: wrap;
  232. justify-content: space-evenly;
  233. align-items: center;
  234. margin-top: 20rpx;
  235. padding: 30rpx;
  236. width: 690rpx;
  237. border-bottom: 1rpx solid #E5E5E5;
  238. background-color: #fff;
  239. .box {
  240. display: flex;
  241. align-items: center;
  242. width: 150rpx;
  243. height: 60rpx;
  244. .name {
  245. flex: 2;
  246. text-align: center;
  247. font-size: 28rpx;
  248. }
  249. .icon {
  250. flex: 1;
  251. display: flex;
  252. align-items: center;
  253. height: 50rpx;
  254. img {
  255. width: 30rpx;
  256. height: 30rpx;
  257. }
  258. }
  259. }
  260. }
  261. .list {
  262. display: flex;
  263. flex-direction: column;
  264. justify-content: space-evenly;
  265. padding-top: 22rpx;
  266. width: 750rpx;
  267. border-bottom: 1rpx solid #E5E5E5;
  268. background-color: #fff;
  269. .item {
  270. margin-bottom: 30rpx;
  271. margin-left: 65rpx;
  272. height: 41rpx;
  273. font-size: 28rpx;
  274. }
  275. }
  276. }
  277. // 解决输入框不居中问题
  278. ::v-deep .uni-searchbar {
  279. padding: 10rpx;
  280. }
  281. </style>