<template>
  <div>
    <div class="describe">上传招标文件</div>
    <div class="padding">
      <div class="details">
       
        <!--  <div class="flex">
          <div class="correct">*文件名称</div>
          <el-input v-model="bidBookPO" style="width: 50%;" placeholder="请输入" clearable>
          </el-input>
        </div> -->
        <el-form ref="ruleForm" :model="ruleForm" :rules="rules" label-width="100px" class="demo-ruleForm">
          <el-form-item label="上传附件" prop="file">
            <upload :limit="1" accept=".pdf" tip="请上传一个招标文件（pdf），不要超过50M。" :max="50" @input="getfile"></upload>
          </el-form-item>
          <el-form-item label="其他附件" >
            <upload :limit="5" tip="最多上传五个附件，单个不超过100M。" :type="1" :max="100" @input="getfile1">
            </upload>
          </el-form-item>
        </el-form>
        <!--   <div>
          <div class="correct">*上传附件</div>
          <upload :file-list="fileList" :limit="1" accept=".pdf" tip="请上传一个招标文件（pdf），不要超过50M。" max="50" @input="getfile"></upload>
        </div>
        <div>
          <div>*其他附件</div>
          <upload :file-list="fileList" :limit="5" tip="最多上传五个附件，单个不超过100M。" max="100" @input="getfile1"></upload>
        </div> -->

      </div>
      <div class="button">
        <el-button @click="upper">上一步</el-button>
        <el-button type="primary" @click="next">发布</el-button>
      </div>
    </div>
  </div>
</template>
<script>
import {
  creatProject
} from '@api/purchaser/bid'

import upload from '@components/Upload/specialUpload.vue'
export default {
  components: {
    upload
  },
  props: {
    allForm: {
      type: Object,
      default() {
        return {}
      }
    }
  },
  data() {
    let checkidentity = (rule, value, callback) => {
      let le
      if (this.ruleForm.bidBookPO.length === 0) {
        callback(new Error('请上传附件'))
      } else {
        callback()
      }
    }
    return {
      ruleForm: {
        bidBookPO: [],
        bidBookAccessoryPOList: []
      },
      fileList: [],
      rules: {
        file: [{
          required: true,
          validator: checkidentity,
          trigger: 'change'
        }],
      }
    }
  },
  methods: {
    getfile(val) {
      this.ruleForm.bidBookPO = val
    },
    getfile1(val) {
      this.ruleForm.bidBookAccessoryPOList = val
    },
    async next() {

      const valid = await this.$refs['ruleForm'].validate()
      console.log(valid)
      if (valid) {
        Object.assign(this.allForm, this.ruleForm)
		let allForm=this.allForm;
		allForm.companyId=localStorage.getItem("companyId")
        const {
          msg,
          code
        } = await creatProject(this.allForm)
        if (code === 200) {
          this.$message({
                        message: msg,
                        type: 'success',
          			  duration:1500
                      })
          			setTimeout(()=>{
          				 this.$router.push("/purchaser/bid/administrationList")
          },1500)
        }
      }
 
    },


    upper() {
      this.$parent.upper()
    }
    // changeType(val) {

    // }
  }

}
</script>

<style scoped>
	.padding {
		padding: 0px 20px 30px 20px
	}

	.details>div {
		margin-bottom: 20px;
	}

	.correct {
		margin-right: 20px;
		margin-top: 5px;
	}

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