index.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. <template>
  2. <app-layout>
  3. <view class="app-pt-index">
  4. <view class="index-nav" v-if="nav_list.length > 0">
  5. <view class="app-index-nav dir-left-nowrap cross-center">
  6. <view class="app-search">
  7. <app-jump-button form open_type="navigate" url="/pages/search/search?sign=pt">
  8. <view class="app-icon"></view>
  9. </app-jump-button>
  10. </view>
  11. <view class="app-line"></view>
  12. <scroll-view scroll-x class="app-scroll">
  13. <text class="app-item" v-for="(item) in nav_list"
  14. :key="item.id"
  15. :style="{'background': cat_id == item.id ? getTheme.key === 'a' ? 'linear-gradient(140deg, #ffa360, #ff5c5c)' : getTheme.background : '','color': cat_id == item.id ? '#ffffff' : ''}"
  16. @click="changeStatus(item.id)"
  17. >{{item.name}}</text>
  18. </scroll-view>
  19. </view>
  20. </view>
  21. <!--#ifdef MP-->
  22. <view class="banner" v-if="banners.length !== 0">
  23. <swiper class="app-banner" autoplay interval="2000" circular easing-function="easeInOutCubic">
  24. <swiper-item v-for="(item, k) in banners" :key="k">
  25. <app-jump-button form :open_type="item.open_type" :item="item" :params="item.params" :url="`${item.page_url}`">
  26. <image class="app-image" :src="item.pic_url" lazy-load></image>
  27. </app-jump-button>
  28. </swiper-item>
  29. </swiper>
  30. </view>
  31. <!--#endif-->
  32. <!--#ifdef H5-->
  33. <app-swiper :height="230" :list="banners" :autoplay="true" name="pic_url"></app-swiper>
  34. <!--#endif-->
  35. <view class="image-ad" v-if="setting.is_advertisement == 1">
  36. <app-image-ad :list="setting.advertisement.list" :imageStyle="imageStyle"></app-image-ad>
  37. </view>
  38. <view class="app-list safe-area-inset-bottom">
  39. <app-product-list :theme="getTheme" :list="goods_list"></app-product-list>
  40. </view>
  41. <app-quick-navigation></app-quick-navigation>
  42. </view>
  43. </app-layout>
  44. </template>
  45. <script>
  46. import appImageAd from '../../../components/page-component/app-image-ad/app-image-ad.vue';
  47. import appProductList from '../components/app-product-list.vue';
  48. import appQuickNavigation from "../../../components/page-component/app-quick-navigation/app-quick-navigation.vue";
  49. import appSwiper from '../../../components/page-component/app-swiper/app-swiper.vue';
  50. import {mapState, mapGetters} from "vuex";
  51. export default {
  52. name: 'index',
  53. data() {
  54. return {
  55. banners: [],
  56. setting: {},
  57. nav_list: [],
  58. page: 1,
  59. page_count: 1,
  60. goods_list: [],
  61. cat_id: 0,
  62. imageStyle: 0
  63. }
  64. },
  65. onLoad(option) { this.$commonLoad.onload(option);
  66. // #ifdef MP-WEIXIN
  67. wx.showShareMenu({
  68. menus: ['shareAppMessage', 'shareTimeline']
  69. })
  70. // #endif
  71. option.cat_id && (this.cat_id = option.cat_id);
  72. this.requestSetting();
  73. this.requestCats(option.cat_id);
  74. },
  75. onReachBottom() {
  76. if (this.page < this.page_count) {
  77. this.page++;
  78. this.requestList(1);
  79. }
  80. },
  81. methods: {
  82. async changeStatus(id) {
  83. this.cat_id = id;
  84. this.page = 1;
  85. this.goods_list = [];
  86. this.requestList(0);
  87. },
  88. async requestList(status) {
  89. const r = await this.$request({
  90. url: this.$api.pt.goods,
  91. data: {
  92. page: this.page,
  93. cat_id: this.cat_id,
  94. }
  95. });
  96. if(r.code === 0) {
  97. let { pagination, list } = r.data;
  98. this.goods_list = 1 === status ? this.goods_list.concat(list) : list;
  99. this.page_count = pagination.page_count;
  100. }
  101. },
  102. requestSetting() {
  103. this.$request({
  104. url: this.$api.pt.index
  105. }).then(e => {
  106. if (e.code === 0) {
  107. this.banners = e.data.banners;
  108. // #ifdef H5
  109. this.banners.forEach(item => {
  110. if (item.open_type === 'app') {
  111. item.id = this.$utils.guid('pt');
  112. }
  113. })
  114. // #endif
  115. this.setting = e.data.setting;
  116. let ad = e.data.setting.advertisement;
  117. let list = [];
  118. for (let i = 0, len = ad.list.length; i < len; i++) {
  119. let item = ad.list[i];
  120. item.link = {
  121. value: item.link_url,
  122. open_type: item.open_type
  123. }
  124. list.push(item);
  125. }
  126. this.setting.advertisement.list = list;
  127. this.imageStyle = Number(ad.style);
  128. }
  129. });
  130. },
  131. requestCats(cat_id) {
  132. this.$request({
  133. url: this.$api.pt.cats
  134. }).then(res => {
  135. if (res.code === 0) {
  136. this.nav_list = this.nav_list.concat(res.data.list);
  137. !cat_id && (this.cat_id = this.nav_list[0].id);
  138. this.requestList(0);
  139. }
  140. });
  141. }
  142. },
  143. computed: {
  144. ...mapGetters('mallConfig', {
  145. getTheme: 'getTheme',
  146. }),
  147. },
  148. components: {
  149. 'app-image-ad': appImageAd,
  150. 'app-product-list': appProductList,
  151. 'app-quick-navigation': appQuickNavigation,
  152. appSwiper
  153. },
  154. // #ifdef MP
  155. onShareAppMessage() {
  156. return this.$shareAppMessage({
  157. path: '/plugins/pt/index/index',
  158. title: this.$children[0].navigationBarTitle,
  159. });
  160. },
  161. // #endif
  162. // #ifdef MP-WEIXIN
  163. onShareTimeline() {
  164. return this.$shareTimeline({
  165. title: this.$children[0].navigationBarTitle,
  166. query: {
  167. }
  168. });
  169. },
  170. // #endif
  171. }
  172. </script>
  173. <style scoped lang="scss">
  174. .app-pt-index {
  175. background-color: #f7f7f7;
  176. min-height: 100vh;
  177. .index-nav {
  178. width: #{750rpx};
  179. height: #{92rpx};
  180. }
  181. .banner {
  182. margin-bottom: #{24rpx};
  183. }
  184. .app-list {
  185. margin-top: #{20rpx};
  186. }
  187. }
  188. .app-banner {
  189. height: #{230rpx};
  190. width: #{750rpx};
  191. .app-image {
  192. height: #{230rpx};
  193. width: #{750rpx};
  194. }
  195. }
  196. .app-index-nav {
  197. height: #{92rpx};
  198. background-color: white;
  199. width: #{750rpx};
  200. position: fixed;
  201. top: 0;
  202. left: 0;
  203. z-index: 1000;
  204. .app-search {
  205. width: #{108rpx};
  206. height: #{92rpx};
  207. .app-icon {
  208. width: #{60rpx};
  209. height: #{60rpx};
  210. background-image: url("../image/big-sarch.png");
  211. background-size: 100% 100%;
  212. background-repeat: no-repeat;
  213. }
  214. }
  215. .app-line {
  216. width: #{1rpx};
  217. height: #{40rpx};
  218. background-color: #e2e2e2;
  219. }
  220. .app-scroll {
  221. width: #{641rpx};
  222. height: #{92rpx};
  223. white-space: nowrap;
  224. .app-item {
  225. display: inline-block;
  226. font-size: #{28rpx};
  227. color: #666666;
  228. padding: 0 #{24rpx};
  229. box-sizing: border-box;
  230. height: #{56rpx};
  231. line-height: #{56rpx};
  232. border-radius: #{28rpx};
  233. margin: #{18rpx} #{32rpx};
  234. }
  235. .app-active-item {
  236. color: white;
  237. }
  238. .default-item {
  239. background: linear-gradient(140deg, #ffa360, #ff5c5c);
  240. }
  241. }
  242. }
  243. </style>