<!--
 * @Author: ysh
 * @Date: 2024-09-27 15:19:36
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2025-01-09 09:51:00
-->
<template>
  <div>
    <el-form ref="taskForm" :model="taskForm" :rules="rules" label-width="80px">
      <el-form-item label="退回节点" prop="targetKey">
        <el-radio-group v-model="taskForm.targetKey">
          <el-radio-button v-for="item in returnTaskList" :key="item.id" :label="item.id" v-if="item.name != '技术安排'">{{ item.name }} 
          </el-radio-button>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="退回意见" prop="comment">
        <el-input type="textarea" v-model="taskForm.comment" placeholder="请输入意见" />
      </el-form-item>
    </el-form>
    <div class="text-center">
      <el-button @click="$emit('cancel')">取 消</el-button>
      <el-button type="primary" @click="taskReturn">确 定</el-button>
    </div>
  </div>
</template>

<script>
import { complete, rejectTask, returnList, returnTask, getNextFlowNode, delegate, flowTaskForm, } from "@/api/flowable/todo";
export default {
  props: {
    taskForm: {
      type: Object,
      require: true
    },
    comment: {
      type: String,
      default: ''
    }
  },
  watch: {
    comment(newval) {
      this.taskForm.comment = newval
    }
  },
  data() {
    return {
      form: {},
      returnTaskList: [],
      rules: {
        targetKey: [{ required: true, message: '请选择退回节点', trigger: 'change' }],
        comment: [{ required: true, message: '请输入意见', trigger: 'blur' }],
      }
    }
  },
  created() {
    this.handleReturn();
  },
  mounted() {
    if (this.comment != '') {
      this.taskForm.comment = this.comment
    }
  },
  methods: {
    /** 可退回任务列表 */
    handleReturn() {
      returnList(this.taskForm).then(res => {
        this.returnTaskList = res.data.reverse();
        this.taskForm.variables = null;
      })
    },
    /** 提交退回任务 */
    taskReturn() {
      this.$refs["taskForm"].validate(valid => {
        if (valid) {
          returnTask(this.taskForm).then(res => {
            this.$modal.msgSuccess(res.msg);
            this.$emit('saves')
            this.$emit('goBack')
          });
        }
      });
    },
  },
}
</script>

<style lang="scss" scoped></style>