record.vue 10.3 KB
<template>
    <div>
        <el-row class="manage-head-wrapper">
            <el-col :xs="24" :sm="24">
                <div class="manage-select-box">
                    <el-select v-model="queryForm.mallId" filterable :placeholder="$t('pholder.select')" @change="mallChange">
                        <el-option :label="$t('pholder.all')" value=""></el-option>
                        <el-option v-for="item in mallListForTerm" :key="item.id" :label="item.name" :value="item.id" />
                    </el-select>
                </div>
                <div class="manage-select-box">
                    <el-date-picker v-model="queryForm.timeVal" type="daterange" range-separator="至" size='small' start-placeholder="开始日期" end-placeholder="结束日期">
                    </el-date-picker>
                </div>
                <el-button type="primary" class="search-btn" @click="searchFun">{{$t('button.search')}}</el-button>
                <el-button type="primary" class="search-btn manage-add-btn" @click="exportFun">{{$t('button.export')}}</el-button>
                <el-button type="primary" class="search-btn manage-add-btn" @click="addFun">{{$t('button.addRecord')}}</el-button>
            </el-col>
        </el-row>
        <el-row class="manage-content">
            <el-col :span="24">
                <el-table ref="row_table" class="gate-table" :data="tableData" :max-height="tableHeight" style="width: 100%" header-row-class-name="manage-tab-head">
                    <el-table-column prop="order" :label="$t('table.order')" align="center" width="100"></el-table-column>
                    <el-table-column prop="mallName" :label="$t('table.squareName')" align="center"></el-table-column>
                    <el-table-column prop="patrolMethodStr" :label="$t('table.patroMode')"  align="center"></el-table-column>
                   <!-- <el-table-column prop="customerContact" :label="$t('table.customerContact')"  align="center"></el-table-column>
                    <el-table-column prop="customerPhone" :label="$t('table.contactInformation')" align="center"></el-table-column> -->
                    <el-table-column prop="poeStatus" :label="$t('table.poeStatus')" align="center"></el-table-column>
                    <el-table-column prop="cameraStatus" :label="$t('table.machineStatus')" align="center"></el-table-column>
                    <el-table-column prop="createByStr" :label="$t('table.inspector')" align="center"></el-table-column>
                    <el-table-column prop="createTime" :label="$t('table.patrolTime')" align="center"></el-table-column>
                    <el-table-column prop="remark" :label="$t('dialog.note')"  align="center" show-overflow-tooltip></el-table-column>
                    <el-table-column :label="$t('table.operate')" align="center" width="150">
                        <template slot-scope="scope">
                            <el-button type="text" size="small" class="tab-btn" @click="editHandle(scope.row)">{{$t('button.edit')}}</el-button>
                            <el-button type="text" size="small" class="tab-btn" @click="delHandle(scope.row)">{{$t('button.delete')}}</el-button>
                        </template>
                    </el-table-column>
                </el-table>
                <el-pagination class="manage-pagination-box" background :current-page="currentPage" :page-sizes="[10, 20, 50, 100]" :page-size="pageSize" @size-change="sizeChange" @current-change="cerrentChange" layout="sizes, prev, pager, next, slot" :total="total">
                    <span class="slot-ele-total">{{$t('table.pageHead')}} {{ total }} {{$t('table.pageTail')}}</span>
                </el-pagination>
            </el-col>
        </el-row>
        <addDialog ref="addModel"></addDialog>
    </div>
</template>

