<template>
  <div>
    <div class="bigBox" :style="{ height: bigHeight }">
      <!-- 组织机构信息 -->
      <div class="left" :style="{ width: lfBoxWid }">
        <div class="title">
          <div style="display: flex; align-items: center">
            <div style="padding-top: 5px; margin-right: 5px">
              <el-icon style="color: var(--el-color-primary) !important">
                <List />
              </el-icon>
            </div>
            <span class="zzjgxx" v-if="iconChange">组织机构信息</span>
          </div>
          <el-icon @click="handleCollapse" v-show="iconChange">
            <DArrowLeft />
          </el-icon>
          <el-icon @click="handleCollapse" v-show="!iconChange">
            <DArrowRight />
          </el-icon>
        </div>
        <div class="treeBox" :style="{ height: treeHeight }">
          <MOSTY.DepartmentTree width="100%" placeholder="管理部门ID" clearable filterable :searchType="'01'"
            @getdeptData="getdeptId" />
        </div>
      </div>

      <!--  -->
      <div class="right" :style="{ width: rgBoxWid }">
        <!-- 头部 -->
        <div class="headBox" style="justify-content: space-between">
          <div class="title">驾驶员准驾证管理列表</div>
          <div class="btnBox" style="display: flex">
            <el-input v-model="listQuery.drivername" placeholder="请输入驾驶员名称进行查询" style="margin-right: 10px;" />
            <el-button type="primary" @click="addInfo" v-if="showsb">
              <!-- 只有车管员才能申请 -->
              <el-icon>
                <Plus />
              </el-icon>
              <span>申请</span>
            </el-button>
            <el-button type="primary" @click="addUserHander">
              <el-icon>
                <Search />
              </el-icon>
              <span>查询</span>
            </el-button>
          </div>
        </div>

        <!-- 表格 -->
        <div class="tabBox">
          <el-table ref="multipleTableRef" stripe :data="tableData" style="width: 100%" row-style="height:32px"
            @selection-change="handleSelectionChange" border>
            <el-table-column label="姓名" show-overflow-tooltip property="drivername"></el-table-column>
            <el-table-column label="性别" show-overflow-tooltip prop="sex">
              <template #default="{ row }">
                <dict-tag v-if="row.sex" :options="D_BZ_XB" :value="row.sex" :tag="false" />
                <span v-else>无</span>
              </template>
            </el-table-column>
            <el-table-column label="出生年月" show-overflow-tooltip property="brithday"></el-table-column>
            <el-table-column label="驾驶工龄" show-overflow-tooltip property="driverhistory"></el-table-column>
            <el-table-column label="驾驶证号" show-overflow-tooltip prop="drivernumber"></el-table-column>
            <el-table-column label="准驾车型" show-overflow-tooltip property="carstyle">
              <template #default="{ row }">
                <dict-tag v-if="row.carstyle" :options="D_TB_DRIVELEVEL" :value="row.carstyle" :tag="false" />
                <span v-else>无</span>
              </template>
            </el-table-column>
            <el-table-column label="当前状态" show-overflow-tooltip property="dqstate"></el-table-column>
            <el-table-column label="操作" width="200">
              <template #default="scope">
                <span class="operate" style="color: yellowgreen !important"
                  @click="handleSee(scope.row, 'see')">查看审核状态</span>
                <span class="operate" style="color: yellowgreen !important" @click="handleedit(scope.row)">查看信息</span>
                <span v-if="showzxtj" class="operate" style="color: yellowgreen !important"
                  @click="handleCkxx(scope.row)">重新提交</span>
                <span v-if="scope.row.state == '7'" class="operate" style="color: yellowgreen !important"
                  @click="handledel(scope.row, 'see')">删除</span>
              </template>
            </el-table-column>
          </el-table>
          <div class="fenye">
            <el-pagination class="pagination" @size-change="handleSizeChange" @current-change="handleCurrentChange"
              :current-page="listQuery.pageCurrent" :page-sizes="[2, 5, 10, 20]" :page-size="listQuery.pageSize"
              layout="total, prev, pager, next, sizes, jumper" :total="total"></el-pagination>
          </div>
        </div>
      </div>
      <!-- 新增 -->
      <div v-if="comprehensiveShow" class="dialog-box">
        <Sgzsbxq :saveBtnShow="saveBtnShow" :editObj="editObj" @close="close" :title="editObj.title" :rwid="rwid"
          :examineshow="examineshow" :type="type" />
      </div>
      <!-- 查看审核状态 -->
      <div v-if="showShzt" class="dialog-box">
        <Zbapxq :editObj="editObj" @close="close2" :title="editObj.title" :type="type" />
      </div>
    </div>
  </div>
