zhanghua
2024-11-26 556a06bbd866af3ef2dde46dce3f587ec58c3ca9
src/views/projectEngineering/projectLibrary/index.vue
@@ -166,75 +166,76 @@
              <svg-icon icon-class="exportIcon" style="margin-right: 8px"/>
              导出数据
            </el-button>
            <el-button :disabled="isReserve" @click="handleImport" size="small">
            <el-button :disabled="!isReserve" @click="handleImport" size="small">
              <svg-icon icon-class="importIcon" style="margin-right: 8px"/>
              导入数据
            </el-button>
          </div>
          <div class="add-btn">
            <el-tooltip content="新增" effect="dark" placement="top">
              <el-button :disabled="isReserve" circle icon="el-icon-plus" @click="add()" size="small"/>
              <el-button :disabled="!isReserve" circle icon="el-icon-plus" @click="add()" size="small"/>
            </el-tooltip>
          </div>
          <VisibilityToolbar
            v-model:showSearch="showSearch"
            :columns="columns"
            :columns="defaultColumns"
            @queryTable="handleQuery"
            @update:sort="handleUpdateSort"
            @update:columns="handleUpdateColumns"
            @update:resetSort="handleResetSort"
          ></VisibilityToolbar>
          <!--            @update:columns="handleUpdateColumns"-->
          <!--            @update:sort="handleUpdateSort"-->
          <!--            @update:resetSort="handleResetSort"-->
        </div>
      </div>
    </el-form>
    <el-table
      :key="tableKey"
      ref="elTable"
      style="margin-top: 20px"
      v-loading="loading"
      :data="projectInfoList"
      @selection-change="handleSelectionChange"
      height="60vh"
      sortable="custom"
      :show-overflow-tooltip="true">
      <el-table-column type="selection" width="55" align="center"/>
      <!-- 动态列 -->
      <template v-for="item in columns">
        <el-table-column
          v-if="item.visible"
          :prop="item.id"
          :label="item.label"
          v-bind="item"
          :min-width="item.minWidth"
        >
          <template slot-scope="scope">
            <!-- 使用具名插槽 -->
            <template v-if="item.slotName">
              <!-- projectStatus插槽 -->
              <template v-if="item.slotName === 'projectStatus'">
                <el-text class="mx-1">{{ '自定义样式' }}</el-text>
              </template>
              <!-- projectColorCode插槽 -->
              <template v-if="item.slotName === 'projectColorCode'">
                <el-text class="mx-1 has-dot">{{ '自定义样式' }}<span class="dot" style="margin-left: 5px"></span></el-text>
              </template>
              <!-- projectType插槽 -->
              <template v-if="item.slotName === 'projectType'">
                <el-text class="mx-1">{{ '自定义样式' }}</el-text>
              </template>
              <!-- investType插槽 -->
              <template v-if="item.slotName === 'investType'">
                <el-text class="mx-1">{{ '自定义样式' }}</el-text>
              </template>
              <!-- planStartTime插槽 -->
              <template v-if="item.slotName === 'planStartTime'">
                {{ '自定义样式' }}
              </template>
      <el-table-column
        v-for="item in columns"
        :key="item.id"
        v-if="item.visible"
        :prop="item.id"
        :label="item.label"
        :min-width="item.minWidth"
      >
        <template slot-scope="scope">
          <!-- 使用具名插槽 -->
          <template v-if="item.slotName">
            <!-- projectStatus插槽 -->
            <template v-if="item.slotName === 'projectStatus'">
              <el-text class="mx-1">{{ '自定义样式' }}</el-text>
            </template>
            <!-- 默认显示 -->
            <span v-else>{{ scope.row[item.id] }}</span>
            <!-- projectColorCode插槽 -->
            <template v-if="item.slotName === 'projectColorCode'">
              <el-text class="mx-1 has-dot">{{ '自定义样式' }}<span class="dot" style="margin-left: 5px"></span></el-text>
            </template>
            <!-- projectType插槽 -->
            <template v-if="item.slotName === 'projectType'">
              <el-text class="mx-1">{{ '自定义样式' }}</el-text>
            </template>
            <!-- investType插槽 -->
            <template v-if="item.slotName === 'investType'">
              <el-text class="mx-1">{{ '自定义样式' }}</el-text>
            </template>
            <!-- planStartTime插槽 -->
            <template v-if="item.slotName === 'planStartTime'">
              {{ '自定义样式' }}
            </template>
          </template>
        </el-table-column>
      </template>
          <!-- 默认显示 -->
          <span v-else>{{ scope.row[item.id] }}</span>
        </template>
      </el-table-column>
      <!-- 操作列 -->
      <el-table-column label="操作" width="140" align="center" >
