index.vue 13 KB

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