home.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. <template>
  2. <view class="box-sizing-b w-full">
  3. <!-- 最上层背景 -->
  4. <view class="top-bg">
  5. <view style="height: 54rpx;width: 100%;"></view>
  6. <!-- 01. 头部组件 -->
  7. <use-header :search-tip="searchTip" :search-auto="searchAuto" @search="search" style="margin-top: 54rpx"></use-header>
  8. <!-- 02. 轮播区 -->
  9. <view class="swiper-area pos-r" v-if="swiperDatas && swiperDatas.length > 0">
  10. <!-- 轮播组件 -->
  11. <swiper class="swiper w-full" autoplay indicator-dots indicator-color="#f7f7f7" indicator-active-color="rgba(36, 147, 241, 1)">
  12. <swiper-item class="swiper-item padding-lr wh-full box-sizing-b" v-for="(item, index) in swiperDatas" :key="index">
  13. <view class="wh-full" @click.stop="topage(item)">
  14. <image class="border-radius wh-full" mode="aspectFill" :lazy-load="true" :src="item.img" />
  15. </view>
  16. </swiper-item>
  17. </swiper>
  18. </view>
  19. <!-- 03. 分类区 -->
  20. <view class="category-area dflex dflex-wrap-w" v-if="categoryDatas && categoryDatas.length > 0">
  21. <view class="category-item dflex dflex-flow-c margin-bottom-sm" v-for="(item, index) in categoryDatas"
  22. :key="index" @click="topage2(item)">
  23. <image class="margin-bottom-xs" lazy-load :src="item.icon"></image>
  24. <text class="tac clamp" style="color: black;">{{ item.name }}</text>
  25. </view>
  26. </view>
  27. <!-- 04. 限时精选 -->
  28. <view class="xianshijing">
  29. <use-list-title title="限时精选" size="32" fwt="600" color="#333" iconfont="icondaishouhuo-" @goto="limit">
  30. </use-list-title>
  31. <view class="limit-area">
  32. <scroll-view class="padding-lr" scroll-x>
  33. <view class="dflex padding-bottom">
  34. <view class="item margin-right-sm" v-for="(item, index) in goodsLimitDatas" :key="index"
  35. @click="togoods(item)">
  36. <image class="border-radius-xs" v-if="((item.imgs).indexOf(',')) != -1"
  37. mode="aspectFill" :lazy-load="true" :src="((item.imgs).substring(0, ((item.imgs).indexOf(','))))"></image>
  38. <image class="border-radius-xs" v-else
  39. mode="aspectFill" :lazy-load="true" :src="item.imgs"></image>
  40. <text class="title clamp padding-bottom-xs">{{ item.name }}</text>
  41. <text class="price">{{ item.price }}</text><text class="m-price">{{ item.marketPrice }}</text>
  42. </view>
  43. </view>
  44. </scroll-view>
  45. </view>
  46. </view>
  47. <!-- 05. 热门推荐 -->
  48. <use-hot-goods :datas="goodsHotDatas" autoload="none" title="热门推荐"></use-hot-goods>
  49. <view style="height: 125px;width: 100%;"></view>
  50. <!-- 置顶 -->
  51. <use-totop ref="usetop" :style="{ marginBottom: navHeight + 'px' }"></use-totop>
  52. <!-- #ifdef MP-WEIXIN -->
  53. <official-account @bindload="wxOAccountLoad" @binderror="wxOAccountErr"></official-account>
  54. <!-- #endif -->
  55. </view>
  56. <!-- <tabbar :current-page="0"></tabbar> -->
  57. </view>
  58. </template>
  59. <script>
  60. import { mapState } from 'vuex';
  61. import {
  62. getLunbo,
  63. goodsgory,
  64. goodslistlimit
  65. } from '../../utils/api_home.js'
  66. import useHeader from '../../components/use-header/use-header.vue'
  67. import useListTitle from '../../components/use-list-title/use-list-title.vue'
  68. import useHotGoods from '../../components/use-hot-goods/use-hot-goods.vue'
  69. import useTotop from '../../components/use-totop/use-totop.vue'
  70. // import tabbar from '../tabbar.vue'
  71. export default {
  72. computed: {
  73. ...mapState(['member'])
  74. },
  75. components:{
  76. useHeader,
  77. useListTitle,
  78. useHotGoods,
  79. useTotop,
  80. // tabbar
  81. },
  82. data() {
  83. return {
  84. // 头部参数
  85. searchAuto: !0,
  86. searchTip: '万千商品,等你来采购',
  87. // 轮播区
  88. swiperDatas: [],
  89. // 金刚区分类
  90. categoryDatas: [],
  91. // 限时精选
  92. goodsLimitDatas: [],
  93. // 热门推荐
  94. goodsHotDatas: [],
  95. scrollTop: 0,
  96. navHeight: 50,
  97. };
  98. },
  99. // 监听页面加载
  100. onLoad() {
  101. },
  102. onPageScroll(e) {
  103. // this.scrollTop = e.scrollTop
  104. this.$refs.usetop.change(e.scrollTop);
  105. },
  106. // 监听页面显示。页面每次出现在屏幕上都触发,包括从下级页面点返回露出当前页面
  107. onShow() {
  108. this.get_lunbo()
  109. this.get_goodsgory()
  110. this.get_goodslist()
  111. this.get_good_hot()
  112. },
  113. // 监听用户下拉刷新
  114. onPullDownRefresh() {
  115. this.get_lunbo(() => {
  116. uni.stopPullDownRefresh();
  117. });
  118. this.get_goodsgory(() => {
  119. uni.stopPullDownRefresh();
  120. });
  121. this.get_goodslist(() => {
  122. uni.stopPullDownRefresh();
  123. });
  124. this.get_good_hot(() => {
  125. uni.stopPullDownRefresh();
  126. });
  127. },
  128. // 用户点击右上角分享
  129. // https://uniapp.dcloud.io/api/plugins/share?id=showsharemenu
  130. onShareAppMessage: function(ops) {
  131. let _this = this,
  132. mid = 0;
  133. if (_this.member && _this.member._id) {
  134. mid = _this.member._id;
  135. }
  136. return {
  137. title: '特产商城',
  138. path: `/pages/tabbar/home?mid=${mid}`,
  139. // imageUrl: 'https://mall-os-api.use-cloud.com/files/upload/image/20200408/200408115587860242.jpg',
  140. success: function(res) {
  141. // 转发成功
  142. console.log('转发成功', res);
  143. },
  144. fail: function(res) {
  145. // 转发失败
  146. console.log('转发失败', res);
  147. }
  148. };
  149. },
  150. methods: {
  151. //轮播图列表
  152. get_lunbo() {
  153. let _self = this
  154. _self.swiperDatas=[]
  155. getLunbo().then((res) => {
  156. if (res.success) {
  157. res.data.list.forEach(data => {
  158. _self.swiperDatas.push(data)
  159. })
  160. }
  161. })
  162. },
  163. // 商品金刚区分类
  164. get_goodsgory(){
  165. let _self = this;
  166. _self.categoryDatas=[]
  167. goodsgory().then((res) => {
  168. if (res.success) {
  169. res.data.forEach(data => {
  170. _self.categoryDatas.push(data)
  171. })
  172. }
  173. })
  174. },
  175. //商品限时精选
  176. get_goodslist(){
  177. let _self = this;
  178. _self.goodsLimitDatas=[]
  179. var data='?limited=1'
  180. goodslistlimit(data).then((res) => {
  181. if (res.success) {
  182. var total=res.data.totalCount
  183. data='?limited=1&pageSize='+total
  184. goodslistlimit(data).then((res) => {
  185. if (res.success) {
  186. res.data.list.forEach(data => {
  187. _self.goodsLimitDatas.push(data)
  188. })
  189. }else{
  190. _self.$message.warning('没有符合条件的数据!')
  191. }
  192. })
  193. }
  194. })
  195. },
  196. // 热门推荐
  197. get_good_hot(){
  198. let _self = this;
  199. _self.goodsHotDatas=[]
  200. var data='?hot=1'
  201. goodslistlimit(data).then((res) => {
  202. if (res.success) {
  203. var total=res.data.totalCount
  204. data='?hot=1&pageSize='+total
  205. goodslistlimit(data).then((res) => {
  206. if (res.success) {
  207. res.data.list.forEach(data => {
  208. _self.goodsHotDatas.push(data)
  209. })
  210. }else{
  211. _self.$message.warning('没有符合条件的数据!')
  212. }
  213. })
  214. }
  215. })
  216. },
  217. // 搜索回调函数
  218. search() {
  219. console.log('home search');
  220. },
  221. // 跳转页面
  222. topage(item) {
  223. },
  224. topage2(item){
  225. uni.navigateTo({
  226. url:'/packageShang/pages/tabbar/category?cid='+item.id
  227. })
  228. // this.$api.togoodslist({
  229. // cid: item.id,
  230. // level:item.level,
  231. // keyword:item.name
  232. // });
  233. },
  234. // 限时精选 -> 商品详情
  235. togoods(item) {
  236. // 跳转商品详情
  237. this.$api.togoods({
  238. id: item.id
  239. });
  240. },
  241. // 限时精选
  242. limit() {
  243. // 跳转商品列表 - 限时精选类目
  244. this.$api.togoodslist({
  245. limited: 1
  246. });
  247. },
  248. },
  249. mounted() {
  250. // #ifdef H5 || MP-360
  251. this.navHeight = 50;
  252. // #endif
  253. }
  254. };
  255. </script>
  256. <style lang="scss">
  257. @import url('/packageShang/components/iconfont/iconfont.css');
  258. @import url('/packageShang/common/common.scss');
  259. page {
  260. min-height: 100%;
  261. background: $page-color-base;
  262. }
  263. // 最上层背景
  264. .top-bg{
  265. width: 100%;
  266. display: flow;
  267. height: 500rpx;
  268. background: linear-gradient(180deg, rgba(36, 147, 241, 1) 0%, rgba(36, 147, 241, 1) 64.28%, rgba(255, 255, 255, 0) 100%);
  269. .top-title{
  270. padding: 106rpx 0 0 30rpx;
  271. font-size: 36rpx;
  272. font-weight: 400;
  273. line-height: 36rpx;
  274. color: rgba(255, 255, 255, 1);
  275. }
  276. }
  277. /* 轮播图区 */
  278. .swiper-area {
  279. padding-top: 20rpx;
  280. .swiper {
  281. height: 276rpx;
  282. }
  283. }
  284. /* 分类区 */
  285. .category-area {
  286. width: 690rpx;
  287. // height: 100%;
  288. border-radius: 14rpx;
  289. background: rgba(255, 255, 255, 1);
  290. margin: 15rpx 0 0 30rpx;
  291. padding: 15rpx 0 30rpx 0;
  292. .category-item {
  293. font-size: $font-sm + 2upx;
  294. color: $font-color-dark;
  295. width: 20%;
  296. }
  297. image {
  298. width: 90rpx;
  299. height: 90rpx;
  300. }
  301. }
  302. /* 限时精选区 */
  303. .xianshijing{
  304. margin: 15rpx 0 0 30rpx;
  305. width: 690rpx;
  306. height: 428rpx;
  307. border-radius: 14rpx;
  308. background: rgba(255, 255, 255, 1);
  309. .limit-area {
  310. min-height: 221rpx;
  311. .item {
  312. width: 221rpx;
  313. image {
  314. width: 221rpx;
  315. height: 221rpx;
  316. }
  317. }
  318. }
  319. }
  320. </style>