<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.orderId"
                                  clearable="true"></el-input>
                    </el-form-item>
                    <el-form-item class="query-form-item">
                        <el-input placeholder="请输入领用记录号" v-model="filterQuery.collOrderId"
                                  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%"
                      highlight-current-row="true"
                      @current-change="handleChange"
            >
                <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>

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

        <el-card>
            <el-table v-loading="loading" :data="detailList" style="width: 100%; margin-top: 10px;">
                <el-table-column label="序号" type="index" width="50"></el-table-column>
                <el-table-column label="条码" width="150" prop="code" show-overflow-tooltip></el-table-column>
                <el-table-column width="200"
                                 label="产品通用名"
                                 prop="productName"
                ></el-table-column>
                <el-table-column width="150" label="规格型号" prop="ggxh"></el-table-column>
                <el-table-column width="150" label="批次号" prop="batchNo"></el-table-column>
                <el-table-column label="养护日期" prop="createTime" width="150"></el-table-column>
                <el-table-column width="150" label="养护状态" prop="maintenanceStatus">
                    <template slot-scope="scope">
                        <el-radio disabled="true" v-model="scope.row.maintenanceStatus"
                                  :label="0">未养护
                        </el-radio>
                        <el-radio disabled="true" v-model="scope.row.maintenanceStatus"
                                  :label="1">已养护
                        </el-radio>
                    </template>
                </el-table-column>
                <el-table-column width="150" label="设备状态" prop="deviceStatus">
                    <template slot-scope="scope">
                        <el-radio v-model="scope.row.deviceStatus" :label="1" disabled="true">
                            正常
                        </el-radio>
                        <el-radio v-model="scope.row.deviceStatus" :label="0" disabled="true">
                            异常
                        </el-radio>
                    </template>
                </el-table-column>
                <el-table-column width="200" label="养护备注" prop="remark" show-overflow-tooltip></el-table-column>
                <el-table-column width="180" label="生产日期(yyMMdd)" prop="produceDate"></el-table-column>
                <el-table-column width="180" label="失效日期(yyMMdd)" prop="expireDate"></el-table-column>
                <el-table-column width="250" label="注册/备案凭证号" prop="zczbhhzbapzbh"
                                 show-overflow-tooltip></el-table-column>
                <el-table-column width="180" label="生产厂家" prop="ylqxzcrbarmc"></el-table-column>
            </el-table>

            <el-pagination
                :page-size="detailQuery.limit"
                :current-page="detailQuery.page"
                @current-change="handleCurrentDetailChange"
                layout="prev, pager, next"
                :total="detailTotal"
            ></el-pagination>
        </el-card>

    </div>
</template>

<script>
import {getDeviceMAOrderList, getDeviceMAOrderDetailList} from "@/api/inventory/deviceMAOrder";

export default {
    data() {
        return {
            filterQuery: {
                status: 1,
                orderId: null,
                collOrderId: null,
                page: 1,
                limit: 20
            },
            list: [],
            total: 0,
            loading: false,
            detailList: [],
            detailQuery: {
                orderIdFk: null,
                page: 1,
                limit: 10
            },
            detailTotal: 0,

        };
    },
    methods: {
        onReset() {
            this.$router.push({
                path: "",
            });
            this.filterQuery = {
                status: 1,
                orderId: null,
                collOrderId: 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
            this.detailList = [];
            this.detailTotal = 0;
            getDeviceMAOrderList(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((error) => {
                this.loading = false;
                this.list = [];
                this.total = 0;
            });
        },
        handleChange(row) {
            this.detailQuery.orderIdFk = row.orderId;
            this.detailQuery.page = 1;
            this.getDeviceCollOrderDetailList();
        },
        handleCurrentDetailChange(val) {
            this.detailQuery.page = val;
            this.getDeviceCollOrderDetailList();
        },
        getDeviceCollOrderDetailList() {
            this.loading = true;
            getDeviceMAOrderDetailList(this.detailQuery).then((res) => {
                this.loading = false;
                if (res.code === 20000) {
                    this.detailList = res.data.list || [];
                    this.detailTotal = res.data.total || 0;
                } else {
                    this.detailList = [];
                    this.detailTotal = 0;
                }
            }).catch((error) => {
                this.loading = false;
                this.detailList = [];
                this.detailTotal = 0;
            })
        },
    },
    created() {
        this.getList();
    },
};
</script>

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