customgroupOps.vue 11.1 KB
<template>
    <div class="behavior-more-option behavior-test-option">
        <div class="opt-left">
            <!-- 广场 -->
            <div class="test-opt-mall">
                <el-select v-model="mallVal" class="mall-opt" filterable :placeholder="$t('pholder.shopSelect')" @change="chooseMall">
                    <el-option v-for="(item, index) in mallOpt" :label="item.name" :value="item.id" :key="item.value"></el-option>
                </el-select>
            </div>
            <!-- 监控点 -->
            <div class="test-opt-monitory">
                <el-select v-model="monitoryVal" filterable :placeholder="$t('pholder.site')" class="multipleClass mall-sel-box" multiple collapse-tags @change="chooseMonitory">
                    <!-- <el-option value="all" label="{{$t('allPages.all')}}">
                            <span class="custom-checkbox__input">
                                <span class="custom-checkbox__inner"></span>
                            </span>
                            <span style="padding-left: 5px;">{{$t('allPages.all')}}</span>
                        </el-option> -->
                    <div :class="isSelAll ? 'sel-all-box selected' : 'sel-all-box'" @click="selAllHandle">
                        <span class="custom-checkbox__input">
                            <span class="custom-checkbox__inner"></span>
                        </span>
                        <span style="padding-left: 5px;">{{$t('allPages.all')}}</span>
                    </div>
                    <el-option v-for="(item, index) in monitoryOpt" :label="item.name" :value="item.id" :key="item.value">
                        <span class="custom-checkbox__input">
                            <span class="custom-checkbox__inner"></span>
                        </span>
                        <span style="padding-left: 5px;">{{ item.name }}</span>
                    </el-option>

                </el-select>
            </div>
            <!-- 时间 -->
            <div class="test-opt-date">
                <span v-for="(item, index) in analyasisTime" :key="item.label" class="time-box" @click="timeHandle(item.value)">
                    <span :class="['time-btn', { 'active-time': item.value === activeTime }]">{{ i18n(item.label) }}</span>
                </span>
            </div> 
            <div class="test-opt-time">
                <el-date-picker class="date-input analysis-date-input" v-show="activeTime == 'day'" v-model="dayTime" type="date" :picker-options="pickerOptions1" format="yyyy-MM-dd" value-format="yyyy-MM-dd">
                </el-date-picker>
                <el-date-picker class="date-input analysis-date-input" v-show="activeTime == 'week'" v-model="weekTime" align="right" type="week" :format="datePickerFormatter('week')" size="mini" :placeholder="$t('pholder.week')" :picker-options="pickerOptions1">
                </el-date-picker>
                <el-date-picker class="date-input analysis-date-input" v-show="activeTime == 'month'" v-model="monthTime" align="right" type="month" :format="datePickerFormatter('month')" size="mini" :placeholder="$t('pholder.month')" :picker-options="pickerOptions1">
                </el-date-picker>
                <el-date-picker class="date-input analysis-date-input" v-show="activeTime == 'year'" v-model="yearTime" align="right" type="year" :format="datePickerFormatter('year')" size="mini" :placeholder="$t('pholder.year')" :picker-options="pickerOptions1">
                </el-date-picker>
                <el-date-picker class="time-opt time-opt-custom"  v-show="activeTime == 'custom'"  v-model="customTime" value-format="yyyy-MM-dd" align="right" type="daterange" size="mini" :picker-options="pickerOptions1" range-separator="-" :start-placeholder="$t('table.startTime')" :end-placeholder="$t('table.endTime')">
                </el-date-picker>
            </div>
        </div>
        <div class="opt-right">
            <el-button type="primary" class="primary-btn behavior-collapse-btn" size="samll" @click="clickHandle">{{$t('button.confirm')}}</el-button>
            <!-- <el-button class="reset-btn behavior-collapse-btn" size="samll" @click="resetRefresh">{{$t('button.reset')}}</el-button> -->
        </div>
    </div>
</template>

