瀏覽代碼

管网材质改成下拉选择

zengy 3 天之前
父節點
當前提交
d9a1525070
共有 2 個文件被更改,包括 68 次插入 和 13 次删除
  1. 25 4
      src/views/subSystem/pipeNetwork/assetInfo/netWorkBase/index.vue
  2. 43 9
      src/views/system/dict/data.vue

+ 25 - 4
src/views/subSystem/pipeNetwork/assetInfo/netWorkBase/index.vue

@@ -264,9 +264,9 @@
                 {{ selectedNetwork.length ?? "-" }} m /
                 {{ selectedNetwork.diameter ?? "-" }} mm
               </el-descriptions-item>
-              <el-descriptions-item label="材质">{{
-                selectedNetwork.material || "-"
-              }}</el-descriptions-item>
+              <el-descriptions-item label="材质">
+                {{ getDictLabel(network_material, selectedNetwork.material) }}
+              </el-descriptions-item>
               <el-descriptions-item label="建设日期">{{
                 selectedNetwork.buildDate || "-"
               }}</el-descriptions-item>
@@ -403,7 +403,21 @@
           </el-col>
           <el-col :span="12">
             <el-form-item label="材质" prop="material">
-              <el-input v-model="form.material" placeholder="请输入材质" />
+              <el-select
+                v-model="form.material"
+                placeholder="请选择材质"
+                filterable
+                allow-create
+                default-first-option
+                style="width: 100%"
+              >
+                <el-option
+                  v-for="dict in network_material"
+                  :key="dict.value"
+                  :label="dict.label"
+                  :value="dict.value"
+                />
+              </el-select>
             </el-form-item>
           </el-col>
           <el-col :span="12">
@@ -459,6 +473,7 @@ import {
 } from "@/api/pipeNetwork/pdeviceInform";
 
 const { proxy } = getCurrentInstance();
+const { network_material } = proxy.useDict("network_material");
 
 const networkList = ref([]);
 const loading = ref(false);
@@ -487,6 +502,12 @@ function getNetworkTypeText(val) {
 function getStatusText(val) {
   return statusMap[val] || val || "-";
 }
+// 字典值转名称(兼容历史自由文本材质)
+function getDictLabel(dictData, val) {
+  if (val == null || val === "") return "-";
+  const item = (dictData || []).find((d) => String(d.value) === String(val));
+  return item ? item.label : val;
+}
 
 const summary = reactive({
   totalNetworks: 0,

+ 43 - 9
src/views/system/dict/data.vue

@@ -225,26 +225,55 @@ const { queryParams, form, rules } = toRefs(data);
 
 /** 查询字典类型详细 */
 function getTypes(dictId) {
+  const queryDictType = route.query?.dictType || '';
+  if (!dictId) {
+    setDictType(queryDictType);
+    return;
+  }
+  const fromOption = typeOptions.value.find(item => String(item.dictId) === String(dictId))?.dictType || '';
   getType(dictId).then(response => {
-    queryParams.value.dictType = response.data.dictType;
-    defaultDictType.value = response.data.dictType;
-    getList();
+    setDictType(response?.data?.dictType || fromOption || queryDictType);
+  }).catch(() => {
+    setDictType(fromOption || queryDictType);
   });
 }
 
+/** 设置当前字典类型;类型不存在时降级为空列表 */
+function setDictType(dictType) {
+  const type = dictType || undefined;
+  queryParams.value.dictType = type;
+  defaultDictType.value = type;
+  if (!type) {
+    proxy.$modal.msgWarning('字典类型不存在或已删除,暂无可展示的字典数据');
+  }
+  getList();
+}
+
 /** 查询字典类型列表 */
 function getTypeList() {
-  getDictOptionselect().then(response => {
-    typeOptions.value = response.data;
+  return getDictOptionselect().then(response => {
+    typeOptions.value = response?.data || [];
+  }).catch(() => {
+    typeOptions.value = [];
   });
 }
 
 /** 查询字典数据列表 */
 function getList() {
+  if (!queryParams.value.dictType) {
+    dataList.value = [];
+    total.value = 0;
+    loading.value = false;
+    return;
+  }
   loading.value = true;
   listData(queryParams.value).then(response => {
-    dataList.value = response.rows;
-    total.value = response.total;
+    dataList.value = response?.rows || [];
+    total.value = response?.total || 0;
+  }).catch(() => {
+    dataList.value = [];
+    total.value = 0;
+  }).finally(() => {
     loading.value = false;
   });
 }
@@ -291,6 +320,10 @@ function resetQuery() {
 
 /** 新增按钮操作 */
 function handleAdd() {
+  if (!queryParams.value.dictType) {
+    proxy.$modal.msgWarning('字典类型不存在,无法新增字典数据');
+    return;
+  }
   reset();
   open.value = true;
   title.value = "添加字典数据";
@@ -357,6 +390,7 @@ function handleExport() {
   }, `dict_data_${new Date().getTime()}.xlsx`);
 }
 
-getTypes(route.params && route.params.dictId);
-getTypeList();
+getTypeList().finally(() => {
+  getTypes(route.params && route.params.dictId);
+});
 </script>