index.js 6.9 KB

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