index.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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. "tradefield": "",
  13. "istool": 1,
  14. "where": {
  15. "condition": ""
  16. },
  17. sort: []
  18. },
  19. filter: [{
  20. label: "领域",
  21. index: null,
  22. showName: "tradefield", //显示字段
  23. valueKey: "tradefield", //返回Key
  24. selectKey: "tradefield", //传参 代表选着字段 不传参返回整个选择对象
  25. value: "", //选中值
  26. list: []
  27. }]
  28. },
  29. onLoad(options) {
  30. this.getBrand()
  31. this.getNum();
  32. this.getDomain();
  33. },
  34. /* 获取领域 */
  35. getDomain() {
  36. _Http.basic({
  37. "id": 20221223141802,
  38. "content": {
  39. "pageNumber": 1,
  40. "pageSize": 99999,
  41. "where": {
  42. "condition": ""
  43. }
  44. }
  45. }).then(res => {
  46. console.log("获取领域", res)
  47. if (res.data.length) this.setData({
  48. "filter[0].list": res.data
  49. });
  50. })
  51. },
  52. /* 处理筛选 */
  53. handleFilter({
  54. detail
  55. }) {
  56. if (detail.tradefield === {}) detail.tradefield = "";
  57. if (detail.tradefield == this.data.content.tradefield) return;
  58. this.setData({
  59. "content.tradefield": detail.tradefield
  60. });
  61. this.getList(true);
  62. },
  63. /* 切换分类 */
  64. typeChange({
  65. detail
  66. }) {
  67. let typeList = this.data.typeList;
  68. if (typeList.length - 1 != detail.rowIndex) typeList = typeList.slice(0, detail.rowIndex + 1);
  69. typeList[detail.rowIndex].active = detail.index
  70. if (detail.item.subdep.length) typeList.push({
  71. active: -1,
  72. list: detail.item.subdep
  73. })
  74. this.setData({
  75. cType: detail.item,
  76. typeList
  77. });
  78. this.getList(true);
  79. },
  80. /* 获取品牌 */
  81. getBrand() {
  82. _Http.basic({
  83. "id": 20220924163702,
  84. "content": {
  85. "pageSize": 999,
  86. }
  87. }).then(res => {
  88. console.log("查询品牌", res)
  89. if (res.data.length) this.setData({
  90. brandList: res.data,
  91. brand: res.data[0],
  92. });
  93. this.getTypeList();
  94. })
  95. },
  96. /* 获取分类 */
  97. getTypeList() {
  98. _Http.basic({
  99. "id": "20220926095202",
  100. "istool": 1, //默认0,不是工具,1表示工具
  101. "pageSize": 1000,
  102. "content": {
  103. "sa_brandid": this.data.brand.sa_brandid
  104. }
  105. }).then(res => {
  106. console.log("工具营销类别", res)
  107. if (res.data[0].ttemclass) this.setData({
  108. ['typeList[0]']: {
  109. active: 0,
  110. list: res.data[0].ttemclass
  111. },
  112. "cType": res.data[0].ttemclass[0]
  113. });
  114. this.getList(true);
  115. })
  116. },
  117. /* 获取产品 */
  118. getList(init = false) {
  119. if (init.detail != undefined) init = init.detail;
  120. let content = this.data.content;
  121. if (init) content.pageNumber = 1;
  122. if (content.pageNumber > content.pageTotal) return;
  123. content.brandids = [this.data.brand.sa_brandid];
  124. content.itemclassids = [this.data.cType.itemclassid];
  125. _Http.basic({
  126. "id": 20220924163802,
  127. content
  128. }).then(res => {
  129. console.log("商品列表", res)
  130. this.selectComponent('#ListBox').RefreshToComplete();
  131. this.setData({
  132. list: res.data,
  133. "content.pageNumber": res.pageNumber + 1,
  134. "content.pageTotal": res.pageTotal,
  135. "content.sort": res.sort,
  136. loading: false
  137. })
  138. this.setListHeight()
  139. })
  140. },
  141. startFiltration() {
  142. /* _Http.basic().then(res => {
  143. console.log("获取领域", res)
  144. }) */
  145. },
  146. /* 搜索 */
  147. onSearch({
  148. detail
  149. }) {
  150. this.setData({
  151. "content.where.condition": detail
  152. });
  153. this.getList(true)
  154. },
  155. onReady() {
  156. this.setListHeight()
  157. },
  158. /* 设置页面高度 */
  159. setListHeight() {
  160. this.selectComponent("#ListBox").setHeight(".division", this);
  161. },
  162. /* 获取购物车数量 */
  163. getNum() {
  164. _Http.basic({
  165. "id": 20220927093202,
  166. "content": {}
  167. }).then(res => {
  168. console.log("购物车数量", res)
  169. getApp().globalData.num = res.data.num;
  170. this.selectComponent("#Float").setNum(res.data.num)
  171. });
  172. },
  173. onShow() {
  174. if (getApp().globalData.num) this.selectComponent("#Float").setNum(getApp().globalData.num)
  175. }
  176. })