contact.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  1. <template>
  2. <view class="page">
  3. <headerline issearch="true" :showsearch="showsearch" searchtips="请输入搜索内容" @clicksearch='clicksearch' :shownav="false" :title="navtitle" :menuitem="menuitem" :statusbarheight='statusBarHeight' :islogo="false" @tapmenu="tapmenu" rightmenu="true"></headerline>
  4. <block v-if="!showsearch">
  5. <view class="friends">
  6. <view class="avatar" @tap="href('group.list',{method:0})" >
  7. <image src="../../static/img/group_add.png" style="height: 40px;width:40px ;"></image>
  8. </view>
  9. <view class="showname" style="padding-left: 10px;" @tap="href('group.list',{method:0})">
  10. 我创建的群组
  11. </view>
  12. </view>
  13. <view class="friends" style="margin-top: 5px;" >
  14. <view class="avatar" @tap="href('group.list',{method:1})">
  15. <image src="../../static/img/mygroup.png" style="height: 40px;width:40px ;"></image>
  16. </view>
  17. <view class="showname" style="padding-left: 10px;" @tap="href('group.list',{method:1})">
  18. 我加入的群组
  19. </view>
  20. </view>
  21. <view class="friends" style="margin-top: 5px;" @tap="href('index.backlist',{})" >
  22. <view class="avatar">
  23. <image src="../../static/img/icon/backlist.png" style="height: 40px;width:40px ;"></image>
  24. </view>
  25. <view class="showname" style="padding-left: 10px;">
  26. 黑名单
  27. </view>
  28. </view>
  29. <view style="height: 8px;"></view>
  30. <view class="pinyin" v-if="kefunum>0">官方</view>
  31. <block v-if="friends.length>0">
  32. <block v-for="(item, index) in friends" :key="item.id" >
  33. <view class="friends" v-if=" item.iskefu!=0" @tap="open_detail(item)">
  34. <view class="avatar">
  35. <image :src="image_cache(item.avatar)"></image>
  36. </view>
  37. <view class="showname">
  38. {{item.nickname}} <view v-if="item.iskefu==1" class="btn_green">客服</view>
  39. <view v-if="item.iskefu==2" class="btn_blue">官方</view>
  40. <view v-if="item.iskefu==3" class="btn_green">上级</view>
  41. </view>
  42. </view>
  43. </block>
  44. <block v-for="(item1, index1) in pinyin" :key="item1" >
  45. <block v-if="ispinyin(item1)">
  46. <view class="pinyin" :id="'char_'+item1">{{item1}}</view>
  47. <block v-for="(item, index) in friends" :key="item.id" >
  48. <view class="friends" v-if="item.pinyin.substr(0,1).toUpperCase()==item1 && item.iskefu==0" @tap="open_detail(item)">
  49. <view class="avatar">
  50. <image :src="image_cache(item.avatar)"></image>
  51. </view>
  52. <view class="showname">
  53. {{item.nickname}} <view v-if="item.iskefu==1" class="btn_green">客服</view>
  54. <view v-if="item.iskefu==2" class="btn_blue">官方</view>
  55. <view v-if="item.iskefu==3" class="btn_green">上级</view>
  56. </view>
  57. </view>
  58. </block>
  59. </block>
  60. </block>
  61. <view class="nodata" >
  62. {{friends.length}}位好友
  63. </view>
  64. <view class="pinyin_right">
  65. <block v-for="(item1, index1) in pinyin" :key="index1" >
  66. <view @tap="gotochar(item1)" :class="{'active':item1==char_select}">{{item1}}</view>
  67. </block>
  68. </view>
  69. </block>
  70. <view v-else class="nodata" >您还没有添加任何好友 </view>
  71. </block>
  72. </view>
  73. </template>
  74. <script>
  75. import scode from "../../library/scode.js"
  76. import api from "../../library/index.js"
  77. import chat from "../../library/chat.js"
  78. import http from "../../library/http.js"
  79. import message from "../../library/message.js"
  80. import action from "../../library/action.js"
  81. import headerline from '../../components/header.vue'
  82. var windowHeight= uni.getSystemInfoSync().windowHeight;
  83. var statusBarHeight = uni.getSystemInfoSync().statusBarHeight ;
  84. var contenttop=statusBarHeight+45;
  85. var conentheight=windowHeight-contenttop;
  86. var lottHeight= conentheight-30;
  87. var lottTop= contenttop + 30;
  88. export default {
  89. components: {
  90. headerline,
  91. },
  92. data() {
  93. return {
  94. statusBarHeight: statusBarHeight+ 'px',
  95. contenttop:contenttop+'px',
  96. contentheight:conentheight+'px',
  97. lottHeight:lottHeight+'px',
  98. lottTop:lottTop+'px',
  99. shownav:false,
  100. navtitle:'通信录',
  101. user:uni.getStorageSync('userInfo'),
  102. showsearch:false,
  103. friends:uni.getStorageSync(uni.getStorageSync('access_token')+'_frienddata'),
  104. pinyin:[],
  105. char_select:false,
  106. };
  107. },
  108. methods:{
  109. friendlist(){
  110. this.friends = uni.getStorageSync(uni.getStorageSync('access_token')+'_frienddata')
  111. this.setfrriends_data();
  112. http.setWait(false).get('user.php?act=getMyFriend',{userid:uni.getStorageSync('access_token')}).then(res=>{
  113. //console.log(res.data.length)
  114. this.friends=res.data;
  115. // this.friends = this.friends.filter(item => {
  116. // return item.id
  117. // })
  118. uni.setStorageSync(uni.getStorageSync('access_token')+'_frienddata',res.data);
  119. this.setfrriends_data();
  120. })
  121. },
  122. setfrriends_data(){
  123. this.kefunum=0;
  124. for(var i=0;i<this.friends.length;i++){
  125. if(this.friends[i].iskefu>0) this.kefunum++;
  126. }
  127. },
  128. pinyin_init(){
  129. var py="ABCDEFGHIJKLMNOPQRSTUVWXYZ#";
  130. var pinyin=[];
  131. for(var i=0;i<py.length;i++){
  132. pinyin.push(py[i]);
  133. }
  134. this.pinyin=pinyin;
  135. },
  136. ispinyin(char){
  137. for(var i=0;i<this.friends.length;i++){
  138. var pinyin=this.friends[i]['pinyin'];
  139. if(pinyin.substr(0,1).toUpperCase()==char.toUpperCase() && this.friends[i]['iskefu']<1) return true;
  140. }
  141. return false;
  142. },
  143. gotochar(char){
  144. this.char_select=char;
  145. uni.createSelectorQuery().select('#char_' + char).boundingClientRect(data=>{//目标节点
  146.   uni.createSelectorQuery().select('.page' ).boundingClientRect((res)=>{//最外层盒子节点    
  147.     uni.pageScrollTo({       
  148.       duration: 0,//过渡时间必须为0,否则运行到手机会报错
  149.       scrollTop: data.top - res.top - 45- statusBarHeight//滚动到实际距离是元素距离顶部的距离减去最外层盒子的滚动距离(如res.top - data.top)
  150.     })
  151.   }).exec()
  152. }).exec()
  153. },
  154. href(path,opts){
  155. if(!opts || opts==undefined || opts == null) opts={};
  156. this.$jump(path,opts);
  157. },
  158. open_detail(item){
  159. this.$jump('friend.detail',{id:item.id});
  160. },
  161. clicksearch(e){
  162. this.showsearch=e;
  163. },
  164. tapmenu(num){
  165. if(this.$action.loginTips('未登录用户,无法完成此操作','/pages/game/index') ==false) return false;
  166. if(this.$action.check_userlock()==false) return false;
  167. if(num==0){
  168. if(this.user.nickname=='' || this.user.nickname==this.user.name){
  169. this.$action.profileTips('未设置昵称,不能创建群','/pages/group/create') ;
  170. return false;
  171. }
  172. else
  173. this.$jump('group.create');
  174. }
  175. else if(num==1){
  176. this.$jump('group.list',{method:0});
  177. }
  178. else if(num==2){
  179. this.$jump('group.list',{method:1});
  180. }
  181. else if(num==3){
  182. this.$jump('mine.note');
  183. }
  184. else if(num==4){
  185. return uni.scanCode({
  186. success(res) {
  187. scode.getScode(res)
  188. },
  189. fail(e) {
  190. console.log(JSON.stringify(e));
  191. console.log('扫码失败')
  192. }
  193. });
  194. }
  195. },
  196. setrightmenu(){
  197. var action=[
  198. {
  199. title: '新建群组',
  200. icon: 'plus'
  201. },
  202. {
  203. title: '创建的群',
  204. icon: 'personadd'
  205. },
  206. {
  207. title: '加入的群',
  208. icon: 'person'
  209. },
  210. // #ifdef APP-PLUS
  211. {
  212. title: '通知设置',
  213. icon: 'gear'
  214. },
  215. {
  216. title: '扫一扫',
  217. icon: 'scan'
  218. },
  219. // #endif
  220. ]
  221. this.menuitem=action;
  222. },
  223. },
  224. onShow() {
  225. uni.hideKeyboard();
  226. var userid=parseInt(uni.getStorageSync('access_token'));
  227. if(userid>0) {
  228. this.friendlist();
  229. }else{
  230. uni.setStorageSync('gourl','/pages/contact/index');
  231. this.$jump('login.index');
  232. }
  233. },
  234. onLoad() {
  235. this.pinyin_init();
  236. this.setrightmenu();
  237. uni.$on('toChat',message=>{
  238. //console.log('index')
  239. this.$action.toChat(message);
  240. })
  241. }
  242. }
  243. </script>
  244. <style lang="scss">
  245. .btn_yellow{
  246. background-color: yellow;
  247. color: #000;
  248. font-size: 12px;
  249. display: inline-block;
  250. height:18px;
  251. line-height: 18px;
  252. padding: 0px 5px;
  253. border-radius: 5px;
  254. text-align: center;
  255. margin: 0px 2px;
  256. }
  257. .btn_green{
  258. background-color: #0aad6c;
  259. color: #fff;font-size: 12px;
  260. display: inline-block;
  261. height: 18px;
  262. line-height: 18px;
  263. padding: 0px 5px;
  264. border-radius: 5px;
  265. text-align: center;
  266. margin: 0px 2px;
  267. }
  268. .btn_blue{
  269. background-color: #2319dc;
  270. color: #fff;font-size: 12px;
  271. display: inline-block;
  272. height: 18px;
  273. line-height: 18px;
  274. padding: 0px 5px;
  275. border-radius: 5px;
  276. text-align: center;
  277. margin: 0px 2px;
  278. }
  279. .btn_grey{
  280. background-color: #ddd;
  281. color: #000;font-size: 12px;
  282. display: inline-block;
  283. height: 18px;
  284. line-height: 18px;
  285. padding: 0px 5px;
  286. border-radius: 5px;
  287. text-align: center;
  288. margin: 0px 2px;
  289. }
  290. .nodata{
  291. height: 35px;
  292. line-height: 35px;
  293. color: #666;
  294. font-size: 12px;
  295. text-align: center;
  296. }
  297. .pinyin{
  298. font-size: 14px;
  299. height: 25px;
  300. line-height: 25px;
  301. width: calc(100% - 20px);
  302. background-color:#eee;
  303. padding:0px 10px;
  304. margin-top: 5px;
  305. }
  306. .istop{
  307. background-color: #fdfdfd;
  308. }
  309. .pinyin_right{
  310. position: fixed;
  311. right: 7px;
  312. top:100px;
  313. height: auto;
  314. width: 18px;
  315. line-height: 20px;
  316. text-align: center;
  317. font-size: 12px;
  318. color: #333;
  319. min-height: 400px;
  320. }
  321. .pinyin_right view{
  322. height: 18px;
  323. line-height: 18px;
  324. text-align: center;
  325. }
  326. .pinyin_right view.active{
  327. background-color: #3388ff;
  328. border-radius: 50%;
  329. color: #fff;
  330. }
  331. .friends{
  332. padding: 5px 0px;
  333. height: 35px;
  334. line-height: 35px;
  335. display: table;
  336. table-layout: fixed;
  337. width: calc(100% - 0px);
  338. margin-bottom: 1px;
  339. }
  340. .friends .avatar{
  341. display: table-cell;
  342. width: 60px;
  343. text-align: center;
  344. }
  345. .friends .avatar image{
  346. height: 35px;
  347. width: 35px;
  348. border-radius: 5px;;
  349. vertical-align: middle;
  350. }
  351. .friends .showname {
  352. text-align:left;
  353. display: table-cell;
  354. font-size: 16px;
  355. color: #333;
  356. line-height: 35px;;
  357. vertical-align: middle;
  358. margin: 0px 0px;
  359. padding: 0px 0px;
  360. border-bottom: 1upx #EFEFEF solid;
  361. }
  362. </style>