index.vue 10 KB

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