list.js 2.58 KB
import api from '../../common/api';
import formatDate from '../../common/formatDate';

export default {
    formatData(data) {
        let build = [];
        let endDate = '';

        data.forEach((val) => {
            if (val.activityStartDate.split('/')[0] === val.activityEndDate.split('/')[0]) {
                endDate = formatDate.slashToString(val.activityEndDate, 0);
                if (val.activityStartDate.split('/')[1] === val.activityEndDate.split('/')[1]) {
                    endDate = formatDate.slashToString(val.activityEndDate, 1);
                }
            } else {
                endDate = formatDate.slashToString(val.activityEndDate);
            }

            build.push({
                activityName: val.activityName,
                activityStartDate: formatDate.slashToString(val.activityStartDate),
                activityEndDate: val.activityStartDate === val.activityEndDate ? '' : endDate,
                activityDayStartTime: val.activityDayStartTime,
                activityDayEndTime: val.activityDayEndTime,
                free: val.isFree === 1,
                price: val.price,
                image: val.image.split(',')[0],
                id: val.id,
                needApo: val.isAppointment === 1,
                apoStatus: val.appointStatus === 1,
                trendClassTypeName: val.trendClassTypeName
            });
        });

        return build;
    },
    newList(params) {
        return api.get({
            url: '/ActivityConfigController/getActivityNowList',
            data: {
                activityType: params.activityType,
                isFront: params.isFront,
                storeId: params.storeId || 0,
                trendClassTypeId: params.trendClassTypeId
            },
            api: 'store',
            code: 200
        }).then((result) => {
            let resu = {};

            if (result && result.length > 0) {
                resu.list = this.formatData(result);
            }
            return resu;
        });
    },
    oldList(params) {
        return api.get({
            url: '/ActivityConfigController/getActivityEndList',
            data: {
                activityType: params.activityType,
                isFront: params.isFront,
                storeId: params.storeId || 0,
                trendClassTypeId: params.trendClassTypeId
            },
            api: 'store',
            code: 200
        }).then((result) => {
            let resu = {};

            if (result && result.length > 0) {
                resu.list = this.formatData(result);
            }
            return resu;
        });
    }
};