index.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. // nova-tourism/pages/collect/good-list/index.js
  2. const Parse = getApp().Parse;
  3. const company = getApp().globalData.company;
  4. const uid = Parse.User.current()?.id
  5. const req = require('../../../../utils/request')
  6. let {
  7. statusBarHeight,
  8. screenHeight,
  9. screenWidth,
  10. safeArea
  11. } = wx.getSystemInfoSync()
  12. let custom = wx.getMenuButtonBoundingClientRect()
  13. let customHeight = custom.height
  14. let customWidth = custom.width
  15. Page({
  16. /**
  17. * 页面的初始数据
  18. */
  19. data: {
  20. goodList: [],
  21. searchTimeOut: null,
  22. value:'',
  23. },
  24. /**
  25. * 生命周期函数--监听页面加载
  26. */
  27. onLoad(options) {
  28. let nav_px = statusBarHeight + customHeight + 10
  29. let scroll_px = +safeArea.bottom - statusBarHeight - customHeight
  30. let {store_id}=options
  31. this.setData({
  32. nav_px,
  33. scroll_px,
  34. cart_buttom: 120,
  35. statusBarHeight,
  36. customWidth,
  37. store_id
  38. })
  39. this.getGood()
  40. },
  41. /**搜索框输入内容 */
  42. searchInput() {
  43. let {
  44. searchTimeOut
  45. } = this.data
  46. if (searchTimeOut) clearTimeout(searchTimeOut)
  47. let that = this
  48. let timeOut = setTimeout(() => {
  49. that.setData({
  50. goodList: []
  51. })
  52. that.getGood()
  53. }, 500);
  54. this.setData({
  55. searchTimeOut: timeOut
  56. })
  57. },
  58. /**获取商品 */
  59. async getGood() {
  60. let {
  61. goodList,
  62. store_id,
  63. value
  64. } = this.data
  65. if (value && value != '') {}
  66. let sql = `SELECT good."objectId",good."name",good."price",good."image"
  67. FROM "ShopGoods" good
  68. WHERE good."company" = '${company}'
  69. AND good."isDeleted" IS NOT TRUE
  70. ${store_id?`AND good."shopStore" = '${store_id}'`:''}
  71. AND good."status" IS TRUE
  72. AND good."name" LIKE '%${value}%'
  73. ORDER BY COALESCE(good."isRecom", FALSE) DESC,
  74. CASE WHEN good."top"= 0 THEN 1 ELSE 0 END,
  75. good."top" ASC
  76. LIMIT 30 OFFSET ${goodList?.length||0}`
  77. let list = await req.customSQL(sql)||[]
  78. console.log(list)
  79. this.setData({
  80. goodList:[...(goodList||[]),...list]
  81. })
  82. },
  83. /** 跳转*/
  84. tourl(e) {
  85. const url = e.currentTarget.dataset.url
  86. wx.navigateTo({
  87. url: `${url}` // 目标页面的路径
  88. });
  89. },
  90. goback() {
  91. wx.navigateBack({
  92. delta: 1
  93. });
  94. },
  95. /**
  96. * 生命周期函数--监听页面初次渲染完成
  97. */
  98. onReady() {
  99. },
  100. /**
  101. * 生命周期函数--监听页面显示
  102. */
  103. onShow() {
  104. },
  105. /**
  106. * 生命周期函数--监听页面隐藏
  107. */
  108. onHide() {
  109. },
  110. /**
  111. * 生命周期函数--监听页面卸载
  112. */
  113. onUnload() {
  114. },
  115. /**
  116. * 页面相关事件处理函数--监听用户下拉动作
  117. */
  118. onPullDownRefresh() {
  119. },
  120. /**
  121. * 页面上拉触底事件的处理函数
  122. */
  123. onReachBottom() {
  124. this.getGood()
  125. },
  126. /**
  127. * 用户点击右上角分享
  128. */
  129. onShareAppMessage() {
  130. }
  131. })