<template>
  <div>
    <el-row>
      <el-form ref="changeInfoRef" :rules='rules' :model="changeInfoForm" label-width="70px">
        <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-option label="结束" value="2"></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 { taskState,getTask } from '@/api/taskManagement/taskManagement'
export default {
  props: {
    rowid: {
      type: Number,
      default:0
    },
    layerid: {
      type: String,
      default: ""
    }
  },
  data() {
    return {
      changeInfoForm: {
        state: "" //变更状态
      },
      rules:{
        state:[{
          required:true,
          message:'请选择状态',
          trigger:'blur'
        }]
      }
    };
  },
  methods: {
    submit(){
      this.$refs.changeInfoRef.validate((valid)=>{
        if(valid){
            return new Promise(resolve=>{
              const params={
                  id:this.rowid,
                  state:this.changeInfoForm.state,//状态
              }
              taskState(params).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('请输入有效的必填项信息')
        }
      })
        
    },
    //获取状态信息
    getState(id){
      getTask(id).then(response=>{
        if(response.state.toLowerCase()=='success'){
          this.changeInfoForm.state=response.data.F_State
        }
      }).catch(resolve=>{
        console.log(resolve)
      })
    }
  }
};
</script>
<style lang="scss" scoped>
</style>