export default {
    /**
     * 重新加载
     */
    indexNeedReload: (state) => {
        return state.indexNeedReload
    },

    /**
     * 重定位信息
     */
    reLocation: (state) => {
        return state.reLocation
    },

    /**
     * 当前城市是否改变
     */
    cityChange: (state, getters) => {
        let city = state.cityChange ? state.cityChange : getters.myLocation.city
        return city
    },

    /**
     * 个人定位信息
     */
    myLocation: (state) => {
        return state.myLocation
    },

    /**
     * 附近的位置信息
     */
    pois: (state) => {
        return state.pois
    },

    /**
     * 所有门店的数据信息
     */
    storeMap: (state) => {
        return state.storeMap
    },

    /**
     * 当前门店的sotreID
     */
    storeID: (state, getters) => {
        let storeID = getters.isMaterial && !getters.isPurchase ? [666666] :               // 物料
            (
                getters.queryStoreID ? [getters.queryStoreID] :          // 扫码
                    (
                        getters.isPurchase && getters.isMaterial ? [Number(getters.materialInfo.toStoreID)] :          // 批量
                            state.storeID   // 定位
                    )
            )
        return storeID
    },

    /**
     * 当前门店的信息
     */
    storeInfo: (state) => {
        return state.storeInfo
    },

    /**
     * 当前门店的减运信息
     */
    waybillSLG: state => {
        return state.waybillSLG
    },

    /**
     * 轮播图
     */
    bannerList: (state, getters) => {
        let bannerList = state.bannerList
        if (getters.StoreMap && getters.storeID.length > 0 && getters.StoreMap[getters.storeID[0]].item.banner) bannerList = getters.StoreMap[getters.storeID[0]].banner
        return bannerList
    },

    /**
     * 物料信息
     */
    materialInfo: (state) => {
        return state.materialInfo
    },

    /**
     * 来自哪的个门店
     */
    fromStoreID: (state, getters) => {
        return getters.materialInfo && getters.materialInfo.fromStoreID ? getters.materialInfo.fromStoreID : null
    },

    /**
     * 来自哪的个门店的信息
     */
    fromStoreInfo: (state) => {
        return state.materialInfo ? state.materialInfo.fromStoreInfo : null
    },

    /**
     * 公众号进入   品牌
     */
    brandID: (state) => {
        return state.brandID
    },

    /**
     * 推广码进入
     */
    promote: (state) => {
        return state.promote
    },

    /**
     * 是否为B2B模式
     */
    isB2B: (state) => {
        return state.storeInfo && state.storeInfo.stores && state.storeInfo.stores[0].brandID === 10 ? true : false
    },

    /**
     * 是否为果园
     */
    isGy: (state, getters) => {
        // return getters.materialInfo && getters.materialInfo.storeType === 'gy' ? true : false
        return state.isGy
    },

    /**
     * 扫码进入
     */
    queryStoreID: (state) => {
        // uni.setStorageSync('queryStoreID',state.queryStoreID)
        return Number(state.queryStoreID)
    },

    /**
     * 京西支付信息
     */
    jxPayInfo: (state) => {
        return state.jxPayInfo
    },

    /**
     * 热销商品
     */
    topGoods: (state) => {
        return state.topGoods || []
    },

    /**
     *---------------
     *是否为物料
     */
    isMaterial: (state) => {
        let flag = false

        // #ifdef MP-WEIXIN
        flag = state.materialInfo &&
            state.materialInfo.storeType &&
            state.materialInfo.fromStoreID &&
            state.materialInfo.storeID === '666666' ? true : false
        //  && !state.materialInfo.toStoreID
        // #endif

        return flag
    },

    /**
     * 是否为批量购买
     */
    isPurchase: (state) => {
        let flag = false

        // #ifdef MP-WEIXIN
        flag = state.materialInfo &&
            state.materialInfo.storeType &&
            state.materialInfo.fromStoreID &&
            state.materialInfo.toStoreID &&
            state.materialInfo.toStoreID !== '666666' ? true : false
        // #endif

        return flag
    },

    /**
     * 物料购买的类型 c4 gy
     */
    storeType: (state) => {
        let str = ''

        // #ifdef MP-WEIXIN
        str = state.materialInfo && state.materialInfo.storeType ? state.materialInfo.storeType : 'c4'
        // #endif

        return str
    },

    /**
     * 当前袋子的销量
     */
    preSaleCount: (state) => {
        return state.preSaleCount
    },

    /**
     * 能否够买物料
     */
    canBuy: (state, getters) => {
        return getters.isMaterial ? state.canBuy : true
    },

    /**
     * 禁止购买物料,需要弹框提示,联系运营
     */
    notBuyPackbag: (getters) => {
        const materialInfo = getters.materialInfo
        return materialInfo && materialInfo.packageSwitch === 1
    },

    /**
     * 袋子的skuid
     */
    bagSkuIDs: (state) => {
        return state.bagSkuIDs
    },

    /**
     * 总的袋子数和份数
     */
    totalBag: (state, getters, allState, allGetters) => {
        let total = 0

        // #ifdef MP-WEIXIN
        const carList = allGetters['cartPage/cartList']
        if (!carList) return
        total = carList.reduce((pre, next) => {
            if (state.bagSkuIDs.includes(next.id)) {
                return {
                    unitCount: pre.unitCount += next.count,
                    totalCount: pre.totalCount += next.specCount * next.count
                }
            } else {
                return pre
            }
        }, {
            unitCount: 0,
            totalCount: 0
        })
        // #endif

        return total
    },

    /**
     * 是否超出购买限制
     */
    bagOverload: (state, getters, allState, allGetters) => {
        let str = '未超出购买限制'
        const { preSaleCount, canBuy, bagSkuIDs } = state
        const { totalBag } = getters
        if (!canBuy) {
            str = '未满足申请条件'
        } else {
            if (preSaleCount === 0) {
                // 新门店，只能买一包袋子
                if (totalBag.unitCount > 1) str = '袋子已经超过可申请数量，继续增加会收取一定费用。'
            } else {
                // 按单量申请
                if (preSaleCount <= totalBag.totalCount) str = '袋子已经超过可申请数量，继续增加会收取一定费用。'
            }
        }
        return str
    },

    /**
     * 附近的门店列表
     */
    storeList:(state) => {
        return state.storeList
    },

    /**
     * 域名
     */
    dns:(state) => {
        return state.dns
    }
}