<script>
const analyasisTime = ['day', 'week', 'month', 'year', 'custom'].map(item => ({ label: item, value: item }))
// const analyasisTime = []
export default {
    // props: {
    //     pageSize: [Number, String]
    // },
    data() {
        return {
            date1: '',
            pickerOptions1: {
                disabledDate(time) {
                    return time.getTime() > Date.now();
                },
            },
            mallName: '',
            mallVal: '',
            mallOpt: [],
            monitoryVal: [],
            monitoryName: '',
            monitoryOpt: [],
            cameraVal: '',
            cameraOpt: [],
            typeVal: '',
            activeTime: 'day',
            analyasisTime,
            dayTime: '',
            weekTime: '',
            monthTime: '',
            yearTime: '',
            customTime: '',
            all_id: [],
            isAll: false,
            isSingle: false,
            arr: [],
            idArr: [],
            isSelAll: false,
        }
    },
    created() {
    },
    watch: {
        dayTime(val) {
            this.sessionDate('dayDate', val);
        },
        weekTime(val) {
            this.sessionDate('weekDate', val);
        },
        monthTime(val) {
            this.sessionDate('monthDate', val);
        },
        yearTime(val) {
            this.sessionDate('yearDate', val);
        },
        customTime(val) {
            this.sessionDate('customDate', val);
        }
    },
    mounted() {
        let {dayDate, weekDate, monthDate , yearDate, customDate} = this.createDate();
        this.dayTime = dayDate;
        this.weekTime = weekDate;
        this.monthTime = monthDate;
        this.yearTime = yearDate;
        this.customTime = customDate;
        this.getMallList();
    },
    methods: {
        i18n(label){
          let langaugeLabel = 'asisTab.' + label
          return this.$t(langaugeLabel)
        },
        timeHandle(val) {
            this.activeTime = val
        },
        getMallList() {
            this.mallOpt = [];
            this.mallVal = '';
            this.mallName = '';
            this.getCommonMalls().then(resolveData => {
                let {mallData,localMallId,titleName,multiMallId} = resolveData;
                this.mallOpt = mallData;
                this.mallVal =  localMallId;
                this.mallName = titleName;
                this.getGates(this.mallVal);
            },(rejectData) => {
            })
        },
        chooseMall() {
            this.mallName = this.behaviorMallChange(this.mallVal,this.mallOpt,true);
            this.getGates(this.mallVal);
        },
        getGates(mallId) {
            this.monitoryOpt = [];
            this.monitoryVal = [];
            this.monitoryName = '';
            this.isSelAll = false;
            this.$api.base.gate({
                mallId: mallId,
                status: 1,
                isHasFace: 1,
                // _t: Date.parse(new Date()) / 1000
                // isMallGate: 1
            })
                .then(res => {
                    let result = res.data.data
                    if (result.length) {
                        this.len = result.length
                        // result.forEach((item, index, arr) => {
                        //     // this.monitoryOpt.push(item);
                        //     this.all_id.push(item.id)
                        // });
                        this.monitoryOpt = result;
                        this.arr = [result[0].id];
                        // this.idArr = [result[0].id];
                        this.monitoryVal.push(result[0].id);
                        this.isSelAll = this.monitoryVal.length == this.monitoryOpt.length ? true : false;
                        this.monitoryName = result[0].name;
                        this.clickHandle();
                    }
                })
                .catch(err => { })
        },
        chooseMonitory() {
            this.isSelAll = this.isSelAll ?
                (this.monitoryVal.length < this.monitoryOpt.length ? false : true) :
                this.monitoryVal.length < this.monitoryOpt.length ? false : true;
        },
        selAllHandle() {
            if (this.isSelAll) {
                this.isSelAll = false;
                if (this.monitoryVal.length == this.monitoryOpt.length) {
                    this.monitoryVal = [];
                }
            } else {
                this.isSelAll = true;
                if (this.monitoryVal.length == this.monitoryOpt.length) {
                    this.monitoryVal = [];
                } else {
                    this.monitoryVal = [];
                    this.monitoryOpt.forEach(item => {
                        this.monitoryVal.push(item.id);
                    })
                }
            }
        },
        clickHandle() {
            this.$emit('startLoading', 'customgroup');
            let repTit = ''
            this.monitoryName = '';
            if (this.monitoryVal.length == 1) {
                this.monitoryOpt.forEach(item => {
                    if (item.id == this.monitoryVal[0]) {
                        this.monitoryName = item.name;
                    }
                })
                repTit = this.mallName ? this.mallName + '-' + this.monitoryName : this.monitoryName;
            }else{
                repTit = this.mallName
            }
            let orgIds = '';
            this.monitoryVal.forEach((item, index, arr) => {
                orgIds += item + ','
            })
            orgIds = orgIds.substring(0, orgIds.length - 1);
            let { startTime, endTime } = this.newDateFormat(this.activeTime,this[this.activeTime + 'Time']);
            if (this.activeTime === 'day') {
              startTime = startTime + ' 00:00:00';
              endTime = endTime + ' 23:59:59';
            }
            let params = {
                orgIds: orgIds,
                startDate: startTime,
                endDate: endTime,
                title: repTit + ' ' + startTime.split(' ')[0] + ' '
            }
            this.$emit('emitParams', params);
        }
    }
}
</script>

<style scoped>
    .test-opt-date {
        float: left;
        font-size: 12px;
        margin-right: 20px;
    }
    @media only screen and (max-width: 1680px) {
        .test-opt-time .time-opt {
            width: 136px;
        }
        .test-opt-monitory {
            width: 160px;
        }
    }
    @media only screen and (max-width: 1440px) {
        .test-opt-time .time-opt {
            width: 136px;
        }
        .test-opt-monitory {
            width: 160px;
        }
    }
    @media only screen and (max-width: 1366px) {
        .test-opt-time .time-opt {
            width: 136px;
        }
        .test-opt-monitory {
            width: 160px;
        }
    }
    @media only screen and (max-width: 1280px) {
        .test-opt-time .time-opt {
            width: 136px;
        }
        .test-opt-monitory {
            width: 160px;
        }
    }
</style>