<template>
  <div style="background-color: #f1f3f5; padding-top: 16px">
    <div slot="footer" class="topfooter">
      <el-tabs v-model="activeNametab">
        <el-tab-pane label="画像审核" name="portrait"></el-tab-pane>
        <el-tab-pane label="路径审核" name="route"></el-tab-pane>
      </el-tabs>
      <div class="right" v-if="activeNametab == 'portrait'">
        <el-button size="mini" @click="cancel">返回</el-button>
        <el-button
          size="mini"
          type="primary"
          @click="auditing"
          v-if="portaitCheckStatus != 'AGREE' && CheckStatus != 'DISAGREE'"
          >审核通过</el-button
        >
        <el-button
          size="mini"
          type="info"
          @click="ignore"
          v-if="portaitCheckStatus != 'AGREE' && CheckStatus != 'DISAGREE'"
          >忽略</el-button
        >
      </div>
      <div class="right" v-else>
        <el-button size="mini" @click="cancel">返回</el-button>
        <el-button
          size="mini"
          type="primary"
          @click="auditing"
          v-if="routeCheckStatus != 'AGREE' && routeCheckStatus != 'DISAGREE'"
          >审核通过</el-button
        >
        <el-button
          size="mini"
          type="info"
          @click="ignore"
          v-if="routeCheckStatus != 'AGREE' && routeCheckStatus != 'DISAGREE'"
          >忽略</el-button
        >
      </div>
    </div>
    <!-- 画像审核 -->
    <div class="card" v-if="activeNametab == 'portrait'">
      <div class="cardleft">
        <div class="title">
          <div style="display: flex; align-items: center">
            <img
              class="headsculpture"
              v-if="list.sex == 'MALE'"
              src="../../../assets/manage/touxiang.png"
            />
            <img
              class="headsculpture"
              v-else
              src="../../../assets/manage/nvtouxiang.png"
            />
            <div class="name">
              {{ list.patientName ? list.patientName : "" }}
            </div>
            <div class="genderandage">
              <span>
                {{ list.sex == "MALE" ? "男" : "" }}
                {{ list.sex == "FEMALE" ? "女" : "" }}
              </span>
              <span v-if="list.sex && list.age" style="padding: 0 6px">|</span>
              <span v-if="list.age">{{ list.age }}岁</span>
            </div>
          </div>
          <div class="source">
            <div class="situation item">
              {{ list.visitMethod == "OUTPATIENT_SERVICE" ? "门诊" : "" }}
              {{ list.visitMethod == "BE_IN_HOSPITAL" ? "住院" : "" }}
            </div>
            <div
              class="item"
              style="color: #00e06e; border-color: #00e06e"
              v-if="list.patientSource == 'WE_CHAT_OFFICIAL_ACCOUNT'"
            >
              <img src="../../../assets/manage/gzh.png" alt="" />
              <div>公众号</div>
            </div>
            <div
              class="item"
              style="color: #339de5; border-color: #339de5"
              v-if="list.patientSource == 'WE_CHAT_APPLET'"
            >
              <img src="../../../assets/manage/xcx.png" alt="" />
              <div>小程序</div>
            </div>
            <div
              class="item"
              style="color: #f4881f; border-color: #f4881f"
              v-if="list.patientSource == 'MANAGE_END'"
            >
              <img src="../../../assets/manage/gld.png" alt="" />
              <div>管理端</div>
            </div>
          </div>
        </div>
        <div class="texts">
          <div class="text">
            医院: {{ list.hospitalAgencyName ? list.hospitalAgencyName : "" }}
          </div>
          <div class="text">
            科室: {{ list.departmentName ? list.departmentName : "" }}
          </div>
          <div class="text" v-if="list.visitMethod == 'BE_IN_HOSPITAL'">
            入院时间: {{ list.admissionTime }}
          </div>
          <div class="text" v-if="list.visitMethod == 'BE_IN_HOSPITAL'">
            出院时间: {{ list.dischargeTime }}
          </div>
          <div class="text" v-if="list.visitMethod == 'BE_IN_HOSPITAL'">
            审核时间: {{ list.portaitCheckDate }}
          </div>
          <div class="text" v-if="list.visitMethod == 'OUTPATIENT_SERVICE'">
            就诊时间: {{ list.dischargeTime }}
          </div>
        </div>
        <el-descriptions title="诊断信息" style="margin: 16px auto">
          <el-descriptions-item label="主要诊断">{{
            list.mainDiagnosis
          }}</el-descriptions-item>
        </el-descriptions>
        <el-descriptions
          title="手术信息"
          style="
            margin: 0 auto 16px;
            padding-top: 16px;
            border-top: 1px solid #e6ebf5;
          "
          v-if="list.visitMethod != 'OUTPATIENT_SERVICE'"
        >
          <el-descriptions-item label="手术名称">{{
            list.surgicalName
          }}</el-descriptions-item>
        </el-descriptions>
        <el-collapse v-model="activeNames">
          <el-collapse-item title="入院记录" name="-1">
            <div v-html="list.inHospitalInfo"></div>
          </el-collapse-item>
          <el-collapse-item
            title="手术记录"
            name="-2"
            v-if="list.visitMethod != 'OUTPATIENT_SERVICE'"
          >
            <div v-html="list.surgicalRecord"></div>
          </el-collapse-item>
          <el-collapse-item
            title="出院记录"
            name="-3"
            v-if="list.visitMethod != 'OUTPATIENT_SERVICE'"
          >
            <div v-html="list.outHospitalInfo"></div>
          </el-collapse-item>
        </el-collapse>
      </div>
      <!-- 画像编辑右侧 -->
      <div class="cardright">
        <portrait
          v-if="patientId"
          @portraitlist="portraitlist"
          :patientId="patientId"
          :portaitCheckStatus="portaitCheckStatus"
        ></portrait>
      </div>
    </div>
    <div class="card" v-else>
      <PathReview
        ref="PathReview"
        @on-routeCheckStatus="onrouteCheckStatus"
      ></PathReview>
    </div>
  </div>
