index.vue 11 KB

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