index.vue 11 KB

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