Newer
Older
KaiFengPC / src / views / project / components / firstLevel.vue
@鲁yixuan 鲁yixuan on 13 Aug 4 KB updata
<template>
  <div class="firstLevel">
    <div class="top">
      <el-form ref="ruleForm" :model="form">
        <el-row :gutter="20">
          <el-col :span="6">
            <el-form-item label="分区名称:" prop="partitionName">
              <el-input v-model="form.partitionName" clearable placeholder="请输入一级分区名称" style="width: 100%"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <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-col>
        </el-row>
      </el-form>
    </div>
    <el-table :data="tableData" v-loading="loading" stripe max-height="600">
      <el-table-column type="index" label="序号" width="60" />
      <el-table-column label="一级分区名称" prop="partitionName" show-overflow-tooltip />
      <el-table-column label="分区面积(k㎡)" prop="partitionArea" />
      <el-table-column label="年径流总量控制率指标%" prop="annualRunoffTarget" show-overflow-tooltip />
      <template v-if="disabled">
        <el-table-column label="年径流总量控制率实际值%" prop="annualRunoffReal" show-overflow-tooltip />
        <el-table-column label="超目标%" prop="superTarget" show-overflow-tooltip>
          <template #default="{ row }">
            <span :class="row.superTarget ? (row.superTarget >= 0 ? 'green' : 'red') : ''">{{ row.superTarget }}</span>
          </template>
        </el-table-column>
      </template>
      <template v-else>
        <el-table-column label="修改时间" prop="updateTime" />
        <el-table-column label="操作" width="170">
          <template #default="{ row }">
            <el-button type="warning" link @click="openDialog(row, 'edit')">编辑</el-button>
          </template>
        </el-table-column>
      </template>
    </el-table>
    <el-dialog v-model="visible" :title="opts.text" :close-on-click-modal="false" width="30%" :before-close="close" class="dialog">
      <el-form ref="dialogFormRef" :model="dialogForm">
        <el-form-item label="分区名称:" prop="partitionName">
          <el-input v-model="dialogForm.partitionName" disabled />
        </el-form-item>
        <el-form-item label="分区面积:" prop="partitionArea">
          <el-input v-model.number="dialogForm.partitionArea" placeholder="请输入分区面积">
            <template #append>k㎡</template>
          </el-input>
        </el-form-item>
      </el-form>
      <template #footer>
        <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 { getControlPartitionList, controlPartitionEdit, getControlPartitionTargetList } from '@/api/project/partition';
import { optTextMap } from '@/utils/map';
import { inheritAttr } from '@/utils/v3';
const { proxy } = getCurrentInstance();
const props = defineProps({
  disabled: {
    type: Boolean,
    default: false,
  },
});
const form = reactive({
  type: 1,
  partitionName: '',
});
const tableData = ref([]);
const loading = ref(false);

const visible = ref(false);
const opts = reactive({
  text: '',
  type: '',
});

const dialogForm = reactive({
  id: '',
  partitionName: '',
  partitionArea: '',
});

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

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

const submit = () => {
  proxy.$refs.dialogFormRef.validate(async (valid, fields) => {
    if (valid) {
      const { id, partitionArea } = dialogForm;
      const res = await controlPartitionEdit({ id, partitionArea });
      if (res?.code !== 200) return;
      close();
      search();
      proxy.$modal.msgSuccess('操作成功');
    } else {
      console.log(fields);
    }
  });
};

const search = () => {
  getTableList();
};

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

const getTableList = async () => {
  loading.value = true;
  try {
    let methed = getControlPartitionList;
    if (props.disabled) methed = getControlPartitionTargetList;
    const res = await methed(form);
    loading.value = false;
    if (res?.code !== 200) return;
    tableData.value = res?.data || [];
  } catch (error) {
    loading.value = false;
  }
};

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

<style lang="scss" scoped>
@import '@/assets/styles/variables.module.scss';
.green {
  color: $green;
}
.red {
  color: $red;
}
</style>