llj
2025-12-03 d14d0908c7137b03e838cf5af317012558bc727a
驾驶员列表和编辑
2个文件已添加
3个文件已修改
2444 ■■■■■ 已修改文件
.env.development 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/router/index.js 19 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/store/modules/permission.js 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/system/user/GyDriver.vue 1676 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/system/user/GyDriverEdit.vue 734 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
.env.development
@@ -5,8 +5,9 @@
ENV = 'development'
# 智云迈思L-MOM管理系统/开发环境
VUE_APP_BASE_API = 'http://localhost:81/API/'
# VUE_APP_BASE_API = 'http://localhost:81/API/'
# VUE_APP_BASE_API = 'http://47.96.97.237/API/'
VUE_APP_BASE_API = 'http://localhost:8082/LuBaoAPI/'
# VUE_APP_BASE_API = 'http://220.189.218.155:9010/API/'
# 路由懒加载
VUE_CLI_BABEL_TRANSPILE_MODULES = true
src/router/index.js
@@ -204,6 +204,25 @@
      },
    ],
  },
  //用户列表
  {
    path: "/system/user/GyDriver",
    component: Layout,
    hidden: true,
    redirect: "noredirect",
    meta: {
      breadcrumb: false, // 如果设置为false,则不会在breadcrumb面包屑中显示
      activeMenu: "/system/user", // 当路由设置了该属性,则会高亮相对应的侧边栏。
    },
    children: [
      {
        path: "/system/user/GyDriver",
        component: () => import("@/views/system/user/GyDriver.vue"),
        name: "gyDriver",
        meta: { title: "驾驶员列表", activeMenu: "system/user" },
      },
    ],
  },
  //采购入库单
  {
    path: "/purchase/POStockInBill/POStockInBillList",
src/store/modules/permission.js
@@ -1259,6 +1259,18 @@
                      icon: "build",
                      link: null,
                      noCache: false,
                      title: "驾驶员列表",
                    },
                    component: () =>import("@/views/system/user/GyDriver.vue"),
                    hidden: false,
                    name: "gyDriver",
                    path: "GyDriver",
                  },
                  {
                    meta: {
                      icon: "build",
                      link: null,
                      noCache: false,
                      title: "权限查询",
                    },
                    component: () =>
src/views/system/user/GyDriver.vue
New file
@@ -0,0 +1,1676 @@
<template>
  <div style="padding: 10px">
    <el-card class="search-card" style="margin-bottom: 15px">
            <el-button
              type="text"
              @click="toggleAdvancedSearch"
              style="font-size: 12px; color: #409eff"
            >
              {{ showAdvancedSearch ? "收起" : "更多" }}
              <i
                :class="
                  showAdvancedSearch
                    ? 'el-icon-arrow-up'
                    : 'el-icon-arrow-down'
                "
              ></i>
            </el-button>
      <div style="margin-top: 15px">
        <el-row :gutter="15">
          <el-col :span="6">
            <div style="display: flex; align-items: center">
              <span style="width: 200px; text-align: right; margin-right: 10px"
                >驾驶员代码:</span
              >
              <el-input
                v-model="queryParams.HNumber"
                placeholder="请输入驾驶员代码"
                size="small"
                @keyup.enter.native="handleQuery"
                clearable
              />
            </div>
          </el-col>
          <el-col :span="6">
            <div style="display: flex; align-items: center">
              <span style="width: 200px; text-align: right; margin-right: 10px"
                >驾驶员名称:</span
              >
              <el-input
                v-model="queryParams.HName"
                placeholder="请输入驾驶员名称"
                size="small"
                @keyup.enter.native="handleQuery"
                clearable
              />
            </div>
          </el-col>
          <el-col :span="6">
            <div style="display: flex; align-items: center">
              <span style="width: 100px; text-align: right; margin-right: 10px"
                >组织:</span
              >
              <el-select
                v-model="queryParams.HUSEORGID"
                placeholder="请选择组织"
                size="small"
                style="width: 100%"
              >
                <el-option
                  v-for="(item, index) in organizationList"
                  :key="index"
                  :label="item.Name"
                  :value="item.ID"
                >
                </el-option>
              </el-select>
            </div>
          </el-col>
          <el-col :span="6">
            <div style="display: flex; align-items: center">
              <span style="width: 80px; text-align: right; margin-right: 10px"
                >重新同步:</span
              >
              <el-input
                v-model="queryParams.HSyncNumber"
                placeholder="请输入驾驶员代码"
                size="small"
                @keyup.enter.native="handleSync"
                clearable
                style="flex: 1"
              />
              <el-button
                @click="handleSync"
                size="small"
                style="margin-left: 5px"
                >同步</el-button
              >
            </div>
          </el-col>
        </el-row>
      <div class="search-header">
        <div style="display: flex; justify-content: space-between; align-items: center">
          <div>
            <el-button
              type="primary"
              icon="el-icon-search"
              size="mini"
              @click="handleQuery"
              style="margin-right: 10px"
              >搜索</el-button
            >
            <el-button
              icon="el-icon-refresh"
              size="mini"
              @click="resetQuery"
              style="margin-right: 10px"
              >重置</el-button
            >
            <el-button
              icon="el-icon-refresh"
              size="mini"
              @click="getList"
              style="margin-right: 10px"
              >刷新</el-button
            >
          </div>
        </div>
      </div>
        <el-collapse-transition>
          <div v-show="showAdvancedSearch">
            <div style="margin-top: 15px">
              <el-row :gutter="15">
                <div style="margin-bottom: 50px">
                <!-- 第一组过滤条件 -->
                <el-col :span="24">
                  <div style="display: flex; align-items: center">
                    <el-select
                      v-model="queryParams.ColName"
                      placeholder="请选择"
                      size="small"
                      style="flex: 1"
                    >
                      <el-option label="" value="0"></el-option>
                      <el-option
                        v-for="(item, index) in filterColumnList"
                        :key="index"
                        :label="item.field"
                        :value="item.field"
                        v-if="!item.hide"
                      ></el-option>
                    </el-select>
                    <el-select
                      v-model="queryParams.Comparator"
                      placeholder="请选择"
                      size="small"
                      style="width: 100px; margin: 0 10px"
                    >
                      <el-option label="" value="0"></el-option>
                      <el-option
                        v-for="(item, index) in comparatorList"
                        :key="index"
                        :label="item.label"
                        :value="item.value"
                      ></el-option>
                    </el-select>
                    <el-input
                      v-model="queryParams.ColContent"
                      placeholder="请输入"
                      size="small"
                      @keyup.enter.native="handleQuery"
                      clearable
                      style="flex: 1"
                    />
                  </div>
                </el-col>
                </div>
                <div style="margin-bottom: 100px">
                <!-- 第二组过滤条件 -->
                <el-col :span="24">
                  <div style="display: flex; align-items: center">
                    <el-select
                      v-model="queryParams.ColName1"
                      placeholder="请选择"
                      size="small"
                      style="flex: 1"
                    >
                      <!-- <el-option label="" value="0"></el-option> -->
                      <el-option
                        v-for="(item, index) in filterColumnList"
                        :key="index"
                        :label="item.field"
                        :value="item.field"
                        v-if="!item.hide"
                      ></el-option>
                    </el-select>
                    <el-select
                      v-model="queryParams.Comparator1"
                      placeholder="请选择"
                      size="small"
                      style="width: 100px; margin: 0 10px"
                    >
                      <!-- <el-option label="" value="0"></el-option> -->
                      <el-option
                        v-for="(item, index) in comparatorList"
                        :key="index"
                        :label="item.label"
                        :value="item.value"
                      ></el-option>
                    </el-select>
                    <el-input
                      v-model="queryParams.ColContent1"
                      placeholder="请输入"
                      size="small"
                      @keyup.enter.native="handleQuery"
                      clearable
                      style="flex: 1"
                    />
                  </div>
                </el-col>
                </div>
                <div style="margin-bottom: 50px">
                <!-- 第三组过滤条件 -->
                <el-col :span="24">
                  <div style="display: flex; align-items: center">
                    <el-select
                      v-model="queryParams.ColName2"
                      placeholder="请选择"
                      size="small"
                      style="flex: 1"
                    >
                      <!-- <el-option label="" value="0"></el-option> -->
                      <el-option
                        v-for="(item, index) in filterColumnList"
                        :key="index"
                        :label="item.field"
                        :value="item.field"
                        v-if="!item.hide"
                      ></el-option>
                    </el-select>
                    <el-select
                      v-model="queryParams.Comparator2"
                      placeholder="请选择"
                      size="big"
                      style="width: 100px; margin: 0 10px"
                    >
                      <el-option label="" value="0"></el-option>
                      <el-option
                        v-for="(item, index) in comparatorList"
                        :key="index"
                        :label="item.label"
                        :value="item.value"
                      ></el-option>
                    </el-select>
                    <el-input
                      v-model="queryParams.ColContent2"
                      placeholder="请输入"
                      size="big"
                      @keyup.enter.native="handleQuery"
                      clearable
                      style="flex: 1"
                    />
                  </div>
                </el-col>
                </div>
              </el-row>
            </div>
            <div
              v-if="currentFilterScheme"
              style="
                margin-top: 15px;
                padding: 10px;
                background-color: #f0f9ff;
                border-radius: 4px;
                border-left: 4px solid #409eff;
              "
            >
              <span style="font-size: 14px; font-weight: bold; color: #fc9393">
                当前过滤方案:{{ currentFilterScheme }}
              </span>
              <span
                v-if="currentFilterRemark"
                style="font-size: 13px; color: #7b90fb; margin-left: 10px"
              >
                ({{ currentFilterRemark }})
              </span>
              <el-button
                type="text"
                @click="handleSaveScheme"
                size="mini"
                style="margin-left: 20px"
                >保存方案</el-button
              >
              <el-button
                type="text"
                @click="handleReadScheme"
                size="mini"
                >读取方案</el-button
              >
              <el-button
                type="text"
                @click="clearFilterScheme"
                size="mini"
                style="color: #f56c6c"
                >清除方案</el-button
              >
            </div>
          </div>
        </el-collapse-transition>
      </div>
    </el-card>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-upload2"
          size="mini"
          @click="handleImport"
          id="set_SouceExcel"
          >导入</el-button
        >
      </el-col>
      <!-- <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          id="get_export"
          >导出</el-button
        >
      </el-col> -->
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAddEdit((OperationType = 1))"
          id="set_add"
          >新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-document-copy"
          size="mini"
          :disabled="single"
          @click="handleCopy"
          id="set_Copy"
          >复制</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleEdit((row = rowForm), (OperationType = 3))"
          id="set_show"
          >编辑</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="single"
          @click="handleDelete"
          id="set_delete"
          >删除</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-check"
          size="mini"
          :disabled="single"
          @click="handleAudit(0)"
          id="btn_audit"
          >审核</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-close"
          size="mini"
          :disabled="single"
          @click="handleAudit(1)"
          id="btn_deaudit"
          >反审核</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-turn-off"
          size="mini"
          :disabled="single"
          @click="handleStop(0)"
          id="btn_stop"
          >禁用</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-open"
          size="mini"
          :disabled="single"
          @click="handleStop(1)"
          id="btn_destop"
          >反禁用</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-setting"
          size="mini"
          @click="handleRowHide"
          id="set_hidecolumn"
          >列设置</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-s-operation"
          size="mini"
          @click="handleBtnHide"
          id="HideButton"
          >按钮设置</el-button
        >
      </el-col>
    </el-row>
    <div class="tableBox" v-loading="loading">
      <el-table
        :data="tableData"
        ref="tableData"
        max-height="650"
        @selection-change="handleSelectionChange"
        border
        @row-click="handleRowClick"
        :row-style="rowStyle"
        @cell-dblclick="handleDblclick"
        v-if="tableShow"
        stripe
      >
        <el-table-column
          type="selection"
          width="55"
          align="center"
          fixed="left"
        />
        <template v-for="(item, index) in btList">
          <el-table-column
            :align="item.align"
            :prop="item.field"
            :label="item.title"
            :width="item.width"
            :key="item.field"
            v-if="!item.hide && item.field !== 'checkbox'"
            :sortable="item.sort"
            show-overflow-tooltip
            :fixed="item.fixed"
          >
            <template slot-scope="{ row, column }">
              <div :style="item.style">
                <!-- 日期格式化 -->
                <span
                  v-if="
                    column.property.includes('日期') ||
                    column.property.includes('Date')
                  "
                >
                  {{ parseTime(row[column.property], "{y}-{m}-{d}") }}
                </span>
                <el-button
                  type="text"
                  @click="handleDriverCodeClick(row)"
                  v-else-if="column.property === '驾驶员代码'"
                  style="color: #409eff"
                  >{{ row[column.property] }}</el-button
                >
                <span
                  v-else-if="column.property === '禁用标记'"
                  :style="{
                    color: row[column.property] === 'Y' ? '#f56c6c' : '#67c23a',
                    fontWeight:
                      row[column.property] === 'Y' ? 'bold' : 'normal',
                  }"
                >
                  {{ row[column.property] === "Y" ? "已禁用" : "正常" }}
                </span>
                <!-- 审核状态特殊样式 -->
                <span
                  v-else-if="column.property === '审核人'"
                  :style="{
                    color: row[column.property] ? '#67c23a' : '#909399',
                  }"
                >
                  {{ row[column.property] || "未审核" }}
                </span>
                <span v-else>{{ row[column.property] }}</span>
              </div>
            </template>
          </el-table-column>
        </template>
      </el-table>
      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="page"
        :limit.sync="pageSize"
        :pageSizes="pageSizes"
        @pagination="getList"
      />
      <!-- 隐藏列设置弹窗 -->
      <el-dialog
        title="隐藏列设置"
        :visible.sync="openRowHide"
        width="816px"
        append-to-body
      >
        <RowSettings
          :colName="btResList"
          :HModName="HModName"
          @rowEditClose="rowSetClose"
          v-if="rowHideShow"
        />
      </el-dialog>
      <!-- 编辑弹窗 -->
      <el-dialog
        :title="editDialogTitle"
        :visible.sync="openEdit"
        width="1480px"
        append-to-body
        class="driver-edit-dialog"
        :before-close="closeEditDialog"
        :close-on-click-modal="false"
      >
        <GyDriverEdit
          :OperationType="OperationType"
          :linterid="rowForm.HItemID"
          :HSouceBillType="''"
          @editCloseGy="editGyClose"
          v-if="editShow"
          ref="editComponent"
        />
        <span slot="footer" class="dialog-footer" v-if="OperationType !== 4">
          <!-- <el-button @click="closeEditDialog">取 消</el-button>
          <el-button type="primary" @click="saveDriverData">保 存</el-button> -->
        </span>
      </el-dialog>
      <!-- 导入弹窗 -->
      <el-dialog
        :title="upload.title"
        :visible.sync="upload.open"
        width="1500px"
        append-to-body
      >
        <div style="margin-top: -20px">
          <el-button type="primary" @click="set_AddNew">导入数据</el-button>
          <el-button type="primary" @click="upload.open = false">退 出</el-button>
          <el-upload
            ref="upload"
            :limit="1"
            accept=".xlsx, .xls"
            style="display: inline-block; margin-left: 10px"
            :action="upload.url + '?updateSupport=' + upload.updateSupport"
            :disabled="upload.isUploading"
            :on-progress="handleFileUploadProgress"
            :on-success="handleFileSuccess"
          >
            <el-button type="primary">文件上传</el-button>
          </el-upload>
        </div>
        <el-table
          :data="uploadData"
          v-loading="uploadTableLoading"
          :row-class-name="uploadDataIndex"
          border
          height="550"
        >
          <el-table-column
            type="index"
            label="序号"
            width="55"
            align="center"
          />
          <el-table-column
            label="驾驶员代码"
            prop="驾驶员代码"
            align="center"
            width="120"
          />
          <el-table-column
            label="驾驶员名称"
            prop="驾驶员名称"
            align="center"
            width="120"
          />
          <el-table-column
            label="联系电话"
            prop="联系电话"
            align="center"
            width="120"
          />
          <el-table-column
            label="驾驶证号"
            prop="驾驶证号"
            align="center"
            width="120"
          />
          <el-table-column label="操作" align="center">
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                icon="el-icon-delete"
                @click="uploadDataDelete(scope.row)"
                >删除</el-button
              >
            </template>
          </el-table-column>
        </el-table>
        <pagination
          v-show="uploadTotal > 0"
          :total="uploadTotal"
          :page.sync="uploadPage"
          :limit.sync="uploadPageSize"
          :pageSizes="uploadPageSizes"
          @pagination="currentPage"
        />
      </el-dialog>
      <!-- 过滤方案弹窗 -->
      <el-dialog
        title="过滤方案列表"
        :visible.sync="openFilterScheme"
        width="80%"
        append-to-body
      >
        <div style="height: 500px; overflow: auto">
          <el-table
            :data="filterSchemeList"
            border
            style="width: 100%"
            @row-click="selectFilterScheme"
          >
            <el-table-column
              prop="方案名称"
              label="方案名称"
              width="200"
            ></el-table-column>
            <el-table-column
              prop="备注"
              label="备注"
              width="300"
            ></el-table-column>
            <el-table-column prop="创建人" label="创建人" width="120"></el-table-column>
            <el-table-column
              prop="创建日期"
              label="创建日期"
              width="150"
            ></el-table-column>
            <el-table-column label="操作" width="150" align="center">
              <template slot-scope="scope">
                <el-button
                  type="text"
                  size="mini"
                  @click="applyFilterScheme(scope.row)"
                  >应用</el-button
                >
                <el-button
                  type="text"
                  size="mini"
                  @click="deleteFilterScheme(scope.row)"
                  style="color: #f56c6c"
                  >删除</el-button
                >
              </template>
            </el-table-column>
          </el-table>
        </div>
        <span slot="footer" class="dialog-footer">
          <el-button type="primary" @click="confirmFilterScheme">确 定</el-button>
          <el-button @click="openFilterScheme = false">取 消</el-button>
        </span>
      </el-dialog>
    </div>
  </div>
