users.vue 11 KB

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