mixin.js 2.4 KB

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