<template>
<div class="EnseList">
    <el-row class="topBar">
        <el-col>
            <el-form :inline="true" :model="searchData">
                <el-form-item label="">
                    <el-select v-model="searchData.materialType" placeholder="请选择资源类型">
                        <el-option label="救援物资" value="救援物资"></el-option>
                        <el-option label="专家资源" value="专家资源"></el-option>
                        <el-option label="救援队伍" value="救援队伍"></el-option>
                        <el-option label="避难场所" value="避难场所"></el-option>
                        <el-option label="防护目标" value="防护目标"></el-option>
                        <el-option label="医疗卫生单位" value="医疗卫生单位"></el-option>
                        <el-option label="通信保障机构" value="通信保障机构"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="">
                    <el-input v-model="searchData.materialName" placeholder="请输入资源名称"></el-input>
                </el-form-item>

                <el-form-item>
                    <el-button type="primary" @click="searchFun()">
                        <i class="el-icon-search"></i> 搜索
                    </el-button>
                    <el-button type="primary" @click="resetFun()">
                        <i class="el-icon-refresh"></i> 重置
                    </el-button>
                </el-form-item>
                <el-form-item class="fr">
                    <el-button plain type="primary" @click="addFun()">
                        <i class="el-icon-plus"></i> 新增资源
                    </el-button>
                </el-form-item>
            </el-form>
        </el-col>
    </el-row>
    <el-table :data="tableData.pageData" stripe border style="width:100%;" :loading="loading">
        <el-table-column width="50" type="index" label="序号"></el-table-column>
		<el-table-column prop="materialName" label="资源名称"></el-table-column>
        <el-table-column prop="materialType" label="资源类型">
        </el-table-column>
        <el-table-column prop="num" label="资源数量"></el-table-column>
        <el-table-column prop="address" label="地址"></el-table-column>
        <el-table-column prop="contacts" label="联系人"></el-table-column>
        <el-table-column prop="phone" label="电话"></el-table-column>
        <el-table-column prop="createTime" label="创建时间"></el-table-column>
        <!-- <el-table-column prop="stockNum" label="库存数量"></el-table-column> -->
        <!-- <el-table-column prop="dangerGrade" label="危险等级"></el-table-column> -->
        <el-table-column label="操作" width="220" align="center">
            <template slot-scope="scope">
                <el-button @click="editFun(scope.row)" size="small">编辑</el-button>
                <el-button type="danger" @click="delFun(scope.row)" size="small">删除</el-button>
            </template>
        </el-table-column>
    </el-table>
    <el-pagination background layout="total,sizes, prev, pager, next, jumper" :total="tableData.total" @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="PAGE.page" :page-size="PAGE.size"></el-pagination>
    <SafetyDeviceMgEdit :dialogVisible="dialogVisible" :editForm="formData" :title="dialogTit" @dialogFun="closeDialog" @refreshTableData="getTableData" :key="zjKey"></SafetyDeviceMgEdit>
</div>
</template>

<script lang="ts">
import {
    Component,
    Vue,
    Provide
} from "vue-property-decorator";
import SafetyDeviceMgEdit from "./guaranteeEdit.vue";
import METHOD from "@/utils/methods";
@Component({
    components: {
        SafetyDeviceMgEdit
    }
})
export default class SafetyDeviceMg extends Vue {
    @Provide() tableData: Object = {
        pageData: [],
        total: 0
    };
    @Provide() PAGE: any = {
        page: 1,
        size: 10
    };
    @Provide() searchData: any = {
        deviceName: "",
        deviceNumber: "",
        shortNum: "",
        dataType: '',
    };
    @Provide() loading: Boolean = false;
    //编辑组件
    @Provide() dialogVisible: Boolean = false;
    @Provide() dialogTit: String = "新增";
    @Provide() formData: any = {
        dataType: "",
        enterpriseId: ""
    };
    @Provide() zjKey: any = 0;
    @Provide() enterpriseId: string = "all";
    @Provide() dataType: string = "";

    getTableData() {
        let that = this,
            param = Object.assign({}, that.PAGE, that.searchData);
		that.enterpriseId="all";
        that.loading = true;
        METHOD.axiosPost(
            that,
            `/material/materialInfoList`,
            param,
            function (res: any) {
                that.loading = false;
                if (res.code == 0) {
                    that.tableData = res.data;
                    console.log(res.data)
                }
            }
        );
    }
    searchFun() {
        this.PAGE = {
            page: 1,
            size: 10
        };
        this.getTableData();
    }
    resetFun() {
        this.PAGE = {
            page: 1,
            size: 10
        };
        this.searchData = {
            deviceName: "",
            deviceNumber: "",
            shortNum: "",
            dataType: ''
        };
        this.getTableData();
    }
    addFun() {
        this.zjKey++;
        this.dialogVisible = true;
        //this.formData.dataType = this.searchData.dataType;
        if(METHOD.enterpriseId){
            this.formData.enterpriseId = METHOD.enterpriseId;
        }
    }
    editFun(row: any) {
        this.dialogTit = "编辑";
        this.formData = Object.assign({}, row);
        this.zjKey++;
        this.dialogVisible = true;
    }
    delFun(row: any) {
        let that = this as any;
        METHOD.deleteFun(
            this,
            `/material/deleteMaterial/${row.id}`,
            function () {
                that.getTableData();
            }
        );
    }
    handleSizeChange(val: any) {
        this.PAGE.size = val;
        this.getTableData();
    }
    handleCurrentChange(val: any) {
        this.PAGE.page = val;
        this.getTableData();
    }
    closeDialog() {
        //关闭窗口
        this.dialogVisible = false;
        this.formData = {};
    }
    selectChange(val: any) {
        this.searchData.dataType = val;
        this.getTableData();
    }
    created() {
        this.enterpriseId = METHOD.enterpriseId;
        this.getTableData();
    }
}
</script>

<style lang="scss">
@import "@/utils/public.scss";
</style>
