<template>
  <div >
    <el-button :type="disabled?'':'primary'"  size="small"  @click="onshow" :disabled="disabled">审 核</el-button>
  </div>
</template>

<script>
export default {
  props:["rowData","disabled"],
  name: "toExamine",
  data(){
    return {
      flag:false
    }
  },
  methods:{
    onshow(){
      this.flag = false
      this.rowData.forEach(e => {
        console.log(e)
        if (e.status === '审核'){
          this.flag = true
        }
      })
      console.log(this.flag)
      if (this.flag){
        this.$alert('所选数据中已有数据被审核，请检查后再进行操作', '提示', {
          confirmButtonText: '确定',
          callback: action => {
            this.$message({
              type: 'info',
              message: `请检查所选数据`
            });
          }
        });
      }else {
        this.onExamine()
      }
    },
    onExamine(){
      this.$confirm('确定通过这些数据的审核吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(async () => {
        console.log(this.rowData)
        let row = []
        this.rowData.forEach(function (item,index) {
          console.log(index)
          console.log(item)
          row[index] = item.itemid
        })
        console.log(row)
        const res = await this.$api.requested({
          "id": 20220923153902,
          "content": {
            "itemids": row,
            "status": 1 //0：不通过，1：通过
          },
        })
        this.tool.showMessage(res,()=>{
          this.$emit('examineSuccess')
        })
      }).catch((err) => {
        console.log(err)
        this.$message({
          type: 'info',
          message: '已取消审核'
        });
      });
    }
  }
}
</script>

<style scoped>

</style>