list.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. <template>
  2. <view class="live-wx-list">
  3. <scroll-view scroll-y="true" class="scroll-Y" :style="'height:' + scrollviewHigh + 'px;'" lower-threshold="50">
  4. <view class="list d-s-c f-w">
  5. <view class="item" v-for="(item, index) in listData" :key="index" @click="gotoLive(item)">
  6. <view class="pic pr">
  7. <text class="state" :class="{bg101:item.live_status==101,bg102:item.live_status==102,bg103:item.live_status==103}" v-if="item.live_status==101||item.live_status==102||item.live_status==103">
  8. {{ convertStatus(item.live_status) }}
  9. </text>
  10. <image :src="item.cover_img" mode="aspectFit"></image>
  11. </view>
  12. <view class="p-20-0 text-ellipsis f28">{{ item.name }}</view>
  13. </view>
  14. </view>
  15. <!-- 没有记录 -->
  16. <view>
  17. <view class="d-c-c p30" v-if="listData.length == 0 && !loading">
  18. <text class="iconfont icon-wushuju"></text>
  19. <text class="cont">亲,暂无相关记录哦</text>
  20. </view>
  21. <uni-load-more v-else :loadingType="loadingType"></uni-load-more>
  22. </view>
  23. </scroll-view>
  24. </view>
  25. </template>
  26. <script>
  27. import uniLoadMore from '@/components/uni-load-more.vue';
  28. export default {
  29. components: {
  30. uniLoadMore
  31. },
  32. data() {
  33. return {
  34. /*手机高度*/
  35. phoneHeight: 0,
  36. /*可滚动视图区域高度*/
  37. scrollviewHigh: 0,
  38. /*底部加载*/
  39. loading: true,
  40. /*没有更多*/
  41. no_more: false,
  42. /*列表*/
  43. listData: [],
  44. /*一页多少条*/
  45. list_rows: 10,
  46. /*当前第几页*/
  47. last_page: 0
  48. };
  49. },
  50. computed: {
  51. /*加载中状态*/
  52. loadingType() {
  53. if (this.loading) {
  54. return 1;
  55. } else {
  56. if (this.listData.length != 0 && this.no_more) {
  57. return 2;
  58. } else {
  59. return 0;
  60. }
  61. }
  62. }
  63. },
  64. mounted() {
  65. this.init();
  66. this.getLive();
  67. },
  68. methods: {
  69. /*初始化*/
  70. init() {
  71. let _this = this;
  72. uni.getSystemInfo({
  73. success(res) {
  74. _this.phoneHeight = res.windowHeight;
  75. _this.scrollviewHigh = _this.phoneHeight;
  76. // 计算组件的高度
  77. /* let view = uni.createSelectorQuery().select('.top-box');
  78. view.boundingClientRect(data => {
  79. let h = _this.phoneHeight - data.height;
  80. _this.scrollviewHigh = h;
  81. }).exec(); */
  82. }
  83. });
  84. },
  85. convertStatus(num) {
  86. let str = '';
  87. switch (num) {
  88. case 101:
  89. str = '直播中';
  90. break;
  91. case 102:
  92. str = '未开始';
  93. break;
  94. case 103:
  95. str = '已结束';
  96. break;
  97. case 104:
  98. str = '禁播';
  99. break;
  100. case 105:
  101. str = '暂停';
  102. break;
  103. case 106:
  104. str = '异常';
  105. break;
  106. case 107:
  107. str = '已过期';
  108. break;
  109. }
  110. return str;
  111. },
  112. /*获取商品*/
  113. getLive() {
  114. let self = this;
  115. uni.showLoading({
  116. title: '加载中'
  117. });
  118. let page = self.page;
  119. let list_rows = self.list_rows;
  120. self.loading = true;
  121. self._get(
  122. 'plus.live.wx/lists',
  123. {
  124. page: page || 1,
  125. list_rows: list_rows
  126. },
  127. function(res) {
  128. self.listData = self.listData.concat(res.data.list.data);
  129. self.last_page = res.data.list.last_page;
  130. if (res.data.list.last_page <= 1) {
  131. self.no_more = true;
  132. }
  133. self.loading = false;
  134. }
  135. );
  136. },
  137. /*可滚动视图区域到底触发*/
  138. scrolltolowerFunc() {
  139. let self = this;
  140. self.bottomRefresh = true;
  141. self.page++;
  142. self.loading = true;
  143. if (self.page > self.last_page) {
  144. self.loading = false;
  145. self.no_more = true;
  146. return;
  147. }
  148. self.getData();
  149. },
  150. /*跳转详情页*/
  151. gotoLive(item) {
  152. let roomId = item.roomid;
  153. let customParams = {
  154. path: 'pages/index/index'
  155. };
  156. wx.navigateTo({
  157. url: `plugin-private://wx2b03c6e691cd7370/pages/live-player-plugin?room_id=${roomId}&custom_params=${encodeURIComponent(JSON.stringify(customParams))}`
  158. });
  159. },
  160. /*分享*/
  161. onShareAppMessage() {
  162. let self = this;
  163. // 构建页面参数
  164. let params = self.getShareUrlParams();
  165. return {
  166. title: '直播列表',
  167. path: '/pages/plus/live/wx?' + params
  168. };
  169. },
  170. }
  171. };
  172. </script>
  173. <style>
  174. .live-wx-list .list {
  175. padding: 20rpx;
  176. background: #ffffff;
  177. }
  178. .live-wx-list .list .item {
  179. width: 345rpx;
  180. margin-right: 20rpx;
  181. }
  182. .live-wx-list .list .item:nth-child(2n + 0) {
  183. margin-right: 0;
  184. }
  185. .live-wx-list .list .item .pic {
  186. width: 340rpx;
  187. height: 340rpx;
  188. }
  189. .live-wx-list .list .item .pic .state{
  190. position: absolute;
  191. top: 20rpx;
  192. left: 20rpx;
  193. padding: 4rpx 8rpx;
  194. background: red;
  195. color: #FFFFFF;
  196. border-radius: 8rpx;
  197. }
  198. .live-wx-list .list .item .pic .state.bg101{
  199. background: red;
  200. }
  201. .live-wx-list .list .item .pic .state.bg102{
  202. background: #ffb100;
  203. }
  204. .live-wx-list .list .item .pic .state.bg103{
  205. background: #333333;
  206. }
  207. .live-wx-list .list .item image {
  208. width: 340rpx;
  209. height: 340rpx;
  210. border-radius: 8rpx;
  211. }
  212. </style>