mixin.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. import { directive, Swiper, SwiperSlide } from 'vue-awesome-swiper'
  2. import 'swiper/css/swiper.css'
  3. import api from '../../config/api'
  4. import {funMixin} from '../../config/mixin'
  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. computed: {
  39. ...mapGetters([
  40. 'groupNum'
  41. ]),
  42. },
  43. watch: {
  44. 'groupNum': {
  45. handler(newVal, oldVal) {
  46. this.getData()
  47. },
  48. deep: true
  49. }
  50. },
  51. mounted() {
  52. this.getData()
  53. },
  54. methods: {
  55. getData() {
  56. const _ = this
  57. let _url = ''
  58. if(_.typeId === 1){
  59. this.beforeGetData()
  60. const params = {
  61. method: 'GET',
  62. url: `${api.getAdminGroupWorks}`,
  63. }
  64. this.sendReq(params, (res) => {
  65. _.afterGetData()
  66. _.productData.products = res.data
  67. _.$forceUpdate()
  68. },(err)=>{
  69. _.afterGetData()
  70. })
  71. } else if(_.typeId === 3) {
  72. if(_.componentContent.shopGroupWorkId){
  73. this.beforeGetData()
  74. const params = {
  75. method: 'GET',
  76. url: `${api.getGroupWorks}?shopId=${_.shopId}&ids=${_.componentContent.shopGroupWorkId}`,
  77. }
  78. this.sendReq(params, (res) => {
  79. _.afterGetData()
  80. _.productData = res.data[0]
  81. },(err)=>{
  82. _.afterGetData()
  83. })
  84. } else {
  85. _.productData = {
  86. products:[]
  87. }
  88. }
  89. }
  90. },
  91. }
  92. }