users.vue 11 KB

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