index.vue 11 KB

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