userlist.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  1. <template>
  2. <view class="page">
  3. <view class="usertop" :style="'top:'+contenttop">
  4. <view class="icon" @tap='click_search'><uni-icons type='search' style="font-size: 28px;vertical-align: middle;"></uni-icons></view>
  5. <view class="avatars" v-if="!issearch">
  6. <block v-for="(m,index) in userlist" :key='m.id'>
  7. <image v-if="get_checkbox(m.id)!=false && (!get_disable(m.id) || next!='invite')" :src="image_cache(m.avatar)"></image>
  8. </block>
  9. </view>
  10. <view class="search" v-else>
  11. <input placeholder="请输入用户昵称" class="input" v-model="keyword" @input="onsearch( $event.detail.value);" />
  12. <button class="btn" @tap='click_search'>取消</button>
  13. </view>
  14. </view>
  15. <view class="userlist">
  16. <block v-if="shownum>0">
  17. <block v-for="(m,index) in userlist" :key='index' >
  18. <view v-if="searchshow(m)" @tap="set_checkbox(m.id)">
  19. <view class="icon">
  20. <checkbox :checked="get_checkbox(m.id)" :disabled="get_checkbox(m.id)"></checkbox>
  21. </view>
  22. <view class="avatar" >
  23. <image :src="image_cache(m.avatar)"></image>
  24. </view>
  25. <view class="nickname" >
  26. {{m.nickname}}
  27. </view>
  28. </view>
  29. </block>
  30. </block>
  31. <view v-else class="nodata" style="text-align: center;color: #666;">
  32. 没有找到相关用户
  33. </view>
  34. </view>
  35. <view style="height: 40px;"></view>
  36. <view class="subbutton" @tap="submit">
  37. {{subtitle}}
  38. <block v-if="clicklen">
  39. ({{clicklen}})
  40. </block>
  41. </view>
  42. </view>
  43. </template>
  44. <script>
  45. import uniIcons from '../../components/uni-icons/uni-icons.vue'
  46. var windowHeight= uni.getSystemInfoSync().windowHeight;
  47. var statusBarHeight = uni.getSystemInfoSync().statusBarHeight ;
  48. var contenttop=0;
  49. // #ifndef APP-PLUS
  50. var contenttop=statusBarHeight+40;
  51. //#endif
  52. export default {
  53. components: {
  54. uniIcons
  55. },
  56. props: {
  57. },
  58. computed:{
  59. clicklen(){
  60. var arr=this.checkbox.split('@');
  61. var num=0;
  62. for(var i=0;i<arr.length;i++){
  63. if(arr[i]>0){
  64. num++;
  65. }
  66. }
  67. var num1=0;
  68. if(this.next=='invite'){
  69. var arr=this.disabled.split('@');
  70. for(var i=0;i<arr.length;i++){
  71. if(arr[i]>0){
  72. num1++;
  73. }
  74. }
  75. }
  76. return num-num1;
  77. }
  78. },
  79. data() {
  80. return {
  81. contenttop:contenttop+'px',
  82. user:uni.getStorageSync('userInfo'),
  83. userlist:uni.getStorageSync(uni.getStorageSync('access_token')+'_frienddata'),
  84. isme:true,
  85. checkbox:'',
  86. disabled:'',
  87. issearch:false,
  88. keyword:'',
  89. shownum:1,
  90. subtitle:'确认',
  91. next:'',
  92. group:[],
  93. group_id:0,
  94. }
  95. },
  96. methods: {
  97. click_search(){
  98. this.issearch=!this.issearch;
  99. this.keyword="";
  100. this.shownum=this.userlist.length;
  101. },
  102. get_checkbox(id){
  103. if(this.checkbox.indexOf('@'+id)>-1) return true;
  104. return false;
  105. },
  106. get_disable(id){
  107. if(this.disabled.indexOf('@'+id)>-1) return true;
  108. return false;
  109. },
  110. set_checkbox(id){
  111. if(this.get_disable(id)) return false;
  112. if(this.get_checkbox(id)){
  113. this.checkbox=this.checkbox.replace('@'+id,'');
  114. }
  115. else{
  116. this.checkbox+="@"+id;;
  117. }
  118. },
  119. searchshow(m){
  120. if(!this.issearch || this.keyword=='') return true;
  121. else{
  122. if(m.nickname.indexOf(this.keyword)>-1) return true;else return false;
  123. }
  124. },
  125. onsearch(value){
  126. var num=0;
  127. for(var i=0;i<this.userlist.length;i++){
  128. if(this.searchshow(this.userlist[i])) num++;
  129. }
  130. this.shownum=num;
  131. },
  132. submit(){
  133. if(this.clicklen>0){
  134. if(this.next=='invite'){
  135. var arr=this.checkbox.split('@');
  136. var checkbox='';
  137. for(var i=0;i<arr.length;i++){
  138. if(arr[i]>0){
  139. if(!this.get_disable(arr[i])){
  140. if(checkbox!='') checkbox+=',';
  141. checkbox+=arr[i];
  142. }
  143. }
  144. }
  145. if(this.group.no_add==0 || this.group.is_owner==1 || this.group.is_manager==1){
  146. //直接进群,无需审核
  147. var apply=0;
  148. }
  149. else{
  150. var apply=1;
  151. }
  152. var data={type:'inviteIntoGroup',userid:this.user.id,group_id:this.group_id,user_id:checkbox,apply:apply};
  153. this.$socket.send(data);
  154. this.$socket.on('apply_response', (res) => {
  155. if(res.data.code==1){
  156. var group=res.data.group;
  157. uni.showToast({
  158. icon:'none',
  159. title:res.data.message
  160. })
  161. setTimeout(function(){
  162. if(apply==1){
  163. uni.navigateBack();
  164. }
  165. else{
  166. uni.redirectTo({
  167. url:"/pages/group/chat?id="+group.id+'&nickname='+group.name
  168. })
  169. }
  170. },800)
  171. }
  172. else{
  173. uni.showToast({
  174. icon:'none',
  175. title:res.data.message
  176. })
  177. }
  178. })
  179. }else{
  180. uni.redirectTo({
  181. url:"../"+this.next+"?userlist="+this.checkbox
  182. })
  183. }
  184. } else{
  185. uni.showToast({
  186. title:'请选择用户',
  187. icon:'none'
  188. })
  189. }
  190. }
  191. },
  192. onLoad(opts) {
  193. if(opts.isme==0) this.isme=false;
  194. if(this.isme) {
  195. this.userlist=[this.user].concat(this.userlist);
  196. this.checkbox+="@"+this.user.id
  197. this.disabled+="@"+this.user.id
  198. }
  199. if(opts.disabled_id){
  200. var arr=opts.disabled_id.split('@');
  201. for(var i=0;i<arr.length;i++){
  202. if(arr[i]>0){
  203. this.checkbox+="@"+arr[i];
  204. this.disabled+="@"+arr[i]
  205. }
  206. }
  207. }
  208. if(opts.subtitle) this.subtitle=opts.subtitle;
  209. if(opts.next) this.next=opts.next;
  210. if(opts.group_id){
  211. this.group_id=opts.group_id;
  212. this.group=uni.getStorageSync('group_'+this.group_id);
  213. var userlist=[];
  214. for(var i=0;i<this.userlist.length;i++){
  215. if(!this.get_disable(this.userlist[i].id)) userlist.push(this.userlist[i])
  216. }
  217. this.userlist=userlist
  218. }
  219. this.shownum=this.userlist.length;
  220. }
  221. }
  222. </script>
  223. <style>
  224. @import "@/static/css/user.css";
  225. .page{
  226. background-color: #fafafa;
  227. position: relative;
  228. }
  229. .usertop{
  230. height: 50px;
  231. line-height: 50px;
  232. background-color: #fafafa;
  233. padding-top: 5px;;
  234. position: fixed;
  235. top: 0px;
  236. left: 0px;
  237. width: 100%;
  238. z-index: 10;
  239. border-bottom:1px solid #eee;
  240. display: table;
  241. table-layout: fixed;
  242. }
  243. .usertop > view{
  244. display: table-cell;
  245. }
  246. .usertop > view.icon{
  247. width: 50px;
  248. text-align: center;
  249. }
  250. .usertop > view.avatars{
  251. text-align: left;
  252. overflow: hidden;
  253. }
  254. .usertop > view.avatars image{
  255. vertical-align: middle;
  256. height: 30px;
  257. width: 30px;
  258. border-radius: 5px;
  259. margin: 0px 3px;
  260. }
  261. .usertop > view.search{
  262. text-align: left;
  263. }
  264. .usertop > view.search .input{
  265. display: inline-block;
  266. width: calc(100% - 80px);
  267. border:0px;
  268. border-bottom: 1px #ccc solid;
  269. color: #222;
  270. height: 35px;
  271. line-height: 35px;
  272. vertical-align: middle;
  273. }
  274. .usertop > view.search .btn{
  275. vertical-align: middle;
  276. float: none;
  277. display: inline-block;
  278. background-color: #eee;
  279. color: #222;
  280. }
  281. .userlist{
  282. margin-top: 60px;
  283. background-color: #fff;
  284. line-height: 40px;
  285. width: 100%;
  286. min-height: 40px;
  287. }
  288. .userlist > view{
  289. width: 100%;
  290. display: table;
  291. table-layout: fixed;
  292. padding: 5px 0px;
  293. border-top:1px solid #eee;
  294. }
  295. .userlist > view:first-child{
  296. border-top: 0px;
  297. }
  298. .userlist > view > view{
  299. display: table-cell;
  300. vertical-align: middle;
  301. }
  302. .userlist > view > view.avatar{
  303. width: 60px;
  304. text-align: center;
  305. }
  306. .userlist > view > view.avatar image{
  307. height: 40px;
  308. width: 40px;
  309. border-radius: 5px;
  310. vertical-align: middle;
  311. }
  312. .userlist > view > view.nickname{
  313. font-size: 16px;
  314. color: #222;
  315. line-height: 40px;
  316. }
  317. .userlist > view > view.icon{
  318. width: 40px;
  319. text-align: right;
  320. }
  321. .profile{
  322. background-color: #fff;
  323. margin: 10px auto;
  324. width: 100%;
  325. }
  326. .profile li{
  327. vertical-align: middle;
  328. }
  329. .profile li:first-child{
  330. padding-left: 10px;
  331. width: 150px;
  332. text-align: left;
  333. }
  334. .profile li:last-child{
  335. padding-right: 10px;
  336. text-align: right;
  337. width: calc(100% - 180px);
  338. vertical-align: middle;
  339. }
  340. .btn{
  341. height: 30px;
  342. line-height: 30px;
  343. background-color: #3388ff;
  344. color: #fff;
  345. padding: 0px 15px;
  346. margin-left: 5px;
  347. cursor: pointer;
  348. vertical-align: middle;
  349. }
  350. .subbutton{
  351. position: fixed;
  352. z-index: 100;
  353. left: 10%;
  354. width: 80%;
  355. bottom: 0px;
  356. height: 40px;
  357. line-height: 40px;
  358. border-radius: 10px;
  359. background-color: #3388ff;
  360. color: #fff;
  361. text-align: center;
  362. }
  363. </style>