marketingGroup.js 11.7 KB
import * as dayjs from "dayjs";

export default {
    data() {
        return {
            selectSenderList: null,
            groupNumber: 0,
            viewLoading: false,
            staffCloudIdListStr: '',
            isUpdate: true,
            dateOptions: {
                disabledDate(time) {
                    let now = new Date()
                    now.setTime(now.getTime() - 3600 * 1000 * 24)
                    return time.getTime() < now
                }
            },
            timeOptions: {
                selectableRange: '00:00:00 - 23:59:59'
            },
        }
    },
    watch: {
        basicForm: {
            handler(val) {
                if (this.firstFlag) {
                    this.firstFlag = false
                } else {
                    this.editStatus = true
                }
            },
            deep: true
        },
        'basicForm.selectType'(newVal, oldVal) {
            if (oldVal == 2 || newVal == 2) {
                this.basicForm.userList = []
                this.selectData = []
                this.basicForm.crowdList = []
                this.$refs.selectLabel.labelTreeRetSelect = []
            }
        },
        'staffCloudIdListStr'(newVal, oldVal) {
            this.basicForm.customerList = newVal == oldVal ? this.basicForm.customerList : []
        },
    },
    methods: {
        getCustomerData(val) {
            this.basicForm.customerList = val
        },
        selectSender(list) {
            this.selectSenderList = list
            this.basicForm.staffCloudIdList.push(list.staffCloudIdList)
            let staffCloudIdList = this.basicForm.staffCloudIdList
            this.staffCloudIdListStr = staffCloudIdList && staffCloudIdList.at(-1).toString()
        },
        // 客户筛选弹窗
        selectCustomer() {
            this.isUpdate = true
            const {staffCloudIdList, customerList} = this.basicForm
            if (staffCloudIdList.length == 0) {
                return this.$message({
                    type: 'error',
                    message: '请选择发送人'
                })
            }
            this.$refs.selectCustomer.init(customerList, this.staffCloudIdListStr)
        },
        // 返回
        handleCancel(path) {
            if (this.editStatus || this.$refs.welcome.previewList.length > 0) {
                this.$confirm('当前有内容信息未保存,是否继续返回?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                })
                    .then(() => {
                        this.$router.push(path)
                    })
                    .catch(() => {
                    })
            } else {
                this.$router.push(path)
            }
        },
        // 选择客户change事件
        radioChange(val) {
            this.isSelectCrowd = false
            this.isUpdate = true
            this.tagging = []
            this.taggingList = []
        },
        // 打开标签筛选
        openLabel(merchant) {
            if (!this.basicForm[merchant]) {
                this.$message({
                    type: 'error',
                    message: '请先选择门店'
                })
                return
            }
            this.dialogVisible = !this.dialogVisible
            this.$refs.selectLabel.init(this.tagging)
        },
        selectChange(val) {
            // 选择门店时,替换欢迎语组件当中的所有merchantId
            this.btnList.forEach(item => {
                if (item.params && item.params.hasOwnProperty('merchant')) {
                    item.params.merchant = val
                }
                if (item.funParams && Object.prototype.toString.call(item.funParams) === '[object Array]') {
                    item.funParams.forEach(funArr => {
                        if (funArr.params && funArr.params.hasOwnProperty('merchantId')) {
                            funArr.params.merchantId = val
                        }
                        if (funArr.merchantOpen && funArr.merchantOpen.params && funArr.merchantOpen.params.hasOwnProperty('merchantId')) {
                            funArr.merchantOpen.params.merchantId = val
                        }
                    })
                }
            })
            this.tagging = []
            this.taggingList = []
            this.basicForm.crowdList = []
            this.$refs.selectLabel.labelTreeRetSelect = []
            this.isUpdate = true
            this.resetMerchantId = val
            this.msgMerchantName = val && this.dataItems.find(item => item.msgMerchantId == val).msgMerchantName
            // this.optionsMe
        },
        handleSelect(val) {
            this.isUpdate = true
            this.tagging = val
            let arr = []
            this.tagging.forEach(item => {
                item.labelList.forEach(tag => {
                    arr.push({
                        groupId: item.labelGroup.id,
                        groupName: item.labelGroup.name,
                        labelId: tag.id,
                        labelName: tag.name,
                        groupType: item.labelType
                    })
                })
            })
            this.taggingList = arr
        },
        // 删除标签
        removeTag(tag, idx1, idx) {
            tag.labelList.splice(idx1, 1)
            if (tag.labelList.length == 0) {
                this.tagging.splice(idx, 1)
            }
            let arr = []
            this.tagging.forEach(item => {
                item.labelList.forEach(tag => {
                    arr.push({
                        groupId: item.labelGroup.id,
                        groupName: item.labelGroup.name,
                        labelId: tag.id,
                        labelName: tag.name,
                        groupType: item.labelType
                    })
                })
            })
            this.taggingList = arr
            this.isUpdate = true
        },
        async getTheNumberOfPeople(params) {
            await this.$apis.wechatGroup
                .batchmessagingCustomercount(params)
                .then(res => {
                    this.groupNumber = res
                })
                .catch(err => {
                    this.viewLoading = false
                    this.groupNumber = 0
                    this.isUpdate = false
                })
        },
        // 查看群发人数
        async viewMembers(managedType) {
            if (managedType == 1) {
                if (this.basicForm.selectType == '1' && !this.taggingList.length) {
                    return this.$message({
                        type: 'error',
                        message: '请选择标签'
                    })
                }
                if (this.basicForm.selectType == 2 && !this.basicForm.crowdList.length) {
                    return this.$message({
                        type: 'error',
                        message: '请选择人群'
                    })
                }
                let params = this.getBaseInfo(managedType)
                this.viewLoading = true
                await this.getTheNumberOfPeople(params)
                this.isUpdate = false
                this.viewLoading = false
            }
            if (managedType == 2) {
                this.groupNumber = this.basicForm.customerList.length
                this.isUpdate = false
            }
        },
        // 发送时间change事件
        changeValue(v) {
            const date = new Date(v).getTime()
            if (date < Date.now()) {
                this.timeOptions = {
                    selectableRange: `${dayjs()
                        .add(1, 'm')
                        .format('HH:mm')}:00 - 23:59:59`
                }
            } else {
                this.timeOptions = {
                    selectableRange: '00:00:00 - 23:59:59'
                }
            }
        },
        getBaseInfo(managedType) {
            let params = {}
            if (managedType == 1) {
                params = {
                    customerType: this.basicForm.selectType,
                    msgName: this.basicForm.groupName,
                    msgMerchantId: this.basicForm.selectStore ? this.basicForm.selectStore : this.basicForm.taskMerchantId,
                    msgMerchantName: this.msgMerchantName
                }
                const combineType = {
                    label: 2,
                    crowd: 1
                }
                if (params.customerType == 1) {
                    params.combineType = combineType.label
                    params.labelList = this.taggingList
                } else if (params.customerType == 2) {
                    params.crowdList = this.basicForm.crowdList
                    params.combineType = combineType.crowd
                }
            }
            if (managedType == 2) {
                let customerCloudIdList = []
                let staffCloudIdList = []
                this.basicForm.customerList.forEach(item => {
                    customerCloudIdList.push(item.userId)
                })
                staffCloudIdList.push(this.basicForm.staffCloudIdList[0])
                params = {
                    customerType: 3,
                    msgName: this.basicForm.groupName,
                    staffCloudIdList,
                    customerCloudIdList
                }
            }
            return params
        },
        // 人群筛选弹窗
        selectCrowd(merchant) {
            if (!this.basicForm[merchant]) {
                this.$message({
                    type: 'error',
                    message: '请先选择门店'
                })
                return
            }
            this.$refs.selectCrowd.init(this.basicForm.crowdList)
        },
        delSelectSenderList(){
            this.basicForm.staffCloudIdList = [] //发送人
            this.selectSenderList = []
            this.$refs.selectEmpForm.selectId = ''
        },
        // getCustomerData(val) {
        //     console.log(val)
        //     this.isUpdate = true
        //     if (val.length) {
        //         this.isSelectCustomer = true
        //         this.basicForm.customerList = val
        //     } else {
        //         this.basicForm.userList = []
        //         this.basicForm.customerList = []
        //         this.selectData = []
        //         this.isSelectCustomer = false
        //         this.editStatus = true
        //         this.key = new Date()
        //     }
        // },
        // 获取人群数据(根据人群筛选获取群发账号人群数据)
        getCrowdData(val) {
            this.isUpdate = true
            if (val.length) {
                this.isSelectCrowd = true
                this.basicForm.crowdList = val
            } else {
                this.basicForm.userList = []
                this.basicForm.crowdList = []
                this.selectData = []
                this.isSelectCrowd = false
                this.editStatus = true
                this.key = new Date()
            }
        },
        // 删除人群筛选标签
        removeCrowd(item, index) {
            this.basicForm.crowdList.splice(index, 1)
            this.getCrowdData(this.basicForm.crowdList)
            if (!this.basicForm.crowdList.length) {
                this.basicForm.userList = []
                this.selectData = this.basicForm.userList
                this.isUpdate = true
                this.isSelectCrowd = false
            }
            this.key = new Date()
        },
        removeCustomer(item, index) {
            this.basicForm.customerList.splice(index, 1)
            this.getCustomerData(this.basicForm.customerList)
            this.key = new Date()
            this.isUpdate = true
        },
    }
}