FriendList.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. <template><page-meta :root-font-size="fontSize+'px'"></page-meta>
  2. <member-base :show="false"><view style="position: absolute;top:0;right:0;left:0;bottom:0" class="scroll-view-wrapper div container member-friend-list">
  3. <view class="div common-header-wrap">
  4. <view class="status-holder"></view>
  5. <view :style="'height:'+navHeight+'px'"></view>
  6. <view class="common-header-holder"></view>
  7. <view class="common-header-fixed">
  8. <title-header />
  9. <uni-nav-bar title="好友列表" class="common-header" left-icon="back" @clickLeft="goBack()">
  10. </uni-nav-bar>
  11. </view>
  12. </view>
  13. <view class="scroll-view div" style="position:relative">
  14. <scroll-view style="position: absolute;top:0;right:0;left:0;bottom:0" class="div" @scrolltolower="loadMore" scroll-y="true">
  15. <uni-swipe-action class="div" v-if="friend_list">
  16. <uni-swipe-action-item class="goods-item" v-for="(item, index) in friend_list" v-bind:key="item.u_id" :right-options="rightOptions" @click="rightBottom($event,item.u_id)">
  17. <view class="div" @click="goChat(item.u_id,item.u_name)">
  18. <view class="div p-img">
  19. <image mode="aspectFit" class="img collection-img" v-bind:src="item.avatar"/>
  20. </view>
  21. <view class="div flex-right">
  22. <text class="span title ml-10">{{ item.u_name }}</text>
  23. </view>
  24. </view>
  25. </uni-swipe-action-item>
  26. </uni-swipe-action>
  27. <empty-record v-if="friend_list && friend_list.length===0"></empty-record>
  28. </scroll-view>
  29. </view>
  30. <view class='common-add-btn-wrapper'><view class="div common-btn common-add-btn" @click="search">添加好友</view></view>
  31. <uni-popup background-color="#fff" ref="searchVisible" type="right" >
  32. <view :style="'width:'+screenWidth+'px'" class="scroll-view-wrapper common-popup-wrapper">
  33. <view class="div common-header-wrap">
  34. <view :style="'height:'+navHeight+'px'"></view>
  35. <view class="common-header-holder"></view>
  36. <view class="common-header-fixed">
  37. <title-header />
  38. <uni-nav-bar title="添加好友" class="common-header" left-icon="back" @clickLeft="hidePopup('searchVisible')">
  39. </uni-nav-bar>
  40. </view>
  41. </view>
  42. <view class="div common-popup-content">
  43. <scroll-view style="position: absolute;top:0;right:0;left:0;bottom:0" class="scroll-view div" @scrolltolower="loadMore2" scroll-y="true">
  44. <view class="div" v-if="friend_list2">
  45. <view class="div goods-item mt-5" v-for="(item, index) in friend_list2" v-bind:key="item.u_id">
  46. <view class="div">
  47. <view class="div p-img">
  48. <image mode="aspectFit" class="img collection-img" v-bind:src="item.avatar"/>
  49. </view>
  50. <view class="div flex-right">
  51. <text class="span title ml-10">{{ item.u_name }}</text>
  52. </view>
  53. <view class="div common-btn ds-button-small button" @click="rightBottom2(item.u_id)">添加</view>
  54. </view>
  55. </view>
  56. </view>
  57. <empty-record v-if="friend_list2 && friend_list2.length===0"></empty-record>
  58. </scroll-view>
  59. </view>
  60. </view>
  61. </uni-popup>
  62. </view>
  63. <uni-popup background-color="#fff" ref="confirm" type="dialog">
  64. <uni-popup-dialog :mode="dialog.mode" :title="dialog.title" :content="dialog.content" :placeholder="dialog.content" @confirm="confirmDialog" @close="closeDialog"></uni-popup-dialog>
  65. </uni-popup>
  66. </member-base>
  67. </template>
  68. <script>
  69. import {getFontSize} from '@/util/common'
  70. import TitleHeader from '../../TitleHeader'
  71. import { urlencode } from '@/util/common'
  72. import MemberBase from '../MemberBase'
  73. import EmptyRecord from '../../EmptyRecord'
  74. import { mapState, mapActions } from 'vuex'
  75. import { getFriendList, delFriend, searchFriend, addFriend } from '../../../api/memberFriend'
  76. export default {
  77. data(){
  78. return {
  79. navHeight: 0,
  80. rightOptions:[{text:'删除',style:{backgroundColor:'#dd524d'}}],
  81. dialog:{},
  82. screenWidth:0,
  83. keyword: '',
  84. friend_list2: false,
  85. friend_list: false,
  86. params: { 'page': 0, 'per_page': 10 },
  87. loading: false, // 是否加载更多
  88. isMore: true, // 是否有更多
  89. params2: { 'page': 0, 'per_page': 10 },
  90. loading2: false, // 是否加载更多
  91. isMore2: true // 是否有更多
  92. }
  93. },
  94. components:{
  95. TitleHeader,
  96. MemberBase,
  97. EmptyRecord: EmptyRecord
  98. },
  99. created () {
  100. this.fetchConfig({}).then(
  101. response => {
  102. },
  103. error => {
  104. uni.showToast({icon:'none',title: error.message})
  105. }
  106. )
  107. this.loadMore()
  108. this.loadMore2()
  109. },
  110. computed:{
  111. fontSize(){
  112. return getFontSize()
  113. },
  114. ...mapState({
  115. config: state => state.config.config
  116. })
  117. },
  118. watch: {
  119. },
  120. mounted(){
  121. // #ifdef MP-WEIXIN
  122. this.navHeight = uni.getMenuButtonBoundingClientRect().top
  123. // #endif
  124. this.screenWidth=uni.getSystemInfoSync().screenWidth
  125. },
  126. methods:{
  127. closeDialog(){
  128. },
  129. confirmDialog(value){
  130. switch(this.dialog.condition){
  131. case 1:
  132. this.keyword = value
  133. this.reload2()
  134. this.showPopup('searchVisible')
  135. break
  136. case 2:
  137. this.delFriend(this.dialog.data)
  138. }
  139. },
  140. showPopup(id){
  141. this.$refs[id].open()
  142. },
  143. hidePopup(id){
  144. this.$refs[id].close()
  145. },
  146. goBack(){uni.navigateBack({delta:1})},
  147. ...mapActions({
  148. fetchConfig: 'fetchConfig'
  149. }),
  150. goChat (user_id,user_name) {
  151. if (this.config.instant_message_open !== '1' || !this.config.instant_message_gateway_url) {
  152. uni.showToast({icon:'none',title: '未开启即时聊天'})
  153. } else {
  154. uni.navigateTo({ url: '/pages/member/chat/ChatInfo'+'?'+urlencode( { t_id: user_id,t_name:user_name } )})
  155. }
  156. },
  157. search () {
  158. this.dialog={condition:1,mode:'input',content:'请输入用户名'}
  159. this.$refs.confirm.open()
  160. },
  161. rightBottom (e,userId) {
  162. this.dialog={condition:2,title:'确认删除',content:'是否要删除该好友?',data:userId}
  163. this.$refs.confirm.open()
  164. },
  165. rightBottom2 (userId) {
  166. addFriend(userId).then(res => {
  167. uni.showToast({icon:'none',title: res.message})
  168. this.reload()
  169. this.hidePopup('searchVisible')
  170. }).catch(function (error) {
  171. uni.showToast({icon:'none',title: error.message})
  172. })
  173. },
  174. delFriend (userId) {
  175. delFriend(userId).then(res => {
  176. this.reload()
  177. }).catch(function (error) {
  178. uni.showToast({icon:'none',title: error.message})
  179. })
  180. },
  181. loadMore () {
  182. this.loading = true
  183. this.params.page = ++this.params.page
  184. if (this.isMore) {
  185. this.loading = false
  186. this.getFriendList(true)
  187. }
  188. },
  189. getFriendList () {
  190. uni.showLoading({ title: '加载中' })
  191. getFriendList(this.params).then(res => {
  192. uni.hideLoading()
  193. if (res.result.hasmore) {
  194. this.isMore = true
  195. } else {
  196. this.isMore = false
  197. }
  198. let temp = res.result.friend_list
  199. if (temp) {
  200. if (!this.friend_list) {
  201. this.friend_list = temp
  202. } else {
  203. this.friend_list.concat(temp)
  204. }
  205. }
  206. }).catch(function (error) {
  207. uni.hideLoading()
  208. uni.showToast({icon:'none',title: error.message})
  209. })
  210. },
  211. reload () {
  212. this.params = { 'page': 0, 'per_page': 10 }
  213. this.friend_list = false
  214. this.loading = false
  215. this.isMore = true
  216. this.loadMore()
  217. },
  218. reload2 () {
  219. this.params2 = { 'page': 0, 'per_page': 10 }
  220. this.friend_list2 = false
  221. this.loading2 = false
  222. this.isMore2 = true
  223. this.loadMore2()
  224. },
  225. loadMore2 () {
  226. this.loading2 = true
  227. this.params2.page = ++this.params2.page
  228. if (this.isMore2) {
  229. this.loading2 = false
  230. this.getFriendList2(true)
  231. }
  232. },
  233. getFriendList2 () {
  234. uni.showLoading({ title: '加载中' })
  235. searchFriend(this.params2, this.keyword).then(res => {
  236. uni.hideLoading()
  237. if (res.result.hasmore) {
  238. this.isMore2 = true
  239. } else {
  240. this.isMore2 = false
  241. }
  242. let temp = res.result.member_list
  243. if (temp) {
  244. if (!this.friend_list2) {
  245. this.friend_list2 = temp
  246. } else {
  247. this.friend_list2 = this.friend_list2.concat(temp)
  248. }
  249. }
  250. }).catch(function (error) {
  251. uni.hideLoading()
  252. uni.showToast({icon:'none',title: error.message})
  253. })
  254. }
  255. }
  256. }
  257. </script>
  258. <style lang="scss" scoped>
  259. .scroll-view-wrapper{display: flex;flex-direction: column;}
  260. .scroll-view{flex:1}
  261. .common-header{
  262. .btn{background: #000;color: #fff;box-shadow: 0px 2px 4px #d2d2d2;}
  263. }
  264. .goods-item{height:3rem;width:100%;border-bottom: 3px solid #f5f5f5;}
  265. .goods-item .p-img{float:left;padding:0.25rem 0;margin-left:0.5rem;}
  266. .goods-item .p-img .img{width:2.5rem;height:2.5rem;border-radius:50%}
  267. .flex-right {float:left;}
  268. .flex-right .span{line-height:3rem;display:block;float:left;font-size:$subFontSize;}
  269. .button{float:right;margin-right:.5rem;margin-top:.7rem;display:flex;align-items:center;justify-content:center;}
  270. </style>
  271. <!--Cell Swipe样式覆盖 -->
  272. <style lang="scss">
  273. .member-friend-list{
  274. .goods-item .mint-cell-swipe-button {
  275. width: 4.5rem;
  276. font-size:$subFontSize;
  277. display: flex !important;
  278. justify-content: center;
  279. align-items: center;
  280. box-sizing: border-box;
  281. }
  282. .goods-item .mint-cell-wrapper {
  283. padding: 0;
  284. }
  285. .goods-item .mint-cell-wrapper .mint-cell-value {
  286. width: 100%;
  287. border-bottom: 1px solid rgba(232, 234, 237, 1);
  288. }
  289. }
  290. </style>