search.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. // pages/search/search.js
  2. var app = getApp();
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. searchKeys: wx.getStorageSync('searchKeys') || [],
  9. loading: false,
  10. loadding: false,
  11. scrollTop: 0,
  12. current: 0,
  13. pages: null,
  14. picTitle: "",
  15. userInfo: wx.getStorageSync('userInfo'),
  16. goodsList: []
  17. },
  18. /**
  19. * 生命周期函数--监听页面加载
  20. */
  21. onLoad(options) {
  22. this.setData({
  23. searchKeys: wx.getStorageSync('searchKeys') || [],
  24. })
  25. },
  26. /**
  27. * 生命周期函数--监听页面初次渲染完成
  28. */
  29. onReady() {
  30. },
  31. /**
  32. * 生命周期函数--监听页面显示
  33. */
  34. onShow() {
  35. },
  36. asyncValue(e) {
  37. this.setData({
  38. ["" + e.target.dataset.name]: e.detail.value
  39. })
  40. },
  41. async getGoodsList() {
  42. if (this.data.pages != null && this.data.current >= this.data.pages) {
  43. return;
  44. }
  45. this.setData({
  46. current: this.data.current + 1,
  47. loadding: true
  48. });
  49. try {
  50. let {
  51. data
  52. } = await app.ajax.get({
  53. url: "/admin/bxdprod/browsePage",
  54. data: {
  55. picTitle: this.data.picTitle,
  56. mini: 1,
  57. current: this.data.current,
  58. size: 20,
  59. virtualInventoryId: wx.getStorageSync('virtualInventoryId')
  60. }
  61. });
  62. let goodsList = this.data.goodsList.concat(data.data.records);
  63. goodsList = goodsList.map(v => {
  64. v["picText"] = v.pic ? v.pic.split(",")[0] : '/images/empty.png';
  65. return v;
  66. });
  67. this.setData({
  68. goodsList: goodsList,
  69. pages: data.data.pages || null,
  70. loadding: false
  71. })
  72. } catch (e) {
  73. this.setData({
  74. loadding: false
  75. })
  76. }
  77. },
  78. searchGoods(e) {
  79. let keys = e.currentTarget.dataset.name1 || this.data.picTitle;
  80. if (!keys) {
  81. return;
  82. }
  83. if (e.currentTarget.dataset.index == undefined) {
  84. let searchKeys = wx.getStorageSync('searchKeys') || [];
  85. if (keys.length <= 20) {
  86. searchKeys.push(keys);
  87. searchKeys = Array.from(new Set(searchKeys))
  88. wx.setStorageSync('searchKeys', searchKeys);
  89. this.setData({
  90. searchKeys: searchKeys
  91. })
  92. }
  93. }
  94. this.setData({
  95. picTitle: keys,
  96. goodsList: [],
  97. current: 0,
  98. pages: null,
  99. loading: true
  100. })
  101. this.getGoodsList();
  102. },
  103. delHistory() {
  104. if (this.data.searchKeys.length == 0) {
  105. return;
  106. }
  107. let that = this;
  108. wx.showModal({
  109. title: '提示',
  110. content: '您确定要删除搜索记录吗?',
  111. success(res) {
  112. if (res.confirm) {
  113. that.setData({
  114. searchKeys: []
  115. })
  116. wx.setStorageSync('searchKeys', [])
  117. } else if (res.cancel) {}
  118. }
  119. })
  120. },
  121. cancelSearch() {
  122. this.setData({
  123. picTitle: "",
  124. goodsList: [],
  125. current: 0,
  126. loading: false,
  127. pages: null
  128. })
  129. },
  130. /**
  131. * 生命周期函数--监听页面隐藏
  132. */
  133. onHide() {
  134. },
  135. /**
  136. * 生命周期函数--监听页面卸载
  137. */
  138. onUnload() {
  139. },
  140. /**
  141. * 页面相关事件处理函数--监听用户下拉动作
  142. */
  143. onPullDownRefresh() {
  144. },
  145. /**
  146. * 页面上拉触底事件的处理函数
  147. */
  148. onReachBottom() {},
  149. /**
  150. * 用户点击右上角分享
  151. */
  152. onShareAppMessage() {
  153. }
  154. })