<template>
    <el-dialog
      title="病历模板详情"
      width="1000px"
      :visible.sync="visible"
      :before-close="_close"
      class="recordDialog"
      append-to-body
    >
        <el-form class="recordForm" :model="form" ref="form" label-width="80px">
          <el-form-item label="模板名称: " prop="name" style="width:100%;">
            <el-input v-model="form.template_name" placeholder=""></el-input>
          </el-form-item>
          <el-form-item label="模板说明: " prop="name" style="width:100%;">
            <el-input v-model="form.template_remark" placeholder=""></el-input>
          </el-form-item>
          <el-form-item label="主诉:" class="width50">
            <el-select @change="changeMainTemplate" v-model="value" style="width:100%;margin-bottom:10px;">
              <el-option
                v-for="(item, index) in tabledata"
                :label="item.title"
                :value="item.content"
                :key="index"
              ></el-option>
            </el-select>
            <el-input
              type="textarea"
              :rows="2"
              placeholder="请输入内容"
              v-model="form.chief_conplaint">
            </el-input>
          </el-form-item>
          <el-form-item label="现病史:" class="width50">
            <el-select @change="changeMainTemplateOne" v-model="valueOne" style="width:100%;margin-bottom:10px;">
              <el-option
                v-for="(item, index) in tabledataOne"
                :label="item.title"
                :value="item.content"
                :key="index"
              ></el-option>
            </el-select>
            <el-input
              type="textarea"
              :rows="2"
              placeholder="请输入内容"
              v-model="form.history_of_present_illness">
            </el-input>
          </el-form-item>
          <el-form-item label="既往史:" class="width50">
            <el-select @change="changeMainTemplateTwo" v-model="valueTwo" style="width:100%;margin-bottom:10px;">
              <el-option
                v-for="(item, index) in tabledataTwo"
                :label="item.title"
                :value="item.content"
                :key="index"
              ></el-option>
            </el-select>
            <el-input
              type="textarea"
              :rows="2"
              placeholder="请输入内容"
              v-model="form.past_history">
            </el-input>
          </el-form-item>
          <el-form-item label="个人史:" class="width50">
            <el-select @change="changeMainTemplateThree" v-model="valueThree" style="width:100%;margin-bottom:10px;">
              <el-option
                v-for="(item, index) in tabledataThree"
                :label="item.title"
                :value="item.content"
                :key="index"
              ></el-option>
            </el-select>
            <el-input
              type="textarea"
              :rows="2"
              placeholder="请输入内容"
              v-model="form.personal_history">
            </el-input>
          </el-form-item>
          <el-form-item  label="家族史:" class="width50">
            <el-select @change="changeMainTemplateFour" v-model="valueFour" style="width:100%;margin-bottom:10px;">
              <el-option
                v-for="(item, index) in tabledataFour"
                :label="item.title"
                :value="item.content"
                :key="index"
              ></el-option>
            </el-select>
            <el-input
            type="textarea"
            :rows="2"
            placeholder="请输入内容"
            v-model="form.family_history">
            </el-input>
          </el-form-item>
          <el-form-item label="诊断信息:" class="width50">
            <el-select @change="changeMainTemplateFive" v-model="valueFive" style="width:100%;margin-bottom:10px;">
              <el-option
                v-for="(item, index) in tabledataFive"
                :label="item.title"
                :value="item.content"
                :key="index"
              ></el-option>
            </el-select>
            <el-input
              type="textarea"
              :rows="2"
              placeholder="请输入内容"
              v-model="form.diagnostic">
            </el-input>
          </el-form-item>
          <el-form-item label="医嘱:" class="width50">
            <el-select @change="changeMainTemplateSix" v-model="valueSix" style="width:100%;margin-bottom:10px;">
              <el-option
                v-for="(item, index) in tabledataSix"
                :label="item.title"
                :value="item.content"
                :key="index"
              ></el-option>
            </el-select>
            <el-input
              type="textarea"
              :rows="2"
              placeholder="请输入内容"
              v-model="form.doctor_advice">
            </el-input>
          </el-form-item>

          <el-form-item label ="备注"  prop="name" class="width50">
            <el-input
              type="textarea"
              :rows="2"
              placeholder="请输入内容"
              v-model="form.remark">
            </el-input>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
            <el-button @click="hide">取 消</el-button>
            <el-button type="primary"  @click="submitAction()">保 存</el-button>
        </div>
    </el-dialog>         
