main.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467
  1. <template>
  2. <div
  3. class="wrapper"
  4. ref="returnWrapper">
  5. <ul>
  6. <li
  7. :class="{'static': isRefresh}"
  8. class="pulldown-wrapper">
  9. <van-loading
  10. v-show="isRefresh"
  11. size="24px"
  12. type="spinner">加载中...
  13. </van-loading>
  14. <div
  15. v-show="!isRefresh"
  16. class="van-loading">
  17. <span
  18. class="van-loading__text">下拉刷新</span>
  19. </div>
  20. </li>
  21. <li
  22. v-for="(item, index) in list"
  23. :key="index"
  24. class="list-item"
  25. @click="getOrderDetail(item.goods_id)">
  26. <div class="photo">
  27. <img
  28. v-lazy="item.goods_thumb_url"
  29. alt="">
  30. </div>
  31. <div class="info">
  32. <div
  33. class="top">
  34. <img
  35. :src="businessLogo"
  36. alt="">
  37. <p>{{ item.goods_name }}</p>
  38. </div>
  39. <div class="middle">
  40. <div class="price-wrap">
  41. <p class="price">
  42. <span>¥</span>
  43. <span>{{ item.price && (item.price * 1).toFixed(2) }}</span>
  44. </p>
  45. <p class="origin">¥{{ item.market_price && (item.market_price * 1).toFixed(2) }}</p>
  46. </div>
  47. <!--暂时不用这个字段-->
  48. <!--<div class="sale-count">-->
  49. <!--<span>已售</span>-->
  50. <!--<span>0</span>-->
  51. <!--</div>-->
  52. </div>
  53. <div class="card" v-show="item.discount > 0 || item.commission > 0">
  54. <p class="coupon" v-show="item.discount > 0">
  55. <span>券</span>
  56. <span>¥{{ item.discount }}</span>
  57. </p>
  58. <p class="profit" v-show="item.commission > 0">
  59. <span>分享赚</span>
  60. <span>¥&nbsp;{{ item.commission }}</span>
  61. </p>
  62. </div>
  63. <div
  64. class="shop"
  65. v-if="item.shop_name">
  66. <van-icon
  67. size="20"
  68. name="shop-o"/>
  69. <p>{{ item.shop_name }}</p>
  70. </div>
  71. </div>
  72. </li>
  73. <li class="pullup-wrapper">
  74. <van-loading
  75. v-show="!finished"
  76. size="24px"
  77. type="spinner">加载中...
  78. </van-loading>
  79. <div
  80. v-show="finished"
  81. class="van-loading">
  82. <span
  83. class="van-loading__text">没有更多了</span>
  84. </div>
  85. </li>
  86. </ul>
  87. </div>
  88. </template>
  89. <script>
  90. import BScroll from 'better-scroll'
  91. import { Toast, Loading, Icon } from 'vant'
  92. import { apiGoodsList } from '../api/api'
  93. export default {
  94. components: {
  95. 'van-loading': Loading,
  96. 'van-icon': Icon
  97. },
  98. props: {
  99. source: {
  100. type: String,
  101. default: ''
  102. },
  103. catId: {
  104. type: [String, Number],
  105. default: ''
  106. }
  107. },
  108. data () {
  109. return {
  110. finished: false, // 所有数据是否加载完
  111. isRefresh: false, // 是否下拉刷新
  112. isFetchLock: false, // 接口调用加锁
  113. pagenum: 0,
  114. pagesize: 20,
  115. list: [],
  116. scroll: null,
  117. screenHeight: Math.round(window.screen.height / 2),
  118. currentSource: ''
  119. }
  120. },
  121. computed: {
  122. sourceList () {
  123. return this.$store.getters['common/sourceList']
  124. },
  125. businessLogo () {
  126. const result = this.sourceList.filter(item => item.value === this.currentSource)
  127. if (result.length) {
  128. return result[0].logo
  129. }
  130. return ''
  131. }
  132. },
  133. methods: {
  134. init () {
  135. this.finished = false
  136. this.isRefresh = false
  137. this.isFetchLock = false
  138. this.pagenum = 0
  139. this.pagesize = 20
  140. this.currentSource = ''
  141. this.list = []
  142. if (this.scroll) {
  143. this.scroll.scrollTo(0, 0)
  144. }
  145. this.getList()
  146. },
  147. onRefresh () {
  148. this.pagenum = 0
  149. this.pagesize = 20
  150. this.finished = false
  151. this.isRefresh = true
  152. this.getList()
  153. },
  154. async getList () {
  155. const source = this.source
  156. if (this.finished) {
  157. return
  158. }
  159. if (this.isFetchLock) {
  160. return
  161. }
  162. this.isFetchLock = true
  163. this.pagenum++
  164. try {
  165. const { status, data, msg } = await apiGoodsList({
  166. page: this.pagenum,
  167. page_size: this.pagesize,
  168. source: source,
  169. cat_id: this.catId
  170. })
  171. if (status) {
  172. const { list } = data
  173. // 下拉刷新数据清空
  174. if (this.isRefresh) {
  175. this.isRefresh = false
  176. this.list = []
  177. }
  178. // 没有数据返回了
  179. if (Array.isArray(list) && !list.length) {
  180. this.finished = true
  181. }
  182. if (Array.isArray(list) && list.length) {
  183. // 总页数小于等于1页时
  184. if (list.length < this.pagesize) {
  185. this.finished = true
  186. }
  187. this.list = this.list.concat(list)
  188. this.currentSource = source
  189. this.$nextTick(() => {
  190. if (!this.scroll) {
  191. this.scroll = new BScroll(this.$refs.returnWrapper, {
  192. probeType: 1,
  193. click: true,
  194. pullDownRefresh: {
  195. threshold: 50, // 顶部下拉的距离
  196. stop: 20 // 回弹停留的距离
  197. },
  198. pullUpLoad: {
  199. threshold: -20
  200. },
  201. scrollbar: true
  202. })
  203. this.scroll.on('pullingDown', () => {
  204. this.onRefresh()
  205. })
  206. this.scroll.on('pullingUp', () => {
  207. this.getList()
  208. })
  209. this.scroll.on('scroll', ({ y }) => {
  210. this.$emit('setShowHeader', Math.abs(y) < this.screenHeight)
  211. })
  212. } else {
  213. this.scroll.finishPullDown()
  214. this.scroll.finishPullUp()
  215. this.scroll.refresh()
  216. }
  217. })
  218. }
  219. } else {
  220. Toast(msg)
  221. }
  222. this.isFetchLock = false
  223. } catch (err) {
  224. this.isFetchLock = false
  225. }
  226. },
  227. getOrderDetail (id) {
  228. this.$router.push({
  229. name: 'CategoryDetail',
  230. params: {
  231. source: this.source,
  232. goodsId: id
  233. }
  234. })
  235. }
  236. },
  237. beforeDestroy () {
  238. this.scroll && this.scroll.destroy()
  239. }
  240. }
  241. </script>
  242. <style lang="scss" scoped>
  243. .wrapper {
  244. position: absolute;
  245. left: 0;
  246. top: 0;
  247. right: 0;
  248. bottom: 0;
  249. width: 100%;
  250. overflow: hidden;
  251. ul {
  252. display: flex;
  253. flex-direction: column;
  254. align-items: center;
  255. width: 100%;
  256. padding: 136px 0 102px;
  257. }
  258. }
  259. .pulldown-wrapper {
  260. position: absolute;
  261. left: 0;
  262. top: -43px;
  263. width: 100%;
  264. text-align: center;
  265. margin-bottom: 10px;
  266. &.static {
  267. position: static;
  268. left: 0;
  269. top: 0;
  270. }
  271. }
  272. .pullup-wrapper {
  273. width: 100%;
  274. text-align: center;
  275. .van-loading {
  276. margin-top: 16px;
  277. }
  278. }
  279. .list-item {
  280. display: flex;
  281. width: 355px;
  282. min-height: 138px;
  283. background: #FEFEFE;
  284. border-radius: 5px;
  285. margin-bottom: 10px;
  286. padding: 9px;
  287. }
  288. .photo {
  289. width: 121px;
  290. height: 121px;
  291. margin-right: 10px;
  292. border-radius: 6px;
  293. overflow: hidden;
  294. img {
  295. display: block;
  296. width: 100%;
  297. }
  298. }
  299. .info {
  300. width: 206px;
  301. padding-top: 6px;
  302. }
  303. .top {
  304. position: relative;
  305. left: 0;
  306. top: 0;
  307. img {
  308. position: absolute;
  309. left: 0;
  310. top: 0;
  311. width: 30px;
  312. height: 16px;
  313. }
  314. p {
  315. display: -webkit-box;
  316. font-size: 14px;
  317. font-weight: bold;
  318. color: #333333;
  319. line-height: 18px;
  320. -webkit-line-clamp: 2;
  321. -webkit-box-orient: vertical;
  322. overflow: hidden;
  323. text-indent: 34px;
  324. }
  325. }
  326. .middle {
  327. display: flex;
  328. align-items: flex-end;
  329. justify-content: space-between;
  330. margin-top: 8px;
  331. }
  332. .price-wrap {
  333. display: flex;
  334. align-items: flex-end;
  335. }
  336. .price {
  337. margin-right: 8px;
  338. font-size: 0;
  339. span {
  340. &:nth-of-type(1) {
  341. margin-right: 4px;
  342. font-size: 12px;
  343. font-weight: bold;
  344. color: #EA483F;
  345. line-height: 18px;
  346. }
  347. &:nth-of-type(2) {
  348. font-size: 16px;
  349. font-weight: bolder;
  350. color: #EA483F;
  351. line-height: 18px;
  352. }
  353. }
  354. }
  355. .origin {
  356. font-size: 10px;
  357. text-decoration: line-through;
  358. color: #999999;
  359. line-height: 18px;
  360. }
  361. .sale-count {
  362. font-size: 0;
  363. span {
  364. font-size: 10px;
  365. color: #999999;
  366. line-height: 18px;
  367. &:nth-of-type(1) {
  368. margin-right: 4px;
  369. }
  370. }
  371. }
  372. .card {
  373. display: flex;
  374. align-items: center;
  375. margin-top: 4px;
  376. }
  377. .coupon {
  378. display: flex;
  379. justify-content: center;
  380. align-items: center;
  381. min-width: 57px;
  382. height: 18px;
  383. background: url("../image/ic_coupon.png") center center/100% 100% no-repeat;
  384. margin-right: 11px;
  385. span {
  386. font-size: 11px;
  387. font-weight: bold;
  388. color: #FFFFFF;
  389. line-height: 18px;
  390. &:nth-of-type(1) {
  391. margin-right: 2px;
  392. }
  393. }
  394. }
  395. .profit {
  396. display: flex;
  397. justify-content: center;
  398. align-items: center;
  399. min-width: 82px;
  400. height: 19px;
  401. background: #FBF4F4;
  402. padding: 0 8px;
  403. border-radius: 3px;
  404. span {
  405. font-size: 10px;
  406. font-weight: 500;
  407. color: #D64136;
  408. line-height: 18px;
  409. &:nth-of-type(1) {
  410. margin-right: 2px;
  411. }
  412. }
  413. }
  414. .shop {
  415. display: flex;
  416. align-items: center;
  417. margin-top: 8px;
  418. p {
  419. width: calc(100% - 24px);
  420. margin-left: 4px;
  421. font-size: 12px;
  422. font-weight: 500;
  423. color: #999999;
  424. line-height: 22px;
  425. overflow: hidden;
  426. white-space: nowrap;
  427. text-overflow: ellipsis;
  428. }
  429. }
  430. </style>