monthReport.js 7.72 KB
// packageOutput/pages/monthReport/monthReport.js
import ActivityApi from '~/api/activityApi/index'
Page({

    /**
     * 页面的初始数据
     */
    data: {
        typeShow: true,
        selectTxt: '产值',
        selectValue: 1,
        dataType: [{
            label: '产值',
            value: 1
        }, {
            label: '成交量',
            value: 2
        }, {
            label: '报价量',
            value: 3
        }, {
            label: '转化率',
            value: 4
        }],
        show: false,
        date: '2023年4月10日',
        maxDate: new Date().getTime(),
        navStyle: 'background-color: rgba(0,0,0,0);',
        currentDate: new Date().getTime(),
        timeValue: new Date().format('yyyy-MM-dd'),
        outputView: {
            outputValue: [{
                label: '报价量(单)',
                name: 'quotationCount',
                unit: '',
                iconUrl: 'store-assistant-assemble/output/icon02.png'
            }, {
                label: '成交量(单)',
                name: 'successCount',
                unit: '',
                iconUrl: 'store-assistant-assemble/output/icon07.png'
            }, {
                label: '产值(元)',
                name: 'outputValue',
                _unit: '¥',
                iconUrl: 'store-assistant-assemble/output/icon05.png'
            }],
            outputValueBoutique: [
                //   {
                //     label: '发券量(总)/张',
                //     name: 'sendCouponTotal',
                //     unit: ''
                // }, 
                // {
                //     label: '营业额(总)/元',
                //     name: 'orderMoneyTotal',
                //     _unit: '¥'
                // }, 
                {
                    label: '升级订单(单)',
                    name: 'upgradeCountTotal',
                    unit: '',
                    iconUrl: 'store-assistant-assemble/output/icon02.png'
                },
                {
                    label: '转化率',
                    name: 'upgradeRatio',
                    unit_: '%',
                    iconUrl: 'store-assistant-assemble/output/icon07.png'
                },
                {
                    label: '客单价(元)',
                    name: 'averagePrice',
                    _unit: '¥',
                    iconUrl: 'store-assistant-assemble/output/icon05.png'
                },
            ],
        }
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        const { time, type, merchantId, merchantName } = options
        this.setData({ timeType: time, type, merchantId, merchantName })
        this.getReport()
    },
    //选择排序
    selectType(e) {
        const {
            value,
            label
        } = e.target.dataset
        this.setData({
            selectValue: value,
            typeShow: true,
            selectTxt: label
        })
        this.getReport()
    },
    showUp() {
        this.setData({
            typeShow: false
        })
    },
    onDisplay() {
        this.setData({ show: true });
    },
    onClose() {
        this.setData({ show: false });
    },
    //查看报表
    getReport() {
        const { type, timeType, merchantId, timeValue,selectValue } = this.data
        let apiName, params
        const dataT = {
            1: {
                day: () => {
                    apiName = 'boutiquecouponQueryByDayReport',
                        params = {
                            merchantId,
                            reportDate: timeValue
                        }
                },
                month: () => {
                    apiName = 'boutiquecouponQueryByMonthReport',
                        params = {
                            merchantId,
                            reportMonth: timeValue.substring(0, 7)
                        }
                }
            },
            2: {
                day: () => {
                    apiName = 'merchantsOutputReport',
                        params = {
                            merchantIds: [merchantId],
                            startTime: timeValue + ' 00:00:00',
                            endTime: timeValue + ' 23:59:59',
                        }
                },
                month: () => {
                    apiName = 'merchantsOutputReport',
                        params = {
                            orderBy:selectValue,
                            merchantIds: [merchantId],
                            startTime: new Date(timeValue).format('yyyy-MM') + '-01' + ' 00:00:00',
                            endTime: new Date(this.getNextMonth(timeValue)).format('yyyy-MM') + '-01' + ' 00:00:00',
                        }
                }
            }
        }
        let orderValue = {
            1: {
                unit: '¥',
                value: 'outputValue',mult:1
            }, 2: {
                unit: '',
                value: 'successCount',mult:1
            }, 3: { unit: '', value: 'quotationCount',mult:1 }, 4: { sign: '%', value: 'conversionRate',mult:100 }
        }
        dataT[type][timeType]()
        ActivityApi[apiName](params).then(res => {
            const list = res.employeeOutputList || res.staffList
            const arr = []
            const staffList = list.length ? Object.assign(arr, list.splice(0, 3)) : arr
            const billboard = staffList.map((item, idx) => {
                return {
                    sort: idx + 1,
                    unit: (type == 2 && timeType == 'month')?orderValue[selectValue].unit:'¥',
                    sign: (type == 2 && timeType == 'month')?orderValue[selectValue].sign:'',
                    value: (type == 2 && timeType == 'month') ? item[orderValue[selectValue].value]*orderValue[selectValue].mult : (item.outputValue || item.orderMoneyTotal || 0),
                    name: item.transferName || item.employeeName
                }
            })
            this.setData({
                outputData: res || {},
                triggered: false,
                billboard
            })
        })
    },
    //获取下个月时间
    getNextMonth(time) {
        const arr = time.split('-')
        let year = arr[0]; //获取当前日期的年份
        let month = +arr[1] + 1; //获取当前日期的月份
        let day = arr[2]; //获取当前日期的日
        if (month == 13) {
            year = parseInt(year) + 1;
            month = 1;
        }
        if (month < 10) {
            month = "0" + month;
        }
        const nextMonth = year + "-" + month + "-" + day;
        return nextMonth;
    },
    formatDate(date) {
        date = new Date(date);
        return `${date.getFullYear()}年${date.getMonth() + 1}}月`;
    },
    onInput(event) {
        this.setData({
            currentDate: event.detail,
        });
    },
    confirm() {
        const { currentDate } = this.data
        this.setData({
            show: false,
            timeValue: new Date(currentDate).format('yyyy-MM-dd')
        });
        this.getReport()
    },
    cancel() {
        this.setData({ show: false });
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})