category.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. // pages/pinduoduo/category.js
  2. var util = require('../../utils/util.js');
  3. var app = getApp()
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. loadover: false,
  10. subcate: [],
  11. level: 0,
  12. show_more_cate: false,
  13. cur_pid: 0,
  14. cur_ppid: 0,
  15. tablebar: 2,
  16. hidetip: true,
  17. tip_html: '^_^已经到底了',
  18. pageNum: 1,
  19. hasRefesh: false,
  20. list: [],
  21. LoadingComplete: true,
  22. isHidenotice: true
  23. },
  24. /**
  25. * 生命周期函数--监听页面加载
  26. */
  27. onLoad: function (options) {
  28. var that = this;
  29. var cur_pid = options.id;
  30. this.setData({
  31. cur_pid: cur_pid,
  32. cur_ppid: cur_pid
  33. })
  34. wx.showLoading({
  35. })
  36. app.util.request({
  37. 'url': 'entry/wxapp/index',
  38. 'data': {
  39. controller: 'goods.get_subcategory',
  40. 'id': cur_pid
  41. },
  42. dataType: 'json',
  43. success: function (res) {
  44. wx.setNavigationBarTitle({
  45. title: res.data.cur_cate_name
  46. });
  47. if (res.data.code == 0) {
  48. that.setData({
  49. level: res.data.level,
  50. subcate: res.data.data,
  51. })
  52. } else {
  53. that.setData({
  54. level: res.data.level,
  55. })
  56. }
  57. }
  58. })
  59. app.util.request({
  60. 'url': 'entry/wxapp/index',
  61. 'data': {
  62. controller: 'goods.get_category_goods',
  63. 'id': cur_pid
  64. },
  65. dataType: 'json',
  66. success: function (res) {
  67. if (res.data.code == 0) {
  68. that.setData({
  69. list: res.data.data,
  70. hidetip: true
  71. })
  72. } else {
  73. that.setData({
  74. LoadingComplete: false,
  75. tip_html: '^_^已经到底了',
  76. hidetip: true
  77. })
  78. }
  79. }
  80. })
  81. wx.hideLoading();
  82. this.setData({ loadover: true })
  83. },
  84. show_more_cate: function () {
  85. this.setData({ show_more_cate: true })
  86. },
  87. hide_cate_d: function () {
  88. this.setData({ show_more_cate: false })
  89. },
  90. goLink: function (event) {
  91. let url = event.currentTarget.dataset.link;
  92. wx.reLaunch({
  93. url: url
  94. })
  95. },
  96. nav_dir_go_link: function (url) {
  97. wx.navigateTo({
  98. url: url,
  99. fail: function () {
  100. wx.redirectTo({
  101. url: url
  102. })
  103. }
  104. })
  105. },
  106. common_godir_link: function (e) {
  107. var url = e.currentTarget.dataset.link;
  108. var that = this;
  109. if (url == '/Snailfish_shop/pages/index/index') {
  110. wx.reLaunch({
  111. url: url
  112. })
  113. } else
  114. this.nav_dir_go_link(url);
  115. },
  116. common_go_link: function (e) {
  117. var url = e.currentTarget.dataset.link;
  118. var id = e.currentTarget.dataset.id;
  119. var that = this;
  120. console.log(id);
  121. this.setData({
  122. show_more_cate: false
  123. })
  124. if (url == '/Snailfish_shop/pages/index/index') {
  125. wx.reLaunch({
  126. url: url
  127. })
  128. } else
  129. if (this.data.level == 2) {
  130. that.setData({
  131. hasRefesh: false,
  132. cur_pid: id,
  133. list: [],
  134. pageNum: 0,
  135. hidetip: false,
  136. });
  137. this.loadMore();
  138. } else {
  139. this.nav_dir_go_link(url);
  140. }
  141. },
  142. /**
  143. * 生命周期函数--监听页面初次渲染完成
  144. */
  145. onReady: function () {
  146. },
  147. /**
  148. * 生命周期函数--监听页面显示
  149. */
  150. onShow: function () {
  151. },
  152. /**
  153. * 生命周期函数--监听页面隐藏
  154. */
  155. onHide: function () {
  156. },
  157. /**
  158. * 生命周期函数--监听页面卸载
  159. */
  160. onUnload: function () {
  161. },
  162. /**
  163. * 页面相关事件处理函数--监听用户下拉动作
  164. */
  165. onPullDownRefresh: function () {
  166. },
  167. /**
  168. * 页面上拉触底事件的处理函数
  169. */
  170. onReachBottom: function () {
  171. this.loadMore();
  172. },
  173. loadMore: function () {
  174. let that = this;
  175. if (!that.data.hasRefesh) {
  176. that.setData({
  177. hasRefesh: true,
  178. hidetip: false
  179. });
  180. var cur_pid = that.data.cur_pid;
  181. app.util.request({
  182. 'url': 'entry/wxapp/index',
  183. 'data': {
  184. controller: 'goods.get_category_goods',
  185. 'id': cur_pid,
  186. 'page': that.data.pageNum + 1
  187. },
  188. dataType: 'json',
  189. success: function (res) {
  190. if (res.data.code == 0) {
  191. var list = that.data.list;
  192. var n_data = res.data.data;
  193. //list.push(n_data);
  194. //console.log(list);
  195. n_data.map(function (good) {
  196. list.push(good);
  197. });
  198. that.setData({
  199. list: list,
  200. pageNum: that.data.pageNum + 1,
  201. hasRefesh: false,
  202. hidetip: true
  203. });
  204. } else {
  205. that.setData({
  206. LoadingComplete: false,
  207. tip_html: '^_^已经到底了',
  208. hidetip: true
  209. });
  210. }
  211. }
  212. })
  213. }
  214. },
  215. goGoods_link: function (e) {
  216. var goods_id = e.currentTarget.dataset.type;
  217. var url = "/Snailfish_shop/pages/goods/index?id=" + goods_id;
  218. this.nav_dir_go_link(url);
  219. },
  220. /**
  221. * 用户点击右上角分享
  222. */
  223. onShareAppMessage: function () {
  224. }
  225. })