<!--
 * @Title: 
 * @Description: 
 * @Author: 893699165@qq.com
 * @Date: 2022-08-24 10:49:21
 * @LastEditors: 
 * @LastEditTime: 2022-08-24 10:49:21
-->
<template>
    <div>
        <el-row>
            <el-col :span="5">
                <div class="box">
                    <el-scrollbar>
                        <basic-container>
                            <avue-tree :option="treeOption" :data="projectTreeData" @node-click="nodeClick">
                                <span class="el-tree-node__label" slot-scope="{ node, data }">
                                    <span>
                                        <i class="el-icon-user-solid"></i>
                                        {{ (node || {}).label }}
                                    </span>
                                </span>
                                <template slot-scope="scope" slot="menu">
                                    <div class="avue-tree__item" @click.native="tip(scope.node,scope.data)">自定义按钮</div>
                                </template>
                            </avue-tree>
                        </basic-container>
                    </el-scrollbar>
                </div>
            </el-col>
            <el-col :span="19">
                <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-col>
        </el-row>
        <!-- <el-dialog
      title="预警配置"
      :visible.sync="configDialog"
      width="600px"
      :before-close="handleClose"
      :close-on-click-modal="false"
      append-to-body
    >
      <el-form label-width="120px">
        <el-form-item label="预警总开关">
          <el-switch
            v-model="warningConfig.configSw"
            active-color="#13ce66"
            inactive-color="#ff4949"
            active-text="开"
            inactive-text="关"
          >
          </el-switch>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="configDialog = false" size="small">取 消</el-button>
        <el-button type="primary" @click="confirmConfig" size="small"
          >确 定</el-button
        >
      </span>
    </el-dialog> -->
        <!-- <el-dialog title="预警信息" :visible.sync="warnInfoDialog" width="80%" :close-on-click-modal="false" append-to-body>
      <rtuWarningList :rtuCode="rtuCode" ref="rtuWarningList"></rtuWarningList>
    </el-dialog> -->
        <el-dialog title="工单填报记录" :visible.sync="recordDialog" width="80%" :close-on-click-modal="false" append-to-body>
            <orderProcessList :id="id" ref="orderProcessList"></orderProcessList>
        </el-dialog>
    </div>


</template>

<script>
import { getTree } from "@/api/business/manage/manage.js";
import {
    getPage,
    orderClose,
    getDetail,
} 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,
            },
            treeCache: {
                orgId: '',
                projectId: '',
            },
            projectTreeData: [

            ],
            treeOption: {
                nodeKey: "id",
                lazy: false,

                // treeLoad: function (node, resolve) {
                // const parentId = node.level === 0 ? 0 : node.data.id;
                // getDeptLazyTree(parentId).then((res) => {
                // resolve(
                // res.data.data.map((item) => {
                // return {
                // ...item,
                // leaf: !item.hasChildren,
                // };
                // })
                // );
                // });
                // },
                defaultExpandAll: true,
                addBtn: false,
                menu: false,
                size: "small",
                props: {
                    labelText: "标题",
                    label: "title",
                    value: "value",
                    children: "children",
                },
            },
            option: {
                labelWidth: 120,
                viewLabelWidth: 100,
                searchlabelWidth: 100,
                height: "auto",
                calcHeight: 30,
                align: "center",
                headerAlign: "center",

                tip: false,
                simplePage: true,
                searchShow: true,
                searchMenuSpan: 6,
                addBtn: false,
                tree: true,
                border: true,
                index: true,
                //  height: 500,
                editBtn: false,
                delBtn: false,
                menuWidth: 160,
                dialogType: "drawer",

                dialogClickModal: false,
                column: [
                    {
                        label: "测站名称",
                        prop: "rtuName",
                        span: 12,
                        search: true,
                    },
                    {
                        label: "测站编码",
                        prop: "rtuCode",
                        span: 12,
                        search: true,
                    },
                    {
                        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: [],
        };
    },
    prop: {
        rtuCode: ["String"],
    },
    created() {
        this.init();
    },
    methods: {
        init() {
            this.initTree();
        },
        initTree() {
            getTree(
            ).then((res) => {
                const data = res.data.data;
                this.projectTreeData = data;

                this.onLoad(this.page);
            });
        },
        nodeClick(data) {
            this.treeCache.orgId = data.orgId;
            this.treeCache.projectId = data.projectId;
            //this.$message.success(JSON.stringify(data))
            this.query = {};
            this.page.currentPage = 1;
            this.onLoad(this.page);
        },
        openProcessList(item) {
            this.recordDialog = true;
            this.id = item.id;
            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['orgId'] = this.treeCache.orgId;
            params['projectId'] = this.treeCache.projectId;
            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>