</template>

<script setup>
// 引入
import { reactive, onMounted, ref, getCurrentInstance } from "vue";
import { ElMessage } from "element-plus";
import { getItem } from "@/utils/storage";
import { downloadImg } from "@/excel/Export2Excel.js";


import Zbapxq from "@/views/yxkzgl/jsygl/zbapxq.vue";
import Sgzsbxq from "@/views/yxkzgl/jsygl/Sgzsbxq.vue";
import { getApi, deleteApi, putApi, postApi } from "@/api/tobAcco_api.js";
import * as MOSTY from "@/components/MyComponents/index";
import { useRouter, useRoute } from "vue-router";
const router = useRouter();
const type = ref(null)
const showsb = ref(false);
const showzxtj = ref(false);
const styles = ref("01");
const { proxy } = getCurrentInstance();
// 数据
const { D_TB_DRIVELEVEL, D_BZ_XB } = proxy.$dict(
  "D_TB_DRIVELEVEL",
  "D_BZ_XB"
);
const bigHeight = ref(); //整个高度
const comprehensiveShow = ref(false);
const showShzt = ref(false);
const title = ref("");

const editObj = reactive({
  deptname: "",
  title: "",
  savebtn: true,
  formData: {}
});
const tableData = ref([]);
// 分页
const listQuery = reactive({
  pageCurrent: 1,
  pageSize: 20,
  orgcode: "",
  type: "2",
  time: "1"
});
const total = ref(0);
// 树的展开与折叠
const iconChange = ref(true);
const lfBoxWid = ref("300px");
const rgBoxWid = ref("calc(100% - 300px)");
// 方法
const bigHeightFn = () => {
  bigHeight.value = window.innerHeight - 147 + "px";
};
const handleCollapse = () => {
  iconChange.value = !iconChange.value;
  if (iconChange.value) {
    lfBoxWid.value = "300px";
    rgBoxWid.value = "calc(100% - 300px)";
  } else {
    lfBoxWid.value = "40px";
    rgBoxWid.value = "calc(100% - 40px)";
  }
};
onMounted(() => {
  bigHeightFn();
  treeHeightFn();
  getIscgy()
});
//获取部门数据
const getdeptId = (val) => {
  listQuery.orgcode = val.id;
  listQuery.pageCurrent = 1;
  getListData();
};

//	查询 是否为车管员
function getIscgy() {
  getApi({}, '/mosty-jcgl/sprole/judgeSprole').then(res => {
    if (res) {
      showsb.value = res;
    }
  })
}

