<template>
    <div>
        <div class="content-head">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item>招标管理 </el-breadcrumb-item>
                <el-breadcrumb-item>招标项目管理</el-breadcrumb-item>
                <el-breadcrumb-item>发布项目</el-breadcrumb-item>
            </el-breadcrumb>
            <h3>编辑项目</h3>
            <h5>编辑招标项目</h5>
        </div>
        <div class="othercontent">
            <!--  项目信息 -->
            <div class="message1">
                <messaage ref="message" :ruleForm="detail"></messaage>
            </div>
            <!-- 标的需求 -->
            <div class="demand">
                <demand ref="demand" :ruleForm="detail"></demand>
            </div>
            <!-- 招标时间设置 -->
            <div class="timeSet">
                <timeSet ref="timeSet" :ruleForm="detail"></timeSet>
            </div>
            <!-- 招标文件上传 -->
            <div class="fileUpload">
                <fileUpload ref="fileUpload" :ruleForm="detail" :limit="3"></fileUpload>
            </div>
        </div>
        <div class="centerButton ">
            <el-button @click="noedit">取消</el-button>
            <el-button @click="edit">提交</el-button>
        </div>
    </div>
</template>

<script>
import { editProject } from '@api/purchaser/bid';
import { getTime1 } from '@utils/time';
import { projectdetail } from '@api/supply/bid';
import messaage from './message.vue';
import demand from './demand.vue';
import timeSet from './timeSet.vue';
import fileUpload from './fileUpload.vue';
export default {
    components: {
        messaage,
        demand,
        timeSet,
        fileUpload
    },
    data() {
        return {
            activeIdx: 0,
            allForm: {},
            detail: {
                projectName: '项目1'
            }
        };
    },
    created() {
        this.getenquiryProjectId();
    },
    methods: {
        /* 取消 */
        noedit(){
            this.$router.go(-1)
        },
        async edit() {
            await this.$refs.message.next();
            await this.$refs.timeSet.next();
            await this.$refs.fileUpload.next();
            console.log('通过');
            console.log(this.detail)
              const { msg, code } = await editProject(this.detail);
                if (code == 200) {
                    this.$message({
                        message: msg,
                        type: 'success',
                        duration: 1500
                    });
                    setTimeout(() => {
                        this.$router.go(-1)
                    }, 1500);
                } else {
                    this.$message.error(msg);
                }
        },
        // 获取详情
        async getenquiryProjectId() {
            let projectId = localStorage.getItem('projectId');
            const { data, code } = await projectdetail(projectId);
            if (code == 200) {
                data.endTime = getTime1(data.endTime);
                data.startTime = getTime1(data.startTime);
                data.createTime = data.createTime.substring(0, 10);
                data.bidBookInfoPO = data.bidBookInfoDO;
                data.earnestInfoPO = data.earnestInfoDO;
                let userInfo = JSON.parse(localStorage.getItem('userInfo'));
                data.purchaseAgent = userInfo.companyName;
                for (let item of data.accessoryDOList) {
                    item.url = item.accessoryUrl;
                    item.name = item.fileName;
                }
                let bidBookPO = [];
                bidBookPO.push(data.bidBookPO);
                data.bidBookPO = bidBookPO;
                for (let item of data.bidBookPO) {
                    item.url = item.fileUrl;
                    item.name = item.fileName;
                }
                for (let item of data.bidBookAccessoryPOList) {
                    item.url = item.fileUrl;
                    item.name = item.fileName;
                }
                console.log(data);
                this.detail = data;
            }
        }
    }
};
</script>

<style scoped>
.steps {
    width: 800px;
    margin: 0 auto;
    padding: 30px 0;
}

.othercontent > div {
    background: #fff;
    margin-bottom: 30px;
}

.bid {
    margin-top: -20px;
}

.button {
    display: flex;
    justify-content: flex-end;
    padding-bottom: 20px;
    margin-right: 20px;
}
.centerButton{
    display: flex;
    justify-content: center;
}
</style>
