follow.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <template>
  2. <view class="wanlfind-follow-container">
  3. <view class="edgeInsetTop"></view>
  4. <wanl-empty src="find_default3x" :text="$t('follow.empty')" v-if="dataList.length === 0 && status !== 'loading'"/>
  5. <view v-if="dataList.length > 0" class="wanlfind-follow-container__list">
  6. <view class="item padding-bj margin-bj bg-white radius-bock" v-for="(item, index) in dataList"
  7. :key="item.id" @click="handleUser(item.user_no)">
  8. <view class="cu-avatar margin-right-bj round"
  9. :style="{backgroundImage: `url(${$appKit.oss(item.shop.avatar, 88, 88)})`}"></view>
  10. <view class="subject">
  11. <view class="info">
  12. <view v-if="item.shop.isself == 1">
  13. <view class="cu-tag sm wanl-bg-redorange radius margin-right-xs">{{ $t('search.shopTag') }}</view>
  14. {{item.shop.shopname}}
  15. </view>
  16. <view class="text-cut-2 margin-bottom-xs" v-else>
  17. <view class="cu-tag sm bg-gray radius margin-right-xs" v-if="item.shop.state == 0">{{ $t('mall.product.personal') }}</view>
  18. <view class="cu-tag sm wanl-bg-blue radius margin-right-xs" v-if="item.shop.state == 1">{{ $t('mall.product.enterprise') }}</view>
  19. <view class="cu-tag sm wanl-bg-orange radius margin-right-xs" v-if="item.shop.state == 2">{{ $t('mall.product.flagship') }}</view>
  20. {{item.shop.shopname}}
  21. </view>
  22. <view class="wanl-gray-light text-sm text-cut">
  23. <text>{{item.shop.city}}</text>
  24. </view>
  25. </view>
  26. <view class="menu">
  27. <button class="cu-btn wlIcon margin-right-sm" @click.stop="onShop(item.shop.id)">
  28. <text class="wlIcon-31dianpu"></text>
  29. </button>
  30. <button v-if="item.isFollow === 0" class="cu-btn wlIcon" @click.stop="handleFollow(index)">
  31. <text class="wlIcon-tianjia"></text>
  32. </button>
  33. <button v-else class="cu-btn radius-bock text-sm" @click.stop="handleFollow(index)">
  34. <text class="wlIcon-31guanbi margin-right-xs text-bold"></text>{{ $t('mall.shop.unfollow') }}
  35. </button>
  36. </view>
  37. </view>
  38. </view>
  39. </view>
  40. <view class="edgeInsetBottom"></view>
  41. <!-- 加载更多 -->
  42. <uni-load-more :status="status" :content-text="contentText" />
  43. </view>
  44. </template>
  45. <script>
  46. import { pullFollowShopList, postFollowShop } from '@/features/mall/mall-gateway'
  47. export default {
  48. data() {
  49. return {
  50. dataList: [],
  51. reload: false,
  52. current_page: 1,
  53. last_page: 1,
  54. status: 'loading',
  55. contentText: {
  56. contentdown: '',
  57. contentrefresh: '',
  58. contentnomore: ''
  59. }
  60. }
  61. },
  62. onLoad() {
  63. this.contentText.contentrefresh = this.$t('follow.loading')
  64. this.loadData()
  65. },
  66. onPullDownRefresh() {
  67. this.current_page = 1
  68. this.reload = true
  69. this.loadData()
  70. },
  71. onReachBottom() {
  72. if (this.current_page >= this.last_page) {
  73. this.status = 'noMore'
  74. } else {
  75. this.reload = false
  76. this.current_page = this.current_page + 1
  77. this.status = 'loading'
  78. this.loadData()
  79. }
  80. },
  81. methods: {
  82. async loadData() {
  83. try {
  84. const res = await pullFollowShopList({ page: this.current_page })
  85. uni.stopPullDownRefresh()
  86. this.dataList = this.reload ? res.data : this.dataList.concat(res.data)
  87. this.current_page = res.current_page
  88. this.last_page = res.last_page
  89. this.status = res.total == 0 ? 'noMore' : 'more'
  90. } catch (e) {
  91. uni.stopPullDownRefresh()
  92. console.error('[follow] load failed:', e)
  93. }
  94. },
  95. async handleFollow(index) {
  96. let data = this.dataList[index]
  97. try {
  98. const result = await postFollowShop({ id: data.user_no, type: 'follow' })
  99. let concern = this.$store.state.statistics.dynamic.concern
  100. if (result.data === 0) {
  101. concern -= 1
  102. } else {
  103. concern += 1
  104. }
  105. this.$store.commit('statistics/dynamic', { concern })
  106. data.isFollow = result.data
  107. } catch (e) {
  108. console.error('[follow] follow action failed:', e)
  109. }
  110. },
  111. handleUser(user_no) {
  112. uni.navigateTo({ url: `/pages/apps/find/user?id=${user_no}` })
  113. },
  114. onShop(shop_id) {
  115. if (shop_id) {
  116. uni.navigateTo({ url: `/pages/shop/index?id=${shop_id}` })
  117. }
  118. }
  119. }
  120. }
  121. </script>
  122. <style lang="scss">
  123. .wanlfind-follow-container {
  124. &__list {
  125. .item {
  126. display: flex;
  127. align-items: center;
  128. .cu-avatar {
  129. width: 100rpx;
  130. height: 100rpx;
  131. flex-shrink: 0;
  132. background-color: #f9f9f9;
  133. }
  134. .subject {
  135. display: flex;
  136. align-items: center;
  137. justify-content: space-between;
  138. flex: 1;
  139. .info {
  140. max-width: 250rpx;
  141. }
  142. .menu {
  143. display: flex;
  144. align-items: center;
  145. }
  146. }
  147. }
  148. }
  149. }
  150. </style>