common.js 8.52 KB
import USERAPI from '~/api/usersApi/index'
import environment from '~/utils/request/environment'
import ActivityApi from '~/api/activityApi/index'

const taskLoginAndRegister = (query, callBack) => {
    if (!query) return callBack && callBack()
    const options = { ...query, ...query.options }
    delete options.options
    console.log(options);
    if (options.merchantId) {
        const sessionId = wx.$storage.get('sessionId')
        if (!sessionId) {
            let para = {
                merchantId: options.merchantId,
                type: 1,
                pages: options.pages
            }
            let temp = encodeURIComponent(JSON.stringify(para))
            wx.navigateTo({
                url: '/packageStoreAssistant/packageAuth/pages/authentication/register/register?data=' + temp,
            });
        } else {
            const USERINFO = wx.$storage.get('userInfo')
            if (USERINFO.merchantId == options.merchantId) {
                USERAPI.checkSession().then(({
                    code
                }) => {
                    if (code == '0') {
                        callBack && callBack()
                    } else {
                        wx.$router.reLaunch('/packageStoreAssistant/packageAuth/pages/authentication/login/login', options)
                    }
                })
            } else {
                let para = {
                    merchantId: options.merchantId,
                    type: 1,
                    pages: options.pages
                }
                let temp = encodeURIComponent(JSON.stringify(para))
                wx.navigateTo({
                    url: '/packageStoreAssistant/packageAuth/pages/authentication/register/register?data=' + temp,
                });
            }
        }
    } else {
        callBack && callBack()
    }
}
const authAvatarAndNickName = () => {
    const {
        domain,
        index
    } = environment,
        redirectUrl = `${domain}/wx-oauth`,
        // redirectUrl = 'http://scrm.dev.glsx.com.cn/wx-oauth',
        // 嘀嘀虎服务 wxeb509497634291f1 ,glsxtest02 wx56bed167ad463f70
        appid = index == 1 || index == 2 ? 'wxeb509497634291f1' : 'wx56bed167ad463f70',
        wxUrl = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${encodeURIComponent(redirectUrl)}&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect`
    console.log(redirectUrl, appid)
    wx.navigateTo({
        url: `/pages/webView/webView?url=${encodeURIComponent(wxUrl)}`,
    })
}
const handlerMiss = (data, query, callBack) => {
    if (!data) return
    if (!query) return
    let { pageNum, orginList, serviceType, listName } = query
    data.list && data.list.forEach((val, index) => {
        val.tabType = serviceType
        val.isCollapse = true
        val.startTime = val.startTime.split(' ')[0]
        val.endTime = val.endTime.split(' ')[0]
        // 活动中/活动未开始默认展开第一条 数据处理
        // 处理不同模块的判断条件
        let condition = false
        let zc = val.activityStatus != 3 && index == 0 && pageNum == 1
        let zc_3 = val.activityStatus == 3 && index == 0 && pageNum == 1
        let pzj = val.activityStatus != 3 && index == 0
        let bussinessScene = 3
        if (serviceType == 0) {
            condition = zc
        } else {
            condition = pzj
            bussinessScene = 2
        }
        if (condition) {
            val.isloading = true
            ActivityApi.getActiveTaskList({ activityId: val.id, bussinessScene }, { isShowLoading: true }).then(res => {
                res.forEach(a => {
                    a.platformMerchantMissionResponseList &&
                        a.platformMerchantMissionResponseList.forEach(k => {
                            k.detailInfo = { activityId: val.id, imgUrlList: [] }
                            k.platformMerchantMissionMaterialResponseList &&
                                k.platformMerchantMissionMaterialResponseList.forEach(i => {
                                    // materialType 素材类型1文案 2图片 3视频 4专属链接
                                    if (i.materialType == 1) {
                                        // 文案
                                        k.detailInfo.textContent = i.materialContent
                                    }
                                    if (i.materialType == 2 || i.materialType == 3) {
                                        // 图片视频
                                        k.detailInfo.imgUrlList.push({
                                            url: i.materialContent,
                                            type: i.materialType == 2 ? 'image' : 'video'
                                        })
                                    }
                                    if (i.materialType == 4) {
                                        // 链接
                                        k.detailInfo.linkUrl = val.activityUrl
                                    }
                                })
                        })
                })
                val.isloading = false
                val.missionList = res
                val.newtaskCalenderList = calenderFilter(JSON.parse(JSON.stringify(val.missionList)) || [], 7)
                let d = new Date()
                let nowDate = (d.getMonth() + 1).toString().padStart(2, '0') + '月' + d.getDate().toString().padStart(2, '0') + '日'
                let ind = 0
                val.calenderActiveIndex = 0
                val.newtaskCalenderList.forEach((v, index) => {
                    v.forEach(k => {
                        k.time = (new Date(k.activityTime).getMonth() + 1).toString().padStart(2, '0') + '月' + new Date(k.activityTime).getDate().toString().padStart(2, '0') + '日'
                        k.ind = ind
                        let completeStatusNum = 0
                        k.platformMerchantMissionResponseList.forEach(i => {
                            if (i.completeStatus == 2) completeStatusNum++
                        })
                        if (nowDate == k.time) {
                            val.calenderActiveIndex = index
                            callBack && callBack({ activeDateIndex: ind })
                        }
                        // status 1过去日期任务全部完成 2过去日期任务有未完成的 3当前日期或未来日期
                        if (completeStatusNum == v.length && d.getTime() > new Date(`${k.activityTime.replace(/-/g, '/')} 23:59:59`).getTime()) {
                            k.status = 1
                        } else if (d.getTime() > new Date(`${k.activityTime.replace(/-/g, '/')} 23:59:59`).getTime()) {
                            k.status = 2
                        } else {
                            k.status = 3
                        }
                        ind++
                    })
                })
                val.isCollapse = false
                let itemVal = `${listName}[${index}]`
                callBack && callBack({ [itemVal]: val })
            }).catch(err => {
                console.log(err);
                val.isloading = false
            })
        } else if (zc_3 && serviceType == 0) {
            ActivityApi.getActivityEndInstallOrderList({ activityId: val.id }, { isShowLoading: true })
                .then(res => {
                    val.isCollapse = false
                    res.orderList &&
                        res.orderList.forEach(it => {
                            it.time = it.createdDate ? new Date(it.createdDate).format('yyyy-MM-dd hh:mm') : ''
                        })
                    val.orderList = res.orderList
                    val.orderTotal = res.orderTotal
                    val.reInstallContactsName = res.reInstallContactsName
                    val.reInstallContactsPhone = res.reInstallContactsPhone
                    let itemVal = `${listName}[${index}]`
                    callBack && callBack({ [itemVal]: val })
                })
                .catch(err => {
                    val.isloading = false
                })
        }
    })
    const RESULT = {
        [listName]: pageNum == 1 ? data.list : [...orginList, ...data.list],
        activeTrigger: false,
        total: data.total,
        noResult: pageNum == 1 ? (data.list.length ? false : true) : false
    }
    callBack && callBack(RESULT)
}
const calenderFilter = (arr, length) => {
    var _arr = []
    while (arr.length) {
        _arr.push(arr.splice(0, length))
    }
    return _arr
}
module.exports = {
    taskLoginAndRegister,
    authAvatarAndNickName,
    handlerMiss
}