index.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768
  1. <template>
  2. <view class="container">
  3. <!-- 兼容小程序搜索 -->
  4. <!-- 顶部logo and 搜索 start-->
  5. <view class="top-search flex">
  6. <view class="search-box flex" @click="clickSearch()">
  7. <image class="search" src="../../static/icon/search-h.png" mode=""></image>
  8. <view class="search-font">输入关键词搜索</view>
  9. </view>
  10. </view>
  11. <!-- 顶部logo and 搜索 end-->
  12. <!-- 轮播图 start -->
  13. <swiper class="top-swiper" autoplay="true" duration="400" interval="5000" @change="swiperChange">
  14. <!-- <view class="carousel-item"><image src="../../static/img/index.png" /></view> -->
  15. <swiper-item v-for="(item, index) in carouselList" :key="index" class="carousel-item"><image :src="item.pic" /></swiper-item>
  16. </swiper>
  17. <!-- 轮播图 end -->
  18. <!-- <view class="swiper-btm flex">
  19. <view class="btm-item flex">
  20. <image src="../../static/icon/index-gou.png" mode=""></image>
  21. <view class="">自用购物返利</view>
  22. </view>
  23. <view class="btm-item flex">
  24. <image src="../../static/icon/index-gou.png" mode=""></image>
  25. <view class="">分享好友赚钱</view>
  26. </view>
  27. <view class="btm-item flex">
  28. <image src="../../static/icon/index-gou.png" mode=""></image>
  29. <view class="">超值正品优惠</view>
  30. </view>
  31. </view> -->
  32. <!-- 预约 start-->
  33. <view class="yuyue-wrap">
  34. <view class="yuyue-top flex"><image src="../../static/img/yuyue-top.png" mode="heightFix"></image></view>
  35. <view class="yuyue-item" v-for="item in list" @click="navToDetailPage(item)">
  36. <view class="share" @click.stop="share(item)">
  37. <image class="share-img" src="../../static/img/share.png" mode=""></image>
  38. <view class="share-font">分享</view>
  39. </view>
  40. <!-- <button class="share" open-type="share">
  41. <image class="share-img" src="../../static/img/share.png" mode=""></image>
  42. <view class="share-font">分享</view>
  43. </button> -->
  44. <view class="yuyue-item-left">
  45. <view class="yuyue-item-left-bg"><image src="../../static/img/index-bg.png" mode=""></image></view>
  46. <image class="yuyue-item-left-image" :src="item.image" mode=""></image>
  47. </view>
  48. <view class="yuyue-item-right">
  49. <view class="yuyue-item-title clamp2">{{ item.store_name }}</view>
  50. <view class="yuyue-item-bottom-box">
  51. <view class="yuyue-item-price">¥{{ item.price }}</view>
  52. <view class="yuyue-item-btn">立即拼团</view>
  53. </view>
  54. </view>
  55. </view>
  56. </view>
  57. <uni-popup ref="popupshare" type="center">
  58. <view class="share-box"><image :src="shareimg" mode="" class="box-img" @longpress="saveImg()"></image></view>
  59. </uni-popup>
  60. <!-- 预约 end-->
  61. <u-tabbar
  62. v-if="userInfo.user_rule == 'leader' || userInfo.user_rule == 'admin'"
  63. v-model="current"
  64. :list="tabbar"
  65. active-color="#FF4C4C"
  66. inactive-color="#666666"
  67. ></u-tabbar>
  68. <u-tabbar v-else v-model="current" :list="tabbar1" active-color="#FF4C4C" inactive-color="#666666"></u-tabbar>
  69. </view>
  70. </template>
  71. <script>
  72. import { loadIndexs } from '@/api/index.js';
  73. import { getProducts, poster } from '@/api/product.js';
  74. import { mapState, mapMutations } from 'vuex';
  75. import { saveUrl, interceptor } from '@/utils/loginUtils.js';
  76. import { tabbar, tabbar1 } from '@/utils/tabbar.js';
  77. export default {
  78. // #ifdef MP
  79. onShareAppMessage: function(res) {
  80. console.log(res);
  81. console.log('是否从按钮进入');
  82. if (res.from === 'button' || res.from === 'menu') {
  83. // 来自页面内分享按钮
  84. let pages = getCurrentPages();
  85. // 获取当前页面
  86. let page = pages[pages.length - 1];
  87. let path = '/' + page.route + '?';
  88. // 保存传值
  89. for (let i in page.options) {
  90. path += i + '=' + page.options[i] + '&';
  91. }
  92. // 保存邀请人
  93. path += 'spread=' + this.userInfo.uid;
  94. let data = {
  95. path: path,
  96. imageUrl: 'http://zhibo.liuniu946.com/uploads/attach/2021/06/20210621/f24e2d3028d95db57944e1816ec464fc.jpg',
  97. title: this.userInfo.nickname + '邀请您进入城攻闪拓项目'
  98. };
  99. return data;
  100. } else {
  101. console.log('else');
  102. }
  103. },
  104. // #endif
  105. data() {
  106. return {
  107. shareimg: '',
  108. imging: 1, //生成海报中1没有2正在运行
  109. tabbar: tabbar,
  110. tabbar1: tabbar1,
  111. current: 0,
  112. carouselList: [],
  113. list: [],
  114. swiperLength: 0,
  115. swiperCurrent: 0,
  116. goodsObjact: {
  117. percent: 1
  118. } //保存商品数据
  119. };
  120. },
  121. onShow() {
  122. let pages = getCurrentPages(); //获取加载的页面
  123. let currentPage = pages[pages.length - 1]; //获取当前页面的对象
  124. let url = currentPage.route; //当前页面url
  125. let item = currentPage.options; //如果要获取url中所带的参数可以查看options
  126. this.url = this.$store.state.baseURL + '/index/#/' + url + '?id=' + item.id + '&spread=' + this.userInfo.uid;
  127. },
  128. onReady() {
  129. let obj = this;
  130. let query = uni.createSelectorQuery();
  131. // 获取页面比例
  132. query
  133. .select('.container')
  134. .fields(
  135. {
  136. size: true
  137. },
  138. e => {
  139. // 保存比例
  140. this.ratio = e.width / 750;
  141. }
  142. )
  143. .exec();
  144. },
  145. onLoad(option) {
  146. let res = uni.getSystemInfoSync();
  147. if (option.spread) {
  148. // 存储邀请人
  149. this.spread = option.spread;
  150. uni.setStorageSync('spread', option.spread);
  151. }
  152. if (option.scene) {
  153. // 存储邀请人
  154. this.spread = option.scene;
  155. uni.setStorageSync('spread_code', option.scene);
  156. }
  157. this.loadData();
  158. },
  159. computed: {
  160. ...mapState(['userInfo', 'baseURL', 'hasLogin', 'urlFile'])
  161. },
  162. methods: {
  163. // 获取首页数据
  164. loadData() {
  165. loadIndexs({}).then(({ data }) => {
  166. this.carouselList = data.banner;
  167. });
  168. getProducts({ pages: 1, limit: 1000 }).then(({ data }) => {
  169. this.list = data;
  170. });
  171. },
  172. //轮播图跳转页面
  173. nav(item) {
  174. if (!this.hasLogin) {
  175. uni.showModal({
  176. title: '登录',
  177. content: '您未登录,是否马上登陆?',
  178. success: e => {
  179. if (e.confirm) {
  180. interceptor();
  181. }
  182. },
  183. fail: e => {
  184. console.log(e);
  185. }
  186. });
  187. return;
  188. }
  189. console.log(item);
  190. if (item.url != '/') {
  191. console.log('11111');
  192. uni.navigateTo({
  193. url: '/' + item.url,
  194. fail(error) {
  195. console.log(error);
  196. }
  197. });
  198. }
  199. },
  200. // 保存海报
  201. saveImg(w) {
  202. let obj = this;
  203. console.log(w, obj.shareimg);
  204. uni.downloadFile({
  205. //下载图片
  206. url: obj.shareimg,
  207. success: res => {
  208. console.log(res.tempFilePath);
  209. uni.saveImageToPhotosAlbum({
  210. //将图片保存在手机
  211. filePath: res.tempFilePath, //保存的位置
  212. success: res => {
  213. uni.showToast({
  214. title: '保存成功',
  215. icon: 'none'
  216. });
  217. }
  218. });
  219. }
  220. });
  221. },
  222. // 分享海报
  223. share(item) {
  224. let obj = this;
  225. if (obj.imging == 2) {
  226. return;
  227. }
  228. uni.showLoading({
  229. title: '生成海报中'
  230. });
  231. obj.imging = 2;
  232. // #ifdef H5
  233. let fromname = 'wechat';
  234. // #endif
  235. // #ifdef MP
  236. let fromname = 'routine';
  237. // #endif
  238. poster({
  239. productId: item.id,
  240. from: fromname
  241. })
  242. .then(({ data }) => {
  243. console.log(data.url);
  244. obj.shareimg = data.url;
  245. obj.imging = 1;
  246. uni.hideLoading();
  247. this.$refs.popupshare.open();
  248. })
  249. .catch(err => {
  250. obj.imging = 1;
  251. });
  252. },
  253. // 点击跳转页面
  254. navTo(url) {
  255. if (!this.hasLogin) {
  256. uni.showModal({
  257. title: '登录',
  258. content: '您未登录,是否马上登陆?',
  259. success: e => {
  260. if (e.confirm) {
  261. interceptor();
  262. }
  263. },
  264. fail: e => {
  265. console.log(e);
  266. }
  267. });
  268. return;
  269. }
  270. uni.navigateTo({
  271. url,
  272. fail(error) {
  273. uni.switchTab({
  274. url
  275. });
  276. }
  277. });
  278. },
  279. // 监听导航栏输入框点击事件
  280. onNavigationBarSearchInputClicked(e) {
  281. //跳转到搜索页面
  282. this.clickSearch();
  283. },
  284. // 點擊搜索框
  285. clickSearch() {
  286. uni.navigateTo({
  287. url: '/pages/product/search'
  288. });
  289. },
  290. //轮播图切换修改背景色
  291. swiperChange(e) {
  292. const index = e.detail.current;
  293. this.swiperCurrent = index;
  294. this.titleNViewBackground = this.carouselList[index].background;
  295. },
  296. // 跳转普通商品
  297. navToDetailPage(item) {
  298. uni.navigateTo({
  299. url: '/pages/product/product?id=' + item.id
  300. });
  301. },
  302. IndexShare() {
  303. let obj = this;
  304. let data = obj.onShareAppMessage();
  305. let item = {
  306. link: data.path, // 分享链接
  307. imgUrl: data.imgUrl,
  308. title: data.title
  309. };
  310. console.log('分享加', item);
  311. weixindata(item);
  312. }
  313. }
  314. };
  315. </script>
  316. <style lang="scss">
  317. /* #ifdef MP || APP-PLUS*/
  318. .input-box {
  319. padding: 25rpx;
  320. /* #ifdef APP-PLUS */
  321. margin-top: var(--status-bar-height);
  322. /* #endif */
  323. background-color: #fe8119;
  324. height: 44px;
  325. .iconsearch {
  326. font-size: 50rpx;
  327. }
  328. .input-content {
  329. border-radius: 99rpx;
  330. flex-grow: 1;
  331. padding: 5rpx 30rpx;
  332. // background-color: rgba(231, 231, 231, 0.7);
  333. background: #ffffff;
  334. .input {
  335. flex-grow: 1;
  336. input {
  337. font-size: $font-base;
  338. }
  339. }
  340. }
  341. .input-button {
  342. padding-left: 20rpx;
  343. font-size: $font-base;
  344. height: 100%;
  345. }
  346. }
  347. /* #endif */
  348. .top-search {
  349. height: 80rpx;
  350. padding: 0 20rpx;
  351. background-color: #fff;
  352. .top-logo {
  353. width: 50rpx;
  354. // height: 50rpx;
  355. margin-right: 10rpx;
  356. image {
  357. width: 48rpx;
  358. }
  359. }
  360. .search-box {
  361. justify-content: center;
  362. width: 698rpx;
  363. height: 60rpx;
  364. background: #eeeeee;
  365. // box-shadow: 0px 10rpx 20rpx 0px rgba(4, 114, 69, 0.22);
  366. border-radius: 30rpx;
  367. .search {
  368. width: 34rpx;
  369. height: 34rpx;
  370. }
  371. .search-font {
  372. margin-left: 14rpx;
  373. font-size: 28rpx;
  374. font-family: PingFang SC;
  375. font-weight: 500;
  376. color: #cbcbcb;
  377. }
  378. }
  379. }
  380. // 顶部轮播图
  381. .top-swiper {
  382. width: 750rpx;
  383. height: 360rpx;
  384. // margin: 20rpx 0 0;
  385. image {
  386. width: 750rpx;
  387. height: 360rpx;
  388. }
  389. }
  390. .swiper-btm {
  391. height: 60rpx;
  392. width: 750rpx;
  393. background-color: #fff;
  394. margin-bottom: 20rpx;
  395. font-size: 21rpx;
  396. font-weight: 500;
  397. color: #333333;
  398. .btm-item {
  399. flex-grow: 1;
  400. justify-content: center;
  401. image {
  402. width: 25rpx;
  403. height: 25rpx;
  404. margin-right: 14rpx;
  405. }
  406. }
  407. }
  408. /* 分类 */
  409. .cate-section {
  410. display: flex;
  411. justify-content: space-around;
  412. align-items: center;
  413. flex-wrap: wrap;
  414. padding: 30rpx 22rpx;
  415. background-color: #ffffff;
  416. .cate-item {
  417. display: flex;
  418. flex-direction: column;
  419. align-items: center;
  420. font-size: $font-sm + 2rpx;
  421. color: $font-color-dark;
  422. }
  423. /* 原图标颜色太深,不想改图了,所以加了透明度 */
  424. image {
  425. width: 88rpx;
  426. height: 88rpx;
  427. margin-bottom: 14rpx;
  428. border-radius: 50%;
  429. opacity: 0.7;
  430. }
  431. }
  432. // 为你推荐
  433. .recommend-box {
  434. background: linear-gradient(180deg, #ffffff, #f8f8f8);
  435. width: 100%;
  436. padding: 0 32rpx;
  437. }
  438. .f-header {
  439. display: flex;
  440. align-items: center;
  441. height: 92rpx;
  442. padding: 6rpx 30rpx 8rpx;
  443. border-radius: 12rpx 12rpx 0 0;
  444. color: #ffffff;
  445. background: linear-gradient(180deg, #fd4646, #ff3535);
  446. .tit-box {
  447. @extend %font-title-box;
  448. font-size: 20rpx;
  449. color: #ffffff;
  450. margin-left: 20rpx;
  451. }
  452. .iconenter {
  453. font-size: $font-lg + 2rpx;
  454. color: #ffffff;
  455. }
  456. .f-left-icon {
  457. font-size: 34rpx;
  458. border-right: 1rpx solid #ffffff;
  459. padding-right: 18rpx;
  460. }
  461. .iconfont {
  462. font-size: 26rpx;
  463. }
  464. }
  465. .guess-section {
  466. width: 100%;
  467. display: flex;
  468. flex-direction: column;
  469. background-color: #ffffff;
  470. border-radius: 0 0 12rpx 12rpx;
  471. .guess-item {
  472. display: flex;
  473. width: 100%;
  474. padding: 24rpx;
  475. border-bottom: 1rpx solid #f0f0f0;
  476. &:nth-last-child(1) {
  477. border-bottom: none;
  478. }
  479. }
  480. .image-wrapper {
  481. width: 168rpx;
  482. height: 168rpx;
  483. border-radius: 3px;
  484. image {
  485. width: 168rpx;
  486. height: 168rpx;
  487. opacity: 1;
  488. }
  489. }
  490. .info-wrapper {
  491. width: 100%;
  492. display: flex;
  493. flex-direction: column;
  494. margin-left: 20rpx;
  495. }
  496. .title {
  497. font-size: 32rpx;
  498. color: $font-color-dark;
  499. word-break: break-all;
  500. display: -webkit-box;
  501. -webkit-line-clamp: 1;
  502. -webkit-box-orient: vertical;
  503. overflow: hidden;
  504. }
  505. .price-box {
  506. margin-top: 10rpx;
  507. display: flex;
  508. justify-content: space-between;
  509. .price-left {
  510. display: flex;
  511. flex-direction: column;
  512. .price {
  513. margin-top: 8rpx;
  514. line-height: 30rpx;
  515. color: #ff0000;
  516. font-size: 40rpx;
  517. font-weight: 700;
  518. .price-tip {
  519. font-size: 28rpx;
  520. }
  521. }
  522. .ot_price {
  523. margin-top: 50rpx;
  524. line-height: 24rpx;
  525. font-size: 28rpx;
  526. margin-left: 4rpx;
  527. text-decoration: line-through;
  528. color: #aaaaaa;
  529. .price-tip {
  530. font-size: 22rpx;
  531. }
  532. }
  533. }
  534. .price-right {
  535. display: flex;
  536. flex-direction: column;
  537. .people {
  538. margin-top: 32rpx;
  539. font-weight: 700;
  540. color: #999999;
  541. font-size: 22rpx;
  542. text-align: right;
  543. margin-right: 4rpx;
  544. }
  545. .buyNow {
  546. margin-top: 68rpx;
  547. background: linear-gradient(180deg, #fd4646, #ff3535);
  548. border-radius: 26rpx;
  549. padding: 6rpx 18rpx;
  550. font-size: 26rpx;
  551. font-weight: 400;
  552. color: #ffffff;
  553. }
  554. }
  555. }
  556. }
  557. // 热销产品
  558. .hotgoodsheader {
  559. width: 100%;
  560. display: flex;
  561. justify-content: center;
  562. align-items: center;
  563. padding: 32rpx 0 24rpx;
  564. image {
  565. width: 374rpx;
  566. height: 34rpx;
  567. }
  568. }
  569. .hotgoods {
  570. width: 100%;
  571. display: flex;
  572. flex-wrap: wrap;
  573. padding: 0 32rpx 108rpx;
  574. .hotgoods-item {
  575. width: 48%;
  576. background-color: #ffffff;
  577. border-radius: 12rpx;
  578. margin-bottom: 24rpx;
  579. &:nth-child(2n + 1) {
  580. margin-right: 24rpx;
  581. }
  582. .image-wrapper {
  583. width: 100%;
  584. height: 330rpx;
  585. border-radius: 3px;
  586. overflow: hidden;
  587. image {
  588. width: 100%;
  589. height: 100%;
  590. opacity: 1;
  591. border-radius: 12rpx 12rpx 0 0;
  592. }
  593. }
  594. .title {
  595. font-size: $font-base;
  596. color: $font-color-dark;
  597. font-weight: bold;
  598. line-height: 80rpx;
  599. }
  600. .hot-price {
  601. display: flex;
  602. justify-content: space-between;
  603. padding: 0 16rpx 12rpx;
  604. .price {
  605. font-size: 40rpx;
  606. color: #ff0000;
  607. font-weight: 500;
  608. }
  609. .cart-icon {
  610. image {
  611. width: 44rpx;
  612. height: 44rpx;
  613. }
  614. }
  615. }
  616. }
  617. }
  618. .award-box {
  619. width: 100%;
  620. padding: 24rpx 24rpx 0;
  621. background: #ffffff;
  622. image {
  623. width: 100%;
  624. height: 170rpx;
  625. }
  626. }
  627. .yuyue-wrap {
  628. background-color: #fff;
  629. .yuyue-top {
  630. height: 117rpx;
  631. justify-content: center;
  632. image {
  633. display: inline-block;
  634. height: 31rpx;
  635. margin: auto;
  636. }
  637. }
  638. .yuyue-item {
  639. width: 710rpx;
  640. background: #ffffff;
  641. box-shadow: 0px 0px 20rpx 0px rgba(50, 50, 52, 0.06);
  642. border-radius: 10rpx;
  643. margin: 20rpx auto 0;
  644. padding: 20rpx 30rpx 20rpx 14rpx;
  645. position: relative;
  646. display: flex;
  647. justify-content: flex-start;
  648. .share {
  649. position: absolute;
  650. top: 0;
  651. right: 30rpx;
  652. width: 72rpx;
  653. height: 96rpx;
  654. background: linear-gradient(0deg, #fc773a, #ffa934);
  655. border-bottom-left-radius: 50rpx;
  656. border-bottom-right-radius: 50rpx;
  657. padding: 10rpx 16rpx 14rpx;
  658. line-height: 1;
  659. display: flex;
  660. flex-direction: column;
  661. justify-content: center;
  662. align-items: center;
  663. .share-img {
  664. width: 32rpx;
  665. height: 32rpx;
  666. }
  667. .share-font {
  668. margin-top: 8rpx;
  669. font-size: 20rpx;
  670. font-family: PingFang SC;
  671. font-weight: 500;
  672. color: #ffffff;
  673. }
  674. }
  675. .yuyue-item-left {
  676. position: relative;
  677. .yuyue-item-left-bg {
  678. position: absolute;
  679. z-index: 2;
  680. top: 0;
  681. right: 0;
  682. left: 0;
  683. width: 236rpx;
  684. height: 236rpx;
  685. image {
  686. width: 100%;
  687. height: 100%;
  688. }
  689. }
  690. .yuyue-item-left-image {
  691. width: 236rpx;
  692. height: 236rpx;
  693. }
  694. }
  695. .yuyue-item-right {
  696. margin-left: 22rpx;
  697. padding: 10rpx 0;
  698. display: flex;
  699. flex-direction: column;
  700. justify-content: space-between;
  701. width: 100%;
  702. .yuyue-item-title {
  703. width: 320rpx;
  704. font-size: 32rpx;
  705. font-family: PingFang SC;
  706. font-weight: bold;
  707. color: #333333;
  708. }
  709. .yuyue-item-bottom-box {
  710. display: flex;
  711. justify-content: space-between;
  712. .yuyue-item-price {
  713. font-size: 36rpx;
  714. font-family: PingFang SC;
  715. font-weight: bold;
  716. color: #ff4c4c;
  717. }
  718. .yuyue-item-btn {
  719. width: 138rpx;
  720. height: 52rpx;
  721. background: linear-gradient(90deg, #fe6f61 0%, #ff4343 100%);
  722. border-radius: 26rpx;
  723. font-size: 26rpx;
  724. font-family: PingFang SC;
  725. font-weight: 500;
  726. color: #ffffff;
  727. line-height: 52rpx;
  728. text-align: center;
  729. }
  730. }
  731. }
  732. }
  733. }
  734. .share-box {
  735. width: 600rpx;
  736. height: 1000rpx;
  737. background: red;
  738. .box-img {
  739. width: 600rpx;
  740. height: 1000rpx;
  741. }
  742. }
  743. </style>