<template>
  <div class="table-form">
    <Form :model="model" :ref="action" :rules="rules" :label-width="labelWidth">
      <Row :gutter="10">
        <Col span="24">
         <Form-item label="命令内容" prop="command" v-validate:command.required="rules">
            <Input type="textarea" :autosize="true"  v-model="model.command" placeholder="请输入命令内容" :disabled="disabled"></Input>
          </Form-item>
            <!-- <Form-item label="用户名称" prop="userName" v-validate:command.required.maxInputLength="rules">
                <Input type="textarea" v-model="model.userName" placeholder="请输入用户名称" :disabled="disabled"></Input>
            </Form-item> -->
          <Form-item label="命令描述" prop="description" v-validate:description.required.maxInputLength="rules">
            <Input v-model="model.description" type="textarea"  :autosize="true" placeholder="请输入命令描述" :disabled="disabled"></Input>
          </Form-item>

          
        </Col>
      </Row>
     
      <Row class="buttonDiv">
        <Button :loading="loading"
          @click="submitForm(action)"
          type="primary"
          v-if="!(action == 'detail')"
        >确&nbsp;&nbsp;定</Button>
        <Button @click="cancel">关&nbsp;&nbsp;闭</Button>
      </Row>
    </Form>
  </div>
</template>
<script lang="ts">
import { Component, Prop, Vue, Emit } from "vue-property-decorator";
@Component
export default class FavorCommandForm extends Vue {
  
    @Prop() private model!:any;
    @Prop(String) private action!:string;
    @Prop() private tableInfo!:any;
    @Prop() private tableVm!:any;
    
    loading : boolean = false;
    labelWidth:number =120;
    rules:any={};

    created(){
    }

    data() {
      return {
        // define the default value
        value: null,
        // define options
      }
    }
    
    mounted(){

    }
    save(){
      console.log('99999',this.model);
        this.getApiData('post',this.$msPrefix.automation+'/api/v1/data/save/commandFavor',this.model,res=>{
           this.loading=!1;
            if (res.rtnCode == 0) {
                this.tableVm.getData();
                this.cancel();
                this.$tools.message('success',(this.action == 'update'?'修改':'新增')+'成功！')
            }
        },err=>{
           this.loading=!1;
        })
    }
    /*提交*/
      submitForm (action) {
      	
        (this.$refs[action] as any).validate((valid) => {
          if (valid) {
          	if(!this.loading){
                this.loading=!0;
                this.save()
            }
          } else {
            this.$tools.message('info',"请完善必填项!")
           
          }
        });
      }

    @Emit('closeModal') close(){}
    cancel() {  
      	this.close();
        (this.$refs[this.action] as any).resetFields();
      }

      get disabled(){
        return this.action=='detail'
      }
}
</script>

