|
@@ -1,59 +1,129 @@
|
|
|
<script setup lang="ts">
|
|
|
-import { FormRules } from "element-plus";
|
|
|
-import { reactive } from "vue";
|
|
|
+import { ElForm } from "element-plus";
|
|
|
+import { computed, reactive, ref } from "vue";
|
|
|
+import { cost_rules } from "./commodityCost/config/configs";
|
|
|
+import RemoteSelect from "/@/components/RemoteSelect";
|
|
|
+import { useResponseHandle } from "/@/hooks";
|
|
|
+import { useRoute, useRouter } from "vue-router";
|
|
|
|
|
|
-defineProps<{
|
|
|
+import BasicDescriptions, {
|
|
|
+ type DescriptionColumn
|
|
|
+} from "/@/components/BasicDescriptions";
|
|
|
+
|
|
|
+import { httpCatlist, httpAdd } from "/@/api/InvoiceSaleSettings/commodityCost";
|
|
|
+
|
|
|
+const props = defineProps<{
|
|
|
title: string;
|
|
|
- detail: Record<string, string>;
|
|
|
- columns: Array<Record<string, string>>;
|
|
|
+ detail: any;
|
|
|
+ columns: Array<DescriptionColumn>;
|
|
|
+ backRoute: string;
|
|
|
}>();
|
|
|
|
|
|
-const rules: FormRules = {
|
|
|
- cost: [{ required: true, trigger: "change", message: "请选择类目" }],
|
|
|
- name: [{ required: true, trigger: "change", message: "请选择商品名称" }],
|
|
|
- fixed: [{ required: true, trigger: "change", message: "请选择税率" }]
|
|
|
-};
|
|
|
+const formRef = ref<InstanceType<typeof ElForm>>(null);
|
|
|
+const responseHandle = useResponseHandle();
|
|
|
+const { push } = useRouter();
|
|
|
+const { query } = useRoute();
|
|
|
+
|
|
|
+const spuCode = computed(() => query.id as string);
|
|
|
+const taxs = ref<Array<string>>([]);
|
|
|
|
|
|
const formData = reactive({
|
|
|
- cost: "",
|
|
|
- fixed: "",
|
|
|
- name: ""
|
|
|
+ cat_code: "",
|
|
|
+ cat_name: "",
|
|
|
+ inv_good_name: "",
|
|
|
+ tax: ""
|
|
|
});
|
|
|
+
|
|
|
+function handleSave() {
|
|
|
+ formRef.value.validate(async isVaild => {
|
|
|
+ if (!isVaild) return;
|
|
|
+
|
|
|
+ const { code, message } = await httpAdd({
|
|
|
+ spuCode: spuCode.value,
|
|
|
+ ...formData
|
|
|
+ });
|
|
|
+
|
|
|
+ responseHandle({
|
|
|
+ code,
|
|
|
+ message,
|
|
|
+ handler: () => push(props.backRoute)
|
|
|
+ });
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
+function handleSelectCategory(category) {
|
|
|
+ if (!category) {
|
|
|
+ formData.tax = "";
|
|
|
+ formData.cat_name = "";
|
|
|
+ return (taxs.value = []);
|
|
|
+ }
|
|
|
+
|
|
|
+ const { tax, cat_name } = category;
|
|
|
+ taxs.value = tax;
|
|
|
+ formData.tax = tax[0];
|
|
|
+ formData.cat_name = cat_name;
|
|
|
+}
|
|
|
</script>
|
|
|
|
|
|
<template>
|
|
|
<div class="settings__content" bg-white>
|
|
|
<h1 mb-2 font-bold>{{ title }}</h1>
|
|
|
- <el-descriptions :column="3" size="small" border mb-5>
|
|
|
- <el-descriptions-item
|
|
|
- label="demo"
|
|
|
- v-for="(item, index) in columns"
|
|
|
- :key="index"
|
|
|
- >{{ detail[item.field] }}</el-descriptions-item
|
|
|
- >
|
|
|
- </el-descriptions>
|
|
|
|
|
|
- <div w-500px m-auto mt-2>
|
|
|
+ <BasicDescriptions
|
|
|
+ v-if="detail"
|
|
|
+ :data="detail"
|
|
|
+ :columns="columns"
|
|
|
+ :col-number="2"
|
|
|
+ />
|
|
|
+
|
|
|
+ <div v-else v-loading="true" h-100px>详情加载中...</div>
|
|
|
+
|
|
|
+ <div w-500px m-auto mt-5>
|
|
|
<el-form
|
|
|
label-width="120px"
|
|
|
label-position="left"
|
|
|
- :rules="rules"
|
|
|
- :mode="formData"
|
|
|
+ ref="formRef"
|
|
|
+ :rules="cost_rules"
|
|
|
+ :model="formData"
|
|
|
>
|
|
|
- <el-form-item label="商品类目设置" prop="cost">
|
|
|
- <!-- 远程搜索 -->
|
|
|
- <el-input placeholder="选择类目设置" />
|
|
|
+ <el-form-item label="商品类目设置" prop="cat_code">
|
|
|
+ <RemoteSelect
|
|
|
+ w-100
|
|
|
+ is-root
|
|
|
+ :api="httpCatlist"
|
|
|
+ v-model="formData.cat_code"
|
|
|
+ placeholder="请选择商品类目"
|
|
|
+ response-label-prop="cat_name"
|
|
|
+ response-val-prop="cat_code"
|
|
|
+ request-prop="cat_name"
|
|
|
+ @item-change="handleSelectCategory"
|
|
|
+ />
|
|
|
</el-form-item>
|
|
|
- <el-form-item label="商品名称" prop="name">
|
|
|
- <el-input placeholder="请输入商品名称" />
|
|
|
+ <el-form-item label="商品名称" prop="inv_good_name">
|
|
|
+ <el-input
|
|
|
+ v-model="formData.inv_good_name"
|
|
|
+ placeholder="请输入商品名称"
|
|
|
+ />
|
|
|
</el-form-item>
|
|
|
- <el-form-item label="税率" prop="fixed">
|
|
|
- <el-input disabled placeholder="请输入税率" />
|
|
|
+ <el-form-item label="税率" prop="tax">
|
|
|
+ <el-select
|
|
|
+ w-390px
|
|
|
+ v-model="formData.tax"
|
|
|
+ :disabled="taxs.length === 0"
|
|
|
+ placeholder="请输入税率"
|
|
|
+ >
|
|
|
+ <el-option
|
|
|
+ v-for="(t, index) in taxs"
|
|
|
+ :key="index"
|
|
|
+ :label="t"
|
|
|
+ :value="t"
|
|
|
+ />
|
|
|
+ </el-select>
|
|
|
</el-form-item>
|
|
|
</el-form>
|
|
|
|
|
|
<div flex justify-center>
|
|
|
- <el-button type="primary">保存</el-button>
|
|
|
+ <el-button type="primary" @click="handleSave">保存</el-button>
|
|
|
</div>
|
|
|
</div>
|
|
|
</div>
|