powerSet.vue 6.3 KB

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