index.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. const _Http = getApp().globalData.http;
  2. Page({
  3. data: {
  4. brand: {}, //当前品牌
  5. brandList: [], //品牌列表
  6. typeList: [],
  7. cType: {},
  8. loading: true,
  9. "content": {
  10. "pageNumber": 1,
  11. "pageTotal": 1,
  12. "where": {
  13. "condition": ""
  14. },
  15. sort: []
  16. },
  17. },
  18. onLoad(options) {
  19. this.getBrand()
  20. },
  21. /* 切换分类 */
  22. typeChange({
  23. detail
  24. }) {
  25. let typeList = this.data.typeList;
  26. if (typeList.length - 1 != detail.rowIndex) typeList = typeList.slice(0, detail.rowIndex + 1);
  27. typeList[detail.rowIndex].active = detail.index
  28. if (detail.item.subdep.length) typeList.push({
  29. active: -1,
  30. list: detail.item.subdep
  31. })
  32. this.setData({
  33. cType: detail.item,
  34. typeList
  35. });
  36. this.setListHeight();
  37. this.getList(true);
  38. },
  39. /* 获取品牌 */
  40. getBrand() {
  41. _Http.basic({
  42. "id": 20220924163702,
  43. "content": {
  44. "pageSize": 999,
  45. }
  46. }).then(res => {
  47. console.log("查询品牌", res)
  48. if (res.data.length) this.setData({
  49. brandList: res.data,
  50. brand: res.data[0],
  51. });
  52. this.getTypeList();
  53. })
  54. },
  55. /* 获取分类 */
  56. getTypeList() {
  57. _Http.basic({
  58. "id": "20220922110403",
  59. "content": {
  60. "sa_brandid": this.data.brand.sa_brandid
  61. }
  62. }).then(res => {
  63. console.log("营销类别", res)
  64. if (res.data[0].ttemclass) this.setData({
  65. ['typeList[0]']: {
  66. active: 0,
  67. list: res.data[0].ttemclass
  68. },
  69. "cType": res.data[0].ttemclass[0]
  70. });
  71. this.getList(true);
  72. this.setListHeight()
  73. })
  74. },
  75. /* 获取产品 */
  76. getList(init) {
  77. if (init.detail != undefined) init = init.detail;
  78. let content = this.data.content;
  79. if (init) content.pageNumber = 1;
  80. if (content.pageNumber > content.pageTotal) return;
  81. content.brandids = [this.data.brand.sa_brandid];
  82. content.where.itemclassid = this.data.cType.itemclassid;
  83. _Http.basic({
  84. "id": 20220926142203,
  85. content
  86. }).then(res => {
  87. console.log("商品列表", res)
  88. this.selectComponent('#ListBox').RefreshToComplete();
  89. this.setData({
  90. list: res.data,
  91. "content.pageNumber": res.pageNumber + 1,
  92. "content.pageTotal": res.pageTotal,
  93. "content.sort": res.sort,
  94. loading: false
  95. })
  96. })
  97. },
  98. /* 去购物车 */
  99. toShopping() {
  100. wx.navigateTo({
  101. url: '/packageA/shopping/index',
  102. })
  103. },
  104. startFiltration() {
  105. /* _Http.basic().then(res => {
  106. console.log("获取领域", res)
  107. }) */
  108. },
  109. /* 搜索 */
  110. onSearch({detail}){
  111. this.setData({
  112. "content.where.condition":detail
  113. });
  114. this.getList(true)
  115. },
  116. onReady() {
  117. this.setListHeight()
  118. },
  119. /* 设置页面高度 */
  120. setListHeight() {
  121. this.selectComponent("#ListBox").setHeight(".division", this);
  122. },
  123. })