index.vue 9.1 KB

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