spring
2 天以前 6ce0d7be73f491fcda424ac815006a82e0d871c4
src/views/basicData/product/index.vue
@@ -158,9 +158,16 @@
                placeholder="请选择单位"
                clearable
                style="width: 100%"
                :filterable="isConsumablesBranch"
                :allow-create="isConsumablesBranch"
                :default-first-option="isConsumablesBranch"
              >
                <el-option label="吨" value="吨" />
                <el-option label="公斤" value="公斤" />
                <el-option
                  v-for="u in unitSelectOptions"
                  :key="u"
                  :label="u"
                  :value="u"
                />
              </el-select>
            </el-form-item>
          </el-col>
@@ -177,7 +184,7 @@
</template>
<script setup>
import { ref } from "vue";
import { ref, computed } from "vue";
import { ElMessageBox } from "element-plus";
import {
  addOrEditProduct,
@@ -256,6 +263,28 @@
  },
});
const { form, rules, modelForm, modelRules } = toRefs(data);
/** 当前选中产品是否属于「耗材」大类下(沿父链查找 label 为「耗材」的节点) */
const isConsumablesBranch = computed(() => {
  if (!tree.value || !currentId.value) return false;
  const n = tree.value.getNode(currentId.value);
  if (!n) return false;
  let p = n.parent;
  while (p && p.data) {
    if (p.data.label === "耗材") return true;
    p = p.parent;
  }
  return false;
});
/** 单位下拉:耗材分支含件、个数且可手动新增;其他分支仅吨、公斤 */
const unitSelectOptions = computed(() => {
  if (isConsumablesBranch.value) {
    return ["吨", "公斤", "件", "个数",'桶'];
  }
  return ["吨", "公斤"];
});
// 查询产品树
const getProductTreeList = () => {
  treeLoad.value = true;