index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466
  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" indicator-dots
  13. indicator-active-color="#ea3855">
  14. <swiper-item v-for="(item, index) in carouselList" :key="index" class="carousel-item"
  15. @click="bannerNavToUrl(item)">
  16. <image :src="item.pic" />
  17. </swiper-item>
  18. </swiper>
  19. <!-- 轮播图 end -->
  20. <view class="jg">
  21. </view>
  22. <view class="good-list">
  23. <view class="good" v-for="item in goodList" @click="navTo('/pages/product/product?id=' + item.id)">
  24. <image :src="item.image" mode=""></image>
  25. </view>
  26. </view>
  27. <view class="jg">
  28. </view>
  29. <view class="art-box flex" v-if="shopList.length !=0">
  30. <view class="art-item" v-for="item in shopList" @click="navTo('/pages/product/product?id=' + item.id)">
  31. <image :src="item.image" mode=""></image>
  32. </view>
  33. </view>
  34. <view class="jg" v-if="shopList.length !=0">
  35. </view>
  36. <view class="good-list">
  37. <view class="good">
  38. <image @click="navTo('/pages/index/artDetail?id=1')" src="https://xyl.liuniukj.com/computent.png">
  39. </image>
  40. </view>
  41. <view class="good">
  42. <image @click="navTo('/pages/index/artDetail?id=3')" src="https://xyl.liuniukj.com/product.png">
  43. </image>
  44. </view>
  45. </view>
  46. </view>
  47. </template>
  48. <script>
  49. import {
  50. loadIndexs,
  51. groom1
  52. } from '@/api/index.js';
  53. import {
  54. getUserInfo,
  55. spread,
  56. // getArtList
  57. } from '@/api/user.js';
  58. import {
  59. getProducts,
  60. } from '@/api/product.js';
  61. import {
  62. saveUrl,
  63. interceptor
  64. } from '@/utils/loginUtils';
  65. import {
  66. mapState,
  67. mapMutations
  68. } from 'vuex';
  69. // #ifdef H5
  70. import {
  71. weixindata,
  72. shareLoad
  73. } from '@/utils/wxAuthorized';
  74. // #endif
  75. export default {
  76. data() {
  77. return {
  78. text: '', //客服微信
  79. page: 1,
  80. limitt: 20,
  81. loadingType: 'more',
  82. current: 0,
  83. shareShow: false, //分享海报
  84. pageProportion: 0, //保存页面基于750宽度的比例
  85. swiperHeight: 0,
  86. checkid: 0,
  87. titleNViewBackground: '',
  88. swiperCurrent: 0,
  89. swiperLength: 0,
  90. carouselList: [], //轮播列表
  91. page: 1,
  92. limit: 5,
  93. firstList: [],
  94. goodList: [], //商品列表
  95. shopList: [],
  96. period: 1,
  97. shareImage: '',
  98. fgList: '', //复购商品
  99. };
  100. },
  101. computed: {
  102. ...mapState('user', ['hasLogin', 'userInfo'])
  103. },
  104. onShareAppMessage(options) {
  105. // 设置菜单中的转发按钮触发转发事件时的转发内容
  106. let pages = getCurrentPages(); //获取加载的页面
  107. let currentPage = pages[pages.length - 1]; //获取当前页面的对象
  108. let url = currentPage.route; //当前页面url
  109. let item = currentPage.options; //如果要获取url中所带的参数可以查看options
  110. let shareObj = {}
  111. if (this.userInfo.uid) {
  112. shareObj = {
  113. title: this.userInfo.nickname + '邀请您加入芯悦澜', // 默认是小程序的名称(可以写slogan等)
  114. path: url + '?scene=' + this.userInfo.uid, // 默认是当前页面,必须是以‘/’开头的完整路径
  115. imageUrl: '',
  116. success: function(res) {
  117. // 转发成功之后的回调
  118. if (res.errMsg == 'shareAppMessage:ok') {}
  119. },
  120. fail: function() {
  121. // 转发失败之后的回调
  122. if (res.errMsg == 'shareAppMessage:fail cancel') {
  123. // 用户取消转发
  124. } else if (res.errMsg == 'shareAppMessage:fail') {
  125. // 转发失败,其中 detail message 为详细失败信息
  126. }
  127. }
  128. };
  129. } else {
  130. shareObj = {
  131. title: '芯悦澜', // 默认是小程序的名称(可以写slogan等)
  132. path: url, // 默认是当前页面,必须是以‘/’开头的完整路径
  133. imageUrl: '',
  134. success: function(res) {
  135. // 转发成功之后的回调
  136. if (res.errMsg == 'shareAppMessage:ok') {}
  137. },
  138. fail: function() {
  139. // 转发失败之后的回调
  140. if (res.errMsg == 'shareAppMessage:fail cancel') {
  141. // 用户取消转发
  142. } else if (res.errMsg == 'shareAppMessage:fail') {
  143. // 转发失败,其中 detail message 为详细失败信息
  144. }
  145. }
  146. };
  147. }
  148. return shareObj;
  149. },
  150. // onReachBottom() {
  151. // console.log('到底')
  152. // this.getGoodList()
  153. // },
  154. onLoad: function(option) {
  155. // #ifdef MP
  156. if (option.scene) {
  157. // 存储小程序邀请人
  158. uni.setStorage({
  159. key: 'spread_code',
  160. data: option.scene
  161. });
  162. uni.setStorage({
  163. key: 'spread',
  164. data: option.scene
  165. });
  166. }
  167. // #endif
  168. if (option.spread) {
  169. uni.setStorage({
  170. key: 'spread',
  171. data: option.spread
  172. });
  173. }
  174. },
  175. onShow: function() {
  176. this.getGoodList()
  177. this.loadData();
  178. this.groom1()
  179. },
  180. methods: {
  181. //获取复购商品
  182. groom1() {
  183. getProducts({
  184. page: 1,
  185. limit: 1000,
  186. type: 2
  187. }).then(res => {
  188. console.log(res, '123456')
  189. this.shopList = res.data
  190. })
  191. },
  192. getGoodList() {
  193. let obj = this
  194. // if (obj.loadingType == 'loading' || obj.loadingType == 'noMore') {
  195. // return
  196. // }
  197. // obj.loadingType = 'loading'
  198. getProducts({
  199. page: 1,
  200. limit: 1000,
  201. type: 1
  202. }).then(res => {
  203. console.log(res)
  204. obj.goodList = res.data
  205. if (obj.limit == res.data.length) {
  206. obj.loadingType = 'more'
  207. } else {
  208. obj.loadingType = 'noMore'
  209. }
  210. })
  211. },
  212. navto(url, type = 0) {
  213. if (type == 1) {
  214. if (!this.hasLogin) {
  215. // 保存地址
  216. saveUrl();
  217. // 登录拦截
  218. interceptor();
  219. } else {
  220. uni.navigateTo({
  221. url,
  222. fail() {
  223. uni.switchTab({
  224. url
  225. })
  226. }
  227. })
  228. }
  229. } else {
  230. uni.navigateTo({
  231. url,
  232. fail() {
  233. uni.switchTab({
  234. url
  235. })
  236. }
  237. })
  238. }
  239. },
  240. navTo(url) {
  241. if (url == '') {
  242. this.$api.msg('暂未开通,敬请期待');
  243. } else {
  244. this.navto(url)
  245. }
  246. },
  247. // 點擊搜索框
  248. clickSearch() {
  249. uni.navigateTo({
  250. url: '/pages/product/search'
  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. comfirm(text) {
  298. console.log(text);
  299. const result = this.uniCopy(text);
  300. if (result === false) {
  301. uni.showToast({
  302. title: '不支持'
  303. });
  304. } else {
  305. uni.showToast({
  306. title: '复制成功',
  307. icon: 'none'
  308. });
  309. }
  310. this.$refs.popupkf.close();
  311. },
  312. uniCopy(content) {
  313. /**
  314. * 小程序端 和 app端的复制逻辑
  315. */
  316. //#ifndef H5
  317. uni.setClipboardData({
  318. data: content,
  319. success: function() {
  320. console.log('success');
  321. return true;
  322. }
  323. });
  324. //#endif
  325. /**
  326. * H5端的复制逻辑
  327. */
  328. // #ifdef H5
  329. if (!document.queryCommandSupported('copy')) {
  330. //为了兼容有些浏览器 queryCommandSupported 的判断
  331. // 不支持
  332. return false;
  333. }
  334. let textarea = document.createElement('textarea');
  335. textarea.value = content;
  336. textarea.readOnly = 'readOnly';
  337. document.body.appendChild(textarea);
  338. textarea.select(); // 选择对象
  339. textarea.setSelectionRange(0, content.length); //核心
  340. let result = document.execCommand('copy'); // 执行浏览器复制命令
  341. textarea.remove();
  342. return result;
  343. // #endif
  344. },
  345. // 打开客服
  346. openKf() {
  347. this.$refs.popupkf.open();
  348. },
  349. // 关闭客服
  350. cancel() {
  351. this.$refs.popupkf.close();
  352. },
  353. }
  354. };
  355. </script>
  356. <style lang="scss">
  357. page {
  358. background: #ffff;
  359. min-height: 100%;
  360. height: auto;
  361. }
  362. .status_bar {
  363. height: var(--status-bar-height);
  364. }
  365. // 顶部搜索
  366. .top-search {
  367. height: 80rpx;
  368. padding: 0 20rpx;
  369. background-color: #fff;
  370. .top-logo {
  371. width: 50rpx;
  372. // height: 50rpx;
  373. margin-right: 10rpx;
  374. image {
  375. width: 48rpx;
  376. }
  377. }
  378. .search-box {
  379. justify-content: center;
  380. width: 698rpx;
  381. height: 60rpx;
  382. background: #EEEEEE;
  383. // box-shadow: 0px 10rpx 20rpx 0px rgba(4, 114, 69, 0.22);
  384. border-radius: 30rpx;
  385. .search {
  386. width: 34rpx;
  387. height: 34rpx;
  388. }
  389. .search-font {
  390. margin-left: 14rpx;
  391. font-size: 28rpx;
  392. font-family: PingFang SC;
  393. font-weight: 500;
  394. color: #CBCBCB;
  395. }
  396. }
  397. }
  398. // 顶部轮播图
  399. .top-swiper {
  400. width: 750rpx;
  401. height: 348rpx;
  402. // margin: 20rpx 0 0;
  403. image {
  404. width: 750rpx;
  405. height: 348rpx;
  406. }
  407. }
  408. .jg {
  409. height: 20rpx;
  410. background: #F8F8F8;
  411. }
  412. .art-box {
  413. width: 690rpx;
  414. margin: 0 auto 20rpx;
  415. flex-wrap: wrap;
  416. .art-item {
  417. margin-top: 20rpx;
  418. width: 330rpx;
  419. height: 370rpx;
  420. border-radius: 20rpx;
  421. image {
  422. width: 100%;
  423. height: 100%;
  424. border-radius: 20rpx;
  425. }
  426. }
  427. }
  428. .good-list {
  429. width: 750rpx;
  430. .good {
  431. margin: 20rpx auto;
  432. width: 690rpx;
  433. height: 370rpx;
  434. image {
  435. width: 100%;
  436. height: 100%;
  437. border-radius: 20rpx;
  438. }
  439. }
  440. }
  441. </style>