index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566
  1. <template>
  2. <view class="container">
  3. <view class="carousel-section">
  4. <image src="../../static/img/home-top.png" mode="widthFix" class="home-top"></image>
  5. <view class="search flex">
  6. <view class="input-box flex" @click.stop="clickSearch">
  7. <view class=" input-content flex">
  8. <view class="iconfont iconsearch"></view>
  9. <view class="input"><input type="text" disabled value="输入关键字搜索" /></view>
  10. </view>
  11. </view>
  12. </view>
  13. <swiper class="carousel" autoplay="true" duration="400" interval="5000" @change="swiperChange"
  14. :indicator-dots="true" indicator-active-color="#FFFFFF">
  15. <swiper-item v-for="(item, index) in carouselList" :key="index" class="carousel-item">
  16. <image :src="item.pic" mode="aspectFill" @click="bannerNavToUrl(item)"></image>
  17. </swiper-item>
  18. </swiper>
  19. </view>
  20. <view class="top-tit">
  21. <image src="../../static/icon/fgq.png" mode="widthFix" v-if="userInfo && userInfo.pay_count >0"></image>
  22. <image src="../../static/icon/bdq.png" mode="widthFix" v-else></image>
  23. </view>
  24. <view class="good-wrap">
  25. <view class="good-img">
  26. <image :src="goodList.image" mode=""></image>
  27. <image src="../../static/img/goog-bg.png" mode=""></image>
  28. </view>
  29. <view class="good-tit clamp2">
  30. {{goodList.store_name}}
  31. </view>
  32. <view class="price-btn flex">
  33. <view class="price flex">
  34. <view class="old-price">
  35. 原价¥{{goodList.ot_price*1 || '0'}}
  36. </view>
  37. <view class="new-price" v-if="userInfo && userInfo.identity == 1">
  38. {{goodList.vip_repurchase*1 || '0'}}
  39. </view>
  40. <view class="new-price" v-if="userInfo && userInfo.identity == 2">
  41. {{goodList.agent_repurchase*1 || '0'}}
  42. </view>
  43. <view class="new-price" v-if="(!hasLogin || userInfo.identity == 0)">
  44. {{goodList.price*1 || '0'}}
  45. </view>
  46. </view>
  47. <view class="btn flex">
  48. <view class="gobuy" @click="navTo('/pages/product/product?id=' + goodList.id)">
  49. 去抢购
  50. </view>
  51. <view class="goshare" @click="getShow(goodList.id)">
  52. 去分享
  53. </view>
  54. </view>
  55. </view>
  56. <view class="" style="height: 25rpx;">
  57. </view>
  58. </view>
  59. <!-- 分享弹出窗 -->
  60. <uni-popup ref="popupshare" type="center">
  61. <view class="share-box">
  62. <image :src="shareImage" mode="" class="box-img" @longpress="saveImg()"></image>
  63. </view>
  64. </uni-popup>
  65. </view>
  66. </template>
  67. <script>
  68. import {
  69. loadIndexs
  70. } from '@/api/index.js';
  71. import {
  72. getUserInfo,
  73. spread
  74. } from '@/api/user.js';
  75. import {
  76. getBargainList,
  77. getProducts,
  78. goodsDetail,
  79. poster
  80. } from '@/api/product.js';
  81. import {
  82. interceptor
  83. } from '@/utils/loginUtils';
  84. import {
  85. mapState,
  86. mapMutations
  87. } from 'vuex';
  88. // #ifdef H5
  89. import {
  90. weixindata,
  91. shareLoad
  92. } from '@/utils/wxAuthorized';
  93. // #endif
  94. export default {
  95. data() {
  96. return {
  97. page: 1,
  98. limitt: 20,
  99. loadingType: 'more',
  100. current: 0,
  101. shareShow: false, //分享海报
  102. pageProportion: 0, //保存页面基于750宽度的比例
  103. swiperHeight: 0,
  104. checkid: 0,
  105. titleNViewBackground: '',
  106. swiperCurrent: 0,
  107. swiperLength: 0,
  108. carouselList: [], //轮播列表
  109. page: 1,
  110. limit: 5,
  111. firstList: [],
  112. goodList: {},
  113. shopList: [],
  114. period: 1,
  115. shareImage: '',
  116. };
  117. },
  118. computed: {
  119. ...mapState('user', ['hasLogin', 'userInfo'])
  120. },
  121. onShareAppMessage(options) {
  122. // 设置菜单中的转发按钮触发转发事件时的转发内容
  123. let pages = getCurrentPages(); //获取加载的页面
  124. let currentPage = pages[pages.length - 1]; //获取当前页面的对象
  125. let url = currentPage.route; //当前页面url
  126. let item = currentPage.options; //如果要获取url中所带的参数可以查看options
  127. let shareObj = {}
  128. if(this.userInfo.uid) {
  129. shareObj = {
  130. title: this.userInfo.nickname + '邀请您加入北京鸿蒙德', // 默认是小程序的名称(可以写slogan等)
  131. path: url + '?scene=' + this.userInfo.uid, // 默认是当前页面,必须是以‘/’开头的完整路径
  132. imageUrl: '',
  133. success: function(res) {
  134. // 转发成功之后的回调
  135. if (res.errMsg == 'shareAppMessage:ok') {}
  136. },
  137. fail: function() {
  138. // 转发失败之后的回调
  139. if (res.errMsg == 'shareAppMessage:fail cancel') {
  140. // 用户取消转发
  141. } else if (res.errMsg == 'shareAppMessage:fail') {
  142. // 转发失败,其中 detail message 为详细失败信息
  143. }
  144. }
  145. };
  146. }else {
  147. shareObj = {
  148. title: '北京鸿蒙德', // 默认是小程序的名称(可以写slogan等)
  149. path: url, // 默认是当前页面,必须是以‘/’开头的完整路径
  150. imageUrl: '',
  151. success: function(res) {
  152. // 转发成功之后的回调
  153. if (res.errMsg == 'shareAppMessage:ok') {}
  154. },
  155. fail: function() {
  156. // 转发失败之后的回调
  157. if (res.errMsg == 'shareAppMessage:fail cancel') {
  158. // 用户取消转发
  159. } else if (res.errMsg == 'shareAppMessage:fail') {
  160. // 转发失败,其中 detail message 为详细失败信息
  161. }
  162. }
  163. };
  164. }
  165. return shareObj;
  166. },
  167. onReachBottom() {},
  168. onLoad: function(option) {
  169. // #ifdef MP
  170. if (option.scene) {
  171. // 存储小程序邀请人
  172. uni.setStorage({
  173. key: 'spread_code',
  174. data: option.scene
  175. });
  176. }
  177. // #endif
  178. },
  179. watch: {
  180. // PXType(val, old) {
  181. // console.log('切换显示')
  182. // this.getStoreList()
  183. // },
  184. // chooseDistrict(val,old) {
  185. // this.reGetStoreList()
  186. // }
  187. },
  188. onShow: function() {
  189. this.getGoodList()
  190. this.loadData();
  191. },
  192. methods: {
  193. getShow(id) {
  194. let obj = this;
  195. uni.showLoading({
  196. title: 'Loading...',
  197. mask: true
  198. });
  199. // // #ifdef H5
  200. // let fromname = 'wechat';
  201. // // #endif
  202. // // #ifdef MP
  203. let fromname = 'routine';
  204. ////#endif
  205. poster({
  206. productId: id,
  207. from: 'routine'
  208. }).then(({data}) => {
  209. obj.shareImage = data.url;
  210. console.log(obj.shareImage, '123456');
  211. uni.hideLoading();
  212. this.$refs.popupshare.open();
  213. }).catch(err => {
  214. uni.hideLoading();
  215. })
  216. },
  217. getGoodList() {
  218. let obj = this
  219. getProducts({
  220. page: 1,
  221. limit: 50,
  222. cid: 1
  223. }).then(res => {
  224. console.log(res, 'libao')
  225. obj.goodList = res.data[0]
  226. })
  227. },
  228. navto(url) {
  229. uni.navigateTo({
  230. url,
  231. fail() {
  232. uni.switchTab({
  233. url
  234. })
  235. }
  236. })
  237. },
  238. navTo(url) {
  239. if (url == '') {
  240. this.$api.msg('暂未开通,敬请期待');
  241. } else {
  242. uni.navigateTo({
  243. url
  244. });
  245. }
  246. },
  247. // 點擊搜索框
  248. clickSearch() {
  249. uni.navigateTo({
  250. url: ''
  251. });
  252. },
  253. // 监听图片加载完成
  254. onImageError(key, index) {
  255. this[key][index].image = '/static/error/errorImage.jpg';
  256. },
  257. // 请求载入数据
  258. async loadData() {
  259. loadIndexs({})
  260. .then(({
  261. data
  262. }) => {
  263. let goods = data.info;
  264. console.log(goods, '商品信息');
  265. this.carouselList = data.banner;
  266. this.swiperLength = this.carouselList.length;
  267. this.bastList = data.giftInfo; //会员礼包
  268. data.info.firstList.forEach(e => {
  269. e.isVip = e.store_type ? "3" : "0"
  270. })
  271. this.firstList = data.info.firstList //首页商品
  272. uni.stopPullDownRefresh();
  273. })
  274. .catch(e => {
  275. uni.stopPullDownRefresh();
  276. });
  277. },
  278. //轮播图切换修改背景色
  279. swiperChange(e) {
  280. const index = e.detail.current;
  281. this.swiperCurrent = index;
  282. this.titleNViewBackground = this.carouselList[index].background;
  283. },
  284. // 轮播图跳转
  285. bannerNavToUrl(item) {
  286. // #ifdef H5
  287. console.log(item.wap_url.indexOf('http'), 'banner');
  288. if (item.wap_url.indexOf('http') >= 0) {
  289. window.location.href = item.wap_url;
  290. }
  291. // #endif
  292. //测试数据没有写id,用title代替
  293. uni.navigateTo({
  294. url: item.wap_url
  295. });
  296. },
  297. // 根据指定个数分割数组
  298. chunkArr(arr, size) {
  299. console.log(arr, 'arr+++++')
  300. //判断如果不是数组(就没有length),或者size没有传值,size小于1,就返回空数组
  301. if (!arr.length || !size || size < 1) return []
  302. let [start, end, result] = [null, null, []]
  303. for (let i = 0; i < Math.ceil(arr.length / size); i++) {
  304. start = i * size
  305. end = start + size
  306. result.push(arr.slice(start, end))
  307. }
  308. return result
  309. },
  310. // 长按保存图片
  311. saveImg(w) {
  312. console.log(w);
  313. let obj = this;
  314. uni.downloadFile({
  315. //下载图片
  316. url: obj.shareImage,
  317. success: res => {
  318. console.log(res.tempFilePath);
  319. uni.saveImageToPhotosAlbum({
  320. //将图片保存在手机
  321. filePath: res.tempFilePath, //保存的位置
  322. success: res => {
  323. uni.showToast({
  324. title: '保存成功',
  325. icon: 'none'
  326. });
  327. }
  328. });
  329. }
  330. });
  331. },
  332. }
  333. };
  334. </script>
  335. <style lang="scss">
  336. page {
  337. background: #ffff;
  338. min-height: 100%;
  339. height: auto;
  340. }
  341. .carousel-section {
  342. position: relative;
  343. // padding-top: 10px;
  344. .home-top {
  345. width: 750rpx;
  346. position: absolute;
  347. top: 0;
  348. }
  349. .bg {
  350. position: absolute;
  351. top: 0;
  352. left: 0;
  353. width: 750rpx;
  354. height: 378rpx;
  355. image {
  356. width: 100%;
  357. height: 100%;
  358. }
  359. }
  360. .titleNview-placing {
  361. height: var(--status-bar-height);
  362. box-sizing: content-box;
  363. }
  364. .search {
  365. justify-content: space-between;
  366. padding: 10rpx 32rpx 20rpx;
  367. align-items: center;
  368. // background-color: #ff5246;
  369. .address {
  370. width: 32rpx;
  371. height: 38rpx;
  372. }
  373. .shop-name {
  374. height: 38rpx;
  375. position: relative;
  376. top: -4rpx;
  377. z-index: 100;
  378. font-size: 30rpx;
  379. font-family: PingFang SC;
  380. font-weight: 500;
  381. padding-left: 10rpx;
  382. }
  383. .shop-jt {
  384. margin-left: 8rpx;
  385. width: 16rpx;
  386. height: 10rpx;
  387. }
  388. .input-box {
  389. margin-left: 10rpx;
  390. position: relative;
  391. z-index: 99;
  392. width: 650rpx;
  393. height: 60rpx;
  394. background: #EEEEEE;
  395. border-radius: 30rpx;
  396. .input-content {
  397. position: relative;
  398. z-index: 11;
  399. border-radius: 99rpx;
  400. flex-grow: 1;
  401. padding: 5rpx 30rpx;
  402. background: #fff;
  403. .iconsearch {
  404. font-size: 50rpx;
  405. color: #CBCBCB;
  406. }
  407. .input {
  408. margin-left: 19rpx;
  409. flex-grow: 1;
  410. color: #CBCBCB;
  411. input {
  412. font-size: 28rpx;
  413. color: #CBCBCB;
  414. }
  415. }
  416. }
  417. .input-button {
  418. padding-left: 20rpx;
  419. font-size: $font-base;
  420. height: 100%;
  421. }
  422. }
  423. }
  424. }
  425. .carousel {
  426. position: relative;
  427. z-index: 3;
  428. width: 100%;
  429. height: 360rpx;
  430. // background-color: #fff;
  431. .carousel-item {
  432. width: 100%;
  433. height: 100%;
  434. padding: 0 28rpx;
  435. overflow: hidden;
  436. }
  437. image {
  438. width: 100%;
  439. height: 100%;
  440. border-radius: $border-radius-sm;
  441. }
  442. }
  443. .top-tit {
  444. width: 332rpx;
  445. height: 32rpx;
  446. margin: 36rpx auto 23rpx;
  447. image {
  448. width: 332rpx;
  449. }
  450. }
  451. .good-wrap {
  452. width: 700rpx;
  453. margin: auto;
  454. background: #FFFFFF;
  455. box-shadow: 0px 0px 20px 0px rgba(50, 50, 52, 0.06);
  456. border-radius: 20px 20px 20px 20px;
  457. .good-img {
  458. width: 700rpx;
  459. height: 300rpx;
  460. position: relative;
  461. image {
  462. position: absolute;
  463. top: 0;
  464. width: 700rpx;
  465. height: 300rpx;
  466. }
  467. }
  468. .good-tit {
  469. padding: 15rpx 22rpx;
  470. font-size: 32rpx;
  471. font-weight: 500;
  472. color: #333333;
  473. }
  474. .price-btn {
  475. padding: 0 22rpx;
  476. .price {
  477. .old-price {
  478. font-size: 26rpx;
  479. font-weight: 500;
  480. text-decoration: line-through;
  481. color: #999999;
  482. }
  483. .new-price {
  484. font-size: 55rpx;
  485. font-weight: bold;
  486. color: #FF4C4C;
  487. &::before {
  488. content: '¥';
  489. font-size: 32rpx;
  490. }
  491. }
  492. }
  493. .btn {
  494. text-align: center;
  495. line-height: 53rpx;
  496. font-size: 28rpx;
  497. font-weight: bold;
  498. color: #FFFFFF;
  499. .gobuy {
  500. width: 170rpx;
  501. height: 53rpx;
  502. background: #ff5346;
  503. border-radius: 27rpx;
  504. color: #fff;
  505. margin-right: 15rpx;
  506. }
  507. .goshare {
  508. width: 129rpx;
  509. height: 53rpx;
  510. border: 2rpx solid #ff5346;
  511. background: #fff;
  512. color: #ff5346;
  513. border-radius: 27rpx;
  514. }
  515. }
  516. }
  517. }
  518. .share-box {
  519. width: 600rpx;
  520. height: 1000rpx;
  521. background: red;
  522. .box-img {
  523. width: 600rpx;
  524. height: 1000rpx;
  525. }
  526. }
  527. </style>