<template>
  <div class="table-form">
    <Form :model="model" :ref="action" :rules="rules" :label-width="labelWidth">
      <Row :gutter="10">
        <Col span="24">
          <Form-item label="服务器IP" prop="ip" v-validate:ip.required.ip="rules">
            <Input v-model="model.ip"   maxlength="32"  placeholder="请输入1~32位合法IP地址" :disabled="disabled"></Input>
          </Form-item>
          <Form-item label="用户名" prop="user" v-validate:user.required="rules">
            <Input v-model="model.user" maxlength="32"  placeholder="请输入1~32位字符" :disabled="disabled"></Input>
          </Form-item>
          <Form-item label="服务器密码" prop="psw" v-validate:psw.required="rules">
            <Input v-model="model.psw"  maxlength="32"  placeholder="请输入1~32位字符" :disabled="disabled" type="password"></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 ServerForm 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={};


    mounted(){
        console.error('configuration-model-----',this.model);

    }
    save(){
        this.getApiData('post',this.$msPrefix.automation+'/api/v1/data/save/scriptServerEntity',this.model,res=>{
           this.loading=!1;
            if (res.rtnCode == 0) {
                this.tableVm.getData();
                this.cancel();
                // this.$emit('group',res.data);
                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>

