mixin.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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: []
  35. }
  36. },
  37. watch: {
  38. 'componentContent': {
  39. handler(newVal, oldVal) {
  40. this.getData()
  41. },
  42. deep: true
  43. }
  44. },
  45. created() {
  46. this.getData(true)
  47. },
  48. computed: {
  49. swiper() {
  50. if(this.$refs.mySwiper){
  51. return this.$refs.mySwiper.$swiper
  52. }
  53. }
  54. },
  55. methods: {
  56. getData(isFirst) {
  57. const _ = this
  58. if (_.componentContent.productData.sourceType === '1') {
  59. if(_.componentContent.productData.productIdList && _.componentContent.productData.productIdList.length>0){
  60. _.sendReq({
  61. url: `${api.getProducts}?page=1&pageSize=99&ids=${_.componentContent.productData.productIdList}`,
  62. method: 'GET'
  63. }, (proRes) => {
  64. _.productData = proRes.data.list
  65. if(isFirst){
  66. _.componentContent.productData.imgTextData = _.productData
  67. }
  68. })
  69. } else {
  70. _.productData = []
  71. }
  72. } else if(_.componentContent.productData.sourceType === '2'){
  73. if(_.componentContent.productData.categoryId) {
  74. _.sendReq({
  75. url: `${api.getProducts}?page=1&pageSize=99&classifyId=${_.componentContent.productData.categoryId}`,
  76. method: 'GET'
  77. }, (proRes) => {
  78. _.productData = proRes.data.list
  79. if(isFirst){
  80. _.componentContent.productData.imgTextData = _.productData
  81. }
  82. // _.swiper.update()
  83. })
  84. } else {
  85. _.productData = {
  86. products:[]
  87. }
  88. }
  89. }
  90. },
  91. }
  92. }