<template>
    <div class="app-container">
        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true">
            <el-form-item label="案件状态" prop="caseFlowId">
                <el-select v-model="queryParams.caseFlowId" placeholder="请选择" @change="columnNameChange(item)" clearable>
                    <el-option v-for="dict in dict.type.case_flow_node" :key="dict.value" :label="dict.label"
                        :value="dict.value" @keyup.enter.native="handleQuery"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="申请机构" prop="applicationOrganId">
                <el-select v-model="queryParams.applicationOrganId" placeholder="请选择" clearable>
                    <el-option v-for="dict in deptList" :key="dict.deptId" :label="dict.deptName" :value="dict.deptId"
                        @keyup.enter.native="handleQuery"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="批号" prop="batchNumber">
                <el-input v-model="queryParams.batchNumber" placeholder="请输入案件批号" clearable style="width: 240px"
                    @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item label="案件编号" prop="caseNum">
                <el-input v-model="queryParams.caseNum" placeholder="请输入案件编号" clearable style="width: 240px"
                    @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item label="创建时间" prop="caseTime">
                <el-date-picker v-model="caseTime" type="datetimerange" align="right" unlink-panels range-separator="至"
                    start-placeholder="开始日期" end-placeholder="结束日期" clearable style="width: 240px" @change="caseTimeChange">
                </el-date-picker>
            </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="addCase">新增案件</el-button>
            </el-col>
            <el-col :span="1.5">
                <el-button type="primary" plain icon="el-icon-plus" size="mini"
                    @click="compressedPackages">案件压缩包上传</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="batchNumber" :show-overflow-tooltip="true" />
            <el-table-column label="案件编号" align="center" prop="caseNum" :show-overflow-tooltip="true" />
            <el-table-column label="申请机构名称" align="center" prop="applicationOrganName" :show-overflow-tooltip="true" />
            <el-table-column label="被申请人" align="center" prop="respondentName" :show-overflow-tooltip="true" />
            <el-table-column label="案件标的" align="center" prop="caseSubjectAmount" :show-overflow-tooltip="true" />
            <el-table-column label="调解员" align="center" prop="mediatorName" :show-overflow-tooltip="true" />
            <el-table-column label="开庭日期" align="center" prop="hearDate" :show-overflow-tooltip="true" />
            <el-table-column label="案件状态" align="center" prop="caseStatusName" :show-overflow-tooltip="true" />
            <el-table-column label="创建时间" align="center" prop="createTime" :show-overflow-tooltip="true" />
            <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
                <template slot-scope="scope">
                    <el-button size="mini" type="text" icon="el-icon-check" @click="onsubmitRow(scope.row)">提交</el-button>
                    <el-button size="mini" @click="eidtNodeprocess(scope.row)" type="text"
                        icon="el-icon-edit">修改</el-button>
                    <el-button size="mini" @click="checkDetail(scope.row)" type="text" icon="el-icon-view">查看详情</el-button>
                    <el-button size="mini" @click="consultantApplica(scope.row)" type="text" icon="el-icon-tickets">法律顾问用印申请</el-button>
                    <el-button size="mini" @click="departmentApplica(scope.row)" type="text" icon="el-icon-edit-outline">部门长用印</el-button>
                    <el-button size="mini" @click="caseFlow(scope.row)" type="text" icon="el-icon-zoom-in">查看流程</el-button>
                    <el-button size="mini" @click="caseLog(scope.row)" type="text" icon="el-icon-edit-outline">案件日志</el-button>
                    <el-button size="mini" @click="paymentconfirmationRow(scope.row)" type="text" icon="el-icon-zoom-in">缴费确认</el-button>
                    <el-button size="mini" @click="caseAccep(scope.row)" type="text" icon="el-icon-zoom-in">案件受理</el-button>
                    <el-button size="mini" @click="viewpaymentformRow(scope.row)" type="text" icon="el-icon-edit">查看缴费单</el-button>
                    <el-button size="mini" @click="caseFiling(scope.row)" type="text" icon="el-icon-tickets">案件归档</el-button>
                    <el-button size="mini" @click="signMediation(scope.row)" type="text" icon="el-icon-edit-outline">签收调解书</el-button>                 
                    <el-button size="mini" type="text" icon="el-icon-edit"
                        @click="evidenceUpload(scope.row)">证据修改</el-button>
                    <el-button size="mini" type="text" icon="el-icon-tickets" @click="payStatus(scope.row)">缴费</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)" />
        <!-- 新增编辑详情 -->
        <addCase :addVisable="addVisable" :queryParams="queryParams" @cancelCaseAdd="cancelCaseAdd" @getList="getList"
            :caseData="caseData" :caseDisabled="caseDisabled" :tabFlag="tabFlag"></addCase>
        <!-- 压缩包导入     -->
        <caseCompressionPackage :openCompressedPackages="openCompressedPackages" :queryParams="queryParams"
            @cancelCompreess="cancelCompreess" :getList="getList">
        </caseCompressionPackage>
        <!-- 案件详情 -->
        <mediationCaseDetails :processVisable="processVisable" @cancelViewProcess="cancelViewProcess">
        </mediationCaseDetails>
        <!-- 案件日志 -->
        <mediationCaseLog :showcaseLog="showcaseLog" @cancelcaseLog="cancelcaseLog"></mediationCaseLog>
        <!-- 证据修改 -->
        <evidenceDialog :evidenceVisable="evidenceVisable" @cancelEvidence="cancelEvidence" :evidenceData="evidenceData">
        </evidenceDialog>
        <!-- 缴费 -->
        <payDialog :openPay="openPay" :payTitle="payTitle" :formPayDetail="formPayDetail" :payId="payId" :payForm="payForm"
            :queryParams="queryParams" @getList="getList" @paycancelRow="paycancelRow"></payDialog>
        <!-- 缴费确认查看详情 -->
        <paymentdetailsDialog :openDialog="openDialog" @cancelpaymentdetails="cancelpaymentdetails" :title="payTitle" :detailform="detailform" :flag="flag" :paymentConfirma="paymentConfirma" :getList="getList"></paymentdetailsDialog>
        <!-- 案件受理 -->
        <caseAcceptance :showAcceptance="showAcceptance" @cancelAcceptance="cancelAcceptance" :caseAcceptanceData="caseAcceptanceData" @getList="getList" :queryParams="queryParams"></caseAcceptance>
    </div>
