client.js 8.83 KB
// pages/tab/output/components/client/client.js
import outputApi from '~/api/outputApi/index'
import { IMG_URL } from '~/utils/constantData'
Component({
    /**
     * 组件的属性列表
     */
    options: {
        addGlobalClass: true
    },
    properties: {},

    options: {
        styleIsolation: 'shared'
    },

    /**
     * 组件的初始数据
     */
    data: {
        IMGURL: IMG_URL,
        pMerchantId: '',
        totalProfit: 0,
        pageObj: {
            currentPage: 1,
            pageSize: 10
        },
        totalPages: -1,
        list: [],
        sceneCodeList: ['SC002', 'SC003', 'SC004', 'SC001'],
        tabActive: 'store',
        // 业务经营汇总
        stickyScrollTop: 0,
        stickyOffsetTop: 0,
        formData: {
            // 0:全部-1;1:精品升级SC002;2:售后众筹SC004;3:会员权益/升级SC001
            busiIdx: 0,
            sceneCode: '-1',
            // 时间筛选Idx(全部,精品升级,会员权益)
            timeIdx: 0,
            // 产品/状态筛选Idx(售后众筹)
            proIdx: 0,
            statusIdx: 0
        },
        busiObj: {},
        busiTotalList: [],
        merchantName4s: '',
        crowdOrderObj: {}
    },
    lifetimes: {
        attached() {
            wx.$eventbus.on('clientRefresh', res => {
                this.getBusinessData()
            })
            this.getBusinessData()
        }
    },

    /**
     * 组件的方法列表
     */
    methods: {
        getBusinessData() {
            this.getBusiStatistics()
        },

        // 升降序
        handleSort() {
            this.getBusiStatistics(true)
        },

        // 吸顶
        handleBusiScroll: wx.$util.debounce(function (e) {
            this.setData({
                stickyScrollTop: e?.detail?.scrollTop
            })
        }, 50),

        resetBusiData() {
            this.setData({
                busiObj: {},
                busiTotalList: [],
                crowdOrderObj: {}
            })
        },
        getBusiStatistics(isReset = false, isBusiTab = false) {
            let sortTabModule = this.selectComponent('#sortTab')
            if (sortTabModule && isBusiTab) {
                sortTabModule.resetAllAsc()
            }
            let sortSearchData = sortTabModule ? sortTabModule.dealParams() : {}
            let { subMerchant } = wx.$storage.get()
            let params = {
                ...sortSearchData,
                merchantIds: subMerchant,
            }
            outputApi.getBusiStatistics(params).then(res => {
                this.resetBusiData()
                if (isReset) {
                    this.setData({
                        busiScrollTop: 0
                    })
                }
                this.setData({
                    triggered: false
                })
                let _list = []
                _list = res.merchantList || []
                // 0:全部-1;1:精品升级SC002;2:售后众筹SC004;3:会员权益/升级SC001
                let _openList = [{
                    code: 'SC002',
                    name: 'boutiqueUpgrade',
                    type: 1,
                }, {
                    code: 'SC004',
                    name: 'afterSalesCrowdfunding',
                    type: 0,
                }, {
                    code: 'SC001',
                    name: 'vdUpgrade',
                    type: 2,
                }, {
                  code: 'usedCarFlag',
                  name: 'usedCarTotal',
                  type: 4,
              }]
                _list.forEach(item => {
                    _openList.forEach(k => {
                      if (k.code === 'usedCarFlag') {
                        // 二手车特殊处理:根据usedCarFlag值判断是否开通(1:开通,0:未开通)
                        if (item.usedCarFlag !== 1) item[k.name] = '未开通'
                        // item[k.name] = item.usedCarFlag === 1 ? '' : '未开通'
                      } else if (!item.sceneCodes) {
                          item[k.name] = '未开通'
                      } else if (item.sceneCodes && !item.sceneCodes.includes(k.code)) {
                          item[k.name] = '未开通'
                      } 
                    })
                })
                this.setData({
                    merchantName4s: '',
                    busiObj: res,
                    totalProfit: res.totalAmount,
                    busiTotalList: _list,
                    busiTotalListFirst: _list
                })
            })
        },

        // 门店经营汇总-start
        getPMerchantInfo() {
            let { userInfo } = wx.$storage.get()
            this.setData({
                pMerchantInfo: userInfo,
                pMerchantId: userInfo.subLoginUser.merchantId
            })
        },
        onBindRefresh() {
            this.clientRefresh(true)
        },
        handleBlur(e) {
            const merchantName4s = e.detail.value;
            const { busiTotalListFirst } = this.data
            this.setData({
                busiTotalList: busiTotalListFirst.filter(item => item.merchantName4s.includes(merchantName4s))
            })
        },
        clientRefresh(isPull = false) {
            this.getPMerchantInfo()
            this.setData({
                ['pageObj.currentPage']: 1,
                list: []
            })
            this.getClientApi(isPull)
        },
        getClientApi(isPull = false) {
            //   this.getProfit()
            //   this.getList()
            isPull &&
                wx.$api.showToast({
                    title: '刷新成功',
                    icon: 'success'
                })
            if (this.data.pageObj.currentPage == 1) {
                this.setData({
                    scrollTop: 0,
                    triggered: false
                })
            }
        },
        getList() {
            let { sceneCodeList } = this.data
            outputApi.getCustomerPageList({ merchantId: this.data.pMerchantId, ...this.data.pageObj }).then(res => {
                var list = this.data.list
                list = list.concat(res.list)
                list.forEach((item, index) => {
                    item.scenePriceList = []
                    item.sceneList.forEach((k, idx) => {
                        item['scene' + (idx + 1)] = item.sceneList[idx].flag
                        let i = sceneCodeList.findIndex(m => m == k.sceneCode)
                        item.scenePriceList[i] = {
                            total: item.sceneList[idx].totalMoney || 0
                        }
                    })
                    item.isOpenScene = item.sceneList.map(item => item.flag).some(item => item == true)
                })
                this.setData({
                    list: list,
                    totalPages: res.pages
                })
            })
        },
        onReachBottom() {
            if (this.data.totalPages != -1 && this.data.pageObj.currentPage == this.data.totalPages) {
                return true
            }
            this.setData({
                ['pageObj.currentPage']: this.data.pageObj.currentPage + 1
            })
            this.getClientApi()
        },
        handleJumpIdx() {
            wx.$router.go('pages.index')
        },

        async handleShare(e) {
            let { idx } = e.currentTarget.dataset
            var item = {
                activityId: this.data.list[idx].activityLastUnSharedInfo.id,
                activityName: this.data.list[idx].activityLastUnSharedInfo.activityName
            }
            wx.$api.showLoading('加载中...')
            outputApi
                .getPosterUrl({
                    id: item.activityId
                })
                .then(res => {
                    item.posterUrl = res
                    this.setData({
                        posterItem: item,
                        isShowTip: false
                    })
                })
                .catch(() => {
                    wx.$api.showToast('下载海报失败')
                })
        },
        /**长按海报 */
        async longtouch(e) {
            this.clientRefresh()
            let { activityId } = e.detail
            const res = await outputApi.reportPosterTrack({
                activityId
            })
        },
        handleJump(e) {
            let { idx } = e.currentTarget.dataset
            var currentItem = this.data.list[idx]
            var params = {
                merchantId: currentItem.merchantId,
                merchantName: currentItem.merchantName,
                pMerchantId: this.data.pMerchantId,
                pMerchantName: this.data.pMerchantInfo.subLoginUser.merchantName,
                isSuper: this.data.pMerchantInfo.isSuper
            }
            wx.$router.go('/packagesList/packageOutput/pages/summary', params)
        }
        // 门店经营汇总-end
    }
})