多租户商城-商户小程序端
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.

70 lines
1.4 KiB

  1. import api from '../../config/api'
  2. import { funMixin } from '../../config/mixin'
  3. export const commonMixin = {
  4. name: 'classifyHeaderComponent',
  5. mixins: [funMixin],
  6. props: {
  7. terminal: {
  8. type: Number,
  9. default: 4,
  10. },
  11. typeId: {
  12. type: Number,
  13. default: 1,
  14. },
  15. shopId: {
  16. type: Number,
  17. default: 0,
  18. },
  19. componentContent: {
  20. type: Object,
  21. },
  22. },
  23. data() {
  24. return {
  25. classifyData: [],
  26. activeTab: 0,
  27. beginIndex: 0,
  28. productData:[]
  29. }
  30. },
  31. mounted() {
  32. this.beginIndex = (this.componentContent.firstClassify && this.componentContent.firstClassify.length ) ? 1 : 0
  33. this.getData()
  34. },
  35. methods: {
  36. getData() {
  37. const _ = this
  38. _.sendReq(
  39. {
  40. url: `${api.getClassify}?page=1&pageSize=20`,
  41. method: 'GET',
  42. },
  43. (res) => {
  44. _.classifyData = res.data
  45. this.getProducts()
  46. },
  47. (err) => {}
  48. )
  49. },
  50. tabChange (index, id) {
  51. this.activeTab = index
  52. this.getProducts()
  53. this.$emit('tabChange', index, id)
  54. },
  55. getProducts(){
  56. const _ = this
  57. if(this.activeTab >= this.beginIndex) {
  58. _.sendReq({
  59. url: `${api.getProductsV2}?page=1&pageSize=20&classifyId=${_.classifyData[this.activeTab-this.beginIndex].id}`,
  60. method: 'GET'
  61. }, (proRes) => {
  62. _.productData = proRes.data.list
  63. })
  64. } else {
  65. _.productData = []
  66. }
  67. }
  68. },
  69. }