powerSet.vue 6.7 KB

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