index.vue 13 KB

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