index.vue 10 KB

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