index.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650
  1. <template>
  2. <layout>
  3. <view class="container">
  4. <view class="banner">
  5. <uv-swiper class="bg" height="250" imgMode="aspectFill" keyName="image" :list="listAds" indicatorMode="dot" indicatorStyle="bottom"></uv-swiper>
  6. </view>
  7. <view class="content">
  8. <view class="flex justify-between font-size-sm p-2 content-user" v-if="isLogin">
  9. <view class="flex align-center">
  10. <image :src="member.avatar ? member.avatar : '/static/images/logo.png'" class="rounded-circle" style="width:100rpx;height: 100rpx;"></image>
  11. <view class="flex flex-column content-user-text ml-1">
  12. <text class="font-weight-bolder">{{ member.nickname }}</text>
  13. <view class="flex justify-between font-size-smaller mt-2">
  14. <view><text class="text-color-assist font-size-20">卡券:</text><text>{{member.couponCount}}</text></view>
  15. <view><text class="text-color-assist font-size-20">积分:</text><text>{{member.integral}}</text></view>
  16. </view>
  17. </view>
  18. </view>
  19. <view class="flex align-center">
  20. <view class="bg-white py-1 px-2 content-user-login" >{{ member.cardId > 0 ? member.cardName : '普通会员' }}</view>
  21. </view>
  22. </view>
  23. <view class="flex justify-between font-size-sm p-2 content-user" v-else>
  24. <view class="flex align-center">
  25. <view><image src="/static/images/logo.png" class="rounded-circle" style="width:100rpx;height: 100rpx;"></image></view>
  26. <text class="ml-1">加入意象会员,享受更多优惠</text>
  27. </view>
  28. <view class="flex align-center">
  29. <view class="bg-white py-1 px-2 content-user-login" @tap="login">前往登陆</view>
  30. </view>
  31. </view>
  32. <view class="content-user2 flex" style="">
  33. <view class="p-3 bg-white rounded" style="width: 350rpx;" @tap="goScan">
  34. <view style="position: relative;">
  35. <view style="position: absolute;top:0;left:0;;"><image src="/static/images/100.jpg" style="width:300rpx;height: 300rpx;"></image></view>
  36. <veiw style="position: relative;top:40rpx;">
  37. <view class="flex flex-column justify-center align-center" >
  38. <view class=" flex">
  39. <text class="font-size-medium font-weight-bold ">堂食点餐</text>
  40. <uv-icon size="10" color="#059825" name="play-right-fill"></uv-icon>
  41. </view>
  42. <view class="text-color-assist" style="font-size: 22rpx;">扫码享用美食</view>
  43. </view>
  44. </veiw>
  45. </view>
  46. </view>
  47. <view class="flex flex-column ml-1" style="width: 350rpx;">
  48. <view class="p-1 bg-white rounded" >
  49. <view style="position: relative;width:300rpx;height: 150rpx;" @tap="takeout">
  50. <view style="position: absolute;top:0;left:0;">
  51. <image src="/static/images/300.jpg" mode="aspectFit" style="width:300rpx;height: 150rpx;"></image>
  52. </view>
  53. <veiw style="position: relative; top:20rpx" class="">
  54. <view class="flex flex-column pl-1" >
  55. <view class=" flex">
  56. <text class="font-size-medium font-weight-bold ">外卖到家</text>
  57. <uv-icon size="10" color="#059825" name="play-right-fill"></uv-icon>
  58. </view>
  59. <view class="text-color-assist" style="font-size: 22rpx;">美食送到家</view>
  60. </view>
  61. </veiw>
  62. </view>
  63. </view>
  64. <view class="p-1 bg-white mt-1 rounded">
  65. <view style="position: relative;width:300rpx;height: 150rpx;" @tap="takein">
  66. <view style="position: absolute;top:0;left:0;">
  67. <image src="/static/images/200.jpg" mode="aspectFit" style="width:300rpx;height: 150rpx;"></image>
  68. </view>
  69. <veiw style="position: relative;top:20rpx">
  70. <view class="flex flex-column pl-1" >
  71. <view class=" flex">
  72. <text class="font-size-medium font-weight-bold ">到店取餐</text>
  73. <uv-icon size="10" color="#059825" name="play-right-fill"></uv-icon>
  74. </view>
  75. <view class="text-color-assist" style="font-size: 22rpx;">下单免排队</view>
  76. </view>
  77. </veiw>
  78. </view>
  79. </view>
  80. </view>
  81. </view>
  82. <view class="coupon-warp" v-if="isLogin">
  83. <view class="coupon-box">
  84. <view class="coupon-top">
  85. <view class="title">
  86. <image class="img" src="https://b2c.yixiang.co/static/home/title-coupon.png" />
  87. <view class="text-color-assist">好券天天领不停</view>
  88. </view>
  89. <view class="btn-more" @tap="toDetail('/pages/components/pages/coupons/coupons',4)">查看更多</view>
  90. </view>
  91. <view class="coupon-list coupon-flex">
  92. <view class="coupon-item" v-for="(item, index) in notCoupons" :key="index">
  93. <view class="coupon-left">
  94. <view class="discount">
  95. <view class="unit pre-unit">
  96. </view>
  97. 2
  98. </view>
  99. <view class="type" >
  100. <text v-if="item.type == 1">自取</text>
  101. <text v-else-if="item.type == 2">外卖</text>
  102. <text v-else>通用</text>
  103. </view>
  104. </view>
  105. <view class="coupon-right">
  106. <view class="info">
  107. <view class="tip">
  108. 满{{item.least}}减{{item.value}}
  109. </view>
  110. </view>
  111. <view class="button get-coupon" v-if="item.isReceive == 0" @tap="receive(item, index)">
  112. 领取
  113. </view>
  114. <view class="button get-coupon" v-else>
  115. 已领取
  116. </view>
  117. </view>
  118. </view>
  119. </view>
  120. </view>
  121. </view>
  122. <view class="member-news">
  123. <view class="header">
  124. <view class="title">活动抢先知</view>
  125. </view>
  126. <view class="list">
  127. <view class="item" v-for="(item,index) in listNews" :key="index" @tap="goNews(item.id)">
  128. <image :src="item.picUrl"></image>
  129. <view class="title">{{ item.title }}</view>
  130. </view>
  131. </view>
  132. </view>
  133. </view>
  134. </view>
  135. </layout>
  136. </template>
  137. <script setup>
  138. import {
  139. ref
  140. } from 'vue'
  141. import { onLoad } from '@dcloudio/uni-app'
  142. import {
  143. menuAds,
  144. getNews
  145. } from '@/api/market'
  146. import {
  147. getWechatConfig
  148. } from '@/api/order'
  149. import {
  150. couponReceive,
  151. couponIndexApi
  152. } from '@/api/coupon'
  153. import { storeToRefs } from 'pinia'
  154. import { useMainStore } from '@/store/store'
  155. // #ifdef H5
  156. import * as jweixin from 'weixin-js-sdk'
  157. // #endif
  158. //
  159. const main = useMainStore()
  160. const { member,store, isLogin} = storeToRefs(main)
  161. //const store = ref(main.store)
  162. const listAds = ref([])
  163. const listNews = ref([])
  164. const notCoupons = ref([])
  165. // const isLogin = ref(main.isLogin)
  166. const handGetListAds = async () => {
  167. let shop_id = store.id ? store.id : 0;
  168. let data = await menuAds({
  169. shop_id: shop_id
  170. });
  171. if (data) {
  172. listAds.value = data.list;
  173. uni.setStorage({
  174. key: 'isActive',
  175. data: data.isActive
  176. });
  177. if(data.list.length > 0){
  178. uni.setStorage({
  179. key: 'shopAd',
  180. data: data.list[0].image
  181. });
  182. }
  183. }
  184. }
  185. const getNewsList = async () => {
  186. let data = await getNews({});
  187. //console.log('listNews:',data)
  188. if (data) {
  189. listNews.value = data;
  190. }
  191. }
  192. const getCoupons = async(type) => {
  193. let page = 1;
  194. let pagesize = 4;
  195. notCoupons.value = await couponIndexApi({page:page,pagesize:pagesize});
  196. }
  197. const takein = () => {
  198. main.SET_ORDER_TYPE('takein')
  199. main.DEL_DESK()
  200. uni.switchTab({
  201. url: '/pages/menu/menu'
  202. })
  203. }
  204. const takeout = () => {
  205. main.SET_ORDER_TYPE('takeout')
  206. main.DEL_DESK()
  207. uni.switchTab({
  208. url: '/pages/menu/menu'
  209. })
  210. }
  211. const selectShop = () => {
  212. uni.navigateTo({
  213. url: '/pages/components/pages/shop/shop'
  214. })
  215. }
  216. const goNews = (id) => {
  217. uni.navigateTo({
  218. url: '/pages/components/pages/mine/news?id=' + id
  219. })
  220. }
  221. //const coupons = () => {
  222. // if(!isLogin) {
  223. // uni.navigateTo({url: '/pages/components/pages/login/login'})
  224. // return
  225. // }
  226. // uni.navigateTo({
  227. // url: '/pages/components/pages/coupons/coupons?current=4'
  228. // })
  229. // }
  230. const goScore = () => {
  231. uni.navigateTo({
  232. url: '/pages/components/pages/scoreproduct/list'
  233. })
  234. }
  235. const toDetail = (page,index) => {
  236. uni.navigateTo({
  237. url: page + '?current=' + index
  238. })
  239. }
  240. const getNewPath = (path) => {
  241. const tempPath = decodeURIComponent(path);
  242. const strList = tempPath.split("?scene=");
  243. const scene = encodeURIComponent(strList[1]);
  244. const newPath = strList[0] +"?scene=" + scene;
  245. return newPath;
  246. }
  247. // 领取优惠券
  248. const receive = async(coupon,index) => {
  249. let data = await couponReceive({id:coupon.id});
  250. if (data) {
  251. uni.showToast({
  252. title: '开领取成功',
  253. icon: 'success'
  254. })
  255. getCoupons()
  256. }
  257. }
  258. const goScan = async() => {
  259. // #ifdef MP-WEIXIN
  260. uni.scanCode({
  261. success: function (res) {
  262. const newPath = getNewPath(res.path);
  263. uni.navigateTo({
  264. url: '/' + newPath
  265. })
  266. },
  267. fail: function (res) {
  268. console.log('扫码失败:', res);
  269. }
  270. });
  271. // #endif
  272. // #ifdef H5
  273. let config = await getWechatConfig();
  274. jweixin.config({
  275. debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
  276. appId: config.appId, // 必填,公众号的唯一标识
  277. timestamp: config.timestamp, // 必填,生成签名的时间戳
  278. nonceStr: config.nonceStr, // 必填,生成签名的随机串
  279. signature: config.signature, // 必填,签名
  280. jsApiList: [
  281. 'scanQRCode'
  282. ] ,
  283. }
  284. );
  285. jweixin.ready(function() {
  286. jweixin.scanQRCode({
  287. needResult: 1,
  288. success: function(res) {
  289. //alert(res.resultStr)
  290. console.log('sanc:',res)
  291. location.href = res.resultStr
  292. }
  293. })
  294. })
  295. // #endif
  296. }
  297. const invite = () => {
  298. // uni.showToast({
  299. // title: '开发中......',
  300. // icon: 'error'
  301. // })
  302. uni.navigateTo({
  303. url: '/pages/components/pages/due/index'
  304. })
  305. }
  306. const login = () => {
  307. uni.navigateTo({
  308. url: '/pages/components/pages/login/login'
  309. })
  310. }
  311. onLoad(() => {
  312. // main.init()
  313. handGetListAds()
  314. getNewsList()
  315. if(isLogin.value){
  316. getCoupons()
  317. }
  318. })
  319. </script>
  320. <style lang="scss">
  321. /* #ifdef H5 */
  322. page {
  323. height: auto;
  324. min-height: 100%;
  325. }
  326. /* #endif */
  327. page {
  328. //background-color: #ffffff!important;
  329. }
  330. .banner {
  331. position: relative;
  332. width: 100%;
  333. //height: 300rpx;
  334. .bg {
  335. width: 100%;
  336. height: 330rpx;
  337. }
  338. .intro {
  339. position: absolute;
  340. top: calc(50rpx + var(--status-bar-height));
  341. left: 40rpx;
  342. color: #FFFFFF;
  343. display: flex;
  344. flex-direction: column;
  345. .greet {
  346. font-size: $font-size-lg;
  347. margin-bottom: 10rpx;
  348. }
  349. .note {
  350. font-size: $font-size-sm;
  351. }
  352. }
  353. }
  354. .content {
  355. padding: 0 20rpx;
  356. }
  357. .content-user {
  358. background-color: #ffffff;position: relative;top:-56rpx;border-radius: 18rpx;
  359. }
  360. .content-user-text {
  361. font-size: 24rpx;color: #282828;
  362. }
  363. .content-user-login {
  364. color:#ffffff;border-radius: 40rpx;font-size: 20rpx;border: solid;background-color: #fa850d;
  365. }
  366. .content-user2 {
  367. position: relative;top:-70rpx;border-radius: 18rpx;padding: 30rpx 0;
  368. }
  369. .member-news {
  370. position: relative;
  371. top:-70rpx;
  372. width: 100%;
  373. margin-bottom: 30rpx;
  374. background-color: #ffffff;
  375. padding: 0 20rpx 30rpx 30rpx;
  376. .header {
  377. display: flex;
  378. align-items: center;
  379. justify-content: space-between;
  380. padding: 20rpx 0;
  381. .title {
  382. font-size: $font-size-lg;
  383. font-weight: bold;
  384. }
  385. .iconfont {
  386. font-size: 52rpx;
  387. color: $text-color-assist;
  388. }
  389. }
  390. .list {
  391. width: 100%;
  392. display: flex;
  393. flex-direction: column;
  394. .item {
  395. width: 100%;
  396. height: 240rpx;
  397. position: relative;
  398. margin-bottom: 10rpx;
  399. image {
  400. width: 100%;
  401. height: 100%;
  402. border-radius: 8rpx;
  403. }
  404. .title {
  405. position: relative;
  406. font-size: 32rpx;
  407. font-weight: 500;
  408. width: 100%;
  409. top: -70rpx;
  410. left: 16rpx;
  411. color: #ffffff;
  412. }
  413. }
  414. }
  415. }
  416. .coupon-warp{
  417. position: relative;
  418. top:-70rpx;
  419. width: 100%;
  420. margin-bottom: 30rpx;
  421. background-color: #ffffff;
  422. //padding: 0 34rpx;
  423. }
  424. .coupon-box {
  425. padding: 24rpx;
  426. background: linear-gradient( 180deg, #FBECDB 0%, #FFFFFF 100%);
  427. border-radius: 15rpx;
  428. .coupon-top{
  429. display: flex;
  430. justify-content: space-between;
  431. margin-bottom: 20rpx;
  432. .title{
  433. flex: 1;
  434. display: flex;
  435. font-size: 24rpx;
  436. color: #988E83;
  437. align-items: center;
  438. .img{
  439. width: 121rpx;
  440. height: 28rpx;
  441. margin-right: 10rpx;
  442. }
  443. }
  444. .btn-more{
  445. font-size: 24rpx;
  446. color: #999;
  447. padding-right: 30rpx;
  448. background: url("https://b2c.yixiang.co/static/images/icon-arrow.png") no-repeat right center / 20rpx 20rpx;
  449. }
  450. }
  451. ::v-deep .coupon-list {
  452. .item {
  453. margin-top: 24rpx;
  454. display: block;
  455. &:first-child {
  456. margin-top: 0;
  457. }
  458. }
  459. .coupon-item {
  460. width: 100%;
  461. height: 160rpx;
  462. background: url('https://b2c.yixiang.co/static/images/canvas/bg-coupon-l.png') no-repeat;
  463. background-size: 100% 100%;
  464. box-sizing: border-box;
  465. display: flex;
  466. align-items: center;
  467. justify-content: space-between;
  468. .discount {
  469. display: flex;
  470. align-items: baseline;
  471. font-size: 68rpx;
  472. line-height: 64rpx;
  473. font-weight: bold;
  474. .unit {
  475. font-size: 32rpx;
  476. }
  477. }
  478. .info {
  479. font-size: 38rpx;
  480. .type {
  481. font-size: 32rpx;
  482. font-weight: bold;
  483. color: #333333;
  484. line-height: 45rpx;
  485. }
  486. .tip {
  487. font-size: 24rpx;
  488. //white-space: nowrap;
  489. }
  490. }
  491. .button {
  492. width: 144rpx;
  493. height: 64rpx;
  494. border-radius: 8rpx;
  495. background: #ee6d46;
  496. font-size: 24rpx;
  497. color: #fff;
  498. display: flex;
  499. align-items: center;
  500. justify-content: center;
  501. }
  502. .disable {
  503. background: #666666;
  504. }
  505. .expired {
  506. background: #999999;
  507. }
  508. .coupon-left {
  509. width: 206rpx;
  510. display: flex;
  511. justify-content: center;
  512. }
  513. .coupon-right {
  514. flex: 1;
  515. display: flex;
  516. padding: 0 32rpx;
  517. justify-content: space-between;
  518. align-items: center;
  519. }
  520. }
  521. &.coupon-flex {
  522. display: flex;
  523. flex-wrap: wrap;
  524. justify-content: space-between;
  525. .item:nth-child(2) {
  526. margin-top: 0;
  527. }
  528. .coupon-item {
  529. width: 309rpx;
  530. height: 120rpx;
  531. background-image: url('https://b2c.yixiang.co/static/images/canvas/bg-coupon-m.png');
  532. .coupon-left {
  533. width: 138rpx;
  534. flex-direction: column;
  535. align-items: center;
  536. .type {
  537. font-size: 20rpx;
  538. font-weight: bold;
  539. line-height: 28rpx;
  540. }
  541. }
  542. .coupon-right {
  543. flex-direction: column;
  544. padding: 0;
  545. }
  546. .discount {
  547. font-size: 32rpx;
  548. line-height: 45rpx;
  549. .unit {
  550. font-size: 24rpx;
  551. }
  552. }
  553. .info {
  554. .tip {
  555. font-size: 20rpx;
  556. line-height: 36rpx;
  557. margin-bottom: 9rpx;
  558. }
  559. }
  560. .button {
  561. width: 100rpx;
  562. height: 32rpx;
  563. border-radius: 16rpx;
  564. font-size: 20rpx;
  565. }
  566. }
  567. }
  568. }
  569. }
  570. </style>