<template>
  <div>
    <el-button v-if="flag === 0 && tool.checkAuth($route.name,'putSubmit')" size="mini" :type="!disabled || rowData.status === '已失败' ?'':'primary'" slot="reference" @click="onSubmit" :disabled="!disabled || rowData.status === '已失败'">提交报备</el-button>
    <el-button v-if="flag === 1 && tool.checkAuth($route.name,'putCheck')" size="mini" type="primary" slot="reference" @click="onCheck" >报备审核</el-button>
    <el-button v-if="flag !== 0 && tool.checkAuth($route.name,'putBack') " size="mini" type="primary" slot="reference"  @click="onUnCheck" >报备驳回(退回)</el-button>
  </div>
</template>

<script>
export default {
  name: "add",
  props:['data','rowData','flagTag','disabled'],
  data(){
    return {
      butTag:'',
      form:{
        sa_projectid: '',
        tag: "" //报备中，已报备
      },
      flag:0, //0:未报备，1：报备中 2：报备审核
    }
  },
  methods:{
    onshow(){
      console.log(this.rowData)
      /*this.tagData()*/
    },
    onSubmit(){
      this.$confirm('确定进行提交报备操作吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(async() => {
        const res = await this.$api.requested({
          "id": 20221114163402,
          "content": {
            "sa_projectid": this.rowData.sa_projectid,
            "type": 1 //报备中，已报备
          },
        })
        this.tool.showMessage(res,()=>{
          this.flag = 1
          this.$emit('putSuccess',this.flag)
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消提交报备'
        });
      });
    },
    onCheck(){
      this.$confirm('确定进行报备审核操作吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(async() => {
        const res = await this.$api.requested({
          "id": 20221114163402,
          "content": {
            "sa_projectid": this.rowData.sa_projectid,
            "type": 2 //报备中，已报备
          },
        })
        this.tool.showMessage(res,()=>{
          this.flag = 2
          this.$emit('putSuccess',this.flag)
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消报备审核'
        });
      });
    },
    onUnCheck(){
      this.$confirm('确定进行报备驳回(退回)操作吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(async() => {
        const res = await this.$api.requested({
          "id": 20221114163402,
          "content": {
            "sa_projectid": this.rowData.sa_projectid,
            "type": 3 //报备中，已报备
          },
        })
        this.tool.showMessage(res,()=>{
          this.flag = 0
          this.$emit('putSuccess',this.flag)
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消报备驳回(退回)'
        });
      });
    },
    async tagData(){
      console.log(this.rowData.sa_projectid,"rowData数据")
      const res = await this.$api.requested({
        content: {
          ownertable: "sa_project",
          ownerid: this.rowData.sa_projectid
        },
        id: 20220929085401
      })
      console.log(res,'标签')
      if (res.data.systemtag.length === 0){
        console.log("还未有报备")
        this.flag = 0
      }else {
        for (let i=0;i<res.data.systemtag.length;i++){
          if (res.data.systemtag[i] === '报备中'){
            this.flag = 1
            break
          }else if (res.data.systemtag[i] === '已报备'){
            this.flag = 2
            break
          }else {
            this.flag = 0
          }
        }
      }
      console.log(this.flag,'报备状态')
    }
  },
  mounted() {
    this.flag = this.flagTag
    console.log("报备状态",this.flagTag,this.flag)
  },
  created() {
  }

}
</script>

<style scoped>
/deep/.el-select {
  width: 100%;
}
</style>