</template>
<script>
import axios from "axios";
import RowSettings from "@/views/component/rowSettings";
import GyDriverEdit from "@/views/system/user/GyDriverEdit.vue";
export default {
  name: "GyDriverListNew",
  components: { RowSettings, GyDriverEdit },
  props: {
    openPage: { type: String },
  },
  data() {
    return {
      HModName: "gy_driver",
      HModuleName: "驾驶员设置",
      showAdvancedSearch: false,
      currentFilterScheme: "",
      currentFilterRemark: "",
      filterSchemeList: [],
      openFilterScheme: false,
      comparatorList: [
        { label: "=", value: "=" },
        { label: ">=", value: ">=" },
        { label: ">", value: ">" },
        { label: "<=", value: "<=" },
        { label: "<", value: "<" },
        { label: "<>", value: "<>" },
        { label: "包含", value: "7" },
        { label: "左包含", value: "8" },
        { label: "右包含", value: "9" },
        { label: "不包含", value: "10" },
      ],
      sWhere: "",
      organizationList: [],
      filterColumnList: [],
      user: "admin",
      Organization: "",
      currentRow: [],
      rowForm: {},
      editShow: false,
      openEdit: false,
      editDialogTitle: "驾驶员编辑",
      tableShow: true,
      openBtnHide: false,
      btnHideShow: false,
      rowHideShow: false,
      openRowHide: false,
      queryParams: {
        HUSEORGID: null,
        HName: null,
        HNumber: null,
        HSyncNumber: null,
        Comparator: "",
        Comparator1: "",
        Comparator2: "",
        ColContent: "",
        ColContent1: "",
        ColContent2: "",
        ColName: "",
        ColName1: "",
        ColName2: "",
      },
      showSearch: true,
      ids: [],
      single: true,
      multiple: true,
      loading: true,
      tyResList: [],
      btList: [],
      btResList: [],
      tableData: [],
      dataList: [],
      titleData: ["HItemID", "HUSEORGID", "HEmpID", "负责人"],
      pageSizes: [50, 100, 500, 5000, 50000],
      page: 1,
      pageSize: 50,
      total: 0,
      upload: {
        open: false,
        title: "导入驾驶员",
        isUploading: false,
        updateSupport: 0,
        url: process.env.VUE_APP_BASE_API + "/Gy_Driver/Gy_Driver_Excel",
      },
      uploadData: [],
      alluploadList: [],
      uploadTableLoading: false,
      uploadPageSizes: [50, 100, 500, 5000, 50000],
      uploadPage: 1,
      uploadPageSize: 50,
      uploadTotal: 0,
      OperationType: null,
      copyType: 0,
      baseURL: process.env.VUE_APP_BASE_API,
    };
  },
  created() {
    this.initData();
  },
  methods: {
    async initData() {
      try {
        const userRes = await axios.get(
          `${this.baseURL}/Web/GetUser?UserName=${
            sessionStorage.getItem("UserName") || "001"
          }&PassWord=123456&HOrgName=100038`
        );
        if (userRes.data.data && userRes.data.data[0]) {
          const userData = userRes.data.data[0];
          this.user = userData.Czymc || "admin";
          this.Organization = userData.HUSEORGID;
          this.queryParams.HUSEORGID = userData.HUSEORGID;
        }
        const orgRes = await axios.get(`${this.baseURL}/Web/GetOrganizations`);
        if (orgRes.data.count == 1) {
          this.organizationList = orgRes.data.data;
        }
        await this.getList();
      } catch (error) {
        this.$modal.msgError("初始化数据失败!");
      }
    },
    toggleAdvancedSearch() {
      this.showAdvancedSearch = !this.showAdvancedSearch;
    },
    async getList() {
      this.tableShow = false;
      this.loading = true;
      console.log("获取列表数据...",this.sWhere );
      try {
        const params = {
          sWhere: this.sWhere || "",
          user: this.user,
          Organization: this.Organization,
          page: this.page,
          size: this.pageSize,
        };
        const res = await axios.get(`${this.baseURL}/Gy_DriverController/list`, {
          params,
        });
        if (res.data.count == 1) {
          this.tyResList = res.data.data;
          this.btResList = res.data.list;
          this.total = res.data.count;
          this.processTableHeader(res.data.list, res.data.data);
        } else {
          this.$modal.msgError(res.data.Message || "获取数据失败");
        }
      } catch (error) {
        this.$modal.msgError("接口请求失败!");
      } finally {
        this.loading = false;
      }
    },
    processTableHeader(headerList, data) {
      const col = [];
      col.push({ type: "checkbox", fixed: "left", field: "checkbox" });
      headerList.forEach((item) => {
        if (this.titleData.includes(item.ColmCols)) {
          col.push({
            field: item.ColmCols,
            title: item.ColmCols,
            align: "center",
            hide: true,
          });
        } else {
          const column = {
            field: item.ColmCols,
            title: item.ColmCols,
            align: "center",
            sort: true,
            width: 200,
          };
          if (item.ColmType === "DateTime") {
            column.templet = true; // 标记为日期类型
          }
          col.push(column);
        }
      });
      this.btList = col;
      this.tableData = data;
      this.tableShow = true;
      this.updateFilterColumns();
      this.DisPlay_HideColumn();
    },
    updateFilterColumns() {
      this.filterColumnList = this.btList.filter(
        (item) => !item.hide && item.field !== "checkbox"
      );
    },
    async DisPlay_HideColumn() {
      try {
        const res = await axios.get(
          `${this.baseURL}/Xt_grdAlignment_WMES/grdAlignmentWMESList`,
          {
            params: {
              HModName: this.HModName,
              user: this.user,
            },
          }
        );
        if (res.data.data.length > 0) {
          const config = res.data.data[0];
          const dataCol = config.HGridString.split(",");
          dataCol.forEach((colStr, index) => {
            if (this.btList[index + 1]) {
              const colParts = colStr.split("|");
              // 隐藏列
              if (colParts[1] == "1") {
                this.btList[index + 1].hide = true;
              }
              // 列宽
              if (colParts[3] > 0) {
                this.btList[index + 1].width = colParts[3];
              }
              // 字体大小
              if (config.HFontSize != 0) {
                this.btList[index + 1].style = `font-size:${config.HFontSize}px;`;
              }
              // 显示列
              if (
                colParts[1] == "0" &&
                !this.titleData.includes(this.btList[index + 1].title)
              ) {
                this.btList[index + 1].hide = false;
              }
              // 对齐方式
              switch (colParts[2]) {
                case "L":
                  this.btList[index + 1].align = "left";
                  break;
                case "M":
                  this.btList[index + 1].align = "center";
                  break;
                case "R":
                  this.btList[index + 1].align = "right";
                  break;
              }
              // 列别名
              if (colParts[4]) {
                this.btList[index + 1].title = colParts[4];
              }
            }
          });
          // 冻结列
          if (config.HFixCols > 0) {
            for (
              let i = 1;
              i <= config.HFixCols && i < this.btList.length;
              i++
            ) {
              this.btList[i].fixed = "left";
            }
          }
          this.tableShow = false;
          this.$nextTick(() => {
            this.tableShow = true;
          });
        }
      } catch (error) {
        console.error("加载列配置失败:", error);
      }
    },
    handleQuery() {
      this.sWhere = "";
      const conditions = [];
      if (this.queryParams.HNumber) {
        conditions.push(`驾驶员代码 like '%${this.queryParams.HNumber}%'`);
      }
      if (this.queryParams.HName) {
        conditions.push(`驾驶员名称 like '%${this.queryParams.HName}%'`);
      }
      // if (this.queryParams.HUSEORGID) {
      //   conditions.push(`HUSEORGID = '${this.queryParams.HUSEORGID}'`);
      // }
      if (this.queryParams.ColName !== "0" && this.queryParams.Comparator !== "0") {
        const condition = this.buildCondition(
          this.queryParams.ColName,
          this.queryParams.Comparator,
          this.queryParams.ColContent
        );
        if (condition) conditions.push(condition);
      }
      if (
        this.queryParams.ColName1 !== "0" &&
        this.queryParams.Comparator1 !== "0"
      ) {
        const condition = this.buildCondition(
          this.queryParams.ColName1,
          this.queryParams.Comparator1,
          this.queryParams.ColContent1
        );
        if (condition) conditions.push(condition);
      }
      if (
        this.queryParams.ColName2 !== "0" &&
        this.queryParams.Comparator2 !== "0"
      ) {
        const condition = this.buildCondition(
          this.queryParams.ColName2,
          this.queryParams.Comparator2,
          this.queryParams.ColContent2
        );
        if (condition) conditions.push(condition);
      }
      if (conditions.length > 0) {
        this.sWhere ="and "+conditions;
      }
      console.log("查询条件:", this.sWhere);
      //this.sWhere += this.addSWhereByOpenType();
      this.page = 1;
      this.getList();
    },
    buildCondition(colName, comparator, content) {
      if (!content) return null;
      switch (comparator) {
        case "7":
          return `${colName} like '%${content}%'`;
        case "8":
          return `${colName} like '%${content}'`;
        case "9":
          return `${colName} like '${content}%'`;
        case "10":
          return `${colName} not like '%${content}%'`;
        default:
          return `${colName} ${comparator} '${content}'`;
      }
    },
    //
    addSWhereByOpenType() {
      // if (this.openPage) {
      //   return " and 禁用标记 = '' and ISNULL(审核人,'') <> ''";
      // }
      // // 直接打开的情况
      // return " and 禁用标记 = ' '";
    },
    resetQuery() {
      this.queryParams = {
        HUSEORGID: this.Organization,
        HName: "",
        HNumber: "",
        HSyncNumber: "",
        Comparator: "0",
        Comparator1: "0",
        Comparator2: "0",
        ColContent: "",
        ColContent1: "",
        ColContent2: "",
        ColName: "0",
        ColName1: "0",
        ColName2: "0",
      };
      this.sWhere = "";
      this.page = 1;
      this.getList();
    },
    async handleSync() {
      if (!this.queryParams.HSyncNumber) {
        this.$modal.msgWarning("请输入要同步的驾驶员代码");
        return;
      }
      try {
        const res = await axios.get(`${this.baseURL}/Gy_Driver/Gy_DriverViewApi`, {
          params: {
            Number: this.queryParams.HSyncNumber,
            Type: "JSY", // 驾驶员类型
            HUseOrgID: this.queryParams.HUSEORGID,
          },
        });
        if (res.data.count == 1) {
          this.$modal.msgSuccess("同步成功");
          this.getList();
        } else {
          this.$modal.msgError(res.data.Message || "同步失败");
        }
      } catch (error) {
        this.$modal.msgError("同步失败");
      }
    },
    // 点击行
    handleRowClick(row) {
      this.$refs.tableData.toggleRowSelection(row);
    },
    // 行样式
    rowStyle({ row }) {
      if (this.ids.includes(row.HItemID)) {
        return { background: "#ecf5ff" };
      }
      return {};
    },
    // 双击行
    handleDblclick(row) {
      this.rowForm = row;
      this.OperationType = 3;
      this.editDialogTitle = "编辑驾驶员";
      this.openEdit = true;
      this.editShow = true;
    },
    handleDriverCodeClick(row) {
      this.rowForm = row;
      this.OperationType = 3;
      this.editDialogTitle = "编辑驾驶员";
      this.openEdit = true;
      this.editShow = true;
    },
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.HItemID);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
      if (!this.single) {
        this.rowForm = selection[0];
      }
    },
    // 新增
    handleAddEdit() {
      this.rowForm = { HItemID: 0 };
      this.OperationType = 1;
      this.editDialogTitle = "新增驾驶员";
      this.openEdit = true;
      this.editShow = true;
    },
    // 复制
    handleCopy() {
      if (this.single) {
        this.$modal.msgWarning("请选择一条数据进行复制");
        return;
      }
      this.OperationType = 2;
      this.editDialogTitle = "复制驾驶员";
      this.openEdit = true;
      this.editShow = true;
    },
    // 编辑
    handleEdit() {
      if (this.single) {
        this.$modal.msgWarning("请选择一条数据进行编辑");
        return;
      }
      this.OperationType = 3;
      this.editDialogTitle = "编辑驾驶员";
      this.openEdit = true;
      this.editShow = true;
    },
    // 关闭编辑弹窗
    closeEditDialog() {
      this.openEdit = false;
      this.editShow = false;
      setTimeout(() => {
        this.getList();
      }, 100);
    },
    // 保存
    async saveDriverData() {
      if (this.$refs.editComponent) {
        await this.$refs.editComponent.handleSave();
        this.closeEditDialog();
      }
    },
    // 关闭编辑页面
    editGyClose(val) {
      this.editShow = false;
      this.openEdit = false;
      this.getList();
    },
    // 删除
    async handleDelete() {
      if (this.single) {
        this.$modal.msgWarning("请选择一条数据进行删除");
        return;
      }
      if (this.rowForm.审核人) {
        this.$modal.msgError("已审核的数据不能删除");
        return;
      }
      try {
        await this.$modal.confirm("确认要删除吗,删除后不能恢复");
        const res = await axios.get(`${this.baseURL}/DeltetGy_Driver`, {
          params: {
            HItemID: this.rowForm.HItemID.toString(),
            user: this.user,
          },
        });
        if (res.data.count == 1) {
          this.$modal.msgSuccess("删除成功");
          this.getList();
        } else {
          this.$modal.msgError(res.data.Message || "删除失败");
        }
      } catch (error) {
        if (error !== "cancel") {
          this.$modal.msgError("删除失败");
        }
      }
    },
    // 审核/反审核
    async handleAudit(isAudit) {
      if (this.single) {
        this.$modal.msgWarning("请选择一条数据");
        return;
      }
      try {
        const action = isAudit ? "反审核" : "审核";
        await this.$modal.confirm(`确认要${action}吗?`);
        const res = await axios.get(`${this.baseURL}/Gy_Driver/AuditGy_Driver`, {
          params: {
            HInterID: this.rowForm.HItemID.toString(),
            IsAudit: isAudit,
            CurUserName: this.user,
          },
        });
        if (res.data.count == 1) {
          this.$modal.msgSuccess(`${action}成功`);
          this.getList();
        } else {
          this.$modal.msgError(res.data.Message || `${action}失败`);
        }
      } catch (error) {
        if (error !== "cancel") {
          this.$modal.msgError("操作失败");
        }
      }
    },
    // 禁用/反禁用
    async handleStop(isStop) {
      if (this.single) {
        this.$modal.msgWarning("请选择一条数据");
        return;
      }
      try {
        const action = isStop ? "反禁用" : "禁用";
        await this.$modal.confirm(`确认要${action}吗?`);
        const res = await axios.get(`${this.baseURL}/Gy_Driver/StopGy_Driver`, {
          params: {
            HInterID: this.rowForm.HItemID.toString(),
            IsStop: isStop,
            CurUserName: this.user,
          },
        });
        if (res.data.count == 1) {
          this.$modal.msgSuccess(`${action}成功`);
          this.getList();
        } else {
          this.$modal.msgError(res.data.Message || `${action}失败`);
        }
      } catch (error) {
        if (error !== "cancel") {
          this.$modal.msgError("操作失败");
        }
      }
    },
    // // 导出
    // handleExport() {
    //   import("@/vendor/Export2Excel").then((excel) => {
    //     const tHeader = this.btList
    //       .filter((item) => !item.hide && item.field !== "checkbox")
    //       .map((item) => item.title);
    //     const filterVal = this.btList
    //       .filter((item) => !item.hide && item.field !== "checkbox")
    //       .map((item) => item.field);
    //     const data = this.formatJson(filterVal, this.tyResList);
    //     excel.export_json_to_excel({
    //       header: tHeader,
    //       data,
    //       filename: `驾驶员设置_${new Date().getTime()}`,
    //       autoWidth: true,
    //       bookType: "xlsx",
    //     });
    //   });
    // },
    formatJson(filterVal, jsonData) {
      return jsonData.map((v) =>
        filterVal.map((j) => {
          if (j.includes("日期") || j.includes("Date")) {
            return this.parseTime(v[j], "{y}-{m}-{d}");
          }
          return v[j];
        })
      );
    },
    parseTime(time, cFormat) {
      if (arguments.length === 0) {
        return null;
      }
      const format = cFormat || "{y}-{m}-{d} {h}:{i}:{s}";
      let date;
      if (typeof time === "object") {
        date = time;
      } else {
        if (typeof time === "string" && /^[0-9]+$/.test(time)) {
          time = parseInt(time);
        }
        if (typeof time === "number" && time.toString().length === 10) {
          time = time * 1000;
        }
        date = new Date(time);
      }
      const formatObj = {
        y: date.getFullYear(),
        m: date.getMonth() + 1,
        d: date.getDate(),
        h: date.getHours(),
        i: date.getMinutes(),
        s: date.getSeconds(),
        a: date.getDay(),
      };
      const time_str = format.replace(/{([ymdhisa])+}/g, (result, key) => {
        const value = formatObj[key];
        if (key === "a") {
          return ["日", "一", "二", "三", "四", "五", "六"][value];
        }
        return value.toString().padStart(2, "0");
      });
      return time_str;
    },
    // 导入
    handleImport() {
      this.uploadData = [];
      this.upload.title = "导入驾驶员";
      this.upload.open = true;
    },
    // 文件上传中
    handleFileUploadProgress(event, file, fileList) {
      this.upload.isUploading = true;
      this.uploadTableLoading = true;
    },
    // 文件上传成功
    handleFileSuccess(response, file, fileList) {
      this.upload.isUploading = false;
      this.$refs.upload.clearFiles();
      if (response.code == 1) {
        this.alluploadList = response.data;
        this.uploadData = this.getPage(this.uploadPage, this.alluploadList);
        this.uploadTotal = this.alluploadList.length;
        this.uploadTableLoading = false;
      } else {
        this.$alert(
          `<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>${response.Message}</div>`,
          "导入结果",
          { dangerouslyUseHTMLString: true }
        );
      }
    },
    // 执行导入
    async set_AddNew() {
      const validData = this.uploadData.filter((item) => item);
      if (validData.length === 0) {
        this.$modal.msgWarning("没有可导入的数据");
        return;
      }
      try {
        const sSubStr = JSON.stringify(validData);
        const sMainSub = sSubStr + "&和" + this.user;
        const res = await axios.post(`${this.baseURL}/Gy_Driver/Gy_Process_Excel`, {
          sMainSub: sMainSub,
        });
        this.$alert(
          `<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>${res.data.Message}</div>`,
          "导入结果",
          { dangerouslyUseHTMLString: true }
        );
        this.upload.open = false;
        this.getList();
      } catch (error) {
        this.$modal.msgError("导入失败");
      }
    },
    // 获取分页数据
    getPage(page, list) {
      const sindex = (page - 1) * this.uploadPageSize;
      const eindex = page * this.uploadPageSize;
      return list.slice(sindex, eindex);
    },
    // 导入分页
    currentPage(val) {
      this.uploadPage = val.page;
      this.uploadData = this.getPage(this.uploadPage, this.alluploadList);
    },
    // 导入数据序号
    uploadDataIndex({ row, rowIndex }) {
      row.index = rowIndex + 1 + (this.uploadPage - 1) * this.uploadPageSize;
    },
    // 删除导入数据
    uploadDataDelete(row) {
      this.$modal.confirm("确认要删除吗").then(() => {
        const deleteIndex = row.index - 1 - (this.uploadPage - 1) * this.uploadPageSize;
        this.uploadData.splice(deleteIndex, 1);
        this.alluploadList.splice(row.index - 1, 1);
        this.uploadTotal = this.alluploadList.length;
        // 重新计算当前页数据
        this.uploadData = this.getPage(this.uploadPage, this.alluploadList);
      });
    },
    // 隐藏列设置
    handleRowHide() {
      this.rowHideShow = true;
      this.openRowHide = true;
    },
    // 关闭列设置
    rowSetClose(val) {
      this.rowHideShow = false;
      this.openRowHide = val;
      this.getList();
    },
    // 按钮设置
    handleBtnHide() {
      this.$modal.msgInfo("按钮设置功能待开发");
    },
    // 保存方案
    handleSaveScheme() {
      this.$modal.msgInfo("保存方案功能待开发");
    },
    // 读取方案
    handleReadScheme() {
      this.loadFilterSchemes();
      this.openFilterScheme = true;
    },
    // 加载过滤方案
    async loadFilterSchemes() {
      try {
        const res = await axios.get(`${this.baseURL}/Xt_FastICScheme/list`, {
          params: {
            HModuleName: this.HModuleName,
            user: this.user,
          },
        });
        if (res.data.count == 1) {
          this.filterSchemeList = res.data.data;
        }
      } catch (error) {
        console.error("加载过滤方案失败:", error);
      }
    },
    // 选择过滤方案
    selectFilterScheme(row) {
      this.selectedFilterScheme = row;
    },
    // 应用过滤方案
    applyFilterScheme(row) {
      this.currentFilterScheme = row.方案名称;
      this.currentFilterRemark = row.备注;
      // 这里应该根据方案内容设置查询条件
      // 由于方案数据结构复杂,这里只做简单演示
      this.$modal.msgSuccess(`已应用方案:${row.方案名称}`);
      this.openFilterScheme = false;
    },
    // 删除过滤方案
    async deleteFilterScheme(row) {
      try {
        await this.$modal.confirm(`确认要删除方案"${row.方案名称}"吗?`);
        const res = await axios.post(`${this.baseURL}/Xt_FastICScheme/delete`, {
          HInterID: row.hmainid,
        });
        if (res.data.count == 1) {
          this.$modal.msgSuccess("删除成功");
          this.loadFilterSchemes();
        } else {
          this.$modal.msgError("删除失败");
        }
      } catch (error) {
        if (error !== "cancel") {
          this.$modal.msgError("删除失败");
        }
      }
    },
    // 确认过滤方案
    confirmFilterScheme() {
      if (this.selectedFilterScheme) {
        this.applyFilterScheme(this.selectedFilterScheme);
      } else {
        this.$modal.msgWarning("请选择一个过滤方案");
      }
    },
    // 清除过滤方案
    clearFilterScheme() {
      this.currentFilterScheme = "";
      this.currentFilterRemark = "";
      this.resetQuery();
      this.$modal.msgSuccess("已清除过滤方案");
    },
  },
};
</script>
<style scoped>
.search-card {
  border-radius: 4px;
  border: 1px solid #ebeef5;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
}
.search-header {
  border-bottom: 1px solid #ebeef5;
  padding-bottom: 8px;
  margin-bottom: 8px;
}
.mb8 {
  margin-bottom: 15px;
}
.tableBox {
  margin-top: 10px;
  border: 1px solid #ebeef5;
  border-radius: 4px;
  padding: 15px;
  background-color: #fff;
}
.driver-edit-dialog ::v-deep .el-dialog__body {
  padding: 20px;
}
/* 响应式调整 */
@media (max-width: 1200px) {
  .el-col {
    margin-bottom: 10px;
  }
}
/* 表格行样式优化 */
::v-deep .el-table--striped .el-table__body tr.el-table__row--striped td {
  background-color: #fafafa;
}
::v-deep .el-table th {
  background-color: #f5f7fa;
  color: #909399;
  font-weight: bold;
}
/* 按钮组样式 */
::v-deep .el-button-group .el-button {
  margin-right: 0;
}
/* 折叠过渡效果 */
.el-collapse-transition-enter-active,
.el-collapse-transition-leave-active {
  transition: all 0.3s ease;
}
.el-collapse-transition-enter,
.el-collapse-transition-leave-to {
  opacity: 0;
  transform: translateY(-10px);
}
</style>
src/views/system/user/GyDriverEdit.vue
New file
@@ -0,0 +1,734 @@
<template>
  <div class="gy-driver-edit">
    <div class="operation-buttons">
      <el-button
        type="primary"
        icon="el-icon-check"
        @click="handleSave"
        :disabled="saveDisabled"
        id="set_SaveBill"
        >保存</el-button
      >
      <el-button
        type="primary"
        icon="el-icon-check"
        @click="handleAudit"
        :disabled="!canAudit"
        id="set_CheckBill"
        >审核</el-button
      >
      <el-button
        type="primary"
        icon="el-icon-close"
        @click="handleCancel"
        id="Cancel"
        >退出</el-button
      >
    </div>
    <el-form
      ref="formRef"
      :model="formData"
      :rules="formRules"
      label-width="120px"
      class="edit-form"
    >
      <el-tabs v-model="activeTab" type="card">
        <el-tab-pane label="基本信息" name="basic">
          <div class="form-row">
            <el-form-item label="驾驶员代码" prop="HNumber">
              <el-input
                v-model="formData.HNumber"
                placeholder="请输入驾驶员代码"
                clearable
                :disabled="isViewMode"
              />
              <el-input
                type="hidden"
                v-model="formData.HCREATEORGID"
                style="display: none"
              />
            </el-form-item>
            <el-form-item label="驾驶员名称" prop="HName">
              <el-input
                v-model="formData.HName"
                placeholder="请输入驾驶员名称"
                clearable
                :disabled="isViewMode"
              />
            </el-form-item>
            <el-form-item label="助记码">
              <el-input
                v-model="formData.HHelpCode"
                placeholder="请输入助记码"
                clearable
                :disabled="isViewMode"
              />
            </el-form-item>
            <el-form-item label="所属公司" prop="HDeptID">
              <div class="dept-select">
                <el-input
                  v-model="formData.HDeptName"
                  placeholder="请选择所属公司"
                  readonly
                  clearable
                  :disabled="isViewMode"
                />
                <el-input
                  type="hidden"
                  v-model="formData.HDeptID"
                  style="display: none"
                />
                <el-button
                  type="primary"
                  icon="el-icon-search"
                  @click="openDeptDialog"
                  :disabled="isViewMode"
                  style="margin-left: 10px"
                >
                </el-button>
              </div>
            </el-form-item>
          </div>
          <div class="form-row">
            <el-form-item label="禁用标记">
              <el-checkbox
                v-model="formData.checkboxHStopflag"
                :true-label="1"
                :false-label="0"
                :disabled="!canEditStopFlag"
                @change="handleStopFlagChange"
              >
                是否禁用
              </el-checkbox>
              <el-input
                type="hidden"
                v-model="formData.HStopflag"
                style="display: none"
              />
            </el-form-item>
          </div>
          <div class="form-row">
            <el-form-item label="备注">
              <el-input
                v-model="formData.HRemark"
                placeholder="请输入备注"
                type="textarea"
                :rows="3"
                style="width: 75%"
                :disabled="isViewMode"
              />
            </el-form-item>
          </div>
          <div class="form-row">
            <el-form-item label="组织" prop="Organization">
              <el-select
                v-model="formData.Organization"
                placeholder="请选择组织"
                style="width: 717px"
                :disabled="isViewMode || orgDisabled"
              >
                <el-option
                  v-for="org in organizationList"
                  :key="org.ID"
                  :label="org.Name"
                  :value="org.ID"
                  style="color: blue"
                />
              </el-select>
            </el-form-item>
          </div>
        </el-tab-pane>
        <el-tab-pane label="其他信息" name="other">
          <div class="form-row">
            <el-form-item label="身份证号码">
              <el-input
                v-model="formData.identityID"
                placeholder="请输入身份证号码"
                clearable
                :disabled="isViewMode"
                style="width: 150px; background-color: #f5f7fa"
              />
            </el-form-item>
            <el-form-item label="手机号码">
              <el-input
                v-model="formData.Telephone"
                placeholder="请输入手机号码"
                clearable
                :disabled="isViewMode"
              />
            </el-form-item>
            <el-form-item label="驾照类型">
              <el-select
                v-model="formData.LicenseType"
                placeholder="请选择驾照类型"
                :disabled="isViewMode"
              >
                <el-option label="A1" value="A1" />
                <el-option label="A2" value="A2" />
                <el-option label="A3" value="A3" />
                <el-option label="B1" value="B1" />
                <el-option label="B2" value="B2" />
              </el-select>
            </el-form-item>
            <el-form-item label="司机类型">
              <el-select
                v-model="formData.DriverType"
                placeholder="请选择司机类型"
                :disabled="isViewMode"
              >
                <el-option label="固定" value="固定" />
                <el-option label="临时" value="临时" />
              </el-select>
            </el-form-item>
          </div>
        </el-tab-pane>
        <el-tab-pane label="制单信息" name="record">
          <div class="form-row">
            <el-form-item label="制单人">
              <el-input
                v-model="formData.HMakeEmp"
                readonly
                style="width: 200px; background-color: #f5f7fa"
              />
            </el-form-item>
            <el-form-item label="审核人">
              <el-input
                v-model="formData.HCheckEmp"
                readonly
                style="width: 200px; background-color: #f5f7fa"
              />
            </el-form-item>
            <el-form-item label="禁用人">
              <el-input
                v-model="formData.HStopEmp"
                readonly
                style="width: 200px; background-color: #f5f7fa"
              />
            </el-form-item>
          </div>
          <div class="form-row">
            <el-form-item label="制单日期">
              <el-input
                v-model="formData.HMakeDate"
                readonly
                style="width: 200px; background-color: #f5f7fa"
              />
            </el-form-item>
            <el-form-item label="审核日期">
              <el-input
                v-model="formData.HCheckDate"
                readonly
                style="width: 200px; background-color: #f5f7fa"
              />
            </el-form-item>
            <el-form-item label="禁用日期">
              <el-input
                v-model="formData.HStopDate"
                readonly
                style="width: 200px; background-color: #f5f7fa"
              />
            </el-form-item>
          </div>
        </el-tab-pane>
      </el-tabs>
      <el-input type="hidden" v-model="formData.HItemID" />
    </el-form>
    <!-- 部门选择弹窗 -->
    <el-dialog
      title="dialogTitle"
      :visible.sync="openData"
      width="90%"
      top="5vh"
      append-to-body
    >
    <Dept @deptEmitDb="dbEmitData" @deptEmit="emitData" v-if="deptShow" />
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="deptClickSub">确 定</el-button>
        <el-button @click="closeDeptDialog">取 消</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import axios from "axios";
