cat.js 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. var _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(t) {
  2. return typeof t
  3. } : function(t) {
  4. return t && "function" == typeof Symbol && t.constructor === Symbol && t !== Symbol.prototype ? "symbol" : typeof t
  5. },
  6. is_no_more = !1,
  7. is_loading_more = !1;
  8. Page({
  9. data: {
  10. cat_list: [],
  11. sub_cat_list_scroll_top: 0,
  12. scrollLeft: 0,
  13. page: 1,
  14. cat_style: 0,
  15. height: 0,
  16. catheight: 120
  17. },
  18. dis: function () {
  19. wx.redirectTo({
  20. url: '/pages/index/index?go=' + 'nd',
  21. })
  22. },
  23. onLoad: function(t) {
  24. var a = this;
  25. getApp().page.onLoad(a, t);
  26. var e = getApp().core.getStorageSync(getApp().const.STORE),
  27. o = t.cat_id;
  28. void 0 !== o && o && (a.data.cat_style = e.cat_style = -1, getApp().core.showLoading({
  29. title: "正在加载",
  30. mask: !0
  31. }), a.childrenCat(o)), a.setData({
  32. store: e
  33. })
  34. },
  35. onShow: function() {
  36. getApp().page.onShow(this), getApp().core.hideLoading(), -1 !== this.data.cat_style && this.loadData()
  37. },
  38. loadData: function(t) {
  39. var a = this,
  40. e = getApp().core.getStorageSync(getApp().const.STORE);
  41. if ("" == a.data.cat_list || 5 != e.cat_style && 4 != e.cat_style && 2 != e.cat_style) {
  42. var o = getApp().core.getStorageSync(getApp().const.CAT_LIST);
  43. o && a.setData({
  44. cat_list: o,
  45. current_cat: null
  46. }), getApp().request({
  47. url: getApp().api.default.cat_list,
  48. success: function(t) {
  49. 0 == t.code && (a.data.cat_list = t.data.list, 5 === e.cat_style && a.goodsAll({
  50. currentTarget: {
  51. dataset: {
  52. index: 0
  53. }
  54. }
  55. }), 4 !== e.cat_style && 2 !== e.cat_style || a.catItemClick({
  56. currentTarget: {
  57. dataset: {
  58. index: 0
  59. }
  60. }
  61. }), 1 !== e.cat_style && 3 !== e.cat_style || (a.setData({
  62. cat_list: t.data.list,
  63. current_cat: null
  64. }), getApp().core.setStorageSync(getApp().const.CAT_LIST, t.data.list)))
  65. },
  66. complete: function() {
  67. getApp().core.stopPullDownRefresh()
  68. }
  69. })
  70. } else a.setData({
  71. cat_list: a.data.cat_list,
  72. current_cat: a.data.current_cat
  73. })
  74. },
  75. childrenCat: function(i) {
  76. var s = this;
  77. is_no_more = !1;
  78. s.data.page;
  79. getApp().request({
  80. url: getApp().api.default.cat_list,
  81. success: function(t) {
  82. if (0 == t.code) {
  83. var a = !0;
  84. for (var e in t.data.list)
  85. for (var o in t.data.list[e].id == i && (a = !1, s.data.current_cat = t.data.list[e], 0 < t.data.list[e].list.length ? (s.setData({
  86. catheight: 100
  87. }), s.firstcat({
  88. currentTarget: {
  89. dataset: {
  90. index: 0
  91. }
  92. }
  93. })) : s.firstcat({
  94. currentTarget: {
  95. dataset: {
  96. index: 0
  97. }
  98. }
  99. }, !1)), t.data.list[e].list) t.data.list[e].list[o].id == i && (a = !1, s.data.current_cat = t.data.list[e], s.goodsItem({
  100. currentTarget: {
  101. dataset: {
  102. index: o
  103. }
  104. }
  105. }, !1));
  106. a && s.setData({
  107. show_no_data_tip: !0
  108. })
  109. }
  110. },
  111. complete: function() {
  112. getApp().core.stopPullDownRefresh(), getApp().core.createSelectorQuery().select("#cat").boundingClientRect().exec(function(t) {
  113. s.setData({
  114. height: t[0].height
  115. })
  116. })
  117. }
  118. })
  119. },
  120. catItemClick: function(t) {
  121. var a = t.currentTarget.dataset.index,
  122. e = this.data.cat_list,
  123. o = null;
  124. for (var i in e) i == a ? (!(e[i].active = !0), o = e[i]) : e[i].active = !1;
  125. this.setData({
  126. cat_list: e,
  127. sub_cat_list_scroll_top: 0,
  128. current_cat: o
  129. })
  130. },
  131. firstcat: function(t) {
  132. var a = !(1 < arguments.length && void 0 !== arguments[1]) || arguments[1],
  133. e = this,
  134. o = e.data.current_cat;
  135. e.setData({
  136. page: 1,
  137. goods_list: [],
  138. show_no_data_tip: !1,
  139. current_cat: a ? o : []
  140. }), e.list(o.id, 2)
  141. },
  142. goodsItem: function(t) {
  143. var a = !(1 < arguments.length && void 0 !== arguments[1]) || arguments[1],
  144. e = this,
  145. o = t.currentTarget.dataset.index,
  146. i = e.data.current_cat,
  147. s = 0;
  148. for (var c in i.list) o == c ? (i.list[c].active = !0, s = i.list[c].id) : i.list[c].active = !1;
  149. e.setData({
  150. page: 1,
  151. goods_list: [],
  152. show_no_data_tip: !1,
  153. current_cat: a ? i : []
  154. }), e.list(s, 2)
  155. },
  156. goodsAll: function(o) {
  157. var i = this,
  158. t = o.currentTarget.dataset.index,
  159. s = i.data.cat_list,
  160. a = null;
  161. for (var e in s) e == t ? (s[e].active = !0, a = s[e]) : s[e].active = !1;
  162. if (i.setData({
  163. page: 1,
  164. goods_list: [],
  165. show_no_data_tip: !1,
  166. cat_list: s,
  167. current_cat: a
  168. }), void 0 === ("undefined" == typeof my ? "undefined" : _typeof(my))) {
  169. var c = o.currentTarget.offsetLeft,
  170. n = i.data.scrollLeft;
  171. n = c - 80, i.setData({
  172. scrollLeft: n
  173. })
  174. } else s.forEach(function(t, a, e) {
  175. t.id == o.currentTarget.id && (1 <= a ? i.setData({
  176. toView: s[a - 1].id
  177. }) : i.setData({
  178. toView: s[a].id
  179. }))
  180. });
  181. i.list(a.id, 1), getApp().core.createSelectorQuery().select("#catall").boundingClientRect().exec(function(t) {
  182. i.setData({
  183. height: t[0].height
  184. })
  185. })
  186. },
  187. list: function(a, t) {
  188. var e = this;
  189. getApp().core.showLoading({
  190. title: "正在加载",
  191. mask: !0
  192. }), is_no_more = !1;
  193. var o = e.data.page || 2;
  194. getApp().request({
  195. url: getApp().api.default.goods_list,
  196. data: {
  197. cat_id: a,
  198. page: o
  199. },
  200. success: function(t) {
  201. 0 == t.code && (getApp().core.hideLoading(), 0 == t.data.list.length && (is_no_more = !0), e.setData({
  202. page: o + 1
  203. }), e.setData({
  204. goods_list: t.data.list
  205. }), e.setData({
  206. cat_id: a
  207. })), e.setData({
  208. show_no_data_tip: 0 == e.data.goods_list.length
  209. })
  210. },
  211. complete: function() {
  212. 1 == t && getApp().core.createSelectorQuery().select("#catall").boundingClientRect().exec(function(t) {
  213. e.setData({
  214. height: t[0].height
  215. })
  216. })
  217. }
  218. })
  219. },
  220. onReachBottom: function() {
  221. getApp().page.onReachBottom(this);
  222. is_no_more || 5 != getApp().core.getStorageSync(getApp().const.STORE).cat_style && -1 != this.data.cat_style || this.loadMoreGoodsList()
  223. },
  224. loadMoreGoodsList: function() {
  225. var e = this;
  226. if (!is_loading_more) {
  227. e.setData({
  228. show_loading_bar: !0
  229. }), is_loading_more = !0;
  230. var t = e.data.cat_id || "",
  231. o = e.data.page || 2;
  232. getApp().request({
  233. url: getApp().api.default.goods_list,
  234. data: {
  235. page: o,
  236. cat_id: t
  237. },
  238. success: function(t) {
  239. 0 == t.data.list.length && (is_no_more = !0);
  240. var a = e.data.goods_list.concat(t.data.list);
  241. e.setData({
  242. goods_list: a,
  243. page: o + 1
  244. })
  245. },
  246. complete: function() {
  247. is_loading_more = !1, e.setData({
  248. show_loading_bar: !1
  249. })
  250. }
  251. })
  252. }
  253. }
  254. });