<template>
  <div class="archives">
    <div class="archives-content">
      <left-form-list
        ref="leftFormList"
        :patient-id="patientId"
        :is-search="isSearch"
        :only-read="onlyRead"
        :form-list="formList"
        :cur-index="curIndex"
        @handleForm="handleForm"
        @addRecord="addRecord"
      />
      <div class="content-right">
        <template v-if="formList.length">
          <ourPatientRecord v-if="name === '门急诊电子病历'" :patient-id="patientId" :only-read="onlyRead" :is-search="isSearch" @formDelete="formDelete" />
          <InformedConsent v-if="name==='眼科激光手术患者知情同意书'" :json-text="jsonText" @handleSaveTable="updateForm" @formDelete="formDelete" />
          <mra-form v-if="name==='眼底血管造影知情同意书'" :json-text="jsonText" @handleSaveTable="updateForm" @formDelete="formDelete" />
          <laser-surgery v-if="name==='眼科激光手术治疗'" :json-text="jsonText" @handleSaveTable="updateForm" @formDelete="formDelete" />
          <report-form v-if="name==='报告'" :json-text="jsonText" @handleSaveTable="updateForm" @formDelete="formDelete" />
        </template>
      </div>
    </div>
  </div>
</template>
<script>
import ourPatientRecord from './outPatientRecord'
import LeftFormList from '@/components/360View/medicalRecord/outPatientRecord/leftFormList.vue'
import InformedConsent from '@/page-subspecialty/views/modules/formList/InformedConsent.vue'
import MraForm from '@/page-subspecialty/views/modules/formList/mraForm.vue'
import LaserSurgery from '@/page-subspecialty/views/modules/formList/laserSurgery.vue'
import ReportForm from '@/page-subspecialty/views/modules/formList/reportForm.vue'
export default {
  components: {
    ReportForm,
    LaserSurgery,
    MraForm,
    InformedConsent,
    LeftFormList,
    ourPatientRecord
  },
  mixins: [],
  props: {
    isSearch: {
      type: String,
      default: ''
    },
    patientIdNumber: {
      type: String,
      default: ''
    },
    patientId: {
      type: String,
      default: ''
    },
    onlyRead: {
      type: Boolean,
      default: false
    }
  },
  inject: ['refresh'],
  data() {
    return {
      id: '',
      name: '',
      curIndex: 0,
      formList: [],
      defaultChecked: [],
      formType: '门诊',
      jsonText: ''
    }
  },
  created() {
    this.getFormList()
  },
  methods: {
    handleForm({ index, item }) {
      this.curIndex = index
      this.id = item.id
      this.name = item.name
      this.jsonText = item.jsonText
      if (item.name === '门急诊电子病历') {
        // this.eyesData = item.jsonText ? JSON.parse(item.jsonText) : {}
        // if (item.jsonText) {
        //   this.$nextTick(() => {
        //     this.$refs.eyes.setData()
        //   })
        // } else {
        //   this.$nextTick(() => {
        //     this.$refs.eyes.reSet()
        //   })
        // }
      }
    },
    async updateForm(data) {
      const params = {
        flag: 8,
        name: this.name,
        jsonText: JSON.stringify(data),
        patientId: this.patientId,
        id: this.id,
        platform: this.isSearch
      }
      const { data: res } = await this.$http.post('/case/update', params)
      if (res.code === 0) {
        this.$message.success('保存成功')
        this.getFormList('update')
      } else {
        this.$message.error(res.msg)
      }
    },
    addRecord(name) {
      this.name = name
      const date = this.$moment().format('YYYY-MM-DD HH:mm:ss')
      const params = {
        flag: 8,
        name: name,
        createTime: date,
        patientId: this.patientId,
        platform: this.isSearch
      }
      this.$http.post('/case/save', params).then(res => {
        this.$message.success('添加成功！')
        this.getFormList()
      }).catch(err => {
        this.$message.error(err.msg)
      })
    },
    // 删除表单
    formDelete() {
      const params = {
        id: this.id
      }
      this.$confirmFun('你确定要删除此随访记录吗？').then(() => {
        this.$http.post('/case/delete', params).then(() => {
          this.getFormList()
          this.$message.success('删除成功')
        })
      })
    },
    async getFormList(mode) {
      const { data: res } = await this.$http.get('/patient/view/getCases', {
        params: {
          patientId: this.patientId,
          platform: this.isSearch,
          flag: 8
        }
      })
      if (res.code === 0) {
        this.formList = res.data || []
        if (this.formList.length) {
          if (mode) {
            this.curIndex = this.formList.findIndex(item => item.id === this.id)
            this.jsonText = this.formList[this.curIndex].jsonText
          } else {
            this.name = this.formList[0].name
            this.id = this.formList[0].id
            this.curIndex = this.formList.findIndex(item => item.id === this.id)
            this.jsonText = this.formList[this.curIndex].jsonText
          }
        }
      } else {
        this.$message.error(res.msg)
      }
    }
  }
}
</script>
<style lang="scss" scoped>
.archives {
  height: 100%;
  .text-ellipsis {
    white-space: nowrap; // 段落不换行
    text-overflow: ellipsis;
    overflow: hidden;
  }
  .printer {
    border: 1px solid #ccc;
    width: 56px;
    height: 32px;
    border-radius: 3px;
    margin: 0;
    margin-left: 10px;
    cursor: pointer;
  }
  .archives-content {
    display: flex;
    height: 100%;
    overflow: hidden;
    .formBox{
      cursor: pointer;
      padding: 2px 8px;
      border-radius: 2px;
      margin-top: 12px;
    }
    .active {
      color: white;
      background-color: #1C76FD;
    }
    .curFont {
      color: #A6A4A4;
    }
    .activeFont {
      color: #D9D9D9;
    }
  }
  .content-right {
    padding: 12px;
    position: relative;
    flex: 1;
    text-align: center;
    background-color: #F0F2F5;
    overflow: hidden;
    overflow-y: scroll;
    .content-right-buttonClick {
      display: flex;
      justify-content: flex-end;
      background: #2e2e2e;
      padding: 10px;
    }
    .editor-CRF {
      height: 93%;
    }
    .content-right-CRF {
      background: #5c5c5c;
      overflow-x: auto;
      padding: 16px 16px 16px 16px;
      position: relative;
      height: 100%;
    }
    .content-right-CRF-class {
      padding-right: 178px;
    }
    .suspension-button {
      position: absolute;
      right: 10px;
      top: 10px;
      z-index: 1;
    }
    .case-template,
    .intelligent-filling {
      cursor: pointer;
      height: 140px;
      width: 32px;
      background: #fff;
      border-radius: 4px;
      display: flex;
      flex-direction: column;
      justify-content: space-around;
      align-items: center;
      box-shadow: 0px 4px 10px rgba(0, 0, 0, 0.1);
      span {
        writing-mode: vertical-rl;
        letter-spacing: 6px;
      }
    }
    .case-template:hover,
    .intelligent-filling:hover {
      background: linear-gradient(270deg, #f4f8fb 0%, #deebff 66.15%);
    }
    .case-template {
      margin-bottom: 6px;
    }
  }
}
</style>
<style lang="scss">
.archives {
  .el-button .el-button--text .el-button--mini {
    padding: 0;
  }
  .tree-date {
    font-size: 14px;
    color: #ccc;
  }
  .tree-date-active {
    color: #e4e4e4;
  }
  .el-tree-node {
    margin-bottom: 6px;
  }
  .el-tree-node__content {
    margin-bottom: 4px;
    height: 35px;
    //padding-left: 0 !important;
  }
  //.tree-children {
  //  padding: 2px 0 2px 20px;
  //  position: relative;
  //}
  //.el-tree-node__expand-icon.is-leaf {
  //  display: none;
  //}
  .tree-children:hover {
    .tree-button {
      display: inline-block;
    }
  }
  .tree-button {
    position: absolute;
    bottom: 6px;
    right: 4px;
    display: none;
  }
  .tree-button-active {
    color: #fff;
  }
  .custom-tree-node {
    flex: 1;
    padding-top: 6px;
    overflow: hidden;
  }
  .tree-forname {
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
    width: 90%;
  }
  .el-tree-node__content:hover,
  .el-upload-list__item:hover {
    background: none;
  }
  .el-icon-caret-right:before {
    color: #262626;
  }
}
.comonForm-tab {
  #tab-mz {
    padding-left: 14px !important;
  }
  .el-tabs__nav-wrap::after {
    height: 0;
  }
  .el-tabs__header {
    padding-right: 0 !important;
  }
  .el-tabs__item.is-active {
    color: #fff;
    background: #1890ff;
  }
  .el-tabs__item {
    background: #f2f3f5;
    padding: 0 14px;
    margin-left: 1px;
    height: 35px;
    line-height: 35px;
  }
  .el-tabs__content {
    padding: 0 !important;
  }
}
.see-doctor .comonForm-tab .el-tabs__item:last-child {
  padding-right: 14px !important;
}
.see-doctor .comonForm-tab .el-tabs__item:nth-child(2) {
  padding-left: 14px !important;
}
</style>
