<template>
  <div>
    <el-row>
      <el-form ref="changeInfoRef" :model="changeInfoForm" label-width="70px" :rules="rules">
        <el-col :span="24">
          <el-form-item label="状态" prop="state">
            <el-select clearable v-model="changeInfoForm.state" placeholder="请选择状态" width>
              <el-option label="未完成" value="0"></el-option>
              <el-option label="已完成" value="1"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-button type="primary" style="margin-left:50%" @click="submit">保存</el-button>
        </el-col>
      </el-form>
    </el-row>
  </div>
</template>
<script>
import { getOperation } from "@/api/todoManagement/todoList";
export default {
  props: {
    rowid: {
      type: Array,
      default: []
    },
    layerid: {
      type: String,
      default: ""
    }
  },
  data() {
    return {
      changeInfoForm: {
        state: "" //变更状态
      },
      rules: {
        state: [
          {
            required: true,
            message: "请选择状态",
            trigger: "blur"
          }
        ]
      }
    };
  },
  methods: {
    submit() {
      this.$refs.changeInfoRef.validate(valid => {
        if (valid) {
            console.log(this.rowid)
            console.log(this.changeInfoForm.state)
          return new Promise(resolve => {
            getOperation(this.rowid,this.changeInfoForm.state)
              .then(response => {
                if (response.state.toLowerCase() === "success") {
                  this.$parent.$layer.close(this.layerid);
                  this.$parent.getList();
                  this.$message.success("恭喜你，操作成功!");
                }
              })
              .catch(result => {
                this.$message.error(result);
              });
          });
        }else{
            this.$message.error('请输入有效的必填项信息!')
            return false
        }
      });
    }
  }
};
</script>
<style lang="scss" scoped>
</style>