<template>
    <div class="app-container">
        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" label-width="68px">
            <el-form-item label="申请人" prop="ipaddr">
                <el-input v-model="queryParams.ipaddr" placeholder="请输入登录地址" clearable @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item label="提交人" prop="userName">
                <el-input v-model="queryParams.userName" placeholder="请输入用户名称" clearable
                    @keyup.enter.native="handleQuery" />
            </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-table v-loading="loading" :data="dataList" style="width: 100%;">
            <el-table-column label="序号" type="index" align="center">
                <template slot-scope="scope">
                    <span>{{ (pageNum - 1) * pageSize + scope.$index + 1 }}</span>
                </template>
            </el-table-column>
            <el-table-column label="案件编号" align="center" prop="caseNum" :show-overflow-tooltip="true" />
            <el-table-column label="案件标的" align="center" prop="caseSubjectAmount" :show-overflow-tooltip="true" />
            <el-table-column label="立案日期" align="center" prop="registerDate" />
            <el-table-column label="仲裁方式" align="center" prop="arbitratMethodName" :show-overflow-tooltip="true" />
            <el-table-column label="案件状态" align="center" prop="caseStatusName" />
            <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-view" @click="confirmation(scope.row)"
                        v-hasPermi="['monitor:online:forceLogout']" style="margin-right: 10px;">查看缴费清单</el-button>
                    <el-popconfirm title="是否确认缴费" @confirm="payStatus(scope.row)">
                        <el-button slot="reference" size="mini" type="text" icon="el-icon-bank-card"
                            v-hasPermi="['monitor:online:forceLogout']">缴费</el-button>
                    </el-popconfirm>
                </template>
            </el-table-column>
        </el-table>
        <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
            <el-form ref="form" :model="form" :rules="rules" label-width="150px" :disabled="true">
                <el-form-item label="案件编号：" prop="caseNum">
                    <el-input v-model="form.caseNum" placeholder="" />
                </el-form-item>
                <el-form-item label="申请人：" prop="applicant">
                    <el-input v-model="form.applicant" placeholder="" />
                </el-form-item>
                <el-form-item label="案件标的：" prop="caseSubjectAmount">
                    <el-input-number v-model="form.caseSubjectAmount" controls-position="right" :min="0" />
                </el-form-item>
                <el-form-item label="案件应缴费用：" prop="feePayable">
                    <el-input-number v-model="form.feePayable" controls-position="right" :min="0" />
                </el-form-item>
                <el-form-item label="案件实缴费用：" prop="paidExpenses">
                    <el-input-number v-model="form.paidExpenses" controls-position="right" :min="0" />
                </el-form-item>
                <el-form-item label="被申请人：" prop="respondent">
                    <el-input v-model="form.Respondent" placeholder="" />
                </el-form-item>
                <el-form-item label="申请人仲裁诉求：" prop="arbitratClaims">
                    <el-input v-model="form.arbitratClaims" placeholder="" />
                </el-form-item>
                <el-form-item label="案件状态：" prop="caseStatusName">
                    <el-input v-model="form.caseStatusName" placeholder="" />
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <!-- <el-button type="primary" @click="submitForm">确 定</el-button> -->
                <el-button @click="cancel">取 消</el-button>
            </div>
        </el-dialog>
        <el-dialog :title="payTitle" :visible.sync="openPay" v-if="openPay" width="800px" append-to-body>
            <el-descriptions title="订单信息">
                <el-descriptions-item label="案件编号：">{{ form.caseNum }}</el-descriptions-item>
                <el-descriptions-item label="申请人：">{{ form.applicant }}</el-descriptions-item>
                <el-descriptions-item label="案件标的：">{{ form.caseSubjectAmount }}</el-descriptions-item>
                <el-descriptions-item label="案件应缴费用：">{{ form.feePayable }}</el-descriptions-item>
                <el-descriptions-item label="被申请人：">{{ form.respondent }}</el-descriptions-item>
                <el-descriptions-item label="申请人仲裁诉求：">{{ form.arbitratClaims }}</el-descriptions-item>
                <el-descriptions-item label="案件状态：">{{ form.caseStatusName }}</el-descriptions-item>
            </el-descriptions>
            <div class="payType">
                <span>请选择支付方式：</span>
                <i class="iconfont icon-weixinzhifu" @click="pay(0)"></i>
                <i class="iconfont icon-zhifubao" @click="pay(1)"></i>
            </div>
            <div class="payImg">
                <div id="qrcodeImg"></div>
            </div>
            <div class="payTitle">{{ payMain }}</div>
            <div slot="footer" class="dialog-footer">
                <el-button @click="payCancel">取 消</el-button>
            </div>
        </el-dialog>
        <pagination v-show="total > 0" :total="total" :page.sync="pageNum" :limit.sync="pageSize" @pagination="getList" />
    </div>
