search.js 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  1. var util = require('../../utils/util.js');
  2. var app = getApp()
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. theme_type: '',
  9. show_search: true,
  10. isHidenotice: true,
  11. cur_view_id: 0,
  12. cur_cate: '',
  13. tablebar: 2,
  14. jarray: [],
  15. },
  16. /**
  17. * 生命周期函数--监听页面加载
  18. */
  19. onLoad: function (options) {
  20. var that = this;
  21. wx.setNavigationBarTitle({
  22. title: '分类'
  23. });
  24. //search
  25. app.util.request({
  26. 'url': 'entry/wxapp/index',
  27. 'data': {
  28. controller: 'goods.search',
  29. },
  30. dataType: 'json',
  31. success: function (res) {
  32. that.setData({
  33. is_show_page: true,
  34. list: res.data.data,
  35. s_count: res.data.data.length - 1
  36. })
  37. }
  38. })
  39. var res = wx.getSystemInfoSync();
  40. var del_height = res.windowHeight - 45 - 58;
  41. this.setData({
  42. del_height: del_height
  43. })
  44. this.socketmsg();
  45. },
  46. goLink: function (event) {
  47. let url = event.currentTarget.dataset.link;
  48. wx.redirectTo({
  49. url: url
  50. })
  51. },
  52. scroll: function (e) {
  53. var _list_length = this.data.list.length;
  54. var that = this;
  55. var is_next = false;
  56. for (var i = 0; i < _list_length; i++) {
  57. var query = wx.createSelectorQuery()
  58. query.select('#cate_' + i).boundingClientRect()
  59. query.selectViewport().scrollOffset()
  60. query.exec(function (res) {
  61. //console.log(res);
  62. that.setData({ cur_cate: res[0].id })
  63. //cur_cate = res[0].id;
  64. // console.log('cate_'+i+':===');
  65. //console.log(res[0].top);
  66. if (res[0].top > 7 && res[0].top < 60) {
  67. is_next = false;
  68. that.show_cur_cate(res[0].id);
  69. }
  70. //console.log(res[0].id);
  71. //res[0].top // #the-id节点的上边界坐标
  72. //res[1].scrollTop // 显示区域的竖直滚动位置
  73. })
  74. }
  75. },
  76. tolower: function (e) {
  77. var that = this;
  78. var _list_length = this.data.list.length - 1;
  79. var query = wx.createSelectorQuery()
  80. query.select('#cate_' + _list_length).boundingClientRect()
  81. query.selectViewport().scrollOffset()
  82. query.exec(function (res) {
  83. that.setData({ cur_cate: res[0].id })
  84. if (res[0].top > 7 && res[0].top < 60) {
  85. that.show_cur_cate(res[0].id);
  86. }
  87. })
  88. },
  89. toupper: function (e) {
  90. var that = this;
  91. var query = wx.createSelectorQuery()
  92. query.select('#cate_0').boundingClientRect()
  93. query.selectViewport().scrollOffset()
  94. query.exec(function (res) {
  95. //console.log(res);
  96. that.setData({ cur_cate: res[0].id })
  97. //cur_cate = res[0].id;
  98. // console.log('cate_'+i+':===');
  99. //console.log(res[0].top);
  100. if (res[0].top > 7 && res[0].top < 60) {
  101. that.show_cur_cate(res[0].id);
  102. }
  103. //console.log(res[0].id);
  104. //res[0].top // #the-id节点的上边界坐标
  105. //res[1].scrollTop // 显示区域的竖直滚动位置
  106. })
  107. },
  108. show_cur_cate: function (b) {
  109. //change_nav: function (nav_id)
  110. var _list_length = this.data.list.length;
  111. var that = this;
  112. var tp_cate = '';
  113. var is_next = false;
  114. for (var i = 0; i < _list_length; i++) {
  115. tp_cate = 'cate_' + i;
  116. if (b == tp_cate) {
  117. that.change_nav(i);
  118. break;
  119. }
  120. }
  121. console.log(b);
  122. },
  123. serach_form_event: function (event) {
  124. var keyword = event.detail.value;
  125. this.nav_dir_go_link('/Snailfish_shop/pages/goods/searchcategory?keyword=' + keyword);
  126. },
  127. socketmsg: function () {
  128. wx.closeSocket();
  129. var domain = util.getdomain();
  130. var self = this;
  131. wx.connectSocket({
  132. url: 'wss://mall.shiziyu888.com/wss',
  133. header: {
  134. 'content-type': 'application/json'
  135. },
  136. method: "GET"
  137. })
  138. wx.onSocketOpen(function (res) {
  139. var login_data = '{ "type":"membre_login","domain":"' + domain + '"} ';
  140. wx.sendSocketMessage({
  141. data: login_data
  142. });
  143. setTimeout(function () {
  144. app.util.request({
  145. 'url': 'entry/wxapp/index',
  146. 'data': {
  147. controller: 'goods.notify_order'
  148. },
  149. dataType: 'json',
  150. success: function (res) {
  151. if (res.data.ret == 1) {
  152. self.send_bao_notify(res.data);
  153. }
  154. }
  155. });
  156. }, 1000);
  157. setInterval(function () {
  158. if (self.data.jarray.length > 0) {
  159. var res = self.data.jarray.pop();
  160. self.show_or(res);
  161. }
  162. }, 4000);
  163. })
  164. wx.onSocketMessage(function (res) {
  165. var data = util.stringToJson(res.data);
  166. console.log(data);
  167. switch (data.type) {
  168. // 服务端ping客户端
  169. case 'ping':
  170. var pong_data = '{"type":"pong"}';
  171. wx.sendSocketMessage({ data: pong_data });
  172. break;
  173. case 'member_buy_msg':
  174. var jarray_str = self.data.jarray;
  175. jarray_str.push(data);
  176. self.setData({
  177. jarray: jarray_str
  178. });
  179. //this.on_member_buy_msg(data);
  180. break;
  181. }
  182. })
  183. wx.onSocketError(function (res) {
  184. console.log('WebSocket连接打开失败,请检查!')
  185. })
  186. },
  187. send_bao_notify: function (res) {
  188. var buy_data = '{ "type":"member_buy","avatar":"' + res.avatar + '","miao":"' + res.miao + '","username":"' + res.username + '","order_id":"' + res.order_id + '","order_url":"' + res.order_url + '"} ';
  189. wx.sendSocketMessage({
  190. data: buy_data
  191. });
  192. },
  193. show_or: function (res) {
  194. this.setData({
  195. notice_orderid: res.order_id,
  196. notice_avatar: res.avatar,
  197. notice_name: res.username,
  198. notice_miao: res.miao,
  199. isHidenotice: false
  200. });
  201. var self = this;
  202. setTimeout(function () {
  203. self.setData({
  204. isHidenotice: true
  205. })
  206. setTimeout(function () {
  207. if (self.data.jarray.length > 0) {
  208. var res = self.data.jarray.pop();
  209. self.show_or(res);
  210. }
  211. }, 3000);
  212. }, 2000);
  213. },
  214. noticego: function (e) {
  215. var orderid = e.currentTarget.dataset.orderid;
  216. var pages_all = getCurrentPages();
  217. this.nav_dir_go_link('/Snailfish_shop/pages/share/index?id=' + orderid);
  218. },
  219. /**
  220. * 生命周期函数--监听页面初次渲染完成
  221. */
  222. onReady: function () {
  223. },
  224. common_go_link: function (e) {
  225. var url = e.currentTarget.dataset.link;
  226. this.nav_dir_go_link(url);
  227. },
  228. nav_dir_go_link: function (url) {
  229. wx.navigateTo({
  230. url: url,
  231. fail: function () {
  232. wx.redirectTo({
  233. url: url
  234. })
  235. }
  236. })
  237. },
  238. /**
  239. * 生命周期函数--监听页面显示
  240. */
  241. onShow: function () {
  242. this.setData({
  243. show_search: true
  244. })
  245. },
  246. show_search_func: function () {
  247. var show_search = this.data.show_search;
  248. if (show_search) {
  249. this.setData({
  250. show_search: false
  251. });
  252. } else {
  253. this.setData({
  254. show_search: true
  255. });
  256. }
  257. },
  258. /**
  259. * 生命周期函数--监听页面隐藏
  260. */
  261. onHide: function () {
  262. },
  263. /**
  264. * 生命周期函数--监听页面卸载
  265. */
  266. onUnload: function () {
  267. },
  268. change_cate: function (e) {
  269. var cate_id = 'cate_' + e.currentTarget.dataset.cate_id;
  270. this.setData({
  271. cur_view_id: e.currentTarget.dataset.cate_id,
  272. del_view_id: cate_id
  273. })
  274. },
  275. change_nav: function (nav_id) {
  276. this.setData({
  277. cur_view_id: nav_id
  278. })
  279. },
  280. /**
  281. * 页面相关事件处理函数--监听用户下拉动作
  282. */
  283. onPullDownRefresh: function () {
  284. },
  285. /**
  286. * 页面上拉触底事件的处理函数
  287. */
  288. onReachBottom: function () {
  289. },
  290. /**
  291. * 用户点击右上角分享
  292. */
  293. onShareAppMessage: function () {
  294. }
  295. })