<template>

  <el-col :span="1.5">
    <el-button
      type="danger"
      icon="el-icon-edit-outline"
      :size="size"
      @click="handleApprove"
    >{{text}}
    </el-button>


  <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
    <!--以下是审批字段-->
    <div v-show="type === 'todo'">
      <el-form label-width="100px">
        <el-form-item :label="itemTitle" v-if="isSelect">
          <el-radio-group v-model="pass">
            <el-radio label="true">{{item1}}</el-radio>
            <el-radio label="false">{{item2}}</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 === 'todo'" type="primary" @click="complete">确 定</el-button>
      <el-button @click="close">关 闭</el-button>
    </div>
  </el-dialog>
  </el-col>
</template>

<script>
  import request from '@/utils/request'

  export default {
    name: "ViewApprove",
    props: {
      row: {
        type: Object,
      },
      taskId: {
        type: String,
      },
      type: {
        type: String,
      },
      size:{
        type:String,
        default: 'medium'
      },
      text:{
        type:String,
        default: '审核'
      },
      itemTitle: {
        type: String,
        default:"审批意见"
      },
      item1: {
        type: String,
        default:"同意"
      },
      item2: {
        type: String,
        default:"驳回"
      },
      isSelect:{
        type: Boolean,
        default:true
      }
    },
    data() {
      return {
        title: this.text,
        open: false,
        pass: 'true',
        comment:this.item1,
      }
    },
    methods: {
      close: function () {
        this.open=false;
      },
      complete() {


            const data = {
              "taskId": this.taskId,
              "instanceId": this.row.instanceId,
              "variables": JSON.stringify({
                "comment": this.comment,
                "pass": this.pass,
                "formData": this.row,
              }),
            };
            return request({
              url: '/activiti/process/complete',
              method: 'post',
              params: data
            }).then(response => {
              this.close();
              // 刷新待办事项列表（丑陋的代码 👇）
              //window.parent.getTodoList();

              this.msgSuccess("操作成功");

                this.$router.go(-1)// 返回
                //关闭子页面
                this.$store.state.tagsView.visitedViews.splice(this.$store.state.tagsView.visitedViews.findIndex(item => item.path === this.$route.path), 1)
                this.$router.push(this.$store.state.tagsView.visitedViews[this.$store.state.tagsView.visitedViews.length - 1].path)


            });


      },
      handleApprove(){
        console.log('this.row.processKey', this.$refs);

        this.open = true;
      },
    },
    watch: {
      pass: function(val) {
        this.comment = val === 'true' ? this.item1 : this.item2;
      },
    },

  }
</script>

<style scoped>

</style>
