catalog.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. var util = require('../../../utils/jmsUtil');
  2. var mall = require('../../../api/mall.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. },
  25. onPullDownRefresh() {
  26. wx.showNavigationBarLoading() //在标题栏中显示加载
  27. this.getCatalog();
  28. wx.hideNavigationBarLoading() //完成停止加载
  29. wx.stopPullDownRefresh() //停止下拉刷新
  30. },
  31. listenerCitySelected(e){
  32. this.setData({
  33. cityIndex:e.detail.value,
  34. city:this.data.citys[e.detail.value]
  35. })
  36. app.globalData.city=this.data.city;
  37. },
  38. getCatalog: function () {
  39. let that = this;
  40. wx.showLoading({
  41. title: '加载中...',
  42. });
  43. util.request(mall.CatalogList).then(function (res) {
  44. //1036763 写死值 如果地址不是苏州市 隐藏活动专享
  45. //20220223关闭所有活动合作专区
  46. //console.info(res.data.categoryList)
  47. var list=res.data.categoryList;
  48. // if(that.data.addressInfo.city&&that.data.addressInfo.city!="苏州市"){
  49. var categorys=[];
  50. res.data.categoryList.forEach(item=>{
  51. if(item.id!=1036763)
  52. categorys.push(item);
  53. });
  54. list=categorys;
  55. // }
  56. that.setData({
  57. categoryList:list,
  58. currentCategory: res.data.currentCategory,
  59. currentSubCategoryList: res.data.currentSubCategory
  60. });
  61. that.getCategoryGoods();
  62. wx.hideLoading();
  63. }).catch((err)=>{
  64. wx.hideLoading();
  65. console.log(err);
  66. });
  67. util.request(mall.GoodsCount).then(function (res) {
  68. that.setData({
  69. goodsCount: res.data
  70. });
  71. });
  72. },
  73. getCategoryGoods(){//获取一级类目下所有商品
  74. let that=this;
  75. util.request(mall.GoodsL1Category,{
  76. id:that.data.currentCategory.name=='热销商品'?'-1':that.data.currentCategory.id,
  77. // shopId:that.data.addressInfo.shopId,
  78. // isHot:that.data.currentCategory.name=='热销商品'?true:false
  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(mall.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. this.getCatalog();
  109. // 页面显示
  110. //显示购物车角标
  111. //user.cartshow();
  112. //确定业务城市
  113. var addressInfo=wx.getStorageSync('addressInfo');
  114. if(addressInfo){
  115. this.setData({
  116. addressInfo:addressInfo
  117. })
  118. }else{
  119. //手机性能慢,可能首页接口没初始化完毕
  120. let that=this;
  121. setTimeout(() => {
  122. var addressInfo=wx.getStorageSync('addressInfo');
  123. if(addressInfo){
  124. that.setData({
  125. addressInfo:addressInfo
  126. })
  127. }
  128. }, 700);
  129. }
  130. },
  131. goLogin: function (e) {
  132. if (e.detail.userInfo == null) {
  133. app.globalData.hasLogin = false;
  134. util.showErrorToast('微信授权失败');
  135. return;
  136. }
  137. app.globalData.hasLogin = false;
  138. wx.setStorageSync('userInfo', null);
  139. user.loginByWeixin(e.detail.userInfo).then(res => {
  140. //跳转注册页
  141. wx.navigateTo({
  142. url: "/pages/auth/register/register"
  143. });
  144. }).catch((err) => {
  145. app.globalData.hasLogin = false;
  146. });
  147. },
  148. onHide: function () {
  149. // 页面隐藏
  150. },
  151. onUnload: function () {
  152. // 页面关闭
  153. },
  154. switchCate: function (event) {
  155. var that = this;
  156. var currentTarget = event.currentTarget;
  157. if (this.data.currentCategory.id == event.currentTarget.dataset.id) {
  158. return false;
  159. }
  160. this.getCurrentCategory(event.currentTarget.dataset.id);
  161. },
  162. goinviteFriends(e) {
  163. console.log(app.globalData.hasLogin);
  164. //跳转到邀请页面
  165. if (app.globalData.hasLogin) {
  166. wx.navigateTo({
  167. url: '/pages/activity/invitefriends/inviteFriends'
  168. })
  169. } else {
  170. wx.navigateTo({
  171. url: "/pages/auth/login/login"
  172. });
  173. };
  174. },
  175. })