index.js 6.7 KB

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