import Dept from "@/views/component/dept";
export default {
  name: "GyDriverEdit",
  components: { Dept},
  props: {
    OperationType: {
      type: Number,
      default: 1, // 1:新增, 2:复制, 3:编辑, 4:浏览
    },
    linterid: {
      type: String,
      type: Number,
      default: "0",
    },
    HSouceBillType: {
      type: String,
      default: "",
    },
  },
  data() {
    return {
      baseURL: process.env.VUE_APP_BASE_API,
      activeTab: "basic",
      // 部门选择弹窗
      deptDialogVisible: false,
      deptDialogUrl: "",
      dialogTitle: "",
      deptShow: false,
      openData: false,
      deptform: {}, //弹窗选中数据
      // 组织列表
      organizationList: [],
      // 表单数据
      formData: {
        HItemID: "0",
        HNumber: "",
        HName: "",
        HHelpCode: "",
        HDeptName: "",
        HDeptID: "0",
        HDepNumber: "",
        identityID: "",
        Telephone: "",
        LicenseType: "A1",
        DriverType: "固定",
        HStopflag: "0",
        checkboxHStopflag: 0,
        HRemark: "",
        HUSEORGID: "",
        HCREATEORGID: "0",
        HMakeEmp: "",
        HMakeDate: "",
        HCheckEmp: "",
        HCheckDate: "",
        HStopEmp: "",
        HStopDate: "",
        Organization: "",
      },
      // 表单验证规则
      formRules: {
        HNumber: [
          { required: true, message: "请输入驾驶员代码", trigger: "blur" },
        ],
        HName: [
          { required: true, message: "请输入驾驶员名称", trigger: "blur" },
        ],
        HUSEORGID: [
          { required: true, message: "请选择组织", trigger: "change" },
        ],
        HDeptID: [
          { required: true, message: "请选择所属公司", trigger: "change" },
        ],
      },
      saveDisabled: false,
      orgDisabled: false,
      isViewMode: false,
      canEditStopFlag: true,
    };
  },
  computed: {
    canAudit() {
      return (
        this.OperationType === 3 &&
        this.formData.HItemID !== "0" &&
        !this.formData.HCheckEmp
      );
    },
    // 格式化当前日期
    currentDate() {
      const now = new Date();
      const year = now.getFullYear();
      const month = String(now.getMonth() + 1).padStart(2, "0");
      const day = String(now.getDate()).padStart(2, "0");
      return `${year}-${month}-${day}`;
    },
  },
  created() {
    this.initData();
  },
  methods: {
    async initData() {
      try {
        await this.getOrganizationList();
        await this.initByOperationType();
      } catch (error) {
        this.$modal.msgError("初始化失败");
        console.error("初始化错误:", error);
      }
    },
    emitData(row) {
        this.deptform = row; // 存储选中的部门数据
    },
    dbEmitData(deptRow){
        this.formData.HDeptName = deptRow.部门名称;
        this.formData.HDeptID = deptRow.HItemID;
        this.openData = false;
    },
    deptClickSub() {
      if (this.deptform && this.deptform.HItemID) {
      this.formData.HDeptName = this.deptform.部门名称;
      this.formData.HDeptID = this.deptform.HItemID;
      this.openData = false;
      this.deptShow = false;
    } else {
      this.$modal.msgWarning("请先选择一个部门");
    }
    },
    deptDialogVisible() {
      this.deptform = {};
      this.openData = false;
    },
    // 获取组织列表
    async getOrganizationList() {
      try {
        const res = await axios.get(`${this.baseURL}/Web/GetOrganizations`);
        if (res.data.count === 1) {
          this.organizationList = res.data.data;
          const orgId = sessionStorage.getItem("Organization");
          this.formData.HUSEORGID = sessionStorage.getItem("OrganizationID") || "";
          this.formData.Organization = orgId;
          this.formData.HCREATEORGID = sessionStorage.getItem("OrganizationID")|| "0";
        }
      } catch (error) {
        console.error("获取组织列表失败:", error);
      }
    },
    async initByOperationType() {
      const { OperationType, linterid } = this;
      this.formData.HMakeEmp = sessionStorage.getItem("HUserName") || "";
      this.formData.HMakeDate = this.currentDate;
      switch (OperationType) {
        case 1: // 新增
          this.orgDisabled = true;
          this.formData.HItemID = "0";
          break;
        case 2: // 复制
          await this.loadDriverData(linterid);
          this.formData.HItemID = "0";
          this.formData.HNumber = "";
          this.formData.HName = "";
          this.formData.HMakeEmp = sessionStorage.getItem("HUserName") || "";
          this.formData.HMakeDate = this.currentDate;
          this.formData.HCheckEmp = "";
          this.formData.HCheckDate = "";
          this.formData.HStopEmp = "";
          this.formData.HStopDate = "";
          break;
        case 3: // 编辑
          this.orgDisabled = true;
          this.formData.HItemID = linterid;
          await this.loadDriverData(linterid);
          break;
        case 4: // 浏览
          this.isViewMode = true;
          this.saveDisabled = true;
          this.canEditStopFlag = false;
          this.formData.HItemID = linterid;
          await this.loadDriverData(linterid);
          break;
        default:
          this.$modal.msgError("未知操作类型");
          break;
      }
    },
    async loadDriverData(linterid) {
      try {
        const res = await axios.get(`${this.baseURL}/Gy_Driver/cx`, {
          params: { HInterID: linterid },
        });
        console.log("驾驶员数据加载响应:", linterid,this.baseURL);
        console.log("加载驾驶员数据:", res.data.data);
        if (res.data.data[0]) {
          const data = res.data.data[0];
          console.log("加载驾驶员数据:", data);
          this.mapDataToForm(data);
        } else {
          this.$modal.msgError(res.data.msg || "加载数据失败");
        }
      } catch (error) {
        console.error("加载驾驶员数据失败:", error);
        this.$modal.msgError("加载数据失败");
      }
    },
    mapDataToForm(data) {
      const mapping = {
        HNumber: "驾驶员代码",
        HName: "驾驶员名称",
        HHelpCode: "短代码",
        HDeptName: "所属公司名称",
        HDepNumber: "所属公司代码",
        HDeptID: "所属公司ID",
        identityID: "身份证号码",
        Telephone: "手机号码",
        HStopflag: "禁用标记",
        HRemark: "备注",
        HUSEORGID: "HUSEORGID",
        LicenseType: "驾照类型",
        DriverType: "司机类型",
        HMakeEmp: "创建人",
        HMakeDate: "创建日期",
        HCheckEmp: "审核人",
        HCheckDate: "审核日期",
        HStopEmp: "禁用人",
        HStopDate: "禁用日期",
      };
      Object.entries(mapping).forEach(([formKey, dataKey]) => {
        if (data[dataKey] !== undefined) {
          if (dataKey.includes("日期")) {
            this.formData[formKey] = this.formatDate(data[dataKey]);
          } else {
            this.formData[formKey] = data[dataKey];
          }
        }
      });
      if (data.禁用标记) {
        this.formData.checkboxHStopflag = 1;
        this.formData.HStopflag = "1";
      } else {
        this.formData.checkboxHStopflag = 0;
        this.formData.HStopflag = "0";
      }
    },
    formatDate(dateStr) {
      if (!dateStr) return "";
      try {
        const date = new Date(dateStr);
        const year = date.getFullYear();
        const month = String(date.getMonth() + 1).padStart(2, "0");
        const day = String(date.getDate()).padStart(2, "0");
        return `${year}-${month}-${day}`;
      } catch (error) {
        return dateStr;
      }
    },
    async handleSave() {
      try {
        await this.$refs.formRef.validate();
        if (!this.formData.HNumber) {
          this.$modal.msgWarning("请输入驾驶员代码!");
          return;
        }
        if (!this.formData.HName) {
          this.$modal.msgWarning("请输入驾驶员名称!");
          return;
        }
        const saveData = {
          ...this.formData,
          HItemID: this.formData.HItemID,
          HStopflag: this.formData.HStopflag,
        };
        console.log("保存数据:", saveData);
        const sMainStr = JSON.stringify(saveData);
        const res = await axios.post(`${this.baseURL}/Gy_Driver/AddBill1`, {
          oMain: `${sMainStr};${sessionStorage.getItem("HUserName")};${
            sessionStorage.getItem("OrganizationID") || 100038
          }`,
        });
        if (res.data.count === 1) {
          this.$modal.msgSuccess("保存成功");
          this.saveDisabled = true;
          if (this.OperationType === 1 || this.OperationType === 2) {
            this.isViewMode = true;
          }
        } else {
          this.$modal.msgError(res.data.Message || "保存失败");
        }
      } catch (error) {
        if (error.name !== "Error") {
          this.$modal.msgError("保存失败");
          console.error("保存错误:", error);
        }
      }
    },
    async handleAudit() {
      try {
        await this.$modal.confirm("确认要审核吗?");
        const res = await axios.get(`${this.baseURL}/Gy_Driver/AuditGy_Driver`, {
          params: {
            HInterID: this.formData.HItemID,
            IsAudit: 0,
            CurUserName: sessionStorage.getItem("HUserName") || "",
          },
        });
        if (res.data.count === 1) {
          this.$modal.msgSuccess("审核成功");
          if (this.formData.HItemID !== "0") {
            await this.loadDriverData(this.formData.HItemID);
          }
        } else {
          this.$modal.msgError(res.data.Message || "审核失败");
        }
      } catch (error) {
        if (error !== "cancel") {
          this.$modal.msgError("审核失败");
        }
      }
    },
    handleCancel() {
      this.$emit("editCloseGy", false);
    },
    handleStopFlagChange(value) {
      this.formData.HStopflag = value ? "1" : "0";
    },
    openDeptDialog() {
        this.deptShow = false;
       this.dialogTitle = "部门列表";
        this.deptShow = true;
        this.openData = true;
    },
    clearDept() {
      this.formData.HDeptName = "";
      this.formData.HDeptID = "0";
      this.formData.HDepNumber = "";
    },
    handleMessage(event) {
      if (event.data && event.data.type === "deptSelected") {
        const dept = event.data.data;
        if (dept) {
          this.formData.HDeptName = dept.部门名称;
          this.formData.HDeptID = dept.HItemID;
          this.formData.HDepNumber = dept.部门代码;
          this.deptDialogVisible = false;
        }
      }
    },
  },
};
</script>
<style scoped>
.gy-driver-edit {
  padding: 15px;
  height: 100%;
  box-sizing: border-box;
}
.operation-buttons {
  margin-bottom: 20px;
}
.operation-buttons .el-button {
  margin-right: 10px;
}
.edit-form {
  height: calc(100% - 60px);
  overflow-y: auto;
}
.form-row {
  display: flex;
  flex-wrap: wrap;
  margin-bottom: 15px;
}
.form-row .el-form-item {
  flex: 1 1 300px;
  margin-right: 20px;
  margin-bottom: 0;
  min-width: 300px;
}
.form-row .el-form-item:last-child {
  margin-right: 0;
}
.dept-select {
  display: flex;
  align-items: center;
}
.dept-select .el-input {
  flex: 1;
}
/* 调整标签页样式 */
::v-deep .el-tabs__header {
  margin-bottom: 20px;
}
::v-deep .el-tabs__content {
  padding: 0 20px;
}
/* 响应式调整 */
@media (max-width: 1200px) {
  .form-row .el-form-item {
    flex: 1 1 100%;
    margin-right: 0;
  }
}
/* 隐藏字段样式 */
input[type="hidden"] {
  display: none;
}
</style>