index.vue 15 KB

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