多租户商城-商户小程序端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

96 lines
2.4 KiB

3 years ago
  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. this.productData = [{},{},{},{},{},{},{},{}]
  59. if (_.componentContent.productData.sourceType === '1') {
  60. if(_.componentContent.productData.productIdList && _.componentContent.productData.productIdList.length>0){
  61. _.sendReq({
  62. url: `${api.getProducts}?page=1&pageSize=99&ids=${_.componentContent.productData.productIdList}`,
  63. method: 'GET'
  64. }, (proRes) => {
  65. _.productData = proRes.data.list
  66. _.productData = _.productData.filter(item=>JSON.stringify(item) !== '{}')
  67. if(isFirst){
  68. _.componentContent.productData.imgTextData = _.productData
  69. }
  70. })
  71. } else {
  72. _.productData = []
  73. }
  74. } else if(_.componentContent.productData.sourceType === '2'){
  75. if(_.componentContent.productData.categoryId) {
  76. _.sendReq({
  77. url: `${api.getProducts}?page=1&pageSize=99&classifyId=${_.componentContent.productData.categoryId}`,
  78. method: 'GET'
  79. }, (proRes) => {
  80. _.productData = proRes.data.list
  81. _.productData = _.productData.filter(item=>JSON.stringify(item) !== '{}')
  82. if(isFirst){
  83. _.componentContent.productData.imgTextData = _.productData
  84. }
  85. // _.swiper.update()
  86. })
  87. } else {
  88. _.productData = {
  89. products:[]
  90. }
  91. }
  92. }
  93. },
  94. }
  95. }