main.vue 9.3 KB

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