index.js 4.67 KB
import { env } from '~/api/env/index'
import { goodsList } from '../constant/lifeConstant'
Page({

    /**
     * 页面的初始数据
     */
    data: {
        tripMenu: [],
        goodsList,
        utilList: []
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        const {
            merchantId
        } = wx.p.storage.get('merchant_info')
        this.getHomeConfig(merchantId)
        this.getAllMerchantList()
    },
    getHomeConfig(merchantId) {
        wx.p.api.homeApi.getHomeConfig({ merchantId }).then(data => {
            wx.hideLoading();
            let utilList = []
            if (data.clueList && data.clueList.length) {
                data.clueList.map(e => {
                    if (e.clueId == 1) {
                        let rescueTypeList = [
                            {
                                confId: 5,
                                name: '事故救援',
                                iconUrl: 'accident_rescue_icon',
                                sign: '免费'
                            },
                            {
                                confId: 3,
                                name: '送油',
                                iconUrl: 'send_oil_icon'
                            },
                            {
                                confId: 4,
                                name: '搭电',
                                iconUrl: 'pick_up_power_icon'
                            },
                            {
                                confId: 2,
                                name: '换胎',
                                iconUrl: 'trie_change_icon'
                            },
                            {
                                confId: 0,
                                name: '紧急脱困',
                                iconUrl: 'emergency_relief_icon',
                            },
                            {
                                confId: 1,
                                name: '拖车',
                                iconUrl: 'trailer_icon'
                            },
                            // {
                            //     confId: 6,
                            //     name: '找车位',
                            //     iconUrl: 'parking_icon',
                            //     url: '/packageEquity/pages/parking/index/index'
                            // },
                        ]
                        rescueTypeList.forEach(v => {
                            utilList.push({
                                ...v,
                                url: v.url ? v.url : '/packageEquity/pages/road/index/index'
                            })
                        })
                    }
                })
            }

            this.setData({
                utilList
            })
        })
    },
    getAllMerchantList() {
        const {
            merchantId
        } = wx.p.storage.get('merchant_info')
        let para = {
            merchantId
        }
        wx.p.api.equityApi.getAllEquity(para).then(res => {
            const carList = res.carServiceList
            const equityList = res.goodsServiceList
            let tripMenu = []
            const needShowEquity = ['高德打车', '曹操出行']
            if (env == 'production') {
                equityList.forEach(el => {
                    if (el.goodsCategory == '交通出行') {
                        if (el.equityGoodsGroupDescDtos) {
                            el.equityGoodsGroupDescDtos.forEach(item => {
                                if (needShowEquity.includes(item.equityName))
                                    tripMenu.push({
                                        name: item.equityName,
                                        icon: item.equityIcon,
                                        ...item,
                                        sign: item.equityName == '高德打车' ? '10元券' : ''
                                    })
                            })
                        }
                    }
                })
            } else if (env == 'test' || env == 'beta') {
                equityList.forEach(el => {
                    if (el.equityGoodsGroupDescDtos) {
                        el.equityGoodsGroupDescDtos.forEach(item => {
                            tripMenu.push({
                                name: item.equityName,
                                icon: item.equityIcon,
                                ...item
                            })
                        })
                    }
                })
            }
            this.setData({
                tripMenu
            })
        })
    },

})