<template>
  <div>
    <el-button v-show="data.leader && data.leader[0] && nowUserid === data.leader[0].userid" :disabled="data.status == '已完成'" class="inline-16" type="primary" size="mini" @click="dialogFormVisible = true" >完成任务</el-button>
    <el-dialog title="完成任务" :visible.sync="dialogFormVisible" append-to-body width="500px">
      <el-form :model="form" label-position="top" label-width="90px">
        <el-form-item label="完成说明">
          <el-input v-model="form.finishnotes" type="textarea" :autosize="{minRows:5}" autocomplete="off" placeholder="输入任务完成说明"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false" size="small">取 消</el-button>
        <el-button type="primary" @click="completeTask" size="small">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  props:['data'],
  data () {
    return {
      dialogFormVisible:false,
      form:{
        finishnotes:''
      },
      nowUserid: JSON.parse(sessionStorage.getItem('active_account')).userid
    }
  },
  methods:{
    async completeTask () {
      const res = await this.$api.requested({
        "id":20221211112501,
        "content": {
          "sys_taskid":this.data.sys_taskid,
          "finishnotes": this.form.finishnotes
        }
      })
      this.tool.showMessage(res,()=>{
        this.dialogFormVisible = false
        this.form.finishnotes = ''
        this.$emit('onSuccess')
      })
    }
  }
}

</script>
<style>
</style>