index.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723
  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: 100,
  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 = 100;
  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. if (obj.limit == data.list.length) {
  258. obj.loadingType = 'more'
  259. } else {
  260. obj.loadingType = 'nomore'
  261. }
  262. })
  263. },
  264. navto(url, type = 0) {
  265. if (type == 1) {
  266. if (!this.hasLogin) {
  267. // 保存地址
  268. saveUrl();
  269. // 登录拦截
  270. interceptor();
  271. } else {
  272. uni.navigateTo({
  273. url,
  274. fail() {
  275. uni.switchTab({
  276. url
  277. })
  278. }
  279. })
  280. }
  281. } else {
  282. uni.navigateTo({
  283. url,
  284. fail() {
  285. uni.switchTab({
  286. url
  287. })
  288. }
  289. })
  290. }
  291. },
  292. navTo(url) {
  293. if (url == '') {
  294. this.$api.msg('暂未开通,敬请期待');
  295. } else {
  296. this.navto(url)
  297. }
  298. },
  299. // 點擊搜索框
  300. clickSearch() {
  301. uni.navigateTo({
  302. url: '/pages/product/search'
  303. });
  304. },
  305. // 监听图片加载完成
  306. onImageError(key, index) {
  307. this[key][index].image = '/static/error/errorImage.jpg';
  308. },
  309. // 请求载入数据
  310. async loadData() {
  311. loadIndexs({})
  312. .then(({
  313. data
  314. }) => {
  315. let goods = data.info;
  316. console.log(goods, '商品信息');
  317. this.carouselList = data.banner;
  318. this.swiperLength = this.carouselList.length;
  319. // this.firstList = data.info.firstList //首页商品
  320. uni.stopPullDownRefresh();
  321. })
  322. .catch(e => {
  323. uni.stopPullDownRefresh();
  324. });
  325. },
  326. //轮播图切换修改背景色
  327. swiperChange(e) {
  328. const index = e.detail.current;
  329. this.swiperCurrent = index;
  330. this.titleNViewBackground = this.carouselList[index].background;
  331. },
  332. // 轮播图跳转
  333. bannerNavToUrl(item) {
  334. // #ifdef H5
  335. console.log(item.wap_url.indexOf('http'), 'banner');
  336. if (item.wap_url.indexOf('http') >= 0) {
  337. window.location.href = item.wap_url;
  338. }
  339. // #endif
  340. //测试数据没有写id,用title代替
  341. uni.navigateTo({
  342. url: item.wap_url
  343. });
  344. },
  345. comfirm(text) {
  346. console.log(text);
  347. const result = this.uniCopy(text);
  348. if (result === false) {
  349. uni.showToast({
  350. title: '不支持'
  351. });
  352. } else {
  353. uni.showToast({
  354. title: '复制成功',
  355. icon: 'none'
  356. });
  357. }
  358. this.$refs.popupkf.close();
  359. },
  360. uniCopy(content) {
  361. /**
  362. * 小程序端 和 app端的复制逻辑
  363. */
  364. //#ifndef H5
  365. uni.setClipboardData({
  366. data: content,
  367. success: function() {
  368. console.log('success');
  369. return true;
  370. }
  371. });
  372. //#endif
  373. /**
  374. * H5端的复制逻辑
  375. */
  376. // #ifdef H5
  377. if (!document.queryCommandSupported('copy')) {
  378. //为了兼容有些浏览器 queryCommandSupported 的判断
  379. // 不支持
  380. return false;
  381. }
  382. let textarea = document.createElement('textarea');
  383. textarea.value = content;
  384. textarea.readOnly = 'readOnly';
  385. document.body.appendChild(textarea);
  386. textarea.select(); // 选择对象
  387. textarea.setSelectionRange(0, content.length); //核心
  388. let result = document.execCommand('copy'); // 执行浏览器复制命令
  389. textarea.remove();
  390. return result;
  391. // #endif
  392. },
  393. // 打开客服
  394. openKf() {
  395. this.$refs.popupkf.open();
  396. },
  397. // 关闭客服
  398. cancel() {
  399. this.$refs.popupkf.close();
  400. },
  401. }
  402. };
  403. </script>
  404. <style lang="scss">
  405. page {
  406. min-height: 100%;
  407. height: auto;
  408. background: #ffffff;
  409. }
  410. .top-bg {
  411. position: absolute;
  412. top: 0;
  413. left: 0;
  414. right: 0;
  415. width: 750rpx;
  416. height: 346rpx;
  417. image {
  418. width: 100%;
  419. height: 100%;
  420. }
  421. }
  422. // 顶部搜索
  423. .top-search {
  424. position: relative;
  425. z-index: 2;
  426. height: 80rpx;
  427. padding: 0 20rpx;
  428. // background-color: #fff;
  429. .top-logo {
  430. width: 50rpx;
  431. // height: 50rpx;
  432. margin-right: 10rpx;
  433. image {
  434. width: 48rpx;
  435. }
  436. }
  437. .search-box {
  438. justify-content: center;
  439. width: 698rpx;
  440. height: 60rpx;
  441. background: rgba(#ffffff, 0.47);
  442. box-shadow: 0rpx 9rpx 21rpx 0rpx rgba(4, 114, 69, 0.22);
  443. border-radius: 30rpx;
  444. .search {
  445. width: 34rpx;
  446. height: 34rpx;
  447. }
  448. .search-font {
  449. margin-left: 14rpx;
  450. font-size: 28rpx;
  451. font-family: PingFang SC;
  452. font-weight: 500;
  453. color: #FFFFFF;
  454. }
  455. }
  456. }
  457. // 顶部轮播图
  458. .top-swiper {
  459. margin: 20rpx auto 0;
  460. width: 700rpx;
  461. border-radius: 14rpx;
  462. image {
  463. width: 700rpx;
  464. height: 300rpx;
  465. }
  466. }
  467. .swiper-btm {
  468. height: 60rpx;
  469. width: 750rpx;
  470. background-color: #fff;
  471. margin-bottom: 20rpx;
  472. font-size: 26rpx;
  473. font-weight: 500;
  474. color: #333333;
  475. .btm-item {
  476. flex-grow: 1;
  477. justify-content: center;
  478. image {
  479. width: 25rpx;
  480. height: 25rpx;
  481. margin-right: 14rpx;
  482. }
  483. }
  484. }
  485. .jg {
  486. height: 20rpx;
  487. background: #F8F8F8;
  488. }
  489. // 分类
  490. .cate-section {
  491. justify-content: space-around;
  492. background-color: #fff;
  493. padding: 30rpx 0 30rpx;
  494. .cate-item {
  495. flex-grow: 0;
  496. width: 20%;
  497. flex-direction: column;
  498. text-align: center;
  499. align-items: center;
  500. justify-content: center;
  501. .img-wrapper {
  502. width: 100rpx;
  503. height: 100rpx;
  504. border-radius: 20rpx;
  505. position: relative;
  506. image {
  507. width: 100%;
  508. height: 100%;
  509. position: absolute;
  510. left: 50%;
  511. top: 50%;
  512. transform: translate(-50%, -50%);
  513. }
  514. }
  515. .item-title {
  516. margin-top: 15rpx;
  517. font-size: 24rpx;
  518. font-weight: 500;
  519. color: #333333;
  520. }
  521. }
  522. }
  523. .popup-box {
  524. width: 522rpx;
  525. height: 605rpx;
  526. background-color: #ffffff;
  527. border-radius: 20rpx;
  528. position: relative;
  529. .img {
  530. position: relative;
  531. top: -56rpx;
  532. left: 0;
  533. width: 522rpx;
  534. height: 132rpx;
  535. display: flex;
  536. justify-content: center;
  537. image {
  538. border-radius: 20rpx 20rpx 0 0;
  539. width: 450rpx;
  540. height: 132rpx;
  541. }
  542. }
  543. .mian {
  544. margin-top: -44rpx;
  545. display: flex;
  546. flex-direction: column;
  547. align-items: center;
  548. // padding: 32rpx 32rpx;
  549. background-color: #ffffff;
  550. border-radius: 0 0 20rpx 20rpx;
  551. text-align: center;
  552. .delivery {
  553. font-size: 40rpx;
  554. color: #333333;
  555. display: flex;
  556. align-items: center;
  557. flex-direction: column;
  558. image {
  559. margin-top: 48rpx;
  560. width: 172rpx;
  561. height: 160rpx;
  562. }
  563. }
  564. .nocancel {
  565. font-size: 32rpx;
  566. color: #333333;
  567. margin-top: 14rpx;
  568. }
  569. .comfirm-box {
  570. margin-top: 52rpx;
  571. display: flex;
  572. // margin-bottom: 32rpx;
  573. // justify-content: space-around;
  574. .cancel {
  575. display: flex;
  576. align-items: center;
  577. justify-content: center;
  578. width: 197rpx;
  579. height: 74rpx;
  580. border: 1px solid #dcc786;
  581. border-radius: 38rpx;
  582. font-size: 32rpx;
  583. color: #605128;
  584. }
  585. .comfirm {
  586. margin-left: 32rpx;
  587. display: flex;
  588. align-items: center;
  589. justify-content: center;
  590. width: 197rpx;
  591. height: 74rpx;
  592. background: linear-gradient(-90deg, #d1ba77 0%, #f7e8ad 100%);
  593. border-radius: 38px;
  594. font-size: 32rpx;
  595. color: #605128;
  596. }
  597. }
  598. }
  599. }
  600. .jhq {
  601. margin: 0 auto;
  602. width: 750rpx;
  603. image {
  604. width: 100%;
  605. }
  606. }
  607. .goodsList {
  608. background: #FFFFFF;
  609. padding-top: 41rpx;
  610. .goodsList-title {
  611. margin: 0 auto 32rpx;
  612. width: 376rpx;
  613. height: 34rpx;
  614. image {
  615. width: 100%;
  616. height: 100%;
  617. }
  618. }
  619. }
  620. .goodsList-box {
  621. background: #FFFFFF;
  622. padding: 26rpx 20rpx 20rpx;
  623. flex-wrap: wrap;
  624. .goodsList-item {
  625. width: 345rpx;
  626. background-color: #ffffff;
  627. border-radius: 12rpx;
  628. box-shadow: 0 0 15rpx rgba(0, 0, 0, 0.2);
  629. margin-bottom: 20rpx;
  630. .image-wrapper {
  631. width: 345rpx;
  632. height: 345rpx;
  633. border-radius: 3px;
  634. position: relative;
  635. .image {
  636. width: 100%;
  637. height: 100%;
  638. opacity: 1;
  639. border-radius: 12rpx 12rpx 0 0;
  640. }
  641. }
  642. .title {
  643. margin-top: 24rpx;
  644. padding: 0 20rpx;
  645. font-size: 32rpx;
  646. font-weight: 500;
  647. color: #333333;
  648. }
  649. .hot-price {
  650. display: flex;
  651. justify-content: flex-start;
  652. align-items: center;
  653. .price {
  654. margin-left: 10rpx;
  655. font-size: 36rpx;
  656. color: #9C0B18;
  657. font-weight: 500;
  658. display: flex;
  659. justify-content: flex-start;
  660. align-items: center;
  661. .ot-price {
  662. margin-left: 7rpx;
  663. font-size: 26rpx;
  664. font-weight: 500;
  665. text-decoration: line-through;
  666. color: #999999;
  667. }
  668. }
  669. }
  670. }
  671. }
  672. </style>