index.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. // nova-tourism/components/suggest/index.js
  2. let Parse = getApp().Parse;
  3. const company = getApp().globalData.company
  4. const uid = Parse.User.current()?.id
  5. const req = require('../../../utils/request')
  6. Component({
  7. /**
  8. * 组件的属性列表
  9. */
  10. properties: {
  11. store_id:null
  12. },
  13. /**
  14. * 组件的初始数据
  15. */
  16. data: {
  17. gift: [], //望仙礼遇-商品
  18. swiper:1,//左右滑动遍历次数
  19. skip:0,
  20. },
  21. lifetimes: {
  22. detached: function () {},
  23. attached: async function () {
  24. setTimeout(() => {
  25. let {store_id}=this.properties
  26. this.setData({store_id})
  27. this.getGift()
  28. this.getCount()
  29. }, 800);
  30. },
  31. },
  32. /**
  33. * 组件的方法列表
  34. */
  35. methods: {
  36. /** 获取望仙礼遇-商品*/
  37. async getGift() {
  38. let {
  39. store_id
  40. } = this.properties
  41. let {skip}=this.data
  42. console.log(store_id)
  43. let sql = `SELECT good."objectId",good."name",good."price",good."image"
  44. FROM "ShopGoods" good
  45. WHERE good."company" = '${company}'
  46. AND good."isDeleted" IS NOT TRUE
  47. AND good."status" IS TRUE
  48. AND good."shopStore"='${store_id}'
  49. ORDER BY COALESCE(good."isRecom", FALSE) DESC,
  50. CASE WHEN good."top"= 0 THEN 1 ELSE 0 END,
  51. good."top" ASC,good."createdAt"
  52. LIMIT 4 OFFSET ${skip}`
  53. let gift = await req.customSQL(sql) || []
  54. console.log(gift)
  55. this.setData({
  56. gift
  57. })
  58. },
  59. /**获取商品总量 */
  60. async getCount(){
  61. let {
  62. store_id
  63. } = this.properties
  64. let query = new Parse.Query('ShopGoods')
  65. query.equalTo('company',company)
  66. query.notEqualTo('isDeleted',true)
  67. query.equalTo('status',true)
  68. query.equalTo('shopStore',store_id)
  69. let count = await query.count()
  70. console.log(count)
  71. let swiper = Math.ceil(count / 4)||1
  72. if(swiper>10) swiper = 10//最多10个内切换,40个商品
  73. this.setData({swiper,count})
  74. },
  75. /**切换Swiper */
  76. changeSwiper(e){
  77. let {current} = e.detail
  78. let skip = current * 4
  79. this.setData({skip})
  80. this.getGift()
  81. },
  82. /** 跳转*/
  83. tourl(e) {
  84. const url = e.currentTarget.dataset.url
  85. wx.navigateTo({
  86. url: `${url}` //目标页面的路径
  87. });
  88. },
  89. }
  90. })