<template>
  <div class="PubTagGroupWrapper">
    <el-form
      class="groups"
      :rules="rules"
      ref="groups"
      :model="form"
      label-width="150px"
    >
      <el-form-item
        label="选择归属："
        prop="region1"
      >
        <span class="changeTips">改变归属后，模板内容将会恢复到默认状态</span>
        <el-select
          :disabled="!!editData.id"
          v-model="form.region1"
          placeholder="请选择模板归属"
          @change="sendData"
        >
          <el-option
            v-for="item in Adscriptions"
            :label="item.name"
            :value="item.key+''"
            :key="item.key"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item
        label="模板名称："
        prop="region2"
      >
        <el-input
          v-model="form.region2"
          :disabled="!!editData.id"
          maxLength="120"
          placeholder="请输入模板名称"
        ></el-input>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
import api from '@api/icss.js';
import utils from '@api/utils.js';

/**
 * 归属type
 * 1：主诉模板 2：现病史模板 3：现病史空模板 4 : 其他史模板 5：嵌套模板 6：慢病模板
 */


export default {
  props:['editData'],
  data() {
    return {
      Adscriptions:[],
      form: {
        region1: '',    //归属
        region2: '',     //模板名称
        tagPool:[],      //标签池
      },
      rules: {
        region1: [
          { required: true, message: '请选择模板归属', trigger: 'change' }
        ],
        region2: [
          { required: true, message: '请输入模板名称', trigger: 'change' },
          // { validator: validatePass2, trigger: 'blur' },
        ],
      },
    }
  },
  beforeMount:function(){
    let templateOwn = localStorage.getItem('icssEnumsData') ? JSON.parse(localStorage.getItem('icssEnumsData')).moduleTypeEnum : []
    this.Adscriptions = templateOwn;
  },
  mounted() {
    const editData = this.$props.editData;
    if(editData.id){      //修改
      // const trans = utils.transformKeys(editData,2);
      this.form = Object.assign({},this.form,editData);
      this.form.region1 = (editData.type+'')
      this.form.region2 = editData.name
    }
    this.$emit('changeVal', this.form, false)
    // this.searchTagList()
  },
  methods:{
    sendData(val){
      this.$emit('changeVal', this.form, false)
    },
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.$emit('validatePass', this.form, false)
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },
  }
}
</script>
<style lang="less">
.PubTagGroupWrapper {
  .groups {
  background-color: #fff;
  padding: 20px;
  margin: 20px 20px -20px 20px;
  .el-form-item__content,
  .el-input__inner {
    height: 30px;
    line-height: 30px;
    width: 200px;
  }
  .el-form-item {
    margin-bottom: 20px;
  }
  .el-form-item__error {
    top: 28px;
  }
  .el-form-item__label {
    line-height: 30px;
    text-align: left;
  }
  .el-input__icon {
    line-height: 30px;
  }
  .verticalMiddle .el-form-item__content {
    position: relative;
    top: 16px;
  }
  .maxAges {
    margin-left: -125px;
  }
  .ages {
    display: inline-block;
    .el-form-item__content {
      width: auto;
    }
    .el-input {
      display: inline-block;
      width: auto;
      .el-input__inner {
        width: 60px;
        padding: 0 5px;
        margin-right: 25px;
        text-align: center;
      }

      .el-input__inner::-webkit-outer-spin-button,
      .el-input__inner::-webkit-inner-spin-button {
        -webkit-appearance: none;
      }

      .el-input__inner[type="number"] {
        -moz-appearance: textfield;
      }
    }
  }
  .el-message-box__btns .el-button--default {
    color: #606266 !important;
  }
  .cancelColor {
    color: #22ccc8 !important;
  }
  .changeTips {
    position: absolute;
    left: 220px;
    min-width: 300px;
    color: #22ccc8;
    font-size: 12px;
  }
}
}
</style>

