search.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. // search.js
  2. var touchDot = 0;//触摸时的原点
  3. var time = 0;// 时间记录,用于滑动时且时间小于1s则执行左右滑动
  4. var interval = "";// 记录/清理时间记录
  5. Page({
  6. data: {
  7. wordClick : false,
  8. searchValue : '',
  9. searchList:[],
  10. logoList:[
  11. {
  12. logoUrl: '/pages/brandInfor/brandInfor?title=Moleskine&intro=传奇笔记本&src=https://www.daliangzao.net/images/1513653278658_Moleskine-2.jpg&src1=https://www.daliangzao.net/images/1513653278658_Moleskine-2.jpg&id=2991',
  13. logoSrc: 'https://www.daliangzao.net/images/searchLogo/search_logo_1.png'
  14. },
  15. {
  16. logoUrl: '/pages/brandInfor/brandInfor?title=凌美&intro=唤醒书写的记忆&src=https://www.daliangzao.net/images/1513653080002_Lamy-2.jpg&src1=https://www.daliangzao.net/images/1513653080002_Lamy-2.jpg&id=3023',
  17. logoSrc: 'https://www.daliangzao.net/images/searchLogo/search_logo_2.png'
  18. },
  19. {
  20. logoUrl: '/pages/brandInfor/brandInfor?title=哲品&intro=东方生活品牌&src=https://www.daliangzao.net/images/1513653110782_哲品-2.jpg&src1=https://www.daliangzao.net/images/1513653110782_哲品-2.jpg&id=3030',
  21. logoSrc: 'https://www.daliangzao.net/images/searchLogo/search_logo_3.png'
  22. },
  23. {
  24. logoUrl: '/pages/brandInfor/brandInfor?title=Foreo&intro=美容护肤新革命&src=https://www.daliangzao.net/images/1513652834541_Foreo-2.jpg&src1=https://www.daliangzao.net/images/1513652834541_Foreo-2.jpg&id=3011',
  25. logoSrc: 'https://www.daliangzao.net/images/searchLogo/search_logo_4.png'
  26. },
  27. {
  28. logoUrl: '/pages/brandInfor/brandInfor?title=Best-Life百灵&intro=遇见更好的自己&src=https://www.daliangzao.net/images/1513652716420_Best-Life百灵-2.jpg&src1=https://www.daliangzao.net/images/1513652716420_Best-Life百灵-2.jpg&id=3008',
  29. logoSrc: 'https://www.daliangzao.net/images/searchLogo/search_logo_5.png'
  30. },
  31. {
  32. logoUrl: '/pages/brandInfor/brandInfor?title=Cutipol&intro=来自葡萄牙的纯手工厨具&src=https://www.daliangzao.net/images/1513652786108_Cutipol-2.jpg&src1=https://www.daliangzao.net/images/1513652786108_Cutipol-2.jpg&id=3010',
  33. logoSrc: 'https://www.daliangzao.net/images/searchLogo/search_logo_6.png'
  34. },
  35. {
  36. logoUrl: '/pages/brandInfor/brandInfor?title=BOSE&intro=享音乐之极&src=https://www.daliangzao.net/images/1513652743364_Bose-2.jpg&src1=https://www.daliangzao.net/images/1513652743364_Bose-2.jpg&id=3003',
  37. logoSrc: 'https://www.daliangzao.net/images/searchLogo/search_logo_7.png'
  38. },
  39. {
  40. logoUrl: '/pages/brandInfor/brandInfor?title=B&O&intro=B&O&src=https://www.daliangzao.net/images/1513645951531_B&O-2.jpg&src1=https://www.daliangzao.net/images/1513645951531_B&O-2.jpg&id=3004',
  41. logoSrc: 'https://www.daliangzao.net/images/searchLogo/search_logo_8.png'
  42. },
  43. {
  44. logoUrl: '/pages/brandInfor/brandInfor?title=PUEBCO&intro=工业风家品&src=https://www.daliangzao.net/images/1513653187662_PUEBCO-2.jpg&src1=https://www.daliangzao.net/images/1513653187662_PUEBCO-2.jpg&id=3019',
  45. logoSrc: 'https://www.daliangzao.net/images/searchLogo/search_logo_9.png'
  46. },
  47. {
  48. logoUrl: '/pages/brandInfor/brandInfor?title=CORKCICLE&intro=来自美国佛罗里达&src=https://www.daliangzao.net/images/1513652765187_CORKCICLE-2.jpg&src1=https://www.daliangzao.net/images/1513652765187_CORKCICLE-2.jpg&id=3009',
  49. logoSrc: 'https://www.daliangzao.net/images/searchLogo/search_logo_10.png'
  50. },
  51. {
  52. logoUrl: '/pages/brandInfor/brandInfor?title=JORDAN&JUDY&intro=以创新设计为基点的时尚生活品牌&src=https://www.daliangzao.net/images/1513652927301_JORDAN&JUDY佐敦朱迪-2.jpg&src1=https://www.daliangzao.net/images/1513652927301_JORDAN&JUDY佐敦朱迪-2.jpg&id=3015',
  53. logoSrc: 'https://www.daliangzao.net/images/searchLogo/search_logo_11.png'
  54. },
  55. {
  56. logoUrl: '/pages/brandInfor/brandInfor?title=ALLYO+&intro=专注生产研发&src=https://www.daliangzao.net/images/1513645926762_ALLOY-2.jpg&src1=https://www.daliangzao.net/images/1513645926762_ALLOY-2.jpg&id=3006',
  57. logoSrc: 'https://www.daliangzao.net/images/searchLogo/search_logo_12.png'
  58. }
  59. ]
  60. },
  61. onLoad: function () {
  62. var that = this;
  63. var host = getApp().globalData.servsers;
  64. wx.request({
  65. url: host +"keywordapi/keywordallxcx",
  66. data: {},
  67. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  68. header: {
  69. 'Accept': 'application/json'
  70. },
  71. success: function (res) {
  72. that.setData({
  73. searchList: res.data.rows,
  74. });
  75. if (res == null || res.data == null) {
  76. console.error('网络请求失败');
  77. return;
  78. }
  79. }
  80. })
  81. },
  82. inputSearch:function(e){
  83. this.setData({
  84. searchValue: e.detail.value
  85. })
  86. },
  87. cancelVal:function(e){
  88. this.setData({
  89. searchValue: '',
  90. })
  91. wx.navigateBack(); //返回上一个页面
  92. },
  93. searResult:function(e){
  94. let data;
  95. let localStorageValue = [];
  96. if (this.data.searchValue != '') {
  97. //调用API从本地缓存中获取数据
  98. var searchData = wx.getStorageSync('searchData') || []
  99. searchData.push(this.data.inputValue)
  100. wx.setStorageSync('searchData', searchData)
  101. wx.redirectTo({
  102. url: '/pages/searchList/searchList?commodity_name=' + this.data.searchValue
  103. })
  104. } else {
  105. console.log('6666');
  106. wx.redirectTo({
  107. url: '/pages/searchList/searchList'
  108. })
  109. }
  110. },
  111. writeVal:function(e){//点击热搜词后
  112. var that = this;
  113. var thisVal = e.currentTarget.dataset.val;
  114. that.setData({
  115. wordClick : true,
  116. 'searchValue': thisVal
  117. })
  118. wx.navigateTo({
  119. url: '/pages/searchList/searchList?commodity_name=' + thisVal,
  120. success:function(){
  121. that.setData({
  122. wordClick: false
  123. })
  124. }
  125. })
  126. },
  127. // 触摸开始事件
  128. touchStart: function (e) {
  129. touchDot = e.touches[0].pageX; // 获取触摸时的原点
  130. interval = setInterval(function () {
  131. time++;
  132. }, 100);
  133. },
  134. // 触摸移动事件
  135. touchMove: function (e) {
  136. var touchMove = e.touches[0].pageX;
  137. console.log("touchMove:" + touchMove + " touchDot:" + touchDot + " diff:" + (touchMove - touchDot));
  138. // 向左滑动
  139. if (touchMove - touchDot <= -40 && time < 10) {
  140. wx.switchTab({
  141. url: '/pages/index/index'
  142. });
  143. }
  144. // 向右滑动
  145. if (touchMove - touchDot >= 40 && time < 10) {
  146. console.log('向右滑动');
  147. wx.switchTab({
  148. url: '/pages/index/index'
  149. });
  150. }
  151. },
  152. // 触摸结束事件
  153. touchEnd: function (e) {
  154. clearInterval(interval); // 清除setInterval
  155. time = 0;
  156. }
  157. })
  158. var that;
  159. var Util = require('../../utils/util.js');