serch-outcome.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. Page({
  2. /**
  3. * 页面的初始数据
  4. */
  5. data: {
  6. list: [],
  7. shoopingtext: "", //搜索框的值
  8. history: false, //显示历史记录
  9. noneview: false, //显示未找到提示
  10. show: false, //显示商品列表
  11. sea: true,
  12. //title: false,
  13. historyArray: [], //历史记录数组,
  14. newArray: [], //添加历史记录数组
  15. },
  16. onInput: function (e) {
  17. // this.setData({ shoopingtext: e.detail.value });
  18. var searchtext = this.data.shoopingtext; //搜索框的值
  19. var sss = true;
  20. if (searchtext != "") {
  21. // //将搜索框的值赋给历史数组
  22. this.data.historyArray.push(searchtext);
  23. //模糊查询 循环查询数组中的title字段
  24. for (var index in this.data.list) {
  25. var num = this.data.list[index].title.indexOf(searchtext);
  26. let temp = "list[" + index + "].status";
  27. if (num != -1) {
  28. //不匹配的不显示
  29. this.setData({
  30. [temp]: 1,
  31. show: true,
  32. });
  33. sss = false; //隐藏未找到提示
  34. } else {
  35. this.setData({
  36. show: false,
  37. });
  38. }
  39. }
  40. this.setData({
  41. history: false, //隐藏历史记录
  42. noneview: sss, //隐藏未找到提示
  43. shoppinglist: true, //显示商品列表
  44. sea: false, //显示图片
  45. newArray: this.data.historyArray, //给新历史记录数组赋值
  46. });
  47. } else {
  48. this.setData({
  49. noneview: true, //显示未找到提示
  50. show: false, //隐藏商品列表
  51. sea: false,
  52. history: false, //隐藏历史记录
  53. });
  54. }
  55. this.setData({
  56. shoopingtext: "",
  57. });
  58. // console.log(this.data.shoopingtext);
  59. },
  60. shoppinginput: function (e) {
  61. //当删除input的值为空时
  62. if (e.detail.value == "") {
  63. this.setData({
  64. history: true, //显示历史记录
  65. shoppinglist: false, //隐藏商品列表
  66. sea: true,
  67. }); //所有商品列表的状态改为0
  68. for (var index in this.data.list) {
  69. let temp = "list[" + index + "].status";
  70. this.setData({
  71. [temp]: 0,
  72. });
  73. }
  74. }
  75. this.setData({
  76. shoopingtext: e.detail.value,
  77. });
  78. },
  79. delete: function () {
  80. wx.showModal({
  81. title: "删除",
  82. content: "您确定要删除全部的搜索历史吗?",
  83. complete: (res) => {
  84. if (res.cancel) {
  85. console.log('您已点击取消')
  86. }
  87. if (res.confirm) {
  88. this.setData({
  89. newArray: "",
  90. historyArray:[]
  91. });
  92. }
  93. },
  94. });
  95. },
  96. /**
  97. * 生命周期函数--监听页面加载
  98. */ onLoad(options) {
  99. wx.request({
  100. url:
  101. "https://www.fastmock.site/mock/883cd62177ae0a3a79638beccc3349da/api/order/list",
  102. success: (e) => {
  103. this.setData({
  104. list: e.data.data.list,
  105. });
  106. },
  107. });
  108. },
  109. });