
<template>
    <!-- 详情页面 -->
    <div class='gdqd-dialog'>
        <div class='top'></div>
        <div class='gdqd-dialog-top'>
            <el-input
                placeholder='搜索设备简称编号'
                style='width:192px;margin-right:12px'
                size='small'
                prefix-icon='el-icon-search'
                v-model='sbjc'
                clearable
                @blur='queryTableList'
            ></el-input>
            <Select v-model='sbglgs' width='180' tipPlace='top' caption='管理归属' size='small' :selectdata='sbglgsOption' @change='queryTableList'></Select>
            <Select
                width='146'
                style='margin: 0 12px;'
                v-model='status'
                tipPlace='top'
                caption='设备状态'
                size='small'
                :selectdata='statusOption'
                @change='queryTableList'
            ></Select>
            <el-input
                placeholder='搜索品牌、型号'
                style='width:192px;margin-right:12px'
                size='small'
                clearable
                prefix-icon='el-icon-search'
                v-model='brand'
                @blur='queryTableList'
            ></el-input>
            <Select
                width='120'
                style='margin-right:12px;'
                v-model='floor'
                tipPlace='top'
                caption='楼层：'
                size='small'
                :selectdata='floorSelect'
                @change='queryTableList'
            ></Select>
            <el-input placeholder='搜索安装位置' clearable style='width:192px;margin-right:12px' size='small' prefix-icon='el-icon-search' v-model='wzjc'></el-input>
            <!-- 多余的筛选 -->
            <input-dialog :type='1' @confirm='confirm'></input-dialog>
        </div>
        <el-table :data='tableData' :border='true' style='width: 100%;amrgin-bottom:30px'>
            <el-table-column type='index' label='序号' width='80'></el-table-column>
            <el-table-column prop='sbjc' label='设备名称' show-overflow-tooltip resizable>
                <template slot-scope='{row}'>{{row.sbjc || '--'}}</template>
            </el-table-column>
            <el-table-column prop='assetnum' label='设备编号' show-overflow-tooltip resizable>
                <template slot-scope='{row}'>{{row.assetnum || '--'}}</template>
            </el-table-column>
            <el-table-column prop='sl' label='数量'>
                <template slot-scope='{row}'>{{row.sl || '--'}}</template>
            </el-table-column>
            <el-table-column prop='sbglgs' label='管理归属' show-overflow-tooltip resizable>
                <template slot-scope='{row}'>{{row.sbglgs || '--'}}</template>
            </el-table-column>
            <el-table-column prop='sb_status' label='设备状态'>
                <template slot-scope='{row}'>{{row.sb_status || '--'}}</template>
            </el-table-column>
            <el-table-column prop='brand' label='品牌' show-overflow-tooltip resizable>
                <template slot-scope='{row}'>{{row.brand || '--'}}</template>
            </el-table-column>
            <el-table-column prop='sbxh' label='型号' show-overflow-tooltip resizable>
                <template slot-scope='{row}'>{{row.sbxh || '--'}}</template>
            </el-table-column>
            <el-table-column prop='floor' sortable label='楼层'>
                <template slot-scope='{row}'>{{row.floor || '--'}}</template>
            </el-table-column>
            <el-table-column prop='wzjc' label='安装位置' show-overflow-tooltip resizable>
                <template slot-scope='{row}'>{{row.wzjc || '--'}}</template>
            </el-table-column>
            <el-table-column prop='manufacturer' label='生产厂商' show-overflow-tooltip resizable>
                <template slot-scope='{row}'>{{row.manufacturer || '--'}}</template>
            </el-table-column>
            <el-table-column prop='fws' label='服务商' show-overflow-tooltip resizable>
                <template slot-scope='{row}'>{{row.fws || '--'}}</template>
            </el-table-column>
        </el-table>
        <div class='foot'>
            <el-pagination
                background
                layout='prev, pager, next'
                :total='total'
                :page-size='size'
                @prev-click='pageChanged'
                @next-click='pageChanged'
                @current-change='pageChanged'
            ></el-pagination>
        </div>
    </div>
