<template>
    <div style="color: #666">
        <div style="margin: 10px 0">
            <el-input size="small" style="width: 300px" placeholder="请输入名称" suffix-icon="el-icon-search" v-model="name"></el-input>
            <el-button class="ml-5" type="primary" @click="load" size="small">搜索</el-button>
            <el-button type="warning" @click="reset" size="small">重置</el-button>
        </div>

        <div style="margin: 10px 0" >
         <!--   <div style="padding: 10px 0; border-bottom: 1px dashed #ccc" v-for="item in tableData" :key="item.id" v-if="item.state==='审核通过'&&item.states==='待开标'">
                <div class="pd-10" style="font-size: 20px; color: #3F5EFB; cursor: pointer" @click="$router.push('/bidsDetail?id=' + item.id)">{{ item.name }}</div>
                <div style="font-size: 14px; margin-top: 10px" >
                    <i class="el-icon-user-solid"></i> <span>{{ item.user }}</span>
                    <i class="el-icon-time" style="margin-left: 10px"></i> <span>{{ new Date(item.time).toLocaleDateString() }}</span>
                </div>
            </div>-->
            <div style="padding: 10px 0; border-bottom: 1px dashed #ccc" v-for="item in tableData" :key="item.id" v-if="item.state==='审核通过'&&item.states==='待开标'&&item.type==1&&!(new Date() >Date.parse(item.overtime))">
                <el-descriptions class="margin-top" title="货物项目" :column="3" :size="size" border>
                   <el-descriptions-item>
                        <template slot="label">
                            <i class="el-icon-document"></i>招标项目名称</template>
                       <el-tooltip class="item" effect="dark" content="点我查看详情" placement="left">
                        <div class="pd-10" style="font-size: 15px; color: black; cursor: pointer" @click="$router.push('/bidsDetail?id=' + item.id)">{{ item.name }}</div>
                       </el-tooltip>
                    </el-descriptions-item>
                    <el-descriptions-item>
                        <template slot="label">
                            <i class="el-icon-user"></i>发布人</template>
                       <span style="color: #409EFF">{{ item.user }}</span>
                    </el-descriptions-item>
                    <el-descriptions-item>
                        <template slot="label">
                            <i class="el-icon-tickets"></i>备注</template>
                        <el-tag size="small" >货物类型项目</el-tag>
                    </el-descriptions-item>
                    <el-descriptions-item>
                        <template slot="label">
                            <i class="el-icon-time"></i>项目开始时间</template>
                    <span style="color: #FF0000">{{ new Date(item.time).toLocaleDateString()}}</span>
                    </el-descriptions-item>
                    <el-descriptions-item>
                        <template slot="label">
                            <i class="el-icon-time"></i>项目结束时间</template>
                        <span style="color: #FF0000">{{ new Date(item.overtime).toLocaleDateString()}}</span>
                    </el-descriptions-item>


                </el-descriptions>
             <!--   <el-descriptions title="货物项目" :column="3" border>
                    <el-descriptions-item label="招标项目名称" labelClassName="my-label" >
                        <div class="pd-10" style="font-size: 15px; color: #3F5EFB; cursor: pointer" @click="$router.push('/bidsDetail?id=' + item.id)">{{ item.name }}</div>
                    </el-descriptions-item>
                    <el-descriptions-item label="发布人">{{ item.user }}</el-descriptions-item>
                    <el-descriptions-item label="备注">
                        <el-tag size="small">货物类型项目</el-tag>
                    </el-descriptions-item>
                    <el-descriptions-item label="项目开始时间">{{ new Date(item.time).toLocaleDateString() }}</el-descriptions-item>

                    <el-descriptions-item label="项目结束时间" >{{ new Date(item.overtime).toLocaleDateString() }}</el-descriptions-item>
                </el-descriptions>-->
            </div>
            <div style="padding: 10px 0; border-bottom: 1px dashed #ccc" v-for="item in tableData" :key="item.id" v-if="item.state==='审核通过'&&item.states==='待开标'&&item.type==3&&!(new Date() >Date.parse(item.overtime))">
                <el-descriptions class="margin-top" title="工程项目" :column="3" :size="size" border >
                    <el-descriptions-item >
                        <template slot="label" >
                            <i class="el-icon-document"></i>招标项目名称</template>
                        <el-tooltip class="item" effect="dark" content="点我查看详情" placement="left">
                        <div class="pd-10" style="font-size: 15px; color: black; cursor: pointer" @click="$router.push('/bidsDetail?id=' + item.id)">{{ item.name }}</div>
                        </el-tooltip>
                    </el-descriptions-item>
                    <el-descriptions-item>
                        <template slot="label">
                            <i class="el-icon-user"></i>发布人</template>
                       <span style="color: #409EFF">{{ item.user }}</span>
                    </el-descriptions-item>
                    <el-descriptions-item>
                        <template slot="label">
                            <i class="el-icon-tickets"></i>备注</template>
                        <el-tag size="small" type="success">工程类型项目</el-tag>
                    </el-descriptions-item>
                    <el-descriptions-item>
                        <template slot="label">
                            <i class="el-icon-time"></i>项目开始时间</template>
                        <span style="color: #FF0000">{{ new Date(item.time).toLocaleDateString()}}</span>
                    </el-descriptions-item>
                    <el-descriptions-item>
                        <template slot="label">
                            <i class="el-icon-time"></i>项目结束时间</template>
                        <span style="color: #FF0000">{{ new Date(item.overtime).toLocaleDateString()}}</span>
                    </el-descriptions-item>


                </el-descriptions>
            </div>
            <div style="padding: 10px 0; border-bottom: 1px dashed #ccc" v-for="item in tableData" :key="item.id" v-if="item.state==='审核通过'&&item.states==='待开标'&&item.type==2&&!(new Date() >Date.parse(item.overtime))">
                <el-descriptions class="margin-top" title="服务项目" :column="3" :size="size" border >
                    <el-descriptions-item>
                        <template slot="label">
                            <i class="el-icon-document"></i>招标项目名称</template>
                        <el-tooltip class="item" effect="dark" content="点我查看详情" placement="left">
                        <div class="pd-10" style="font-size: 15px; color: black; cursor: pointer" @click="$router.push('/bidsDetail?id=' + item.id)">{{ item.name }}</div>
                        </el-tooltip>
                    </el-descriptions-item>
                    <el-descriptions-item>
                        <template slot="label">
                            <i class="el-icon-user"></i>发布人</template>
                        <span style="color: #409EFF">{{ item.user }}</span>
                    </el-descriptions-item>
                    <el-descriptions-item>
                        <template slot="label">
                            <i class="el-icon-tickets"></i>备注</template>
                        <el-tag size="small" type="warning">服务类型项目</el-tag>
                    </el-descriptions-item>
                    <el-descriptions-item>
                        <template slot="label">
                            <i class="el-icon-time"></i>项目开始时间</template>
                        <span style="color: #FF0000">{{ new Date(item.time).toLocaleDateString()}}</span>
                    </el-descriptions-item>
                    <el-descriptions-item>
                        <template slot="label">
                            <i class="el-icon-time"></i>项目结束时间</template>
                        <span style="color: #FF0000">{{ new Date(item.overtime).toLocaleDateString()}}</span>
                    </el-descriptions-item>


                </el-descriptions>
            </div>
            <div style="padding: 10px 0; border-bottom: 1px dashed #ccc" v-for="item in tableData" :key="item.id" v-if="item.state==='审核通过'&&item.states==='待开标'&&item.type==4&&!(new Date() >Date.parse(item.overtime))">
                <el-descriptions class="margin-top" title="电子项目" :column="3" :size="size" border >
                    <el-descriptions-item>
                        <template slot="label"><i class="el-icon-document"></i>招标项目名称</template>
                        <el-tooltip class="item" effect="dark" content="点我查看详情" placement="left">
                        <div class="pd-10" style="font-size: 15px; color: black; cursor: pointer" @click="$router.push('/bidsDetail?id=' + item.id)">{{ item.name }}</div>
                        </el-tooltip>
                    </el-descriptions-item>
                    <el-descriptions-item>
                        <template slot="label">
                            <i class="el-icon-mobile-phone"></i>发布人</template>
                        <span style="color: #409EFF">{{ item.user }}</span>
                    </el-descriptions-item>
                    <el-descriptions-item>
                        <template slot="label">
                            <i class="el-icon-tickets"></i>备注</template>
                        <el-tag size="small" type="info">电子类型项目</el-tag>
                    </el-descriptions-item>
                    <el-descriptions-item>
                        <template slot="label">
                            <i class="el-icon-time"></i>项目开始时间</template>
                        <span style="color: #FF0000">{{ new Date(item.time).toLocaleDateString()}}</span>
                    </el-descriptions-item>
                    <el-descriptions-item>
                        <template slot="label">
                            <i class="el-icon-time"></i>项目结束时间</template>
                        <span style="color: #FF0000">{{ new Date(item.overtime).toLocaleDateString()}}</span>
                    </el-descriptions-item>


                </el-descriptions>
            </div>
        </div>


        <div style="padding: 10px 0">
            <el-pagination
                    @size-change="handleSizeChange"
                    @current-change="handleCurrentChange"
                    :current-page="pageNum"
                    :page-sizes="[2, 5, 10, 20]"
                    :page-size="pageSize"
                    layout="total, prev, pager, next"
                    >
            </el-pagination>
        </div>
    </div>
