goods-tabs.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import { VueLikePage } from '../../utils/page'
  2. import Router from '../../utils/routes'
  3. import GoodsApi from '../../apis/goods'
  4. VueLikePage([], {
  5. data: {
  6. active: 0,
  7. categoryList: [],
  8. goodsList: []
  9. },
  10. methods: {
  11. async onLoad (options) {
  12. await this.getCategoryList()
  13. if (options.active) {
  14. this.setData({
  15. active: Number(options.active)
  16. })
  17. }
  18. },
  19. search (value) {
  20. },
  21. onChange (e) {
  22. const { index} = e.detail
  23. this.goodsListParams = {
  24. pageNum: 1,
  25. pageSize: 20,
  26. categoryId: this.data.categoryList[index].id
  27. }
  28. this.getCategoryGoodsList()
  29. },
  30. toDetail (e) {
  31. const { goods_id } = e.currentTarget.dataset
  32. Router.push({
  33. url: 'goodsDetail',
  34. query: {
  35. goods_id
  36. }
  37. })
  38. },
  39. getCategoryList () {
  40. return GoodsApi.getCategoryList().then(res => {
  41. this.setData({
  42. categoryList: res.data.list
  43. })
  44. })
  45. },
  46. toSearch () {
  47. Router.push('search')
  48. },
  49. async getCategoryGoodsList (data) {
  50. let res = await GoodsApi.getCategoryGoods(this.goodsListParams)
  51. this.setData({
  52. goodsList: res.data.list
  53. })
  54. }
  55. }
  56. })