index.js 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  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. sys_enterpriseid: "",
  28. },
  29. onLoad(options) {
  30. this.setData({
  31. istool: options.istool ? 1 : 0,
  32. userrole: wx.getStorageSync('userrole')
  33. })
  34. this.getBrand()
  35. this.getNum();
  36. this.getTradefie();
  37. this.getOptionTypeSelect();
  38. },
  39. /* 业务员选择角色 */
  40. selsectedRole(e) {
  41. wx.navigateTo({
  42. url: './selected/index',
  43. })
  44. getApp().globalData.handleSelect = this.handleRole.bind(this);
  45. },
  46. handleRole({
  47. sys_enterpriseid,
  48. enterprisename
  49. }) {
  50. console.log(sys_enterpriseid)
  51. this.setData({
  52. buttonText: enterprisename,
  53. tradefieid: "",
  54. sys_enterpriseid
  55. });
  56. this.getBrand();
  57. this.getTradefie();
  58. wx.navigateBack();
  59. },
  60. onCleaRole() {
  61. this.setData({
  62. buttonText: "",
  63. sys_enterpriseid: ""
  64. })
  65. setTimeout(() => {
  66. this.getTradefie();
  67. this.getBrand();
  68. }, 0)
  69. },
  70. /* 获取系统分类 */
  71. getOptionTypeSelect() {
  72. _Http.basic({
  73. "classname": "sysmanage.develop.optiontype.optiontype",
  74. "method": "optiontypeselect",
  75. "content": {
  76. "pageNumber": 1,
  77. "pageSize": 999,
  78. "typename": "itemstandards",
  79. "parameter": {
  80. "siteid": wx.getStorageSync('userMsg').siteid
  81. }
  82. }
  83. }, false).then(res => {
  84. console.log("系统标准列表", res)
  85. if (res.msg == '成功') this.setData({
  86. "filter[0].list": res.data
  87. })
  88. })
  89. },
  90. /* 处理筛选 */
  91. handleFilter({
  92. detail
  93. }) {
  94. console.log(detail)
  95. },
  96. /* 获取领域 */
  97. getTradefie() {
  98. let content = {
  99. nocache: true,
  100. pageNumber: 1,
  101. pageSize: 9999,
  102. where: {
  103. condition: ""
  104. }
  105. };
  106. if (this.data.sys_enterpriseid) content.sys_enterpriseid = this.data.sys_enterpriseid;
  107. _Http.basic({
  108. "id": 20221223141802,
  109. content
  110. }, false).then(res => {
  111. console.log("获取领域", res)
  112. if (res.msg != '成功') {
  113. res.data = [{
  114. rowindex: 0,
  115. subvalues: [],
  116. sys_enterprise_tradefieldid: 0,
  117. tradefield: "全部"
  118. }]
  119. } else {
  120. if (res.data.length == 1) {
  121. res.data[0] = {
  122. rowindex: 0,
  123. subvalues: [],
  124. sys_enterprise_tradefieldid: 0,
  125. tradefield: "全部"
  126. }
  127. } else {
  128. res.data.unshift({
  129. rowindex: 0,
  130. subvalues: [],
  131. sys_enterprise_tradefieldid: 0,
  132. tradefield: "全部"
  133. })
  134. }
  135. }
  136. this.setData({
  137. tradefieid: "",
  138. tradefieList: res.data
  139. });
  140. })
  141. },
  142. /* 切换领域 */
  143. tradefieChange(e) {
  144. this.setData({
  145. tradefieid: e.detail.item.tradefield == '全部' ? "" : e.detail.item.tradefield
  146. })
  147. this.getList(true);
  148. },
  149. /* 切换分类 */
  150. typeChange({
  151. detail
  152. }) {
  153. let typeList = this.data.typeList;
  154. if (typeList.length - 1 != detail.rowIndex) typeList = typeList.slice(0, detail.rowIndex + 1);
  155. typeList[detail.rowIndex].active = detail.index
  156. if (detail.item.subdep.length) typeList.push({
  157. active: -1,
  158. list: detail.item.subdep
  159. })
  160. this.setData({
  161. cType: detail.item,
  162. typeList
  163. });
  164. this.getList(true);
  165. },
  166. /* 获取品牌 */
  167. getBrand() {
  168. let content = {
  169. nocache: true,
  170. pageSize: 999,
  171. };
  172. if (this.data.sys_enterpriseid) content.sys_enterpriseid = this.data.sys_enterpriseid;
  173. _Http.basic({
  174. "id": 20220924163702,
  175. content
  176. }).then(res => {
  177. console.log("查询品牌", res)
  178. if (res.msg != '成功') return wx.showToast({
  179. title: res.msg,
  180. icon: "none"
  181. });
  182. if (res.data.length != 0) {
  183. this.setData({
  184. brandList: res.data,
  185. });
  186. this.data.brand = res.data[0];
  187. this.getTypeList();
  188. } else {
  189. wx.showToast({
  190. title: '未查询到授权品牌',
  191. icon: "none"
  192. })
  193. this.setData({
  194. brandList: [],
  195. loading: false,
  196. list: [],
  197. typeList: []
  198. })
  199. }
  200. })
  201. },
  202. /* 切换品牌 */
  203. brandChange(e) {
  204. this.data.brand = e.detail.item;
  205. this.getTypeList();
  206. },
  207. /* 获取分类 */
  208. getTypeList() {
  209. let content = {
  210. sa_brandid: this.data.brand.sa_brandid,
  211. nocache: true,
  212. where: {
  213. istool: 0, //默认0,不是工具,1表示工具
  214. }
  215. }
  216. if (this.data.sys_enterpriseid) content.sys_enterpriseid = this.data.sys_enterpriseid;
  217. _Http.basic({
  218. "id": "20220922110403",
  219. "pageSize": 1000,
  220. content
  221. }).then(res => {
  222. console.log("营销类别", res)
  223. if (res.data[0].ttemclass) {
  224. res.data[0].ttemclass.unshift({
  225. itemclassid: "",
  226. itemclassfullname: "全部",
  227. itemclassname: "全部",
  228. subdep: []
  229. })
  230. this.setData({
  231. ['typeList[0]']: {
  232. active: 0,
  233. list: res.data[0].ttemclass
  234. },
  235. "cType": res.data[0].ttemclass[0],
  236. loading: false
  237. });
  238. }
  239. this.getList(true);
  240. })
  241. },
  242. /* 获取产品 */
  243. getList(init = false) {
  244. if (init.detail != undefined) init = init.detail;
  245. let content = JSON.parse(JSON.stringify(this.data.content));
  246. if (init) content.pageNumber = 1;
  247. if (content.pageNumber > content.pageTotal) return;
  248. content.brandids = [this.data.brand.sa_brandid];
  249. content.where.itemclassid = this.data.cType.itemclassid;
  250. content.where.tradefield = this.data.tradefieid;
  251. if (this.data.sys_enterpriseid) content.sys_enterpriseid = this.data.sys_enterpriseid;
  252. _Http.basic({
  253. "id": 20220926142203,
  254. content
  255. }).then(res => {
  256. console.log("商品列表", res)
  257. this.selectComponent('#ListBox').RefreshToComplete();
  258. this.setData({
  259. list: res.pageNumber == 1 ? res.data : this.data.list.concat(res.data),
  260. "content.pageNumber": res.pageNumber + 1,
  261. "content.pageTotal": res.pageTotal,
  262. "content.sort": res.sort,
  263. loading: false
  264. })
  265. this.setListHeight()
  266. })
  267. },
  268. startFiltration() {
  269. /* _Http.basic().then(res => {
  270. console.log("获取领域", res)
  271. }) */
  272. },
  273. /* 搜索 */
  274. onSearch({
  275. detail
  276. }) {
  277. this.setData({
  278. "content.where.condition": detail
  279. });
  280. this.getList(true)
  281. },
  282. onReady() {
  283. this.setListHeight()
  284. },
  285. /* 设置页面高度 */
  286. setListHeight() {
  287. this.selectComponent("#ListBox").setHeight(".division", this);
  288. },
  289. /* 获取购物车数量 */
  290. getNum() {
  291. if (this.data.userrole == '业务员') return;
  292. _Http.basic({
  293. "id": 20220927093202,
  294. "content": {}
  295. }).then(res => {
  296. console.log("购物车数量", res)
  297. getApp().globalData.num = res.data.num;
  298. this.selectComponent("#Float").setNum(res.data.num)
  299. });
  300. },
  301. onShow() {
  302. if (getApp().globalData.num && this.data.userrole != '业务员') this.selectComponent("#Float").setNum(getApp().globalData.num)
  303. }
  304. })