<template>
  <div>
    <!--以下是审批字段-->
    <div v-show="type === '0'">
      <el-form label-width="100px">
        <el-divider></el-divider>
        <el-form-item label="审批意见">
          <el-radio-group v-model="pass">
            <el-radio label="true">同意</el-radio>
<!--            <el-radio label="false">退回修改</el-radio>-->
            <el-radio label="refuse">拒绝</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="批注" prop="remark">
          <el-input v-model="comment" type="textarea" :value="comment" />
        </el-form-item>
      </el-form>
    </div>
    <div slot="footer" class="dialog-footer" style="text-align: right;">
      <el-button v-show="type === '0'" type="primary" @click="complete">确 定</el-button>
      <el-button @click="close">关 闭</el-button>
    </div>
  </div>
</template>

<script>
  import request from '@/utils/request'
  export default {
    name: "ViewVerify",
    props: {
      row: {
        type: Object,
      },
      taskId: {
        type: String,
      },
      type: {
        type: String,
      },
    },
    data() {
      return {
        pass: 'true',
        comment: '',
      }
    },
    methods: {
      close: function () {
        this.$emit('update:open', false);
        this.pass='true'
        this.comment=''
      },
      complete() {
        // this.$parent.$children[0].validate(valid => {
        //   if (valid) {
        if(this.pass=="refuse"){
          if(this.comment.trim()==""){
            this.$modal.alert('请输入审批批注！')
            return ;
          }
          var data = {
            "taskId": this.taskId,
            "instanceId": this.row.instanceId,
            refuse:false,
            "variables": JSON.stringify({
              "comment": this.comment,
              "pass": false,
               refuse:false
              // "formData": this.row,
            }),
          };
        }else if(this.pass=="false"){
          if(this.comment.trim()==""){
            this.$modal.alert('请输入审批批注！')
            return ;
          }
          var data = {
            "taskId": this.taskId,
            "instanceId": this.row.instanceId,
            refuse:true,
            "variables": JSON.stringify({
              "comment": this.comment,
              "pass": false,
              refuse:true
              // "formData": this.row,
            }),
          };
        }else{
          var data = {
            "taskId": this.taskId,
            "instanceId": this.row.instanceId,
            "variables": JSON.stringify({
              "comment": this.comment,
              refuse:true,
              "pass": true,
            }),
          };
        }
            return request({
              url: '/activiti/process/complete',
              method: 'post',
              data: data
            }).then(response => {
              this.close();
              // 刷新待办事项列表（丑陋的代码 👇）
              this.pass='true'
              this.comment=''
              this.$parent.$parent.$parent.$parent.$parent.getList();
              this.$modal.msgSuccess("审批成功");
            });
          // }
        // });
      },
    },
    // watch: {
    //   pass: function(val) {
    //     this.comment = val === 'true' ? '同意' : '驳回';
    //   },
    // },
  }
</script>

<style scoped>

</style>
