index.js 6.9 KB

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