<template>
    <div>
        <crumbs :title="title" :param="$route.params" linkTo="RecordManager"></crumbs>
        <div class="contents">
            <div class="content">
                <el-form ref="form" :label-position="labelPosition" label-width="125px" class="add-record-form" :model="form">
                    <el-form-item label="性别：" prop="sexType">
                        <el-select v-model="form.brbaxb"
                                   placeholder="请选择"
                                   size="small">
                            <el-option
                                    v-for="item in sexType"
                                    :key="String(item.key)"
                                    :label="item.name"
                                    :value="String(item.key)">
                            </el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="血型：" prop="brbaxx">
                        <el-select v-model="form.brbaxx"
                                   placeholder="请选择"
                                   size="small">
                            <el-option
                                    v-for="item in bloodType"
                                    :key="String(item.key)"
                                    :label="item.name"
                                    :value="String(item.key)">
                            </el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="RH型：" prop="brbarh">
                        <el-select v-model="form.brbarh"
                                   placeholder="请选择"
                                   size="small">
                            <el-option
                                    v-for="item in rhType"
                                    :key="String(item.key)"
                                    :label="item.name"
                                    :value="String(item.key)">
                            </el-option>
                        </el-select>
                    </el-form-item>
                    <p class="sub-title">门（急）诊诊断：</p>
                    <el-form-item label="主要诊断：" prop="mjzzdmc">
                        <p v-for="i in form.mjzzyzdList" class="treatments">
                            <el-input v-model="i.zdjbmc" placeholder="请输入主要诊断"></el-input>
                            <el-input v-model="i.jbdmid" placeholder="请输诊断编码"></el-input>
                        </p>
                    </el-form-item>
                    <el-form-item label="其他诊断：" prop="mjzzdmc">
                        <p v-for="i in form.mjzqtzdList" class="treatments">
                            <el-input v-model="i.zdjbmc" placeholder="请输入其他诊断"></el-input>
                            <el-input v-model="i.jbdmid" placeholder="请输诊断编码"></el-input>
                        </p>
                    </el-form-item>
                    <p class="sub-title">出院诊断：</p>
                    <el-form-item label="主要诊断：" prop="zyzyzdmc">
                        <p v-for="i in form.zyzyzdList" class="treatments">
                            <el-input v-model="i.zdjbmc" placeholder="请输入门（急）诊诊断"></el-input>
                            <el-input v-model="i.jbdmid" placeholder="请输诊断编码"></el-input>
                        </p>
                    </el-form-item>
                    <el-form-item label="其他诊断：" prop="zyqtzdmc">
                        <p v-for="i in form.zyqtzdList" class="treatments">
                            <el-input v-model="i.zdjbmc" placeholder="请输入门（急）诊诊断"></el-input>
                            <el-input v-model="i.jbdmid" placeholder="请输诊断编码"></el-input>
                        </p>
                        <!--<el-input v-model="form.zyqtzdmc" placeholder="请输入次要诊断"></el-input>-->
                    </el-form-item>
                    <el-form-item label="病例记录：">
                        <el-tabs tab-position="left">
                            <el-tab-pane :label="i.bljlmc" v-for="i in form.zybljlList">
                                <el-input
                                        type="textarea"
                                        :rows="20"
                                        v-model="i.bljlnr"
                                        placeholder="请输入内容">
                                </el-input>
                            </el-tab-pane>
                        </el-tabs>
                    </el-form-item>
                    <p class="oper">
                        <el-button style="margin-right: 30px" size="small" type="primary" @click="comfirn('form')">确定</el-button>
                        <el-button size="small" @click="cancel">取消</el-button>
                    </p>
                </el-form>
            </div>
        </div>
    </div>
