<template>
  <!-- 随访审核详情 -->
  <div class="follow-form">
    <el-header v-if="titlePosition === 'top'">
      <div class="follow-tab-top">
        <el-tabs v-model="activeTab" type="card">
          <el-tab-pane label="筛查" name="999"></el-tab-pane>
          <el-tab-pane
            v-for="(item, index) in followList"
            :key="index"
            :label="'第' + Number(index + 1) + '次随访数据'"
            :name="String(index)"
          ></el-tab-pane>
        </el-tabs>
      </div>
      <div class="extra_btn">
        <slot name="button"></slot>
      </div>
    </el-header>
    <el-container v-loading="fromLoading">
      <el-aside width="auto" v-if="titlePosition === 'left'">
        <div class="follow-tab">
          <el-tabs
            v-model="activeTab"
            tab-position="right"
            style="height: 200px"
          >
            <el-tab-pane label="筛查病例数据" name="999"></el-tab-pane>
            <el-tab-pane
              v-for="(item, index) in followList"
              :key="index"
              :label="'第' + Number(index + 1) + '次随访数据'"
              :name="String(index)"
            ></el-tab-pane>
          </el-tabs>
        </div>
      </el-aside>
      <el-main class="transition-box">
        <div class="my_form">
          <MyCustomForm
            v-show="activeTab === '999'"
            v-for="form in formTabs"
            :key="form.id"
            :form="form"
            :patientId="currentRow.patientId"
          ></MyCustomForm>
          <MyCustomForm
            v-show="activeTab !== '999'"
            v-for="form in followForms"
            :key="form.id"
            :form="form"
            :patientId="currentRow.patientId"
            :followId="followId"
          ></MyCustomForm>
        </div>
      </el-main>
      <el-aside width="auto" class="transition-box">
        <div class="follow-list">
          <ul class="list">
            <li v-for="(item, index) in screenList" :key="index">
              <div class="time">{{ item.update_time || item.create_time }}</div>
              <div class="time">
                {{ item.update_user_name || item.create_time }}
              </div>
              <div class="time">{{ item.sub_title }}</div>
            </li>
          </ul>
        </div>
      </el-aside>
    </el-container>
  </div>
</template>

<script>
import { mapGetters } from "vuex"
import CustomForm from "@/components/FormComponents/CustomForm/index"
import MyCustomForm from "./MyCustomForm.vue"
import { getCurrentFormByType } from "@/api/coop-group.js"
import { getFollowList } from "@/api/patient"
import { getFollowRecord } from "@/api/followup"
export default {
  name: "FollowReview",
  components: {
    CustomForm,
    MyCustomForm,
  },
  provide() {
    return {
      showIndex: true,
    }
  },
  props: {
    currentRow: {},
    titlePosition: {
      type: String,
      default: "left",
      validator: function (value) {
        return ["left", "top"].includes(value)
      },
    },
  },
  data() {
    return {
      fromLoading: false,
      formTabs: [],
      followForms: [],
      activeTab: "999",
      screenList: [],
      followList: [],
    }
  },
  computed: {
    ...mapGetters({
      group: ["user/group"],
    }),
    isEmpty() {
      return this.formTabs.length
    },
    followId() {
      return (
        (this.followList[this.activeTab] &&
          this.followList[this.activeTab].followId) ||
        null
      )
    },
  },
  watch: {
    followId() {
      this.getLogList()
    },
  },
  created() {
    this.getCurrentFormByType()
    this.getFollowInfo()
    this.getLogList()
  },

  methods: {
    getLogList() {
      const obj = {
        patientId: this.currentRow.patientId,
        followId: this.followId,
      }
      const key = obj.followId ? "followId" : "patientId"
      getFollowList({
        [key]: obj[key],
      }).then((res) => {
        if (res.code == 1) {
          this.screenList = res.data || []
        }
      })
    },
    getCurrentFormByType(type = 1) {
      this.fromLoading = true
      getCurrentFormByType({
        type,
        groupId: this.group.groupId,
      }).then((res) => {
        this.fromLoading = false
        if (res.code === 1) {
          const list = res.data.map((item, index) => {
            return {
              id: item.id,
              formId: item.formId,
              label: item.tabName,
            }
          })
          if (type === 2) {
            this.followForms = list
          } else {
            this.formTabs = list
          }
        }
      })
    },
    getFollowRecord() {
      getFollowRecord({
        patientId: this.currentRow.patientId,
        patientFrom: this.$store.getters["table/selectedIndex"],
      }).then((res) => {
        this.followList = res.data.filter((_) => _.followBatch > 0)
      })
    },
    getFollowInfo() {
      const { followBatch } = this.currentRow
      if (!followBatch) return
      this.getCurrentFormByType(2)
      this.getFollowRecord()
    },
  },
}
</script>

<style lang="scss" scoped>
.el-header {
  display: flex;
  margin-top: 20px;
  padding-right: 0;
  justify-content: space-between;
}
.follow-tab-top {
  width: calc(100% - 200px);
  padding-left: 10px;
  ::v-deep {
    .el-tabs--card > .el-tabs__header {
      border-bottom: none;
    }

    .el-tabs--card > .el-tabs__header .el-tabs__nav {
      border: none;
    }
    .el-tabs--card > .el-tabs__header .el-tabs__item {
      min-width: 116px;
      text-align: center;
      background: #f0f1fa;
      font-size: 14px;
      border: none;
    }
    .el-tabs--card > .el-tabs__header .el-tabs__item.is-active {
      background: #4e68ff;
      color: #fff;
    }
  }
}
.my_form {
  height: calc(100vh - 200px);
  overflow-y: auto;
}
.el-main {
  padding: 0px 20px;
}
.el-aside {
  padding-bottom: 20px;
}
.extra_btn {
  width: 170px;
  text-align: right;
  margin-top: 5px;
}
.follow-tab {
  ::v-deep {
    border-radius: 4px;
    border: 1px solid #cccccc;
    height: calc(100vh - 200px);

    .el-tabs__header {
      margin-left: 0px;
    }
    .el-tabs__nav-wrap.is-right::after {
      width: 0px;
    }
    .el-tabs__active-bar.is-right {
      width: 3px;
      height: 52px !important;
    }
    .el-tabs--right {
      height: auto !important;
    }
    .tab-title {
      padding: 16px;
      background: #fafafa;
      color: #333333;
      border-bottom: 1px solid #cccccc;
    }
    .el-tabs__item {
      padding: 16px;
      width: 180px;
      background: #fafafa;
      height: auto;
      line-height: inherit;
      border-bottom: 1px solid #cccccc;
      transition: all 1s;
    }
    .el-tabs__item.is-active {
      background: transparent;
    }
  }
}
.follow-list {
  border-radius: 4px;
  border: 1px solid #cccccc;
  height: 100%;
  background: #fafafa;
  padding-right: 15px;
  height: calc(100vh - 200px);
  overflow-y: overlay;
  li {
    padding: 16px;
    border-bottom: 1px solid #ccc;
    // cursor: pointer;
    .time {
      font-size: 14px;
      margin-bottom: 8px;
      font-family: AlibabaPuHuiTiR;
      text-align: left;
      &:first-child {
        color: #4e68ff;
      }
    }
  }
}
</style>
