mall.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. <template>
  2. <view class="indexBox">
  3. <swiper class="top-swiper" autoplay="true" duration="400" interval="5000" @change="swiperChange">
  4. <swiper-item v-for="item in imagelist" class="carousel-item" @click="navTo(item.url)">
  5. <image class="imageitem" :src="item.img" />
  6. </swiper-item>
  7. </swiper>
  8. <view class="hot-list-box">
  9. <view class="list-box">
  10. <view class="list" v-for="(item,index) in navList.orderList" @click="navTo('/pages/user/model/model?mtype=' + item.id)">
  11. <view class="list-image-box">
  12. <image class="list-image" :src="item.img" mode="widthFix"></image>
  13. </view>
  14. <view class="list-content">
  15. <view class="list-title clamp">
  16. {{item.title}}
  17. </view>
  18. <view class="list-money flex flex-start">
  19. <view class="money">
  20. ¥{{item.price}}
  21. </view>
  22. </view>
  23. </view>
  24. </view>
  25. </view>
  26. </view>
  27. <uni-load-more :status="navList.loadingType"></uni-load-more>
  28. </view>
  29. </template>
  30. <script>
  31. import {
  32. mapState,
  33. mapMutations
  34. } from 'vuex';
  35. import {
  36. share
  37. } from '@/api/wx';
  38. // import {
  39. // getBannerList,
  40. // getShowTemplateList
  41. // } from '@/api/model.js';
  42. export default {
  43. data() {
  44. return {
  45. //轮播图
  46. imagelist: [],
  47. // 推荐商品
  48. navList: {
  49. state: 1,
  50. text: '通知',
  51. loadingType: 'more',
  52. orderList: [],
  53. page: 1, //当前页数
  54. limit: 10, //每次信息条数
  55. count: 0, //总消息条数
  56. },
  57. // 热门商品
  58. rmList: []
  59. };
  60. },
  61. computed: {
  62. ...mapState('user', [ 'userInfo']),
  63. },
  64. onLoad: function(option) {
  65. // #ifndef MP
  66. if (option.spread) {
  67. // 存储其他邀请人
  68. uni.setStorageSync('spread', option.spread);
  69. }
  70. // #endif
  71. // #ifdef MP
  72. if (option.scene) {
  73. // 存储小程序邀请人
  74. uni.setStorage({
  75. key: 'spread_code',
  76. data: option.scene
  77. });
  78. }
  79. // #endif
  80. // 加载分享信息
  81. this.share()
  82. },
  83. onShow() {
  84. // this.loadIndexs();
  85. },
  86. onReady() {},
  87. // 滚动到底部
  88. onReachBottom() {
  89. // this.getShowTemplateList();
  90. },
  91. // #ifdef MP
  92. onShareAppMessage(options) {
  93. // 设置菜单中的转发按钮触发转发事件时的转发内容
  94. let pages = getCurrentPages(); //获取加载的页面
  95. let currentPage = pages[pages.length - 1]; //获取当前页面的对象
  96. let url = currentPage.route; //当前页面url
  97. let item = currentPage.options; //如果要获取url中所带的参数可以查看options
  98. let shareObj = {
  99. title: "母婴界严选", // 默认是小程序的名称(可以写slogan等)
  100. path: url, // 默认是当前页面,必须是以‘/’开头的完整路径
  101. imageUrl: this.shareData.img,
  102. desc: this.shareData.synopsis,
  103. success: function(res) {
  104. // 转发成功之后的回调
  105. if (res.errMsg == 'shareAppMessage:ok') {}
  106. },
  107. fail: function() {
  108. // 转发失败之后的回调
  109. if (res.errMsg == 'shareAppMessage:fail cancel') {
  110. // 用户取消转发
  111. } else if (res.errMsg == 'shareAppMessage:fail') {
  112. // 转发失败,其中 detail message 为详细失败信息
  113. }
  114. }
  115. };
  116. // 判断是否可以邀请
  117. if (this.userInfo.uid) {
  118. shareObj.path += '&spread=' + this.userInfo.uid;
  119. }
  120. return shareObj;
  121. },
  122. // #endif
  123. methods: {
  124. share() {
  125. // console.log('加载分享');
  126. const that = this;
  127. // 请求获取默认数据
  128. share({}).then(({
  129. data
  130. }) => {
  131. // console.log('分享回调', data);
  132. that.shareData = data.data
  133. });
  134. },
  135. // 首页初始化
  136. loadIndexs() {
  137. const that = this;
  138. // 轮播图
  139. getBannerList().then(
  140. (res) => {
  141. that.imagelist = res.data.list
  142. console.log(res);
  143. }
  144. ).catch(
  145. (res) => {
  146. console.log(res);
  147. }
  148. )
  149. // 获取热门
  150. getShowTemplateList({
  151. is_hot: 1,
  152. pageSize: 3
  153. }).then(
  154. (res) => {
  155. that.rmList = res.data.list
  156. console.log(res);
  157. }
  158. ).catch(
  159. (res) => {
  160. console.log(res);
  161. }
  162. )
  163. that.getShowTemplateList();
  164. },
  165. // 获取模板列表
  166. getShowTemplateList(source) {
  167. //这里是将订单挂载到tab列表下
  168. let navItem = this.navList;
  169. let state = navItem.state;
  170. if (source === 'tabChange' && navItem.loaded === true) {
  171. //tab切换只有第一次需要加载数据
  172. return;
  173. }
  174. if (navItem.loadingType === 'loading') {
  175. //防止重复加载
  176. return;
  177. }
  178. if (navItem.loadingType === 'noMore') {
  179. //防止重复加载
  180. return;
  181. }
  182. // 修改当前对象状态为加载中
  183. navItem.loadingType = 'loading';
  184. getShowTemplateList({
  185. is_recommend: 1,
  186. page: navItem.page,
  187. pageSize: navItem.limit
  188. })
  189. .then(({
  190. data
  191. }) => {
  192. let arr = data.list.map(e => {
  193. return e;
  194. });
  195. navItem.orderList = navItem.orderList.concat(arr);
  196. navItem.page++;
  197. if (navItem.limit == arr.length) {
  198. //判断是否还有数据, 有改为 more, 没有改为noMore
  199. navItem.loadingType = 'more';
  200. return;
  201. } else {
  202. //判断是否还有数据, 有改为 more, 没有改为noMore
  203. navItem.loadingType = 'noMore';
  204. }
  205. uni.hideLoading();
  206. this.$set(navItem, 'loaded', true);
  207. })
  208. .catch(e => {
  209. console.log(e);
  210. });
  211. },
  212. navTo(url) {
  213. if (url) {
  214. if (url.indexOf('http') > -1) {
  215. // #ifdef H5
  216. window.location.href = url
  217. // #endif
  218. // #ifdef APP
  219. plus.runtime.openURL(url)
  220. // #endif
  221. } else {
  222. uni.navigateTo({
  223. url: url
  224. })
  225. }
  226. }
  227. }
  228. },
  229. };
  230. </script>
  231. <style lang="scss">
  232. page,
  233. .indexBox {
  234. height: auto;
  235. min-height: 100%;
  236. }
  237. .indexBox {
  238. padding-bottom: 50rpx;
  239. }
  240. .top-swiper {
  241. margin: auto;
  242. width: 750rpx;
  243. height: 273rpx;
  244. padding: 0 $page-row-spacing;
  245. background: linear-gradient(to bottom, #ff629f, rgba(255, 255, 255, 1) 80%, rgba(255, 255, 255, 1));
  246. .carousel-item {
  247. border-radius: 20rpx;
  248. .imageitem {
  249. // margin: auto;
  250. width: 690rpx;
  251. height: 273rpx;
  252. }
  253. }
  254. }
  255. .hot-list-box {
  256. padding: $page-row-spacing;
  257. background-color: #FFFFFF;
  258. padding-bottom: 0;
  259. .list-box {
  260. display: flex;
  261. flex-wrap: wrap;
  262. justify-content: space-between;
  263. align-items: flex-start;
  264. padding-top: 30rpx;
  265. padding-bottom: 20rpx;
  266. .list {
  267. box-shadow: 0px 0px 20rpx 0px rgba(50,50,52,0.06);
  268. border-radius: 15rpx;
  269. .list-image-box {
  270. width: 330rpx;
  271. height: 420rpx;
  272. overflow: hidden;
  273. .list-image {
  274. width: 100%;
  275. }
  276. }
  277. .list-content{
  278. padding: 20rpx;
  279. line-height: 1;
  280. .list-title {
  281. color: $font-color-dark;
  282. font-size: $font-base;
  283. margin-bottom: 20rpx;
  284. }
  285. .list-money {
  286. .money {
  287. font: $font-lg;
  288. color: #FF3342;
  289. }
  290. }
  291. }
  292. }
  293. }
  294. }
  295. </style>