index.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. <template>
  2. <view class="content">
  3. <view class="one">
  4. <input type="text" v-model="searchInfo.title" @blur="toInput" placeholder="请输入视频名称">
  5. </view>
  6. <view class="two">
  7. <scroll-view scroll-y="true" class="scroll-view" @scrolltolower="toPage" @scroll="toScroll">
  8. <view class="list-scroll-view">
  9. <view class="two_1">
  10. <view class="list" v-for="(item,index) in list" :key="index">
  11. <image class="image" :src="item.img_url&&item.img_url.length>0?item.img_url[0].url:''"
  12. mode="">
  13. </image>
  14. <view class="name textOver">
  15. {{item.title}}
  16. </view>
  17. <view class="other">
  18. <view class="other_1">
  19. <uni-icons type="eye" color="var(--rgbfff)" size="12"></uni-icons>
  20. {{item.view_num}}
  21. </view>
  22. <view class="other_2">
  23. {{item.time_num}}
  24. </view>
  25. </view>
  26. </view>
  27. </view>
  28. </view>
  29. </scroll-view>
  30. </view>
  31. </view>
  32. </template>
  33. <script>
  34. export default {
  35. data() {
  36. return {
  37. searchInfo: {},
  38. list: [],
  39. total: 0,
  40. page: 0,
  41. skip: 0,
  42. limit: 10,
  43. // 数据是否触底
  44. is_bottom: false,
  45. scrollTop: 0
  46. }
  47. },
  48. onLoad(options) {
  49. const that = this;
  50. that.$set(that, `searchInfo`, options);
  51. that.searchOther();
  52. that.search();
  53. },
  54. onHide() {
  55. const that = this;
  56. // that.clearPage()
  57. },
  58. onPullDownRefresh: async function() {
  59. const that = this;
  60. that.clearPage();
  61. await that.search();
  62. uni.stopPullDownRefresh();
  63. },
  64. methods: {
  65. async search() {
  66. const that = this;
  67. let info = {
  68. skip: that.skip,
  69. limit: that.limit,
  70. }
  71. let res = await that.$api('videos', 'GET', {
  72. ...info,
  73. ...that.searchInfo,
  74. })
  75. if (res.errcode == '0') {
  76. let list = [...that.list, ...res.data]
  77. that.$set(that, `list`, list);
  78. that.$set(that, `total`, res.total);
  79. }
  80. },
  81. async searchOther() {
  82. const that = this;
  83. if (that.searchInfo.is_hot) {
  84. uni.setNavigationBarTitle({
  85. title: '热播'
  86. });
  87. } else {
  88. let res;
  89. if (that.searchInfo.firm_id) {
  90. res = await that.$api(`scenedata/${that.searchInfo.firm_id}`)
  91. } else if (that.searchInfo.type_id) {
  92. res = await that.$api(`scenedata/${that.searchInfo.type_id}`)
  93. } else if (that.searchInfo.place_id) {
  94. res = await that.$api(`scenedata/${that.searchInfo.place_id}`)
  95. } else if (that.searchInfo.year) {
  96. res = await that.$api(`scenedata/${that.searchInfo.year}`)
  97. } else if (that.searchInfo.head_actor) {
  98. res = await that.$api(`scenedata/${that.searchInfo.head_actor}`)
  99. }
  100. if (res.errcode == '0') {
  101. uni.setNavigationBarTitle({
  102. title: res.data.title
  103. });
  104. }
  105. }
  106. },
  107. toInput(e) {
  108. const that = this;
  109. let title = e.detail.value;
  110. if (title) that.$set(that.searchInfo, `title`, title);
  111. else delete that.searchInfo.title;
  112. that.clearPage();
  113. that.search()
  114. },
  115. toPage() {
  116. const that = this;
  117. let list = that.list;
  118. let limit = that.limit;
  119. if (that.total > list.length) {
  120. uni.showLoading({
  121. title: '加载中',
  122. mask: true
  123. })
  124. let page = that.page + 1;
  125. that.$set(that, `page`, page)
  126. let skip = page * limit;
  127. that.$set(that, `skip`, skip)
  128. that.search();
  129. uni.hideLoading();
  130. } else that.$set(that, `is_bottom`, true)
  131. },
  132. toScroll(e) {
  133. const that = this;
  134. let up = that.scrollTop;
  135. that.$set(that, `scrollTop`, e.detail.scrollTop);
  136. let num = Math.sign(up - e.detail.scrollTop);
  137. if (num == 1) that.$set(that, `is_bottom`, false);
  138. },
  139. // 清空列表
  140. clearPage() {
  141. const that = this;
  142. that.$set(that, `list`, [])
  143. that.$set(that, `skip`, 0)
  144. that.$set(that, `limit`, 10)
  145. that.$set(that, `page`, 0)
  146. if (!that.searchInfo.title) delete that.searchInfo.title;
  147. },
  148. },
  149. }
  150. </script>
  151. <style lang="scss">
  152. .content {
  153. background-color: var(--rgb111);
  154. .one {
  155. padding: 2vw;
  156. input {
  157. border: 1px solid var(--rgbf1f);
  158. border-radius: 5px;
  159. padding: 5px;
  160. font-size: 14px;
  161. color: var(--rgbfff);
  162. }
  163. }
  164. .two {
  165. flex-grow: 1;
  166. position: relative;
  167. .two_1 {
  168. display: flex;
  169. flex-wrap: wrap;
  170. .list {
  171. width: 48%;
  172. margin: 0 10px 10px 0;
  173. .image {
  174. width: 100%;
  175. height: 100px;
  176. overflow: hidden;
  177. border-radius: 5px;
  178. box-shadow: 0 0 5px var(--rgbf1f);
  179. margin: 0 0 5px 0;
  180. }
  181. .name {
  182. font-size: 14px;
  183. color: var(--rgbfff);
  184. margin: 0 0 5px 0;
  185. }
  186. .other {
  187. display: flex;
  188. color: var(--rgbfff);
  189. font-size: 12px;
  190. justify-content: space-between;
  191. }
  192. }
  193. .list:nth-child(2n) {
  194. margin: 0 0 10px 0;
  195. }
  196. }
  197. }
  198. }
  199. .scroll-view {
  200. position: absolute;
  201. top: 0;
  202. left: 0;
  203. right: 0;
  204. bottom: 0;
  205. .list-scroll-view {
  206. display: flex;
  207. flex-direction: column;
  208. padding: 0 2vw;
  209. }
  210. }
  211. .is_bottom {
  212. text-align: center;
  213. text {
  214. padding: 2vw 0;
  215. display: inline-block;
  216. color: #858585;
  217. font-size: 14px;
  218. }
  219. }
  220. </style>