<template>
    <div class="content-main tradingCheckPage">
        <el-form ref="formData" :model="formData" :inline="true" class="search-bm-boder" label-width="72px">
            <el-form-item label="企业名称:">
                <el-input v-model="formData.qymc" clearable placeholder='请输入' class="inputCompatible"></el-input>
            </el-form-item>
            <el-form-item label="注册日期:">
                <el-date-picker
                    class="dateInputCompatible"
                    v-model="datePicker"
                    value-format="yyyy-MM-dd"
                    type="daterange"
                    range-separator="至"
                    format="yyyy-MM-dd"
                    start-placeholder="开始日期"
                    end-placeholder="结束日期"
                ></el-date-picker>
            </el-form-item>
            <el-form-item>
                <div class="search-button">
                    <span class="search-line"></span>
                    <div class="search-select" @click="searchShowMoreBool = !searchShowMoreBool">
                        更多条件
                        <i class="el-icon-arrow-up" v-show="searchShowMoreBool"></i>
                        <i class="el-icon-arrow-down" v-show="!searchShowMoreBool"></i>
                    </div>
                    <el-button type="primary" class="iconfont iconchaxun" size="small"  @click="queryFun">查询</el-button>
                    <el-button type="primary" size="small" class="iconfont iconzhongzhi" @click="resetFun">重置</el-button>
                </div>
            </el-form-item>
            <el-row v-show="searchShowMoreBool"> 
                <el-form-item label="企业信用代码:" label-width="100px">
                    <el-input v-model="formData.tyshxydm" clearable placeholder='请输入' class="inputCompatible"></el-input>
                </el-form-item>
                <el-form-item label="单位代码:">
                    <el-input v-model="formData.dwdm" clearable placeholder='请输入' class="inputCompatible"></el-input>
                </el-form-item>
                <el-form-item label="状态:" label-width="45px">
                    <el-select v-model="formData.qyzt" clearable placeholder="请选择" class="inputCompatible">
                        <el-option v-for="(item,index) in ztData" :key="index" :label="item.name" :value="item.status"></el-option>
                    </el-select>
                </el-form-item>
            </el-row>
        </el-form>
        <el-row>
            <el-col :span="24">
                <el-table
                    :data="tableList"
                    v-loading="loading"
                    border
                    stripe
                    highlight-current-row
                >
                    <el-table-column align="center" label="序号" width="60">
                        <template slot-scope="scope">
                            <span>{{scope.$index+1}}</span>
                        </template>
                    </el-table-column>
                    <el-table-column prop="qymc" label="企业名称" align="center" :show-overflow-tooltip="true"></el-table-column>
                    <el-table-column prop="tyshxydm" label="企业信用代码" align="center" :show-overflow-tooltip="true"></el-table-column>
                    <el-table-column prop="dwdm" label="单位代码" align="center" :show-overflow-tooltip="true"></el-table-column>
                    <el-table-column prop="qylxr" label="联系人" align="center" :show-overflow-tooltip="true"></el-table-column>
                    <el-table-column prop="zcrq" label="注册日期" align="center" :show-overflow-tooltip="true"></el-table-column>
                    <el-table-column prop="qyzt" label="状态" align="center" :show-overflow-tooltip="true" width="200">
                        <template slot-scope="scope">
                            <span v-if='scope.row.qyzt == 1'>待审核</span>
                            <span v-if='scope.row.qyzt == 2'>审核通过</span>
                            <span v-if='scope.row.qyzt == 3'>审核不通过</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="操作" align="center" width="80">
                        <template slot-scope="scope">
                            <el-tooltip class="item" effect="light" content="查看" placement="top">
                                <el-button
                                    type="primary"
                                    size="small"
                                    class="iconfont iconchakan2 operate_show_btn"
                                    @click.stop="goSee(scope.row)"  
                                ></el-button>
                            </el-tooltip>
                            <el-tooltip class="item" effect="light" content="审核" placement="top" v-if="buttonNameList.indexOf('审核') > -1">
                                <el-button
                                    v-if='scope.row.qyzt == 1'
                                    type="primary"
                                    size="small"
                                    class="iconfont iconshenhe operate_edit_btn"
                                    @click="goCheck(scope.row)"
                                ></el-button>
                            </el-tooltip>
                            <el-tooltip class="item" effect="light" content="重置密码" placement="top" v-if="buttonNameList.indexOf('重置密码') > -1">
                                <el-button
                                    v-if='scope.row.qyzt == 2'
                                    type="primary"
                                    size="small"
                                    class="iconfont iconzhongzhimima operate_issued_btn"
                                    @click.stop="goReset(scope.row)"
                                ></el-button>
                            </el-tooltip>
                        </template>
                    </el-table-column>
                </el-table>
                <div class="pag-right clearFix">
                    <el-pagination
                        class="right"
                        @size-change="handleSizeChange"
                        @current-change="handleCurrentChange"
                        :current-page.sync="page.page"
                        :page-sizes="[10,20,30,40]"
                        :page-size="page.size"
                        layout="total, sizes, prev, pager, next, jumper"
                        :total="page.total"
                        v-if="paginationShow"
                    ></el-pagination>
                </div>
            </el-col>
        </el-row>
        <el-dialog
            title="重置密码"
            :visible.sync="dialogVisible"
            width="30%"
            center
            :close-on-click-modal="false"
        >
            <span style='text-align: center;display: block;'>是否重置密码为 "lscbj@123"</span>
            <div class='dialogFooter'>
                <el-button type="primary" size="small" @click="goSure" :loading='btnLoading'>确 定</el-button>
                <el-button type="primary" size="small" @click="dialogVisible = false">取 消</el-button>
            </div>
        </el-dialog>
    </div>
