index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515
  1. <template>
  2. <view class="wrapper" :style="colorStyle">
  3. <view class='productList'>
  4. <view class='search bg-color acea-row row-between-wrapper'>
  5. <view class='input acea-row row-between-wrapper'><text class='iconfont icon-sousuo'></text>
  6. <input :placeholder='$t(`搜索商品名称`)' placeholder-class='placeholder' confirm-type='search'
  7. name="search" :value='where.keyword' @confirm="searchSubmit"></input>
  8. </view>
  9. <view class='iconfont' :class='is_switch==true?"icon-pailie":"icon-tupianpailie"' @click='Changswitch'>
  10. </view>
  11. </view>
  12. <view class='nav acea-row row-middle'>
  13. <view class='item line1' :class='title ? "font-num":""' @click='set_where(1)'>
  14. {{title ? $t(title) : $t(`默认`)}}
  15. </view>
  16. <view class='item' @click='set_where(2)'>
  17. {{$t(`价格`)}}
  18. <image v-if="price==1" src='../../../static/images/up.png'></image>
  19. <image v-else-if="price==2" src='../../../static/images/down.png'></image>
  20. <image v-else src='../../../static/images/horn.png'></image>
  21. </view>
  22. <view class='item' @click='set_where(3)'>
  23. {{$t(`销量`)}}
  24. <image v-if="stock==1" src='../../../static/images/up.png'></image>
  25. <image v-else-if="stock==2" src='../../../static/images/down.png'></image>
  26. <image v-else src='../../../static/images/horn.png'></image>
  27. </view>
  28. <!-- down -->
  29. <view class='item' :class='nows ? "font-color":""' @click='set_where(4)'>{{$t(`新品`)}}</view>
  30. </view>
  31. <scroll-view :scroll-top="scrollTop" scroll-y="true" class="scroll-Y" @scroll="scroll"
  32. @scrolltolower="scrolltolower">
  33. <view class='list acea-row row-between-wrapper' :class='is_switch==true?"":"on"'>
  34. <view class='item' :class='is_switch==true?"":"on"' hover-class='none'
  35. v-for="(item,index) in productList" :key="index" @click="godDetail(item)">
  36. <view class='pictrue' :class='is_switch==true?"":"on"'>
  37. <image :src='item.image' :class='is_switch==true?"":"on"'></image>
  38. <span class="pictrue_log_class"
  39. :class="is_switch === true ? 'pictrue_log_big' : 'pictrue_log'"
  40. v-if="item.activity && item.activity.type === '1'">{{$t(`秒杀`)}}</span>
  41. <span class="pictrue_log_class"
  42. :class="is_switch === true ? 'pictrue_log_big' : 'pictrue_log'"
  43. v-if="item.activity && item.activity.type === '2'">{{$t(`砍价`)}}</span>
  44. <span class="pictrue_log_class"
  45. :class="is_switch === true ? 'pictrue_log_big' : 'pictrue_log'"
  46. v-if="item.activity && item.activity.type === '3'">{{$t(`拼团`)}}</span>
  47. </view>
  48. <view class='text' :class='is_switch==true?"":"on"'>
  49. <view class='name line2'>{{item.store_name}}</view>
  50. <view class='money font-color' :class='is_switch==true?"":"on"'>{{$t(`¥`)}}<text
  51. class='num'>{{item.price}}</text></view>
  52. <view class='vip acea-row row-between-wrapper' :class='is_switch==true?"":"on"'>
  53. <view class='vip-money' v-if="item.vip_price && item.vip_price > 0">
  54. {{$t(`¥`)}}{{item.vip_price}}
  55. <image src='../../../static/images/vip.png'></image>
  56. </view>
  57. <view>{{$t(`已售`)}} {{item.sales}}{{$t(item.unit_name) || $t(`件`)}}</view>
  58. </view>
  59. </view>
  60. </view>
  61. <view class='loadingicon acea-row row-center-wrapper' v-if='productList.length > 0'>
  62. <text class='loading iconfont icon-jiazai' :hidden='loading==false'></text>{{loadTitle}}
  63. </view>
  64. </view>
  65. </scroll-view>
  66. </view>
  67. <view class='noCommodity' v-if="productList.length==0 && where.page > 1">
  68. <view class='emptyBox'>
  69. <image :src="imgHost + '/statics/images/no-thing.png'"></image>
  70. <view class="tips">{{$t(`暂无商品,去看点别的吧`)}}</view>
  71. </view>
  72. <recommend :hostProduct="hostProduct"></recommend>
  73. </view>
  74. <!-- #ifndef MP -->
  75. <home></home>
  76. <!-- #endif -->
  77. <view v-if="scrollTopShow" class="back-top" @click="goTop">
  78. <text class="iconfont icon-xiangshang"></text>
  79. </view>
  80. </view>
  81. </template>
  82. <script>
  83. import home from '@/components/home';
  84. import {
  85. getProductslist,
  86. getProductHot
  87. } from '@/api/store.js';
  88. import recommend from '@/components/recommend';
  89. import {
  90. mapGetters
  91. } from "vuex";
  92. import {
  93. goShopDetail
  94. } from '@/libs/order.js'
  95. import {
  96. HTTP_REQUEST_URL
  97. } from '@/config/app';
  98. import colors from '@/mixins/color.js';
  99. export default {
  100. computed: mapGetters(['uid']),
  101. components: {
  102. recommend,
  103. home
  104. },
  105. mixins: [colors],
  106. data() {
  107. return {
  108. imgHost: HTTP_REQUEST_URL,
  109. productList: [],
  110. is_switch: true,
  111. where: {
  112. sid: 0,
  113. keyword: '',
  114. priceOrder: '',
  115. salesOrder: '',
  116. news: 0,
  117. page: 1,
  118. limit: 20,
  119. cid: 0,
  120. },
  121. price: 0,
  122. stock: 0,
  123. nows: false,
  124. loadend: false,
  125. loading: false,
  126. loadTitle: this.$t(`加载更多`),
  127. title: '',
  128. hostProduct: [],
  129. hotPage: 1,
  130. hotLimit: 10,
  131. hotScroll: false,
  132. scrollTop: 0,
  133. old: {
  134. scrollTop: 0
  135. },
  136. scrollTopShow: false
  137. };
  138. },
  139. onLoad: function(options) {
  140. this.where.cid = options.cid || 0;
  141. this.where.coupon_category_id = options.coupon_category_id || '';
  142. this.$set(this.where, 'sid', options.sid || 0);
  143. this.title = options.title || '';
  144. this.$set(this.where, 'keyword', options.searchValue || '');
  145. this.$set(this.where, 'productId', options.productId || '');
  146. this.get_product_list();
  147. },
  148. methods: {
  149. scroll(e) {
  150. this.scrollTopShow = e.detail.scrollTop > 150
  151. this.old.scrollTop = e.detail.scrollTop
  152. },
  153. goTop(e) {
  154. // 解决view层不同步的问题
  155. this.scrollTop = this.old.scrollTop
  156. this.$nextTick(() => {
  157. this.scrollTop = 0
  158. });
  159. },
  160. // 去详情页
  161. godDetail(item) {
  162. goShopDetail(item, this.uid).then(res => {
  163. uni.navigateTo({
  164. url: `/pages/goods_details/index?id=${item.id}`
  165. })
  166. })
  167. },
  168. Changswitch: function() {
  169. let that = this;
  170. that.is_switch = !that.is_switch
  171. },
  172. searchSubmit: function(e) {
  173. let that = this;
  174. that.$set(that.where, 'keyword', e.detail.value);
  175. that.loadend = false;
  176. that.$set(that.where, 'page', 1)
  177. this.get_product_list(true);
  178. },
  179. /**
  180. * 获取我的推荐
  181. */
  182. get_host_product: function() {
  183. let that = this;
  184. if (that.hotScroll) return
  185. getProductHot(
  186. that.hotPage,
  187. that.hotLimit,
  188. ).then(res => {
  189. that.hotPage++
  190. that.hotScroll = res.data.length < that.hotLimit
  191. that.hostProduct = that.hostProduct.concat(res.data)
  192. // that.$set(that, 'hostProduct', res.data)
  193. });
  194. },
  195. //点击事件处理
  196. set_where: function(e) {
  197. switch (e) {
  198. case 1:
  199. // #ifdef H5
  200. return history.back();
  201. // #endif
  202. // #ifndef H5
  203. return uni.navigateBack({
  204. delta: 1,
  205. })
  206. // #endif
  207. break;
  208. case 2:
  209. if (this.price == 0) this.price = 1;
  210. else if (this.price == 1) this.price = 2;
  211. else if (this.price == 2) this.price = 0;
  212. this.stock = 0;
  213. break;
  214. case 3:
  215. if (this.stock == 0) this.stock = 1;
  216. else if (this.stock == 1) this.stock = 2;
  217. else if (this.stock == 2) this.stock = 0;
  218. this.price = 0
  219. break;
  220. case 4:
  221. this.nows = !this.nows;
  222. break;
  223. }
  224. this.loadend = false;
  225. this.$set(this.where, 'page', 1);
  226. this.get_product_list(true);
  227. },
  228. //设置where条件
  229. setWhere: function() {
  230. if (this.price == 0) this.where.priceOrder = '';
  231. else if (this.price == 1) this.where.priceOrder = 'asc';
  232. else if (this.price == 2) this.where.priceOrder = 'desc';
  233. if (this.stock == 0) this.where.salesOrder = '';
  234. else if (this.stock == 1) this.where.salesOrder = 'asc';
  235. else if (this.stock == 2) this.where.salesOrder = 'desc';
  236. this.where.news = this.nows ? 1 : 0;
  237. },
  238. //查找产品
  239. get_product_list: function(isPage) {
  240. let that = this;
  241. that.setWhere();
  242. if (that.loadend) return;
  243. if (that.loading) return;
  244. if (isPage === true) that.$set(that, 'productList', []);
  245. that.loading = true;
  246. that.loadTitle = '';
  247. getProductslist(that.where).then(res => {
  248. let list = res.data;
  249. let productList = that.$util.SplitArray(list, that.productList);
  250. let loadend = list.length < that.where.limit;
  251. that.loadend = loadend;
  252. that.loading = false;
  253. that.loadTitle = loadend ? that.$t(`没有更多内容啦~`) : that.$t(`加载更多`);
  254. that.$set(that, 'productList', productList);
  255. that.$set(that.where, 'page', that.where.page + 1);
  256. if (!that.productList.length) this.get_host_product();
  257. }).catch(err => {
  258. that.loading = false;
  259. that.loadTitle = that.$t(`加载更多`);
  260. });
  261. },
  262. scrolltolower() {
  263. if (this.productList.length > 0) {
  264. this.get_product_list();
  265. uni.$emit('scroll');
  266. } else {
  267. this.get_host_product();
  268. uni.$emit('scroll');
  269. }
  270. }
  271. },
  272. onPullDownRefresh() {
  273. },
  274. onReachBottom() {
  275. console.log('11')
  276. },
  277. // 滚动监听
  278. onPageScroll(e) {
  279. // 传入scrollTop值并触发所有easy-loadimage组件下的滚动监听事件
  280. uni.$emit('scroll');
  281. },
  282. }
  283. </script>
  284. <style scoped lang="scss">
  285. .scroll-Y {
  286. margin-top: 86rpx;
  287. height: calc(100vh - 43rpx);
  288. }
  289. .wrapper {
  290. position: relative;
  291. max-height: 100vh;
  292. overflow: hidden;
  293. .back-top {
  294. position: absolute;
  295. right: 40rpx;
  296. bottom: 60rpx;
  297. width: 60rpx;
  298. height: 60rpx;
  299. border-radius: 50%;
  300. display: flex;
  301. justify-content: center;
  302. align-items: center;
  303. border: 1rpx solid #ccc;
  304. background-color: #fff;
  305. .icon-xiangshang {
  306. color: #ccc;
  307. font-weight: bold;
  308. }
  309. }
  310. }
  311. .productList .search {
  312. width: 100%;
  313. height: 86rpx;
  314. padding-left: 23rpx;
  315. box-sizing: border-box;
  316. position: fixed;
  317. left: 0;
  318. top: 0;
  319. z-index: 9;
  320. }
  321. .productList .search .input {
  322. width: 640rpx;
  323. height: 60rpx;
  324. background-color: #fff;
  325. border-radius: 50rpx;
  326. padding: 0 20rpx;
  327. box-sizing: border-box;
  328. }
  329. .productList .search .input input {
  330. width: 548rpx;
  331. height: 100%;
  332. font-size: 26rpx;
  333. }
  334. .productList .search .input .placeholder {
  335. color: #999;
  336. }
  337. .productList .search .input .iconfont {
  338. font-size: 35rpx;
  339. color: #555;
  340. }
  341. .productList .search .icon-pailie,
  342. .productList .search .icon-tupianpailie {
  343. color: #fff;
  344. width: 62rpx;
  345. font-size: 40rpx;
  346. height: 86rpx;
  347. line-height: 86rpx;
  348. }
  349. .productList .nav {
  350. height: 86rpx;
  351. color: #454545;
  352. position: fixed;
  353. left: 0;
  354. width: 100%;
  355. font-size: 28rpx;
  356. background-color: #fff;
  357. margin-top: 86rpx;
  358. top: 0;
  359. z-index: 9;
  360. }
  361. .productList .nav .item {
  362. width: 25%;
  363. text-align: center;
  364. }
  365. .productList .nav .item.font-color {
  366. font-weight: bold;
  367. }
  368. .productList .nav .item image {
  369. width: 15rpx;
  370. height: 19rpx;
  371. margin-left: 10rpx;
  372. }
  373. .productList .list {
  374. padding: 0 20rpx 30rpx 20rpx;
  375. margin-top: 86rpx;
  376. }
  377. .productList .list.on {
  378. background-color: #fff;
  379. border-top: 1px solid #f6f6f6;
  380. }
  381. .productList .list .item {
  382. width: 345rpx;
  383. margin-top: 20rpx;
  384. background-color: #fff;
  385. border-radius: 20rpx;
  386. }
  387. .productList .list .item.on {
  388. width: 100%;
  389. display: flex;
  390. border-bottom: 1rpx solid #f6f6f6;
  391. padding: 30rpx 0;
  392. margin: 0;
  393. }
  394. .productList .list .item .pictrue {
  395. position: relative;
  396. width: 100%;
  397. height: 345rpx;
  398. }
  399. .productList .list .item .name {
  400. line-height: 42rpx;
  401. height: 84rpx;
  402. }
  403. .productList .list .item .pictrue.on {
  404. width: 180rpx;
  405. height: 180rpx;
  406. }
  407. .productList .list .item .pictrue image {
  408. width: 100%;
  409. height: 100%;
  410. border-radius: 20rpx 20rpx 0 0;
  411. }
  412. .productList .list .item .pictrue image.on {
  413. border-radius: 6rpx;
  414. }
  415. .productList .list .item .text {
  416. padding: 20rpx 17rpx 26rpx 17rpx;
  417. font-size: 30rpx;
  418. color: #222;
  419. }
  420. .productList .list .item .text.on {
  421. width: 508rpx;
  422. padding: 0 0 0 22rpx;
  423. }
  424. .productList .list .item .text .money {
  425. font-size: 26rpx;
  426. font-weight: bold;
  427. margin-top: 8rpx;
  428. }
  429. .productList .list .item .text .money.on {
  430. margin-top: 50rpx;
  431. }
  432. .productList .list .item .text .money .num {
  433. font-size: 34rpx;
  434. }
  435. .productList .list .item .text .vip {
  436. font-size: 22rpx;
  437. color: #aaa;
  438. margin-top: 7rpx;
  439. }
  440. .productList .list .item .text .vip.on {
  441. margin-top: 12rpx;
  442. }
  443. .productList .list .item .text .vip .vip-money {
  444. font-size: 24rpx;
  445. color: #282828;
  446. font-weight: bold;
  447. display: flex;
  448. align-items: center;
  449. }
  450. .productList .list .item .text .vip .vip-money image {
  451. width: 64rpx;
  452. height: 26rpx;
  453. margin-left: 4rpx;
  454. }
  455. .noCommodity {
  456. background-color: #fff;
  457. padding-bottom: 30rpx;
  458. .emptyBox {
  459. text-align: center;
  460. padding-top: 20rpx;
  461. .tips {
  462. color: #aaa;
  463. font-size: 26rpx;
  464. }
  465. image {
  466. width: 414rpx;
  467. height: 304rpx;
  468. }
  469. }
  470. }
  471. </style>