main.vue 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428
  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 border-bottom-1px"
  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. }
  114. },
  115. methods: {
  116. init () {
  117. this.finished = false
  118. this.isRefresh = false
  119. this.isFetchLock = false
  120. this.pagenum = 0
  121. this.pagesize = 20
  122. this.list = []
  123. if (this.scroll) {
  124. this.scroll.scrollTo(0, 0)
  125. }
  126. this.getList()
  127. },
  128. onRefresh () {
  129. this.pagenum = 0
  130. this.pagesize = 20
  131. this.finished = false
  132. this.isRefresh = true
  133. this.getList()
  134. },
  135. async getList () {
  136. if (this.finished) {
  137. return
  138. }
  139. if (this.isFetchLock) {
  140. return
  141. }
  142. this.isFetchLock = true
  143. this.pagenum++
  144. try {
  145. const { status, data, msg } = await apiGoodsList({
  146. page: this.pagenum,
  147. page_size: this.pagesize,
  148. source: this.source,
  149. cat_id: this.catId
  150. })
  151. if (status) {
  152. const { list } = data
  153. // 下拉刷新数据清空
  154. if (this.isRefresh) {
  155. this.isRefresh = false
  156. this.list = []
  157. }
  158. // 没有数据返回了
  159. if (Array.isArray(list) && !list.length) {
  160. this.finished = true
  161. }
  162. if (Array.isArray(list) && list.length) {
  163. // 总页数小于等于1页时
  164. if (list.length < this.pagesize) {
  165. this.finished = true
  166. }
  167. this.list = this.list.concat(list)
  168. this.$nextTick(() => {
  169. if (!this.scroll) {
  170. this.scroll = new BScroll(this.$refs.returnWrapper, {
  171. click: true,
  172. pullDownRefresh: {
  173. threshold: 50, // 顶部下拉的距离
  174. stop: 20 // 回弹停留的距离
  175. },
  176. pullUpLoad: {
  177. threshold: -20
  178. },
  179. scrollbar: true
  180. })
  181. this.scroll.on('pullingDown', () => {
  182. this.onRefresh()
  183. })
  184. this.scroll.on('pullingUp', () => {
  185. this.getList()
  186. })
  187. } else {
  188. this.scroll.finishPullDown()
  189. this.scroll.finishPullUp()
  190. this.scroll.refresh()
  191. }
  192. })
  193. }
  194. } else {
  195. Toast(msg)
  196. }
  197. this.isFetchLock = false
  198. } catch (err) {
  199. this.isFetchLock = false
  200. }
  201. },
  202. getOrderDetail (id) {
  203. this.$router.push({
  204. name: 'CategoryDetail',
  205. params: {
  206. source: this.source,
  207. goodsId: id
  208. }
  209. })
  210. }
  211. },
  212. beforeDestroy () {
  213. this.scroll && this.scroll.destroy()
  214. }
  215. }
  216. </script>
  217. <style lang="scss" scoped>
  218. .wrapper {
  219. position: absolute;
  220. left: 0;
  221. top: 137px;
  222. right: 0;
  223. bottom: 0;
  224. width: 100%;
  225. overflow: hidden;
  226. ul {
  227. display: flex;
  228. flex-direction: column;
  229. align-items: center;
  230. width: 100%;
  231. padding: 0 0 102px;
  232. }
  233. }
  234. .pulldown-wrapper {
  235. position: absolute;
  236. left: 0;
  237. top: -43px;
  238. width: 100%;
  239. text-align: center;
  240. margin-bottom: 10px;
  241. &.static {
  242. position: static;
  243. left: 0;
  244. top: 0;
  245. }
  246. }
  247. .pullup-wrapper {
  248. width: 100%;
  249. text-align: center;
  250. .van-loading {
  251. margin-top: 16px;
  252. }
  253. }
  254. .list-item {
  255. display: flex;
  256. width: 355px;
  257. min-height: 138px;
  258. background: #FEFEFE;
  259. border-radius: 5px;
  260. margin-bottom: 10px;
  261. padding: 9px;
  262. }
  263. .photo {
  264. width: 121px;
  265. height: 121px;
  266. margin-right: 10px;
  267. border-radius: 6px;
  268. overflow: hidden;
  269. img {
  270. display: block;
  271. width: 100%;
  272. }
  273. }
  274. .info {
  275. width: 206px;
  276. padding-top: 6px;
  277. }
  278. .top {
  279. p {
  280. display: -webkit-box;
  281. font-size: 14px;
  282. font-weight: bold;
  283. color: #333333;
  284. line-height: 18px;
  285. -webkit-line-clamp: 2;
  286. -webkit-box-orient: vertical;
  287. overflow: hidden;
  288. }
  289. }
  290. .middle {
  291. display: flex;
  292. align-items: flex-end;
  293. justify-content: space-between;
  294. margin-top: 8px;
  295. }
  296. .price-wrap {
  297. display: flex;
  298. align-items: flex-end;
  299. }
  300. .price {
  301. margin-right: 8px;
  302. font-size: 0;
  303. span {
  304. &:nth-of-type(1) {
  305. margin-right: 4px;
  306. font-size: 12px;
  307. font-weight: bold;
  308. color: #EA483F;
  309. line-height: 18px;
  310. }
  311. &:nth-of-type(2) {
  312. font-size: 16px;
  313. font-weight: bolder;
  314. color: #EA483F;
  315. line-height: 18px;
  316. }
  317. }
  318. }
  319. .origin {
  320. font-size: 10px;
  321. text-decoration: line-through;
  322. color: #999999;
  323. line-height: 18px;
  324. }
  325. .sale-count {
  326. font-size: 0;
  327. span {
  328. font-size: 10px;
  329. color: #999999;
  330. line-height: 18px;
  331. &:nth-of-type(1) {
  332. margin-right: 4px;
  333. }
  334. }
  335. }
  336. .card {
  337. display: flex;
  338. align-items: center;
  339. margin-top: 4px;
  340. }
  341. .coupon {
  342. display: flex;
  343. justify-content: center;
  344. align-items: center;
  345. min-width: 57px;
  346. height: 18px;
  347. background: url("../image/ic_coupon.png") center center/100% 100% no-repeat;
  348. margin-right: 11px;
  349. span {
  350. font-size: 11px;
  351. font-weight: bold;
  352. color: #FFFFFF;
  353. line-height: 18px;
  354. &:nth-of-type(1) {
  355. margin-right: 2px;
  356. }
  357. }
  358. }
  359. .profit {
  360. display: flex;
  361. justify-content: center;
  362. align-items: center;
  363. min-width: 82px;
  364. height: 19px;
  365. background: #FBF4F4;
  366. padding: 0 8px;
  367. border-radius: 3px;
  368. span {
  369. font-size: 10px;
  370. font-weight: 500;
  371. color: #D64136;
  372. line-height: 18px;
  373. &:nth-of-type(1) {
  374. margin-right: 2px;
  375. }
  376. }
  377. }
  378. .shop {
  379. display: flex;
  380. align-items: center;
  381. margin-top: 8px;
  382. p {
  383. width: calc(100% - 24px);
  384. margin-left: 4px;
  385. font-size: 12px;
  386. font-weight: 500;
  387. color: #999999;
  388. line-height: 22px;
  389. overflow: hidden;
  390. white-space: nowrap;
  391. text-overflow: ellipsis;
  392. }
  393. }
  394. </style>