</template>

<script>
import {
  getRouteNodeList,
  getByPatientId,
  updateRouteCheckStatus,
  updatePortaitCheckStatus
} from '@/api/manage/Auditing.js'
import { getAge } from "@/utils/age";
import portrait from '../components/portrait.vue'
import PathReview from '../components/PathReview.vue'
export default {
  components: {
    portrait,
    PathReview
  },
  name: "Auditing",
  data() {
    return {
      activeNametab: 'portrait',//切换
      baseUrl: process.env.VUE_APP_BASE_API,
      activeNames: ['-1', '-2', '-3'],
      list: {},
      // nodelist: [],
      lookitem: {},
      routeCheckStatus: undefined,
      patientId: null,
      portraitlistdata: [],
      CheckStatus: undefined,
      portaitCheckStatus: undefined,
    };
  },
  created() {
    // this.info();
    this.patientId = this.$route.query.patientId
    this.CheckStatus = this.$route.query.routeCheckStatus
    console.log(this.CheckStatus, 'CheckStatus')
    getByPatientId(this.$route.query.patientId).then(res => {
        res.data.birthDate ? res.data.age = getAge(res.data.birthDate) : ''
        this.list = res.data
        this.portaitCheckStatus = res.data.portaitCheckStatus
        console.log(this.portaitCheckStatus, '------')
      })

    // console.log(this.portaitCheckStatus, '--------------')
  },
  methods: {
    //路径审核页面传值
    onrouteCheckStatus(e) {
      this.routeCheckStatus = e.routeCheckStatus
    },
    // 画像审核传值
    portraitlist(val) {
      this.portraitlistdata = val
      console.log(this.portraitlistdata, '999999999')
    },
    // 忽略
    ignore() {
      // let manageRouteNodeIds = []
      // this.nodelist.map(e => {
      //   manageRouteNodeIds = [...manageRouteNodeIds, ...e.nodeList.map(el => el.id)]
      // })
      this.$prompt('请输入忽略备注信息?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
      }).then(({ value }) => {
        if (this.activeNametab == 'route') {
          let obj = {
            routeCheckRemark: value,
            routeCheckStatus: 'DISAGREE',
            signPatientRecordId: this.$route.query.signRecordId
          }
          updateRouteCheckStatus(obj).then(res => {
            this.$notify({
              type: 'success',
              title: '提示',
              message: '路径审核已忽略',
              duration: 3000
            });
            setTimeout(() => {
              this.$refs.PathReview.info();
            }, 1500);
          })
        } else {
          let obj = {
            patientId: this.patientId,
            portaitCheckRemark: value,
            portaitCheckStatus: 'DISAGREE',
            signPatientRecordId: this.$route.query.signRecordId,
            labelFieldAndPartitionDictList: [],
          }
          obj.labelFieldAndPartitionDictList = this.portraitlistdata
          updatePortaitCheckStatus(obj).then(res => {
            this.$notify({
              type: 'success',
              title: '提示',
              message: '已忽略,即将返回上一页',
              duration: 3000
            });
            setTimeout(() => {
              this.$store.dispatch('tagsView/delView', this.$route).then(({ visitedViews }) => {
                this.$router.push({
                  path: "/task/manualReview",
                });
              })
            }, 3000);
          })
        }
      })
    },
    //审核
    auditing() {
      let manageRouteNodeIds = []
      // this.nodelist.map(e => {
      //   manageRouteNodeIds = [...manageRouteNodeIds, ...e.nodeList.map(el => el.id)]
      // })
      this.$prompt('请输入审核备注信息?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
      }).then(({ value }) => {
        if (this.activeNametab == 'route') {
          let obj = {
            routeCheckRemark: value,
            routeCheckStatus: 'AGREE',
            signPatientRecordId: this.$route.query.signRecordId
          }
          updateRouteCheckStatus(obj).then(res => {
            this.$notify({
              type: 'success',
              title: '提示',
              message: '路径审核通过',
              duration: 3000
            });
            setTimeout(() => {
              this.$refs.PathReview.info();
            }, 1500);
          })
        } else {
          let obj = {
            patientId: this.patientId,
            portaitCheckRemark: value,
            portaitCheckStatus: 'AGREE',
            signPatientRecordId: this.$route.query.signRecordId,
            labelFieldAndPartitionDictList: [],
          }
          obj.labelFieldAndPartitionDictList = this.portraitlistdata
          console.log(obj, 'tijiao')
          // return
          updatePortaitCheckStatus(obj).then(res => {
            this.$notify({
              type: 'success',
              title: '提示',
              message: '画像审核通过',
              duration: 3000
            });
            this.info()
          })
        }
      })
    },
    info() {
      getByPatientId(this.$route.query.patientId).then(res => {
        res.data.birthDate ? res.data.age = getAge(res.data.birthDate) : ''
        this.list = res.data
        this.portaitCheckStatus = res.data.portaitCheckStatus
        console.log(this.portaitCheckStatus, '===============')
      })
      // getRouteNodeList({ patientId: this.$route.query.patientId, taskCreateType: 'MANUAL_CREATE', routeCheckStatus: "UNAUDITED" }).then(res => {
      //   this.nodelist = res.data
      // })
    },
    cancel() {
      this.$store.dispatch('tagsView/delView', this.$route).then(({ visitedViews }) => {
        this.$router.push({
          path: "/task/manualReview",
        });
      })
    },
  }
};
</script>
<style lang="scss" scoped>
::v-deep .el-tabs__nav {
  padding-left: 15px;
}

