Newer
Older
KaiFengPC / src / views / spongePerformance / waterUtilizationRate / surfaceWater / detial / waterquality.vue
@鲁yixuan 鲁yixuan on 19 Aug 9 KB updata
<template>
  <!-- 水质目标管理 -->
  <div class="publicContainer" v-if="back">
    <!-- 操作栏 -->
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="Plus" @click="addData" v-hasPermi="['system:post:add']">新增</el-button>
        <el-button type="warning" plain icon="Plus" @click="backout">返回</el-button>
      </el-col>
      <right-toolbar v-model:showSearch="showSearch" @queryTable="getDataList"></right-toolbar>
    </el-row>
    <!-- 表格 -->
    <el-table :data="tableData" v-loading="tableLoading" :max-height="600">
      <el-table-column type="index" width="55" label="序号" />
      <el-table-column label="考核水体" prop="riverName" />
      <el-table-column label="水功能区" prop="waterFunction">
        <template #default="{ row }">
          <dict-tag :options="water_function" :value="row.waterFunction" />
        </template>
      </el-table-column>
      <el-table-column label="目标水质类别" prop="targerWaterQuality">
        <template #default="{ row }">
          <dict-tag :options="water_quality_level" :value="row.targerWaterQuality" />
        </template>
      </el-table-column>

      <el-table-column label="特征污染因子" prop="polluteFactor" show-overflow-tooltip>
        <template #default="{ row }">
          <span>{{ row.polluteFactorName }}</span>
        </template>
      </el-table-column>
      <el-table-column label="修改时间" prop="updateTime" />
      <el-table-column label="修改人" prop="updateBy" />
      <el-table-column label="状态" prop="status">
        <template #default="scope">
          <span
            :style="{
              color: scope.row.status == '0' ? 'red' : 'lime',
            }"
          >
            <el-tag :type="scope.row.status == '0' ? 'error' : scope.row.status == '1' ? 'success' : ''">
              {{ scope.row.status == '0' ? '停用' : '启用' }}
            </el-tag>
          </span>
        </template>
      </el-table-column>

      <el-table-column label="操作" show-overflow-tooltip width="200">
        <template #default="{ row }">
          <el-button type="primary" link @click="checkDetail(row)">详情</el-button>
          <el-button type="primary" link @click="editData(row)">修改</el-button>
          <el-button type="danger" link @click="deleteData(row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <pagination
      v-show="total > 0"
      :total="total"
      v-model:page="queryParams.pageNum"
      v-model:limit="queryParams.pageSize"
      @pagination="getDataList"
    />
    <!-- 添加 修改 查看彈框 -->
    <el-dialog :title="dialogTitle" v-model="showDialog" width="70%" :close-on-click-modal="false">
      <el-form ref="ruleForm" :model="formData" :rules="formRules" label-width="auto" :disabled="isDisab">
        <el-row>
          <el-form-item label="考核水体:" prop="riverId" style="width: 45%">
            <el-select clearable v-model="formData.riverId" class="m-2" placeholder="请选择" size="mini" style="width: 100%">
              <el-option v-for="item in responseAA" :key="item.id" :label="item.riverName" :value="item.id" />
            </el-select>
          </el-form-item>
          <el-form-item label="水功能区:" prop="waterFunction" style="width: 45%">
            <el-select clearable v-model="formData.waterFunction" class="m-2" placeholder="请选择" size="mini" style="width: 100%">
              <el-option v-for="item in water_function" :key="item.value" :label="item.label" :value="item.value" />
            </el-select>
          </el-form-item>
          <el-form-item label="状态:" prop="status" style="width: 45%">
            <el-select clearable v-model="formData.status" class="m-2" placeholder="请选择" size="mini" style="width: 100%">
              <el-option v-for="item in modifystatus" :key="item.value" :label="item.name" :value="item.value" />
            </el-select>
          </el-form-item>
          <el-form-item label="水质目标:" prop="targerWaterQuality" style="width: 45%">
            <el-select clearable v-model="formData.targerWaterQuality" class="m-2" placeholder="请选择" size="mini" style="width: 100%">
              <el-option v-for="item in water_quality_level" :key="item.value" :label="item.label" :value="item.value" />
            </el-select>
          </el-form-item>
          <el-form-item label="特征污染因子:" prop="polluteFactor">
            <el-checkbox-group v-model="formData.polluteFactor">
              <el-checkbox v-for="item in dbs_sample_factor" :key="item.value" :label="item.value">
                {{ item.label }}
              </el-checkbox>
            </el-checkbox-group>
          </el-form-item>
        </el-row>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" @click="submitForm" v-show="!isDisab">保 存</el-button>
          <el-button @click="cancel">关闭</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
  <surfaceWater v-else />
