index.js 6.6 KB

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