search.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. // pages/home/search/search.js
  2. const app = getApp()
  3. const url = require('../../../utils/url.js')
  4. var call = require("../../../utils/net.js")
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. issearch:null,//搜索默认页搜索结果页
  11. condition:false,
  12. search: {
  13. pla: "搜索 社保/公积金/身份证"
  14. },
  15. recommend:[
  16. { name: '社保五险', img:'/icon/search/shebaowuxian.png'},
  17. { name: '养老保险', img: '/icon/search/yanglaobaoxian.png'},
  18. { name: '医疗保险', img: '/icon/search/yiliaobaoxian.png' },
  19. { name: '生育保险', img: '/icon/search/shengyubaoxian.png' },
  20. { name: '工商保险', img: '/icon/search/gongshangbaoxian.png' },
  21. { name: '事业保险', img: '/icon/search/shiyebaoxian.png' },
  22. ],
  23. hotSearch: ['社保查询', '养老保险', '养老', '五险一金', '驾驶证', '港澳通行证'],
  24. question: {
  25. range: null
  26. }
  27. },
  28. //查看详情要进行授权
  29. getUserInfo(e) {
  30. //console.log(e)
  31. let ids = e.currentTarget.dataset.ids;
  32. let title = e.currentTarget.dataset.title;
  33. var userId = wx.getStorageSync('userId');
  34. if (userId) {
  35. wx.navigateTo({
  36. url: '/pages/home/detail/detail?id=' + ids + '&title=' + title,
  37. })
  38. } else {
  39. if (e.detail.errMsg == 'getUserInfo:ok') {
  40. let reqData = {
  41. 'signature': e.detail.signature,
  42. 'rawData': e.detail.rawData
  43. }
  44. wx.login({
  45. success(res) {
  46. if (res.code) {
  47. let code = res.code
  48. reqData['code'] = code
  49. call.request(url.host + url.login,
  50. { code: res.code },
  51. res => {
  52. //console.log(res.data)
  53. wx.setStorageSync('userId', res.data.data); //将userId存入本地缓存
  54. if (res.data.code == 200) {
  55. call.request(url.host + url.getuserinfo,
  56. reqData,
  57. res => {
  58. wx.navigateTo({
  59. url: '/pages/home/detail/detail?id=' + ids + '&title=' + title,
  60. })
  61. console.log(res)
  62. },
  63. res => {
  64. console.log(res)
  65. })
  66. } else {
  67. wx.showToast({
  68. icon: 'none',
  69. title: res.data.msg,
  70. })
  71. }
  72. },
  73. res => {
  74. console.log(res)
  75. })
  76. } else {
  77. console.log('登录失败!' + res.errMsg)
  78. }
  79. }
  80. })
  81. } else if (e.detail.errMsg == 'getUserInfo:fail auth deny') {
  82. wx.showToast({
  83. icon: 'none',
  84. title: '授权失败!',
  85. })
  86. }
  87. }
  88. },
  89. //取消返回上一页
  90. backpage:function(){
  91. wx.navigateBack({
  92. delta: 1
  93. })
  94. },
  95. //跳转详情
  96. // toproblem: function (e) {
  97. // let ids = e.currentTarget.dataset.ids;
  98. // wx.navigateTo({
  99. // url: '/pages/home/detail/detail?id=' + ids,
  100. // })
  101. // },
  102. //搜索
  103. confirm: function (e) {
  104. var that = this
  105. let word = e.detail.value;
  106. //查询接口
  107. if (word.match(/^\s*$/) || word == null || word == undefined || word == ''){
  108. wx.showToast({
  109. title: '请输入搜索关键词!',
  110. icon: 'none',
  111. duration: 2000
  112. })
  113. }else{
  114. wx.showLoading({
  115. mask: true,
  116. title: '搜索中...',
  117. });
  118. call.request(url.host + url.query,
  119. { city: app.globalData.city, word: word },
  120. res => {
  121. console.log(res)
  122. if(res.data.code == 200){
  123. that.setData({
  124. titltRange: res.data.data
  125. })
  126. }else{
  127. wx.showToast({
  128. icon: 'none',
  129. title: res.data.msg,
  130. })
  131. }
  132. wx.hideLoading()
  133. },
  134. res => {
  135. console.log(res)
  136. wx.hideLoading()
  137. })
  138. }
  139. },
  140. /**
  141. * 生命周期函数--监听页面加载
  142. */
  143. onLoad: function (options) {
  144. var that = this;
  145. call.request(url.host + url.query,
  146. { city: app.globalData.city , word: options.word },
  147. res => {
  148. console.log(res)
  149. let word = "search.word"
  150. that.setData({
  151. [word]: options.word,
  152. titltRange: res.data.data
  153. })
  154. },
  155. res => {
  156. console.log(res)
  157. })
  158. },
  159. /**
  160. * 生命周期函数--监听页面初次渲染完成
  161. */
  162. onReady: function () {
  163. },
  164. /**
  165. * 生命周期函数--监听页面显示
  166. */
  167. onShow: function () {
  168. },
  169. /**
  170. * 生命周期函数--监听页面隐藏
  171. */
  172. onHide: function () {
  173. },
  174. /**
  175. * 生命周期函数--监听页面卸载
  176. */
  177. onUnload: function () {
  178. },
  179. /**
  180. * 页面相关事件处理函数--监听用户下拉动作
  181. */
  182. onPullDownRefresh: function () {
  183. },
  184. /**
  185. * 页面上拉触底事件的处理函数
  186. */
  187. onReachBottom: function () {
  188. },
  189. /**
  190. * 用户点击右上角分享
  191. */
  192. onShareAppMessage: function () {
  193. }
  194. })