index.js 6.0 KB

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