contact.vue 15 KB

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