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