</template>
<script>
import Select from '@/components/Select/Select.vue'
import { mapGetters } from 'vuex'
import { queryAsset } from '@/api/equipmentList.js'
import { querySelect } from '@/api/public.js'
import inputDialog from './inputDIalog'
export default {
    data() {
        return {
            tableData: [],
            dataSelect2: [
                { id: 'test1', name: '选择项' },
                { id: 'test2', name: '单平米' },
                { id: 'test3', name: '下级分项' },
                { id: 'test4', name: '滑动平均滑动平均' }
            ],
            page: 1,
            size: 10,
            total: 1,
            sbjc: '',
            brand: '',
            wzjc: '',
            floor: '',
            status: '',
            manufacturer: '',
            fws: '',
            sbglgs: '',
            sbglgsOption: [],
            statusOption: []
        }
    },
    components: {
        Select,
        inputDialog
    },
    computed: {
        ...mapGetters(['floorSelect'])
    },
    props: ['row', 'major'],
    mounted() {
        this.queryTableList()
        this.tabFind()
    },
    methods: {
        //多余输入框监听
        confirm(fws, manufacturer) {
            console.log(fws, manufacturer, '------')
            this.fws = fws
            this.manufacturer = manufacturer
            this.queryTableList()
        },
        //下拉框查询
        tabFind() {
            let postParams = [
                {
                    columnName: { sbglgs: 'sbglgs', sb_status: 'sb_status' },
                    params: {
                        type_code: this.row.type_code
                    },
                    tableName: 'glsms_asset' //视图名称
                }
            ]
            let major
            if (this.major.slice(0, 2) == 'GD') {
                major = '供电'
            } else if (this.major.slice(0, 2) == 'XF') {
                major = '消防'
            } else if (this.major.slice(0, 2) == 'GPS') {
                major = '给排水'
            } else if (this.major.slice(0, 2) == 'DT') {
                major = '电梯'
            } else if (this.major.slice(0, 2) == 'RQ') {
                major = '燃气'
            } else {
                major = this.major
            }
            let data = {
                major: major,
                plazaId: this.$store.state.plazaId
            }
            querySelect({ data, postParams }).then(res => {
                console.log(res)
                let sb_status = res.data.data.glsms_asset.sb_status
                let sbglgs = res.data.data.glsms_asset.sbglgs
                this.sbglgsOption = []
                this.statusOption = []
                sb_status.forEach(el => {
                    this.statusOption.push({
                        name: el.value,
                        id: el.key
                    })
                })
                sbglgs.forEach(el => {
                    this.sbglgsOption.push({
                        name: el.value,
                        id: el.key
                    })
                })
            })
        },
        pageChanged(page) {
            this.page = page
            this.queryTableList()
        },
        queryTableList() {
            let major
            if (this.major.slice(0, 2) == 'GD') {
                major = '供电'
            } else if (this.major.slice(0, 2) == 'XF') {
                major = '消防'
            } else if (this.major.slice(0, 2) == 'GPS') {
                major = '给排水'
            } else if (this.major.slice(0, 2) == 'DT') {
                major = '电梯'
            } else if (this.major.slice(0, 2) == 'RQ') {
                major = '燃气'
            } else {
                major = this.major
            }
            let data = {
                major: major,
                plazaId: this.$store.state.plazaId,
                page: this.page,
                size: this.size
            }
            //输入框搜索
            data.keyword = ''
            if (this.sbjc) {
                data.keyword += `${this.sbglgs}:sbjc,assetnum;`
            }
            if (this.brand) {
                data.keyword += `${this.brand}:brand,sbxh;`
            }
            if (this.wzjc) {
                data.keyword += `${this.wzjc}:wzjc;`
            }
            if (this.manufacturer) {
                data.keyword += `${this.manufacturer}:manufacturer;`
            }
            if (this.fws) {
                data.keyword += `${this.fws}:fws;`
            }
            if (data.keyword == '') {
                delete data.keyword
            }
            let postParams = {
                type_code: this.row.type_code
                // manufacturer: this.row.manufacturer,
                // sbxh: this.row.sbxh,
                // // floor: '--',
                // brand: '--'
            }
            //下拉筛选
            if (this.floor) {
                postParams.floor = this.floor
            }
            if (this.sbglgs) {
                postParams.sbglgs = this.sbglgs
            }
            if (this.status) {
                postParams.status = this.status
            }
            queryAsset({ data, postParams }).then(res => {
                console.log(res)
                this.tableData = res.data.data
                this.total = res.data.count
            })
        }
    },
    watch: {
        'row.type_code': {
            handler(newV, oldV) {
                if (newV != oldV) {
                    this.queryTableList()
                    this.tabFind()
                }
            },
            deep: true
        }
    }
}
</script>
<style lang="less" scoped>
.gdqd-dialog {
    padding: 16px 24px 40px;
    height: 610px;
    .gdqd-dialog-top {
        display: flex;
        margin-bottom: 12px;
    }
    td {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    .foot {
        height: 32px;
        display: flex;
        justify-content: flex-end;
        margin-top: 28px;
    }
}
</style>
<style lang="less">
</style>