<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="region3"
        v-if="form.region1 == 5"
      >
        <span class="changeTips">改变子模板归属后，模板内容将会恢复到默认状态</span>
        <el-select
          :disabled="!!editData.id"
          v-model="form.region3"
          placeholder="请选择子模板"
          @change="sendData"
        >
          <el-option
            v-for="item in sonLis"
            :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 {
      numWord:0,
      Adscriptions:[],
      sonLis:[{
        name:'空',
        key:'-1',
      },{
        name:'主诉模板',
        key:'1'
      },{
        name:'现病史模板',
        key:'2'
      },{
        name:'现病史空模板',
        key:'3'
      }],
      form: {
        region1: '',    //归属
        region2: '',     //模板名称
        region3: '-1',     //子模板
        tagPool:[],      //标签池
      },
      rules: {
        region1: [
          { required: true, message: '请选择模板归属', trigger: 'change' }
        ],
        region2: [
          { required: true, message: '请输入模板名称', trigger: 'change' },
          // { validator: validatePass2, trigger: 'blur' },
        ],
        region3: [
          { required: true, message: '请选择子模板归属', trigger: 'change' },
          // { validator: validatePass2, trigger: 'blur' },
        ],
      },
    }
  },
  beforeMount:function(){
    let templateOwn = localStorage.getItem('icssEnumsData') ? JSON.parse(localStorage.getItem('icssEnumsData')).moduleTypeEnum : []
    let guisu = localStorage.getItem('guisu') ? JSON.parse(localStorage.getItem('guisu')) : []
    for(let k = 0;k < guisu.length;k++){
      templateOwn = templateOwn.filter(item => item.key != guisu[k])
    }
    this.Adscriptions = templateOwn;
  },
  mounted() {
    const editData = this.$props.editData;
    let templateOwn = localStorage.getItem('icssEnumsData') ? JSON.parse(localStorage.getItem('icssEnumsData')).moduleTypeEnum : []
    if(editData.id){      //修改
      // const trans = utils.transformKeys(editData,2);
      this.form = Object.assign({},this.form,editData);
      this.Adscriptions = templateOwn
      this.form.region1 = (editData.type+'')
      this.form.region2 = editData.name
    }
    this.$emit('changeVal', this.form, false)
    // this.searchTagList()
  },
  methods:{
    changes(){
      let nameVal = this.form.region2
      console.log(nameVal.length)
      if(nameVal.length == 10){
        this.$message({
          message: '最多输入120个字',
          type: 'warning',
          showClose: true,
        });
      }
      if(nameVal.length == 10){
        this.numWord = 10
      }else{
        this.numWord = 0
      }
    },
    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>

