index.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. const content = {
  2. pageNumber: 1,
  3. pageTotal: 1,
  4. where: {
  5. condition: "",
  6. itemclassid: "",
  7. tradefield: ""
  8. }
  9. },
  10. _Http = getApp().globalData.http;
  11. let sa_brandid = null,
  12. downCount = null;
  13. Component({
  14. options: {
  15. addGlobalClass: true
  16. },
  17. data: {
  18. CustomBar: getApp().globalData.CustomBar,
  19. typeList: [],
  20. list: [],
  21. filtratelist: []
  22. },
  23. methods: {
  24. init() {
  25. this.getBrand();
  26. this.getTradefie();
  27. this.setData({
  28. hidePrice: wx.getStorageSync('hidePrice'),
  29. })
  30. return true;
  31. },
  32. showModal(e) {
  33. this.setData({
  34. modalName: e.currentTarget.dataset.target
  35. })
  36. },
  37. hideModal(e) {
  38. this.setData({
  39. modalName: null
  40. })
  41. },
  42. /* 获取品牌 */
  43. getBrand() {
  44. getApp().globalData.setTemporaryId = this.handleFiltrate.bind(this);
  45. _Http.basic({
  46. "id": 20220924163702,
  47. content: {
  48. nocache: true,
  49. pageSize: 999,
  50. }
  51. }).then(res => {
  52. console.log("查询品牌", res)
  53. if (res.msg != '成功') return wx.showToast({
  54. title: res.msg,
  55. icon: "none"
  56. });
  57. if (res.data.length != 0) {
  58. sa_brandid = res.data[0].sa_brandid;
  59. this.getTypeList();
  60. } else {
  61. wx.showToast({
  62. title: '未查询到授权品牌',
  63. icon: "none"
  64. })
  65. }
  66. })
  67. },
  68. /* 获取分类 */
  69. getTypeList() {
  70. _Http.basic({
  71. "id": "20220922110403",
  72. pageSize: 1000,
  73. content: {
  74. nocache: true,
  75. sa_brandid: sa_brandid,
  76. where: {
  77. istool: 0,
  78. }
  79. }
  80. }).then(res => {
  81. console.log("营销类别", res)
  82. if (res.data[0].ttemclass) {
  83. res.data[0].ttemclass.unshift({
  84. itemclassid: "",
  85. itemclassfullname: "全部",
  86. itemclassname: "全部",
  87. subdep: []
  88. })
  89. this.data.filtratelist.push({
  90. label: "营销分类",
  91. index: 0,
  92. type: "multilevelClass",
  93. showName: "itemclassname", //显示字段
  94. valueKey: "itemclassid", //返回Key
  95. selectKey: "itemclassid", //传参 代表选着字段 不传参返回整个选择对象
  96. value: "", //选中值
  97. list: res.data[0].ttemclass
  98. })
  99. this.setData({
  100. filtratelist: this.data.filtratelist
  101. });
  102. }
  103. this.getList(true);
  104. })
  105. },
  106. /* 获取产品 */
  107. getList(init = false) {
  108. if (init.detail != undefined) init = init.detail;
  109. if (init) content.pageNumber = 1;
  110. if (content.pageNumber > content.pageTotal) return;
  111. content.brandids = [sa_brandid];
  112. _Http.basic({
  113. "id": 20220926142203,
  114. content
  115. }).then(res => {
  116. console.log("商品列表", res)
  117. if (res.msg != '成功') return wx.showToast({
  118. title: res.msg,
  119. icon: "none"
  120. })
  121. this.selectComponent('#ListBox').RefreshToComplete();
  122. content.pageNumber = res.pageNumber + 1;
  123. content.pageTotal = res.pageTotal;
  124. this.setData({
  125. list: res.pageNumber == 1 ? res.data : this.data.list.concat(res.data)
  126. })
  127. this.setListHeight()
  128. })
  129. },
  130. /* 开始搜索 */
  131. onSearch({
  132. detail
  133. }) {
  134. content.where.condition = detail;
  135. this.getList(true)
  136. },
  137. /* 获取领域 */
  138. getTradefie() {
  139. _Http.basic({
  140. "id": 20221223141802,
  141. content: {
  142. nocache: true,
  143. pageNumber: 1,
  144. pageSize: 9999,
  145. where: {
  146. condition: ""
  147. }
  148. }
  149. }, false).then(res => {
  150. console.log("获取领域", res)
  151. if (res.msg == '成功' && res.data.length > 1) {
  152. res.data.unshift({
  153. rowindex: 0,
  154. subvalues: [],
  155. sys_enterprise_tradefieldid: 0,
  156. tradefield: "全部"
  157. })
  158. this.data.filtratelist.unshift({
  159. label: "领域",
  160. index: 0,
  161. showName: "tradefield", //显示字段
  162. valueKey: "tradefield", //返回Key
  163. selectKey: "tradefield", //传参 代表选着字段 不传参返回整个选择对象
  164. value: "", //选中值
  165. list: res.data
  166. })
  167. this.setData({
  168. filtratelist: this.data.filtratelist
  169. });
  170. }
  171. })
  172. },
  173. /* 设置页面高度 */
  174. setListHeight() {
  175. this.selectComponent("#ListBox").setHeight(".division", this);
  176. },
  177. handleFiltrate({
  178. detail
  179. }) {
  180. clearTimeout(downCount);
  181. if (detail.tradefield) content.where.tradefield = detail.tradefield == '全部' ? "" : detail.tradefield;
  182. content.where.itemclassid = detail.temporaryId || detail.temporaryId == '' ? detail.temporaryId : content.where.itemclassid;
  183. downCount = setTimeout(() => {
  184. this.getList(true);
  185. }, 300);
  186. }
  187. }
  188. })