</template>

<script>
import { getTemplateDetail,updateRecordTemplate,getMedicalTemplateList } from "@/api/project/project"
export default {
    data(){
        return{
            visible:false,
            form:{
              id:0,
              template_name:'',
              template_remark:"",
              chief_conplaint:"",
              history_of_present_illness:"",
              past_history:"",
              personal_history:"",
              family_history:"",
              diagnostic:"",
              remark:'',
              doctor_advice:'',
            
            },
            textarea:"",
            templatedetail:{},
            tabledata:[],
            tabledataOne:[],
            tabledataTwo:[],
            tabledataThree:[],
            tabledataFour:[],
            tabledataFive:[],
            tabledataSix:[],
            tabledataSeven:[],
            value:'',
            valueOne:'',
            valueTwo:'',
            valueThree:'',
            valueFour:'',
            valueFive:'',
            valueSix:'',
            valueSeven:''
        }
    },
    methods:{
        _close: function(done) {
            // this.clear()
            done()
        },
        clear: function() {
            this.form.id = 0;
            this.form.name = "";
            this.form.intro = "";
        },
        show(id) {
          this.getTemplateDetail(id)
          this.visible = true
          
        },
        hide() {
            // this.clear()
            this.visible = false
        },
        getTemplateDetail(id){
          getTemplateDetail(id).then(response=>{
              if(response.data.state == 1){  
                var templatedetail =  response.data.data.templateDetail
                console.log("templatedetail",templatedetail)
                this.form.id = templatedetail.id
                this.form.template_name =   templatedetail.template_name 
                this.form.template_remark = templatedetail.template_remark 
                this.form.chief_conplaint =  templatedetail.chief_conplaint 
                this.form.history_of_present_illness =  templatedetail.history_of_present_illness 
                this.form.past_history =  templatedetail.past_history 
                this.form.personal_history =    templatedetail.personal_history 
                this.form.family_history = templatedetail.family_history 
                this.form.diagnostic = templatedetail.diagnostic 
                this.form.doctor_advice = templatedetail.doctor_advice
                this.form.remark = templatedetail.remark 
              }
          })
        },
        submitAction(){
          var params = {
            id:this.form.id,
            template_name:this.form.template_name,
            template_remark:this.form.template_remark,
            chief_conplaint:this.form.chief_conplaint,
            history_of_present_illness:this.form.history_of_present_illness,
            past_history:this.form.past_history,
            personal_history:this.form.personal_history,
            family_history:this.form.family_history,
            diagnostic:this.form.diagnostic,
            doctor_advice:this.form.doctor_advice,
            remark:this.form.remark
          }  
          updateRecordTemplate(params).then(response=>{
             if(response.data.state == 1){
                var template =  response.data.data.templateDetail
                this.$message.success("保存成功")
                this.visible = false
                // this.$parents.getlist()
             }
          }) 
        },
        
         getlist(){
           getMedicalTemplateList().then(response=>{
           if(response.data.state == 1){
             var list =  response.data.data.list
             console.log("list",list)
             this.tabledata = list
             this.tabledataOne =  response.data.data.listOne
             this.tabledataTwo = response.data.data.listTwo
             this.tabledataThree = response.data.data.listThree
             this.tabledataFour =  response.data.data.listFour
             this.tabledataFive = response.data.data.listFive
             this.tabledataSix = response.data.data.listSix
             this.tabledataSeven =  response.data.data.listSeven
           }
        })   
       },

       changeMainTemplate(values){
         if(this.case_history.chief_conplaint == ''){
           this.case_history.chief_conplaint = values
         } else {
          if (this.case_history.chief_conplaint.indexOf(values) == -1) {
            if (this.case_history.chief_conplaint.charAt(this.case_history.chief_conplaint.length - 1).indexOf('。') == -1) {
              this.case_history.chief_conplaint = this.case_history.chief_conplaint + ',' + values
            } else {
              this.case_history.chief_conplaint = this.case_history.chief_conplaint + values
            }
          }
        }
       },
       changeMainTemplateOne(values){
          if(this.case_history.history_of_present_illness == ''){
           this.case_history.history_of_present_illness = values
         } else {
          if (this.case_history.history_of_present_illness.indexOf(values) == -1) {
            if (this.case_history.history_of_present_illness.charAt(this.case_history.history_of_present_illness.length - 1).indexOf('。') == -1) {
              this.case_history.history_of_present_illness = this.case_history.history_of_present_illness + ',' + values
            } else {
              this.case_history.history_of_present_illness = this.case_history.history_of_present_illness + values
            }
          }
        }
      },
      changeMainTemplateTwo(values){
         if(this.case_history.past_history == ''){
           this.case_history.past_history = values
         } else {
          if (this.case_history.past_history.indexOf(values) == -1) {
            if (this.case_history.past_history.charAt(this.case_history.past_history.length - 1).indexOf('。') == -1) {
              this.case_history.past_history = this.case_history.past_history + ',' + values
            } else {
              this.case_history.past_history = this.case_history.past_history + values
            }
          }
        }
      },
      changeMainTemplateThree(values){
         if(this.case_history.personal_history == ''){
           this.case_history.personal_history = values
         } else {
          if (this.case_history.personal_history.indexOf(values) == -1) {
            if (this.case_history.personal_history.charAt(this.case_history.personal_history.length - 1).indexOf('。') == -1) {
              this.case_history.personal_history = this.case_history.personal_history + ',' + values
            } else {
              this.case_history.personal_history = this.case_history.personal_history + values
            }
          }
        }
      },
      changeMainTemplateFour(values){
          if(this.case_history.family_history == ''){
           this.case_history.family_history = values
         } else {
          if (this.case_history.family_history.indexOf(values) == -1) {
            if (this.case_history.family_history.charAt(this.case_history.family_history.length - 1).indexOf('。') == -1) {
              this.case_history.family_history = this.case_history.family_history + ',' + values
            } else {
              this.case_history.family_history = this.case_history.family_history + values
            }
          }
        }
      },

      changeMainTemplateFive(values){
          if(this.case_history.diagnostic == ''){
           this.case_history.diagnostic = values
         } else {
          if (this.case_history.diagnostic.indexOf(values) == -1) {
            if (this.case_history.diagnostic.charAt(this.case_history.diagnostic.length - 1).indexOf('。') == -1) {
              this.case_history.diagnostic = this.case_history.diagnostic + ',' + values
            } else {
              this.case_history.diagnostic = this.case_history.diagnostic + values
            }
          }
        }
      },
      changeMainTemplateSix(values){
          if(this.case_history.doctor_advice == ''){
           this.case_history.doctor_advice = values
         } else {
          if (this.case_history.doctor_advice.indexOf(values) == -1) {
            if (this.case_history.doctor_advice.charAt(this.case_history.doctor_advice.length - 1).indexOf('。') == -1) {
              this.case_history.doctor_advice = this.case_history.doctor_advice + ',' + values
            } else {
              this.case_history.doctor_advice = this.case_history.doctor_advice + values
            }
          }
        }
      },
    },

    created(){
       this.getlist()  
    }
}
</script>

<style lang="scss" scoped>
.recordForm{
  display: flex;
  flex-wrap: wrap;
  .el-form-item{
    width:24%;
    margin-right: 1%;
  }
  .width50{
    width: 49%;
  }
}
</style>

