<template>
  <el-dialog width="430px" :title="titles" :visible.sync="visibility"  :close-on-click-modal="isClose"
             :close-on-press-escape="isClose">
    <el-form :rules="rules" ref="formValue" :model="formValue" label-width="80px">
      <el-row>
         <el-col >
          <el-form-item label="类型名称" prop="type_name">
            <el-input   v-model="formValue.type_name"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col>
          <el-form-item label="耗材属性">
            
              <el-radio-group v-model="formValue.stock_attribute" @change="changeRadio">
                  <el-radio label="1">无</el-radio>
                  <el-radio label="2">透析器</el-radio>
                  <el-radio label="3">灌流器</el-radio>
              </el-radio-group>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col>
          <el-form-item label="耗材出库" prop="out_stock" v-show="showAttribute">
             <el-radio v-model="formValue.out_stock" label="1">是</el-radio>
             <el-radio v-model="formValue.out_stock" label="2">否</el-radio>
          </el-form-item>     
        </el-col>
      </el-row>
      <el-row>
         <el-col >
          <el-form-item label="备注">
            <el-input type="textarea" :row="5" v-model="formValue.remark" placeholder="请输入内容">
            </el-input>
          </el-form-item>
        </el-col>
      </el-row>
   

    </el-form>


    <span slot="footer" class="dialog-footer">
    <el-button v-if="isCreated == 3" @click="cancle('formValue')">取 消</el-button>
    <el-button v-if="isCreated != 3 " @click="cancle('formValue')">取 消</el-button>
    <el-button v-if="isCreated != 3" type="primary" @click="comfirm('formValue')">保 存</el-button>
  </span>
  </el-dialog>


</template>

<script>
export default {
  name: "goodTypeDialog",
  data() {
    return {
      visibility:false,
      isClose: false,
      labelPosition: 'right',
      resetForm: {
        remark: "",
        type_name: ""
      },
      rules: {
        type_name: [
          { required: true, message: "请输入类型名称", trigger: "blur" }
        ]
      },
       out_stock: '1',
       stock_attribute:"1",
       showAttribute:true
    };
  },
  props: {
    titles: {
      type: String,
      default: ""
    },
    formValue: {
      type: Object
    },
    isCreated: {
      type: Number,
      default: 1
    }
  },
  methods: {
    show:function(val){
      // console.log("val22222222",this.formValue)
      // if(this.formValue.stock_attribute == "1"){
      //   this.showAttribute = false
      // }
      // if(this.formValue.stock_attribute == "2" || this.formValue.stock_attribute =="3"){
      //   this.showAttribute = true
      // }
   
      this.visibility = true

    },hide:function(){
      this.visibility = false
    },
    cancle: function(formName) {
      this.$emit("dialog-cancle");
      this.$refs[formName].resetFields();
    },
    comfirm: function(formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          this.$emit("dialog-comfirm", this.getValue());
        }
      });
    },
    getValue: function() {
      let form = {};
      form["type_name"] = this.formValue.type_name;
      form["remark"] = this.formValue.remark;
      form["isCreated"] = this.isCreated;
      form['out_stock'] = this.formValue.out_stock;
      form["stock_attribute"] = this.formValue.stock_attribute
      return form;
    },

    changeRadio(val){
      if(val == 1){
        this.showAttribute = false
      }
      if(val == 2 || val == 3){
        this.showAttribute = true
      }
    }
  },
  
  watch: {
    visibility(val) {
      
      !val && setTimeout(() => {
        
          this.$refs["formValue"].resetFields();
          this.formValue.remark = "";
          this.formValue.type_name = "";
          this.formValue.stock_attribute="1";
          this.formValue.out_stock = "1"
       }, 0);
    },
    
   
  },

 
};
</script>

