index.js 6.7 KB

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