users.vue 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  1. <template>
  2. <view class="column" style="height: calc(100% - 20rpx) ;">
  3. <view class="top " >
  4. <u-search placeholder="输入姓名/昵称搜索" bgColor='#F8F8FC'
  5. v-model="searchContent" @custom="search()" @search="search()"></u-search>
  6. <view class="justify-around fs28">
  7. <view v-for="(item,index) in tabs" :key="index" :class="act==index?'active':'notact'"
  8. @click="tabact(index)" class="flex-1 center ptb20">{{item}}</view>
  9. <view v-show="act==1" @click="selectact=!selectact" :class="selectact?'active':''"
  10. class="flex-1 center ptb20">批量</view>
  11. </view>
  12. </view>
  13. <scroll-view scroll-y class="indexes flex-1 pb60" :scroll-into-view="'indexes-'+ listCurID" :style="[{height:'calc(100vh - 300rpx)'}]"
  14. :scroll-with-animation="true" :enable-back-to-top="true" >
  15. <view v-for="(item,index) in list" :key="index">
  16. <view :class="'indexItem-' + item.firstLetter" :id="'indexes-' + item.firstLetter" :data-index="item.firstLetter">
  17. <view class="zm">{{item.firstLetter}}</view>
  18. <view class="user-list">
  19. <view class="user-item justify-start" v-for="(subitem,index) in item.list"
  20. @click="navTo(subitem)" :key="index">
  21. <u-checkbox-group @change="changeitem(subitem.userId)" v-if="selectact">
  22. <u-checkbox :checked="subitem.checked" shape="circle" activeColor="#1773ff" :name="subitem.userId"
  23. labelColor="#1773ff" />
  24. </u-checkbox-group>
  25. <view class="bgf p20 radius16 flex-1">
  26. <view class="justify-between align-center">
  27. <view class="justify-start align-center">
  28. <view class="avatar" >
  29. <image class="img" :src="subitem.avatar?(baseUrl+subitem.avatar):avatar" mode="aspectFill"></image>
  30. </view>
  31. <view class="content">
  32. <view class="name">
  33. {{subitem.nickName}}
  34. </view>
  35. <view class="dept justify-start align-center">
  36. <u-icon name="phone"></u-icon><view>1576984582</view> </view>
  37. <view class="dept">注册时间:2025-01-24</view>
  38. </view>
  39. </view>
  40. <view class="base-color fs24">未禁用</view>
  41. </view>
  42. <view class="justify-between mt10">
  43. <view class="fs24 mt20 ml10" style="color: #115296;">
  44. {{subitem.deptName}}
  45. </view>
  46. <!-- <view class="fs24 base-color-red mr10 bor-red
  47. base-bg-false plr20 radius40 ptb4">已禁用</view> -->
  48. <view class="fs24 base-color mr10 bor-blue h52 lh50
  49. base-bg-sure plr20 radius40 " style="width: fit-content;" v-if="act==0">已审核</view>
  50. <view class="fs24 base-color-red mr10 bor-red h52 lh50
  51. base-bg-false plr20 radius40 " style="width: fit-content;" v-if="!selectact&&act==1">待审核</view>
  52. </view>
  53. </view>
  54. </view>
  55. </view>
  56. </view>
  57. </view>
  58. </scroll-view>
  59. <view class="indexBar" :style="[{height:'calc(100vh - 88rpx)'}]">
  60. <view class="indexBar-box" @touchstart="tStart" @touchend="tEnd" @touchmove.stop="tMove">
  61. <view class="indexBar-item" v-for="(item,index) in list" :key="index" :id="index"
  62. @touchstart="getCur" @touchend="setCur"> {{item.firstLetter}}</view>
  63. </view>
  64. </view>
  65. <view class="justify-between base-bg-f foot-select " v-if="selectact">
  66. <view class="align-center justify-between " v-if="selectact">
  67. <u-checkbox-group @change="selectAll">
  68. <u-checkbox :checked="isSelectAll" shape="circle" activeColor="#1773ff" :name="true"
  69. label="全选" labelColor="#333" />
  70. <text class="fs24 base-color-9 ml12">已选{{ selectedUsers.length }}个</text>
  71. <!-- {{selectedCount}} -->
  72. </u-checkbox-group>
  73. </view>
  74. <view class="justify-center ">
  75. <button class="base-bg-f radius100 base-color-red h62 ml10 fs28 lh60"
  76. style="border: #ef4c50 solid 2rpx;"
  77. @click="batchApprove">通过审核</button>
  78. </view>
  79. </view>
  80. <!--选择显示-->
  81. <view v-show="!hidden" class="indexToast">
  82. {{listCur}}
  83. </view>
  84. </view>
  85. </template>
  86. <script>
  87. import {getAllUsers} from '@/api/user.js';
  88. export default {
  89. data() {
  90. return {
  91. baseUrl:uni.getStorageSync('requestPath'),
  92. avatar:"/static/images/default.png",
  93. CustomBar: 0,
  94. hidden: true,
  95. listCurID: '',
  96. list: [],
  97. listCur: '',
  98. searchContent:"",
  99. tabs:['已审核','未审核'],
  100. act:0,
  101. selectact:false,
  102. isSelectAll:false,
  103. selectedUsers:[]
  104. }
  105. },
  106. onLoad() {
  107. this.getUser();
  108. },
  109. onReady() {
  110. let that = this;
  111. uni.createSelectorQuery().select('.indexBar-box').boundingClientRect(function(res) {
  112. that.boxTop = res.top
  113. }).exec();
  114. uni.createSelectorQuery().select('.indexes').boundingClientRect(function(res) {
  115. that.barTop = res.top
  116. }).exec()
  117. },
  118. methods: {
  119. batchApprove(){
  120. if (this.selectedUsers.length === 0) {
  121. uni.showToast({
  122. title: '请先选择用户',
  123. icon: 'none',
  124. });
  125. return;
  126. }
  127. },
  128. // 全选
  129. selectAll() {
  130. this.isSelectAll = !this.isSelectAll;
  131. this.selectedUsers = []; // 清空已选列表
  132. // 遍历所有用户项,更新 checked 状态
  133. this.list = this.list.map(group => {
  134. group.list = group.list.map(user => {
  135. if (this.isSelectAll) {
  136. this.selectedUsers.push(user.userId); // 添加用户ID到选中列表
  137. }
  138. return {
  139. ...user,
  140. checked: this.isSelectAll,
  141. };
  142. });
  143. return group;
  144. });
  145. // 如果取消全选,清空 selectedUsers
  146. if (!this.isSelectAll) {
  147. this.selectedUsers = [];
  148. }
  149. },
  150. // 单选 /反选
  151. changeitem(userId) {
  152. const index = this.selectedUsers.indexOf(userId);
  153. if (index === -1) {
  154. this.selectedUsers.push(userId); // 选中
  155. } else {
  156. this.selectedUsers.splice(index, 1); // 取消选中
  157. }
  158. // 更新全选状态
  159. this.isSelectAll = this.selectedUsers.length === this.getTotalUsers();
  160. },
  161. // 计算总用户数
  162. getTotalUsers() {
  163. return this.list.reduce((total, group) => total + group.list.length, 0);
  164. },
  165. tabact(index){
  166. this.act=index
  167. if(index==0){
  168. this.selectact=false
  169. }
  170. },
  171. getUser(){
  172. var data = {searchKey:this.searchContent};
  173. var that=this;
  174. getAllUsers(data).then(
  175. res => {
  176. if(res.code==200){
  177. that.list=res.users;
  178. }
  179. },
  180. rej => {}
  181. );
  182. },
  183. //获取文字信息
  184. getCur(e) {
  185. this.hidden = false;
  186. this.listCur = this.list[e.target.id].firstLetter;
  187. },
  188. setCur(e) {
  189. this.hidden = true;
  190. this.listCur = this.listCur
  191. },
  192. //滑动选择Item
  193. tMove(e) {
  194. let y = e.touches[0].clientY,
  195. offsettop = this.boxTop,
  196. that = this;
  197. //判断选择区域,只有在选择区才会生效
  198. if (y > offsettop) {
  199. let num = parseInt((y - offsettop) / 20);
  200. console.log(num);
  201. if(num<that.list.length){
  202. this.listCur = that.list[num].firstLetter
  203. }
  204. };
  205. },
  206. //触发全部开始选择
  207. tStart() {
  208. this.hidden = false
  209. },
  210. //触发结束选择
  211. tEnd() {
  212. this.hidden = true;
  213. this.listCurID = this.listCur
  214. },
  215. indexSelect(e) {
  216. let that = this;
  217. let barHeight = this.barHeight;
  218. let list = this.list;
  219. let scrollY = Math.ceil(list.length * e.detail.y / barHeight);
  220. for (let i = 0; i < list.length; i++) {
  221. if (scrollY < i + 1) {
  222. that.listCur = list[i].firstLetter;
  223. that.movableY = i * 20
  224. return false
  225. }
  226. }
  227. },
  228. navTo(subitem){
  229. uni.navigateTo({
  230. url: './userInfo?userId='+subitem.userId
  231. })
  232. },
  233. search(){
  234. this.getUser()
  235. }
  236. }
  237. }
  238. </script>
  239. <style lang="scss">
  240. ::v-deep {
  241. .foot-select {
  242. position: fixed;
  243. bottom: 0;
  244. width: 100%;
  245. padding: 20rpx;
  246. background: #fff;
  247. box-shadow: 0 -2rpx 10rpx rgba(0,0,0,0.1);
  248. z-index: 1000;
  249. }
  250. }
  251. .active{
  252. color: #1773ff;
  253. font-weight: bold;
  254. }
  255. .notact{
  256. color: #888;
  257. }
  258. page {
  259. background-color: #F8F8FC;
  260. }
  261. .top{
  262. /* height: 88rpx; */
  263. background-color: #fff;
  264. padding: 0rpx 15rpx;
  265. padding-top: 20rpx;
  266. }
  267. .indexes {
  268. position: relative;
  269. }
  270. .indexBar {
  271. position: fixed;
  272. right: 0px;
  273. bottom: 0px;
  274. padding: 20upx 20upx 20upx 60upx;
  275. display: flex;
  276. align-items: center;
  277. }
  278. .indexBar .indexBar-box {
  279. width: 40upx;
  280. height: auto;
  281. background: #fff;
  282. display: flex;
  283. flex-direction: column;
  284. box-shadow: 0 0 20upx rgba(0, 0, 0, 0.1);
  285. border-radius: 10upx;
  286. }
  287. .indexBar-item {
  288. flex: 1;
  289. width: 40upx;
  290. height: 40upx;
  291. display: flex;
  292. align-items: center;
  293. justify-content: center;
  294. font-size: 24upx;
  295. color: #888;
  296. }
  297. movable-view.indexBar-item {
  298. width: 40upx;
  299. height: 40upx;
  300. z-index: 9;
  301. position: relative;
  302. }
  303. movable-view.indexBar-item::before {
  304. content: "";
  305. display: block;
  306. position: absolute;
  307. left: 0;
  308. top: 10upx;
  309. height: 20upx;
  310. width: 4upx;
  311. background-color: #f37b1d;
  312. }
  313. .indexToast {
  314. position: fixed;
  315. top: 0;
  316. right: 80upx;
  317. bottom: 0;
  318. background: rgba(0, 0, 0, 0.5);
  319. width: 100upx;
  320. height: 100upx;
  321. border-radius: 10upx;
  322. margin: auto;
  323. color: #fff;
  324. line-height: 100upx;
  325. text-align: center;
  326. font-size: 48upx;
  327. }
  328. .zm{
  329. height:30rpx;
  330. padding: 0rpx 20rpx;
  331. font-size: 24rpx;
  332. color: #888;
  333. background: #F8F8FC;
  334. }
  335. .user-list{
  336. margin: 20rpx;
  337. border-radius: 20rpx;
  338. }
  339. .user-item{
  340. width: 100%;
  341. margin: 12rpx 0;
  342. }
  343. .user-item .avatar{
  344. width: 100upx;
  345. height: 100upx;
  346. }
  347. .user-item .avatar .img{
  348. border-radius: 50%;
  349. width: 100%;
  350. height: 100%;
  351. }
  352. .user-item .content{
  353. margin-left: 15rpx;
  354. }
  355. .user-item .content .name{
  356. font-size: 26rpx;
  357. color: #111;
  358. }
  359. .user-item .content .dept{
  360. font-size: 24rpx;
  361. color: #888;
  362. margin-top: 15rpx;
  363. }
  364. </style>