::v-deep .el-tabs__active-bar {
  left: 15px;
}

::v-deep iframe {
  width: 100%;
  height: 500px;
}

::v-deep .el-collapse-item__header {
  font-size: 16px;
  font-weight: bold;
}

.topfooter {
  background: #fff;
  width: 98%;
  margin: 0 auto;
  height: 60px;

  .right {
    /* float: right; */
    padding: 10px 10px 0 0;
    height: 35px;
    position: absolute;
    right: 15px;
    top: 12px;
  }
}

.texts {
  margin: 16px 0 20px;
  flex-wrap: wrap;
  width: 100%;
  display: flex;
  font-size: 14px;

  .text {
    margin-bottom: 10px;
    width: 50%;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    -o-text-overflow: ellipsis;
  }
}

.card {
  width: 100%;
  display: flex;
  justify-content: space-evenly;
  // padding: 20px 0;
  height: calc(100vh - 159px);

  .cardleft {
    width: 35%;
    background-color: #fff;
    overflow: auto;
    padding: 20px;

    .title {
      display: flex;
      align-items: center;
      justify-content: space-between;

      .source {
        display: flex;

        .situation {
          background-color: #f1faf7;
          padding: 3px 6px;
          color: #83cac0 !important;
          border: 1px solid #83cac0 !important;
        }

        .item {
          font-size: 14px;
          margin-left: 5px;
          border: 1px solid #fff;
          padding: 3px 6px;
          border-radius: 5px;
          justify-content: center;
          display: flex;
          align-items: center;

          img {
            margin-right: 2px;
            width: 16px;
            height: 16px;
          }
        }
      }

      .name {
        padding: 0 6px;
      }

      .genderandage {
        padding: 0 6px;
      }

      .headsculpture {
        width: 35px;
        height: 35px;
      }
    }
  }

  .cardright {
    overflow: auto;
    background-color: #fff;
    width: 62%;
    padding: 20px;
    font-size: 14px;
    margin-top: 20px;

    .textarea {
      font-size: 14px;
      font-weight: 400;
      margin-bottom: 10px;
      width: 100%;
    }

    .text {
      font-size: 16px;
      font-weight: bold;
    }
  }
}

.titletop {
  font-size: 16px;
  font-weight: 700;
}

.bodytop {
  position: relative;
  top: 20px;
  height: 500px;
  overflow: auto;
  border: 1px solid #e2e2e2;

  .titledata {
    margin: 30px 0px 15px 30px;
    top: 14px;
    font-size: 20px;
  }

  .audiotop {
    margin: 10px 0px 10px 30px;
  }

  img {
    // width: 100%;
    // width: 362px;
    // height: 127px;
    margin: 0px 0px 0px 30px;
  }

  .know {
    margin: 11px 0px 10px 30px;
    font-size: 16px;
  }

  .knowlist {
    margin: 10px 0px 10px 30px;
    font-size: 16px;
  }
}
</style>
