<template>
    <div>
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item>
                    <i class="el-icon-lx-cascades"></i> 账户管理
                </el-breadcrumb-item>
                <el-breadcrumb-item>摘牌方开户审核</el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="container">
            <div class="handle-box">
                <el-input v-model="query.firm_name" placeholder="机构名称" class="handle-input mr10"></el-input>
                <el-input v-model="query.phone"  placeholder="账户号码" class="handle-input mr10"></el-input>
                <el-input v-model="query.username" placeholder="申请人名称" class="handle-input mr10"></el-input>
                <el-select v-model="query.enter_shop_type" placeholder="挂牌方" class="handle-select mr10">
                    <el-option key="1" label="是" :value="1"></el-option>
                    <el-option key="2" label="否" :value="0"></el-option>
                </el-select>
                <el-select v-model="query.third_party_type" placeholder="第三方服务机构" class="handle-select mr10">
                    <el-option key="1" label="是" :value="1"></el-option>
                    <el-option key="2" label="否" :value="0"></el-option>
                </el-select>
                <el-select v-model="query.audit_status" placeholder="审核状态" class="handle-select mr10">
                    <el-option key="1" label="已通过" :value="1"></el-option>
                    <el-option key="2" label="待审核" :value="0"></el-option>
                    <el-option key="3" label="未通过" :value="2"></el-option>
                </el-select>
                <el-date-picker
                    class="mr10"
                    v-model="query.time"
                    type="datetimerange"
                    :picker-options="pickerOptions"
                    range-separator="至"
                    value-format="timestamp"
                    start-placeholder="开始日期"
                    end-placeholder="结束日期"
                    align="right"
                >
                </el-date-picker>
                <el-button type="primary" icon="el-icon-search" @click="handleSearch">搜索</el-button>
                <el-button type="primary" plain  @click="reset">重置</el-button>
            </div>
            <el-table
                :data="tableData"
                border
                class="table"
                ref="multipleTable"
                header-cell-class-name="table-header"
            >
                <el-table-column prop="id" label="序号" width="55" align="center"></el-table-column>
                <el-table-column :formatter="formatDate" prop="create_time" label="申请时间"></el-table-column>
                <el-table-column label="机构名称" prop="firm_name"></el-table-column>
                <el-table-column label="账户号码" prop="phone"></el-table-column>
                <el-table-column prop="apply_name" label="申请人名称"></el-table-column>
                <el-table-column prop="is_enter_shop" label="挂牌方开户/第三方服务机构开户" align="center" width="250">
                    <template slot-scope="scope">
                        <span>{{scope.row.is_enter_shop==1 ? '是':'否'}}</span>
                        <span> /{{scope.row.is_third_party==1 ? '是':'否'}}</span>
                    </template>
                </el-table-column>
                <!-- <el-table-column prop="is_third_party" label="是否第三方服务机构">
                    <template slot-scope="scope">
                        
                    </template>
                </el-table-column> -->

                <el-table-column prop="audit_status" label="审核状态">
                    <template slot-scope="scope">
                        <span v-if="scope.row.audit_status==1">已通过</span>
                        <span v-else-if="scope.row.audit_status==0">待审核</span>
                        <span v-else>未通过</span>
                    </template>
                </el-table-column>
                <el-table-column label="操作" width="280" align="center">
                    <template slot-scope="scope">
                        <el-button
                            type="text"
                            @click="handleEdit(scope.$index, scope.row)"
                        >资料审核</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination">
                <el-pagination
                    background
                    layout="total, prev, pager, next"
                    :current-page="query.page"
                    :page-size="query.limit"
                    :total="pageTotal"
                    @current-change="handlePageChange"
                ></el-pagination>
            </div>
        </div>

        <whyDialog v-if="editVisible" :isshow="editVisible" :dialogID="dialogID" :dialogType="dialogType" @MisShow="MisShow" @getData="getData" :isexamine="true" :account_type="query.type"></whyDialog>
    </div>
</template>

<script>
import { applyList } from '../../../api/index';
import moment from 'moment'
export default {
    name: 'basetable',
    data() {
        return {
            query: {
                firm_name: '',
                phone: '',
                username: '',
                buyer_account_type: '',
                enter_shop_type: '',
                third_party_type: '',
                audit_status: '',
                time: '',
                page: 1,
                limit: 10,
                type:'buyer'
            },
            tableData: [],
            multipleSelection: [],
            delList: [],
            editVisible: false,
            pageTotal: 0,
            dialogType:1,
            dialogID:'',
            pickerOptions: {
                shortcuts: [
                    {
                    text: "最近一周",
                    onClick(picker) {
                        const end = new Date();
                        const start = new Date();
                        start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
                        picker.$emit("pick", [start, end]);
                    },
                    },
                    {
                    text: "最近一个月",
                    onClick(picker) {
                        const end = new Date();
                        const start = new Date();
                        start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
                        picker.$emit("pick", [start, end]);
                    },
                    },
                    {
                    text: "最近三个月",
                    onClick(picker) {
                        const end = new Date();
                        const start = new Date();
                        start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
                        picker.$emit("pick", [start, end]);
                    },
                    },
                ],
            },
        };
    },
    components:{
        whyDialog: () => import('../../common/dialog/insex.vue')
    },
    created() {
        this.getData();
    },
    methods: {
        MisShow(){
            this.editVisible=false
        },
        // 重置方法
        reset(){
            Object.keys(this.query).forEach(key => {
                console.info(key)
                if (key!='page' && key!='limit') {
                    this.query[key] = ''
                }
            });
        },
        //时间戳转换时间
        formatDate(row,colnum){
            return moment(row[colnum.create_time]).format('YYYY-MM-DD HH:mm:ss')
        },
        // 获取 easy-mock 的模拟数据
        getData() {
            applyList(this.query).then(res => {
                console.log(res);
                if (res.code==100) {
                    this.tableData = res.data.list;
                    this.pageTotal = res.data.count;
                }
            });
        },
        // 触发搜索按钮
        handleSearch() {
            this.$set(this.query, 'page', 1);
            this.getData();
        },
        // 编辑操作
        handleEdit(index, row) {
            this.editVisible = true;
            this.dialogID=row.id;
            this.dialogType=1
        },
        // 保存编辑
        saveEdit() {
            this.editVisible = false;
            this.$message.success(`修改第 ${this.idx + 1} 行成功`);
            this.$set(this.tableData, this.idx, this.form);
        },
        // 分页导航
        handlePageChange(val) {
            this.$set(this.query, 'page', val);
            this.getData();
        }
    }
};
</script>

<style scoped>
.handle-box {
    margin-bottom: 20px;
}

.handle-select {
    width: 120px;
}

.handle-input {
    width: 150px;
    display: inline-block;
}
.table {
    width: 100%;
    font-size: 14px;
}
.red {
    color: #ff0000;
}
.mr10 {
    margin-right: 10px;
}
.table-td-thumb {
    display: block;
    margin: auto;
    width: 40px;
    height: 40px;
}
</style>
