<template>
  <div>
    <MOSTY.PageTree :pageTitle="''" :searchType="'03'" @getDeptId="getdeptId">
      <template #serach>
        <el-divider />
        <section class="button">
          <el-button type="primary" @click="addUserHander">
            <el-icon>
              <CirclePlus />
            </el-icon>
            <span>新增</span>
          </el-button>
        </section>
      </template>
      <template #table>
        <section class="eltab8">
          <MOSTY.Table :table-columns="tableColumn" :tableData="tableData" :tableloading="tableloading"
            :isSelect="false" :isSort="true" @SortChange="SortChange" style="width: 100%;" :actionsW="250">
            <template #studyType="{ row }">
              <dict-tag :options="D_BZ_AQXX_TYPE" :value="row.studyType" :tag="false" />
            </template>
            <template #actions="{ row }">
              <span class="operedit" @click="editClick(row)"><el-icon>
                  <EditPen />
                </el-icon>修改</span>
              <span class="operedit" @click="signInClick(row)"><el-icon>
                  <EditPen />
                </el-icon>签到</span>
              <span class="operesee" @click="seeClick(row)"><el-icon>
                  <View />
                </el-icon>查看</span>
              <el-popconfirm confirm-button-text="是" cancel-button-text="否" icon-color="red" title="确定要删除?"
                @confirm="handledelete(row)">
                <template #reference>
                  <span class="operdel" size="small">
                    <el-icon>
                      <Delete />
                    </el-icon>删除</span>
                </template>
              </el-popconfirm>
            </template>
          </MOSTY.Table>
        </section>
        <div class="fenye">
          <MOSTY.Pages :pageConfiger="pageConfiger" @changeSize="handleSizeChange" @changeNo="handleCurrentChange">
          </MOSTY.Pages>
        </div>
      </template>
    </MOSTY.PageTree>

    <!-- 修改 -->
    <div v-if="comprehensiveShow" class="dialog-box">
      <EditLlxx @close="close" :title="title" :studyType='"04"' :orgcode="listQuery.ssdwid" :rowId="rowId"
        :saveBtnShow="saveBtnShow" />
    </div>
    <!-- 签到 -->
    <SignInDialog v-if="signInDialog" :id="currId" @close="signInDialog = false" :isAuth="isAqbm" />
  </div>
</template>

<script setup>
// 引入
import { onMounted, reactive, ref, getCurrentInstance, computed, nextTick, watch } from "vue";
import { ElMessage } from "element-plus";
import EditLlxx from "@/views/dutyBook/jgryandzz/commponents/EditLlxx.vue";
import SignInDialog from '@/views/dutyBook/jgryandzz/commponents/SignInDialog.vue'
import * as MOSTY from "@/components/MyComponents/index";
import { getApi, deleteApi, putApi, postApi } from "@/api/tobAcco_api.js";
import { getItem } from "@/utils/storage";
const { proxy } = getCurrentInstance();
const { D_BZ_AQXX_TYPE } = proxy.$dict("D_BZ_AQXX_TYPE");
// 数据
const comprehensiveShow = ref(false);
const listQuery = reactive({
  pageCurrent: 1,
  pageSize: 20,
  theme: '',
  studyType: '04',
  ssbmid: '',
  ssdwid: getItem("deptId").ssdwid
});
const tableData = ref([]);
const signInDialog = ref(false);
const currId = ref(null)
const rowId = ref(null);
const saveBtnShow = ref(true);
const title = ref("");

const tableColumn = ref([
  {
    title: "所属单位",
    prop: "ssdwmc",
    sortable: true
  },
  {
    title: "所属部门",
    prop: "ssbmmc",
    sortable: true
  },
  {
    title: "学习类型",
    prop: "studyType",
    slot: true,
    sortable: true
  },
  {
    title: "安全主题",
    prop: "theme",
    sortable: true
  },
  {
    title: "学习日期",
    prop: "studyTime",
    sortable: true
  },
  {
    title: "操作",
    prop: "actions",
    slot: true
  }
])
const pageConfiger = reactive({
  pageSize: 20,
  pageCurrent: 1,
  total: 0
})

function close() {
  rowId.value = null
  comprehensiveShow.value = false
  getListData()
}
//获取列表数据
const tableloading = ref(false);
function getListData() {
  tableloading.value = true;
  getApi(listQuery, `/mosty-jcgl/aqxx/getPageList`).then((res) => {
    if (res) {
      tableData.value = res.records
      pageConfiger.total = res.total
    }
  }).finally(() => {
    tableloading.value = false;
  })
}

//分页
const handleSizeChange = (currentSize) => {
  listQuery.pageSize = currentSize;
  pageConfiger.pageSize = currentSize;
  getListData();
};
const handleCurrentChange = (currentPage) => {
  listQuery.pageCurrent = currentPage;
  pageConfiger.pageCurrent = currentPage;
  getListData();
};
//选择右侧部门
const getdeptId = (val) => {
  listQuery.ssbmid = val.id;
  listQuery.pageCurrent = 1;
  pageConfiger.pageCurrent = 1;
  getListData();
};
// 方法

//新增
const addUserHander = () => {
  title.value = "驾驶员培训登记新增";
  orgcode.value = listQuery.ssbmid
  comprehensiveShow.value = true;
  rowId.value = null;
  saveBtnShow.value = true;
};

// 编辑
const orgcode = ref("")
const editClick = (row) => {
  title.value = "驾驶员培训登记修改";
  orgcode.value = listQuery.ssbmid
  comprehensiveShow.value = true;
  saveBtnShow.value = true;
  rowId.value = row.id
};
// 签到
const signInClick = (row) => {
  currId.value = row.id
  signInDialog.value = true
}
// 查看
const seeClick = (row) => {
  title.value = "驾驶员培训登记详情";
  comprehensiveShow.value = true;
  rowId.value = row.id
  saveBtnShow.value = false;
};
//删除
const handledelete = (row) => {
  deleteApi({}, "/mosty-jcgl	/aqxx/del/" + row.id).then(() => {
    ElMessage.success("删除成功");
    getListData();
  }
  );
};

</script>

<style lang="scss" scoped>
.toggle {
  height: 40px;
  cursor: pointer;
  display: flex;
  align-items: center;
  color: #0f3916;

  .el-icon {
    transform: rotate(90deg);
    transition: all 0.25s ease;
  }

  &.active {
    .el-icon {
      transform: rotate(-90deg);
    }
  }
}

.flex {
  display: flex;
  align-items: center;

  .left-tj {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: start;
  }
}

.query-flex {
  display: flex;
  justify-content: space-between;

  .query-section {

    width: 68%;
  }

  .query-btn {
    width: 360px;
    display: flex;
    justify-content: end;

    .toggle {
      height: 32px;
      cursor: pointer;
      display: flex;
      align-items: center;
      color: #0f3916;

      .el-icon {
        transform: rotate(90deg);
        transition: all 0.25s ease;
      }

      &.active {
        .el-icon {
          transform: rotate(-90deg);
        }
      }
    }
  }
}

.button {
  display: flex;
  align-items: center;
  justify-content: end;
  margin-bottom: 12px;
}
</style>