Newer
Older
KaiFengPC / src / views / preassess / adaptationConfig / index.vue
@zhangdeliang zhangdeliang on 7 Nov 7 KB update
<template>
  <div class="adaptationConfig">
    <div class="top">
      <el-form ref="ruleForm" inline :model="form">
        <el-form-item label="使用状态:" prop="status">
          <el-select v-model="form.status" placeholder="使用状态">
            <el-option label="全部" value="" />
            <el-option label="启用" value="1" />
            <el-option label="停用" value="0" />
          </el-select>
        </el-form-item>
        <el-form-item label="时间:" prop="time">
          <el-date-picker
            v-model="form.time"
            type="daterange"
            range-separator="~"
            start-placeholder="开始时间"
            end-placeholder="结束时间"
            format="YYYY-MM-DD"
            value-format="YYYY-MM-DD"
          />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="Search" @click="search"> 搜索</el-button>
          <el-button icon="Refresh" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>
      <el-row class="mb8">
        <el-button type="primary" plain icon="Plus" @click="openDialog({}, 'add')">新增</el-button>
      </el-row>
    </div>
    <el-table :data="tableData" v-loading="loading" stripe :max-height="600">
      <el-table-column type="index" width="55" label="序号" />
      <el-table-column label="记录名称" prop="configName" show-overflow-tooltip width="200">
        <template #default="{ row }">
          <span style="color: #409eef">{{ row.configName }}</span>
        </template>
      </el-table-column>
      <el-table-column label="启用时间" prop="startDatetime" show-overflow-tooltip />
      <el-table-column label="停用时间" prop="endDatetime" show-overflow-tooltip />
      <el-table-column label="修改人" prop="updateNickName" show-overflow-tooltip />
      <el-table-column label="修改日期" prop="updateTime" show-overflow-tooltip />
      <el-table-column label="使用状态" prop="status" show-overflow-tooltip>
        <template #default="{ row }">
          <el-tag :type="statusMap.get(row.status).type" v-if="row.status">{{ statusMap.get(row.status).text }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="操作" show-overflow-tooltip width="300">
        <template #default="{ row }">
          <el-button type="primary" link @click="copy(row)">复制</el-button>
          <el-button type="primary" link @click="enable(row)" :disabled="row.status === '1'">启用</el-button>
          <el-button icon="View" type="primary" link @click="openDialog(row, 'view')">详情</el-button>
          <el-button type="warning" icon="Edit" link @click="openDialog(row, 'edit')">修改</el-button>
          <el-button type="danger" icon="Delete" link @click="del(row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination :total="total" v-model:page="pageNum" v-model:limit="pageSize" @pagination="getTableList" />
    <el-dialog
      v-model="visible"
      :title="`${opts.text}适应性配置`"
      :close-on-click-modal="false"
      width="70%"
      :before-close="close"
      class="dialog"
    >
      <tableDalgo v-if="visible" ref="tableDalgoRef" :id="row.id || ''" :opts="opts.type"></tableDalgo>
      <template #footer v-if="opts.type !== 'view'">
        <div class="dialog-footer">
          <el-button type="primary" @click="submit">确定</el-button>
          <el-button @click="close">取消</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script setup>
import tableDalgo from './tableDalgo.vue';
import { reactive, ref, onMounted, computed } from 'vue';
import { optTextMap, statusMap } from '@/utils/map';
import {
  getFacilitiesAdaptabilityConfigPage,
  getFacilitiesAdaptabilityConfigAddWithItem,
  facilitiesAdaptabilityConfigDel,
  facilitiesAdaptabilityConfigCopy,
  facilitiesAdaptabilityConfigEnable,
} from '@/api/preassess/adaptationConfig.js';
import { usePagination } from '@/hooks';
const { proxy } = getCurrentInstance();

const form = reactive({
  status: '',
  time: [],
});
const params = computed(() => {
  const args = JSON.parse(JSON.stringify(form));
  const { time } = args;
  delete args.time;
  return {
    ...args,
    startDatetime: time[0] || '',
    endDatetime: time[1] || '',
  };
});
const { pageNum, pageSize, tableData, total, loading, getTableList } = usePagination(getFacilitiesAdaptabilityConfigPage, params);
const visible = ref(false);
const row = ref({});
const opts = reactive({
  type: '',
  text: '',
});

const search = () => {
  pageNum.value = 1;
  getTableList();
};

const resetQuery = () => {
  proxy.$refs.ruleForm.resetFields();
  search();
};

const openDialog = (data, type) => {
  visible.value = true;
  opts.type = type;
  opts.text = optTextMap.get(type);
  row.value = data;
};

const close = () => {
  visible.value = false;
  opts.type = '';
  opts.text = '';
  row.value = {};
};

const submit = async () => {
  opts.type === 'add' ? create() : update();
};

const create = async () => {
  console.log(proxy.$refs.tableDalgoRef.tableData);
  const list = proxy.$refs.tableDalgoRef.tableData;
  const typeList = proxy.$refs.tableDalgoRef.sponge_engineering_type.map(it => it.value);
  const params = list.map(item => {
    const result = {
      facilitiesPolluteRemoveConfigItemId: item.id,
      adaptabilityConfigJson: [],
    };
    for (const key in item) {
      if (Object.hasOwnProperty.call(item, key)) {
        if (typeList.includes(key)) {
          result.adaptabilityConfigJson.push({
            key,
            value: item[key],
          });
        }
      }
    }
    result.adaptabilityConfigJson = JSON.stringify(result.adaptabilityConfigJson);
    return result;
  });
  console.log(params);
  const res = await getFacilitiesAdaptabilityConfigAddWithItem(params);
  if (res.code !== 200) return;
  proxy.$modal.msgSuccess('操作成功!');
  close();
  search();
};

const update = () => {
  close();
  proxy.$modal.msgSuccess('操作成功!');
};

const del = row => {
  proxy.$modal
    .confirm('是否确认删除?')
    .then(async () => {
      const res = await facilitiesAdaptabilityConfigDel(row.id);
      if (res?.code !== 200) return;
      proxy.$modal.msgSuccess('操作成功!');
      getTableList();
    })
    .catch(() => {});
};

const copy = row => {
  proxy.$modal
    .confirm('是否确认复制?')
    .then(async () => {
      const res = await facilitiesAdaptabilityConfigCopy({ id: row.id });
      if (res?.code !== 200) return;
      proxy.$modal.msgSuccess('操作成功!');
      getTableList();
    })
    .catch(() => {});
};

const enable = row => {
  proxy.$modal
    .confirm('是否确认启用?')
    .then(async () => {
      const res = await facilitiesAdaptabilityConfigEnable(row.id);
      if (res?.code !== 200) return;
      proxy.$modal.msgSuccess('操作成功!');
      getTableList();
    })
    .catch(() => {});
};

onMounted(() => {
  getTableList();
});
</script>

<style lang="scss" scoped>
.adaptationConfig {
  padding: 20px;
  height: 90vh;
  overflow-y: hidden;
  .top {
    margin-bottom: 15px;
  }
}

:deep(.dialog) {
  .el-dialog__body {
    padding-bottom: 20px !important;
  }
  .el-dialog__footer {
    padding-top: 0 !important;
  }
}
</style>