index.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437
  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="title-box flex">
  10. <view class="flex">
  11. <image class="hot margin-r-10" src="../../static/icon/hot.png" mode="scaleToFill"></image>
  12. <view class="title">
  13. 热门装扮
  14. </view>
  15. </view>
  16. <navigator url="/pages/user/model/modelList?ishot=1">
  17. <view class="right flex">
  18. <text class="margin-r-10">
  19. 更多
  20. </text>
  21. <image src="../../static/icon/next1.png" mode="scaleToFill" class="tip"></image>
  22. </view>
  23. </navigator>
  24. </view>
  25. <view class="hot-list">
  26. <view class="item" v-for="item in rmList">
  27. <view class="hot-image-box">
  28. <image class="hot-image" :src="item.img" mode="widthFix"></image>
  29. </view>
  30. <view class="hot-title clamp">
  31. {{item.title}}
  32. </view>
  33. <view class="hot-money flex flex-start">
  34. <view class="money">
  35. ¥{{item.price}}
  36. </view>
  37. <view class="oldmoney">
  38. {{item.old_price}}
  39. </view>
  40. </view>
  41. </view>
  42. <view class="item-none" v-if="rmList.length<3" v-for="item in (3-rmList.length)">
  43. </view>
  44. </view>
  45. <view class="title-box flex">
  46. <view class="flex">
  47. <image class="hot margin-r-10" src="../../static/icon/hot.png" mode="scaleToFill"></image>
  48. <view class="title">
  49. 精选推荐
  50. </view>
  51. </view>
  52. <navigator url="/pages/user/model/modelList?isrecommend=1">
  53. <view class="right flex">
  54. <text class="margin-r-10">
  55. 更多
  56. </text>
  57. <image src="../../static/icon/next1.png" mode="scaleToFill" class="tip"></image>
  58. </view>
  59. </navigator>
  60. </view>
  61. <view class="list-box">
  62. <view class="list" v-for="(item,index) in navList.orderList">
  63. <view class="list-image-box">
  64. <image class="list-image" :src="item.img" mode="widthFix"></image>
  65. </view>
  66. <view class="list-content">
  67. <view class="list-title clamp">
  68. {{item.title}}
  69. </view>
  70. <view class="list-money flex flex-start">
  71. <view class="money">
  72. ¥{{item.price}}
  73. </view>
  74. </view>
  75. </view>
  76. </view>
  77. </view>
  78. </view>
  79. <uni-load-more :status="navList.loadingType"></uni-load-more>
  80. </view>
  81. </template>
  82. <script>
  83. import {
  84. mapState,
  85. mapMutations
  86. } from 'vuex';
  87. import {
  88. share
  89. } from '@/api/wx';
  90. import {
  91. getBannerList,
  92. getShowTemplateList
  93. } from '@/api/model.js';
  94. export default {
  95. data() {
  96. return {
  97. //轮播图
  98. imagelist: [],
  99. // 推荐商品
  100. navList: {
  101. state: 1,
  102. text: '通知',
  103. loadingType: 'more',
  104. orderList: [],
  105. page: 1, //当前页数
  106. limit: 10, //每次信息条数
  107. count: 0, //总消息条数
  108. },
  109. // 热门商品
  110. rmList: []
  111. };
  112. },
  113. computed: {
  114. ...mapState('user', [ 'userInfo']),
  115. },
  116. onLoad: function(option) {
  117. // #ifndef MP
  118. if (option.spread) {
  119. // 存储其他邀请人
  120. uni.setStorageSync('spread', option.spread);
  121. }
  122. // #endif
  123. // #ifdef MP
  124. if (option.scene) {
  125. // 存储小程序邀请人
  126. uni.setStorage({
  127. key: 'spread_code',
  128. data: option.scene
  129. });
  130. }
  131. // #endif
  132. // 加载分享信息
  133. this.share()
  134. },
  135. onShow() {
  136. this.loadIndexs();
  137. },
  138. onReady() {},
  139. // 滚动到底部
  140. onReachBottom() {
  141. this.getShowTemplateList();
  142. },
  143. // #ifdef MP
  144. onShareAppMessage(options) {
  145. // 设置菜单中的转发按钮触发转发事件时的转发内容
  146. let pages = getCurrentPages(); //获取加载的页面
  147. let currentPage = pages[pages.length - 1]; //获取当前页面的对象
  148. let url = currentPage.route; //当前页面url
  149. let item = currentPage.options; //如果要获取url中所带的参数可以查看options
  150. let shareObj = {
  151. title: this.shareData.title, // 默认是小程序的名称(可以写slogan等)
  152. path: url, // 默认是当前页面,必须是以‘/’开头的完整路径
  153. imageUrl: this.shareData.img,
  154. desc: this.shareData.synopsis,
  155. success: function(res) {
  156. // 转发成功之后的回调
  157. if (res.errMsg == 'shareAppMessage:ok') {}
  158. },
  159. fail: function() {
  160. // 转发失败之后的回调
  161. if (res.errMsg == 'shareAppMessage:fail cancel') {
  162. // 用户取消转发
  163. } else if (res.errMsg == 'shareAppMessage:fail') {
  164. // 转发失败,其中 detail message 为详细失败信息
  165. }
  166. }
  167. };
  168. // 判断是否可以邀请
  169. if (this.userInfo.uid) {
  170. shareObj.path += '&spread=' + this.userInfo.uid;
  171. }
  172. return shareObj;
  173. },
  174. // #endif
  175. methods: {
  176. share() {
  177. // console.log('加载分享');
  178. const that = this;
  179. // 请求获取默认数据
  180. share({}).then(({
  181. data
  182. }) => {
  183. // console.log('分享回调', data);
  184. that.shareData = data.data
  185. });
  186. },
  187. // 首页初始化
  188. loadIndexs() {
  189. const that = this;
  190. // 轮播图
  191. getBannerList().then(
  192. (res) => {
  193. that.imagelist = res.data.list
  194. console.log(res);
  195. }
  196. ).catch(
  197. (res) => {
  198. console.log(res);
  199. }
  200. )
  201. // 获取热门
  202. getShowTemplateList({
  203. is_hot: 1,
  204. pageSize: 3
  205. }).then(
  206. (res) => {
  207. that.rmList = res.data.list
  208. console.log(res);
  209. }
  210. ).catch(
  211. (res) => {
  212. console.log(res);
  213. }
  214. )
  215. that.getShowTemplateList();
  216. },
  217. // 获取模板列表
  218. getShowTemplateList(source) {
  219. //这里是将订单挂载到tab列表下
  220. let navItem = this.navList;
  221. let state = navItem.state;
  222. if (source === 'tabChange' && navItem.loaded === true) {
  223. //tab切换只有第一次需要加载数据
  224. return;
  225. }
  226. if (navItem.loadingType === 'loading') {
  227. //防止重复加载
  228. return;
  229. }
  230. if (navItem.loadingType === 'noMore') {
  231. //防止重复加载
  232. return;
  233. }
  234. // 修改当前对象状态为加载中
  235. navItem.loadingType = 'loading';
  236. getShowTemplateList({
  237. is_recommend: 1,
  238. page: navItem.page,
  239. pageSize: navItem.limit
  240. })
  241. .then(({
  242. data
  243. }) => {
  244. let arr = data.list.map(e => {
  245. return e;
  246. });
  247. navItem.orderList = navItem.orderList.concat(arr);
  248. navItem.page++;
  249. if (navItem.limit == arr.length) {
  250. //判断是否还有数据, 有改为 more, 没有改为noMore
  251. navItem.loadingType = 'more';
  252. return;
  253. } else {
  254. //判断是否还有数据, 有改为 more, 没有改为noMore
  255. navItem.loadingType = 'noMore';
  256. }
  257. uni.hideLoading();
  258. this.$set(navItem, 'loaded', true);
  259. })
  260. .catch(e => {
  261. console.log(e);
  262. });
  263. },
  264. navTo(url) {
  265. if (url) {
  266. if (url.indexOf('http') > -1) {
  267. // #ifdef H5
  268. window.location.href = url
  269. // #endif
  270. // #ifdef APP
  271. plus.runtime.openURL(url)
  272. // #endif
  273. } else {
  274. uni.navigateTo({
  275. url: url
  276. })
  277. }
  278. }
  279. }
  280. },
  281. };
  282. </script>
  283. <style lang="scss">
  284. page,
  285. .indexBox {
  286. height: auto;
  287. min-height: 100%;
  288. }
  289. .indexBox {
  290. padding-bottom: 50rpx;
  291. }
  292. .top-swiper {
  293. margin: auto;
  294. width: 750rpx;
  295. height: 273rpx;
  296. padding: 0 $page-row-spacing;
  297. background: linear-gradient(to bottom, #ff629f, rgba(255, 255, 255, 1) 80%, rgba(255, 255, 255, 1));
  298. .carousel-item {
  299. border-radius: 20rpx;
  300. .imageitem {
  301. // margin: auto;
  302. width: 690rpx;
  303. height: 273rpx;
  304. }
  305. }
  306. }
  307. .hot-list-box {
  308. padding: $page-row-spacing;
  309. background-color: #FFFFFF;
  310. padding-bottom: 0;
  311. .title-box {
  312. line-height: 1;
  313. .hot {
  314. width: 36rpx;
  315. height: 36rpx;
  316. }
  317. .title {
  318. font-size: $font-lg;
  319. font-weight: bold;
  320. }
  321. .right {
  322. font-size: $font-sm;
  323. color: #999999;
  324. .tip {
  325. width: 15rpx;
  326. height: 25rpx;
  327. }
  328. }
  329. }
  330. .hot-list {
  331. display: flex;
  332. flex-wrap: wrap;
  333. justify-content: space-between;
  334. align-items: flex-start;
  335. padding-top: 30rpx;
  336. padding-bottom: 15rpx;
  337. .item-none {
  338. width: 220rpx;
  339. }
  340. .item {
  341. padding: 13rpx;
  342. width: 220rpx;
  343. border-radius: 10rpx;
  344. border: 2px solid #F65486;
  345. margin-bottom: 16rpx;
  346. line-height: 1;
  347. .hot-title {
  348. color: $font-color-dark;
  349. font-size: $font-base;
  350. padding: 10rpx 0;
  351. }
  352. .hot-image-box {
  353. width: 194rpx;
  354. height: 228rpx;
  355. overflow: hidden;
  356. .hot-image {
  357. width: 100%;
  358. }
  359. }
  360. .hot-money {
  361. .money {
  362. font: $font-lg;
  363. color: #FF3342;
  364. }
  365. .oldmoney {
  366. color: #969696;
  367. font-size: $font-sm;
  368. text-decoration: line-through;
  369. }
  370. }
  371. }
  372. }
  373. .list-box {
  374. display: flex;
  375. flex-wrap: wrap;
  376. justify-content: space-between;
  377. align-items: flex-start;
  378. padding-top: 30rpx;
  379. padding-bottom: 20rpx;
  380. .list {
  381. box-shadow: 0px 0px 20rpx 0px rgba(50,50,52,0.06);
  382. border-radius: 15rpx;
  383. .list-image-box {
  384. width: 330rpx;
  385. height: 420rpx;
  386. overflow: hidden;
  387. .list-image {
  388. width: 100%;
  389. }
  390. }
  391. .list-content{
  392. padding: 20rpx;
  393. line-height: 1;
  394. .list-title {
  395. color: $font-color-dark;
  396. font-size: $font-base;
  397. margin-bottom: 10rpx;
  398. }
  399. .list-money {
  400. .money {
  401. font: $font-lg;
  402. color: #FF3342;
  403. }
  404. }
  405. }
  406. }
  407. }
  408. }
  409. </style>