<!--
 * @Title: 
 * @Description: 测站RTU更换列表
 * @Author: swp
 * @Date: 2022-08-24 10:49:21
 * @LastEditors: 
 * @LastEditTime: 2022-08-24 10:49:21
-->
<template>
    <div>
        <basic-container>
            <avue-crud :option="option" :table-loading="loading" :page.sync="page" :data="data" ref="crud" v-model="form"
                :permission="permissionList" @row-del="rowDel" @row-update="rowUpdate" @row-save="rowSave"
                @search-change="searchChange" @search-reset="searchReset" @selection-change="selectionChange"
                @current-change="currentChange" @size-change="sizeChange" @refresh-change="refreshChange" @on-load="onLoad">
                <template slot-scope="{ row, index }" slot="menu">
                    <el-button v-if="row.replaceKind === 1" type="text" size="small" @click="openCheckOrderDetail(row)">维修详情
                    </el-button>
                    <el-button v-else-if="row.replaceKind === 2" type="text" size="small"
                        @click="openInspectionReportDetail(row)">巡检详情
                    </el-button>
                </template>
            </avue-crud>
        </basic-container>
        <el-drawer :visible.sync="recordDialog" v-if="recordDialog" title="维修详情" direction="rtl" size="50%"
            append-to-body="true">
            <div slot="title" class="header-title">
                <span class="name">{{ dialogTitle }}</span>
            </div>
            <checkorderprocessdetail :orderId="orderId" ref="checkorderprocessdetail"></checkorderprocessdetail>
        </el-drawer>
        <el-drawer title="巡检填报记录" :visible.sync="reportDialog" v-if="reportDialog" size="50%" direction="rtl"
            append-to-body="true">
            <div slot="title" class="header-title">
                <span class="name">{{ dialogTitle }}</span>
            </div>
            <inspectionreportdetail :id="inspectionId" ref="inspectionreportdetail"></inspectionreportdetail>
        </el-drawer>
    </div>
</template>

<script>

import { getRtuReplaceList } from "@/api/business/manage/manage.js";
import checkorderprocessdetail from "../order/checkorderprocessdetail.vue";
import inspectionreportdetail from "../inspection/inspectionreportdetail.vue";
export default {
    components: {
        checkorderprocessdetail,
        inspectionreportdetail
    },
    name: 'rtuwarninglist',
    data() {
        return {
            orderId: 0,
            inspectionId: 0,
            dialogTitle: "维修任务处理记录",
            recordDialog: false,
            reportDialog: false,
            drawer: false,
            form: {},
            selectionList: [],
            query: {},
            loading: true,
            page: {
                pageSize: 10,
                currentPage: 1,
                total: 0,
            },
            option: {
                labelWidth: 120,
                viewLabelWidth: 100,
                searchlabelWidth: 100,
                height: "auto",
                calcHeight: 80,
                align: "center",
                headerAlign: "center",
                tip: false,
                simplePage: true,
                searchShow: true,
                searchMenuSpan: 6,
                menu: true,
                border: true,
                index: true,
                editBtn: false,
                delBtn: false,
                addBtn: false,
                viewBtn: false,
                viewBtnText: "RTU更换历史",
                menuWidth: 220,
                dialogType: "drawer",
                dialogClickModal: false,
                columnBtn: false,
                column: [
                    {
                        label: "更换时间",
                        prop: "replaceDate",
                        span: 24,
                    },
                    {
                        label: "更换种类",
                        prop: "replaceKind",
                        span: 24,
                        html: true,
                        formatter: (val) => {
                            let htmltext = '';
                            if (val.replaceKind === 0) {
                                htmltext = '<b style="color:blue">更换</b>';
                            } else if (val.replaceKind === 1) {
                                htmltext = '<b style="color:blue">维修更换</b>';
                            } else if (val.replaceKind === 2) {
                                htmltext = '<b style="color:blue">巡检更换</b>';
                            }
                            return htmltext;
                        }
                    },
                    {
                        label: "RTU品牌",
                        prop: "rtuBrand",
                        span: 24,
                    },
                    {
                        label: "RTU型号",
                        prop: "rtuModel",
                        span: 24,
                    },
                    {
                        label: "备注",
                        prop: "replaceDesc",
                        span: 24,
                    },
                ],
            },
            data: [],

        };
    },
    props: {
        rtuCode: {
            type: [String],
            required: true
        },
    },
    created() {
        this.init();
    },
    methods: {
        init() {
            this.onLoad(this.page);
        },
        openCheckOrderDetail(row) {
            this.recordDialog = true;
            this.dialogTitle = "维修任务详情";
            this.orderId = row.orderId;
            this.$nextTick(() => {
                this.$refs["checkorderprocessdetail"].init();
            });
        },
        openInspectionReportDetail(row) {
            this.reportDialog = true;
            this.dialogTitle = '汛前巡检填报信息';
            this.inspectionId = row.inspectionId;
            this.$nextTick(() => {
                this.$refs["inspectionreportdetail"].init();
            });
        },
        searchReset() {
            this.query = {};
            this.onLoad(this.page);
        },
        searchChange(params, done) {
            this.query = params;
            this.page.currentPage = 1;
            this.onLoad(this.page, params);
            done();
        },
        selectionChange(list) {
            this.selectionList = list;
        },
        selectionClear() {
            this.selectionList = [];
            this.$refs.crud.toggleSelection();
        },
        currentChange(currentPage) {
            this.page.currentPage = currentPage;
        },
        sizeChange(pageSize) {
            this.page.pageSize = pageSize;
        },
        refreshChange() {
            this.onLoad(this.page, this.query);
        },
        onLoad(page, params = {}) {
            this.loading = true;
            params['rtuCode'] = this.rtuCode;
            getRtuReplaceList(
                Object.assign(params, this.query)
            ).then((res) => {
                const data = res.data.data;
                this.data = data;
                this.loading = false;
                this.selectionClear();
            });
        },
    },
};
</script>
