index.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  1. <template>
  2. <view class="container">
  3. <view class="titleNview-placing"></view>
  4. <view class="bg"></view>
  5. <view class="main-title">好运优选</view>
  6. <view class="top-search flex">
  7. <view class="search-box flex" @click="clickSearch()">
  8. <image class="search" src="../../static/icon/search-h.png" mode=""></image>
  9. <view class="search-font"><input type="text" placeholder="输入关键词搜索" /></view>
  10. </view>
  11. </view>
  12. <swiper class="banner" autoplay="true" duration="400" interval="5000">
  13. <swiper-item class="banner-item" v-for="(item, index) in carouselList"><image :src="item.pic" /></swiper-item>
  14. </swiper>
  15. <view class="tongz">
  16. <view class="tongz-left flex">
  17. <view class="left">
  18. <image class="image-left" src="../../static/img/ling.png" mode=""></image>
  19. <view class="tongz-title">系统公告</view>
  20. </view>
  21. <u-notice-bar
  22. style="width: 100%;"
  23. mode="vertical"
  24. type="none"
  25. :volume-icon="false"
  26. :more-icon="true"
  27. :list="text"
  28. @click="goDetails"
  29. @getMore="navTo('/pages/index/message?type=1')"
  30. ></u-notice-bar>
  31. </view>
  32. </view>
  33. <view class="xian"></view>
  34. <view class="guess-section">
  35. <view v-for="(item, index) in integralList" :key="index" class="guess-item" @click="navToDetailPage(item)">
  36. <view class="image-wrapper"><image :src="item.image" mode="scaleToFill"></image></view>
  37. <text class="title clamp2 margin-c-20">{{ item.store_name }}</text>
  38. <view class="cmy-hr"></view>
  39. <view class="price margin-c-20 flex">
  40. <view>¥{{ item.price }}</view>
  41. <!-- <view class="font-size-sm">
  42. <text class="font-color-gray">月销:{{ item.sales }}</text>
  43. </view> -->
  44. </view>
  45. </view>
  46. </view>
  47. </view>
  48. </template>
  49. <script>
  50. import { loadIndexs } from '@/api/index.js';
  51. import { getUserInfo, spread } from '@/api/user.js';
  52. import { interceptor } from '@/utils/loginUtils';
  53. import { mapState, mapMutations } from 'vuex';
  54. import { groomList } from '@/api/product.js';
  55. // #ifdef H5
  56. import { weixindata, shareLoad } from '@/utils/wxAuthorized';
  57. // #endif
  58. import uniCopy from '@/js_sdk/xb-copy/uni-copy.js';
  59. export default {
  60. data() {
  61. return {
  62. text: '',
  63. titleNViewBackground: '',
  64. swiperCurrent: 0,
  65. swiperLength: 0,
  66. carouselList: [], //轮播列表
  67. integralList: [], //商品列表
  68. page: 1,
  69. limit: 10,
  70. loadType: 'more'
  71. };
  72. },
  73. computed: {
  74. ...mapState(['loginInterceptor', 'baseURL']),
  75. ...mapState('user', ['hasLogin', 'userInfo'])
  76. },
  77. onLoad: function(option) {
  78. // #ifdef MP
  79. if (option.scene) {
  80. // 存储小程序邀请人
  81. uni.setStorage({
  82. key: 'spread_code',
  83. data: option.scene
  84. });
  85. }
  86. // #endif
  87. },
  88. onShow: function() {
  89. // 判断是否强制登录
  90. // if (!this.hasLogin) {
  91. // // 登录拦截
  92. // interceptor();
  93. // }
  94. this.page = 1;
  95. this.limit = 10;
  96. this.loadType = 'more';
  97. this.integralList = [];
  98. this.loadData();
  99. },
  100. onReachBottom() {
  101. this.getProduct();
  102. },
  103. methods: {
  104. goDetails(e) {
  105. uni.navigateTo({
  106. url: '/pages/index/messageInfo?id=' + this.article[e].id
  107. });
  108. },
  109. navTo(url) {
  110. if (url == '') {
  111. this.$api.msg('暂未开通,敬请期待');
  112. } else {
  113. uni.navigateTo({
  114. url,
  115. fail() {
  116. uni.switchTab({
  117. url
  118. });
  119. }
  120. });
  121. }
  122. },
  123. clickSearch() {
  124. uni.navigateTo({
  125. url: '/pages/product/search'
  126. });
  127. },
  128. // 监听图片加载完成
  129. onImageError(key, index) {
  130. this[key][index].image = '/static/error/errorImage.jpg';
  131. },
  132. // 请求载入数据
  133. async loadData() {
  134. this.text = [];
  135. loadIndexs({})
  136. .then(({ data }) => {
  137. console.log(data);
  138. let goods = data.info;
  139. this.carouselList = data.banner;
  140. this.swiperLength = this.carouselList.length;
  141. this.integralList = goods.firstList;
  142. })
  143. .catch(e => {});
  144. },
  145. //轮播图切换修改背景色
  146. swiperChange(e) {
  147. const index = e.detail.current;
  148. this.swiperCurrent = index;
  149. this.titleNViewBackground = this.carouselList[index].background;
  150. },
  151. //详情页
  152. navToDetailPage(item) {
  153. let id = item.id;
  154. uni.navigateTo({
  155. url: '/pages/product/product?id=' + id
  156. });
  157. },
  158. // 轮播图跳转
  159. bannerNavToUrl(item) {
  160. // #ifdef H5
  161. console.log(item.wap_url.indexOf('http'), 'banner');
  162. if (item.wap_url.indexOf('http') >= 0) {
  163. window.location.href = item.wap_url;
  164. }
  165. // #endif
  166. //测试数据没有写id,用title代替
  167. uni.navigateTo({
  168. url: item.wap_url
  169. });
  170. }
  171. }
  172. };
  173. </script>
  174. <style lang="scss">
  175. page,
  176. .container {
  177. height: auto;
  178. min-height: 100%;
  179. background: #ffffff;
  180. }
  181. .titleNview-placing {
  182. height: var(--status-bar-height);
  183. box-sizing: content-box;
  184. }
  185. .bg {
  186. position: absolute;
  187. top: 0;
  188. left: 0;
  189. width: 750rpx;
  190. height: 460rpx;
  191. background: linear-gradient(#ff4c4c, #ffffff);
  192. }
  193. .main-title {
  194. padding: 20rpx 0 0;
  195. text-align: center;
  196. position: relative;
  197. z-index: 2;
  198. font-size: 36rpx;
  199. font-family: PingFang SC;
  200. font-weight: bold;
  201. color: #ffffff;
  202. }
  203. .top-search {
  204. margin-top: 30rpx;
  205. height: 80rpx;
  206. padding: 0 20rpx;
  207. .search-box {
  208. position: relative;
  209. z-index: 2;
  210. justify-content: center;
  211. width: 740rpx;
  212. height: 60rpx;
  213. background: #fff;
  214. border-radius: 30rpx;
  215. .search {
  216. width: 26rpx;
  217. height: 30rpx;
  218. }
  219. .search-font input {
  220. width: 500rpx;
  221. margin-left: 14rpx;
  222. font-size: 28rpx;
  223. font-family: PingFang SC;
  224. font-weight: 500;
  225. color: #aaaaaa;
  226. }
  227. }
  228. }
  229. .banner {
  230. margin: 20rpx auto 0;
  231. width: 690rpx;
  232. height: 350rpx;
  233. .banner-item {
  234. width: 690rpx;
  235. height: 350rpx;
  236. image {
  237. width: 100%;
  238. height: 100%;
  239. }
  240. }
  241. }
  242. .tongz {
  243. width: 690rpx;
  244. height: 70rpx;
  245. margin: 32rpx auto 0;
  246. padding: 18rpx 30rpx 18rpx 24rpx;
  247. background: #f8f8fa;
  248. align-items: center;
  249. position: relative;
  250. .tongz-bg {
  251. position: absolute;
  252. top: 0;
  253. right: 0;
  254. left: 0;
  255. width: 690rpx;
  256. height: 70rpx;
  257. image {
  258. width: 100%;
  259. height: 100%;
  260. }
  261. }
  262. .tongz-left {
  263. width: 640rpx;
  264. .left {
  265. display: flex;
  266. align-items: center;
  267. }
  268. .tongz-title {
  269. margin-left: 10rpx;
  270. font-size: 26rpx;
  271. font-family: PingFang SC;
  272. font-weight: bold;
  273. color: #ff1a1a;
  274. }
  275. .image-left {
  276. width: 28rpx;
  277. height: 28rpx;
  278. }
  279. .tongz-font {
  280. margin-left: 22rpx;
  281. font-size: 28rpx;
  282. font-family: Source Han Sans CN;
  283. font-weight: 400;
  284. color: #0f253a;
  285. }
  286. }
  287. .tongz-right {
  288. position: relative;
  289. z-index: 11;
  290. width: 12rpx;
  291. height: 26rpx;
  292. image {
  293. width: 100%;
  294. height: 100%;
  295. }
  296. }
  297. }
  298. .xian {
  299. margin-top: 30rpx;
  300. width: 750rpx;
  301. height: 20rpx;
  302. background: #f8f8f8;
  303. }
  304. %icon {
  305. margin-right: 10rpx;
  306. display: inline-block;
  307. padding: 2rpx 10rpx;
  308. border: 1rpx solid $color-yellow;
  309. color: $color-yellow;
  310. line-height: 1;
  311. font-size: $font-base;
  312. border-radius: 10rpx;
  313. }
  314. .guess-section {
  315. margin-top: 40rpx;
  316. display: flex;
  317. flex-wrap: wrap;
  318. padding: 0 30rpx;
  319. .guess-item {
  320. padding-bottom: 35rpx;
  321. overflow: hidden;
  322. display: flex;
  323. flex-direction: column;
  324. width: 48%;
  325. margin-bottom: 4%;
  326. border-radius: $border-radius-sm;
  327. background-color: white;
  328. box-shadow: $box-shadow;
  329. &:nth-child(2n + 1) {
  330. margin-right: 4%;
  331. }
  332. }
  333. .image-wrapper {
  334. width: 100%;
  335. height: 330rpx;
  336. border-radius: 3px;
  337. overflow: hidden;
  338. image {
  339. width: 100%;
  340. height: 100%;
  341. opacity: 1;
  342. }
  343. }
  344. .title {
  345. margin-top: 28rpx;
  346. font-size: $font-base;
  347. color: $font-color-dark;
  348. font-weight: bold;
  349. }
  350. .price {
  351. margin-top: 34rpx;
  352. font-size: 24rpx;
  353. font-family: PingFang SC;
  354. font-weight: 800;
  355. color: #ff4c4c;
  356. line-height: 1;
  357. .yuan-price {
  358. display: inline-block;
  359. margin-left: 10rpx;
  360. font-size: 24rpx;
  361. font-family: PingFang SC;
  362. font-weight: 500;
  363. text-decoration: line-through;
  364. color: #969696;
  365. }
  366. }
  367. .icon {
  368. @extend %icon;
  369. }
  370. .detail {
  371. line-height: 1;
  372. }
  373. .tip {
  374. color: white;
  375. background-color: $color-yellow;
  376. line-height: 1.5;
  377. font-size: $font-sm;
  378. padding-left: 20rpx;
  379. }
  380. }
  381. </style>