category.js 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  1. // pages/category/category.js
  2. // pages/home/home.js
  3. const app = getApp();
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. topBarHeight: app.globalData.statBarHeight,
  10. loading: true,
  11. loadding: false,
  12. scrollTop: 0,
  13. current: 0,
  14. pages: null,
  15. picTitle: "",
  16. company: wx.getStorageSync('company'),
  17. userInfo: wx.getStorageSync('userInfo'),
  18. categoryList: [],
  19. category1Index: 0,
  20. category2Index: 0,
  21. category3Index: -1,
  22. goodsList: [],
  23. brandList: [],
  24. query: {
  25. all: 1
  26. }
  27. },
  28. /**
  29. * 生命周期函数--监听页面加载
  30. */
  31. async onLoad(options) {
  32. let categoryId = options.categoryId;
  33. let userInfo = wx.getStorageSync('userInfo');
  34. if (!userInfo || !userInfo.userId) {
  35. // app.globalData.tabbar.list[0].show = true;
  36. // app.globalData.tabbar.list[1].show = false;
  37. wx.navigateTo({
  38. url: '/pages/login/login',
  39. })
  40. return;
  41. }
  42. let {
  43. data: categoryList
  44. } = await app.ajax.get({
  45. url: "/admin/bxdcategory/query"
  46. });
  47. let category1Index = this.data.category1Index;
  48. let categoryLists = categoryList.data.filter(v => v.status == 1);
  49. if (categoryId) {
  50. category1Index = categoryLists.findIndex(v => v.categoryId == categoryId);
  51. }
  52. this.setData({
  53. categoryList: categoryLists,
  54. category1Index: category1Index || 0
  55. });
  56. this.getBrandList();
  57. this.getGoodsList();
  58. this.setData({
  59. loading: false
  60. });
  61. },
  62. /**
  63. * 生命周期函数--监听页面初次渲染完成
  64. */
  65. onReady() {
  66. },
  67. /**
  68. * 生命周期函数--监听页面显示
  69. */
  70. onShow() {
  71. },
  72. selectCategory(e) {
  73. let name = e.currentTarget.dataset.name;
  74. if (this.data["" + e.currentTarget.dataset.name] == e.currentTarget.dataset.index) {
  75. return;
  76. }
  77. if (name.indexOf('1') != -1) {
  78. this.setData({
  79. ["" + name.replace('1', '2')]: 0,
  80. ["" + name.replace('1', '3')]: -1,
  81. goodsList: []
  82. })
  83. } else if (name.indexOf('2') != -1) {
  84. this.setData({
  85. ["" + name.replace('2', '3')]: -1,
  86. goodsList: []
  87. })
  88. } else if (name.indexOf('3') != -1) {
  89. this.setData({
  90. goodsList: []
  91. })
  92. }
  93. let query = this.data.query;
  94. delete query['brandNameList'];
  95. this.setData({
  96. ["" + e.currentTarget.dataset.name]: e.currentTarget.dataset.index,
  97. current: 0,
  98. query
  99. });
  100. this.getBrandList();
  101. this.getGoodsList();
  102. },
  103. async getGoodsList() {
  104. if (this.data.pages != null && this.data.current >= this.data.pages) {
  105. return;
  106. }
  107. let category1 = this.data.categoryList[this.data.category1Index];
  108. if (this.data.category2Index > -1) {
  109. category1 = this.data.categoryList[this.data.category1Index].categories[this.data.category2Index];
  110. }
  111. if (this.data.category3Index > -1) {
  112. category1 = this.data.categoryList[this.data.category1Index].categories[this.data.category2Index].categories[this.data.category3Index];
  113. }
  114. // //console.log(category1, category2, category3)
  115. this.setData({
  116. current: this.data.current + 1,
  117. loadding: true
  118. });
  119. try {
  120. let {
  121. data
  122. } = await app.ajax.get({
  123. url: "/admin/bxdprod/browsePage",
  124. data: {
  125. picTitle: this.data.picTitle,
  126. mini: 1,
  127. current: this.data.current,
  128. size: 20,
  129. categoryIdList: this.getCategoryIdList(category1),
  130. virtualInventoryId: wx.getStorageSync('virtualInventoryId'),
  131. ...this.data.query
  132. }
  133. });
  134. let goodsList = this.data.goodsList;
  135. this.setData({
  136. goodsList: goodsList.concat(data.data.records),
  137. pages: data.data.pages || null,
  138. loadding: false
  139. })
  140. } catch (e) {
  141. this.setData({
  142. loadding: false
  143. })
  144. }
  145. },
  146. async getBrandList() {
  147. let category1 = this.data.categoryList[this.data.category1Index];
  148. if (this.data.category2Index > -1) {
  149. category1 = this.data.categoryList[this.data.category1Index].categories[this.data.category2Index];
  150. }
  151. if (this.data.category3Index > -1) {
  152. category1 = this.data.categoryList[this.data.category1Index].categories[this.data.category2Index].categories[this.data.category3Index];
  153. }
  154. let {
  155. data
  156. } = await app.ajax.get({
  157. url: "/admin/bxdbrand/queryMoreCategoryBrandList",
  158. data: {
  159. categoryIds: category1.categoryId
  160. }
  161. });
  162. this.setData({
  163. brandList: data.data.map(v => {
  164. v = {
  165. name: v,
  166. check: false
  167. }
  168. return v;
  169. })
  170. })
  171. },
  172. onBrand(e) {
  173. let brandList = this.data.brandList;
  174. brandList[e.currentTarget.dataset.index].check = !brandList[e.currentTarget.dataset.index].check;
  175. this.setData({
  176. brandList
  177. })
  178. },
  179. getCategoryIdList(categorie) {
  180. let result = [];
  181. result.push(categorie.categoryId);
  182. if (categorie.categories && categorie.categories.length > 0) {
  183. for (let i = 0; i < categorie.categories.length; i++) {
  184. let tmp = this.getCategoryIdList(categorie.categories[i]);
  185. result.push(result, tmp);
  186. }
  187. }
  188. return result.join(",");
  189. },
  190. searchGoods(e) {
  191. this.setData({
  192. picTitle: e.detail.value,
  193. goodsList: [],
  194. current: 0,
  195. pages: null
  196. })
  197. this.getGoodsList();
  198. },
  199. goodsScroll(e) {
  200. //console.log(e)
  201. },
  202. query(e) {
  203. let param = e.currentTarget.dataset.param;
  204. let query = this.data.query;
  205. if (!param) {
  206. this.setData({
  207. query: {}
  208. });
  209. }
  210. if (param) {
  211. let pars = query[param];
  212. query = {};
  213. if (pars != undefined) {
  214. query[param] = pars;
  215. }
  216. if (query[param] == undefined) {
  217. query[param] = false;
  218. } else if (query[param] == false) {
  219. query[param] = true;
  220. } else if (query[param] == true) {
  221. delete query[param];
  222. }
  223. if (!param || query[param] == undefined) {
  224. query = {
  225. all: 1
  226. }
  227. }
  228. } else {
  229. query = {
  230. all: 1
  231. }
  232. }
  233. let brandList = this.data.brandList;
  234. brandList = brandList.map(v => {
  235. v.check = false;
  236. return v;
  237. });
  238. this.setData({
  239. query,
  240. brandList,
  241. pages: null,
  242. current: 0
  243. });
  244. this.getGoodsList();
  245. },
  246. powerDrawer() {
  247. app.dialog(this, 'close');
  248. },
  249. shaixuan() {
  250. app.dialog(this, 'open');
  251. },
  252. submitShaixuan(e) {
  253. let query = this.data.query;
  254. query = {
  255. shaixuan: 1
  256. };
  257. this.setData({
  258. query: {
  259. ...query,
  260. ...e.detail.value,
  261. brandNameList: this.data.brandList.filter(v => v.check).map(v => v.name).join(",")
  262. },
  263. goodsList: [],
  264. current: 0,
  265. pages: null,
  266. showDialog: false
  267. });
  268. this.getGoodsList()
  269. },
  270. submitShaixuanReset(e) {
  271. let query = this.data.query;
  272. let brandList = this.data.brandList;
  273. brandList = brandList.map(v => {
  274. v.check = false;
  275. return v;
  276. });
  277. delete query["brandNameList"];
  278. delete query["startPrice"];
  279. delete query["endPrice"];
  280. delete query["shaixuan"];
  281. query["all"] = 1;
  282. this.setData({
  283. brandList,
  284. query,
  285. showDialog: false,
  286. goodsList: [],
  287. current: 0,
  288. pages: null,
  289. });
  290. this.getGoodsList()
  291. },
  292. onMenu(e) {},
  293. /**
  294. * 生命周期函数--监听页面隐藏
  295. */
  296. onHide() {
  297. },
  298. /**
  299. * 生命周期函数--监听页面卸载
  300. */
  301. onUnload() {
  302. },
  303. /**
  304. * 页面相关事件处理函数--监听用户下拉动作
  305. */
  306. onPullDownRefresh() {
  307. },
  308. /**
  309. * 页面上拉触底事件的处理函数
  310. */
  311. onReachBottom() {
  312. },
  313. /**
  314. * 用户点击右上角分享
  315. */
  316. onShareAppMessage() {
  317. },
  318. onPageScroll(e) {
  319. this.setData({
  320. scrollTop: e.scrollTop
  321. });
  322. },
  323. scrollTop: function () {
  324. wx.pageScrollTo({
  325. scrollTop: 0,
  326. duration: 300
  327. });
  328. },
  329. })