<template>
  <div class="resident-list">
    <bread-crumb
      :curmbFirst="curmbFirst"
      :curmbSecond="curmbSecond"
      :curmbThird="curmbThird"
      :jumPathThird="jumPathThird">
    </bread-crumb>
    <div class="f-main-content screenSet">
      <div class="header-title">
        <span>基本信息</span>
        <p>
          <el-button plain size="small" @click="cancelEdit">取消</el-button>
          <el-button type="primary" size="small" @click="saveEdit">保存</el-button>
        </p>
      </div>
      <edit-information
        :patientInfoObj="patientInfo"
        :checkForm="checkForm"
        @addListenSave="addListenSave"
        :patientId="patientId"></edit-information>
    </div>
  </div>
</template>

<script>
  import BreadCrumb from '@/components/breadcrumb'
  import editInformation from './components/edit-information'
  import { mapGetters } from 'vuex'
  import { getPatientDetail, getRemindPatient, savePatientInfo } from '@/utils/patients/patientsapi'
  export default {
    name: "basicInfo",
    components: {
      BreadCrumb,
      editInformation
    },
    data() {
      return {
        /*面包屑配置*/
        curmbFirst: '居民管理',
        curmbSecond: '我的居民',
        curmbThird: '居民详情',
        jumPathThird: '/patients-manage/mypatients-manage/patients-list',
        patientId: '',
        patientInfo: {},
        checkForm: false,
      }
    },
    created() {
      this.patientId = String(this.$route.query.patientId);
      this.init();
    },
    computed: {
      ...mapGetters([
        '_token',
      ])
    },
    methods: {
      init() {
        getPatientDetail(this.patientId).then((data) => {
          if(data.code == '000000') {
            this.patientInfo = data.data;
          }
        })
      },
      cancelEdit() {
        this.$router.go(-1);
      },
      saveEdit() {
        this.checkForm = true;
      },
      addListenSave(val) {
        this.checkForm = false;
        if(val.status) {
          this.patientInfo = val.patientInfoForm
          savePatientInfo(this.patientInfo).then(data => {
            if(data.code == '000000'){
              this.$message.success('保存备注成功')
              setTimeout(() => {
                this.$router.go(-1);
              },500)
            }else {
              this.$message.error(data.message);
            }
          })
        //  调用保存接口
        }else {
          this.$message.error('请正确填写信息');
        }
      },

      //提醒绑定
      // remindBind() {
      //   let remindMobileWechatPara = {
      //     qrcodeType: 1,
      //     patientId: this.patientId,
      //     // deviceInfo: window.getDeviceInfo()
      //   }
      //   getRemindPatient({
      //     ...remindMobileWechatPara
      //   }).then( data => {
      //     if(data.code == '000000') {
      //       this.$message.success(data.data.respMsg);
      //     }else {
      //       this.$message.error(data.message);
      //     }
      //   })
      // },
    },
    filters: {
      emptyFilter: function(value) {
        if (!value) {
          return '-';
        } else {
          return value;
        }
      },
      sexFileter: function(value) {
        if (!value && value != 0) {
          return '-';
        } else {
          let hash = {
            1: '男',
            2: '女'
          };
          return hash[value];
        }
      },
    },
  }
</script>
<style lang="scss" scoped>
  @import '../../../style/patients-style/element-reset.css';

  .f-main-content{
    background: #ffffff;
    padding: 30px;
    .header-title{
      display: flex;
      display: -webkit-flex;
      align-items: center;
      justify-content: space-between;
      border-bottom: 2px solid #E4E7ED;
      padding-bottom: 10px;
    }

    .right-btn-group{
      position: absolute;
      right: 60px;
      z-index: 1800;
    }
    .section{
      .item{
        display: flex;
        font-size: 14px;
        div{
          display: flex;
          flex: 1;
          line-height: 36px;
          .title{
            width: 180px;
            text-align: right;
          }
          .info{
            color: #999;
            padding-left: 15px;
            width: 100%;
          }
        }
        &.wrap-p{
          div{
            line-height: 28px;
          }
        }
        .btn-right{
          width: 35%;
          padding-left:10px;
        }
      }
      .has-header{
        display: flex;
        justify-content: space-between;
        padding: 15px 0;
        margin-bottom: 15px;
        border-bottom: 1px dashed #888;
        .right-p{
          display: inline-block;
          text-align: right;
          color: #999;
          font-size: 14px;
          span:last-child{
            margin-left: 15px;
          }
        }
      }
    }
    .health-record-list{
      .item{
        width: 100%;
        margin-bottom: 15px;
        .record-date{
          color: #999;
          padding-bottom: 10px;
        }
        .record-content{
          width: 100%;
          border: 1px solid #E4E7ED;
          border-radius: 5px;
          padding: 10px 15px 13px;
          .record-title{
            display: flex;
            justify-content: space-between;
            padding: 5px 0;
            span{
              color: #999;
              font-size: 14px;
            }
          }
          .list-visit{
            line-height: 28px;
            padding: 6px 0 2px;
            display: flex;
            display: -webkit-flex;
            align-items: flex-start;
            font-size: 14px;
            color: #999;
            .left-label{
              line-height: 28px;
            }
            .right-item{
              flex: 1;
              line-height: 28px;
              p{
                line-height: 28px;
                .check-btn{
                  color: #449284;
                  cursor: pointer;
                  margin-left: 15px;
                }
              }
            }
          }
        }
      }
    }
    .no-record-content{
      @media screen and (min-width:1240px) and (max-width:1545px){
        height: 300px;
      }
      @media screen and (min-width:1545px) and (max-width:1600px){
        height: 500px;
      }
      @media screen and (min-width:1600px){
        height: 600px;
      }
      text-align: center;
      padding: 50px 0 60px;
      img{
        width: 120px;
      }
      p{
        color: #B9B9C6;
        font-size: 20px;
      }
    }
    .ml10{
      margin-left: 10px;
    }
  }
</style>
