1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- // pages/demo11/index.js
- var Nova = getApp().Nova;
- Component({
- options: {
- multipleSlots: true, //在组件定义时的选项中启用多slot支持
- },
- /**
- * 组件的属性列表
- */
- properties: {
- options: null,
- },
- /**
- * 组件的初始数据
- */
- data: {
- timeData: {},
- },
- ready: function () {
- // 在组件布局完成后执行,确保options参数中有data信息
- this.loadData()
- },
- lifetimes: {
- attached: function () {}
- },
- /**
- * 组件的方法列表
- */
- methods: {
- async loadData() {
- await Nova.checkComponentsDataProperties(this);
- let list = await Nova.getBlockData(this.data.options.data);
- let {
- options
- } = this.data;
- console.log('秒杀', options);
- console.log('list', list);
- list = list.reduce((arr, item) => {
- let now = new Date();
- let endTime = new Date(item.endTime.iso).getTime();
- let time = (endTime - now.getTime()) >= 0 ? (endTime - now.getTime()) : 0;
- item.time = time;
- item.timeData = {};
- item.discount = (item.goods.costPrice ? item.goods.costPrice : item.goods.originalPrice || 0) - (item.goods.price);
- console.log(item);
- if(item.goods.total > 0){
- arr.push(item)
- return arr
- }
- },[]);
- let {
- data,
- column,
- style,
- } = options
- let {
- className,
- filter
- } = data;
- this.setData({
- column,
- list,
- data,
- className,
- style,
- filter,
- })
- },
- onChange(e) {
- let index = e.currentTarget.dataset.index;
- let timeData = `list[${index}].timeData`;
- this.setData({
- [timeData]: e.detail,
- });
- },
- toSeckill(e) {
- let item = e.currentTarget.dataset.item
- console.log(item)
- wx.navigateTo({
- url: `/nova-shop/pages/goods/rushGoods/details/index?id=${item.objectId}`,
- })
- }
- }
- })
|