index.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. <template>
  2. <view class="content">
  3. <view class="one">
  4. <input type="text" v-model="searchInfo.name" @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="list" v-for="(item, index) in list" :key="index">
  10. <view class="name">
  11. <text>{{ index + 1 }}.</text>
  12. <text>{{ item.name }}</text>
  13. </view>
  14. <view class="other">
  15. <view class="other_1">
  16. <text>节目类型:</text>
  17. <text>{{ getDict(item.type,'typeList') }}</text>
  18. </view>
  19. <view class="other_1">
  20. <text>视频流:</text>
  21. <text>{{ item.path||'暂无视频流' }}</text>
  22. </view>
  23. </view>
  24. <view class="btn">
  25. <button type="primary" size="mini" @tap="toPlay(item)">
  26. 播放视频
  27. </button>
  28. </view>
  29. </view>
  30. </view>
  31. </scroll-view>
  32. </view>
  33. <view class="is_bottom" v-if="is_bottom">
  34. <text>到底了,嘻嘻!</text>
  35. </view>
  36. </view>
  37. </template>
  38. <script>
  39. export default {
  40. data() {
  41. return {
  42. // 查询
  43. searchInfo: {},
  44. list: [],
  45. total: 0,
  46. page: 0,
  47. skip: 0,
  48. limit: 10,
  49. // 数据是否触底
  50. is_bottom: false,
  51. scrollTop: 0,
  52. // 节目类型
  53. typeList: this.$config.pro_type
  54. };
  55. },
  56. onLoad() {
  57. const that = this;
  58. that.search();
  59. },
  60. onPullDownRefresh: async function() {
  61. const that = this;
  62. that.clearPage();
  63. await that.search();
  64. uni.stopPullDownRefresh();
  65. },
  66. methods: {
  67. async search() {
  68. const that = this;
  69. let info = {
  70. skip: that.skip,
  71. limit: that.limit,
  72. is_use: "0"
  73. };
  74. let res = await that.$api("program", "GET", {
  75. ...info,
  76. ...that.searchInfo
  77. });
  78. if (res.errcode == '0') {
  79. let list = [...that.list, ...res.data]
  80. that.$set(that, `list`, list)
  81. that.$set(that, `total`, res.total)
  82. } else {
  83. uni.showToast({
  84. title: res.errmsg,
  85. icon: 'icon'
  86. });
  87. }
  88. },
  89. // 分页
  90. toPage() {
  91. const that = this;
  92. let list = that.list;
  93. let limit = that.limit;
  94. if (that.total > list.length) {
  95. uni.showLoading({
  96. title: '加载中',
  97. mask: true
  98. })
  99. let page = that.page + 1;
  100. that.$set(that, `page`, page)
  101. let skip = page * limit;
  102. that.$set(that, `skip`, skip)
  103. that.search();
  104. uni.hideLoading();
  105. } else that.$set(that, `is_bottom`, true)
  106. },
  107. toScroll(e) {
  108. const that = this;
  109. let up = that.scrollTop;
  110. that.$set(that, `scrollTop`, e.detail.scrollTop);
  111. let num = Math.sign(up - e.detail.scrollTop);
  112. if (num == 1) that.$set(that, `is_bottom`, false);
  113. },
  114. // 输入框
  115. toInput(e) {
  116. const that = this;
  117. if (e.detail.value) that.$set(that.searchInfo, `name`, e.detail.value);
  118. else that.$set(that, `searchInfo`, {});
  119. that.clearPage();
  120. that.search();
  121. },
  122. toPlay(e) {
  123. if (e.path) {
  124. uni.navigateTo({
  125. url: `/pagesHome/home/video?id=${e._id}`,
  126. });
  127. } else {
  128. uni.showToast({
  129. title: '暂无视频流,无法播放',
  130. icon: 'none'
  131. });
  132. }
  133. },
  134. getDict(value, model) {
  135. const that = this;
  136. let data = that[model].find(i => i.dict_value == value);
  137. if (data) return data.dict_label
  138. else return '暂无'
  139. },
  140. // 清空列表
  141. clearPage() {
  142. const that = this;
  143. that.$set(that, `list`, [])
  144. that.$set(that, `skip`, 0)
  145. that.$set(that, `limit`, 10)
  146. that.$set(that, `page`, 0)
  147. }
  148. },
  149. };
  150. </script>
  151. <style lang="scss">
  152. .content {
  153. .one {
  154. border-bottom: 1px solid #000000;
  155. input {
  156. padding: 2vw;
  157. background-color: #f1f1f1;
  158. font-size: 14px;
  159. border-radius: 5px;
  160. }
  161. }
  162. .two {
  163. position: relative;
  164. flex-grow: 1;
  165. padding: 0 10px;
  166. .list {
  167. // width: 90%;
  168. margin: 10px 0 0 0;
  169. padding: 10px;
  170. border-radius: 5px;
  171. box-shadow: 0 0 5px #cccccc;
  172. .name {
  173. font-size: 16px;
  174. font-weight: bold;
  175. margin: 0 0 5px 0;
  176. }
  177. .other {
  178. margin: 0 0 10px 0;
  179. .other_1 {
  180. margin: 0 0 5px 0;
  181. text {
  182. font-size: 14px;
  183. color: #858585;
  184. }
  185. text:last-child {
  186. color: #000000;
  187. word-break: break-all;
  188. }
  189. }
  190. }
  191. .btn {
  192. text-align: center;
  193. }
  194. }
  195. .list:last-child {
  196. margin: 10px 0;
  197. }
  198. }
  199. }
  200. .scroll-view {
  201. position: absolute;
  202. top: 0;
  203. left: 0;
  204. right: 0;
  205. bottom: 0;
  206. .list-scroll-view {
  207. display: flex;
  208. flex-direction: column;
  209. padding: 0 10px;
  210. }
  211. }
  212. .is_bottom {
  213. text-align: center;
  214. text {
  215. padding: 2vw 0;
  216. display: inline-block;
  217. color: #858585;
  218. font-size: 14px;
  219. }
  220. }
  221. </style>