<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.serial_name" placeholder="资产名称" class="handle-input mr10"></el-input>
                <el-input v-model="query.firm_name" placeholder="机构名称" class="handle-input mr10"></el-input>
                <el-input v-model="query.apply_name" placeholder="法人名称" class="handle-input mr10"></el-input>
                <el-select v-model="query.account_apply" placeholder="审核状态" class="handle-select mr10">
                    <el-option key="4" label="全部" :value="4"></el-option>
                    <el-option key="2" label="湖南省" value="湖南省"></el-option>
                </el-select>
                <el-select v-model="query.auditID" placeholder="审核人员" class="handle-select mr10">
                    <el-option v-for="item in auditList" :key="item.uid" :label="item.username" :value="item.uid"></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"
                @selection-change="handleSelectionChange"
            >
                <el-table-column prop="id" label="序号" width="55" align="center"></el-table-column>
                <el-table-column prop="update_time" :formatter="formatDate" label="申请时间"></el-table-column>
                <el-table-column label="资产名称" prop="serial_name"></el-table-column>
                <el-table-column prop="firm_name" label="机构名称"></el-table-column>
                <el-table-column prop="apply_name" label="法人名称"></el-table-column>
                <el-table-column  label="审核状态">
                    <template slot-scope="scope">
                        <span v-if="scope.row.asset_check_status==0">待审核</span>
                        <span v-else-if="scope.row.asset_check_status==1">审核通过</span>
                    </template>
                </el-table-column>
                <el-table-column  label="审核图片" align="center">
                    <template slot-scope="scope" v-if="scope.row.delist_file_img!=null">
                        <img :src="scope.row.delist_file_img"  width="40" height="40" @click="onPreview([scope.row.delist_file_img])">
                    </template>
                </el-table-column>
                <el-table-column prop="audit_staff_name" label="审核人员"></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>
            <whyDialog v-if="editVisible" :isshow="editVisible" :dialogID="dialogID"
            :dialogType="dialogType" @MisShow="MisShow" :isexamine="true" :assets_type="4" @getData="getData">
            </whyDialog>
        </div>
        <el-image-viewer
            v-if="showViewer"
            :on-close="closeViewer"
            :url-list="showBigImgList"
        />

    </div>
</template>

<script>
import { outCheckList,auditList } from '../../../api/index';
import moment from 'moment'
export default {
    name: 'basetable',
    data() {
        return {
            query: {
                account_name: '',
                firm_name: '',
                account_status: '',
                audit_staff_name:'',
                account_apply: '',
                auditID: '',
                time: '',
                page: 1,
                limit: 10
            },
            showViewer:false,
            showBigImgList:[],
            tableData: [],
            multipleSelection: [],
            delList: [],
            auditList:[],
            editVisible: false,
            pageTotal: 0,
            dialogID:'',
            dialogType:2,
            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();
        this.getAuditList();
    },
    methods: {
        // 关闭查看器
        closeViewer() {
            this.showViewer = false
        },
        onPreview(url) {
            this.showBigImgList=url;
            this.showViewer = true
        },
        MisShow(){
            this.editVisible=false
        },
        //时间戳转换时间
        formatDate(row,colnum){
            return moment(row.create_time *1000).format('YYYY-MM-DD HH:mm:ss')
        },
        // 重置方法
        reset(){
            Object.keys(this.query).forEach(key => {
                console.info(key)
                if (key!='page' && key!='limit') {
                    this.query[key] = ''
                }
            });
        },
        // 审核人员下拉数据
        getAuditList(){
            auditList().then(res => {
                // console.log(res);
                if (res.code==100) {
                    this.auditList=res.data.list
                }
            });
        },
        // 获取 easy-mock 的模拟数据
        getData() {
            outCheckList(this.query).then(res => {
                console.log(res);
                this.tableData = res.data.list;
                this.pageTotal = res.pageTotal || 50;
            });
        },
        // 触发搜索按钮
        handleSearch() {
            this.$set(this.query, 'pageIndex', 1);
            this.getData();
        },
        // 删除操作
        handleDelete(index, row) {
            // 二次确认删除
            this.$confirm('确定要删除吗？', '提示', {
                type: 'warning'
            })
                .then(() => {
                    this.$message.success('删除成功');
                    this.tableData.splice(index, 1);
                })
                .catch(() => {});
        },
        // 多选操作
        handleSelectionChange(val) {
            this.multipleSelection = val;
        },
        // 编辑操作
        handleEdit(index, row) {
            this.editVisible = true;
            this.dialogID=row.id;
        },
        // 保存编辑
        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>