// 获取表格数据
const tableloading = ref(false);
function getListData() {
  tableloading.value = true;
  editObj.deptname = getItem("deptId").ssbmid;
  postApi(listQuery, `/mosty-jcgl/driverposts/queryDriverpostsList`).then(
    (res) => {
      if (res.records) {
        tableloading.value = false;
        tableData.value = res.records;
        tableData.value.forEach(item => {
          if (item.tokzstate == '2') {
            item.dqstate = '省/市-安全处(科)负责人审批不通过'
            showzxtj.value = true
          } else if (item.tokzstate == '1') {
            item.dqstate = '完成'
            showzxtj.value = false
          } else if (item.carcontrollerstate == '2') {
            item.dqstate = '省/市-安全管理员审批不通过'
            showzxtj.value = true
          } else if (item.carcontrollerstate == '1') {
            item.dqstate = '省/市-安全处(科)负责人审批中'
            showzxtj.value = false
          } else if (item.unitspheadspsate == '2') {
            item.dqstate = '省/市-车管部门负责人审批不通过'
            showzxtj.value = true
          } else if (item.unitspheadspsate == '1') {
            item.dqstate = '省/市-安全管理员审批中'
            showzxtj.value = false
          } else if (item.fgldstate == '2') {
            item.dqstate = '市车管员审批不通过'
            showzxtj.value = true
          } else if (item.fgldstate == '1') {
            item.dqstate = '省/市-车管部门负责人审批中'
            showzxtj.value = false
          } else if (item.unitsecurityspstate == '2') {
            item.dqstate = '物流-车管部门负责人审批不通过'
            showzxtj.value = true
          } else if (item.unitsecurityspstate == '1') {
            item.dqstate = '市车管员审批中'
            showzxtj.value = false
          } else if (item.unitpartspstate == '2') {
            item.dqstate = '县-车管部门负责人审批不通过'
            showzxtj.value = true
          } else if (item.unitpartspstate == '1') {
            item.dqstate = '物流-车管部门负责人审批中'
            showzxtj.value = false
          } else {
            item.dqstate = '县-车管部门负责人审批中'
            showzxtj.value = false
          }
        })
        total.value = res.total;
      } else {
        tableData.value = [];
        tableloading.value = false;
      }
    }
  );
}
//弹窗关闭
const close = () => {
  comprehensiveShow.value = false;
  type.value = null;
  editObj.rowId = null
  getListData();
};
const close2 = () => {
  showShzt.value = false;
  getListData();
};
const saveBtnShow = ref(true);
const examineshow = ref(false);
//新增
function addInfo() {
  editObj.rowId = null
  type.value = 'zjzsq'
  comprehensiveShow.value = true;
  saveBtnShow.value = true;
  editObj.title = "驾驶员准驾证申请";
}
// 查看审核状态
function handleSee(row) {
  editObj.title = "驾驶员准驾证详情";
  type.value = 'zjzsq'
  editObj.rowId = row.id
  showShzt.value = true;
  saveBtnShow.value = false;
}
//修改
function handleCkxx(row) {
  editObj.title = "驾驶员准驾证详情";
  type.value = 'zjzsq'
  editObj.rowId = row.id
  comprehensiveShow.value = true;
  saveBtnShow.value = true;
}
//详情
function handleedit(row) {
  editObj.title = "驾驶员准驾证详情";
  type.value = 'zjzsq'
  comprehensiveShow.value = true;
  saveBtnShow.value = false;
  editObj.rowId = row.id
}
//删除
function delInfo(row) {
  postApi({}, `/mosty-jcgl/driverposts/deleteDriverpostsOne/${row.id}`).then((res) => {
    ElMessage.success("删除成功");
    getListData();
  });
}
//查询
function addUserHander() {
  listQuery.pageCurrent = 1;
  getListData();
}
//分页
const handleSizeChange = (currentSize) => {
  listQuery.pageSize = currentSize;
  getListData();
};
const handleCurrentChange = (currentPage) => {
  listQuery.pageCurrent = currentPage;
  getListData();
};

const treeHeight = ref("");
// 树高度计算
function treeHeightFn() {
  treeHeight.value = window.innerHeight - 187 + "px";
}
const rwid = ref("");
const route = useRoute();


</script>

<style lang="scss" scoped>
.from_box {
  display: flex;
  justify-content: space-between;

  .from_left {
    width: 25%;
  }
}

.el-form {
  width: 100%;
  display: flex;
  flex-wrap: wrap;
}

.bigBox {
  display: flex;

  .title {
    height: 60px;
    line-height: 60px;
    font-size: 18px;
    color: #0f3916;
    display: flex;
    justify-content: space-between;
    align-items: center;

    .el-icon {
      cursor: pointer;
    }
  }

  .left {
    width: 300px;
    // height: 1030px;
    background: #ffffff;
    box-shadow: 0px 2px 10px 0px rgba(107, 107, 107, 0.1);
    border-radius: 0px 0px 0px 0px;
    opacity: 1;

    .treeBox {
      overflow: auto;
    }
  }

  .right {
    padding: 0 10px;
    margin: 0px 14px;
    background: #fff;

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

    .btnBox {
      .el-select {
        width: 150px;
      }

      .header-right {
        display: flex;
        align-items: center;
      }

      .btnBox {
        display: flex;
        width: 500px;
        justify-content: space-between;
        align-items: center;
      }
    }
  }
}

.tabBox {
  height: calc(100% - 70px);
  border-left: 0 !important;

  .el-table {
    height: 91%;
  }

  .fenye {
    top: 95%;
  }
}
</style>