index.js 6.6 KB

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