index.js 5.8 KB

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