<template>
    <div style="margin-top:80px">
        <div>
            <el-table :data="loanBackedList" stripe style="width: 100%">
                <el-table-column prop="raiseNo" label="放款单号" ></el-table-column>
                <el-table-column prop="loanNo" label="借款单编号"></el-table-column>
                <el-table-column prop="raiseAmt" label="放款金额" ></el-table-column>
                <!-- <el-table-column prop="result" label="放款结果" :formatter="dateSuccess" ></el-table-column> -->
                <el-table-column prop="gmtCreated" label="放款时间"  :formatter="dateFormat" ></el-table-column>
                <el-table-column prop="cardOwnerName" label="持卡人姓名" ></el-table-column>
                <el-table-column prop="cardBankAccount" label="开户银行卡账号"></el-table-column>
                <el-table-column prop="cardBankName" label="开户银行" ></el-table-column>
                <el-table-column prop="cardOwnerMobile" label="客户电话"></el-table-column>
                <el-table-column prop="confirmDesc" label="备注信息" ></el-table-column>
                <el-table-column label="操作">
                    <template scope="scope">
                            <el-button type="text" size="small" @click="passDerate(scope.row)" >已处理</el-button>
                            <!-- <el-button type="text" size="small" @click="refuseDerate(scope.row)">作废借款申请</el-button> -->
                    </template>
                </el-table-column>
            </el-table>
        </div>

        <!--分页-->
        <div class="page">
            <el-pagination
               @current-change="handleCurrentChange"
                :current-page.sync="page.current"
                :page-size="page.size"
                layout="prev, pager, next"
                :total="page.total">
            </el-pagination>
        </div>


    </div>
</template>

<script>
    import * as moment from "moment";
    export default {
        name: "ByhLoanBackedList",
        data(){
            return {
                flag: false,
                page: {
                    current: 1,
                    size: 10,
                    total: 0
                },
                loginName: '',
                loanBackedList:[],
                formInline: {
                    derateNo: '',
                    clientCell:'',
                    confirmUser: '',
                    memo: '',
                },
            }
        },

        created() {
            if (this.$route != null && this.$route.query != null && this.$route.query.flag) {
                this.flag = this.$route.query.flag;
                this.formInline.clientCell = this.$route.query.clientCell;
            }
        },

        mounted() {
            //还款日志
            this.loanBackedList = this.backedData();
            this.loginName = localStorage.getItem("loginName");
        },

        methods: {
            /** 加载数据 */
            backedData(params) {
                this.$$post('/raise/getRaiseHandList', this.buildHandParam()).then(res => {
                    if (res.data.code != 1) {
                        this.$message.error(res.data.msg);
                        this.loanBackedList = '';
                        return
                    }
                    this.loanBackedList = res.data.data.records;
                    this.page.total = res.data.data.total;
                }).catch(error => {
                    this.$Message.error(error || '系统异常');
                });
            },

            /*查看详情*/
            passDerate(record) {
                this.$$get('/raise/doRaise/'+record.raiseNo)
                .then(res => {
                    if (res.data.code == 1){
                        this.$message({message: res.data.msg, type: 'success'});
                        this.handleClose();
                        window.location.reload();
                    }else{
                        this.$message({message: res.data.msg, type: 'error'});
                    }
                })
                .catch(err => this.$$msg.err(err))
            },
            refuseDerate(record) {
                this.$$post('/derate/refuseDerate', this.buildParamRefuse(record)).then(res => {
                    if (res.data.code != 1) {
                        this.$message.error(res.data.msg);
                        return
                    }
                    this.$message({message: res.data.msg, type: 'success'});
                    this.handleClose();
                    window.location.reload();
                })
            },

            /*搜索条件*/
            onSubmit() {
                this.backedData();
            },
            /*重置*/
            reset() {
                this.formInline.clientCell = '';
            },

            /** 处理分页操作*/
            handleCurrentChange() {
                this.loanBackedList = this.backedData()
            },

            dateFormatText: function (param) {
                return moment(param).format("YYYY-MM-DD");
            },
            dateSuccess: function (row, column) {
                var status = row['result'];
                return this.$enumUtils.toMsg('SuccessAndFail', status);
            },

            getDate(param, num) {
                if (param && param[num] !== '') {
                    return moment(param[num]).format("YYYY-MM-DD")
                }
                return ""
            },

            mergeDate(param1, param2) {
                if (param1 == "") {
                    return ""
                }
                var array = new Array();
                array[0] = new Date(param1)
                array[1] = new Date(param2)
                return array;
            },

            /*日期*/
            dateFormat: function (row, column) {
                var date = row[column.property]
                if (date == undefined) {
                    return ''
                }
                return moment(date).format("YYYY-MM-DD HH:mm:ss")
            },

            //还款类型
            typyFormat: function (row, column) {
                var status = row['backedType'];
                return this.$enumUtils.toMsg('BackedTransferTypeEnum', status);
            },
            //还款单状态
            statusFormat: function (row, column) {
                var status = row['status'];
                return this.$enumUtils.toMsg('XmRaiseBackedStatus', status);
            },
            //结果状态
            resultFormat: function (row, column) {
                var result = row['result'];
                if(result!=null){
                    return this.$enumUtils.toMsg('SuccessAndFail', result);
                }else{
                    return '未处理';
                }

            },

            /** 处理分页操作*/
            handleCurrentChange() {
                this.loanBackedList = this.backedData()
            },

             /** 关闭处理 */
            handleClose() {
                this.visible = false;
                setTimeout(() => {
                    this.$emit('update:dialogVisible', false)
                }, 300);
            },

            //参数
            buildParam() {
                var return_hash = {
                    size: this.page.size,
                    current: this.page.current,
                      result: 'FAIL',
                };
                if (this.formInline.backedNo != '') {
                    return_hash['clientCell'] = this.formInline.clientCell
                }
                return return_hash;
            },
            // 人工线下打款列表
            buildHandParam() {
                var return_hash = {
                    size: this.page.size,
                    current: this.page.current,
                };
                if (this.formInline.backedNo != '') {
                    return_hash['clientCell'] = this.formInline.clientCell
                }
                return return_hash;
            },

            buildParamRefuse(record) {
                var return_hash = {
                    size: this.page.size,
                    current: this.page.current,
                };
                if (record.derateNo != '') {
                    return_hash['derateNo'] = record.derateNo
                }
              
                if (this.loginName != '') {
                    return_hash['confirmUser'] = this.loginName
                }
                return return_hash;
            },
        }
    }


</script>

<style scoped>

</style>