<template>
    <div class="app-container">
        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true">
            <el-form-item label="案件状态" prop="caseStatusName">
                <el-input v-model="queryParams.caseStatusName" placeholder="请输入案件状态" clearable style="width: 240px"
                    @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item label="节点名称" prop="nodeName">
                <el-select v-model="queryParams.nodeName" placeholder="节点名称" clearable style="width: 240px">
                    <el-option v-for="dict in dict.type.case_flow_node" :key="dict.value" :label="dict.label"
                        :value="dict.value" />
                </el-select>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
            </el-form-item>
        </el-form>
        <el-row :gutter="10" class="mb8">
            <el-col :span="1.5">
                <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="addnodeprocess">新增流程节点</el-button>
            </el-col>
        </el-row>
        <el-table v-loading="loading" :data="dataList" style="width: 100%">
            <el-table-column label="序号" type="index" align="center">
                <template slot-scope="scope">
                    <span>{{
                        (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1
                    }}</span>
                </template>
            </el-table-column>
            <el-table-column label="节点名称" align="center" prop="nodeName" :show-overflow-tooltip="true" />
            <el-table-column label="案件状态" align="center" prop="caseStatusName" :show-overflow-tooltip="true" />
            <el-table-column label="驳回节点" align="center" prop="backFlowName" :show-overflow-tooltip="true" />
            <el-table-column label="关联角色" align="center" prop="roleNames" :show-overflow-tooltip="true" />
            <el-table-column label="节点图标" align="center" prop="nodeIcon" :show-overflow-tooltip="true">
                <template slot-scope="scope">
                    <img v-if="scope.row.fileName" class="nodeIcon" :src="iconHead+scope.row.fileName"/>
                    <span v-else>暂无图标</span>
                </template>
            </el-table-column>
            <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
                <template slot-scope="scope">
                    <el-button size="mini" @click="moveDown(scope.row)" type="text" icon="el-icon-arrow-down"></el-button>

                    <el-button size="mini" @click="moveUp(scope.row)" type="text" icon="el-icon-arrow-up"></el-button>
                    <el-button size="mini" @click="eidtNodeprocess(scope.row)" type="text"
                        icon="el-icon-edit">修改</el-button>
                    <el-button size="mini" @click="deleteNodeprocess(scope.row)" type="text"
                        icon="el-icon-delete">删除</el-button>
                </template>
            </el-table-column>
        </el-table>
        <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
            @pagination="getList(queryParams)" />

        <addNodeprocess :addvisiable="addvisiable" @cancelAdd="cancelAdd" :editData="editData" @getList="getList"
            :queryParams="queryParams">
        </addNodeprocess>
    </div>
</template>
  
<script>
import { queryCaseFlowInfo, deleteCaseFlow, sortCaseFlow } from "@/api/caseprocessManagement/caseprocessManagement.js";
import addNodeprocess from "./components/addNodeprocess";
export default {
    name: "paymentList",
    components: {
        addNodeprocess,
    },
    dicts: ['case_flow_node'],
    data() {
        return {
            queryParams: {
                pageNum: 1,
                pageSize: 10,
            },
            // 遮罩层
            loading: false,
            // 总条数
            total: 0,
            // 表格数据
            form: {},
            // 校验表单
            rules: {},
            dataList: [],
            addvisiable: false,//新增弹窗
            editData: {},
            iconHead: process.env.VUE_APP_BASE_API
        };
    },
    created() {
        this.getList(this.queryParams);
    },
    computed: {
        
    },
    methods: {
        // 删除
        deleteNodeprocess(row) {
            this.$modal
                .confirm("是否删除")
                .then((res) => {
                    this.deleteSealFn({ id: row.id })
                })
        },
        // 删除接口
        deleteSealFn(data) {
            deleteCaseFlow(data).then(res => {
                this.$modal.msgSuccess("删除成功！");
                this.getList(this.queryParams);
            })
        },
        // 向下 sortType
        moveDown(row) {
            let params = {
                id: row.id,
                sortType: 0
            }
            sortCaseFlow(params).then((res) => {
                this.getList(this.queryParams);
            })
        },
        // 向上
        moveUp(row) {
            let params = {
                id: row.id,
                sortType: 1
            }
            sortCaseFlow(params).then((res) => {
                this.getList(this.queryParams);
            })
        },
        // 新增流程节点
        addnodeprocess(row) {
            this.addvisiable = true;
            this.editData = {};
        },
        cancelAdd() {
            this.addvisiable = false;
        },
        // 编辑
        eidtNodeprocess(row) {
            this.addvisiable = true;
            this.editData = row;
        },
        // 关联角色
        associatedRoles() { },
        /** 搜索按钮操作 */
        handleQuery() {
            this.queryParams.pageNum = 1;
            this.getList(this.queryParams);
        },
        /** 重置按钮操作 */
        resetQuery() {
            this.resetForm("queryForm");
            this.handleQuery();
        },
        // 查询列表数据
        getList(parms) {
            this.loading = true;
            parms.nodeId = parseInt(parms.nodeName)
            queryCaseFlowInfo(parms).then((response) => {
                this.dataList = response.rows;
                this.total = response.total;
                this.loading = false;
            });
        },
    },
};
</script>
  
<style lang="scss" scoped>
.nodeIcon {
    width: 20%;
    height: 20%;
}
</style>