</template>
<script>
import * as management from "@/api/transaction/customerManager"
import { authorityControl } from "@/api/menuList";
export default {
    data() {
        return {
            searchShowMoreBool: false,
            formData: {
                qymc: '',
                zcksrq: '',
                zcjsrq: '',
                tyshxydm: '',
                dwdm: '',
                qyzt: ''
            },
            datePicker: [],
            ztData: [
                {
                    name: '待审核',
                    status: '1'
                },
                {
                    name: '审核通过',
                    status: '2'
                },
                {
                    name: '审核不通过',
                    status: '3'
                },
            ],
            paginationShow: true,
            tableList: [],
            loading: false,
            page: {
                page: 1,
                size: 10,
                total: 0
            },
            buttonNameList: [],
            btnLoading: false,
            dialogVisible: false,
            curUserCode: ''
        }
    },
    created() {
        this.getList()
        this.getresourceCode()
    },
    methods: {
        getresourceCode() {
            let codeData = {
                resourceCode: sessionStorage.getItem("resourceCode"),
                userId: sessionStorage.getItem("userCode")
            };
            authorityControl(codeData).then(res => {
                this.buttonNameList = [];
                res.data.forEach(item => {
                    this.buttonNameList.push(item.resourceName);
                });
            });
        },
        getList() {
            this.loading = true
            this.formData.zcksrq = this.datePicker ? this.datePicker[0] : ''
            this.formData.zcjsrq = this.datePicker ? this.datePicker[1] : ''
            management.checkList(this.formData,this.page).then(res => {
                if(res.infoCode == 200) {
                    this.tableList = res.data.content
                    this.page.total = res.data.totalElements
                }else {
                    this.$message({
                        type: 'error',
                        message: res.msg,
                        duration: 2000
                    })
                }
                this.loading = false
            })
        },
        queryFun() {//查询
            this.paginationShow = false;
            this.handleCurrentChange(1);
            this.$nextTick(() => {
                this.paginationShow = true;
            });
        },
        goReset(row) {//重置密码
            this.btnLoading = false
            this.dialogVisible = true
            this.curUserCode = row.userCode
        },
        goSure() {//确定
            this.btnLoading = true
            management.resetPwd(this.curUserCode).then(res => {
                if(res.infoCode == 200) {
                    this.$message({
                        type: 'success',
                        message: '重置密码成功',
                        duration: 2000
                    })
                    this.dialogVisible = false
                    this.getList()
                }else {
                    this.$message({
                        type: 'error',
                        message: res.msg,
                        duration: 2000
                    })
                    this.btnLoading = false
                }
            })
        },
        goSee(row) {//查看
            this.$router.push({
                path: '/transaction/customerManager/tradingDetail',
                query: {
                    id: row.id,
                    state: 'see'
                }
            })
        },
        goCheck(row) {//审核
            this.$router.push({
                path: '/transaction/customerManager/tradingDetail',
                query: {
                    id: row.id
                }
            })
        },
        resetFun() {//重置
            this.formData = {}
            this.datePicker = []
            this.queryFun()
        },
        handleSizeChange(val) {//条数改变
            this.page.size = val
            this.getList()
        },
        handleCurrentChange(val) {//页数改变
            this.page.page = val
            this.getList()
        }
    }
}
</script>
<style lang="scss">
    .tradingCheckPage {
        .dialogFooter{
            text-align: center;
            margin-top: 20px;
        }
    }
</style>