<script>
    import moment from 'moment'
    import addDialog from './add.vue'
    export default {
        props: ['groupMallId', 'endDate', 'startDate'],
        components:{
          addDialog  
        },
        data() {
            return {
                mallListForTerm: [],
                tableData: [],
                total: 0,
                pageSize: 10,
                currentPage: 1,
                queryForm: {
                    mallId: '',
                    timeVal: [moment().subtract(30, 'days').format('YYYY-MM-DD'), moment().format('YYYY-MM-DD')]
                }
            };
        },
        mounted() {
            if (this.startDate) {
                this.queryForm.timeVal = [this.startDate, this.endDate]
            }else{
                this.queryForm.timeVal = [moment().subtract(30, 'days').format('YYYY-MM-DD'), moment().format('YYYY-MM-DD')]
            }

            this.getMallListForTerm()
        },
        computed: {
            tableHeight() {
                const windowInnerHeight = window.innerHeight;
                return windowInnerHeight - windowInnerHeight * 0.24;
            }
        },
        methods: {
            getMallListForTerm() {
                this.mallListForTerm = [];
                this.queryForm.mallId = "";
                this.$api.base.mall({
                    accountId: this.$cookie.get('accountId')
                }).then(data => {
                    let result = data.data;
                    if (result.data.length) {
                        if (this.groupMallId) {
                            this.queryForm.mallId = this.groupMallId;
                        } else {
                            if (this.getSessionLocal("mallId")) {
                                this.queryForm.mallId = Number(this.getSessionLocal("mallId"));
                            } else {
                                this.queryForm.mallId = '';
                            }
                        }
                        this.mallListForTerm = result.data;
                    }
                    this.getTableData();
                })
            },
            mallChange() {
                this.setSessionLocal("mallId", this.queryForm.mallId);
                this.getTableData();
            },
            getTableData() {
                if (!this.queryForm.timeVal) {
                    this.$message({
                        message: '请选择时间范围',
                        type: 'warning'
                    });
                    return
                }
                let tabelParams = {
                    pageNum: this.currentPage,
                    pageSize: this.pageSize,
                    accountId: this.$cookie.get('accountId'),
                    mallId: this.queryForm.mallId,
                    startDate: moment(this.queryForm.timeVal[0]).format('YYYY-MM-DD'),
                    endDate: moment(this.queryForm.timeVal[1]).format('YYYY-MM-DD'),
                };
                Object.keys(tabelParams).map(key => (!tabelParams[key] ? delete tabelParams[key] : ''));
                this.$api.management.getPatrolList(tabelParams, null, true).then(data => {
                    this.tableData = [];
                    var result = data.data;
                    if (result.code == 200) {
                        if (result.data.list && result.data.list.length) {
                            result.data.list.forEach((item, index) => {
                                item.order = (this.currentPage - 1) * this.pageSize + index + 1;
                            });
                        }
                        this.tableData = result.data.list;
                        this.total = result.data.total;
                    }
                })
            },
            sizeChange(val) {
                this.pageSize = val;
                this.getTableData();
            },
            cerrentChange(val) {
                if (this.currentPage != val) {
                    this.currentPage = val;
                    this.getTableData();
                }
            },
            addFun(){
                this.$refs.addModel.dialogInit(this.queryForm.mallId,'add');
            },
            editHandle(row){
                this.$refs.addModel.dialogInit(this.queryForm.mallId,'edit',row);
            },
            delHandle(row){
                this.$confirm(this.$t("message.confirDelete"), this.$t("button.delete"), {
                    confirmButtonText: this.$t("message.confirm"),
                    cancelButtonText: this.$t("message.cancel"),
                    type: "warning"
                }).then(() => {
                    this.$api.management.delPatrol(row.id).then(res => {
                        if(res.data.code==200){
                            this.$message({
                                showClose: true,
                                type: "success",
                                message: this.$t("message.deleteSuccess")
                            });
                            this.getTableData();
                        }else{
                            this.$message({
                                showClose: true,
                                type: "error",
                                message: res.data.msg
                            });
                        }
                    })
                })
            },
            exportFun() {
                let parameter = {
                    accountId: this.$cookie.get('accountId'),
                    mallIds: this.queryForm.mallId,
                    startDate: moment(this.queryForm.timeVal[0]).format('YYYY-MM-DD'),
                    endDate: moment(this.queryForm.timeVal[1]).format('YYYY-MM-DD'),
                };
                let Url = window._vionConfig.apiUrl + "/b-mall-patrol/list/export?";
                let dowloadUrl = `${Url}accountId=${parameter.accountId}&mallId=${parameter.mallIds}&patrolType=1&startDate=${parameter.startDate}&endDate=${parameter.endDate}&authorization=${this.$cookie.get("atoken")}`
                window.open(dowloadUrl);
            },
            searchFun() {
                this.currentPage = 1;
                this.getTableData();
            }
        }
    };
</script>

<style scoped="scoped" lang="less">
    .manage-head-wrapper {
        padding-top: 0;
    }
    .gate-table{
        /deep/.cell{
            text-overflow: ellipsis !important;
        }
    }
    .manage-select-box {
        /deep/.el-date-editor.el-input__inner {
            width: 230px;
        }

        /deep/.el-select {
            width: 200px;
        }
    }
</style>