index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475
  1. <template>
  2. <view class="container">
  3. <!-- 轮播图 start -->
  4. <swiper class="top-swiper" autoplay="true" duration="400" interval="10000" @change="swiperChange">
  5. <swiper-item v-for="(item, index) in bannerList" :key="index" class="carousel-item"
  6. @click="navto(item.url)">
  7. <image class="topImg" :src="item.pic" mode="scaleToFill" />
  8. </swiper-item>
  9. </swiper>
  10. <!-- 轮播图 end -->
  11. <view class="user-section">
  12. <view class="user-info-box">
  13. <view class="detail" @click="navTo('/pages/set/userinfo')">
  14. <view class="portrait-box">
  15. <image class="portrait" :src="userInfo.avatar || '/static/error/missing-face.png'"></image>
  16. </view>
  17. <view class="info-box">
  18. <view class="username">{{ userInfo.nickname || '游客' }}</view>
  19. <view class="font-size-sm">升级会员享收益</view>
  20. </view>
  21. </view>
  22. <view class="config text-white ">
  23. 某娘粉丝
  24. </view>
  25. </view>
  26. <view class="upVipBox flex margin-t-20">
  27. <image class="upViewTip" src="../../static/img/indexUpVipIcon.png" mode="scaleToFill"></image>
  28. <view class="flex-grow-true padding-c-10 flex">
  29. <view>
  30. <view class="font-size-base text-default">购买会员礼包成为会员</view>
  31. <view class="font-size-sm text-gray">每月赠送33元积分,下单抵扣当钱花</view>
  32. </view>
  33. <view class="font-size-sm">
  34. <text>详情</text>
  35. <text class="font-size-base">></text>
  36. </view>
  37. </view>
  38. </view>
  39. </view>
  40. <swiper indicator-dots indicator-color='rgba(255, 255, 255, .5)' indicator-active-color='#FFFFFF'
  41. class="content-swiper" autoplay="true" duration="400" interval="5000" @change="swiperChange">
  42. <swiper-item v-for="(item, index) in activity" :key="index" class="nav" @click="navto(item.url)">
  43. <image class="contentImg" :src="item.pic" mode="scaleToFill" />
  44. </swiper-item>
  45. </swiper>
  46. <view class="cate-section flex">
  47. <view class="cate-item flex" v-for="item in menus" @click="navto(item.url)">
  48. <view class="img-wrapper flex">
  49. <image :src="item.pic" mode=" scaleToFill"></image>
  50. </view>
  51. <view class="item-title">{{item.name}}</view>
  52. </view>
  53. </view>
  54. <view class="activty padding-b-20">
  55. <view class="action-title flex">
  56. <image class="action-title-icon" src="../../static/img/indexTitleLeft.png" mode="heightFix"></image>
  57. <view class="margin-c-20">推荐商品</view>
  58. <image class="action-title-icon" src="../../static/img/indexTitleRight.png" mode="scaleToFill"></image>
  59. </view>
  60. <view class="action-title-tip">
  61. 悦享套餐 格调生活
  62. </view>
  63. </view>
  64. <view class="productList" v-for="(item,ind) in hotgoods">
  65. <view class="tipLeft text-white font-size-base">
  66. 立省¥{{item.ot_price-item.price}}
  67. </view>
  68. <image class="productImg" :src="item.image" mode="scaleToFill"></image>
  69. <view class="padding-c-20 padding-t-10 padding-b-20">
  70. <view class="product-name clamp">
  71. {{item.store_name}}
  72. </view>
  73. <view class="flex padding-t-10">
  74. <view class="mask">
  75. {{item.store_info}}
  76. </view>
  77. <view class="sales" v-if="item.sales>0">
  78. 已售{{item.sales+item.unit_name}}
  79. </view>
  80. </view>
  81. <view class="flex padding-t-10">
  82. <view class="flex money">
  83. <view class="payMoney font-size-sm">
  84. </view>
  85. <view class="payMoney font-size-lg">
  86. {{item.price}}
  87. </view>
  88. <view class="oldMoney margin-l-10">
  89. {{item.ot_price}}
  90. </view>
  91. </view>
  92. <view class="buttomPlay text-white" @click.stop="navto('/pages/')">
  93. 立即抢购
  94. </view>
  95. </view>
  96. </view>
  97. </view>
  98. </view>
  99. </template>
  100. <script>
  101. import {
  102. loadIndexs,
  103. } from '@/api/index.js';
  104. import {
  105. getUserInfo
  106. } from '@/api/user.js';
  107. import {
  108. interceptor
  109. } from '@/utils/loginUtils';
  110. import {
  111. mapState,
  112. mapMutations
  113. } from 'vuex';
  114. export default {
  115. data() {
  116. return {
  117. // 轮播图
  118. bannerList: [],
  119. // 中间轮播图
  120. activity: [],
  121. // 金刚区
  122. menus: [],
  123. // 首页推荐
  124. hotgoods: []
  125. };
  126. },
  127. computed: {
  128. ...mapState(['loginInterceptor']),
  129. ...mapState('user', ['userInfo', 'checkedStore', 'des', 'latlng', 'hasLogin'])
  130. },
  131. async onLoad(option) {
  132. let obj = this;
  133. // #ifndef MP
  134. if (option.spread) {
  135. // 存储其他邀请人
  136. uni.setStorageSync('spread', option.spread);
  137. }
  138. // #endif
  139. // #ifdef MP
  140. if (option.scene) {
  141. // 存储小程序邀请人
  142. uni.setStorage({
  143. key: 'spread_code',
  144. data: option.scene
  145. });
  146. }
  147. // #endif
  148. //获取当前位置
  149. await this.loadData();
  150. },
  151. onShow() {
  152. // 判断是否强制登录
  153. if (this.loginInterceptor && !this.hasLogin) {
  154. // 登录拦截
  155. interceptor();
  156. }
  157. if (this.userInfo.uid) {
  158. console.log(this.userInfo);
  159. getUserInfo({})
  160. .then(({
  161. data
  162. }) => {
  163. this.setUserInfo(data);
  164. if (this.userInfo.store_info.length != 0) {
  165. this.isAdmin = true;
  166. }
  167. })
  168. .catch(e => {
  169. console.log(e);
  170. });
  171. }
  172. },
  173. //下拉刷新
  174. onPullDownRefresh() {
  175. this.loadData();
  176. },
  177. onShareAppMessage(options) {
  178. // 设置菜单中的转发按钮触发转发事件时的转发内容
  179. let pages = getCurrentPages(); //获取加载的页面
  180. let currentPage = pages[pages.length - 1]; //获取当前页面的对象
  181. let url = currentPage.route; //当前页面url
  182. let item = currentPage.options; //如果要获取url中所带的参数可以查看options
  183. let shareObj = {
  184. // title: '子臣餐饮数字化服务平台', // 默认是小程序的名称(可以写slogan等)
  185. path: url + '?scene=' + this.userInfo.uid, // 默认是当前页面,必须是以‘/’开头的完整路径
  186. imageUrl: '',
  187. success: function(res) {
  188. // 转发成功之后的回调
  189. if (res.errMsg == 'shareAppMessage:ok') {}
  190. },
  191. fail: function() {
  192. // 转发失败之后的回调
  193. if (res.errMsg == 'shareAppMessage:fail cancel') {
  194. // 用户取消转发
  195. } else if (res.errMsg == 'shareAppMessage:fail') {
  196. // 转发失败,其中 detail message 为详细失败信息
  197. }
  198. }
  199. };
  200. return shareObj;
  201. },
  202. methods: {
  203. ...mapMutations('user', ['setUserInfo']),
  204. navTo(url) {
  205. uni.navigateTo({
  206. url: url
  207. });
  208. },
  209. // 點擊搜索框
  210. clickSearch() {
  211. uni.navigateTo({
  212. url: '/pages/product/search'
  213. });
  214. },
  215. // 请求载入数据
  216. async loadData() {
  217. loadIndexs({})
  218. .then(({
  219. data
  220. }) => {
  221. // banner轮播图
  222. this.bannerList = data.banner;
  223. // 中间轮播图
  224. this.activity = data.activity;
  225. // 金刚区
  226. this.menus = data.menus;
  227. // 商品推荐
  228. this.hotgoods = data.info.bastList;
  229. })
  230. .catch(e => {
  231. uni.stopPullDownRefresh();
  232. });
  233. },
  234. // 轮播图跳转
  235. navto(item) {
  236. // #ifdef H5
  237. console.log(url.indexOf('http'), 'banner');
  238. if (url.indexOf('http') >= 0) {
  239. window.location.href = url;
  240. }
  241. // #endif
  242. //测试数据没有写id,用title代替
  243. uni.navigateTo({
  244. url: url
  245. });
  246. },
  247. }
  248. };
  249. </script>
  250. <style lang="scss">
  251. .container {
  252. height: 100%;
  253. background-color: $page-color-base;
  254. padding-bottom: 30rpx;
  255. }
  256. .content-box {
  257. height: 100%;
  258. }
  259. .user-section {
  260. position: relative;
  261. width: 690rpx;
  262. margin: 0 30rpx;
  263. margin-top: -100rpx;
  264. padding: 20rpx;
  265. border-radius: 15rpx;
  266. background-color: #FFFFFF;
  267. .upVipBox {
  268. padding: 12rpx;
  269. background-color: #F5F5F5;
  270. border-radius: 10rpx;
  271. font-weight: bold;
  272. .upViewTip {
  273. height: 78rpx;
  274. width: 78rpx;
  275. }
  276. }
  277. .user-info-box {
  278. position: relative;
  279. height: 100%;
  280. width: 100%;
  281. color: white;
  282. display: flex;
  283. justify-content: space-between;
  284. z-index: 10;
  285. .detail {
  286. display: flex;
  287. // justify-content: space-between;
  288. width: 100%;
  289. .portrait-box {
  290. height: 80rpx;
  291. width: 80rpx;
  292. .portrait {
  293. width: 100%;
  294. height: 100%;
  295. border: 5rpx solid #fff;
  296. border-radius: 50%;
  297. }
  298. }
  299. .info-box {
  300. margin: auto 20rpx;
  301. color: $font-color-dark;
  302. .username {
  303. font-size: $font-lg;
  304. font-weight: bold;
  305. // height: 100%;
  306. }
  307. }
  308. }
  309. .config {
  310. flex-shrink: 0;
  311. line-height: 1;
  312. padding-top: 5rpx;
  313. margin: auto 0;
  314. padding: 16rpx 34rpx;
  315. border-radius: 26rpx;
  316. font-size: $font-sm;
  317. background-color: #E896B3;
  318. text-align: center;
  319. }
  320. }
  321. }
  322. .top-swiper {
  323. width: 750rpx;
  324. height: 580rpx;
  325. .topImg {
  326. width: 750rpx;
  327. height: 580rpx;
  328. }
  329. }
  330. .content-swiper {
  331. background-color: #FFFFFF;
  332. margin: 20rpx 30rpx;
  333. width: 690rpx;
  334. height: 238rpx;
  335. border-radius: 15rpx;
  336. .contentImg {
  337. width: 690rpx;
  338. height: 238rpx;
  339. }
  340. }
  341. .cate-section {
  342. justify-content: flex-start;
  343. background-color: #fff;
  344. padding: 30rpx 10rpx;
  345. padding-bottom: 10rpx;
  346. margin: 20rpx 30rpx 0rpx 30rpx;
  347. flex-wrap: wrap;
  348. border-radius: 15rpx;
  349. .cate-item {
  350. flex-grow: 0;
  351. width: 25%;
  352. flex-direction: column;
  353. text-align: center;
  354. align-items: center;
  355. justify-content: center;
  356. padding-bottom: 20rpx;
  357. .img-wrapper {
  358. width: 90rpx;
  359. height: 90rpx;
  360. border-radius: 20rpx;
  361. position: relative;
  362. image {
  363. width: 90rpx;
  364. height: 90rpx;
  365. position: absolute;
  366. left: 50%;
  367. top: 50%;
  368. transform: translate(-50%, -50%);
  369. }
  370. }
  371. .item-title {
  372. margin-top: 15rpx;
  373. font-size: 26rpx;
  374. font-weight: bold;
  375. color: #6B4216;
  376. }
  377. }
  378. }
  379. .activty {
  380. padding-top: 30rpx;
  381. .action-title {
  382. color: #EE2F72;
  383. font-weight: bold;
  384. justify-content: center;
  385. .action-title-icon {
  386. width: 20rpx;
  387. height: 12rpx;
  388. }
  389. }
  390. .action-title-tip {
  391. font-size: $font-sm;
  392. color: $font-color-light;
  393. text-align: center;
  394. }
  395. }
  396. .productList {
  397. margin: 0 30rpx 20rpx 30rpx;
  398. border-radius: 20rpx;
  399. overflow: hidden;
  400. background-color: #FFFFFF;
  401. position: relative;
  402. line-height: 1;
  403. .tipLeft{
  404. background-color:rgba(255, 51, 66, 1) ;
  405. border-radius: 100rpx;
  406. border-bottom-left-radius: 0rpx;
  407. padding: 15rpx 25rpx;
  408. position: absolute;
  409. left: 0;
  410. top: 0;
  411. z-index: 9;
  412. }
  413. .productImg {
  414. height: 330rpx;
  415. width: 690rpx;
  416. }
  417. .product-name{
  418. font-size: $font-base + 2rpx;
  419. font-weight: bold;
  420. color: $font-color-dark;
  421. }
  422. .mask,.sales{
  423. font-size: $font-sm;
  424. color: $font-color-light;
  425. }
  426. .money{
  427. align-items: flex-end;
  428. line-height: 0;
  429. .payMoney{
  430. color: #FF4C4C;
  431. }
  432. .oldMoney{
  433. text-decoration:line-through;
  434. color: $font-color-light;
  435. font-size: $font-base - 2rpx;
  436. }
  437. }
  438. .buttomPlay{
  439. font-size: $font-base - 2rpx;
  440. background-color:#EE2F72 ;
  441. border-radius: 10rpx;
  442. padding: 10rpx 20rpx;
  443. }
  444. }
  445. </style>