</template>

<script>
import { caseApplicationList, caseApplicationSelectById,submitCaseApply,selectPaymentDetail,sealApply,selectSealUrl } from '@/api/caseManagement/caseManagement.js'
import { listDept } from '@/api/system/dept.js'
import moment from "moment";
import addCase from './components/addCase.vue'
import evidenceDialog from './components/evidenceDialog.vue';
import caseCompressionPackage from './components/caseCompressionPackage.vue';
import mediationCaseDetails from './components/mediationCaseDetails.vue'
import mediationCaseLog from './components/mediationCaseLog.vue'
import payDialog from "./components/payDialog.vue";
import paymentdetailsDialog from './components/paymentdetailsDialog.vue'
import caseAcceptance from './components/caseAcceptance.vue'
export default {
    name: "caseList",
    dicts: ["case_flow_node"],
    components: {
        addCase,
        caseCompressionPackage,
        mediationCaseDetails,
        mediationCaseLog,
        evidenceDialog,
        payDialog,
        paymentdetailsDialog,
        caseAcceptance
    },
    data() {
        return {
            queryParams: {
                pageNum: 1,
                pageSize: 10,
            },
            // 遮罩层
            loading: false,
            // 总条数
            total: 0,
            // 表格数据
            form: {},
            // 校验表单
            rules: {},
            dataList: [],
            addVisable: false,//新增弹窗
            openPay: false, //缴费弹框
            formPayDetail: {},
            payId: null,
            payForm: {},
            openCompressedPackages:false,//压缩包导入弹窗
            processVisable:false,//案件详情
            showcaseLog:false,//案件日志
            openDialog:false,//确认缴费和缴费详情
            detailform: {}, //缴费详情数据
            evidenceVisable: false,//证据修改弹窗
            payTitle:"",//缴费标题
            paymentConfirma:{},//缴费确认
            showAcceptance:false,//案件受理弹框
            caseAcceptanceData:{},//案件受理数据
            flag: null,
            caseData: {},
            evidenceData: {},
            caseDisabled: false,
            caseTime: '',
            deptList: [],
            payTitle: '',
            tabFlag: false
        };
    },
    created() {
        this.getList(this.queryParams);
        this.listDeptFn()
    },
    methods: {
        /** 新增案件 */
        addCase() {
            this.addVisable = true;
            this.caseData = {};
            this.caseDisabled = false;
            this.tabFlag = false;
        },
        /** 查看详情 */
        checkDetail(val) {
            this.addVisable = true;
            this.caseData = val;
            this.caseData.flag = 1;
            this.caseDisabled = true;
            this.tabFlag = true;
        },
        /** 修改案件 */
        eidtNodeprocess(row) {
            this.addVisable = true;
            this.caseData = row;
            this.caseDisabled = false;
            this.tabFlag = false;
        },
        /** 案件导入压缩包 */
        compressedPackages() {
            this.openCompressedPackages = true;
        },
        /** 缴费 */
        payStatus(val) {
            this.getDetail({ id: val.id });
            this.payTitle = "缴费";
            this.payId = val.id;
            this.openPay = true;
        },
        /** 列表提交立案 */
        onsubmitRow(row) {
            this.$modal
                .confirm("是否提交立案申请？")
                .then(function () {
                    return submitCaseApply({ id: row.id,caseFlowId:row.caseFlowId });
                })
                .then(() => {
                    this.getList(this.queryParams);
                    this.$modal.msgSuccess("立案申请成功");
                })
                .catch(() => { });
        },
        getDetail(parms) {
            caseApplicationSelectById(parms).then((res) => {
                this.formPayDetail = res.data;
                this.payForm.feePayable = res.data.feePayable;
                this.payForm.caseId = res.data.id;
            });
        },
        /** 时间改变处理 */
        caseTimeChange() {
            if (this.caseTime) {
                this.queryParams.startTime = moment(
                    this.caseTime[0]
                ).format("YYYY-MM-DD HH:mm:ss");
                this.queryParams.endTime = moment(
                    this.caseTime[1]
                ).format("YYYY-MM-DD HH:mm:ss");
            } else {
                this.queryParams.startTime = '';
                this.queryParams.endTime = '';
            }

        },
        /** 获取所有部门 */
        listDeptFn() {
            listDept().then(res => {
                this.deptList = res.data;
            })
        },
        /** 修改证据 */
        evidenceUpload(row) {
            this.evidenceData = row;
            this.evidenceVisable = true;
        },
        /** 取消弹窗（证据弹窗） */
        cancelEvidence() {
            this.evidenceVisable = false;
        },
        /** 关闭新增弹窗 */
        cancelCaseAdd() {
            this.addVisable = false;
        },
        /** 关闭压缩包导入弹窗 */
        cancelCompreess() {
            this.openCompressedPackages = false;
        },
        /**取消缴费*/
        paycancelRow(row) {
            this.openPay = false;
        },
        /** 搜索按钮操作 */
        handleQuery() {
            this.queryParams.pageNum = 1;
            this.getList(this.queryParams);
        },
        /** 重置按钮操作 */
        // resetQuery() {
        //     this.resetForm("queryForm");
        //     this.handleQuery();
        // },
        // 查询列表数据
        getList(parms) {
            this.loading = true;
            caseApplicationList(parms).then((response) => {
                this.dataList = response.rows;
                this.total = response.total;
                this.loading = false;
            })
        },
        // 法律顾问用印申请
        consultantApplica(row) {
            let paramsValue ={
                caseId:row.id,
                batchNumber:"",
                caseFlowId:row.caseFlowId
            }
            this.$modal.confirm("你确定要用印申请吗？").then((res) => {
                sealApply(paramsValue).then(res=>{
                    this.getList(this.queryParams);
                    this.$modal.msgSuccess("用印申请成功");
                })
            }).catch(() => {

            })
        },
        // 部门长用印申请
        departmentApplica(row) {
             this.$modal.confirm("你确定要用印确认吗？").then((res) => {
                 let paramsValue ={
                     caseId:row.id
                 }
                 selectSealUrl(paramsValue).then(res=>{
                     window.open(res.data.sealUrl)
                     this.$modal.confirm("你确认用印了吗？").then((res) => {
                     this.getList(this.queryParams);
                    }).catch(() => {

                    })
                 })
            }).catch(() => {

            })
        },
        // 案件受理
        caseAccep(row){
            this.caseAcceptanceData = row
            this.showAcceptance = true
        },
        cancelAcceptance(){
            this.showAcceptance = false
        },
        // 缴费确认
        paymentconfirmationRow(row){
            this.paymentConfirma = row
            console.log(this.paymentConfirma)
            this.paymentDetails({
                id:row.id
            })
            this.openDialog = true
            this.payTitle = "缴费确认"
            this.flag = 0;
            this.detailform = {}
        },
        cancelpaymentdetails(){
            this.openDialog = false
        },
        // 查看缴费确认
        viewpaymentformRow(row){
             this.paymentDetails({
                id:row.id
            })
            this.payTitle = "缴费单详情"
            this.flag = 1;
            this.detailform = {}
            this.openDialog = true
        },
        // 缴费详情
        paymentDetails(val){
            selectPaymentDetail(val).then(res=>{
                this.detailform = res.data;
            })
        },
        //案件流程
        caseFlow(row) {
            this.processVisable = true
        },
        cancelViewProcess() {
            this.processVisable = false
        },
        //案件日志
        caseLog() {
            this.showcaseLog = true
        },
        cancelcaseLog() {
            this.showcaseLog = false
        },
        // 案件归档
        caseFiling() {
            this.$modal.confirm("你确定要案件归档吗？").then((res) => {

            }).catch(() => {

            })
        },
        //签收调解书
        signMediation() {
            this.$modal.confirm("你确定要签收调解书吗？").then((res) => {

            }).catch(() => {

            })
        },
        departmentApplica() {

        }
    },
};
</script>

<style lang="scss" scoped></style>