collect-list.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. <template>
  2. <view class="front-box">
  3. <!-- #ifndef MP-TOUTIAO -->
  4. <uni-nav-bar :status-bar="false" :shadow="false" :border="false" :fixed="true" color="#333" background-color=""
  5. height="125px" leftWidth="0" rightWidth="0">
  6. <view class="nav-bg">
  7. <view class="status-bar"></view>
  8. <view class="nav-title">
  9. <view class="left">
  10. <IconText style="padding: 5px;" @click.native="handleBack" color="#666"
  11. :code="`\ue8be`" size="16" />
  12. </view>
  13. <view class="title">收藏</view>
  14. <view class="right"></view>
  15. </view>
  16. <view class="nav-list">
  17. <view class="nav-item" :class="{active: navActive === index}" v-for="(item, index) in navList" :key="index" @click="changeNavActive(index)">
  18. {{item.name}}
  19. <view class="bar"></view>
  20. </view>
  21. </view>
  22. </view>
  23. </uni-nav-bar>
  24. <!-- #endif -->
  25. <!-- #ifdef MP-TOUTIAO -->
  26. <uni-nav-bar :status-bar="false" :shadow="true" :border="false" :fixed="true" color="#333" background-color=""
  27. height="80px" leftWidth="0" rightWidth="0">
  28. <view class="nav-bg dy">
  29. <view class="nav-list">
  30. <view class="nav-item" :class="{active: navActive === index}" v-for="(item, index) in navList" :key="index" @click="changeNavActive(index)">
  31. {{item.name}}
  32. <view class="bar"></view>
  33. </view>
  34. </view>
  35. </view>
  36. </uni-nav-bar>
  37. <!-- #endif -->
  38. <swiper class="swiper" :current="navActive" @change="changeSwiper">
  39. <swiper-item>
  40. <scroll-view class="swiper-item" :scroll-y="true" @scrolltolower="loadGoods">
  41. <view class="goods-list">
  42. <GoodItem v-for="(good, index) in goodsList" :good="good" :key="index" style="width: 100%"></GoodItem>
  43. </view>
  44. </scroll-view>
  45. </swiper-item>
  46. <swiper-item>
  47. <scroll-view class="swiper-item" :scroll-y="true" @scrolltolower="loadArticle">
  48. <view class="article-list">
  49. <ArticleItem v-for="(article, index) in articleList" :article="article" :key="index" style="width: 100%"></ArticleItem>
  50. </view>
  51. </scroll-view>
  52. </swiper-item>
  53. </swiper>
  54. </view>
  55. </template>
  56. <script lang="ts">
  57. import {
  58. Component,
  59. Mixins
  60. } from 'vue-property-decorator';
  61. import {
  62. namespace
  63. } from 'vuex-class';
  64. import {
  65. APP_BASE_URL
  66. } from '@/common/constants';
  67. import {
  68. types
  69. } from '@/common/store/index';
  70. const baseModule = namespace('base');
  71. import loginMixin from '@/common/mixins/loginMixin.ts';
  72. @Component({})
  73. export default class Front extends Mixins(loginMixin) {
  74. staticUrl : string = this.$oss_url; //oss地址
  75. size : number = 10; //每页数量
  76. goodsList : any = []; //商品列表
  77. goodsFinish : boolean = false; //是否需要加载
  78. goodsCurrent : number = 1; //当前页
  79. goodsLoading : boolean = false; //是否加载
  80. articleList : any = []; //文章列表
  81. articleFinish : boolean = false; //是否需要加载
  82. articleCurrent : number = 1; //当前页
  83. articleLoading : boolean = false; //是否加载
  84. shareInfo : any = {}; //分享信息
  85. navActive: any = 0;
  86. navList: any = [
  87. {
  88. name: '奶粉',
  89. },
  90. {
  91. name: '文章',
  92. }
  93. ];
  94. async onPullDownRefresh() {
  95. this.initList();
  96. // this.getShareInfo();
  97. uni.stopPullDownRefresh();
  98. }
  99. async onLoad(opt : any) {
  100. // #ifndef H5
  101. // @ts-ignore
  102. this.$Router.forceGuardEach();
  103. // #endif
  104. this.initList();
  105. // this.getShareInfo();
  106. }
  107. onShow() {
  108. this.$nextTick(() => {
  109. uni.hideTabBar();
  110. });
  111. }
  112. initList(){
  113. this.articleCurrent = 1;
  114. this.goodsFinish = false;
  115. this.goodsList = [];
  116. this.getGoodsList();
  117. this.articleCurrent = 1;
  118. this.articleFinish = false;
  119. this.articleList = [];
  120. this.getArticleList();
  121. }
  122. getSuperior(opt : any) {
  123. if (opt.scene) {
  124. let sceneArr = decodeURIComponent(opt.scene).split('&');
  125. let scene : any = {};
  126. sceneArr.forEach((item : any) => {
  127. let arr = item.split('=');
  128. if (arr[0]) scene[arr[0]] = arr[1];
  129. });
  130. }
  131. if (opt.s === '1' && opt.uid) {
  132. // console.log(opt);
  133. uni.setStorageSync('referrerId', opt.uid);
  134. }
  135. }
  136. onShareAppMessage() {
  137. return {
  138. title: '育百通',
  139. path: '/pages/front/front?s=1&uid=' + this._userInfo.uid,
  140. imageUrl: this.shareInfo.pic
  141. };
  142. }
  143. getShareInfo() {
  144. this.$http
  145. .get({
  146. url: this.$api.getShareInfo
  147. })
  148. .then((res : any) => {
  149. this.shareInfo = res;
  150. // if(res.pic){
  151. // (this.$refs.tanchuang as any).open('center');
  152. // }
  153. }, (err : any) => {
  154. console.log(err);
  155. });
  156. }
  157. changeNavActive(index: any){
  158. this.navActive = index;
  159. }
  160. changeSwiper(e: any){
  161. // console.log(e.detail);
  162. this.navActive = e.detail.current;
  163. }
  164. //获取商品列表
  165. getGoodsList() {
  166. this.goodsLoading = true;
  167. // uni.showLoading({
  168. // title: '加载中',
  169. // });
  170. return this.$http
  171. .get({
  172. url: this.$api.getGoodsList,
  173. data: {
  174. size: this.size,
  175. page: this.goodsCurrent,
  176. status: '3',
  177. }
  178. })
  179. .then((res : any) => {
  180. this.goodsLoading = false;
  181. this.goodsList = [...this.goodsList, ...res.list];
  182. if (res.list.length < this.size) {
  183. this.goodsFinish = true;
  184. }
  185. // uni.hideLoading();
  186. }, (err : any) => {
  187. this.goodsLoading = false;
  188. console.log(err);
  189. // uni.hideLoading();
  190. });
  191. }
  192. getArticleList() {
  193. this.articleLoading = true;
  194. this.$http
  195. .get({
  196. url: this.$api.getGoodsList,
  197. data: {
  198. page: this.articleCurrent,
  199. size: this.size
  200. }
  201. })
  202. .then((res : any) => {
  203. this.articleList = [...this.articleList, ...res.list];
  204. this.articleLoading = false;
  205. if (res.list.length < this.size) {
  206. this.articleFinish = true;
  207. }
  208. }, (err : any) => {
  209. this.articleFinish = true;
  210. console.log(err);
  211. });
  212. }
  213. loadGoods(){
  214. if (this.goodsFinish || this.goodsLoading) return;
  215. this.goodsCurrent++;
  216. this.getGoodsList();
  217. }
  218. loadArticle(){
  219. if (this.articleFinish || this.articleLoading) return;
  220. this.articleCurrent++;
  221. this.getArticleList();
  222. }
  223. toArticle(link : any) {
  224. this.$Router.push({
  225. path: '/pages/front/article',
  226. query: {
  227. link
  228. }
  229. })
  230. }
  231. toPage(path : any) {
  232. if (!path) {
  233. uni.showToast({
  234. title: '敬请期待',
  235. icon: 'none'
  236. });
  237. return;
  238. }
  239. this.$Router.push({
  240. path: path
  241. })
  242. }
  243. }
  244. </script>
  245. <style lang="scss" scoped>
  246. page {
  247. min-height: 100vh;
  248. background: #F6F8FB;
  249. }
  250. .nav-bg {
  251. width: 100%;
  252. background: linear-gradient(180deg, #FFD9F9 0%, #F1E6FF 67.19%, #F1E9FE 82.84%, #FBF6FC 100%);
  253. &.dy{
  254. background: #fff;
  255. }
  256. .status-bar {
  257. // height: var(--status-bar-height);
  258. height: 44px;
  259. }
  260. .nav-title {
  261. width: 100%;
  262. box-sizing: border-box;
  263. height: 40px;
  264. padding: 0 vw(3);
  265. @include flex-x();
  266. @include word-vw(16, #000);
  267. .left, .right{
  268. width: vw(60);
  269. @include flex-x(flex-satrt);
  270. }
  271. .title{
  272. flex: 1;
  273. @include flex-x(center);
  274. }
  275. }
  276. .nav-list{
  277. height: vw(36);
  278. @include flex-x(flex-start);
  279. padding: 0 vw(12);
  280. box-sizing: border-box;
  281. .nav-item{
  282. padding: 0 vw(12);
  283. @include flex-y(center, center);
  284. position: relative;
  285. @include word-vw(14, #2E2E2E);
  286. &.active{
  287. font-weight: bold;
  288. .bar{
  289. height: vw(3);
  290. border-radius: vw(2);
  291. width: vw(18);
  292. background: $btn-color;
  293. position: absolute;
  294. bottom: vw(-5);
  295. }
  296. }
  297. }
  298. }
  299. }
  300. /deep/.uni-navbar__header {
  301. padding: 0 !important;
  302. .uni-navbar__header-container {
  303. padding: 0 !important;
  304. }
  305. }
  306. .swiper {
  307. min-height: calc(100vh - 150px);
  308. .swiper-item {
  309. height: 100%;
  310. padding-top: vw(10);
  311. box-sizing: border-box;
  312. overflow-y: auto;
  313. }
  314. }
  315. </style>