newfriend.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. <!-- 聊天 -->
  2. <template>
  3. <view class="page page--divider">
  4. <view class="widget">
  5. <view class="widget-inner" v-if="list.length>0">
  6. <view class="item" v-for="(item, index) in list" :key="index" >
  7. <image :src="item.avatar" class="leftImg" @tap="handleChat(item)"/>
  8. <view class="rightContent">
  9. <view class="topCont">
  10. <view class="userName" @tap="handleChat(item)">{{item.nickname||item.name||'匿名'}}
  11. <view class="mark" v-for="(item1, index1) in item.mark" :key="index1" @tap="handleChat(item)" >
  12. {{item1}}
  13. </view>
  14. </view>
  15. <view class="time">
  16. <block v-if="item.status==0">
  17. <view @tap="handleFriendApply(item,1,index)">同意</view>
  18. <view @tap="handleFriendApply(item,2,index)">拒绝</view>
  19. </block>
  20. <block v-else-if="item.status==1">
  21. <view>已同意</view>
  22. </block>
  23. <block v-else-if="item.status==2">
  24. <view>已拒绝</view>
  25. </block>
  26. </view>
  27. </view>
  28. </view>
  29. </view>
  30. </view>
  31. <view v-else class="nofriend">
  32. 目前没有好友申请
  33. </view>
  34. </view>
  35. </view>
  36. </template>
  37. <script>
  38. import api from "../../library/index.js"
  39. export default {
  40. data() {
  41. return {
  42. list: {}
  43. }
  44. },
  45. onShow() {
  46. this.getFriend()
  47. },
  48. methods: {
  49. getFriend() {
  50. let data = {
  51. userid: this.$store.state.userinfo.id,
  52. read:1
  53. }
  54. api.getFriendApply(data).then(res => {
  55. this.list = res.data
  56. })
  57. },
  58. sendmessage(item){
  59. var userid=item.userid;
  60. var mark="我们已经是好友了,很高兴认识你";
  61. // if(item.mark.length>0 && item.mark[item.mark.length-1]) mark=item.mark[item.mark.length-1];
  62. if(userid>0){
  63. let data1 = {
  64. userid:this.$store.state.userinfo.id,
  65. friend_uid:userid,
  66. type:'chat',
  67. msgtype: 'text',
  68. content: mark
  69. }
  70. console.log(data1);
  71. this.$socket.send(data1);
  72. }
  73. },
  74. handleChat(item){
  75. this.$jump('friend.detail', {id:item.userid,nickname:item.nickname,avatar:item.avatar});
  76. },
  77. handleFriendApply(item,status,index){
  78. this.list[index].status =status;
  79. uni.showLoading({
  80. title: '发送中'
  81. });
  82. var id=item.id;
  83. let data2={id:id,status:status}
  84. api.handleFriendApply(data2).then(
  85. res=>{
  86. uni.hideLoading();
  87. let data = {
  88. userid:this.$store.state.userinfo.id,
  89. type:'send_newfriendnum',
  90. }
  91. this.$socket.send(data);
  92. if(status==1){
  93. this.sendmessage(item);
  94. uni.switchTab({
  95. url:'../index/index'
  96. });
  97. }
  98. })
  99. }
  100. },
  101. }
  102. </script>
  103. <style lang="scss">
  104. .item {
  105. border-bottom: 1px solid #F0F0F0;
  106. overflow: hidden;
  107. padding: $uni-spacing-col-lg 30upx;
  108. display: flex;
  109. flex-direction: row;
  110. justify-content: flex-start;
  111. align-items: center;
  112. }
  113. .leftImg {
  114. width: 76upx;
  115. height: 76upx;
  116. margin-right: $uni-spacing-row-base;
  117. border-radius: $uni-border-radius-base;
  118. display: flex;
  119. flex-flow: wrap;
  120. justify-content: center;
  121. background-color: #eee;
  122. align-items: center;
  123. &:not(image) {
  124. padding: 1upx;
  125. }
  126. view,
  127. image {
  128. width: (76upx-2upx*4)/3;
  129. height: (76upx-2upx*4)/3;
  130. margin: 1upx;
  131. }
  132. }
  133. .rightContent {
  134. flex: 1;
  135. }
  136. .rightContent,
  137. .topCont {
  138. overflow: hidden;
  139. line-height: 1.25;
  140. }
  141. .topCont {
  142. display: flex;
  143. flex-direction: row;
  144. justify-content: space-between;
  145. align-items: center;
  146. }
  147. .userName {
  148. color: $uni-text-color;
  149. font-size: 30upx;
  150. }
  151. .userName .mark{
  152. color:#999999;
  153. font-size: 20upx;
  154. height:25upx;
  155. line-height: 25upx;
  156. text-align: left;
  157. max-height: 50upx;
  158. overflow-y: scroll;
  159. }
  160. .time {
  161. color: #999999;
  162. font-size: 22upx;
  163. view{
  164. float: left;
  165. padding: 4upx 10upx;
  166. }
  167. }
  168. .bottomCont {
  169. width: 100%;
  170. font-size: 24upx;
  171. color: #999999;
  172. display: flex;
  173. align-items: center;
  174. justify-content: space-between;
  175. }
  176. .content {
  177. overflow: hidden;
  178. text-overflow: ellipsis;
  179. white-space: nowrap;
  180. }
  181. .badge {
  182. background-color: red;
  183. color: #fff;
  184. border-radius: 16upx;
  185. line-height: 32upx;
  186. width: 32upx;
  187. height: 32upx;
  188. text-align: center;
  189. }
  190. .nofriend{
  191. font-size: 28upx;
  192. color: #999999;
  193. text-align: center;
  194. }
  195. </style>