</template>
  
<script>
import { caseApplicationList, caseApplicationDetail, casePay } from "@/api/pay/pay";
import QRCode from 'qrcodejs2';
export default {
    name: "payList",
    data() {
        return {
            // 付款二维码
            paySrc: "",
            // 遮罩层
            loading: false,
            // 总条数
            total: 0,
            // 表格数据
            list: [],
            pageNum: 1,
            pageSize: 10,
            // 弹出层标题
            title: "",
            payTitle: "",
            // 是否显示弹出层
            open: false,
            openPay: false,
            // 查询参数
            queryParams: {
                caseStatus: 2,
                pageNum: 1,
                pageSize: 10
            },
            // 弹出层内容
            form: {},
            // 校验表单
            rules: {

            },
            dataList: [],
            // 支付文字
            payMain: "",
            // 支付元素显示
            payFlag: false,
            // 案件id，案件实付金额
            payForm: {}
        };
    },
    created() {
        this.getList();
    },
    methods: {
        // 生成二维码
        qrcode(url) {  // 前端根据 URL 生成微信支付二维码
            document.getElementById("qrcodeImg").innerHTML = "";
            return new QRCode('qrcodeImg', {
                width: 200,
                height: 200,
                text: url,
                colorDark: '#000',
                colorLight: '#fff'
            });
        },
        // 取消按钮
        cancel() {
            this.open = false;
        },
        payCancel() {
            this.openPay = false;
        },
        /** 查看缴费清单 */
        confirmation(val) {
            this.getDetail({ id: val.id })
            this.open = true;
            this.title = "缴费清单";
        },
        payStatus(val) {
            this.getDetail({ id: val.id })
            this.openPay = true;
            this.payMain = "";
            this.payTitle = "缴费确认";
            // console.log(")))))))))))))))))))))))))", val);
        },
        // 提交表单
        submitForm() { },
        /** 查询案件列表 */
        getList() {
            this.loading = true;
            caseApplicationList(this.queryParams).then(response => {
                this.dataList = response.rows;
                this.dataList.forEach(item => {
                    if (item.caseStatus == 1) {
                        item.caseStatusName = '待缴费'
                    }
                    if (item.arbitratMethod == "1") {
                        item.arbitratMethodName = '视频仲裁'
                    } else if (item.arbitratMethod == "2") {
                        item.arbitratMethodName = '书面仲裁'
                    }
                });
                this.total = response.total;
                this.loading = false;
            });
        },
        /** 查询详情 */
        getDetail(parms) {
            caseApplicationDetail(parms).then(res => {
                if (res.data.caseStatus == 1) {
                    res.data.caseStatusName = '待缴费'
                }
                this.form = res.data;
                this.payForm.feePayable = res.data.feePayable;
                this.payForm.caseId = res.data.id
            })
        },
        // 支付
        pay(val) {
            if (this.payForm.feePayable == 0 || !this.payForm.feePayable) {
                this.$message({
                    message: '此案件无需缴费',
                    type: 'error'
                });
                return
            }
            let payType = ""
            if (val == 0) {
                payType = "wxpay"
                this.payMain = "请使用微信扫二维码支付"
            } else if (val == 1) {
                payType = "alipay"
                this.payMain = "请使用支付宝扫二维码支付"
            }
            casePay({
                totalFee: this.payForm.feePayable * 100,
                caseId: this.payForm.caseId,
                tradeType: "native",
                platform: payType
            }).then(res => {
                this.paySrc = res.data.code_url
                this.qrcode(this.paySrc)
            })
        },
        /** 搜索按钮操作 */
        handleQuery() {
            // this.pageNum = 1;
            // this.getList();
        },
        /** 重置按钮操作 */
        resetQuery() {
            // this.resetForm("queryForm");
            // this.handleQuery();
        },
    }
};
</script>
<style scoped lang="scss">
.payType {
    height: 80px;
    line-height: 80px;

    .icon-weixinzhifu {
        font-size: 24px;
        color: #27a56f;
        margin-right: 15px;
    }

    .icon-zhifubao {
        font-size: 24px;
        color: #1d76cc;
    }
}

.payImg {
    width: 100%;
    display: flex;
    justify-content: center;
}

.payTitle {
    margin-top: 20px;
    width: 100%;
    text-align: center;
}
</style>
  
  