<template>
  <div class="physical">
    <!-- 底部数据 -->
    <div class="data-show">
      <div style="margin-bottom:10px;">
        <el-button type="primary" size="mini" @click="back()">返回</el-button>
      </div>
      <!-- <div class="flex-vertical-center-l btns">
                <div class="flex-center" @click="back()">返回</div>
                <div class="flex-center bg-yellow"
                    @click="$router.push({path:'/index/questions?pid='+$route.query.pid})">测试</div>
            </div>
      <div class="title-from">题目来源：中医体质分类与判定zyyxht/t157-2009</div>-->

      <div class="today-table">
        <el-table :data="tableData" stripe style="width: 100%" border height="100%">
          <!-- <el-table-column type="selection" width="55">
          </el-table-column>-->
          <el-table-column prop="id" label="序号" width="50" align="center"></el-table-column>
          <el-table-column prop="endoftime" label="测试时间" align="center" width="145"></el-table-column>
          <el-table-column prop="patientname" label="姓名" width="80" align="center"></el-table-column>
          <el-table-column prop="sex" label="性别" width="60" align="center"></el-table-column>
          <el-table-column prop="age" label="年龄" width="60" align="center"></el-table-column>
          <el-table-column prop="questionnaireType" label="问卷类型" width="80" align="center">
            <template
              slot-scope="scope"
            >{{scope.row.questionnaireType==1?'标准':scope.row.questionnaireType===null?'标准':'基公卫'}}</template>
          </el-table-column>
          <el-table-column prop="mainphysical" label="主要体质" align="center" width="180"></el-table-column>
          <el-table-column prop="secondphysical" label="倾向体质" align="center"></el-table-column>

          <el-table-column label="操作" align="center" width="350">
            <template slot-scope="scope">
              <!-- <div class="flex-center operation"> -->
              <!-- <div class="flex-center"
              @click="$router.push({path:'/index/questionsr?pid='+scope.row.pid})">查看</div>-->

              <el-button
                size="mini"
                type="primary"
                @click="$router.push({path:'/index/questionsr?pid='+scope.row.pid})"
              >详情</el-button>
              <el-button
                size="mini"
                type="primary"
                @click="$router.push({path:'/index/questionsr?pid='+scope.row.pid+'&type=edit'})"
              >健康干预</el-button>
              <el-button
                size="mini"
                type="primary"
                @click="$router.push({path:'/index/healthTrack?pid='+scope.row.pid})"
              >健康跟踪</el-button>
              <el-button size="mini" type="danger" @click="deleteRecord(scope)">删除</el-button>
              <!-- </div> -->
            </template>
          </el-table-column>
        </el-table>
      </div>
      <div class="flex-vertical-center-r today-page">
        <el-pagination
          background
          layout=" prev, pager, next, jumper, total"
          :total="total"
          :page-size="limit"
          @current-change="sizeC($event)"
        ></el-pagination>
      </div>
    </div>
  </div>
</template>
<script>
import {
  getUserPhysicList,
  getPhysicaRes,
  deletePhysicRecord
} from "@/api/diagnosis.js";
import { load } from "mime";

export default {
  data() {
    return {
      search_name: "",
      page: 1,
      limit: 10,
      total: 0,
      tableData: []
    };
  },
  created() {
    this.getUserPhysicList();
  },
  methods: {
    // 返回按钮点击
    back() {
      this.$router.back();
      // this.$router.push({
      //     path: '/index/physical'
      // })
    },
    sizeC(e) {
      this.page = e;
      this.getUserPhysicList();
    },
    deleteRecord(scope) {
      this.$confirm("确定要删除当前数据吗", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          this.deletePhysicRecord(scope.row.pid);
        })
        .catch(() => {});
    },
    // 获取列表
    async getUserPhysicList() {
      let res = await getUserPhysicList({
        patientId: this.$route.query.pid,
        page: this.page,
        limit: this.limit
      });
      if (res.ResultCode == 0) {
        this.tableData = res.Data.Items;
        this.total = res.Data.TotalRecordCount;

        this.tableData.filter((item, index) => {
          if (this.page > 1) {
            return (item.id = (this.page - 1) * 10 + (index + 1));
          } else {
            return (item.id = index + 1);
          }
        });
      }
    },
    // 删除 记录
    async deletePhysicRecord(id) {
      const loading = this.$loading({
        lock: true,
        text: "正在删除",
        spinner: "el-icon-loading",
        background: "rgba(0, 0, 0, 0.7)"
      });
      let res = await deletePhysicRecord({
        ids: id
      }).catch(err => {
        loading.close();
      });
      if (res.ResultCode == 0) {
        loading.close();
        this.$message({
          type: "success",
          message: "删除成功",
          showClose: true
        });

        this.getUserPhysicList();
      }
    }
  }
};
</script>
<style lang="scss" scoped>
@import "../../style/common.scss";
@import "../../style/base.scss";

.data-show {
  margin-top: 10px;
  padding: 10px;
  background: #ffffff;
  border-radius: 5px;
  height: 77vh;

  .btns {
    margin-bottom: 30px;

    div {
      width: 74px;
      height: 36px;
      background: #5386f6;
      border-radius: 4px;

      font-size: 14px;
      font-family: PingFang SC;
      font-weight: 400;
      color: #ffffff;
      cursor: pointer;
    }

    .bg-yellow {
      background: #ffae45;
      margin-left: 20px;
    }
  }

  .today-table {
    height: 82%;

    .operation {
      div {
        width: 60px;
        height: 24px;
        background: #5386f6;
        border-radius: 2px;
        cursor: pointer;
        font-size: 14px;
        font-family: PingFang SC;
        font-weight: 400;
        color: #ffffff;
      }

      .bg-yellow {
        background: #ffae45;
        margin-left: 15px;
      }
    }
  }
}

.table::v-deep .el-table .cell {
  text-align: center;
}
</style>

<style lang="scss" scoped>
@media screen and (min-width: 1681px) and (max-width: 1920px) {
  .data-show {
    height: 85vh;

    .today-table {
      height: 90%;
    }
  }

  .today-table::v-deep .el-table td {
    padding: 18px 0;
  }

  .today-table::v-deep .el-table th {
    padding: 18px 0;
  }
}

@media screen and (min-width: 1601px) and (max-width: 1680px) {
  .data-show {
    height: 85vh;

    .today-table {
      height: 90%;
    }
  }

  .today-table::v-deep .el-table td {
    padding: 16px 0;
  }

  .today-table::v-deep .el-table th {
    padding: 16px 0;
  }

  .today-table::v-deep .el-table td {
    padding: 16px 0;
  }

  .today-table::v-deep .el-table th {
    padding: 18px 0;
  }
}

@media screen and (min-width: 1361px) and (max-width: 1600px) {
  .data-show {
    height: 78vh;

    .today-table {
      height: 85%;
    }
  }

  .today-table::v-deep .el-table td {
    padding: 5px 0;
  }

  .today-table::v-deep .el-table th {
    padding: 5px 0;
  }
}

@media screen and(min-width:1281px) and (max-width: 1360px) {
  .data-show {
    height: 78vh;

    .today-table {
      height: 85%;
    }
  }

  .today-table::v-deep .el-table td {
    padding: 5px 0;
  }

  .today-table::v-deep .el-table th {
    padding: 5px 0;
  }
}
</style>