index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434
  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. //测试数据没有写id,用title代替
  203. uni.navigateTo({
  204. url: url
  205. });
  206. }
  207. }
  208. };
  209. </script>
  210. <style lang="scss">
  211. .container {
  212. height: 100%;
  213. background-color: $page-color-base;
  214. padding-bottom: 30rpx;
  215. }
  216. .content-box {
  217. height: 100%;
  218. }
  219. .user-section {
  220. position: relative;
  221. width: 690rpx;
  222. margin: 0 30rpx;
  223. margin-top: -100rpx;
  224. padding: 20rpx;
  225. border-radius: 15rpx;
  226. background-color: #ffffff;
  227. .upVipBox {
  228. padding: 12rpx;
  229. background-color: #f5f5f5;
  230. border-radius: 10rpx;
  231. font-weight: bold;
  232. .upViewTip {
  233. height: 78rpx;
  234. width: 78rpx;
  235. }
  236. }
  237. .user-info-box {
  238. position: relative;
  239. height: 100%;
  240. width: 100%;
  241. color: white;
  242. display: flex;
  243. justify-content: space-between;
  244. z-index: 10;
  245. .detail {
  246. display: flex;
  247. // justify-content: space-between;
  248. width: 100%;
  249. .portrait-box {
  250. height: 80rpx;
  251. width: 80rpx;
  252. .portrait {
  253. width: 100%;
  254. height: 100%;
  255. border: 5rpx solid #fff;
  256. border-radius: 50%;
  257. }
  258. }
  259. .info-box {
  260. margin: auto 20rpx;
  261. color: $font-color-dark;
  262. .username {
  263. font-size: $font-lg;
  264. font-weight: bold;
  265. // height: 100%;
  266. }
  267. }
  268. }
  269. .config {
  270. flex-shrink: 0;
  271. line-height: 1;
  272. padding-top: 5rpx;
  273. margin: auto 0;
  274. padding: 16rpx 34rpx;
  275. border-radius: 26rpx;
  276. font-size: $font-sm;
  277. background-color: #e896b3;
  278. text-align: center;
  279. }
  280. }
  281. }
  282. .top-swiper {
  283. width: 750rpx;
  284. height: 580rpx;
  285. .topImg {
  286. width: 750rpx;
  287. height: 580rpx;
  288. }
  289. }
  290. .content-swiper {
  291. background-color: #ffffff;
  292. margin: 20rpx 30rpx;
  293. width: 690rpx;
  294. height: 238rpx;
  295. border-radius: 15rpx;
  296. .contentImg {
  297. width: 690rpx;
  298. height: 238rpx;
  299. }
  300. }
  301. .cate-section {
  302. justify-content: flex-start;
  303. background-color: #fff;
  304. padding: 30rpx 10rpx;
  305. padding-bottom: 10rpx;
  306. margin: 20rpx 30rpx 0rpx 30rpx;
  307. flex-wrap: wrap;
  308. border-radius: 15rpx;
  309. .cate-item {
  310. flex-grow: 0;
  311. width: 25%;
  312. flex-direction: column;
  313. text-align: center;
  314. align-items: center;
  315. justify-content: center;
  316. padding-bottom: 20rpx;
  317. .img-wrapper {
  318. width: 90rpx;
  319. height: 90rpx;
  320. border-radius: 20rpx;
  321. position: relative;
  322. image {
  323. width: 90rpx;
  324. height: 90rpx;
  325. position: absolute;
  326. left: 50%;
  327. top: 50%;
  328. transform: translate(-50%, -50%);
  329. }
  330. }
  331. .item-title {
  332. margin-top: 15rpx;
  333. font-size: 26rpx;
  334. font-weight: bold;
  335. color: #6b4216;
  336. }
  337. }
  338. }
  339. .activty {
  340. padding-top: 30rpx;
  341. .action-title {
  342. color: #ee2f72;
  343. font-weight: bold;
  344. justify-content: center;
  345. .action-title-icon {
  346. width: 20rpx;
  347. height: 12rpx;
  348. }
  349. }
  350. .action-title-tip {
  351. font-size: $font-sm;
  352. color: $font-color-light;
  353. text-align: center;
  354. }
  355. }
  356. .productList {
  357. margin: 0 30rpx 20rpx 30rpx;
  358. border-radius: 20rpx;
  359. overflow: hidden;
  360. background-color: #ffffff;
  361. position: relative;
  362. line-height: 1;
  363. .tipLeft {
  364. background-color: rgba(255, 51, 66, 1);
  365. border-radius: 20rpx;
  366. border-bottom-left-radius: 0rpx;
  367. padding: 15rpx 25rpx;
  368. position: absolute;
  369. left: 0;
  370. top: 0;
  371. z-index: 9;
  372. }
  373. .productImg {
  374. height: 330rpx;
  375. width: 690rpx;
  376. }
  377. .product-name {
  378. font-size: $font-base + 2rpx;
  379. font-weight: bold;
  380. color: $font-color-dark;
  381. }
  382. .mask,
  383. .sales {
  384. font-size: $font-sm;
  385. color: $font-color-light;
  386. }
  387. .money {
  388. align-items: flex-end;
  389. line-height: 0;
  390. .payMoney {
  391. color: #ff4c4c;
  392. }
  393. .oldMoney {
  394. text-decoration: line-through;
  395. color: $font-color-light;
  396. font-size: $font-base - 2rpx;
  397. }
  398. }
  399. .buttomPlay {
  400. font-size: $font-base - 2rpx;
  401. background-color: #ee2f72;
  402. border-radius: 10rpx;
  403. padding: 10rpx 20rpx;
  404. }
  405. }
  406. </style>