<template>
  <div>
    <div class="content-head">
      <dataBreadcrumb :breads="breads"></dataBreadcrumb>
      <h3>中标通知书编辑</h3>
      <h5>中标通知书编辑</h5>
    </div>
    <div class="content ">
      <div class="message flex-colunm">
        <div class="flex-between">
        <div>项目编号：{{projectCode}}</div>
        <div>项目名称：{{projectName}}</div>
        </div>
        <div class="flex-between">
          <div>日期：{{ winDate}}</div>
          <div>*中标金额：{{money}}元</div>
        </div>
        <div>
          <div class="flex" style="margin-bottom:50px">
            <div class="adjustment">上传附件：</div>
            <singleUpload :limit='1' tip="支持上传一个pdf格式文件，大小不超过100M。" accept='.pdf' @input="getfile"></singleUpload>
          </div>
          <div>
            <el-form ref="ruleForm" :model="ruleForm" :rules="rules" label-width="120px" class="demo-ruleForm">
              <el-form-item label="中标通知书编号" prop="number">
                <el-input v-model="ruleForm.number" placeholder="请输入" oninput="value=value.replace(/[^\d]/g,'')"></el-input>
              </el-form-item>
            </el-form>
          </div>
        </div>
        <div class="flex-center button">
          <el-button @click="back">取消</el-button>
          <el-button type="primary" @click="submitData">保存</el-button>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import {generateNumber} from '@api/common/list'
import {getTime } from '@utils/time'	
import { editSentBook} from '@api/purchaser/bid'
import dataBreadcrumb from '@components/dataBreadcrumb.vue'
import singleUpload from '@components/Upload/Upload.vue'
export default {
  components: {
    dataBreadcrumb,
    singleUpload
  },
  data() {
    return {
		money:"",
		winDate:"",
		projectCode:"",
		projectName:"",
		resultId:"",
      ruleForm: {
        number: '',
		fileList:[]
      },
      rules: {
        number: [{
          required: true,
          message: '请填写编号',
          trigger: 'blur'
        }]
      },
      breads: ['招标管理', '招标项目管理', '工作台']
    }
  },
  created() {
	  this.getGenerateNumber();
	  this.resultId=this.$route.query.id;
	  this.money=this.$route.query.money
	  this.winDate=this.$route.query.winDate.split(" ")[0]
	  this.projectCode=localStorage.getItem("projectCode")
	  this.projectName=localStorage.getItem("projectName")
  },
  methods: {
	  back(){
		this.$router.go(-1)  
	  },
	  getfile(val){
		this.ruleForm.fileList=val
	  },
	    async getGenerateNumber() {
	        try {
	          const {
	            data,
	            code
	          } = await generateNumber(4)
			  this.ruleForm.number=data
	        } catch (e) {
	          console.log(e)
	        }
	      },
   //提交表单
   async submitData() {
         try {
           const valid = await this.$refs['ruleForm'].validate()
           if (valid) {
			   let ruleForm=this.ruleForm;
			   ruleForm.id=this.resultId
			   ruleForm.projectId=localStorage.getItem("projectId")
			   ruleForm.companyId=localStorage.getItem("companyId")
             const { code,msg } = await editSentBook(ruleForm);
             if (code === 200) {
               this.$message({
                            message: msg,
                            type: 'success',
              			  duration:1500
                          })
              			setTimeout(()=>{
              				 this.$router.go(-1)
              			},1500)
             }else{
				 this.$message.error(msg)
			 }
           }
         } catch (e) {
          console.log(e)
       }
   }
  }

}
</script>


<style scoped>
	.message>div{
	margin-bottom: 30px;
	width: 50%;
	}
	.message>.button{
		margin:100px
	}
</style>
