search.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. import {
  2. TestVerify
  3. } from "../../utils/verify";
  4. import {
  5. ApiModel
  6. } from "../../utils/api"
  7. const _Http = new ApiModel();
  8. const _Verify = new TestVerify();
  9. const processingData = require("../../utils/processingData.js");
  10. Page({
  11. /**
  12. * 页面的初始数据
  13. */
  14. data: {
  15. tabsList: ['通告', '供需', '直播'],
  16. ftype: 3, //1:直播,2:供需,3:通告
  17. annunciateList: [], //通告列表
  18. liveList: [], //直播列表
  19. supplyanddemandList: [], //供需列表
  20. showPlaceholder: true, //是否显示占位图
  21. },
  22. /**
  23. * 生命周期函数--监听页面加载
  24. */
  25. onLoad: function (options) {
  26. },
  27. //切换搜索类型
  28. tabsSelectedIitem({
  29. detail
  30. }) {
  31. let ftype = this.data.ftype;
  32. switch (detail) {
  33. case "通告":
  34. ftype = 3;
  35. break;
  36. case "供需":
  37. ftype = 2;
  38. break;
  39. case "直播":
  40. ftype = 1;
  41. break;
  42. }
  43. if (ftype == this.data.ftype) return;
  44. this.setData({
  45. ftype
  46. });
  47. this.isPlaceholder()
  48. },
  49. /* 搜索关键字 */
  50. searchContent(e) {
  51. let {
  52. value
  53. } = e.detail;
  54. value = _Verify.Eliminate(value.trim());
  55. if (value) {
  56. _Http.basic({
  57. "classname": "publicmethod.homepage.homepage",
  58. "method": "searchPortalInfo",
  59. "content": {
  60. "getdatafromdbanyway": true,
  61. "keyStr": value,
  62. "ftype": ""
  63. }
  64. }).then(res => {
  65. if (res.msg != '成功') return wx.showToast({
  66. title: res.data,
  67. icon: 'none'
  68. })
  69. let annunciateList = res.data.TNOTICE,
  70. supplyanddemandList = res.data.tsupplyanddemand;
  71. if (annunciateList.length != 0) annunciateList = processingData.annunciateCheckdate(annunciateList);
  72. if (supplyanddemandList.length != 0) supplyanddemandList = processingData.annunciateCheckdate(supplyanddemandList);
  73. this.setData({
  74. annunciateList,
  75. liveList: res.data.tlive,
  76. supplyanddemandList
  77. })
  78. this.isPlaceholder()
  79. })
  80. } else {
  81. this.setData({
  82. annunciateList: [],
  83. liveList: [],
  84. supplyanddemandList: []
  85. })
  86. this.isPlaceholder()
  87. }
  88. },
  89. /* 是否显示占位图 */
  90. isPlaceholder() {
  91. let showPlaceholder = false;
  92. switch (this.data.ftype) {
  93. case 3:
  94. showPlaceholder = (this.data.annunciateList.length == 0) ? true : false;
  95. break;
  96. case 2:
  97. showPlaceholder = (this.data.supplyanddemandList.length == 0) ? true : false;
  98. break;
  99. case 1:
  100. showPlaceholder = (this.data.liveList.length == 0) ? true : false;
  101. break;
  102. }
  103. this.setData({
  104. showPlaceholder
  105. })
  106. },
  107. /**
  108. * 生命周期函数--监听页面初次渲染完成
  109. */
  110. onReady: function () {
  111. },
  112. /**
  113. * 生命周期函数--监听页面显示
  114. */
  115. onShow: function () {
  116. },
  117. /**
  118. * 生命周期函数--监听页面隐藏
  119. */
  120. onHide: function () {
  121. },
  122. /**
  123. * 生命周期函数--监听页面卸载
  124. */
  125. onUnload: function () {
  126. },
  127. /**
  128. * 页面相关事件处理函数--监听用户下拉动作
  129. */
  130. onPullDownRefresh: function () {
  131. },
  132. /**
  133. * 页面上拉触底事件的处理函数
  134. */
  135. onReachBottom: function () {
  136. },
  137. /**
  138. * 用户点击右上角分享
  139. */
  140. onShareAppMessage: function () {
  141. }
  142. })