<template>
    <div>
        <el-card>
            <el-form :inline="true" :model="filterQuery" size="mini">
                <el-row style="width: 100%">
                    <el-form-item class="query-form-item">
                        <el-input placeholder="请输入设备号" v-model="filterQuery.code"
                                  clearable="true"></el-input>
                    </el-form-item>
                    <el-form-item class="query-form-item">
                        <el-input placeholder="DI" v-model="filterQuery.nameCode"
                                  clearable="true"></el-input>
                    </el-form-item>
                    <el-form-item>
                        <el-button-group>
                            <el-button
                                type="primary"
                                icon="el-icon-refresh"
                                @click="onReset"
                            ></el-button>
                            <el-button type="primary" icon="search" @click="onSubmit"
                            >查询
                            </el-button
                            >
                        </el-button-group>
                    </el-form-item>
                </el-row>
            </el-form>

            <el-table v-loading="loading" :data="list" style="width: 100%">
                <el-table-column label="序号" type="index" fixed></el-table-column>
                <el-table-column label="养护记录号" prop="orderId" width="180"></el-table-column>
                <el-table-column label="领用记录号" prop="collOrderId" width="180"></el-table-column>
                <el-table-column label="养护日期" prop="createTime" width="180"></el-table-column>
                <el-table-column label="养护人" prop="createUser" width="120"></el-table-column>
                <el-table-column label="操作" width="180" fixed="right">
                    <template slot-scope="scope">
                        <el-button
                            type="text"
                            size="small"
                            @click.native.stop="addMAOrder(scope.row)"
                        >养护
                        </el-button
                        >
                    </template>
                </el-table-column>
            </el-table>
        </el-card>

        <el-pagination
            :page-size="filterQuery.limit"
            :current-page="filterQuery.page"
            @current-change="handleCurrentChange"
            layout="prev, pager, next"
            :total="total"
        ></el-pagination>

        <el-dialog
            title="设备养护"
            :visible.sync="formVisible"
            width="70%"
            :close-on-click-modal="false"
            :close-on-press-escape="false"
            v-if="formVisible"
        >
            <deviceMAOrderDialog
                :deviceMAOrder="deviceMAOrder"
                :closeDialog="closeDialog"
            >
            </deviceMAOrderDialog>
        </el-dialog>

    </div>
</template>

<script>
import {deviceList} from "@/api/inventory/deviceMAOrder";
import deviceMAOrderDialog from "@/views/inventory/deviceMAOrderDialog.vue";

export default {
    data() {
        return {
            filterQuery: {
                code: null,
                nameCode: null,
                page: 1,
                limit: 20
            },
            list: [],
            total: 0,
            loading: false,
            idQuery: null,
            formVisible: false,
            formName: null,
            deviceMAOrder: {
                code: null,
                deptName: null,
                createUser: null,
                createTime: null
            }
        };
    },
    components: {
        deviceMAOrderDialog
    },
    methods: {
        onReset() {
            this.$router.push({
                path: "",
            });
            this.filterQuery = {
                code: null,
                nameCode: null,
                page: 1,
                limit: 20,
            };
            this.getList();
        },
        onSubmit() {
            this.filterQuery.page = 1;
            this.getList();
        },
        handleSizeChange(val) {
            this.filterQuery.limit = val;
            this.getList();
        },
        handleCurrentChange(val) {
            this.filterQuery.page = val;
            this.getList();
        },
        getList() {
            this.loading = true;
            deviceList(this.filterQuery).then((res) => {
                this.loading = false;
                if (res.code == 20000) {
                    this.list = res.data.list || [];
                    this.total = res.data.total || 0;
                } else {
                    this.list = [];
                    this.total = 0;
                }
            }).catch(() => {
                this.loading = false;
                this.list = [];
                this.total = 0;
            });
        },
        closeDialog() {
            this.formVisible = false;
            this.getList();
        },
        addMAOrder(row) {
            this.deviceMAOrder = {
                code: row.code,
                createUser: this.$store.getters.employName,
                deptName: row.deptName,
                deptCode: row.deptCode,
                createTime: new Date().toLocaleString()
            }
            this.formVisible = true;
        },
    },
    created() {
        this.getList();
    },
};
</script>

<style type="text/scss" lang="scss">
</style>
