index.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  1. // pages/index/index.js
  2. // pages/home/home.js
  3. const app = getApp();
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. userInfo: wx.getStorageSync('userInfo'),
  10. topBarHeight: app.globalData.statBarHeight,
  11. scrollTop: 0,
  12. animationData: null,
  13. showDialog: false,
  14. company: wx.getStorageSync('company'),
  15. picTitle: '',
  16. current: 0,
  17. pages: null,
  18. loadding: false,
  19. loading: true,
  20. contact: {},
  21. businessList: [],
  22. home: {
  23. businessList: [{
  24. id: 1,
  25. img: 'http://voms.cdn.bosind.com/mini/11.png'
  26. },
  27. {
  28. id: 2,
  29. img: 'http://voms.cdn.bosind.com/mini/12.png'
  30. },
  31. {
  32. id: 3,
  33. img: 'http://voms.cdn.bosind.com/mini/13.png'
  34. },
  35. {
  36. id: 4,
  37. img: 'http://voms.cdn.bosind.com/mini/14.png'
  38. },
  39. {
  40. id: 5,
  41. img: 'http://voms.cdn.bosind.com/mini/15.png'
  42. },
  43. {
  44. id: 6,
  45. img: 'http://voms.cdn.bosind.com/mini/16.png'
  46. },
  47. {
  48. id: 7,
  49. img: 'http://voms.cdn.bosind.com/mini/17.png'
  50. },
  51. {
  52. id: 8,
  53. img: 'http://voms.cdn.bosind.com/mini/18.png'
  54. },
  55. ]
  56. },
  57. banner: [],
  58. menuList: [],
  59. goodsList: [],
  60. brandList: [
  61. // {
  62. // id: 0,
  63. // name: "小米",
  64. // check: true
  65. // },
  66. // {
  67. // id: 1,
  68. // name: "华为",
  69. // check: false
  70. // },
  71. // {
  72. // id: 2,
  73. // name: "苹果",
  74. // check: false
  75. // },
  76. // {
  77. // id: 3,
  78. // name: "三星",
  79. // check: false
  80. // },
  81. // {
  82. // id: 4,
  83. // name: "锤子",
  84. // check: false
  85. // },
  86. ],
  87. queryIndex: 0,
  88. query: {
  89. all: 1
  90. }
  91. },
  92. /**
  93. * 生命周期函数--监听页面加载
  94. */
  95. async onLoad(options) {
  96. let userInfo = wx.getStorageSync('userInfo');
  97. this.setData({
  98. userInfo
  99. })
  100. // if (typeof this.getTabBar === 'function' && this.getTabBar()) {
  101. // if (userInfo && userInfo.userId) {
  102. // app.globalData.tabbar.list[0].show = false;
  103. // } else {
  104. // app.globalData.tabbar.list[0].show = true;
  105. // }
  106. // }
  107. let that = this;
  108. app.indeCallBack = e => {
  109. if (!userInfo || !userInfo.userId) {
  110. that.onShow();
  111. }
  112. };
  113. },
  114. /**
  115. * 生命周期函数--监听页面初次渲染完成
  116. */
  117. onReady() {
  118. let userInfo = wx.getStorageSync('userInfo');
  119. this.setData({
  120. userInfo
  121. })
  122. if (typeof this.getTabBar === 'function' && this.getTabBar()) {
  123. this.getTabBar().setData({
  124. selectIndex: 0,
  125. tabbar: app.globalData.tabbar
  126. })
  127. }
  128. },
  129. /**
  130. * 生命周期函数--监听页面显示
  131. */
  132. async onShow() {
  133. let userInfo = wx.getStorageSync('userInfo');
  134. let company = wx.getStorageSync('company');
  135. this.setData({
  136. userInfo,
  137. company
  138. })
  139. let param = {};
  140. if (company) {
  141. param = {
  142. companyId: company.companyId
  143. }
  144. }
  145. let {
  146. data: indexData
  147. } = await app.ajax.get({
  148. url: '/admin/miniConfig/index',
  149. noCompany: true,
  150. isToken: false,
  151. data: param
  152. });
  153. this.setData({
  154. banner: indexData.data.BANNER.split(','),
  155. businessList: indexData.data.OUR_BUSINESS ? JSON.parse(indexData.data.OUR_BUSINESS) : [],
  156. contact: indexData.data.CONTACT_US ? JSON.parse(indexData.data.CONTACT_US) : []
  157. });
  158. app.globalData.tabbar = JSON.parse(indexData.data.TABBAR);
  159. if (typeof this.getTabBar === 'function' && this.getTabBar()) {
  160. setTimeout(() => {
  161. this.getTabBar().setData({
  162. selectIndex: 0,
  163. tabbar: app.globalData.tabbar
  164. })
  165. }, 500);
  166. }
  167. if (!userInfo || !userInfo.userId) {
  168. return;
  169. }
  170. // if (userInfo && userInfo.userId) {
  171. // app.globalData.tabbar.list[0].show = false;
  172. // app.globalData.tabbar.list[1].show = true;
  173. // this.getTabBar().setData({
  174. // selectIndex: 1,
  175. // tabbar: app.globalData.tabbar
  176. // })
  177. // } else {
  178. // app.globalData.tabbar.list[0].show = true;
  179. // app.globalData.tabbar.list[1].show = false;
  180. // this.getTabBar().setData({
  181. // selectIndex: 1,
  182. // tabbar: app.globalData.tabbar
  183. // })
  184. // wx.switchTab({
  185. // url: '/pages/login/login',
  186. // })
  187. // return;
  188. // }
  189. let {
  190. data
  191. } = await app.ajax.gets("/admin/bxdcategory/query");
  192. let menuDataList = data.data.filter(v => v.status == 1);
  193. let menuList = [];
  194. for (var i = 0; i < menuDataList.length; i += 10) {
  195. menuList.push(menuDataList.slice(i, i + 10));
  196. }
  197. //console.log(menuList)
  198. this.setData({
  199. menuList
  200. })
  201. // this.getBrandList();
  202. this.getGoodsList();
  203. },
  204. onMenu(e) {
  205. //console.log(e)
  206. wx.navigateTo({
  207. url: `/pages/category/category?categoryId=${e.currentTarget.dataset.item.categoryId}`,
  208. })
  209. },
  210. powerDrawer() {
  211. app.dialog(this, 'close');
  212. },
  213. shaixuan() {
  214. app.dialog(this, 'open');
  215. },
  216. submitShaixuan(e) {
  217. let query = this.data.query;
  218. query = {
  219. shaixuan: 1
  220. };
  221. this.setData({
  222. query: {
  223. ...query,
  224. ...e.detail.value,
  225. brandNameList: this.data.brandList.filter(v => v.check).map(v => v.name).join(",")
  226. },
  227. showDialog: false
  228. });
  229. this.getGoodsList()
  230. },
  231. submitShaixuanReset(e) {
  232. let query = this.data.query;
  233. let brandList = this.data.brandList;
  234. brandList = brandList.map(v => {
  235. v.check = false;
  236. return v;
  237. });
  238. delete query["brandNameList"];
  239. delete query["startPrice"];
  240. delete query["endPrice"];
  241. query["all"] = 1;
  242. this.setData({
  243. brandList,
  244. query
  245. })
  246. },
  247. onBrand(e) {
  248. let brandList = this.data.brandList;
  249. brandList[e.currentTarget.dataset.index].check = !brandList[e.currentTarget.dataset.index].check;
  250. this.setData({
  251. brandList
  252. })
  253. },
  254. query(e) {
  255. let param = e.currentTarget.dataset.param;
  256. let query = this.data.query;
  257. if (!param) {
  258. this.setData({
  259. query: {}
  260. });
  261. }
  262. if (param) {
  263. let pars = query[param];
  264. query = {};
  265. if (pars != undefined) {
  266. query[param] = pars;
  267. }
  268. if (query[param] == undefined) {
  269. query[param] = false;
  270. } else if (query[param] == false) {
  271. query[param] = true;
  272. } else if (query[param] == true) {
  273. delete query[param];
  274. }
  275. if (!param || query[param] == undefined) {
  276. query = {
  277. all: 1
  278. }
  279. }
  280. } else {
  281. query = {
  282. all: 1
  283. }
  284. }
  285. let brandList = this.data.brandList;
  286. brandList = brandList.map(v => {
  287. v.check = false;
  288. return v;
  289. });
  290. this.setData({
  291. query,
  292. brandList
  293. });
  294. this.getBrandList();
  295. this.getGoodsList();
  296. },
  297. async getBrandList() {
  298. let category1 = this.data.categoryList[this.data.category1Index];
  299. if (this.data.category2Index > -1) {
  300. category1 = this.data.categoryList[this.data.category1Index].categories[this.data.category2Index];
  301. }
  302. if (this.data.category3Index > -1) {
  303. category1 = this.data.categoryList[this.data.category1Index].categories[this.data.category2Index].categories[this.data.category3Index];
  304. }
  305. let {
  306. data
  307. } = await app.ajax.get({
  308. url: "/admin/bxdbrand/queryMoreCategoryBrandList",
  309. data: {
  310. categoryIds: category1.categoryId
  311. }
  312. });
  313. this.setData({
  314. brandList: data.data
  315. })
  316. },
  317. async getGoodsList() {
  318. this.setData({
  319. current: 1,
  320. loadding: true
  321. });
  322. //console.log('virtualInventoryId', wx.getStorageSync('virtualInventoryId'))
  323. try {
  324. let {
  325. data
  326. } = await app.ajax.get({
  327. url: "/admin/bxdprod/browsePage",
  328. data: {
  329. picTitle: this.data.picTitle,
  330. mini: 1,
  331. current: 1,
  332. size: 20,
  333. virtualInventoryId: wx.getStorageSync('virtualInventoryId'),
  334. ...this.data.query
  335. },
  336. // isLoading: this.data.loading
  337. });
  338. let goodsList = data.data.records.map(v => {
  339. v["picText"] = v.pic ? v.pic.split(",")[0] : '/images/empty.png';
  340. return v;
  341. });
  342. this.setData({
  343. goodsList: goodsList,
  344. pages: data.data.pages || null,
  345. loadding: false,
  346. loading: false,
  347. })
  348. } catch (e) {
  349. this.setData({
  350. loadding: false
  351. })
  352. }
  353. },
  354. async getGoodsPageList() {
  355. if (this.data.current >= this.data.pages) {
  356. return;
  357. }
  358. this.setData({
  359. current: this.data.current + 1,
  360. loadding: true
  361. });
  362. //console.log('virtualInventoryId', wx.getStorageSync('virtualInventoryId'))
  363. try {
  364. let {
  365. data
  366. } = await app.ajax.get({
  367. url: "/admin/bxdprod/browsePage",
  368. data: {
  369. picTitle: this.data.picTitle,
  370. mini: 1,
  371. current: this.data.current,
  372. size: 20,
  373. virtualInventoryId: wx.getStorageSync('virtualInventoryId'),
  374. ...this.data.query
  375. },
  376. // isLoading: this.data.loading
  377. });
  378. let goodsList = data.data.records.map(v => {
  379. v["picText"] = v.pic ? v.pic.split(",")[0] : '/images/empty.png';
  380. return v;
  381. });
  382. this.setData({
  383. goodsList: this.data.goodsList.concat(goodsList),
  384. pages: data.data.pages || null,
  385. loadding: false,
  386. loading: false,
  387. })
  388. } catch (e) {
  389. this.setData({
  390. loadding: false
  391. })
  392. }
  393. },
  394. /**
  395. * 生命周期函数--监听页面隐藏
  396. */
  397. onHide() {
  398. },
  399. /**
  400. * 生命周期函数--监听页面卸载
  401. */
  402. onUnload() {
  403. },
  404. /**
  405. * 页面相关事件处理函数--监听用户下拉动作
  406. */
  407. onPullDownRefresh() {},
  408. /**
  409. * 页面上拉触底事件的处理函数
  410. */
  411. onReachBottom() {
  412. this.getGoodsPageList();
  413. },
  414. /**
  415. * 用户点击右上角分享
  416. */
  417. onShareAppMessage() {
  418. },
  419. onPageScroll(e) {
  420. this.setData({
  421. scrollTop: e.scrollTop
  422. });
  423. },
  424. scrollTop: function () {
  425. wx.pageScrollTo({
  426. scrollTop: 0,
  427. duration: 300
  428. });
  429. },
  430. })