@@ -247,6 +248,7 @@
          >
          </el-button>
          <el-button
            v-if="isReserve"
            size="medium"
            type="text"
            icon="el-icon-edit"
@@ -254,6 +256,7 @@
          >
          </el-button>
          <el-button
            v-if="isReserve"
            size="medium"
            type="text"
            icon="el-icon-delete"
@@ -283,7 +286,7 @@
<script>
import {listInfo, getInfo, delInfo, addInfo, updateInfo} from "@/api/projectInfo";
import {current} from './list';
import {current, currentRest} from './list';
import FileDialog from '../component/FileDialog';
export default {
@@ -297,8 +300,11 @@
      fileDialogVisible: false,
      //是否需要新增按钮(储蓄项目需要)
      isReserve: false,
      //项目状态筛选条件
      isProjectCategory: false,
      //表头
      columns: [],
      defaultColumns: [],
      //控制更多筛选显隐
      popoverValue: false,
      // 遮罩层
@@ -318,6 +324,7 @@
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      tableKey: 0,
      open: false,
      timeRange: [],
      // 查询参数
@@ -347,21 +354,69 @@
          {required: true, message: "项目名称不能为空", trigger: "blur"}
        ],
        projectStatus: [
          {required: true, message: "项目状态  (0未开工,1已开工,2已竣工,3暂停)不能为空", trigger: "change"}
          {required: true, message: "项目状态不能为空", trigger: "change"}
        ],
      }
    };
  },
  created() {
    this.columns = current.map((item, index) => {
    const projectCategory = this.$route.query.projectCategory;
    if(!projectCategory || projectCategory === '1'){
      this.isReserve = true;
    }
    if(projectCategory){
      this.isProjectCategory = true;
    }
    const columns = current.map((item, index) => {
      item.index = index + 1;
      item.key = index;
      item.serialNumber = index + 1;
      return item;
    });
    this.columns = columns;
    this.defaultColumns = JSON.parse(JSON.stringify(columns));
    this.getList();
  },
  methods: {
    // 重置排序的方法
    handleResetSort() {
      this.defaultColumns = currentRest.map((item, index) => {
        item.index = index + 1;
        item.key = index;
        item.serialNumber = index + 1
        return item;
      });
      this.columns = currentRest.map((item, index) => {
        item.index = index + 1;
        item.key = index;
        item.serialNumber = index + 1
        return item;
      });
    },
    // 更新列的方法
    handleUpdateColumns(row) {
      // this.currentColumns = row;
      this.columns = this.columns.map(item => {
        if (item.key === row.key) {
          return row;
        }
        return item;
      });
    },
    handleUpdateSort(row) {
      console.log( this.columns, '排序前的列');
      this.columns = this.columns.map(item => {
        if (item.key === row.key) {
          return row;
        }
        return item;
      });
      this.defaultColumns = JSON.parse(JSON.stringify(this.columns)).sort((a, b) => a.index - b.index);
      this.columns.sort((a, b) => a.serialNumber - b.serialNumber);
      //强制table渲染
      this.tableKey = this.tableKey +1;
      console.log( this.columns, '排序后的列');
    },
    // 关闭文件处理弹框的方法
    fileDialogCancel() {
      this.tableLoading = true;
@@ -379,7 +434,6 @@
    /** 查询项目管理基础信息列表 */
    getList() {
      this.loading = true;
      console.log("查询")
      listInfo(this.queryParams).then(response => {
        this.projectInfoList = response.data;
        this.total = response.total;