index.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. // pages/demo11/index.js
  2. var Nova = getApp().Nova;
  3. Component({
  4. options: {
  5. multipleSlots: true, //在组件定义时的选项中启用多slot支持
  6. },
  7. /**
  8. * 组件的属性列表
  9. */
  10. properties: {
  11. options: null,
  12. },
  13. /**
  14. * 组件的初始数据
  15. */
  16. data: {
  17. timeData: {},
  18. },
  19. ready: function () {
  20. // 在组件布局完成后执行,确保options参数中有data信息
  21. this.loadData()
  22. },
  23. lifetimes: {
  24. attached: function () {}
  25. },
  26. /**
  27. * 组件的方法列表
  28. */
  29. methods: {
  30. async loadData() {
  31. await Nova.checkComponentsDataProperties(this);
  32. let list = await Nova.getBlockData(this.data.options.data);
  33. let {
  34. options
  35. } = this.data;
  36. console.log('秒杀', options);
  37. console.log('list', list);
  38. list = list.reduce((arr, item) => {
  39. let now = new Date();
  40. let endTime = new Date(item.endTime.iso).getTime();
  41. let time = (endTime - now.getTime()) >= 0 ? (endTime - now.getTime()) : 0;
  42. item.time = time;
  43. item.timeData = {};
  44. item.discount = (item.goods.costPrice ? item.goods.costPrice : item.goods.originalPrice || 0) - (item.goods.price);
  45. console.log(item);
  46. if(item.goods.total > 0){
  47. arr.push(item)
  48. return arr
  49. }
  50. },[]);
  51. let {
  52. data,
  53. column,
  54. style,
  55. } = options
  56. let {
  57. className,
  58. filter
  59. } = data;
  60. this.setData({
  61. column,
  62. list,
  63. data,
  64. className,
  65. style,
  66. filter,
  67. })
  68. },
  69. onChange(e) {
  70. let index = e.currentTarget.dataset.index;
  71. let timeData = `list[${index}].timeData`;
  72. this.setData({
  73. [timeData]: e.detail,
  74. });
  75. },
  76. toSeckill(e) {
  77. let item = e.currentTarget.dataset.item
  78. console.log(item)
  79. wx.navigateTo({
  80. url: `/nova-shop/pages/goods/rushGoods/details/index?id=${item.objectId}`,
  81. })
  82. }
  83. }
  84. })