index.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  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. getApp().globalData.Language.showToast('未查询到授权品牌')
  181. this.setData({
  182. brandList: [],
  183. loading: false,
  184. list: [],
  185. typeList: []
  186. })
  187. }
  188. })
  189. },
  190. /* 切换品牌 */
  191. brandChange(e) {
  192. this.data.brand = e.detail.item;
  193. this.getTypeList();
  194. },
  195. /* 获取分类 */
  196. getTypeList() {
  197. let content = {
  198. sa_brandid: this.data.brand.sa_brandid,
  199. nocache: true,
  200. where: {
  201. istool: 0, //默认0,不是工具,1表示工具
  202. }
  203. }
  204. if (this.data.sys_enterpriseid) content.sys_enterpriseid = this.data.sys_enterpriseid;
  205. _Http.basic({
  206. "id": "20220922110403",
  207. "pageSize": 1000,
  208. content
  209. }).then(res => {
  210. console.log("营销类别", res)
  211. if (res.data[0].ttemclass) {
  212. res.data[0].ttemclass.unshift({
  213. itemclassid: "",
  214. itemclassfullname: "全部",
  215. itemclassname: "全部",
  216. subdep: []
  217. })
  218. this.setData({
  219. ['typeList[0]']: {
  220. active: 0,
  221. list: res.data[0].ttemclass
  222. },
  223. "cType": res.data[0].ttemclass[0],
  224. loading: false
  225. });
  226. }
  227. this.getList(true);
  228. })
  229. },
  230. /* 获取产品 */
  231. getList(init = false) {
  232. if (init.detail != undefined) init = init.detail;
  233. let content = JSON.parse(JSON.stringify(this.data.content));
  234. if (init) content.pageNumber = 1;
  235. if (content.pageNumber > content.pageTotal) return;
  236. content.brandids = [this.data.brand.sa_brandid];
  237. content.where.itemclassid = this.data.cType.itemclassid || "";
  238. content.where.tradefield = this.data.tradefieid || "";
  239. content.where.standards = this.data.standard || '';
  240. if (this.data.sys_enterpriseid) content.sys_enterpriseid = this.data.sys_enterpriseid;
  241. _Http.basic({
  242. "id": 20220926142203,
  243. content
  244. }).then(res => {
  245. console.log("商品列表", res)
  246. if (res.msg != '成功') return wx.showToast({
  247. title: res.msg,
  248. icon: "none"
  249. })
  250. this.selectComponent('#ListBox').RefreshToComplete();
  251. this.setData({
  252. list: res.pageNumber == 1 ? res.data : this.data.list.concat(res.data),
  253. "content.pageNumber": res.pageNumber + 1,
  254. "content.pageTotal": res.pageTotal,
  255. "content.sort": res.sort,
  256. loading: false
  257. })
  258. this.setListHeight()
  259. })
  260. },
  261. /* 搜索 */
  262. onSearch({
  263. detail
  264. }) {
  265. this.setData({
  266. "content.where.condition": detail
  267. });
  268. this.getList(true)
  269. },
  270. onReady() {
  271. this.setListHeight()
  272. },
  273. /* 设置页面高度 */
  274. setListHeight() {
  275. this.selectComponent("#ListBox").setHeight(".division", this);
  276. },
  277. /* 获取购物车数量 */
  278. getNum() {
  279. if (this.data.userrole == '业务员') return;
  280. _Http.basic({
  281. "id": 20220927093202,
  282. "content": {}
  283. }).then(res => {
  284. console.log("购物车数量", res)
  285. getApp().globalData.num = res.data.num;
  286. this.selectComponent("#Float").setNum(res.data.num)
  287. });
  288. },
  289. onShow() {
  290. if (getApp().globalData.num && this.data.userrole != '业务员') this.selectComponent("#Float").setNum(getApp().globalData.num)
  291. }
  292. })