main.vue 9.2 KB

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