search.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. <template>
  2. <view>
  3. <!-- 导航 -->
  4. <view class="nav bg-white">
  5. <block v-for="(item, index) in nav_status_list" :key="index">
  6. <view :class="'item fl tc cr-gray ' + (nav_status_index == index ? 'cr-main' : '')" :data-index="index" @tap="nav_event">{{item.name}}</view>
  7. </block>
  8. </view>
  9. <!-- 列表 -->
  10. <scroll-view :scroll-y="true" class="scroll-box" @scrolltolower="scroll_lower" lower-threshold="60">
  11. <view v-if="data_list.length > 0" class="data-list padding-horizontal-main padding-top-main">
  12. <view v-for="(item, index) in data_list" :key="index" class="item padding-main border-radius-main oh pr bg-white spacing-mb">
  13. <navigator :url="'/pages/plugins/weixinliveplayer/detail/detail?id=' + item.id" hover-class="none">
  14. <image class="fl radius" :src="item.share_img" mode="aspectFit"></image>
  15. <view class="base fl">
  16. <view class="single-text text-size">{{item.name}}</view>
  17. <view class="margin-top-xl oh">
  18. <view class="time-title fl cr-white radius tc text-size-sm padding-sm margin-right-sm">开播时间</view>
  19. <view class="fl cr-green">{{item.start_time}}</view>
  20. <view class="fl cr-red">{{item.end_time}}</view>
  21. </view>
  22. <view :class="'status pa status-' + item.status">{{item.status_name}}</view>
  23. </view>
  24. </navigator>
  25. </view>
  26. </view>
  27. <view v-else>
  28. <!-- 提示信息 -->
  29. <component-no-data :propStatus="data_list_loding_status"></component-no-data>
  30. </view>
  31. <!-- 结尾 -->
  32. <component-bottom-line :propStatus="data_bottom_line_status"></component-bottom-line>
  33. </scroll-view>
  34. </view>
  35. </template>
  36. <script>
  37. const app = getApp();
  38. import componentNoData from "../../../../components/no-data/no-data";
  39. import componentBottomLine from "../../../../components/bottom-line/bottom-line";
  40. export default {
  41. data() {
  42. return {
  43. data_list_loding_status: 1,
  44. data_bottom_line_status: false,
  45. params: null,
  46. load_status: 0,
  47. data_list: [],
  48. data_base: null,
  49. data_total: 0,
  50. data_page_total: 0,
  51. data_page: 1,
  52. nav_status_list: [
  53. { name: "全部", value: "-1" },
  54. { name: "未开始", value: "0" },
  55. { name: "直播中", value: "1" },
  56. { name: "暂停中", value: "2" },
  57. { name: "已结束", value: "3" },
  58. ],
  59. nav_status_index: 0,
  60. // 自定义分享信息
  61. share_info: {}
  62. };
  63. },
  64. components: {
  65. componentNoData,
  66. componentBottomLine
  67. },
  68. props: {},
  69. onLoad(params) {
  70. // 是否指定状态
  71. var nav_status_index = 0;
  72. if ((params.status || null) != null) {
  73. for (var i in this.nav_status_list) {
  74. if (this.nav_status_list[i]['value'] == params.status) {
  75. nav_status_index = i;
  76. break;
  77. }
  78. }
  79. }
  80. this.setData({
  81. params: params,
  82. nav_status_index: nav_status_index
  83. });
  84. this.init();
  85. },
  86. onShow() {},
  87. // 下拉刷新
  88. onPullDownRefresh() {
  89. this.setData({
  90. data_page: 1
  91. });
  92. this.get_data_list(1);
  93. },
  94. methods: {
  95. init() {
  96. // 获取数据
  97. this.get_data_list();
  98. },
  99. // 获取数据
  100. get_data_list(is_mandatory) {
  101. // 分页是否还有数据
  102. if ((is_mandatory || 0) == 0) {
  103. if (this.data_bottom_line_status == true) {
  104. uni.stopPullDownRefresh();
  105. return false;
  106. }
  107. }
  108. // 加载loding
  109. uni.showLoading({
  110. title: '加载中...'
  111. });
  112. this.setData({
  113. data_list_loding_status: 1
  114. });
  115. // 参数
  116. var status = (this.nav_status_list[this.nav_status_index] || null) == null ? -1 : this.nav_status_list[this.nav_status_index]['value'];
  117. // 获取数据
  118. uni.request({
  119. url: app.globalData.get_request_url("index", "search", "weixinliveplayer"),
  120. method: 'POST',
  121. data: {
  122. page: this.data_page,
  123. status: status,
  124. is_more: 1
  125. },
  126. dataType: 'json',
  127. success: res => {
  128. uni.hideLoading();
  129. uni.stopPullDownRefresh();
  130. if (res.data.code == 0) {
  131. if (res.data.data.data.length > 0) {
  132. if (this.data_page <= 1) {
  133. var temp_data_list = res.data.data.data;
  134. } else {
  135. var temp_data_list = this.data_list || [];
  136. var temp_data = res.data.data.data;
  137. for (var i in temp_data) {
  138. temp_data_list.push(temp_data[i]);
  139. }
  140. }
  141. this.setData({
  142. data_base: res.data.data.base || null,
  143. data_list: temp_data_list,
  144. data_total: res.data.data.total,
  145. data_page_total: res.data.data.page_total,
  146. data_list_loding_status: 3,
  147. data_page: this.data_page + 1
  148. });
  149. // 是否还有数据
  150. this.setData({
  151. data_bottom_line_status: (this.data_page > 1 && this.data_page > this.data_page_total)
  152. });
  153. // 首次设置首次加载状态
  154. if(this.load_status == 0) {
  155. // 基础自定义分享
  156. this.setData({
  157. load_status: 1,
  158. share_info: {
  159. title: this.data_base.seo_title || this.data_base.application_name,
  160. desc: this.data_base.seo_desc,
  161. path: '/pages/plugins/weixinliveplayer/search/search',
  162. query: 'status='+this.nav_status_index
  163. }
  164. });
  165. // 分享菜单处理
  166. app.globalData.page_share_handle(this.share_info);
  167. }
  168. } else {
  169. this.setData({
  170. data_list_loding_status: 0,
  171. data_list: [],
  172. data_bottom_line_status: false
  173. });
  174. }
  175. } else {
  176. this.setData({
  177. data_list_loding_status: 0
  178. });
  179. app.globalData.showToast(res.data.msg);
  180. }
  181. },
  182. fail: () => {
  183. uni.hideLoading();
  184. uni.stopPullDownRefresh();
  185. this.setData({
  186. data_list_loding_status: 2
  187. });
  188. app.globalData.showToast('服务器请求出错');
  189. }
  190. });
  191. },
  192. // 滚动加载
  193. scroll_lower(e) {
  194. this.get_data_list();
  195. },
  196. // 导航事件
  197. nav_event(e) {
  198. this.setData({
  199. nav_status_index: e.currentTarget.dataset.index || 0,
  200. data_page: 1
  201. });
  202. this.get_data_list(1);
  203. }
  204. }
  205. };
  206. </script>
  207. <style>
  208. @import './search.css';
  209. </style>