index.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572
  1. <template>
  2. <!-- index.wxml -->
  3. <view class="wrap">
  4. <view class="top_bg_w">
  5. <view class="banner_wrap" v-if="topBannerList.length > 1">
  6. <swiper :autoplay="true" :circular="true" :interval="intervalTopBanner" :duration="durationTopBanner" @change="changeTopBanner">
  7. <swiper-item v-for="(item, index) in topBannerList" :key="index">
  8. <image class="top_bg" :src="imgUrl + item.thumb"></image>
  9. </swiper-item>
  10. </swiper>
  11. <view class="dots">
  12. <block v-for="(item, index) in topBannerList" :key="index">
  13. <view :class="index == currentTopBanner ? 'dot active' : 'dot'"></view>
  14. </block>
  15. </view>
  16. </view>
  17. <view class="banner_wrap" v-else>
  18. <image class="top_bg" :src="imgUrl + item.thumb" v-for="(item, index) in topBannerList" :key="index"></image>
  19. </view>
  20. </view>
  21. <view class="wrap_nr">
  22. <!-- 用户信息 -->
  23. <view class="user_wrap">
  24. <!-- 未登录 -->
  25. <view class="user_item" v-if="!token">
  26. <view class="item_l">
  27. <image class="user_touxiang" :src="userInfo.thumb ? userInfo.thumb : '/statics/img/logo.png'"></image>
  28. <view class="user_info">
  29. <view class="user_nickname">Hey,{{ userInfo.nickname ? userInfo.nickname : '羊汤馆' }}</view>
  30. <view class="shop_tip">用心做好每一碗羊汤</view>
  31. </view>
  32. </view>
  33. <view class="item_r">
  34. <view class="ac_btn" @tap="toLogin">立即登录</view>
  35. </view>
  36. </view>
  37. <!-- 已登录 -->
  38. <view class="user_item login_ed" v-else>
  39. <view class="item_l">
  40. <image class="user_touxiang" :src="userInfo.thumb"></image>
  41. <view class="user_info">
  42. <view class="user_nickname" :style="'max-width:' + (userInfo.is_member ? '200rpx' : '260rpx') + ';'">Hey,{{ userInfo.nickname }}</view>
  43. <image class="vip_tag" src="/static/statics/img/vip_tag.png" v-if="userInfo.is_member"></image>
  44. </view>
  45. </view>
  46. <view class="item_r">
  47. <view class="user_count">
  48. <view class="count_num">{{ userInfo.coupon }}</view>
  49. <view class="count_name">优惠券</view>
  50. </view>
  51. <view class="separation_line"></view>
  52. <view class="user_count">
  53. <view class="count_num">{{ userInfo.money }}</view>
  54. <view class="count_name">余额</view>
  55. </view>
  56. </view>
  57. </view>
  58. </view>
  59. <!-- 门店自取 外卖 -->
  60. <view class="process_wrap">
  61. <view class="process_item" @tap="goStore">
  62. <image class="item_icon mendian" mode="heightFix" src="/static/statics/img/mendian_icon.png"></image>
  63. <image class="item_name" mode="heightFix" src="/static/statics/img/mendian_text.png"></image>
  64. <view class="item_desc">在线点餐</view>
  65. </view>
  66. <view class="process_item waimai" @tap="goGoods">
  67. <image class="item_icon" mode="heightFix" src="/static/statics/img/waimai_icon.png"></image>
  68. <image class="item_name" mode="heightFix" src="/static/statics/img/waimai_text.png"></image>
  69. <view class="item_desc">无接触配送,外送到家</view>
  70. </view>
  71. </view>
  72. <!-- 1元购 领券 -->
  73. <view class="activity_wrap">
  74. <view class="ac_item" @tap="goActivityPage">
  75. <image class="ac_tu" :src="imgUrl + activityFirst.thumb"></image>
  76. </view>
  77. <view class="ac_item" @tap="goPage" data-url="/pages/take-coupons/index">
  78. <image class="ac_tu" src="/static/statics/img/quan_banner.png"></image>
  79. </view>
  80. </view>
  81. <!-- 广告区 -->
  82. <view class="ad_wrap_w" v-if="adList.length != 0">
  83. <!-- 多图 -->
  84. <view class="ad_wrap" v-if="adList.length > 1">
  85. <swiper :autoplay="true" :circular="true" :interval="interval" :duration="duration" @change="changeAd">
  86. <swiper-item v-for="(item, index) in adList" :key="index">
  87. <image class="ad_tu" :src="imgUrl + item.thumb" @tap="goAdUrl" :data-item="item"></image>
  88. </swiper-item>
  89. </swiper>
  90. <view class="dots">
  91. <block v-for="(item, index) in adList" :key="index">
  92. <view :class="index == current ? 'dot active' : 'dot'"></view>
  93. </block>
  94. </view>
  95. </view>
  96. <!-- 单图 -->
  97. <view class="ad_wrap" v-else>
  98. <image class="ad_tu" :src="imgUrl + item.thumb" @tap="goAdUrl" :data-item="item" v-for="(item, index) in adList" :key="index"></image>
  99. </view>
  100. </view>
  101. </view>
  102. </view>
  103. </template>
  104. <script>
  105. // index.js
  106. import * as api from '@/service/api'
  107. import * as util from '@/util/util.js'
  108. import func from '@/util/wxUtil.js';
  109. export default {
  110. data() {
  111. return {
  112. interval: '3000',
  113. // 自动切换时间间隔
  114. duration: '500',
  115. // 滑动动画时长
  116. adList: [],
  117. current: 0,
  118. imgUrl: api.API_BASE_IMAGE,
  119. userInfo: null,
  120. token: null,
  121. setBgHeight: getApp().globalData.setBgHeight,
  122. topBannerList: [],
  123. intervalTopBanner: '3000',
  124. // 自动切换时间间隔
  125. durationTopBanner: '500',
  126. // 滑动动画时长
  127. currentTopBanner: 0,
  128. activityFirst: {
  129. thumb: ''
  130. }
  131. };
  132. },
  133. onLoad: function (options) {
  134. // Do some initialize when page load.
  135. let that = this;
  136. },
  137. onShow: function () {
  138. // Do something when page show.
  139. let that = this; // 顶部banner
  140. that.getTopBanner(); // 一元加购 1加购
  141. that.getAdList(1); // 广告位 3底部滚动
  142. that.getAdList(3); // that.setData({
  143. // token: getApp().globalData.token,
  144. // userInfo: getApp().globalData.userInfo
  145. // });
  146. if (uni.getStorageSync('token')) {
  147. that.setData({
  148. token: uni.getStorageSync('token')
  149. });
  150. } // console.log('onshow',getApp().globalData);
  151. // 清掉
  152. uni.removeStorageSync('fare_type');
  153. uni.removeStorageSync('checkedAddress'); // wx.removeStorageSync('store');
  154. // console.log('token',that.data.token)
  155. if (that.token) {
  156. that.getUserInfo();
  157. }
  158. },
  159. methods: {
  160. // 广告banner
  161. getAdList(cateId) {
  162. let that = this;
  163. let params = {
  164. cate_id: cateId
  165. };
  166. api.getArticleList(params).then(res => {
  167. console.log(res)
  168. // 底部滚动
  169. if (cateId == 3) {
  170. that.setData({
  171. adList: res.result
  172. });
  173. } // 加购
  174. if (cateId == 1) {
  175. that.setData({
  176. activityFirst: res.result[0]
  177. });
  178. }
  179. })
  180. },
  181. // 广告轮播图切换
  182. changeAd(event) {
  183. let that = this;
  184. that.setData({
  185. current: event.detail.current
  186. });
  187. },
  188. // 广告跳转(单页)
  189. goAdUrl(event) {
  190. let that = this;
  191. let item = event.currentTarget.dataset.item;
  192. uni.navigateTo({
  193. url: '/pages/singlepage/index?id=' + item.id
  194. });
  195. },
  196. // 页面跳转
  197. goPage(event) {
  198. let that = this;
  199. console.log(event);
  200. let url = event.currentTarget.dataset.url;
  201. uni.navigateTo({
  202. url: url
  203. });
  204. },
  205. // 自取流程
  206. goStore() {
  207. let that = this; // 配送方式 0外卖 1自提
  208. uni.setStorage({
  209. key: 'fare_type',
  210. data: '1'
  211. }); // 因为是单店(所以直接去商品页)
  212. // wx.navigateTo({
  213. // url: '/pages/goods/index'
  214. // });
  215. uni.navigateTo({
  216. url: '/pages/tables/index'
  217. });
  218. },
  219. // 外卖流程
  220. goGoods() {
  221. let that = this; // 配送方式 0外卖 1自提
  222. uni.setStorage({
  223. key: 'fare_type',
  224. data: '0'
  225. });
  226. uni.navigateTo({
  227. url: '/pages/user/address/list/index'
  228. });
  229. },
  230. // 用户信息
  231. getUserInfo() {
  232. let that = this;
  233. api.getUserInfo({}).then(res => {
  234. console.log(res)
  235. that.setData({
  236. userInfo: res.result
  237. });
  238. })
  239. },
  240. // 去登录
  241. toLogin() {
  242. let that = this;
  243. uni.reLaunch({
  244. url: '/pages/login/index/index'
  245. });
  246. },
  247. // 一元购 (单页)
  248. goActivityPage() {
  249. let that = this;
  250. let id = that.activityFirst.id;
  251. uni.navigateTo({
  252. url: '/pages/singlepage/index?id=' + id
  253. });
  254. },
  255. // 顶部banner
  256. getTopBanner() {
  257. let that = this;
  258. api.getBannerList({}).then(res => {
  259. console.log(res)
  260. that.setData({
  261. topBannerList: res.result
  262. });
  263. })
  264. },
  265. // 顶部banner切换
  266. changeTopBanner(event) {
  267. let that = this;
  268. that.setData({
  269. currentTopBanner: event.detail.current
  270. });
  271. }
  272. },
  273. onReady: function () {
  274. // Do something when page ready.
  275. let that = this;
  276. },
  277. onHide: function () {
  278. // Do something when page hide.
  279. },
  280. onUnload: function () {
  281. // Do something when page close.
  282. },
  283. onPullDownRefresh: function () {
  284. // Do something when pull down.
  285. },
  286. onReachBottom: function () {
  287. // Do something when page reach bottom.
  288. },
  289. onShareAppMessage: function () {
  290. // return custom share data when user share.
  291. },
  292. onPageScroll: function () {
  293. // Do something when page scroll
  294. },
  295. onResize: function () {
  296. // Do something when page resize
  297. },
  298. };
  299. </script>
  300. <style>
  301. /**index.wxss**/
  302. .top_bg_w {
  303. width: 750rpx;
  304. height: 594rpx;
  305. position: fixed;
  306. top: 0;
  307. left: 0;
  308. }
  309. .top_bg_w swiper {
  310. width: 750rpx;
  311. height: 594rpx;
  312. }
  313. .top_bg {
  314. width: 750rpx;
  315. height: 594rpx;
  316. /* position: fixed;
  317. top: 0;
  318. left: 0; */
  319. }
  320. .top_bg_w .dots {
  321. position: absolute;
  322. bottom: 110rpx;
  323. left: 50%;
  324. transform: translateX(-50%);
  325. display: flex;
  326. align-items: center;
  327. }
  328. .wrap_nr {
  329. padding: 0 30rpx;
  330. padding-top: 507rpx;
  331. /* margin-top: -45rpx; */
  332. }
  333. .process_wrap {
  334. width: 690rpx;
  335. height: 246rpx;
  336. background-color: #ffffff;
  337. box-shadow: 0rpx 5rpx 15rpx 0rpx #e0e0e0;
  338. border-radius: 10rpx;
  339. display: flex;
  340. align-items: center;
  341. justify-content: space-between;
  342. position: relative;
  343. margin-top: 20rpx;
  344. }
  345. .process_bg {
  346. position: absolute;
  347. bottom: 0;
  348. left: 0;
  349. width: 690rpx;
  350. height: 30rpx;
  351. background-repeat: repeat-x;
  352. background-size: 18rpx 30rpx;
  353. }
  354. .process_wrap .process_item {
  355. flex: 1;
  356. display: flex;
  357. flex-direction: column;
  358. align-items: center;
  359. justify-content: center;
  360. }
  361. .process_item .item_icon {
  362. display: block;
  363. /* width: 113rpx; */
  364. height: 86rpx;
  365. }
  366. .process_item .item_icon.mendian {
  367. height: 106rpx;
  368. }
  369. .process_item .item_name {
  370. display: block;
  371. width: 130rpx;
  372. height: 35rpx;
  373. margin-top: 15rpx;
  374. }
  375. .process_item .item_desc {
  376. padding-top: 8rpx;
  377. font-size: 22rpx;
  378. color: #666666;
  379. }
  380. .process_wrap::after {
  381. content: '';
  382. display: block;
  383. width: 1rpx;
  384. height: 101rpx;
  385. background: rgba(102, 102, 102, 0.2);
  386. position: absolute;
  387. top: 62rpx;
  388. left: 350rpx;
  389. }
  390. .feedback_wrap {
  391. width: 690rpx;
  392. display: flex;
  393. align-items: center;
  394. justify-content: space-between;
  395. }
  396. .feedback_wrap .feedback_item {
  397. width: 335rpx;
  398. height: 158rpx;
  399. background-repeat: no-repeat;
  400. background-size: cover;
  401. margin-top: 22rpx;
  402. box-shadow: 0rpx 0rpx 25rpx 0rpx #f3f3f3;
  403. border-radius: 10rpx;
  404. display: flex;
  405. flex-direction: column;
  406. align-items: center;
  407. justify-content: center;
  408. }
  409. .feedback_item .item_icon {
  410. width: 99rpx;
  411. height: 101rpx;
  412. }
  413. .feedback_item .item_name {
  414. font-size: 30rpx;
  415. color: #000000;
  416. margin-top: -5rpx;
  417. }
  418. .ad_wrap {
  419. margin-top: 20rpx;
  420. width: 690rpx;
  421. height: 230rpx;
  422. border-radius: 10rpx;
  423. overflow: hidden;
  424. position: relative;
  425. }
  426. .ad_wrap .ad_tu {
  427. width: 690rpx;
  428. height: 230rpx;
  429. }
  430. .ad_wrap .dots {
  431. position: absolute;
  432. bottom: 19rpx;
  433. right: 50rpx;
  434. display: flex;
  435. align-items: center;
  436. }
  437. .dots .dot {
  438. width: 8rpx;
  439. height: 8rpx;
  440. background: #ffffff;
  441. border-radius: 4rpx;
  442. margin-left: 6rpx;
  443. }
  444. .dots .dot.active {
  445. width: 30rpx;
  446. }
  447. /* 用户信息 */
  448. .user_wrap {
  449. position: relative;
  450. }
  451. .user_wrap .user_item {
  452. width: 690rpx;
  453. padding: 20rpx 20rpx 20rpx 30rpx;
  454. background: #ffffff;
  455. box-shadow: 0rpx 5rpx 15rpx 0rpx #e0e0e0;
  456. border-radius: 10rpx;
  457. display: flex;
  458. align-items: center;
  459. justify-content: space-between;
  460. }
  461. .user_wrap .user_item .item_l {
  462. display: flex;
  463. align-items: center;
  464. justify-content: center;
  465. }
  466. .user_wrap .user_item .user_touxiang {
  467. width: 84rpx;
  468. height: 84rpx;
  469. border-radius: 50%;
  470. }
  471. .user_wrap .user_item .user_info {
  472. padding: 16rpx;
  473. font-size: 28rpx;
  474. color: #000000;
  475. }
  476. .user_item .user_info .shop_tip {
  477. color: #999999;
  478. }
  479. .user_item .ac_btn {
  480. width: 166rpx;
  481. height: 55rpx;
  482. background: #1f524d;
  483. border-radius: 28rpx;
  484. font-size: 30rpx;
  485. color: #ffffff;
  486. display: flex;
  487. align-items: center;
  488. justify-content: center;
  489. }
  490. .user_wrap .user_item.login_ed .user_info {
  491. display: flex;
  492. align-items: center;
  493. }
  494. .user_wrap .user_item .vip_tag {
  495. width: 70rpx;
  496. height: 30rpx;
  497. margin-left: 20rpx;
  498. }
  499. .user_item.login_ed .item_r {
  500. display: flex;
  501. align-items: center;
  502. }
  503. .user_item .user_count {
  504. display: flex;
  505. flex-direction: column;
  506. align-items: center;
  507. justify-content: space-between;
  508. font-size: 30rpx;
  509. color: #000000;
  510. }
  511. .user_item .user_count .count_name {
  512. font-size: 24rpx;
  513. color: #999999;
  514. }
  515. .user_item .item_r .separation_line {
  516. width: 1px;
  517. height: 38rpx;
  518. background: rgba(0, 0, 0, 0.2);
  519. margin: 0 30rpx;
  520. }
  521. .user_wrap .user_item .user_info .user_nickname {
  522. max-width: 300rpx;
  523. }
  524. .user_wrap .user_item.login_ed .user_info .user_nickname {
  525. max-width: 200rpx;
  526. }
  527. /* 一元购&领券区 */
  528. .activity_wrap {
  529. width: 690rpx;
  530. margin-top: 20rpx;
  531. display: flex;
  532. align-items: center;
  533. justify-content: space-between;
  534. }
  535. .activity_wrap .ac_item .ac_tu {
  536. width: 335rpx;
  537. height: 189rpx;
  538. display: block;
  539. border-radius: 10rpx;
  540. }
  541. </style>