index.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. <template>
  2. <home-frame @toPath="toPath">
  3. <view class="main">
  4. <view class="one">
  5. <view class="list" v-for="(item,index) in typeList" :key="index" @tap="typeChange(item,index)">
  6. <span :style="{background:tActive==index?'var(--rgbfa4)':''}" class="textOver">{{item.title}}</span>
  7. </view>
  8. </view>
  9. <view class="two">
  10. <scroll-view scroll-y="true" class="scroll-view" @scrolltolower="toPage" @scroll="toScroll">
  11. <view class="list-scroll-view">
  12. <view class="two_1">
  13. 推荐
  14. </view>
  15. <view class="two_2">
  16. <view class="list" v-for="(item,index) in recomList" :key="index">
  17. <image class="image"
  18. :src="item.img_url&&item.img_url.length>0?item.img_url[0].url:'../../static/error.jpg'"
  19. mode="">
  20. </image>
  21. <span class="name" v-if="item.title">{{item.title}}</span>
  22. </view>
  23. </view>
  24. <view class="two_1">
  25. 全部
  26. </view>
  27. <view class="two_2">
  28. <view class="list" v-for="(item,index) in list" :key="index">
  29. <image class="image"
  30. :src="item.img_url&&item.img_url.length>0?item.img_url[0].url:'../../static/error.jpg'"
  31. mode="">
  32. </image>
  33. <span class="name" v-if="item.title">{{item.title}}</span>
  34. </view>
  35. </view>
  36. </view>
  37. </scroll-view>
  38. </view>
  39. </view>
  40. </home-frame>
  41. </template>
  42. <script>
  43. import homeFrame from "../components/home-frame.vue";
  44. export default {
  45. components: {
  46. homeFrame
  47. },
  48. data() {
  49. return {
  50. typeList: [],
  51. tActive: 0,
  52. type_id: '',
  53. recomList: [],
  54. list: [],
  55. total: 0,
  56. page: 0,
  57. skip: 0,
  58. limit: 20,
  59. // 数据是否触底
  60. is_bottom: false,
  61. scrollTop: 0
  62. };
  63. },
  64. onLoad() {
  65. },
  66. onShow() {
  67. const that = this;
  68. that.search()
  69. },
  70. onHide() {
  71. const that = this;
  72. that.clearPage()
  73. },
  74. methods: {
  75. async search() {
  76. const that = this;
  77. let res = await that.$api('scenetype', 'GET', {
  78. is_use: '0'
  79. })
  80. if (res.errcode == '0') {
  81. that.$set(that, `typeList`, res.data);
  82. if (res.total > 0) {
  83. that.$set(that, `type_id`, res.data[0]._id);
  84. that.searchScene()
  85. that.searchData()
  86. }
  87. }
  88. },
  89. // 类型选择
  90. typeChange(e, index) {
  91. const that = this;
  92. that.$set(that, `tActive`, index);
  93. that.$set(that, `type_id`, e._id);
  94. that.clearPage();
  95. that.searchScene();
  96. that.searchData();
  97. },
  98. // 查询推荐
  99. async searchScene() {
  100. const that = this;
  101. let res = await that.$api('scenedata', 'GET', {
  102. skip: 0,
  103. limit: 6,
  104. type_id: that.type_id,
  105. is_scene: '1',
  106. is_use: '0',
  107. })
  108. if (res.errcode == '0') {
  109. that.$set(that, `recomList`, res.data);
  110. }
  111. },
  112. // 查询数据
  113. async searchData() {
  114. const that = this;
  115. let res = await that.$api('scenedata', 'GET', {
  116. skip: that.skip,
  117. limit: that.limit,
  118. type_id: that.type_id,
  119. is_use: '0',
  120. })
  121. if (res.errcode == '0') {
  122. let list = [...that.list, ...res.data]
  123. that.$set(that, `list`, list);
  124. that.$set(that, `total`, res.total);
  125. }
  126. },
  127. toPage() {
  128. const that = this;
  129. let list = that.list;
  130. let limit = that.limit;
  131. if (that.total > list.length) {
  132. uni.showLoading({
  133. title: '加载中',
  134. mask: true
  135. })
  136. let page = that.page + 1;
  137. that.$set(that, `page`, page)
  138. let skip = page * limit;
  139. that.$set(that, `skip`, skip)
  140. that.searchData();
  141. uni.hideLoading();
  142. } else that.$set(that, `is_bottom`, true)
  143. },
  144. toScroll(e) {
  145. const that = this;
  146. let up = that.scrollTop;
  147. that.$set(that, `scrollTop`, e.detail.scrollTop);
  148. let num = Math.sign(up - e.detail.scrollTop);
  149. if (num == 1) that.$set(that, `is_bottom`, false);
  150. },
  151. // 清空列表
  152. clearPage() {
  153. const that = this;
  154. that.$set(that, `list`, [])
  155. that.$set(that, `skip`, 0)
  156. that.$set(that, `limit`, 20)
  157. that.$set(that, `page`, 0)
  158. },
  159. // 跳转页面
  160. toPath(e) {
  161. let url = `/${e.route}`;
  162. if (e.type == '0') uni.navigateTo({
  163. url
  164. })
  165. else if (e.type == '1') uni.redirectTo({
  166. url
  167. })
  168. else if (e.type == '2') uni.reLaunch({
  169. url
  170. })
  171. else if (e.type == '3') uni.switchTab({
  172. url
  173. })
  174. }
  175. },
  176. };
  177. </script>
  178. <style lang="scss">
  179. .main {
  180. background-color: var(--rgb111);
  181. display: flex;
  182. flex-direction: row;
  183. width: 96vw;
  184. height: 92vh;
  185. padding: 0 2vw;
  186. .one {
  187. width: 24vw;
  188. color: var(--rgbfff);
  189. margin: 0 10px 0 0;
  190. background-color: var(--rgb000);
  191. overflow-y: auto;
  192. .list {
  193. span {
  194. display: inline-block;
  195. width: 100%;
  196. height: 40px;
  197. line-height: 40px;
  198. text-align: center;
  199. font-size: 14px;
  200. }
  201. }
  202. }
  203. .two {
  204. flex-grow: 1;
  205. color: var(--rgbfff);
  206. background-color: var(--rgb000);
  207. padding: 0 2vw;
  208. overflow-y: auto;
  209. position: relative;
  210. .two_1 {
  211. padding: 1vw 0;
  212. }
  213. .two_2 {
  214. display: flex;
  215. // justify-content: space-around;
  216. flex-wrap: wrap;
  217. position: relative;
  218. .list {
  219. width: 30%;
  220. height: 70px;
  221. overflow: hidden;
  222. position: relative;
  223. margin: 0 10px 10px 0;
  224. box-shadow: 0 0 5px var(--rgbf1f);
  225. border-radius: 5px;
  226. .image {
  227. width: 100%;
  228. height: 100%;
  229. border-radius: 5px;
  230. }
  231. .name {
  232. position: absolute;
  233. bottom: 10px;
  234. width: 100%;
  235. text-align: center;
  236. left: 0;
  237. color: var(--rgb000);
  238. font-size: 12px;
  239. font-family: monospace;
  240. }
  241. }
  242. .list:nth-child(3n) {
  243. margin: 0 0 10px 0;
  244. }
  245. }
  246. }
  247. }
  248. .scroll-view {
  249. position: absolute;
  250. top: 0;
  251. left: 0;
  252. right: 0;
  253. bottom: 0;
  254. .list-scroll-view {
  255. display: flex;
  256. flex-direction: column;
  257. padding: 0 2vw;
  258. }
  259. }
  260. .is_bottom {
  261. text-align: center;
  262. text {
  263. padding: 2vw 0;
  264. display: inline-block;
  265. color: #858585;
  266. font-size: 14px;
  267. }
  268. }
  269. </style>