<template>
  <div style="display: flex;">
    <div :style="'width:' + (window.pageWidth - 200 - 120 - 90) + 'px;'">
      <el-table :data="customerOrg.customerOrgRegisterList" border :height="window.pageHeight < 600 ? 148:window.pageHeight - 452" size="small"
        highlight-current-row @row-click="rowClick" ref="customerOrg.customerOrgRegisterList">
        <el-table-column prop="medicalTimes" label="体检次数" />
        <el-table-column prop="beginTime" label="开始日期">
          <template slot-scope="scope">
            {{ moment(scope.row.beginTime).format('yyyy-MM-DD') }}
          </template>
        </el-table-column>
        <el-table-column prop="endTime" label="结束日期">
          <template slot-scope="scope">
            {{ moment(scope.row.endTime).format('yyyy-MM-DD') }}
          </template>
        </el-table-column>
        <el-table-column prop="isComplete" label="完成标志">
          <template slot-scope="scope">
            <div>{{ scope.row.isComplete === "Y" ? "是" : "否" }}</div>
          </template>
        </el-table-column>
        <el-table-column prop="creatorName" label="创建者" width="" />
        <el-table-column prop="creationTime" label="创建时间" width="200">
          <template slot-scope="scope">
            {{ moment(scope.row.creationTime).format('yyyy-MM-DD HH:mm:ss') }}
          </template>
        </el-table-column>
        <el-table-column prop="lastModifierName" label="修改者" />
        <el-table-column prop="lastModificationTime" label="修改时间" width="200">
          <template slot-scope="scope">
            {{ moment(scope.row.lastModificationTime).format('yyyy-MM-DD HH:mm:ss') }}
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div style="margin-left: 10px; margin-top: 40px">
      <div style="margin-top: 10px">
        <el-button type="primary" @click="add" class="btnClass">增加次数</el-button>
      </div>
      <div style="margin-top: 10px">
        <el-button type="success" @click="edit" class="btnClass">体检完成</el-button>
      </div>
      <div style="margin-top: 10px">
        <el-button type="danger" @click="cansel" class="btnClass">取消完成</el-button>
      </div>
    </div>
  </div>
</template>
<script>
import moment from "moment";
import { mapState, mapMutations } from "vuex";
import { getapi, postapi, putapi, deletapi } from "@/api/api";

export default {
  components: {},
  data() {
    return {
      customerOrgRegisterId: "", //体检次数ID
    };
  },

  created() { },

  //挂载完成
  mounted() { },

  computed: {
    ...mapState(["customerOrg", "window"]),
  },

  methods: {
    moment,
    //点击体检次数行
    rowClick(row) {
      this.customerOrgRegisterId = row.id;
    },

    //获取体检次数列表
    getCustomerOrgRegisterList(customerOrgId) {
      getapi(
        `/api/app/customer-org-register/in-customer-org-id/${customerOrgId}`
      ).then((res) => {
        //console.log('res.data',res.data)
        this.customerOrg.customerOrgRegisterList = res.data;
      });
      this.customerOrgRegisterId = "";
    },

    //设置体检次数状态
    setOrgRegisterState(IsComplete) {
      if (!this.customerOrg.customerOrgId || !this.customerOrgRegisterId) {
        console.log(this.customerOrg.customerOrgId, this.customerOrgRegisterId);
        alert("请选中要操作的体检次数");
        return;
      }
      //console.log(`/api/app/customer-org-register/${this.customerOrgRegisterId}/state`)
      putapi(
        `/api/app/customer-org-register/${this.customerOrgRegisterId}/state?IsComplete=${IsComplete}`
      ).then((res) => {
        console.log("设置体检次数状态", res.data);
        this.getCustomerOrgRegisterList(this.customerOrg.customerOrgId);
        this.$message.success("操作成功！");
      });
    },

    //体检次数 相关操作
    add() {
      //this.$message.success("增加次数 addTimes");
      let customerOrgId = this.customerOrg.customerOrgRegisterList[0].customerOrgId
      if (!customerOrgId) {
        alert("单位信息未保存！");
        return;
      }
      postapi(
        `/api/app/customer-org-register/default/${customerOrgId}`
      ).then((res) => {
        if (res.Code != -1) {
          this.getCustomerOrgRegisterList(customerOrgId);
          this.$message.success("操作成功！");
        }
      });
    },
    edit() {
      //this.$message.success("体检完成 editCustomerOrgRegister");
      this.setOrgRegisterState("Y");
    },
    cansel() {
      //this.$message.success("体检完成 editCustomerOrgRegister");
      this.setOrgRegisterState("N");
    },
  },
};
</script>
<style scoped>
.box {
  display: flex;
}

.btnClass {
  width: 110px;
}
</style>
