<template>
  <div >
    <div class="content">
      <dataBreadcrumb :breads="breads"></dataBreadcrumb>
      <changeNav :navs="navs"></changeNav>
      <dataTable :table-data="tableData" :columns="columns" :is-pageobj="false" >
        <el-table-column slot="code" label="中标通知书编号" align="center" fixed="right">
          <template slot-scope="scope">
            <div v-if="scope.row.number">{{scope.row.number}}</div>
            <div v-else>(空)</div>
          </template>
        </el-table-column>
        <el-table-column slot="operate" label="操作" align="center" fixed="right" width="150">
          <template slot-scope="scope">
            <el-button type="text" size="small" @click="edit(scope.row)">通知书编辑</el-button>
          </template>
        </el-table-column>
      </dataTable>
      <div class="button flex-center">
        <el-button @click="back">返回</el-button>
        <el-button type="primary" @click="submitData">提交</el-button>
      </div>
    </div>
  </div>
</template>

<script>
	import {
		resultBookList,
		resultBookAduit
	} from '@api/purchaser/bid'
import dataTable from '@components/nopageTable.vue'
import dataBreadcrumb from '@components/dataBreadcrumb.vue'
import changeNav from '@components/changeNav.vue'
export default {
  components: {
    dataTable,
    dataBreadcrumb,
    changeNav
  },
  data() {
    return {
      navs: ['招标结果通知书'],
      breads: ['招标管理', '招标项目管理', '工作台'],
      tableData: [],
      columns: [{
        label: '投标人',
        prop: 'companyName'
      },
      {
        slot: 'code'
      },
      {
        label: '状态',
        prop: 'state'
      },
      {
        label: '接收人',
        prop: 'companyName'
      },
      {
        slot: 'operate'
      }
      ], // 操作列
    }
  },
  created(){
	  this.getresultBookList()
  }, 
 methods: {
 	edit(row) {
 		this.$router.push(`/purchaser/bid/bidSure/bidResult/edit?id=${row.resultId}&winDate=${row.createTime}`)
 	},
 	back() {
 		this.$router.go(-1)
 	},
 	// 获取列表
 	async getresultBookList() {
 		try {
 			let projectId = localStorage.getItem("projectId");
 			const {
 				data,
 				code
 			} = await resultBookList(projectId)
 			if (code === 200) {
 				for (let item of data) {
 					if (item.status == 1) {
 						item.state = "已发送"
 					} else if (item.status == -1) {
 						item.state = "暂存本地"
 					}
 				}
 				this.tableData = data
 			}
 		} catch (e) {
 			console.log(e)
 		}
 	},
 	async submitData() {
 		try {
 			let projectId = localStorage.getItem("projectId")
 			const {
 				msg,
 				code
 			} = await resultBookAduit(projectId)
 			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>
	.button{
		width: 100%;
		height: 400px;
	}
</style>
