index.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724
  1. <template>
  2. <view class="container">
  3. <!-- 顶部logo and 搜索 start-->
  4. <view class="status_bar"></view>
  5. <view class="top-bg">
  6. <image src="../../static/img/index-bg.png" mode=""></image>
  7. </view>
  8. <view class="top-search flex">
  9. <view class="search-box flex" @click="clickSearch()">
  10. <image class="search" src="../../static/icon/search-h.png" mode=""></image>
  11. <view class="search-font">输入关键词搜索</view>
  12. </view>
  13. </view>
  14. <!-- 顶部logo and 搜索 end-->
  15. <view class="jg" style="background-color: #fff;"></view>
  16. <!-- 轮播图 start -->
  17. <swiper class="top-swiper" autoplay="true" duration="400" interval="5000" @change="swiperChange">
  18. <swiper-item v-for="(item, index) in carouselList" :key="index" class="carousel-item"
  19. @click="bannerNavToUrl(item)">
  20. <image :src="item.pic" />
  21. </swiper-item>
  22. </swiper>
  23. <!-- 轮播图 end -->
  24. <!-- 分类 start -->
  25. <view class="cate-section flex">
  26. <view class="cate-item flex" @click="navto('/pages/category/category')">
  27. <view class="img-wrapper flex">
  28. <image src="../../static/icon/in1.png" mode=""></image>
  29. </view>
  30. <view class="item-title">全部商品</view>
  31. </view>
  32. <view class="cate-item flex" @click="navto('/pages/index/artDetail?id=1')">
  33. <view class="img-wrapper flex">
  34. <image src="../../static/icon/in2.png" mode=""></image>
  35. </view>
  36. <view class="item-title">公司介绍</view>
  37. </view>
  38. <view class="cate-item flex" @click="navTo('/pages/product/classify?type=3')">
  39. <view class="img-wrapper flex">
  40. <image src="../../static/icon/in5.png" mode=""></image>
  41. </view>
  42. <view class="item-title">爆款区</view>
  43. </view>
  44. <view class="cate-item flex" @click="openKf">
  45. <view class="img-wrapper flex">
  46. <image src="../../static/icon/in3.png" mode=""></image>
  47. </view>
  48. <view class="item-title">联系客服</view>
  49. </view>
  50. <view class="cate-item flex" @click="navto('/pages/user/shareQrCode',1)">
  51. <view class="img-wrapper flex">
  52. <image src="../../static/icon/in4.png" mode=""></image>
  53. </view>
  54. <view class="item-title">邀请有礼</view>
  55. </view>
  56. </view>
  57. <!-- 分类 ed -->
  58. <!-- 进货商品列表 start -->
  59. <view v-if="userInfo && userInfo. is_power == 1" class="jhq" @click="navTo('/pages/product/classify?type=2')">
  60. <image src="../../static/img/jhq.png" mode="widthFix">
  61. </image>
  62. </view>
  63. <!-- 进货商品列表 ed-->
  64. <view class="jg"></view>
  65. <!-- 普通商品列表start -->
  66. <view class="goodsList">
  67. <view class="goodsList-title">
  68. <image src="../../static/icon/title.png" mode=""></image>
  69. </view>
  70. <view class="goodsList-box flex">
  71. <view class="goodsList-item" :key="ind" v-for="(ls, ind) in firstList"
  72. @click="navTo('/pages/product/product?id=' + ls.id)">
  73. <view class="image-wrapper">
  74. <image class="image" :src="ls.image" mode=" scaleToFill"></image>
  75. </view>
  76. <view class="title clamp2">
  77. {{ ls.store_name }}
  78. </view>
  79. <view class="hot-price">
  80. <view class="price">
  81. ¥{{ ls.price * 1 }}
  82. <text class="ot-price" v-if="ls.ot_price*1>ls.price*1">¥{{ls.ot_price}}</text>
  83. </view>
  84. </view>
  85. </view>
  86. </view>
  87. </view>
  88. <!-- 普通商品列表end -->
  89. <uni-popup ref="popupkf" type="center">
  90. <view class="popup-box">
  91. <view class="img">
  92. <image src="../../static/img/img009.png" mode=""></image>
  93. </view>
  94. <view class="mian">
  95. <view class="delivery">
  96. <view class="title">已经为您定制专属客服</view>
  97. <image src="../../static/img/img010.png" mode=""></image>
  98. </view>
  99. <view class="nocancel">客服VX:{{ text }}</view>
  100. <view class="comfirm-box">
  101. <view class="cancel" @click="cancel">取消</view>
  102. <view class="comfirm" @click="comfirm(text)">复制微信</view>
  103. </view>
  104. </view>
  105. </view>
  106. </uni-popup>
  107. </view>
  108. </template>
  109. <script>
  110. import {
  111. loadIndexs,
  112. groom
  113. } from '@/api/index.js';
  114. import {
  115. getUserInfo,
  116. spread
  117. } from '@/api/user.js';
  118. import {
  119. getBargainList,
  120. getProducts,
  121. goodsDetail,
  122. poster
  123. } from '@/api/product.js';
  124. import {
  125. saveUrl,
  126. interceptor
  127. } from '@/utils/loginUtils';
  128. import {
  129. mapState,
  130. mapMutations
  131. } from 'vuex';
  132. // #ifdef H5
  133. import {
  134. weixindata,
  135. shareLoad
  136. } from '@/utils/wxAuthorized';
  137. // #endif
  138. export default {
  139. data() {
  140. return {
  141. text: '', //客服微信
  142. current: 0,
  143. swiperHeight: 0,
  144. checkid: 0,
  145. titleNViewBackground: '',
  146. swiperCurrent: 0,
  147. swiperLength: 0,
  148. carouselList: [], //轮播列表
  149. page: 1,
  150. limit: 10,
  151. loadingType: 'more',
  152. firstList: [],
  153. shareImage: '',
  154. };
  155. },
  156. computed: {
  157. ...mapState('user', ['hasLogin', 'userInfo'])
  158. },
  159. onShareAppMessage(options) {
  160. // 设置菜单中的转发按钮触发转发事件时的转发内容
  161. let pages = getCurrentPages(); //获取加载的页面
  162. let currentPage = pages[pages.length - 1]; //获取当前页面的对象
  163. let url = currentPage.route; //当前页面url
  164. let item = currentPage.options; //如果要获取url中所带的参数可以查看options
  165. let shareObj = {}
  166. if (this.userInfo.uid) {
  167. shareObj = {
  168. title: this.userInfo.nickname + '邀请您加入华中康新堂', // 默认是小程序的名称(可以写slogan等)
  169. path: url + '?scene=' + this.userInfo.uid, // 默认是当前页面,必须是以‘/’开头的完整路径
  170. imageUrl: '',
  171. success: function(res) {
  172. // 转发成功之后的回调
  173. if (res.errMsg == 'shareAppMessage:ok') {}
  174. },
  175. fail: function() {
  176. // 转发失败之后的回调
  177. if (res.errMsg == 'shareAppMessage:fail cancel') {
  178. // 用户取消转发
  179. } else if (res.errMsg == 'shareAppMessage:fail') {
  180. // 转发失败,其中 detail message 为详细失败信息
  181. }
  182. }
  183. };
  184. } else {
  185. shareObj = {
  186. title: '华中康新堂', // 默认是小程序的名称(可以写slogan等)
  187. path: url, // 默认是当前页面,必须是以‘/’开头的完整路径
  188. imageUrl: '',
  189. success: function(res) {
  190. // 转发成功之后的回调
  191. if (res.errMsg == 'shareAppMessage:ok') {}
  192. },
  193. fail: function() {
  194. // 转发失败之后的回调
  195. if (res.errMsg == 'shareAppMessage:fail cancel') {
  196. // 用户取消转发
  197. } else if (res.errMsg == 'shareAppMessage:fail') {
  198. // 转发失败,其中 detail message 为详细失败信息
  199. }
  200. }
  201. };
  202. }
  203. return shareObj;
  204. },
  205. onReachBottom() {
  206. this.getgroom();
  207. },
  208. onLoad: function(option) {
  209. // #ifdef MP
  210. if (option.scene) {
  211. // 存储小程序邀请人
  212. uni.setStorage({
  213. key: 'spread_code',
  214. data: option.scene
  215. });
  216. }
  217. // #endif
  218. },
  219. onShow: function() {
  220. this.page = 1;
  221. this.limit = 10;
  222. this.loadingType = 'more';
  223. this.firstList = []
  224. this.loadData();
  225. this.getgroom();
  226. if (this.hasLogin) {
  227. this.getuser()
  228. }
  229. },
  230. methods: {
  231. ...mapMutations('user', ['setUserInfo']),
  232. getuser() {
  233. getUserInfo({})
  234. .then(({
  235. data
  236. }) => {
  237. this.setUserInfo(data);
  238. })
  239. .catch(e => {
  240. console.log(e);
  241. });
  242. },
  243. getgroom() {
  244. const obj = this
  245. if (obj.loadingType == 'nomore' || obj.loadingType == 'loading') {
  246. return
  247. }
  248. obj.loadingType = 'loading'
  249. groom({
  250. page: this.page,
  251. limit: this.limit
  252. }, 3).then(({
  253. data
  254. }) => {
  255. console.log(data, '123456');
  256. obj.firstList = obj.firstList.concat(data.list)
  257. obj.page++
  258. if (obj.limit == data.list.length) {
  259. obj.loadingType = 'more'
  260. } else {
  261. obj.loadingType = 'nomore'
  262. }
  263. })
  264. },
  265. navto(url, type = 0) {
  266. if (type == 1) {
  267. if (!this.hasLogin) {
  268. // 保存地址
  269. saveUrl();
  270. // 登录拦截
  271. interceptor();
  272. } else {
  273. uni.navigateTo({
  274. url,
  275. fail() {
  276. uni.switchTab({
  277. url
  278. })
  279. }
  280. })
  281. }
  282. } else {
  283. uni.navigateTo({
  284. url,
  285. fail() {
  286. uni.switchTab({
  287. url
  288. })
  289. }
  290. })
  291. }
  292. },
  293. navTo(url) {
  294. if (url == '') {
  295. this.$api.msg('暂未开通,敬请期待');
  296. } else {
  297. this.navto(url)
  298. }
  299. },
  300. // 點擊搜索框
  301. clickSearch() {
  302. uni.navigateTo({
  303. url: '/pages/product/search'
  304. });
  305. },
  306. // 监听图片加载完成
  307. onImageError(key, index) {
  308. this[key][index].image = '/static/error/errorImage.jpg';
  309. },
  310. // 请求载入数据
  311. async loadData() {
  312. loadIndexs({})
  313. .then(({
  314. data
  315. }) => {
  316. let goods = data.info;
  317. console.log(goods, '商品信息');
  318. this.carouselList = data.banner;
  319. this.swiperLength = this.carouselList.length;
  320. // this.firstList = data.info.firstList //首页商品
  321. uni.stopPullDownRefresh();
  322. })
  323. .catch(e => {
  324. uni.stopPullDownRefresh();
  325. });
  326. },
  327. //轮播图切换修改背景色
  328. swiperChange(e) {
  329. const index = e.detail.current;
  330. this.swiperCurrent = index;
  331. this.titleNViewBackground = this.carouselList[index].background;
  332. },
  333. // 轮播图跳转
  334. bannerNavToUrl(item) {
  335. // #ifdef H5
  336. console.log(item.wap_url.indexOf('http'), 'banner');
  337. if (item.wap_url.indexOf('http') >= 0) {
  338. window.location.href = item.wap_url;
  339. }
  340. // #endif
  341. //测试数据没有写id,用title代替
  342. uni.navigateTo({
  343. url: item.wap_url
  344. });
  345. },
  346. comfirm(text) {
  347. console.log(text);
  348. const result = this.uniCopy(text);
  349. if (result === false) {
  350. uni.showToast({
  351. title: '不支持'
  352. });
  353. } else {
  354. uni.showToast({
  355. title: '复制成功',
  356. icon: 'none'
  357. });
  358. }
  359. this.$refs.popupkf.close();
  360. },
  361. uniCopy(content) {
  362. /**
  363. * 小程序端 和 app端的复制逻辑
  364. */
  365. //#ifndef H5
  366. uni.setClipboardData({
  367. data: content,
  368. success: function() {
  369. console.log('success');
  370. return true;
  371. }
  372. });
  373. //#endif
  374. /**
  375. * H5端的复制逻辑
  376. */
  377. // #ifdef H5
  378. if (!document.queryCommandSupported('copy')) {
  379. //为了兼容有些浏览器 queryCommandSupported 的判断
  380. // 不支持
  381. return false;
  382. }
  383. let textarea = document.createElement('textarea');
  384. textarea.value = content;
  385. textarea.readOnly = 'readOnly';
  386. document.body.appendChild(textarea);
  387. textarea.select(); // 选择对象
  388. textarea.setSelectionRange(0, content.length); //核心
  389. let result = document.execCommand('copy'); // 执行浏览器复制命令
  390. textarea.remove();
  391. return result;
  392. // #endif
  393. },
  394. // 打开客服
  395. openKf() {
  396. this.$refs.popupkf.open();
  397. },
  398. // 关闭客服
  399. cancel() {
  400. this.$refs.popupkf.close();
  401. },
  402. }
  403. };
  404. </script>
  405. <style lang="scss">
  406. page {
  407. min-height: 100%;
  408. height: auto;
  409. background: #ffffff;
  410. }
  411. .top-bg {
  412. position: absolute;
  413. top: 0;
  414. left: 0;
  415. right: 0;
  416. width: 750rpx;
  417. height: 346rpx;
  418. image {
  419. width: 100%;
  420. height: 100%;
  421. }
  422. }
  423. // 顶部搜索
  424. .top-search {
  425. position: relative;
  426. z-index: 2;
  427. height: 80rpx;
  428. padding: 0 20rpx;
  429. // background-color: #fff;
  430. .top-logo {
  431. width: 50rpx;
  432. // height: 50rpx;
  433. margin-right: 10rpx;
  434. image {
  435. width: 48rpx;
  436. }
  437. }
  438. .search-box {
  439. justify-content: center;
  440. width: 698rpx;
  441. height: 60rpx;
  442. background: rgba(#ffffff, 0.47);
  443. box-shadow: 0rpx 9rpx 21rpx 0rpx rgba(4, 114, 69, 0.22);
  444. border-radius: 30rpx;
  445. .search {
  446. width: 34rpx;
  447. height: 34rpx;
  448. }
  449. .search-font {
  450. margin-left: 14rpx;
  451. font-size: 28rpx;
  452. font-family: PingFang SC;
  453. font-weight: 500;
  454. color: #FFFFFF;
  455. }
  456. }
  457. }
  458. // 顶部轮播图
  459. .top-swiper {
  460. margin: 20rpx auto 0;
  461. width: 700rpx;
  462. border-radius: 14rpx;
  463. image {
  464. width: 700rpx;
  465. height: 300rpx;
  466. }
  467. }
  468. .swiper-btm {
  469. height: 60rpx;
  470. width: 750rpx;
  471. background-color: #fff;
  472. margin-bottom: 20rpx;
  473. font-size: 26rpx;
  474. font-weight: 500;
  475. color: #333333;
  476. .btm-item {
  477. flex-grow: 1;
  478. justify-content: center;
  479. image {
  480. width: 25rpx;
  481. height: 25rpx;
  482. margin-right: 14rpx;
  483. }
  484. }
  485. }
  486. .jg {
  487. height: 20rpx;
  488. background: #F8F8F8;
  489. }
  490. // 分类
  491. .cate-section {
  492. justify-content: space-around;
  493. background-color: #fff;
  494. padding: 30rpx 0 30rpx;
  495. .cate-item {
  496. flex-grow: 0;
  497. width: 20%;
  498. flex-direction: column;
  499. text-align: center;
  500. align-items: center;
  501. justify-content: center;
  502. .img-wrapper {
  503. width: 100rpx;
  504. height: 100rpx;
  505. border-radius: 20rpx;
  506. position: relative;
  507. image {
  508. width: 100%;
  509. height: 100%;
  510. position: absolute;
  511. left: 50%;
  512. top: 50%;
  513. transform: translate(-50%, -50%);
  514. }
  515. }
  516. .item-title {
  517. margin-top: 15rpx;
  518. font-size: 24rpx;
  519. font-weight: 500;
  520. color: #333333;
  521. }
  522. }
  523. }
  524. .popup-box {
  525. width: 522rpx;
  526. height: 605rpx;
  527. background-color: #ffffff;
  528. border-radius: 20rpx;
  529. position: relative;
  530. .img {
  531. position: relative;
  532. top: -56rpx;
  533. left: 0;
  534. width: 522rpx;
  535. height: 132rpx;
  536. display: flex;
  537. justify-content: center;
  538. image {
  539. border-radius: 20rpx 20rpx 0 0;
  540. width: 450rpx;
  541. height: 132rpx;
  542. }
  543. }
  544. .mian {
  545. margin-top: -44rpx;
  546. display: flex;
  547. flex-direction: column;
  548. align-items: center;
  549. // padding: 32rpx 32rpx;
  550. background-color: #ffffff;
  551. border-radius: 0 0 20rpx 20rpx;
  552. text-align: center;
  553. .delivery {
  554. font-size: 40rpx;
  555. color: #333333;
  556. display: flex;
  557. align-items: center;
  558. flex-direction: column;
  559. image {
  560. margin-top: 48rpx;
  561. width: 172rpx;
  562. height: 160rpx;
  563. }
  564. }
  565. .nocancel {
  566. font-size: 32rpx;
  567. color: #333333;
  568. margin-top: 14rpx;
  569. }
  570. .comfirm-box {
  571. margin-top: 52rpx;
  572. display: flex;
  573. // margin-bottom: 32rpx;
  574. // justify-content: space-around;
  575. .cancel {
  576. display: flex;
  577. align-items: center;
  578. justify-content: center;
  579. width: 197rpx;
  580. height: 74rpx;
  581. border: 1px solid #dcc786;
  582. border-radius: 38rpx;
  583. font-size: 32rpx;
  584. color: #605128;
  585. }
  586. .comfirm {
  587. margin-left: 32rpx;
  588. display: flex;
  589. align-items: center;
  590. justify-content: center;
  591. width: 197rpx;
  592. height: 74rpx;
  593. background: linear-gradient(-90deg, #d1ba77 0%, #f7e8ad 100%);
  594. border-radius: 38px;
  595. font-size: 32rpx;
  596. color: #605128;
  597. }
  598. }
  599. }
  600. }
  601. .jhq {
  602. margin: 0 auto;
  603. width: 750rpx;
  604. image {
  605. width: 100%;
  606. }
  607. }
  608. .goodsList {
  609. background: #FFFFFF;
  610. padding-top: 41rpx;
  611. .goodsList-title {
  612. margin: 0 auto 32rpx;
  613. width: 376rpx;
  614. height: 34rpx;
  615. image {
  616. width: 100%;
  617. height: 100%;
  618. }
  619. }
  620. }
  621. .goodsList-box {
  622. background: #FFFFFF;
  623. padding: 26rpx 20rpx 20rpx;
  624. flex-wrap: wrap;
  625. .goodsList-item {
  626. width: 345rpx;
  627. background-color: #ffffff;
  628. border-radius: 12rpx;
  629. box-shadow: 0 0 15rpx rgba(0, 0, 0, 0.2);
  630. margin-bottom: 20rpx;
  631. .image-wrapper {
  632. width: 345rpx;
  633. height: 345rpx;
  634. border-radius: 3px;
  635. position: relative;
  636. .image {
  637. width: 100%;
  638. height: 100%;
  639. opacity: 1;
  640. border-radius: 12rpx 12rpx 0 0;
  641. }
  642. }
  643. .title {
  644. margin-top: 24rpx;
  645. padding: 0 20rpx;
  646. font-size: 32rpx;
  647. font-weight: 500;
  648. color: #333333;
  649. }
  650. .hot-price {
  651. display: flex;
  652. justify-content: flex-start;
  653. align-items: center;
  654. .price {
  655. margin-left: 10rpx;
  656. font-size: 36rpx;
  657. color: #9C0B18;
  658. font-weight: 500;
  659. display: flex;
  660. justify-content: flex-start;
  661. align-items: center;
  662. .ot-price {
  663. margin-left: 7rpx;
  664. font-size: 26rpx;
  665. font-weight: 500;
  666. text-decoration: line-through;
  667. color: #999999;
  668. }
  669. }
  670. }
  671. }
  672. }
  673. </style>