mixin.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. // import { directive, Swiper, SwiperSlide } from 'vue-awesome-swiper'
  2. // import 'swiper/css/swiper.css'
  3. import {funMixin} from '../../config/mixin'
  4. import api from '../../config/api'
  5. export const commonMixin = {
  6. name: 'productList',
  7. mixins: [funMixin],
  8. props: {
  9. terminal: {
  10. type: Number,
  11. default: 4
  12. },
  13. typeId: {
  14. type: Number,
  15. default: 1
  16. },
  17. shopId: {
  18. type: Number,
  19. default: 0
  20. },
  21. componentContent: {
  22. type: Object
  23. }
  24. },
  25. // components: {
  26. // Swiper,
  27. // SwiperSlide
  28. // },
  29. // directives: {
  30. // swiper: directive
  31. // },
  32. data () {
  33. return {
  34. productData: [1,2,3,4],
  35. pageTotal:0,
  36. pageSize:8,
  37. currentPage:1,
  38. loading:true,
  39. isFirst:true
  40. }
  41. },
  42. watch: {
  43. 'componentContent': {
  44. handler(newVal, oldVal) {
  45. //this.getData()
  46. },
  47. deep: true
  48. }
  49. },
  50. created() {
  51. this.getData(true)
  52. },
  53. computed: {
  54. swiper() {
  55. if(this.$refs.mySwiper){
  56. return this.$refs.mySwiper.$swiper
  57. }
  58. }
  59. },
  60. methods: {
  61. getData() {
  62. const _ = this
  63. // 纵向
  64. _.loading=true
  65. if (_.componentContent.productData.sourceType === '1') {
  66. if(_.componentContent.productData.productIdList && _.componentContent.productData.productIdList.length>0){
  67. _.sendReq({
  68. url: `${api.getProductsV2}?page=${_.currentPage}&pageSize=${_.pageSize}&ids=${_.componentContent.productData.productIdList}`,
  69. method: 'GET'
  70. }, (proRes) => {
  71. _.productData = [..._.productData,...proRes.data.list].filter(item=>!!item.productId)
  72. _.pageTotal = proRes.data.total
  73. if(_.isFirst){
  74. _.componentContent.productData.imgTextData = _.productData
  75. }
  76. _.isFirst = false
  77. _.loading = false
  78. })
  79. } else {
  80. _.productData = []
  81. _.isFirst = false
  82. _.loading = false
  83. }
  84. } else if(_.componentContent.productData.sourceType === '2'){
  85. if(_.componentContent.productData.categoryId) {
  86. _.sendReq({
  87. url: `${api.getProductsV2}?page=1&pageSize=99&classifyId=${_.componentContent.productData.categoryId}`,
  88. method: 'GET'
  89. }, (proRes) => {
  90. _.productData = proRes.data.list
  91. _.productData = _.productData.filter(item=>JSON.stringify(item) !== '{}')
  92. if(_.isFirst){
  93. _.componentContent.productData.imgTextData = _.productData
  94. }
  95. // _.swiper.update()
  96. _.isFirst = false
  97. _.loading = false
  98. })
  99. } else {
  100. _.productData = {
  101. products:[]
  102. }
  103. _.isFirst = false
  104. _.loading = false
  105. }
  106. }
  107. },
  108. loadNext(){
  109. if(this.loading)return;
  110. if(this.productData.length>=this.pageTotal && this.pageTotal!==0)return
  111. this.currentPage ++;
  112. this.getData()
  113. }
  114. }
  115. }