index.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. this.getNum();
  21. },
  22. /* 切换分类 */
  23. typeChange({
  24. detail
  25. }) {
  26. let typeList = this.data.typeList;
  27. if (typeList.length - 1 != detail.rowIndex) typeList = typeList.slice(0, detail.rowIndex + 1);
  28. typeList[detail.rowIndex].active = detail.index
  29. if (detail.item.subdep.length) typeList.push({
  30. active: -1,
  31. list: detail.item.subdep
  32. })
  33. this.setData({
  34. cType: detail.item,
  35. typeList
  36. });
  37. this.setListHeight();
  38. this.getList(true);
  39. },
  40. /* 获取品牌 */
  41. getBrand() {
  42. _Http.basic({
  43. "id": 20220924163702,
  44. "content": {
  45. "pageSize": 999,
  46. }
  47. }).then(res => {
  48. console.log("查询品牌", res)
  49. if (res.data.length) this.setData({
  50. brandList: res.data,
  51. brand: res.data[0],
  52. });
  53. this.getTypeList();
  54. })
  55. },
  56. /* 获取分类 */
  57. getTypeList() {
  58. _Http.basic({
  59. "id": "20220922110403",
  60. "content": {
  61. "sa_brandid": this.data.brand.sa_brandid
  62. }
  63. }).then(res => {
  64. console.log("营销类别", res)
  65. if (res.data[0].ttemclass) this.setData({
  66. ['typeList[0]']: {
  67. active: 0,
  68. list: res.data[0].ttemclass
  69. },
  70. "cType": res.data[0].ttemclass[0]
  71. });
  72. this.getList(true);
  73. this.setListHeight()
  74. })
  75. },
  76. /* 获取产品 */
  77. getList(init) {
  78. if (init.detail != undefined) init = init.detail;
  79. let content = this.data.content;
  80. if (init) content.pageNumber = 1;
  81. if (content.pageNumber > content.pageTotal) return;
  82. content.brandids = [this.data.brand.sa_brandid];
  83. content.where.itemclassid = this.data.cType.itemclassid;
  84. _Http.basic({
  85. "id": 20220926142203,
  86. content
  87. }).then(res => {
  88. console.log("商品列表", res)
  89. this.selectComponent('#ListBox').RefreshToComplete();
  90. this.setData({
  91. list: res.data,
  92. "content.pageNumber": res.pageNumber + 1,
  93. "content.pageTotal": res.pageTotal,
  94. "content.sort": res.sort,
  95. loading: false
  96. })
  97. })
  98. },
  99. startFiltration() {
  100. /* _Http.basic().then(res => {
  101. console.log("获取领域", res)
  102. }) */
  103. },
  104. /* 搜索 */
  105. onSearch({
  106. detail
  107. }) {
  108. this.setData({
  109. "content.where.condition": detail
  110. });
  111. this.getList(true)
  112. },
  113. onReady() {
  114. this.setListHeight()
  115. },
  116. /* 设置页面高度 */
  117. setListHeight() {
  118. this.selectComponent("#ListBox").setHeight(".division", this);
  119. },
  120. /* 获取购物车数量 */
  121. getNum() {
  122. _Http.basic({
  123. "id": 20220927093202,
  124. "content": {}
  125. }).then(res => {
  126. console.log("购物车数量", res)
  127. getApp().globalData.num = res.data.num;
  128. this.selectComponent("#Float").setNum(res.data.num)
  129. });
  130. },
  131. onShow() {
  132. if (getApp().globalData.num) this.selectComponent("#Float").setNum(getApp().globalData.num)
  133. }
  134. })