index.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. LEFT JOIN "ShopStore" shop ON shop."objectId"=good."shopStore"
  69. WHERE good."company" = '${company}'
  70. AND good."isDeleted" IS NOT TRUE
  71. ${store_id?`AND good."shopStore" = '${store_id}'`:''}
  72. AND good."status" IS TRUE
  73. AND good."name" LIKE '%${value}%'
  74. AND shop."isDeleted" IS NOT TRUE
  75. AND shop."isVerified" IS TRUE
  76. ORDER BY COALESCE(good."isRecom", FALSE) DESC,
  77. CASE WHEN good."top"= 0 THEN 1 ELSE 0 END,
  78. good."top" ASC
  79. LIMIT 20 OFFSET ${goodList?.length||0}`
  80. console.log(sql)
  81. let list = await req.customSQL(sql)||[]
  82. console.log(list)
  83. this.setData({
  84. goodList:[...(goodList||[]),...list]
  85. })
  86. },
  87. /** 跳转*/
  88. tourl(e) {
  89. const url = e.currentTarget.dataset.url
  90. wx.navigateTo({
  91. url: `${url}` // 目标页面的路径
  92. });
  93. },
  94. goback() {
  95. wx.navigateBack({
  96. delta: 1
  97. });
  98. },
  99. /**
  100. * 生命周期函数--监听页面初次渲染完成
  101. */
  102. onReady() {
  103. },
  104. /**
  105. * 生命周期函数--监听页面显示
  106. */
  107. onShow() {
  108. },
  109. /**
  110. * 生命周期函数--监听页面隐藏
  111. */
  112. onHide() {
  113. },
  114. /**
  115. * 生命周期函数--监听页面卸载
  116. */
  117. onUnload() {
  118. },
  119. /**
  120. * 页面相关事件处理函数--监听用户下拉动作
  121. */
  122. onPullDownRefresh() {
  123. },
  124. /**
  125. * 页面上拉触底事件的处理函数
  126. */
  127. onReachBottom() {
  128. this.getGood()
  129. },
  130. /**
  131. * 用户点击右上角分享
  132. */
  133. onShareAppMessage() {
  134. }
  135. })