<!--
 * @Title: 
 * @Description: 
 * @Author: 893699165@qq.com
 * @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>
                    <el-button type="text" size="small" @click="orderOff(row)">人工关闭
                    </el-button>
                </template>
            </avue-crud>
        </basic-container>
        <el-dialog title="工单填报记录" :visible.sync="recordDialog" v-if="recordDialog" width="80%"
            :close-on-click-modal="false" append-to-body>
            <orderProcessList :id="id" ref="orderProcessList"></orderProcessList>
        </el-dialog>
    </div>
</template>

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

// import { mapGetters } from "vuex";
import orderProcessList from "./orderProcessList";
export default {
    components: {
        orderProcessList,
    },
    data() {
        return {
            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: 30,
                align: "center",
                headerAlign: "center",

                tip: false,
                simplePage: true,
                searchShow: false,
                searchMenuSpan: 6,
                addBtn: false,

                border: true,
                index: true,
                height: 500,
                editBtn: false,
                delBtn: false,
                menuWidth: 160,
                dialogType: "drawer",

                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: 12,
                    },
                    {
                        label: "处理人",
                        prop: "processorName",
                        span: 12,
                    },
                    {
                        label: "工单更新时间",
                        prop: "updateTime",
                        span: 12,
                    },


                ],
            },
            data: [],
        };
    },
    create() {
        this.init();
    },
    methods: {
        init() {
            this.$refs.crud.doLayout();
        },
        openProcessList(item) {
            this.id = item.id;
            this.recordDialog = true;
            this.$nextTick(() => {
                this.$refs["orderProcessList"].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>
