classify.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. const Parse = getApp().Parse
  2. const company = getApp().globalData.company
  3. var Nova = getApp().Nova
  4. Component({
  5. /**
  6. * 组件的属性列表
  7. */
  8. properties: {
  9. options: null,
  10. bgColor: {
  11. type: String,
  12. value: '#009de1'
  13. },
  14. active: {
  15. type: Number,
  16. value: 1
  17. },
  18. },
  19. /**
  20. * 组件的初始数据
  21. */
  22. data: {
  23. activeItem: 0,
  24. },
  25. ready: function () { // 在组件布局完成后执行,确保options参数中有data信息
  26. this.getCategory()
  27. },
  28. /**
  29. * 组件的方法列表
  30. */
  31. methods: {
  32. async changeCate(e) {
  33. console.log(e);
  34. let {
  35. id,
  36. index
  37. } = e.currentTarget.dataset
  38. console.log(id);
  39. let query = new Parse.Query("ShopGoods")
  40. query.equalTo("category", id)
  41. query.equalTo("company", company)
  42. let res = await query.find()
  43. let goods = res.reduce((arr, item) => {
  44. let req = item.toJSON()
  45. arr.push(req)
  46. return arr
  47. }, [])
  48. console.log(goods);
  49. this.setData({
  50. goods,
  51. activeItem:index
  52. })
  53. },
  54. async getCategory() {
  55. let cate = new Parse.Query("Category")
  56. cate.equalTo("company", company)
  57. cate.equalTo("type", "shop")
  58. let res = await cate.find()
  59. let categorys = res.reduce((arr, item) => {
  60. let req = item.toJSON()
  61. arr.push(req)
  62. return arr
  63. }, [])
  64. console.log(categorys);
  65. this.setData({
  66. categorys
  67. })
  68. let e = {
  69. currentTarget: {
  70. dataset: {
  71. id: categorys[0].objectId && categorys[0].objectId,
  72. index:0
  73. }
  74. }
  75. }
  76. console.log(e);
  77. categorys.length > 0 && this.changeCate(e)
  78. },
  79. goNovaURL: function (ev) {
  80. let url = ev.currentTarget.dataset.url;
  81. Nova.goNovaURL(url);
  82. }
  83. }
  84. })