<!--
 * @Title: 
 * @Description: 每个测站发生的维修任务列表
 * @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 type="text" size="small" @click="openProcessList(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="id" ref="checkorderprocessdetail"></checkorderprocessdetail>
        </el-drawer>
    </div>
</template>

<script>
import {
    getPage,
    getDetail,
    orderClose,
} from "@/api/business/order/order.js";

import checkorderprocessdetail from "./checkorderprocessdetail.vue";
import { mapGetters } from "vuex";
export default {
    components: {
        checkorderprocessdetail,
    },
    name: 'rtucheckorderlist',
    data() {
        return {
            dialogTitle: "测站维修任务",
            recordDialog: false,
            id: "",
            editForm: {},
            editDialog: 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: false,
                searchMenuSpan: 6,
                addBtn: false,
                border: true,
                index: true,
                editBtn: false,
                delBtn: false,
                menuWidth: 160,
                dialogType: "drawer",
                columnBtn: false,
                dialogClickModal: false,
                column: [
                    // {
                    //     label: "工单来源",
                    //     prop: "orderFromKey",
                    //     span: 12,
                    //     props: {
                    //         label: 'dictValue',
                    //         value: 'id'
                    //     },
                    //     dicUrl: '/api/galaxy-system/dict-biz/dictionary?code=rtu_check_order_from',
                    // },
                    {
                        label: "维修状态",
                        prop: "orderStatusKey",
                        span: 12,
                        props: {
                            label: 'dictValue',
                            value: 'id'
                        },
                        dicUrl: '/api/galaxy-system/dict-biz/dictionary?code=rtu_check_order_status',
                    },
                    {
                        label: "维修说明",
                        prop: "orderDesc",
                        span: 24,
                    },
                    // {
                    //     label: "预警类别",
                    //     prop: "warnKind",
                    //     span: 12,
                    //     props: {
                    //         label: 'dictValue',
                    //         value: 'id'
                    //     },
                    //     dicUrl: '/api/galaxy-system/dict-biz/dictionary?code=warn_kinds',
                    // },
                    // {
                    //     label: "处理人",
                    //     prop: "processorName",
                    //     span: 12,
                    // },
                    {
                        label: "创建时间",
                        prop: "createTime",
                        span: 12,
                    },
                    {
                        label: "最新反馈时间",
                        prop: "updateTime",
                        span: 12,
                    },
                ],
            },
            data: [],
        };
    },
    props: {
        rtuCode: {
            type: [String],
            required: true
        },
    },
    computed: {
        ...mapGetters(["userInfo", "permission"]),
        permissionList() {
            return {
                // closeBtn: this.vaildData(this.permission.order_close, false),
            };
        },
    },
    create() {
        this.init();
    },
    methods: {
        init() {
            // this.$message.success(this.rtuCode)
            this.onLoad(this.page);
            this.$refs.crud.doLayout();
        },
        openProcessList(item) {
            this.id = item.id;
            this.dialogTitle = "维修任务详情[" + item.rtuName + item.rtuCode + "]";
            this.recordDialog = true;
            this.$nextTick(() => {
                this.$refs["checkorderprocessdetail"].init();
            });
        },
        orderOff(item) {
            this.$prompt("请输入处理意见", "是否确认关闭此工单？", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",

            })
                .then(({ value }) => {
                    orderClose({ id: item.id, orderDesc: value }).then((res) => {
                        if (res.data.code == 200) {
                            this.$message({
                                type: "info",
                                message: "操作成功",
                            });
                            this.refreshChange();
                        }
                    });
                })
                .catch(() => { });
        },
        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();
        },

        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() {
            this.onLoad(this.page, this.query);
        },
        onLoad(page, params = {}) {
            this.loading = true;
            params['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>
