<template>
  <a-drawer
    :visible="avisible"
    class="drawerStyle update-record"
    placement="right"
    width="80%"
  >
    <div class="drawerMain">
      <div class="header">
        <div class="headerTitle">修改记录</div>
        <img
          style="width: 29px; height: 29px; cursor: pointer"
          src="../../assets/images/basicinfo/close.png"
          @click="closeDrawer"
        />
      </div>
      <div class="main">
        <div class="header_top">
          <div class="pathnameInp">
            <a-input
              v-model:value="username"
              style="width: 270px; height: 40px; border-radius: 8px"
              placeholder="请输入操作人姓名/工号"
            />
          </div>
          <div class="select addTimeBox">
            <div class="addTime">操作时间：</div>
            <a-range-picker
              v-model:value="searchdate"
              separator="至"
              :placeholder="['      开始时间', '        结束时间']"
              @change="searchTimeChange"
              valueFormat="YYYY-MM-DD"
            />
          </div>
          <div style="display: flex; margin-bottom: 20px">
            <div class="btn btn1" @click="getList">
              <div class="search"></div>
              <div class="btnText">搜索</div>
            </div>
            <div class="btnn1 btn2" @click="resetLearnPath">
              <div class="search"></div>
              <div class="btnText">重置</div>
            </div>
          </div>
        </div>
        <div class="table">
          <a-table
            :columns="tableColumns"
            :data-source="tableData"
            :pagination="pagination"
          ></a-table>
        </div>
      </div>
    </div>
  </a-drawer>
</template>

<script>
import { reactive, toRefs, computed, ref, onMounted } from "vue";
import { modifyList } from "@/api/growthpath";
export default {
  name: "UpdateRecord",
  setup(props, ctx) {
    const state = reactive({
      username: null,
      searchdate: [],
      avisible: false,
      growthId: null,
      pageSize: 10,
      pageNum: 1,
      total: 0,
      startTime: "",
      endTime: "",
    });
    const pagination = computed(() => ({
      total: state.total,
      showSizeChanger: false,
      current: state.pageNum,
      pageSize: state.pageSize,
      onChange: changePagination,
    }));
    const tableData = ref([]);
    const getList = () => {
      modifyList({
        growthId: state.growthId,
        pageSize: state.pageSize,
        pageNum: state.pageNum,
        username: state.username,
        startTime: state.startTime,
        endTime: state.endTime,
      }).then((res) => {
        console.log(res);
        tableData.value = res.data.data.records;
        state.total = res.data.data.total;
      });
    };
    const changePagination = (page) => {
      state.pageNum = page;
      getList();
    };

    const tableColumns = ref([
      {
        title: "操作内容",
        dataIndex: "operationContent",
        key: "operationContent",
        align: "center",
      },
      {
        title: "操作人",
        dataIndex: "createName",
        key: "createName",
        align: "center",
      },
      {
        title: "操作时间",
        dataIndex: "createTime",
        key: "createTime",
        align: "center",
      },
    ]);
    const searchTimeChange = (date) => {
      console.log(date);
      if (date) {
        state.startTime = date[0] + " 00:00:00";
        state.endTime = date[1] + " 23:59:59";
      } else {
        state.startTime = "";
        state.endTime = "";
      }
    };
    const resetLearnPath = () => {
      state.username = null;
      state.searchdate = [];
      state.startTime = "";
      state.endTime = "";
      state.pageNum = 1;
      getList();
    };
    const closeDrawer = () => {
      state.username = null;
      state.searchdate = [];
      state.avisible = false;
      state.startTime = "";
      state.endTime = "";
    };
    const open = (row) => {
      state.growthId = row.id;
      state.avisible = true;
      getList();
    };

    return {
      ...toRefs(state),
      closeDrawer,
      open,
      tableColumns,
      searchTimeChange,
      resetLearnPath,
      getList,
      tableData,
      pagination,
      changePagination,
    };
  },
};
</script>

