<template>
  <div>
    <el-button slot="reference" size="mini" style="width:100%" @click="onShow" type="primary" >审 核</el-button>
    <el-dialog title="报价单审核" :visible.sync="draw" width="20%" append-to-body>
      <span>确定通过该报价单的审核吗？</span>
      <div slot="footer" class="dialog-footer">
        <el-button size="mini" @click="draw = false">取 消</el-button>
        <el-button type="primary" size="mini" @click="breakShow">退 回</el-button>
        <el-button type="primary" size="mini" @click="onExamine">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  name: "examineTo",
  props:["sa_quotedpriceid","disabled"],
  data(){
    return {
      draw:false,
      examineDraw:false,
      form: {
        name: '',
        backreason:'',
        region: '',
        date1: '',
        date2: '',
        delivery: false,
        type: [],
        resource: '',
        desc: ''
      },
      rules:{
        backreason:[
          { required: true, message: '还未填写退回原因', trigger: 'change'},
        ],
      },
      formLabelWidth: '120px'
    }
  },
  methods:{
    async CheckRow(){
      console.log("报价单id"+this.sa_quotedpriceid)
      const res = await this.$api.requested({
        "id": 20221020165403,
        "version":1,
        "content": {
          "sa_quotedpriceid":this.sa_quotedpriceid,
          "ischeck":true
        }
      })
      this.tool.showMessage(res,()=>{
        console.log(res)
        this.$emit("onExamine")
      })
    },
    onShow(){
      this.$confirm('是否通过该报价单的审核?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.CheckRow()
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消审核'
        });
      });
    },
    breakShow(){
      this.draw = false
      this.examineDraw = true
      this.$prompt('请输入退回原因', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        inputValidator: (value => {
          if (!value){
            return '请输入退回原因'
          }
        }),
      }).then(({ value }) => {
        this.onBack(value)
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '取消审核'
        });
      });
    },
    onExamine(){
      console.log("审核操作开始")
      if (this.form.backreason === ''){
        console.log("执行222")
        this.CheckRow()
      }else{
        console.log("执行1111")
        this.onBack()
      }
    },
    async onBack(val){
      console.log("执行")
      /*this.$refs.form.validate(async (valid) => {
        if (!valid) return false*/
        const res = await this.$api.requested({
          "id":20221125162803,
          "version":1,
          "content":{
            "sa_quotedpriceid":this.sa_quotedpriceid,
            "backreason":val
          }
        })
        this.tool.showMessage(res,()=>{
          console.log(res)
          this.$emit("onExamine")
        })
      /*})*/
    }
  }
}
</script>

<style scoped>

</style>