index.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. <template>
  2. <view class="container">
  3. <!-- 轮播图 start -->
  4. <swiper class="top-swiper" autoplay="true" duration="400" interval="5000" @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 class="content-swiper" autoplay="true" duration="400" interval="10000" @change="swiperChange">
  41. <swiper-item v-for="(item, index) in bannerList" :key="index" class="nav"
  42. @click="navto(item.url)">
  43. <image class="contentImg" :src="item.lovely" 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">全部商品</view>
  52. </view>
  53. <!-- <view class="cate-item flex" @click="navto('/pages/index/artDetail?id=1')">
  54. <view class="img-wrapper flex">
  55. <image src="../../static/index/in2.png" mode=""></image>
  56. </view>
  57. <view class="item-title">公司介绍</view>
  58. </view>
  59. <view class="cate-item flex" @click="openKf">
  60. <view class="img-wrapper flex">
  61. <image src="../../static/index/in3.png" mode=""></image>
  62. </view>
  63. <view class="item-title">联系客服</view>
  64. </view>
  65. <view class="cate-item flex" @click="navto('/pages/index/storeList')">
  66. <view class="img-wrapper flex">
  67. <image src="../../static/index/in6.png" mode=""></image>
  68. </view>
  69. <view class="item-title">本地门店</view>
  70. </view> -->
  71. </view>
  72. </view>
  73. </template>
  74. <script>
  75. import {
  76. loadIndexs,
  77. } from '@/api/index.js';
  78. import {
  79. getUserInfo
  80. } from '@/api/user.js';
  81. import {
  82. interceptor
  83. } from '@/utils/loginUtils';
  84. import {
  85. mapState,
  86. mapMutations
  87. } from 'vuex';
  88. export default {
  89. data() {
  90. return {
  91. // 轮播图
  92. bannerList: [],
  93. // 中间轮播图
  94. lovely:[],
  95. menus:[],
  96. };
  97. },
  98. computed: {
  99. ...mapState(['loginInterceptor']),
  100. ...mapState('user', ['userInfo', 'checkedStore', 'des', 'latlng', 'hasLogin'])
  101. },
  102. async onLoad(option) {
  103. let obj = this;
  104. // #ifndef MP
  105. if (option.spread) {
  106. // 存储其他邀请人
  107. uni.setStorageSync('spread', option.spread);
  108. }
  109. // #endif
  110. // #ifdef MP
  111. if (option.scene) {
  112. // 存储小程序邀请人
  113. uni.setStorage({
  114. key: 'spread_code',
  115. data: option.scene
  116. });
  117. }
  118. // #endif
  119. //获取当前位置
  120. await this.loadData();
  121. },
  122. onShow() {
  123. // 判断是否强制登录
  124. if (this.loginInterceptor && !this.hasLogin) {
  125. // 登录拦截
  126. interceptor();
  127. }
  128. if (this.userInfo.uid) {
  129. console.log(this.userInfo);
  130. getUserInfo({})
  131. .then(({
  132. data
  133. }) => {
  134. this.setUserInfo(data);
  135. if (this.userInfo.store_info.length != 0) {
  136. this.isAdmin = true;
  137. }
  138. })
  139. .catch(e => {
  140. console.log(e);
  141. });
  142. }
  143. },
  144. //下拉刷新
  145. onPullDownRefresh() {
  146. this.loadData();
  147. },
  148. onShareAppMessage(options) {
  149. // 设置菜单中的转发按钮触发转发事件时的转发内容
  150. let pages = getCurrentPages(); //获取加载的页面
  151. let currentPage = pages[pages.length - 1]; //获取当前页面的对象
  152. let url = currentPage.route; //当前页面url
  153. let item = currentPage.options; //如果要获取url中所带的参数可以查看options
  154. let shareObj = {
  155. // title: '子臣餐饮数字化服务平台', // 默认是小程序的名称(可以写slogan等)
  156. path: url + '?scene=' + this.userInfo.uid, // 默认是当前页面,必须是以‘/’开头的完整路径
  157. imageUrl: '',
  158. success: function(res) {
  159. // 转发成功之后的回调
  160. if (res.errMsg == 'shareAppMessage:ok') {}
  161. },
  162. fail: function() {
  163. // 转发失败之后的回调
  164. if (res.errMsg == 'shareAppMessage:fail cancel') {
  165. // 用户取消转发
  166. } else if (res.errMsg == 'shareAppMessage:fail') {
  167. // 转发失败,其中 detail message 为详细失败信息
  168. }
  169. }
  170. };
  171. return shareObj;
  172. },
  173. methods: {
  174. ...mapMutations('user', ['setUserInfo']),
  175. navTo(url) {
  176. uni.navigateTo({
  177. url: url
  178. });
  179. },
  180. // 點擊搜索框
  181. clickSearch() {
  182. uni.navigateTo({
  183. url: '/pages/product/search'
  184. });
  185. },
  186. // 请求载入数据
  187. async loadData() {
  188. loadIndexs({})
  189. .then(({
  190. data
  191. }) => {
  192. this.bannerList = data.banner;
  193. this.lovely = data.lovely;
  194. this.menus = data.menus;
  195. })
  196. .catch(e => {
  197. uni.stopPullDownRefresh();
  198. });
  199. },
  200. // 轮播图跳转
  201. navto(item) {
  202. // #ifdef H5
  203. console.log(url.indexOf('http'), 'banner');
  204. if (url.indexOf('http') >= 0) {
  205. window.location.href = url;
  206. }
  207. // #endif
  208. //测试数据没有写id,用title代替
  209. uni.navigateTo({
  210. url: url
  211. });
  212. },
  213. }
  214. };
  215. </script>
  216. <style lang="scss">
  217. .container {
  218. height: 100%;
  219. background-color: $page-color-base;
  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. .upViewTip {
  237. height: 78rpx;
  238. width: 78rpx;
  239. }
  240. }
  241. .user-info-box {
  242. position: relative;
  243. height: 100%;
  244. width: 100%;
  245. color: white;
  246. display: flex;
  247. justify-content: space-between;
  248. z-index: 10;
  249. .detail {
  250. display: flex;
  251. // justify-content: space-between;
  252. width: 100%;
  253. .portrait-box {
  254. height: 80rpx;
  255. width: 80rpx;
  256. .portrait {
  257. width: 100%;
  258. height: 100%;
  259. border: 5rpx solid #fff;
  260. border-radius: 50%;
  261. }
  262. }
  263. .info-box {
  264. margin: auto 20rpx;
  265. color: $font-color-dark;
  266. .username {
  267. font-size: $font-lg;
  268. // height: 100%;
  269. }
  270. }
  271. }
  272. .config {
  273. flex-shrink: 0;
  274. line-height: 1;
  275. padding-top: 5rpx;
  276. margin: auto 0;
  277. padding: 16rpx 34rpx;
  278. border-radius: 26rpx;
  279. font-size: $font-sm;
  280. background-color: #E896B3;
  281. text-align: center;
  282. }
  283. }
  284. }
  285. .top-swiper {
  286. width: 750rpx;
  287. height: 580rpx;
  288. .topImg {
  289. width: 750rpx;
  290. height: 580rpx;
  291. }
  292. }
  293. .content-swiper{
  294. background-color: #FFFFFF;
  295. margin: 20rpx 30rpx;
  296. width: 690rpx;
  297. height: 238rpx;
  298. border-radius: 15rpx;
  299. .contentImg {
  300. width: 690rpx;
  301. height: 238rpx;
  302. }
  303. }
  304. .cate-section {
  305. justify-content: flex-start;
  306. background-color: #fff;
  307. padding: 30rpx 10rpx;
  308. margin: 20rpx 30rpx 0rpx 30rpx;
  309. flex-wrap: wrap;
  310. border-radius: 15rpx;
  311. .cate-item {
  312. flex-grow: 0;
  313. width: 33.3%;
  314. flex-direction: column;
  315. text-align: center;
  316. align-items: center;
  317. justify-content: center;
  318. padding-bottom: 20rpx;
  319. .img-wrapper {
  320. width: 90rpx;
  321. height: 90rpx;
  322. border-radius: 20rpx;
  323. position: relative;
  324. image {
  325. width: 90rpx;
  326. height: 90rpx;
  327. position: absolute;
  328. left: 50%;
  329. top: 50%;
  330. transform: translate(-50%, -50%);
  331. }
  332. }
  333. .item-title {
  334. margin-top: 15rpx;
  335. font-size: 26rpx;
  336. font-weight: 500;
  337. color: #6B4216;
  338. }
  339. }
  340. }
  341. </style>