<style scoped lang="scss">
.update-record {
  .ant-drawer-content-wrapper {
    // max-width: 1000px;
    .ant-drawer-header {
      display: none !important;
    }
    .ant-drawer-body {
      padding: 0;
    }
  }
  .drawerMain {
    min-width: 600px;
    margin: 0px 32px 0px 32px;
    overflow-x: auto;
    display: flex;
    flex-direction: column;
    .header {
      position: sticky;
      top: 0;
      right: 0;
      height: 73px;
      z-index: 9999;
      background-color: #fff;
      border-bottom: 1px solid #e8e8e8;
      display: flex;
      justify-content: space-between;
      align-items: center;
      // background-color: red;
      margin-bottom: 20px;
      .headerTitle {
        font-size: 18px;
        font-weight: 600;
        color: #333333;
        line-height: 25px;
        // margin-left: 24px;
      }
    }
    .main {
      display: flex;
      flex-direction: column;
      //align-items: center;
      .header_top {
        display: flex;
        flex-wrap: wrap;
        justify-content: start;
        .pathnameInp {
          margin-right: 20px;
          margin-bottom: 20px;
        }

        .select {
          margin-right: 20px;
          margin-bottom: 20px;
        }

        .addTimeBox {
          position: relative;
          display: flex;
          align-items: center;

          .addTime {
            position: absolute;
            z-index: 10;
            margin-left: 10px;
            color: rgba(0, 0, 0, 0.4);
          }

          .ant-picker {
            padding-left: 85px;
          }

          .ant-picker-range .ant-picker-active-bar {
            margin-left: 85px;
          }
        }

        .btn {
          padding: 0px 26px 0px 26px;
          height: 38px;
          background: #4ea6ff;
          border-radius: 8px;
          display: flex;
          align-items: center;
          justify-content: center;
          margin-right: 14px;
          flex-shrink: 0;
          cursor: pointer;

          .search {
            background-size: 100%;
          }

          .btnText {
            font-size: 14px;
            font-weight: 400;
            color: #ffffff;
            line-height: 36px;
            margin-left: 5px;
          }
        }

        .btnn1 {
          padding: 0px 26px 0px 26px;
          height: 38px;
          background: rgba(64, 158, 255, 1);
          border-radius: 8px;
          border: 1px solid rgba(64, 158, 255, 1);
          display: flex;
          align-items: center;
          justify-content: center;
          margin-right: 14px;
          flex-shrink: 0;
          cursor: pointer;

          .search {
            background-size: 100%;
          }

          .btnText {
            font-size: 14px;
            font-weight: 400;
            color: #fff;
            line-height: 36px;
            margin-left: 5px;
          }
        }

        .btn1 {
          .search {
            width: 15px;
            height: 17px;
            background-image: url("../../assets/images/courseManage/search0.png");
          }
        }

        .btn2 {
          .search {
            width: 16px;
            height: 18px;
            background-image: url("../../assets/images/courseManage/reset0.png");
          }
        }
        .btn1:active {
          background: #0982ff;
        }
        .btn2:active {
          background: #0982ff;
        }
      }
      .table {
        padding-bottom: 80px;
      }
    }
    .btnn {
      height: 72px;
      width: 100%;
      position: absolute;
      bottom: 0;
      left: 0;
      display: flex;
      align-items: center;
      justify-content: center;
      box-shadow: 0px 1px 35px 0px rgba(118, 136, 166, 0.16);
      .btn1 {
        width: 100px;
        height: 40px;
        border: 1px solid #4ea6ff;
        border-radius: 8px;
        color: #4ea6ff;
        background-color: #fff;
        cursor: pointer;
      }
      .btn2 {
        cursor: pointer;
        width: 100px;
        height: 40px;
        background: #4ea6ff;
        border-radius: 8px;
        border: 0;
        margin-left: 15px;
        color: #fff;
      }
    }
  }
}
</style>