</template>
<script type="text/javascript">
  import api from '@api/records.js';
  export default {
    name:'AddRecord',
    data(){
      return{
        // data:{},
        labelPosition:'left',
        /*zybljlList:[
          {name:'aaa',content:'333333'},
          {name:'vvv',content:'333sa'}
        ],*/
        sexType:[],
        bloodType:[],
        rhType:[],
        title:'测试病例记录维护-修改测试病例记录',
        form:{
          brbaxb:'',
          brbaxx:'',
          brbarh:'',
          mjzzdmc:'',
          zyzyzdmc:'',
          zyqtzdmc:'',
          zybljlList:[]
        },
        id:null,
      }
    },
    created(){
      let info = this.$route.params;
      this.getTypes();
      if(Object.keys(info).length>0){
        this.basyid = info.basyid;
        this.brzyid = info.brzyid;
        this.title = "测试病例记录维护-修改测试病例记录";
        this.getDetail(info.basyid,info.brzyid);
      }
    },
    methods:{
      getTypes(){
        api.getTypes().then((res)=>{
          const result = res.data;
          if(result.code==0){
            this.sexType = result.data.sexEnum;
            this.bloodType = result.data.bloodTypeEnum;
            this.rhType = result.data.rhTypeEnum;
          }else{
            this.$message({
              message:result.msg,
              type:'warning'
            });
          }
        })
      },
      getDetail(syid,zyid){
        api.getRecordDetail({basyid:syid,brzyid:zyid}).then((res)=>{
          const result = res.data;
          if(result.code==0){
            this.form = result.data;
          }else{
            this.$message({
              message:result.msg,
              type:'warning'
            });
          }
        })
      },
      cancel(){
        this.$router.push({
          name: 'RecordManager',
          params: Object.assign({}, this.$route.params)
        });
      },
      comfirn(form){
        /*if(!this.form.name.trim() || !this.form.refreshTime.trim()){
          this.$message({
            message:'请填写相关内容',
            type:'warning'
          });
          return
        }*/
        /*this.$refs[form].validate((valid) => {
          if (valid) {*/
            if(this.basyid){//修改
              const param = Object.assign({},this.form,{basyid:this.basyid,brzyid:this.brzyid});
              api.saveRecord(param).then((res)=>{
                if(res.data.code==0){
                  this.$message({
                    message:"修改成功",
                    type:'success'
                  });
                  //返回带搜索条件的首页
                  this.$router.push({
                    name: 'RecordManager',
                    params: Object.assign({}, this.$route.params)
                  });
                }else{
                  this.$message({
                    message:res.data.msg,
                    type:'warning'
                  });
                }
              })
            }else{//添加
              // 复制时把list多余字段过滤掉，如id等
              const detail = this.list;
              let copyDetail=[];
              let item={};
              if(detail && detail.length>0){
                for(let i=0; i<detail.length; i++){
                  item.title = detail[i].title;
                  item.description = detail[i].description;
                  copyDetail.push(item);
                  item={};
                }
              }
              const params = Object.assign({},this.form);
              // api.addVersInfo(this.form).then((res)=>{
              api.saveRecord(params).then((res)=>{
                if(res.data.code==0){
                  this.$message({
                    message:"添加成功",
                    type:'success'
                  })
                  // this.$router.push({path: 'LT-GBBXXWH-BBXXWH'});
                  this.$router.push({name: 'RecordManager'});
                }else{
                  this.$message({
                    message:res.data.msg,
                    type:'warning'
                  });
                }
              })
            }
          /*} else {
            return false;
          }
        });*/
      },
    }
  }
</script>
<style lang="less">
    @import "../../less/admin.less";
    .content{
        background: #fff;
        padding: 20px 20px 50px;
        color: #545455;
        min-width: 980px;
        position: relative;
    .short-inp{
        width: 200px;
    }
    .sub-title{
        font-weight: bold;
        font-size: 16px;
        margin-bottom: 20px;
    }
    .oper{
        text-align: right;
    }
    .treatments{
    .el-input{
        width:200px;
        display: inline-block;
    }
    .el-input:first-child{
        margin-right:20px;
        &:before{
             content: '诊断名称:';
         }
    }
    .el-input:last-child:before{
        content: '诊断编码:';
    }
    }
    }

</style>