mixin.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import {funMixin} from '../../config/mixin'
  2. // import { directive, Swiper, SwiperSlide } from 'vue-awesome-swiper'
  3. // import 'swiper/css/swiper.css'
  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. mounted() {
  38. this.getData(true)
  39. },
  40. watch: {
  41. 'componentContent': {
  42. handler(newVal, oldVal) {
  43. this.getData()
  44. },
  45. deep: true
  46. }
  47. },
  48. methods: {
  49. getData(isFirst) {
  50. const _ = this
  51. if (_.componentContent.productData.sourceType === '1') {
  52. if(_.componentContent.productData.productIdList && _.componentContent.productData.productIdList.length>0){
  53. _.sendReq({
  54. url: `${api.getProductsV2}?page=1&pageSize=99&ids=${_.componentContent.productData.productIdList}`,
  55. method: 'GET'
  56. }, (proRes) => {
  57. _.productData = proRes.data.list
  58. if(isFirst){
  59. _.componentContent.productData.imgTextData = _.productData
  60. }
  61. // _.$forceUpdate() // 刷新轮播图
  62. })
  63. } else {
  64. _.productData = []
  65. }
  66. } else if(_.componentContent.productData.sourceType === '2'){
  67. if(_.componentContent.productData.categoryId) {
  68. _.sendReq({
  69. url: `${api.getProductsV2}?page=1&pageSize=99&classifyId=${_.componentContent.productData.categoryId}`,
  70. method: 'GET'
  71. }, (proRes) => {
  72. _.productData = proRes.data.list
  73. if(isFirst){
  74. _.componentContent.productData.imgTextData = _.productData
  75. }
  76. _.$forceUpdate() // 刷新轮播图
  77. // _.swiper.update()
  78. })
  79. } else {
  80. _.productData = []
  81. }
  82. }
  83. }
  84. },
  85. }