searchcategory.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. // pages/pinduoduo/category.js
  2. var util = require('../../utils/util.js');
  3. var app = getApp()
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. theme_type: '',
  10. loadover: false,
  11. subcate: [],
  12. cur_pid: 0,
  13. cur_price_index: 0,
  14. show_price_search: false,
  15. search_min_price: 0,
  16. search_max_price: 0,
  17. sort: '',
  18. hidetip: true,
  19. tip_html: '^_^已经到底了',
  20. cur_type: 'default',
  21. pageNum: 1,
  22. keyword: '',
  23. hasRefesh: false,
  24. list: [],
  25. LoadingComplete: true,
  26. isHidenotice: true
  27. },
  28. /**
  29. * 生命周期函数--监听页面加载
  30. */
  31. onLoad: function (options) {
  32. var that = this;
  33. var keyword = options.keyword;
  34. if (keyword == undefined) {
  35. keyword = '';
  36. } else {
  37. this.setData({
  38. keyword: keyword
  39. })
  40. }
  41. wx.showLoading({
  42. })
  43. app.util.request({
  44. 'url': 'entry/wxapp/index',
  45. 'data': { controller: 'index.get_index_category' },
  46. dataType: 'json',
  47. success: function (res) {
  48. that.setData({
  49. nav: res.data.data,
  50. })
  51. }
  52. });
  53. app.util.request({
  54. 'url': 'entry/wxapp/index',
  55. 'data': {
  56. controller: 'goods.get_category_keyword_goods',
  57. keyword: keyword,
  58. },
  59. dataType: 'json',
  60. success: function (res) {
  61. if (res.data.code == 0) {
  62. that.setData({
  63. list: res.data.data,
  64. hidetip: true
  65. })
  66. } else {
  67. that.setData({
  68. LoadingComplete: false,
  69. tip_html: '^_^已经到底了',
  70. hidetip: true
  71. })
  72. }
  73. }
  74. });
  75. wx.hideLoading();
  76. this.setData({ loadover: true })
  77. },
  78. bindKeyInput: function (e) {
  79. this.setData({
  80. keyword: e.detail.value
  81. })
  82. },
  83. bindKeyInputmin: function (e) {
  84. this.setData({
  85. search_min_price: e.detail.value
  86. })
  87. },
  88. bindKeyInputmax: function (e) {
  89. this.setData({
  90. search_max_price: e.detail.value
  91. })
  92. },
  93. clear_input: function () {
  94. this.setData({
  95. keyword: ''
  96. })
  97. },
  98. go_sort_by: function (event) {
  99. let type = event.currentTarget.dataset.type;
  100. var s_sort = '';
  101. if (type == 'price') {
  102. s_sort = this.data.sort;
  103. if (s_sort == 'desc') {
  104. s_sort = 'asc';
  105. } else if (s_sort == 'asc') {
  106. s_sort = 'desc';
  107. } else {
  108. s_sort = 'asc';
  109. }
  110. }
  111. this.setData({
  112. cur_type: type,
  113. sort: s_sort,
  114. list: [],
  115. hasRefesh: false,
  116. hidetip: true,
  117. pageNum: 0
  118. })
  119. this.loadMore();
  120. },
  121. chose_price: function (event) {
  122. let price_index = event.currentTarget.dataset.price_index;
  123. let min_price = event.currentTarget.dataset.min_price;
  124. let max_price = event.currentTarget.dataset.max_price;
  125. if (this.data.cur_price_index == price_index) {
  126. this.setData({
  127. cur_price_index: 0
  128. })
  129. } else {
  130. this.setData({
  131. cur_price_index: price_index,
  132. search_min_price: min_price,
  133. search_max_price: max_price,
  134. list: [],
  135. hasRefesh: false,
  136. hidetip: true,
  137. pageNum: 0
  138. })
  139. this.loadMore();
  140. }
  141. },
  142. searchbtn: function (e) {
  143. console.log(12);
  144. this.setData({
  145. list: [],
  146. hasRefesh: false,
  147. hidetip: true,
  148. pageNum: 0
  149. })
  150. this.loadMore();
  151. },
  152. nav_dir_go_link: function (url) {
  153. wx.navigateTo({
  154. url: url,
  155. fail: function () {
  156. wx.redirectTo({
  157. url: url
  158. })
  159. }
  160. })
  161. },
  162. show_price_search_do: function () {
  163. this.setData({
  164. show_price_search: true
  165. })
  166. },
  167. hide_search: function () {
  168. this.setData({
  169. show_price_search: false
  170. })
  171. },
  172. go_search: function () {
  173. this.hide_search();
  174. this.setData({
  175. list: [],
  176. hasRefesh: false,
  177. hidetip: true,
  178. pageNum: 0
  179. })
  180. this.loadMore();
  181. },
  182. goLink: function (event) {
  183. let url = event.currentTarget.dataset.link;
  184. var pages_all = getCurrentPages();
  185. if (pages_all.length > 3) {
  186. wx.redirectTo({
  187. url: url
  188. })
  189. } else {
  190. wx.navigateTo({
  191. url: url
  192. })
  193. }
  194. },
  195. common_go_link: function (e) {
  196. var url = e.currentTarget.dataset.link;
  197. this.nav_dir_go_link(url);
  198. },
  199. /**
  200. * 生命周期函数--监听页面初次渲染完成
  201. */
  202. onReady: function () {
  203. },
  204. /**
  205. * 生命周期函数--监听页面显示
  206. */
  207. onShow: function () {
  208. },
  209. /**
  210. * 生命周期函数--监听页面隐藏
  211. */
  212. onHide: function () {
  213. },
  214. /**
  215. * 生命周期函数--监听页面卸载
  216. */
  217. onUnload: function () {
  218. },
  219. /**
  220. * 页面相关事件处理函数--监听用户下拉动作
  221. */
  222. onPullDownRefresh: function () {
  223. },
  224. /**
  225. * 页面上拉触底事件的处理函数
  226. */
  227. onReachBottom: function () {
  228. this.loadMore();
  229. },
  230. loadMore: function () {
  231. let that = this;
  232. if (!that.data.hasRefesh) {
  233. that.setData({
  234. hasRefesh: true,
  235. hidetip: false
  236. });
  237. var cur_pid = that.data.cur_pid;
  238. var keyword = that.data.keyword;
  239. app.util.request({
  240. 'url': 'entry/wxapp/index',
  241. 'data': {
  242. controller: 'goods.get_category_keyword_goods',
  243. keyword: keyword,
  244. "page": that.data.pageNum + 1,
  245. "cur_price_index": that.data.cur_price_index,
  246. "cur_type": that.data.cur_type,
  247. "sort": that.data.sort,
  248. "search_min_price": that.data.search_min_price,
  249. "search_max_price": that.data.search_max_price,
  250. },
  251. method:'post',
  252. dataType: 'json',
  253. success: function (res) {
  254. if (res.data.code == 0) {
  255. var list = that.data.list;
  256. var n_data = res.data.data;
  257. //list.push(n_data);
  258. //console.log(list);
  259. n_data.map(function (good) {
  260. list.push(good);
  261. });
  262. that.setData({
  263. list: list,
  264. pageNum: that.data.pageNum + 1,
  265. hasRefesh: false,
  266. hidetip: true
  267. });
  268. } else {
  269. that.setData({
  270. LoadingComplete: false,
  271. tip_html: '^_^已经到底了',
  272. hidetip: true
  273. });
  274. }
  275. }
  276. })
  277. }
  278. },
  279. goGoods_link: function (e) {
  280. var goods_id = e.currentTarget.dataset.type;
  281. var url = "/Snailfish_shop/pages/goods/index?id=" + goods_id;
  282. this.nav_dir_go_link(url);
  283. },
  284. /**
  285. * 用户点击右上角分享
  286. */
  287. onShareAppMessage: function () {
  288. }
  289. })