<template>
  <div class="physical">
    <!-- 顶部筛选 -->
    <div class="screening">
      <div class="screening-title flex-vertical-center-l">
        <img src="~@/assets/filters.png" alt />
      </div>
      <div class="screening-form flex-vertical-center-l flex-wrap">
        <div class="screening-item flex-vertical-center-l" style="max-width:240px;">
          <span>姓名：</span>
          <div class="input">
            <el-input size="mini" v-model="search_name" placeholder="请输入姓名"></el-input>
          </div>
        </div>
        <el-button type="primary" size="mini" @click="search()">搜索</el-button>
        <el-button type="warning" size="mini" @click="clearFilter()">清空</el-button>

        <el-button
          type="primary"
          size="mini"
          @click="$router.push({path:'/index/questions'})"
        >点击开始测试</el-button>
      </div>
    </div>

    <!-- 底部数据 -->
    <div class="data-show">
      <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="patientname" label="姓名" width="100" align="center"></el-table-column>
          <el-table-column prop="sex" label="性别" width="100" align="center"></el-table-column>
          <el-table-column prop="age" label="年龄" width="100" align="center"></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 prop="endoftime" label="末次测试时间" align="center"></el-table-column>

          <el-table-column label="操作" align="center" width="130">
            <template slot-scope="scope">
              <div class="flex-center operation">
                <div
                  class="flex-center"
                  @click="$router.push({path:`/index/physicald?pid=${scope.row.patientid}`})"
                >查看</div>
                <!-- <div class="flex-center bg-yellow" @click="deleteData(scope)">删除</div> -->
              </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 { getPhysicalList, deletePhysicRecord } from "@/api/diagnosis.js";
import { mapState, mapGetters, mapActions, mapMutations } from "vuex";
export default {
  data() {
    return {
      search_name: "",
      page: 1,
      limit: 10,
      total: 0,
      tableData: []
    };
  },
  created() {
    this.getPhysicalList(1);
  },
  methods: {
    clearFilter() {
      this.search_name = "";
      this.getPhysicalList();
    },
    deleteData(scope) {
      this.$confirm("确定要删除当前数据吗", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          this.deletePhysicRecord(scope.row.pid);
        })
        .catch(() => {});
    },
    sizeC(e) {
      this.page = e;
      this.getPhysicalList();
    },
    search() {
      this.page = 1;
      this.getPhysicalList();
    },
    // 获取列表接口
    async getPhysicalList(type) {
      const loading = this.$loading({
        lock: true,
        text: "正在获取数据....",
        spinner: "el-icon-loading",
        background: "rgba(0, 0, 0, 0.7)"
      });
      let params = {
        page: this.page,
        limit: this.limit,
        name: this.search_name,
        // patientId: this.getPatiensInfo.basisPatient ? this.getPatiensInfo.basisPatient.pid : ''
        patientId: ""
      };
      let res = await getPhysicalList(params).catch(err => loading.close());

      if (res.ResultCode == 0) {
        loading.close();
        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);
          }
        });

        // if (type == 1) return
        // if (this.getPatiensInfo.basisPatient) {

        //     this.$router.push({
        //         path: '/index/physicald?pid=' + this.getPatiensInfo.basisPatient.pid
        //     })

        //     return
        // }
        // if (this.getPatiensInfo.basisPatient) {
        //     res.Data.Items.forEach(item => {

        //         if (item.endoftime && item.patientid == this.getPatiensInfo.basisPatient.pid) {
        //             this.$router.push({
        //                 path: '/index/physicald?pid=' + item.patientid
        //             })
        //         }
        //     })
        // }
      }
    },
    // 删除 记录
    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.getPhysicalList();
      }
    }
  },
  computed: {
    ...mapGetters(["getPatiensInfo"])
  },
  beforeRouteEnter(to, from, next) {
    // if (from.name == 'physicald') {
    //     next(vm => {
    //         vm.getPhysicalList(1)
    //     })
    // } else {

    //     next(vm => {
    //         vm.getPhysicalList(2)
    //     })
    // }
    next();
  }
};
</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: 70vh;

  .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: 90%;

    .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: 81vh;

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

  .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: 81vh;

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

  .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: 72vh;

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

  .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: 72vh;

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

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

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