</template>
<script setup>
import {
  riverInfoWater,
  waterQualityConfigAdd,
  waterQualityConfigDelete,
  waterQualityConfigEdit,
  waterQualityfigpaging,
} from '@/api/spongePerformance/surfaceWater';
import surfaceWater from './index';

const { proxy } = getCurrentInstance();
const { water_function, water_quality_level, dbs_sample_factor } = proxy.useDict(
  'water_function',
  'water_quality_level',
  'dbs_sample_factor'
);

const isDisab = ref(false);
const showDialog = ref(false);
const showSearch = ref(true);
const tableLoading = ref(true);
const back = ref(true);
const total = ref(0);
const dialogTitle = ref('');
const responseAA = ref([]);
const tableData = ref([]);
const modifystatus = ref([
  { value: '0', name: '停用' },
  { value: '1', name: '启用' },
]);
const AllData = reactive({
  formData: {},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
  },
  formRules: {
    riverId: [{ required: true, message: '请选择', trigger: 'blur' }],
    targerWaterQuality: [{ required: true, message: '请选择', trigger: 'blur' }],
    waterFunction: [{ required: true, message: '请选择', trigger: 'blur' }],
    status: [{ required: true, message: '请选择', trigger: 'blur' }],
    polluteFactor: [{ required: true, message: '请选择', trigger: 'blur' }],
  },
});
const { queryParams, formData, formRules } = toRefs(AllData);

/** 表单重置 */
function resetForm() {
  formData.value = {
    waterFunction: undefined,
    riverId: undefined,
    targerWaterQuality: undefined,
    polluteFactor: undefined,
    status: undefined,
  };
  proxy.resetForm('ruleForm');
}
/** 新增按钮操作 */
function addData() {
  resetForm();
  isDisab.value = false;
  showDialog.value = true;
  dialogTitle.value = '新增水质目标';
}
// 获取下拉框数据
const getSelData = async () => {
  let params = { riverType: 'water_quality' };
  riverInfoWater(params).then(response => {
    if (response.code == 200) {
      responseAA.value = response.data;
    }
  });
};
// 返回
function backout() {
  console.log(111);
  back.value = false;
}

/** 搜索列表 */
const getDataList = async () => {
  tableLoading.value = true;
  let params = {};
  const res = await waterQualityfigpaging(params);
  if (res && res.code == 200) {
    tableLoading.value = false;
    tableData.value = res.data;
    total.value = res.total;
  }
};
/** 新增弹框 修改弹框 提交按钮 */
async function submitForm() {
  proxy.$refs['ruleForm'].validate(valid => {
    if (valid) {
      formData.value.polluteFactor = formData.value.polluteFactor.join();
      console.log(formData.value.polluteFactor, '11111');

      if (formData.value.id != undefined) {
        waterQualityConfigEdit(formData.value).then(() => {
          proxy.$modal.msgSuccess('修改成功');
          showDialog.value = false;
          getDataList();
        });
      } else {
        waterQualityConfigAdd(formData.value).then(() => {
          console.log(formData.value, 'formData.value');
          proxy.$modal.msgSuccess('新增成功');
          showDialog.value = false;
          getDataList();
        });
      }
    }
  });
}
//表格修改
function editData(row) {
  dialogTitle.value = '修改水质目标';
  isDisab.value = false;
  showDialog.value = true;
  formData.value.polluteFactor = row.polluteFactor.split(',');
  formData.value.targerWaterQuality = row.targerWaterQuality;
  formData.value.riverId = row.riverId;
  formData.value.status = row.status;
  formData.value.waterFunction = row.waterFunction;
  // formData.value = { ...row };
  formData.value.id = row.id;
  console.log(row.id, '111');
}
// 表格删除
function deleteData(row) {
  proxy.$modal
    .confirm('是否确认删除?')
    .then(async () => {
      const res = await waterQualityConfigDelete(row.id);
      if (res?.code !== 200) return;
      proxy.$modal.msgSuccess('操作成功!');
      getDataList();
    })
    .catch(() => {});
}
//详情按钮
function checkDetail(row) {
  dialogTitle.value = '查看水质目标';
  isDisab.value = true;
  showDialog.value = true;
  formData.value = { ...row };
}

/** 取消按钮 */
function cancel() {
  showDialog.value = false;
  resetForm();
}
onMounted(() => {
  getDataList();
  getSelData();
});
</script>
<style scoped lang="scss"></style>