</template>

<script>

    import axios from "axios";

    export default {
        name: "bidding",
        data() {
            return {
                form: {},
                tableData: [],
                name: '',
                multipleSelection: [],
                pageNum: 1,
                pageSize: 10,
                total: 0,
                dialogFormVisible: false,
                teachers: [],
                user: localStorage.getItem("user") ? JSON.parse(localStorage.getItem("user")) : {},
                content: '',
                viewDialogVis: false
            }
        },
        created() {
            this.load()
            this.request.get("/bids").then(res => {
                this.article = res.data.splice(0, 5)

            })
        },
        methods: {
            view(content) {
                this.content = content
                this.viewDialogVis = true
            },
            // 绑定@imgAdd event
            imgAdd(pos, $file) {
                let $vm = this.$refs.md
                // 第一步.将图片上传到服务器.
                const formData = new FormData();
                formData.append('file', $file);
                axios({
                    url: 'http://localhost:9090/file/upload',
                    method: 'post',
                    data: formData,
                    headers: {'Content-Type': 'multipart/form-data'},
                }).then((res) => {
                    // 第二步.将返回的url替换到文本原位置![...](./0) -> ![...](url)
                    $vm.$img2Url(pos, res.data);
                })
            },
            load() {
                this.request.get("/bids/page", {
                    params: {
                        pageNum: this.pageNum,
                        pageSize: this.pageSize,
                        name: this.name,
                    }
                }).then(res => {

                    this.tableData = res.data.records
                    this.total = res.data.total

                })

            },
            changeEnable(row) {
                this.request.post("/bids/update", row).then(res => {
                    if (res.code === '200') {
                        this.$message.success("操作成功")
                    }
                })
            },
            handleAdd() {
                this.dialogFormVisible = true
                this.form = {}
            },
            handleEdit(row) {
                this.form = JSON.parse(JSON.stringify(row))
                this.dialogFormVisible = true
            },
            del(id) {
                this.request.delete("/bids/" + id).then(res => {
                    if (res.code === '200') {
                        this.$message.success("删除成功")
                        this.load()
                    } else {
                        this.$message.error("删除失败")
                    }
                })
            },
            handleSelectionChange(val) {
                console.log(val)
                this.multipleSelection = val
            },
            delBatch() {
                let ids = this.multipleSelection.map(v => v.id)  // [{}, {}, {}] => [1,2,3]
                this.request.post("/bids/del/batch", ids).then(res => {
                    if (res.code === '200') {
                        this.$message.success("批量删除成功")
                        this.load()
                    } else {
                        this.$message.error("批量删除失败")
                    }
                })
            },
            save() {
                this.request.post("/bids", this.form).then(res => {
                    if (res.code === '200') {
                        this.$message.success("保存成功")
                        this.dialogFormVisible = false
                        this.load()
                    } else {
                        this.$message.error("保存失败")
                    }
                })
            },
            reset() {
                this.name = ""
                this.load()
            },
            handleSizeChange(pageSize) {
                console.log(pageSize)
                this.pageSize = pageSize
                this.load()
            },
            handleCurrentChange(pageNum) {
                console.log(pageNum)
                this.pageNum = pageNum
                this.load()
            },
            download(url) {
                window.open(url)
            },
        }
    }
</script>

<style scoped>
    .item {
        margin: 4px;
    }
</style>