增加单位功能
This commit is contained in:
@@ -50,8 +50,15 @@
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="单位" prop="unit">
|
||||
<el-select v-model="form.unit" filterable allow-create clearable placeholder="请选择" style="width: 100%">
|
||||
<el-option v-for="i in PRODUCT_UNIT_OPTIONS" :key="i.value" :label="i.label" :value="i.value" />
|
||||
<el-select
|
||||
v-model="form.unit"
|
||||
filterable
|
||||
allow-create
|
||||
clearable
|
||||
placeholder="请选择或输入单位"
|
||||
style="width: 100%"
|
||||
>
|
||||
<el-option v-for="i in unitOptions" :key="i" :label="i" :value="i" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
@@ -65,7 +72,7 @@
|
||||
<el-button type="primary" link @click="devVisible = true">
|
||||
📁 编辑模块树({{ (form.dev_tree || []).length }} 项 · ¥{{ formatMoney(treeSellTotal(form.dev_tree, form.dev_unit_price)) }})
|
||||
</el-button>
|
||||
<div class="dev-tip">叶子模块只填「人天」,人天单价统一;父级自动汇总金额</div>
|
||||
<!-- <div class="dev-tip">叶子模块只填「人天」,人天单价统一;父级自动汇总金额</div> -->
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="8" v-if="form.line_type === 'product'">
|
||||
@@ -122,6 +129,7 @@ import { ref, reactive, watch } from "vue";
|
||||
import { ElMessage } from "element-plus";
|
||||
import { createProduct, updateProduct } from "@/api/crmProduct";
|
||||
import { getProductCategoryList } from "@/api/crmProductCategory";
|
||||
import { getUnitList } from "@/api/crmUnit";
|
||||
import { PRODUCT_STATUS_OPTIONS, PRODUCT_UNIT_OPTIONS, formatMoney } from "../../dict";
|
||||
import { treeSellTotal } from "../../contract/components/utils";
|
||||
import DevModuleTree from "../../contract/components/DevModuleTree.vue";
|
||||
@@ -137,6 +145,7 @@ const submitting = ref(false);
|
||||
const isEdit = ref(false);
|
||||
const internalId = ref(null);
|
||||
const categoryOptions = ref([]);
|
||||
const unitOptions = ref([]);
|
||||
const devVisible = ref(false);
|
||||
|
||||
const defaultForm = () => ({
|
||||
@@ -205,6 +214,7 @@ watch(
|
||||
Object.assign(form, defaultForm());
|
||||
}
|
||||
fetchCategories();
|
||||
fetchUnits();
|
||||
}
|
||||
}
|
||||
);
|
||||
@@ -219,6 +229,27 @@ async function fetchCategories() {
|
||||
}
|
||||
}
|
||||
|
||||
/** 单位下拉合并:单位设置中的启用项 + 内置默认单位 + 当前产品的历史单位值 */
|
||||
function mergeUnitOptions(names) {
|
||||
const all = (names || []).filter(Boolean);
|
||||
PRODUCT_UNIT_OPTIONS.forEach((i) => {
|
||||
if (!all.includes(i.value)) all.push(i.value);
|
||||
});
|
||||
if (form.unit && !all.includes(form.unit)) all.push(form.unit);
|
||||
return all;
|
||||
}
|
||||
|
||||
/** 加载计量单位(取自「基本设置 - 单位设置」,取启用中的单位) */
|
||||
async function fetchUnits() {
|
||||
try {
|
||||
const res = await getUnitList({ page: 1, pageSize: 200, status: 1 });
|
||||
const names = (res?.data?.list || []).map((i) => i.name);
|
||||
unitOptions.value = mergeUnitOptions(names);
|
||||
} catch (e) {
|
||||
unitOptions.value = mergeUnitOptions([]);
|
||||
}
|
||||
}
|
||||
|
||||
function handleClose() {
|
||||
emit("update:visible", false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user