<template>
    <div>
        <el-form
            :model="inputQuery"
            :rules="rules"
            ref="inputQuery"
            label-width="100px"
        >
            <el-card class="el-card">
                <el-form :inline="true" :model="logQuery" class="query-form" size="mini">
                    <el-row style="width: 100%">
<!--                        <el-form-item class="query-form-item">-->
<!--                            <el-input-->
<!--                                v-model="logQuery.name"-->
<!--                                placeholder="业务员姓名"-->
<!--                            ></el-input>-->
<!--                        </el-form-item>-->
                        <el-form-item class="query-form-item">
                            <el-select v-model="logQuery.status" placeholder="审核状态">
                                <el-option label="全部" value=""></el-option>
                                <el-option label="未审核" value='1'></el-option>
                                <el-option label="通过" value='2'></el-option>
                                <el-option label="未通过" value='3'></el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item class="query-form-item">
                            <el-select v-model="logQuery.logType" placeholder="审核类型">
                                <el-option label="全部" value=""></el-option>
                                <el-option label="新增审核" value='1'></el-option>
                                <el-option label="变更审核" value='2'></el-option>
                            </el-select>
                        </el-form-item>

                        <el-form-item>
                            <el-button-group>
                                <el-button
                                    type="primary"
                                    icon="el-icon-refresh"
                                    @click="onReset"
                                ></el-button>
                                <el-button type="primary" icon="search" @click="onSubmit"
                                >查询
                                </el-button
                                >
                            </el-button-group>
                        </el-form-item>

                        <el-form-item style="margin: 0 100px 0 auto;">
                            <el-button-group>
                            </el-button-group>
                        </el-form-item>
                    </el-row>
                </el-form>

                <el-table v-loading="loading"
                          :data="dataList"
                          style="width: 100%; height: 500px">
                    <el-table-column type="index" label="序号" width="50"></el-table-column>
                    <el-table-column label="原因" prop="updateCause"></el-table-column>
                    <el-table-column label="审核类型" prop="status" width="150">
                        <template slot-scope="scope">
                            <span>{{ logTypeMap[scope.row.logType] }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="审核状态" prop="status" width="150">
                        <template slot-scope="scope">
                            <span>{{ statusMap[scope.row.status] }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="提交人员" prop="submit"></el-table-column>
                    <el-table-column label="审核人员" prop="auditor"></el-table-column>
                    <el-table-column label="拒绝原因" prop="noPassCause"></el-table-column>
                    <el-table-column label="提交时间" prop="create_time" show-overflow-tooltip width="150">
                        <template slot-scope="scope">
                            <i class="el-icon-time"></i>
                            <span>{{ scope.row.create_time }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="审核时间" prop="update_time" show-overflow-tooltip width="150">
                        <template slot-scope="scope">
                            <i class="el-icon-time"></i>
                            <span>{{ scope.row.update_time }}</span>
                        </template>
                    </el-table-column>
                </el-table>
                <el-pagination
                    :page-size="logQuery.limit"
                    @current-change="handleCurrentChange"
                    layout="prev, pager, next"
                    :total="logTotal"
                    :current-page="logQuery.page"
                >
                </el-pagination>
            </el-card>

        </el-form>
    </div>
</template>

<script>
import store from "../../store/index";
import {
    provinceAndCityData,
    regionData,
    provinceAndCityDataPlus,
    regionDataPlus,
    CodeToText,
    TextToCode,
} from "element-china-area-data";
import {BASE_URL} from "../../config/app";
import {deleteCompanyProductRelevance, filterCompanyProductRelevance} from "../../api/warehouse/companyProductRelevance";
import draggable from "vuedraggable";
import {filterCompanyUpdateLog} from "../../api/warehouse/companyUpdateLog";

export default {
    data() {
        return {
            classesDisplay: false,
            selectedOptions: [],
            options: regionDataPlus,
            rules: {
                companyName: [
                    {
                        required: true,
                        message: "请输入企业名称",
                        trigger: "blur"
                    }
                ],
            },
            uploadUrl: "",
            fileList: [],
            fileUrl: "",
            idQuery: {
                id: "",
            },
            statusMap: {
                1: '未审核',
                2: '通过',
                3: '未通过',
            },
            logTypeMap: {
                1: '新增审核',
                2: '变更审核',
            },
            selectLocalVisible: false,
            logQuery: {
                name: "",
                status: "",
                logType: "",
                page: 1,
                limit: 20
            },
            dataList: [],
            logTotal: 0,
            loading: false,
            uuid: null,
        };
    },
    created() {
        this.getLogList();
    },
    components: {
        draggable,
    },
    methods: {
        onReset() {
            this.logQuery = {
                name: "",
                status: "",
                logType: "",
                page: 1,
                limit: 20
            };
            this.getLogList();
        },
        onSubmit() {
            this.getLogList();
        },
        openFile() {
            window.open(this.fileUrl + this.inputQuery.filePath);
        },
        handleCurrentChange(val) {
            this.logQuery.page = val;
            this.getLogList();
        },
        getLogList() {
            this.loading = true;
            filterCompanyUpdateLog(this.logQuery)
                .then((response) => {
                    this.loading = false;
                    this.dataList = response.data.list || [];
                    this.logTotal = response.data.total || 0;
                })
                .catch(() => {
                    this.loading = false;
                    this.dataList = [];
                    this.logTotal = 0;
                });
        },
        deleteCompanyProductRelevance(row) {
            this.$confirm("是否删除?", "提示", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning",
            }).then(() => {
                this.loading = true;
                let tQuery = {
                    id: row.id,
                };
                deleteCompanyProductRelevance(tQuery)
                    .then((response) => {
                        this.loading = false;
                        if (response.code === 20000) {
                            this.getLogList();
                            this.$message({
                                type: "success",
                                message: "删除成功！",
                            });
                        } else {
                            this.$message.error(response.message);
                        }
                    })
                    .catch(() => {
                        this.loading = false;
                    });
            }).catch(() => {
            });
        },
        closeDialog(type) {
            this.selectLocalVisible = false;
        },
        handleChange(value) {
            this.inputQuery.area =
                CodeToText[value[0]] + CodeToText[value[1]] + CodeToText[value[2]];
            this.inputQuery.areaCode = value.toString();
        },
    }
};
</script>
<style>
.itemTag {
    float: left;
    text-align: left;
    margin-top: 10px;
    width: 120px;
}

.text {
    width: 100%;
    font-size: 13px;
    font-family: "Microsoft YaHei";
}

.el-card {
    margin-right: 20px;
    margin-top: 15px;
    /*transition: all .5s;*/
}

.el-row {
    display: flex;
    flex-wrap: wrap;
}

.el-col {
    border-radius: 4px;
    flex-wrap: wrap;
}
</style>
