catalog.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. var util = require('../../../utils/util.js');
  2. var api = require('../../../config/api.js');
  3. const user = require('../../../utils/user.js');
  4. const area = require('../../../utils/area.js');
  5. //获取应用实例
  6. const app = getApp();
  7. Page({
  8. data: {
  9. categoryList: [],
  10. currentCategory: {},
  11. currentSubCategoryList: {},
  12. scrollLeft: 0,
  13. scrollTop: 0,
  14. goodsList:[],
  15. goodsCount: 0,
  16. scrollHeight: 0,
  17. hasLogin: true,
  18. city:'',//当前业务城市
  19. citys:[],
  20. cityIndex:0,
  21. addressInfo:{},
  22. },
  23. onLoad: function (options) {
  24. this.getCatalog();
  25. },
  26. onPullDownRefresh() {
  27. wx.showNavigationBarLoading() //在标题栏中显示加载
  28. this.getCatalog();
  29. wx.hideNavigationBarLoading() //完成停止加载
  30. wx.stopPullDownRefresh() //停止下拉刷新
  31. },
  32. listenerCitySelected(e){
  33. this.setData({
  34. cityIndex:e.detail.value,
  35. city:this.data.citys[e.detail.value]
  36. })
  37. app.globalData.city=this.data.city;
  38. },
  39. getCatalog: function () {
  40. //CatalogList
  41. let that = this;
  42. wx.showLoading({
  43. title: '加载中...',
  44. });
  45. util.request(api.CatalogList).then(function (res) {
  46. //1036763 写死值 如果地址不是苏州市 隐藏活动专享
  47. //20220223关闭所有活动合作专区
  48. //console.info(res.data.categoryList)
  49. var list=res.data.categoryList;
  50. // if(that.data.addressInfo.city&&that.data.addressInfo.city!="苏州市"){
  51. var categorys=[];
  52. res.data.categoryList.forEach(item=>{
  53. if(item.id!=1036763)
  54. categorys.push(item);
  55. });
  56. list=categorys;
  57. // }
  58. that.setData({
  59. categoryList:list,
  60. currentCategory: res.data.currentCategory,
  61. currentSubCategoryList: res.data.currentSubCategory
  62. });
  63. that.getCategoryGoods();
  64. wx.hideLoading();
  65. });
  66. util.request(api.GoodsCount).then(function (res) {
  67. that.setData({
  68. goodsCount: res.data
  69. });
  70. });
  71. },
  72. getCategoryGoods(){//获取一级类目下所有商品
  73. let that=this;
  74. util.request(api.GoodsL1Category,{
  75. id:that.data.currentCategory.name=='热销商品'?'-1':that.data.currentCategory.id,
  76. //shopId:that.data.addressInfo.shopId,
  77. isHot:that.data.currentCategory.name=='热销商品'?true:false,
  78. city:that.data.addressInfo.city
  79. }).then(res=>{
  80. console.info(res.data)
  81. that.setData({
  82. goodsList:res.data
  83. })
  84. })
  85. },
  86. getCurrentCategory: function (id) {
  87. let that = this;
  88. util.request(api.CatalogCurrent, {
  89. id:id,
  90. })
  91. .then(function (res) {
  92. that.setData({
  93. currentCategory: res.data.currentCategory,
  94. currentSubCategoryList: res.data.currentSubCategory,
  95. });
  96. that.getCategoryGoods();
  97. });
  98. },
  99. onReady: function () {
  100. // 页面渲染完成
  101. if (app.globalData.hasLogin) {
  102. this.setData({
  103. hasLogin: true
  104. });
  105. }
  106. },
  107. onShow: function () {
  108. // 页面显示
  109. //显示购物车角标
  110. //user.cartshow();
  111. //确定业务城市
  112. var addressInfo=wx.getStorageSync('addressInfo');
  113. if(addressInfo){
  114. this.setData({
  115. addressInfo:addressInfo
  116. })
  117. }else{
  118. //手机性能慢,可能首页接口没初始化完毕
  119. let that=this;
  120. setTimeout(() => {
  121. var addressInfo=wx.getStorageSync('addressInfo');
  122. if(addressInfo){
  123. that.setData({
  124. addressInfo:addressInfo
  125. })
  126. }
  127. }, 500);
  128. }
  129. },
  130. goLogin: function (e) {
  131. if (e.detail.userInfo == null) {
  132. app.globalData.hasLogin = false;
  133. util.showErrorToast('微信授权失败');
  134. return;
  135. }
  136. app.globalData.hasLogin = false;
  137. wx.setStorageSync('userInfo', null);
  138. user.loginByWeixin(e.detail.userInfo).then(res => {
  139. //跳转注册页
  140. wx.navigateTo({
  141. url: "/pages/auth/register/register"
  142. });
  143. }).catch((err) => {
  144. app.globalData.hasLogin = false;
  145. });
  146. },
  147. onHide: function () {
  148. // 页面隐藏
  149. },
  150. onUnload: function () {
  151. // 页面关闭
  152. },
  153. switchCate: function (event) {
  154. var that = this;
  155. var currentTarget = event.currentTarget;
  156. if (this.data.currentCategory.id == event.currentTarget.dataset.id) {
  157. return false;
  158. }
  159. this.getCurrentCategory(event.currentTarget.dataset.id);
  160. },
  161. goinviteFriends(e) {
  162. console.log(app.globalData.hasLogin);
  163. //跳转到邀请页面
  164. if (app.globalData.hasLogin) {
  165. wx.navigateTo({
  166. url: '/pages/activity/invitefriends/inviteFriends'
  167. })
  168. } else {
  169. wx.navigateTo({
  170. url: "/pages/auth/login/login"
  171. });
  172. };
  173. },
  174. })