topic.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. <template>
  2. <!--pages/topic/topic.wxml-->
  3. <!-- 顶部轮播图 -->
  4. <view :style="'background-color:' + pageList.backgroundColor + ';'">
  5. <view :class="' ' + (pageList.displayStyle == '2' ? 'banner2' : 'banner') + ' r20'"
  6. v-if="bannerList.length > 0">
  7. <swiper class="swiper" @change="swiperChange" :current="swiperCurrent">
  8. <block v-for="(item, index) in bannerList" :key="index">
  9. <swiper-item autoplay="true">
  10. <image lazy-load="true" :src="item.pic + '?x-oss-process=style/w750-auto'" mode="aspectFit"
  11. :data-type="item.type" :data-content="item.content"></image>
  12. </swiper-item>
  13. </block>
  14. </swiper>
  15. <view class="dots dflex">
  16. <block v-for="(item, index) in bannerList" :key="index">
  17. <view :class="'dot ' + (index == swiperCurrent ? ' active' : '')" :data-current="index"
  18. @tap="dotEvent"></view>
  19. </block>
  20. </view>
  21. </view>
  22. <!-- 商品列表 -->
  23. <goods-list :pageList="pageList"></goods-list>
  24. <!-- #ifdef H5 -->
  25. <wx-share ref="wxshare" />
  26. <!-- #endif -->
  27. </view>
  28. </template>
  29. <script>
  30. // pages/topic/topic.js
  31. const app = getApp();
  32. const req = require('../../utils/request.js');
  33. import goodsList from '../../components/goodsList/goodsList';
  34. export default {
  35. data() {
  36. return {
  37. picUrlss: req.public.picUrls,
  38. page: 1,
  39. pageList: {},
  40. bannerList: [],
  41. swiperCurrent: 0,
  42. isLoad: true,
  43. hasmore: true,
  44. Title: '',
  45. isRuleTrue: false,
  46. //筛选是否显示
  47. styletype: 0,
  48. productId: 0, //专题id
  49. options: ''
  50. };
  51. },
  52. components: {
  53. goodsList
  54. },
  55. props: {},
  56. /**
  57. * 生命周期函数--监听页面加载
  58. */
  59. onLoad: function(options) {
  60. if (options.appId) req.setStorage('appId', options.appId);
  61. this.options = options;
  62. uni.showShareMenu({
  63. menus: ['shareAppMessage']
  64. });
  65. // uni.setNavigationBarTitle({
  66. // title: options.title ? options.title : '专题详情'
  67. // });
  68. this.setData({
  69. productId: options.id
  70. });
  71. this.getList(options.id);
  72. },
  73. onShareAppMessage() {
  74. return this.onShareMessage();
  75. },
  76. onReady() {
  77. // #ifdef H5
  78. var that = this;
  79. //初始化分享内容
  80. setTimeout(function() {
  81. var shareContent = that.onShareMessage();
  82. if (shareContent) {
  83. shareContent.path = window.location.origin + shareContent.path;
  84. }
  85. console.log('分享内容》》》》》', shareContent);
  86. that.$refs.wxshare.init(shareContent);
  87. }, 4 * 1000);
  88. // #endif
  89. },
  90. methods: {
  91. onShareMessage() {
  92. let path = '';
  93. let isSolution = '';
  94. // #ifndef H5
  95. isSolution = req.env[req.env.NODE_ENV].isSolution;
  96. // #endif
  97. // #ifdef H5
  98. isSolution = false;
  99. // #endif
  100. let userInfo = req.getStorage('userInfo');
  101. if (isSolution) {
  102. path = '/share/home/index?appId=' + req.getStorage('appId') + '&userId=' + userInfo.id;
  103. } else {
  104. path = '/pages/topic/topic?id=' + this.productId + '&appId=' + req.getStorage('appId');
  105. }
  106. return {
  107. title: this.options.title,
  108. path: path
  109. }
  110. },
  111. //获取商品列表数据
  112. getList(id) {
  113. let that = this;
  114. // console.log("isLoad", that.isLoad);
  115. if (!that.isLoad) return false;
  116. that.isLoad = false;
  117. let form = {
  118. id: id //searchTitle: that.data.searchTitle,
  119. //sort: that.data.sort,
  120. //attr: that.data.attr,
  121. //categoryId: that.data.categoryId
  122. };
  123. let isShowLoading = false;
  124. this.allShow = false;
  125. if (!isShowLoading) {
  126. req.loadIng('加载中');
  127. isShowLoading = true;
  128. }
  129. req.getRequest('/api/special/detail', form, data => {
  130. // console.log("pageList:", data);
  131. uni.setNavigationBarTitle({
  132. title: data.title ? data.title : '专题详情'
  133. });
  134. if (data && data.length >= 10) that.isLoad = true;
  135. if (that.page > 1) data = that.pageList.concat(data);
  136. if (data) {
  137. data.products = data.products.map(it => {
  138. if (it.deliverWay && JSON.parse(it.deliverWay).indexOf(3) != -1) it.isJs =
  139. true;
  140. return it;
  141. });
  142. // console.log(data)
  143. that.getBanner(data.bannerGroupId);
  144. that.setData({
  145. pageList: data
  146. });
  147. }
  148. if (isShowLoading) {
  149. uni.hideLoading();
  150. isShowLoading = false;
  151. }
  152. });
  153. req.postRequest(
  154. '/api/browse', {
  155. bindId: id,
  156. type: 3
  157. },
  158. data => {
  159. // console.log("api/browse", data);
  160. }
  161. );
  162. },
  163. //获取banner图数据
  164. getBanner(groupId) {
  165. let that = this;
  166. req.getRequest(
  167. '/api/banner', {
  168. groupId: groupId
  169. },
  170. data => {
  171. // console.log("banner图数据", data);
  172. if (data && data.length >= 10) that.isLoad = true;
  173. if (that.page > 1) data = that.pageList.concat(data);
  174. if (data && data.length > 0) {
  175. that.setData({
  176. bannerList: data
  177. });
  178. }
  179. }
  180. );
  181. },
  182. /**
  183. * 轮播切换
  184. */
  185. swiperChange({
  186. detail
  187. }) {
  188. if (detail.source !== 'touch') return;
  189. this.setData({
  190. swiperCurrent: detail.current
  191. });
  192. }
  193. }
  194. };
  195. </script>
  196. <style>
  197. @import './topic.css';
  198. </style>