main.vue 8.8 KB

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