<!--
 * @Author: zouwenying
 * @Date: 2020-10-22 11:08:44
 * @LastEditTime: 2021-04-28 08:49:01
 * @LastEditors: zwy
 * @Description: In User Settings Edit
 * @FilePath: \vue-manage-system-master\src\views\system\dictionarys\index.vue
-->
<script src="../../../../../../WEB/WEB/userCenter/src/router/index.js"></script>
<template>
    <div class="main">
        <div>
            <div class="search">
                <el-input v-model="query.buildingName" placeholder="请输入楼栋名称" class="search-input" v-model.trim="mixins_query.keyWords"></el-input>
                <el-select v-model="query.communityName" placeholder="请选择社区名称">
                    <el-option label="清空" value=""></el-option>
                    <el-option v-for="(item,index) in communityList" :label="item.label" :value="item.id"></el-option>
                </el-select>
                <el-button type="primary" @click="mixins_search" class="search-btn" icon="el-icon-search">查询
                    <!-- <i class="iconfont">&#xe6fc;</i> -->
                </el-button>
                <template>
                    <el-tooltip
                            class="item"
                            effect="light"
                            placement="bottom"
                            content="导出"
                    >
              <span class="zoniot_font item el-fl-right" @click="exportExcel()"
              >&#xe66d;</span
              >
                    </el-tooltip>
                    <el-dropdown
                            type="primary"
                            @command="addCommand"
                            class="el-fl-right"
                    >
                        <span class="zoniot_font item el-fl-right">&#xe664;</span>
                        <el-dropdown-menu
                                slot="dropdown"
                                hide-on-click="false"
                                class="device-search-dropdown"
                        >
                            <el-dropdown-item command="add">单个添加</el-dropdown-item>
                            <el-dropdown-item command="batchAdd">
                                <div class="upload_div">
                                    <xk-upload
                                            class="upload_class"
                                            @callback="mixins_search"
                                            :params="{ importType: 7 }"
                                    >
                                        <span class="upload_text" slot="content">批量添加</span>
                                    </xk-upload>
                                </div>
                            </el-dropdown-item>
                            <el-dropdown-item command="template">下载模板</el-dropdown-item>
                        </el-dropdown-menu>
                    </el-dropdown>
                </template>
            </div>
            <div class="dictionarys-wrap">
                <zz-table
                        :cols="cols"
                        :settings="{ showCheckbox: true, showIndex: true, stripe: true }"
                        :loading="mixins_onQuery"
                        :data="mixins_list"
                        :pageset="mixins_pageset"
                        @page-change="pageChange"
                        @selection-change="selectionChange"
                >
                    <template slot-scope="scope" slot="opt">
                        <i @click="addOrEdit('edit', scope.index)" class="iconfont" style="color:#2787F1;margin-right:30px" v-txt-tip data-txt="编辑">&#xe645;</i>
                        <i @click="deleteOne(scope.row.id)"  class="iconfont" style="color:#FF7272" v-txt-tip data-txt="删除">&#xe63a;</i>
                    </template>
                </zz-table>
            </div>
        </div>
<!--        <addplan :userinfo='userinfo' v-if="showaddDialog" @close='showaddDialog = false'  @refresh='mixins_search'></addplan>-->
    </div>
</template>

<script>
import list from '@utils/list.js';
// import addplan from './pageJump/addoredit';
export default {
    mixins: [list],
    data() {
        return {
            communityList:[],//社区名称下拉列表
            query:{
                buildingName:'',//楼栋名称
                communityName:'',//社区名称
            },
            cols: [
                {
                    label: '所属社区',
                    prop: 'dictCode'
                },
                {
                    label: '楼栋名称',
                    prop: 'dictName'
                },
                {
                    label: '单元数',
                    prop: 'remark'
                },
                {
                    label: '楼栋类型',
                    prop: 'remark'
                },
                {
                    label: '建筑结构',
                    prop: 'remark'
                },
                {
                    label: '楼层',
                    prop: 'remark'
                },
                {
                    label: '楼栋用途',
                    prop: 'remark'
                },
                {
                    label: '建成日期',
                    prop: 'remark'
                },
                {
                    label: '验收日期',
                    prop: 'remark'
                },
                {
                    label: '建筑面积',
                    prop: 'remark'
                },
                {
                    label: '使用面积',
                    prop: 'remark'
                },
                {
                    label: '操作',
                    prop: 'opt',
                    slot: 'opt'
                }
            ],
            selectRow: [],
            // showaddDialog:false,
        };
    },
    components: {
        // addplan
        // viewDetail
    },
    methods: {
        //获取社区名称下拉列表
        communityNameList(){
            this.communityList=[];
            let onOption='';
            this.$http.get('/assets/community/list', {}).then((res) => {
                res.data.map(res=>{
                    onOption={
                        label:res.communityName,
                        id:res.id
                    }
                    this.communityList.push(onOption)
                })
            });
        },
        addCommand(command) {
            if (command === "add") {
                // this.showaddDialog=true
                this.$router.push('/buildingManagement/pageJump/addoredit')
                return;
            }
            if (command === "template") {
                // this.__exportExcel("/installPlan/plan/downTemplate");
                return;
            }
        },
        //批量删除
        deleteRow() {
            let ids = [];
            if (!this.selectRow.length) {
                this.$message.error('您尚未选择要删除的记录，请选择后再操作批量删除');
                return;
            }
            this.selectRow.forEach((v) => {
                ids.push(v.id);
            });
           this.$msgBox(`刪除楼栋`, '删除后将无法恢复，请问是否继续?')
                .then(() => {
                    this.$http.post('/dict/delete', ids).then(({ status, data, msg }) => {
                        if (0 === status) {
                            this.$message({
                                type: 'success',
                                message: '删除成功!'
                            });
                            this.mixins_search();
                        } else {
                            this.$message.error('删除失败!');
                        }
                    });
                })
                .catch(() => {
                });
        },
        //单个删除
        deleteOne(ids) {
            this.$msgBox(`刪除字典`, '删除后将无法恢复，请问是否继续?')
                .then(() => {
                    this.$http.post('/dict/delete', [ids]).then(({ status, data, msg }) => {
                        if (0 === status) {
                            this.$message({
                                type: 'success',
                                message: '删除成功!'
                            });
                            this.mixins_search();
                        } else {
                            this.$message.error('删除失败!');
                        }
                    });
                })
                .catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消删除'
                    });
                });
        },
        selectionChange(val) {
            this.selectRow = val;
        },
        mixins_search(){
            this.communityList()
        },
        //获取列表数据
        communityList(){
            let submitData={
                "pageNum": 1,
                "pageSize": 10
            }
            this.$http.post('/sc-community-web/assets/building/page', submitData).then((data) => {
                this.mixins_list=data.data.list;
                this.mixins_onQuery=false;
            }).catch(function () {

            });
        }
    },
    created() {
        this.communityNameList();
        this.communityList();
        this.mixins_dataUrl = '/dict/selectPage';
        this.mixins_query = {
            keyWords: ''
        };
        // this.mixins_search();
    }
};
</script>

<style lang="scss" scoped>
</style>
