main.vue 8.7 KB

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