product-list.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. // components/product-list/product-list.js
  2. // 获取应用实例
  3. const {API} = require('../../service/api.js');
  4. Component({
  5. properties: {
  6. // header嵌入的位置,index:首页
  7. position:{
  8. type:String,
  9. value:''
  10. }
  11. },
  12. data: {
  13. goodsList: [
  14. {
  15. name: "哪吒魔童闹海周边哪吒魔童闹海周边哪吒魔童闹海周边",
  16. price: 49.5,
  17. image:'/images/index/hot-item.png'
  18. },
  19. {
  20. name: "若来十二生肖盲盒 桌面手办若来十二生肖盲盒 桌面手办若来十二生肖盲盒 桌面手办",
  21. price: 49.5,
  22. image:'/images/index/hot-item.png'
  23. },
  24. {
  25. name: "官方正版姜子牙电影四不像",
  26. price: 49.5,
  27. image:'/images/index/hot-item.png'
  28. },
  29. {
  30. name: "若来十二生肖盲盒 十二节气祖国版",
  31. price: 49.5,
  32. image:'/images/index/hot-item.png'
  33. },
  34. {
  35. name: "哪吒魔童闹海周边哪吒魔童闹海周边哪吒魔童闹海周边",
  36. price: 49.5,
  37. image:'/images/index/hot-item.png'
  38. },
  39. {
  40. name: "若来十二生肖盲盒 桌面手办若来十二生肖盲盒 桌面手办若来十二生肖盲盒 桌面手办",
  41. price: 49.5,
  42. image:'/images/index/hot-item.png'
  43. },
  44. {
  45. name: "官方正版姜子牙电影四不像",
  46. price: 49.5,
  47. image:'/images/index/hot-item.png'
  48. },
  49. {
  50. name: "若来十二生肖盲盒 十二节气祖国版",
  51. price: 49.5,
  52. image:'/images/index/hot-item.png'
  53. },
  54. ],
  55. },
  56. methods: {
  57. // 获取今日热门商品列表
  58. getHotCommodity(){
  59. API.getLeftProds().then(res=>{
  60. if(res){
  61. this.setData({
  62. goodsList:res.prodList
  63. })
  64. };
  65. })
  66. },
  67. // 获取上新商品列表
  68. getNewCommodity(){
  69. API.getMiddleProds().then(res=>{
  70. if(res){
  71. this.setData({
  72. goodsList:res.prodList
  73. })
  74. };
  75. })
  76. },
  77. // 获取预售商品列表
  78. getPresaleCommodity(){
  79. API.getRightProds().then(res=>{
  80. if(res){
  81. this.setData({
  82. goodsList:res.prodList
  83. })
  84. }
  85. })
  86. }
  87. },
  88. ready: function(){
  89. if(this.data.position === 'hot') this.getHotCommodity();
  90. if(this.data.position === 'new') this.getNewCommodity();
  91. if(this.data.position === 'presale') this.getPresaleCommodity();
  92. }
  93. })