index.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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. brandChange(e) {
  98. this.data.brand = e.detail.item;
  99. this.getTypeList();
  100. },
  101. /* 获取分类 */
  102. getTypeList() {
  103. _Http.basic({
  104. "id": "20220926095202",
  105. "istool": 1, //默认0,不是工具,1表示工具
  106. "pageSize": 1000,
  107. "content": {
  108. "sa_brandid": this.data.brand.sa_brandid
  109. }
  110. }).then(res => {
  111. console.log("工具营销类别", res)
  112. if (res.data[0].ttemclass) {
  113. res.data[0].ttemclass.unshift({
  114. itemclassid: "",
  115. itemclassfullname: "全部",
  116. itemclassname: "全部",
  117. subdep: []
  118. })
  119. this.setData({
  120. ['typeList[0]']: {
  121. active: 0,
  122. list: res.data[0].ttemclass
  123. },
  124. "cType": res.data[0].ttemclass[0]
  125. });
  126. }
  127. this.getList(true);
  128. })
  129. },
  130. /* 获取产品 */
  131. getList(init = false) {
  132. if (init.detail != undefined) init = init.detail;
  133. let content = this.data.content;
  134. if (init) content.pageNumber = 1;
  135. if (content.pageNumber > content.pageTotal) return;
  136. content.brandids = [this.data.brand.sa_brandid];
  137. content.itemclassids = this.data.cType.itemclassid ? [this.data.cType.itemclassid] : [''];
  138. _Http.basic({
  139. "id": 20220924163802,
  140. content
  141. }).then(res => {
  142. console.log("工具列表", res)
  143. this.selectComponent('#ListBox').RefreshToComplete();
  144. this.setData({
  145. list: res.data,
  146. "content.pageNumber": res.pageNumber + 1,
  147. "content.pageTotal": res.pageTotal,
  148. "content.sort": res.sort,
  149. loading: false
  150. })
  151. this.setListHeight()
  152. })
  153. },
  154. startFiltration() {
  155. /* _Http.basic().then(res => {
  156. console.log("获取领域", res)
  157. }) */
  158. },
  159. /* 搜索 */
  160. onSearch({
  161. detail
  162. }) {
  163. this.setData({
  164. "content.where.condition": detail
  165. });
  166. this.getList(true)
  167. },
  168. onReady() {
  169. this.setListHeight()
  170. },
  171. /* 设置页面高度 */
  172. setListHeight() {
  173. this.selectComponent("#ListBox").setHeight(".division", this);
  174. },
  175. /* 获取购物车数量 */
  176. getNum() {
  177. _Http.basic({
  178. "id": 20220927093202,
  179. "content": {}
  180. }).then(res => {
  181. console.log("购物车数量", res)
  182. getApp().globalData.num = res.data.num;
  183. this.selectComponent("#Float").setNum(res.data.num)
  184. });
  185. },
  186. onShow() {
  187. if (getApp().globalData.num) this.selectComponent("#Float").setNum(getApp().globalData.num)
  188. }
  189. })