<!--
 * @Title: 
 * @Description:  历史维修任务
 * @Author: swp
 * @Date: 2022-08-24 10:49:21
 * @LastEditors: 
 * @LastEditTime: 2022-08-24 10:49:21
-->
<template>
    <div>
        <el-row>
            <el-col :span="24">
                <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="scope" slot="menuLeft">
                            <div class="line">

                                <div class="lineText">
                                    <span class="orderProcessing">完成任务数量: {{
                                        countInfo.reportOrderCount }}</span>
                                </div>
                            </div>
                        </template> -->

                        <template slot-scope="{ row, index }" slot="menu">
                            <el-button type="text" size="small" @click="openProcessList(row)">查看详情
                            </el-button>
                        </template>
                    </avue-crud>
                </basic-container>
            </el-col>
        </el-row>
        <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="id" ref="checkorderprocessdetail"></checkorderprocessdetail>
        </el-drawer>
    </div>
</template>

<script>
import {
    getPage,
    getDetail,
} from "@/api/business/order/order.js";
import checkorderprocessdetail from "./checkorderprocessdetail.vue";
import { mapGetters } from "vuex";
export default {
    components: {
        checkorderprocessdetail,
    },
    name: 'rtucheckorderhistorylist',
    props: {
        rtuCode: {
            type: [String],
            required: true
        },
    },
    data() {
        return {
            dialogTitle: "维修任务历史记录",
            recordDialog: false,
            id: "",
            form: {},
            selectionList: [],
            countInfo: {
                reportOrderCount: 0
            },
            query: {},
            loading: true,
            page: {
                pageSize: 10,
                currentPage: 1,
                total: 0,
            },
            treeCode: '',
            treeParentCode: '',
            treeData: [],
            treeOption: {
                nodeKey: "id",
                defaultExpandedKeys: [],
                lazy: false,
                addBtn: false,
                menu: true,
                size: "small",
                props: {
                    labelText: "标题",
                    label: "title",
                    value: "value",
                    children: "children",
                },
            },
            option: {
                labelWidth: 120,
                viewLabelWidth: 100,
                searchlabelWidth: 100,
                height: "auto",
                calcHeight: 80,
                align: "center",
                headerAlign: "center",
                tip: false,
                simplePage: true,
                searchShow: true,
                searchMenuSpan: 6,
                addBtn: false,
                tree: true,
                border: true,
                index: true,
                editBtn: false,
                delBtn: false,
                menuWidth: 160,
                dialogType: "drawer",
                dialogClickModal: false,
                columnBtn: false,
                column: [
                    {
                        label: "测站编码",
                        prop: "rtuCode",
                        span: 12,
                        hide: true,
                        width: 120,
                    },
                    {
                        label: "测站名称",
                        prop: "rtuName",
                        span: 12,
                        html: true,
                        formatter: (val) => {
                            if (val.rtuName) {
                                return '<b>' + val.rtuName + '</b>/' + '<b style="color:grey">' + val.rtuCode + '</b>'
                            } else {
                                return '<b>' + val.rtuName + '</b>'
                            }
                        }
                    },
                    {
                        label: "任务确认人",
                        prop: "orderConfirmUserName",
                        span: 12,
                    },
                    {
                        label: "填报人",
                        prop: "processUserName",
                        span: 12,
                    },
                    // {
                    //     label: '异常类型',
                    //     prop: 'warnKind',
                    //     type: 'select',
                    //     width: 100,
                    //     hide: true,
                    //     editDisplay: false,
                    //     addDisplay: false,
                    //     search: true,
                    //     searchSpan: 8,
                    //     props: {
                    //         label: 'name',
                    //         value: 'code'
                    //     },
                    //     span: 24,
                    //     dicData: [{
                    //         name: '测站离线',
                    //         code: 1
                    //     }, {
                    //         name: '测站时钟异常',
                    //         code: 2
                    //     }, {
                    //         name: '测站雨量小时报漏报',
                    //         code: 3
                    //     }, {
                    //         name: '测站水位小时报漏报',
                    //         code: 4
                    //     }, {
                    //         name: '雨量5分钟上报延时',
                    //         code: 5
                    //     }, {
                    //         name: '雨量站小时上报延时',
                    //         code: 6
                    //     }, {
                    //         name: '水位站小时上报延时',
                    //         code: 7
                    //     }, {
                    //         name: '雨量疑似异常值',
                    //         code: 8
                    //     }]
                    // },
                    // {
                    //     label: "任务创建时间",
                    //     prop: "createTime",
                    //     span: 12,
                    // },
                    // {
                    //     label: "任务确认时间",
                    //     prop: "orderConfirmTime",
                    //     span: 12,
                    // },
                    // {
                    //     label: "任务关闭时间",
                    //     prop: "updateTime",
                    //     span: 12,
                    // },
                    {
                        label: "维修时长",
                        prop: "taskProcessDuration",
                        span: 12,
                    },
                    {
                        label: "异常信息",
                        prop: "warnKindInfo",
                        span: 12,
                    },
                    {
                        label: "任务关闭类别",
                        prop: "orderCloseType",
                        span: 12,
                        html: true,
                        formatter: (val) => {

                            if (val.orderCloseType == 0) {
                                return '<b style="color:blue">系统自动关闭</b>'
                            } else if (val.orderCloseType == 1) {
                                return '<b style="color:blue">人工关闭</b>'
                            }

                        }
                    },
                    {
                        label: "是否维修",
                        prop: "orderReportStatus",
                        span: 12,
                        html: true,
                        formatter: (val) => {
                            if (val.orderReportStatus == 0) {
                                return '<b style="color:blue">否</b>'
                            } else if (val.orderReportStatus == 1) {
                                return '<b style="color:blue">已维修</b>'
                            }
                        }
                    },
                ],
            },
            data: [],
        };
    },
    computed: {
        ...mapGetters(["userInfo", "permission"]),
        permissionList() {
            return {
                // closeBtn: this.vaildData(this.permission.order_close, false),
            };
        },
    },
    created() {
        console.log("rtuCode " + this.rtuCode)
    },
    methods: {
        init() {
            console.log("rtuCode " + this.rtuCode)
            this.onLoad(this.page);
            this.$refs.crud.doLayout();
        },
        openProcessList(item) {
            this.recordDialog = true;
            this.dialogTitle = "维修任务详情[" + item.rtuName + "_" + item.rtuCode + "]";
            this.id = item.id;
            this.$nextTick(() => {
                this.$refs["checkorderprocessdetail"].init();
            });
        },
        searchReset() {
            this.query = {};
            this.page.currentPage = 1;
            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();
        },
        beforeOpen(done, type) {
            if (["edit", "view"].includes(type)) {
                getDetail(this.form.id).then((res) => {
                    this.form = res.data.data;
                });
            }
            done();
        },
        currentChange(currentPage) {
            this.page.currentPage = currentPage;
        },
        sizeChange(pageSize) {
            this.page.pageSize = pageSize;
        },
        refreshChange() {
            var params = {};
            this.onLoad(this.page, params);
        },
        onLoad(page, params = {}) {
            this.loading = true;
            params['rtuCode'] = this.rtuCode;
            params['orderClose'] = 1;
            params['orderReportStatus'] = 1;
            console.log("rtuCode " + this.rtuCode)
            getPage(
                page.currentPage,
                page.pageSize,
                Object.assign(params, this.query)
            ).then((res) => {
                const data = res.data.data;
                this.page.total = data.total;
                this.data = data.records;
                this.loading = false;
                this.selectionClear();
            });
        },
    },
};
</script>
<style  lang="scss" scoped>
.line {
    display: flex;
    flex-direction: row;
    justify-content: flex-start;
}

.line .lineText {
    margin-left: 10px;
    margin-right: 0px;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.line .lineText .orderProcessing {

    color: dodgerblue;
    font-size: 0.8rem;
}
</style>