|
@@ -1,18 +1,18 @@
|
|
|
<script setup lang="ts">
|
|
|
-import { ElForm } from "element-plus";
|
|
|
-import { computed, reactive, ref, watchEffect, nextTick, watch } from "vue";
|
|
|
-import { cost_rules, inv_tag, add_tax } from "./commodityCost/config/configs";
|
|
|
+import { computed, reactive, ref, nextTick, watch } from "vue";
|
|
|
+import { cost_rules, inv_tag } from "./commodityCost/config/configs";
|
|
|
import RemoteSelect from "/@/components/RemoteSelect";
|
|
|
import { useResponseHandle } from "/@/hooks";
|
|
|
import { useRoute, useRouter } from "vue-router";
|
|
|
+import { ElForm } from "element-plus";
|
|
|
+
|
|
|
+import { httpCatlist, httpAdd } from "/@/api/InvoiceSaleSettings/commodityCost";
|
|
|
+const remoteSelectRef = ref<InstanceType<typeof RemoteSelect>>(null);
|
|
|
|
|
|
import BasicDescriptions, {
|
|
|
type DescriptionColumn
|
|
|
} from "/@/components/BasicDescriptions";
|
|
|
|
|
|
-import { httpCatlist, httpAdd } from "/@/api/InvoiceSaleSettings/commodityCost";
|
|
|
-const remoteSelectRef = ref<InstanceType<typeof RemoteSelect>>(null);
|
|
|
-
|
|
|
const props = defineProps<{
|
|
|
title: string;
|
|
|
detail: any;
|
|
@@ -22,34 +22,88 @@ const props = defineProps<{
|
|
|
canChange?: boolean;
|
|
|
}>();
|
|
|
|
|
|
-const formRef = ref<InstanceType<typeof ElForm>>(null);
|
|
|
-const responseHandle = useResponseHandle();
|
|
|
-const inv_tag_options = ref([...inv_tag]);
|
|
|
-const { push } = useRouter();
|
|
|
-const { query } = useRoute();
|
|
|
-const rules = reactive({ ...cost_rules });
|
|
|
-
|
|
|
-const spuCode = computed(() => query.id as string);
|
|
|
-const taxs = ref<Array<string>>([]);
|
|
|
-
|
|
|
-const formData = reactive({
|
|
|
+const initalFormData = {
|
|
|
cat_code: "",
|
|
|
cat_name: "",
|
|
|
inv_good_name: "",
|
|
|
tax: "",
|
|
|
- inv_tag: "0",
|
|
|
- is_discount: "0",
|
|
|
+ inv_tag: "",
|
|
|
+ is_discount: "",
|
|
|
addTax: ""
|
|
|
+};
|
|
|
+
|
|
|
+const { push } = useRouter();
|
|
|
+const { query } = useRoute();
|
|
|
+
|
|
|
+const formRef = ref<InstanceType<typeof ElForm>>(null);
|
|
|
+const responseHandle = useResponseHandle();
|
|
|
+const taxs = ref<Array<string>>([]);
|
|
|
+const spuCode = computed(() => query.id as string);
|
|
|
+const formData = reactive({ ...initalFormData });
|
|
|
+
|
|
|
+const state = computed(() => ({
|
|
|
+ //是否包含优惠政策
|
|
|
+ isDiscount: formData.is_discount === "1",
|
|
|
+ //税率是否为0
|
|
|
+ isZeroTaxRate: formData.tax === "0%"
|
|
|
+}));
|
|
|
+
|
|
|
+//禁用字段
|
|
|
+const disabledField = computed(() => {
|
|
|
+ const { isDiscount, isZeroTaxRate } = state.value;
|
|
|
+ const isDisabledTaxField = !formData.cat_code;
|
|
|
+ return {
|
|
|
+ tax: isDisabledTaxField,
|
|
|
+ is_discount: isDisabledTaxField,
|
|
|
+ //非零税率没有优惠政策禁用
|
|
|
+ addTax: isDisabledTaxField || !isZeroTaxRate || !isDiscount,
|
|
|
+ //非零税率禁用 有优惠政策且零税率
|
|
|
+ inv_tag:
|
|
|
+ isDisabledTaxField || !isZeroTaxRate || (isDiscount && isZeroTaxRate)
|
|
|
+ };
|
|
|
});
|
|
|
|
|
|
-function handleSave() {
|
|
|
+//动态验证规则
|
|
|
+const dynamicRules = computed(() => {
|
|
|
+ const { isDiscount, isZeroTaxRate } = state.value;
|
|
|
+ return {
|
|
|
+ ...cost_rules,
|
|
|
+ //汇率标识是否必填(零税率)
|
|
|
+ inv_tag: [{ ...cost_rules.inv_tag[0], required: isZeroTaxRate }],
|
|
|
+ //增值税管理是否必填(有优惠政策且零税率)
|
|
|
+ addTax: [{ ...cost_rules.addTax[0], required: isDiscount && isZeroTaxRate }]
|
|
|
+ };
|
|
|
+});
|
|
|
+
|
|
|
+const dynamicOptions = computed(() => {
|
|
|
+ const { isDiscount, isZeroTaxRate } = state.value;
|
|
|
+ let addTax = [];
|
|
|
+ let invTag = [];
|
|
|
+
|
|
|
+ if (isDiscount && isZeroTaxRate) {
|
|
|
+ invTag = addTax = [inv_tag[0], inv_tag[1]];
|
|
|
+ }
|
|
|
+
|
|
|
+ if (isZeroTaxRate && !isDiscount) {
|
|
|
+ invTag = [inv_tag[2]];
|
|
|
+ }
|
|
|
+ return {
|
|
|
+ addTax,
|
|
|
+ invTag
|
|
|
+ };
|
|
|
+});
|
|
|
+
|
|
|
+function handleRelatedCategories() {
|
|
|
formRef.value.validate(async isVaild => {
|
|
|
if (!isVaild) return;
|
|
|
|
|
|
- const { code, message } = await httpAdd({
|
|
|
+ const params = {
|
|
|
spuCode: spuCode.value,
|
|
|
...formData
|
|
|
- });
|
|
|
+ };
|
|
|
+
|
|
|
+ console.log(params);
|
|
|
+ const { code, message } = await httpAdd(params);
|
|
|
|
|
|
responseHandle({
|
|
|
code,
|
|
@@ -67,38 +121,41 @@ function handleSelectCategory(category) {
|
|
|
}
|
|
|
|
|
|
const { tax, cat_name } = category;
|
|
|
-
|
|
|
- console.log(tax);
|
|
|
-
|
|
|
- taxs.value = tax;
|
|
|
- formData.tax = tax[0];
|
|
|
+ taxs.value = [...tax];
|
|
|
formData.cat_name = cat_name;
|
|
|
+ formData.tax = "";
|
|
|
+ formData.addTax = "";
|
|
|
+ formData.inv_tag = "";
|
|
|
+ formData.is_discount = "";
|
|
|
}
|
|
|
|
|
|
-watchEffect(() => {
|
|
|
- const { is_discount } = formData;
|
|
|
- let tags: Array<string> = [];
|
|
|
+//优惠政策改变清空增值税管理和汇率标识
|
|
|
+const handleDiscountChange = () => {
|
|
|
+ formData.addTax = "";
|
|
|
formData.inv_tag = "";
|
|
|
- //非优惠政策 -》 税率标识可选择为3 普通零税率和0非零税率
|
|
|
- if (is_discount === "0" || !is_discount) {
|
|
|
- tags = ["0", "3"];
|
|
|
- formData.addTax = "";
|
|
|
- } else {
|
|
|
- //优惠政策 => 税率标识可选择为 0/1/2
|
|
|
- tags = ["0", "1", "2"];
|
|
|
- }
|
|
|
+};
|
|
|
|
|
|
- rules.addTax[0].required = is_discount === "1";
|
|
|
- inv_tag_options.value = inv_tag.filter(i => tags.includes(i.value));
|
|
|
-});
|
|
|
+//税率改变清空增值税管理和汇率标识
|
|
|
+const handleTaxChange = () => {
|
|
|
+ formData.is_discount = "";
|
|
|
+ formData.addTax = "";
|
|
|
+ formData.inv_tag = "";
|
|
|
+};
|
|
|
+
|
|
|
+watch(
|
|
|
+ () => formData.addTax,
|
|
|
+ addTax => {
|
|
|
+ if (!addTax) return;
|
|
|
+ //零税率且有优惠政策时需要同步增值税管理和汇率标识的值
|
|
|
+ const { isZeroTaxRate, isDiscount } = state.value;
|
|
|
+ if (isZeroTaxRate && isDiscount) formData.inv_tag = formData.addTax;
|
|
|
+ }
|
|
|
+);
|
|
|
|
|
|
watch(
|
|
|
() => props.detail,
|
|
|
() => {
|
|
|
if (!props.detail) return;
|
|
|
-
|
|
|
- console.log(props.detail);
|
|
|
-
|
|
|
const {
|
|
|
good_name,
|
|
|
inv_good_name,
|
|
@@ -118,15 +175,14 @@ watch(
|
|
|
}
|
|
|
|
|
|
nextTick(() => {
|
|
|
- formData.inv_tag = String(inv_tag);
|
|
|
+ formData.inv_tag = String(inv_tag) !== "0" ? String(inv_tag) : "";
|
|
|
formData.addTax = addTax;
|
|
|
});
|
|
|
|
|
|
- if (inv_cat_code) {
|
|
|
- remoteSelectRef.value &&
|
|
|
- (remoteSelectRef.value as any).initalData({
|
|
|
- cat_code: inv_cat_code
|
|
|
- });
|
|
|
+ if (inv_cat_code && remoteSelectRef.value) {
|
|
|
+ (remoteSelectRef.value as any).initalData({
|
|
|
+ cat_code: inv_cat_code
|
|
|
+ });
|
|
|
}
|
|
|
}
|
|
|
);
|
|
@@ -150,7 +206,7 @@ watch(
|
|
|
<el-form
|
|
|
label-position="left"
|
|
|
ref="formRef"
|
|
|
- :rules="rules"
|
|
|
+ :rules="dynamicRules"
|
|
|
:model="formData"
|
|
|
v-if="canChange"
|
|
|
>
|
|
@@ -182,38 +238,13 @@ watch(
|
|
|
</div>
|
|
|
|
|
|
<div flex gap-3>
|
|
|
- <el-form-item label="是否有优惠政策" prop="is_discount">
|
|
|
- <el-select
|
|
|
- w-150px
|
|
|
- v-model="formData.is_discount"
|
|
|
- placeholder="请选择是否包含优惠政策"
|
|
|
- >
|
|
|
- <el-option label="否" value="0" />
|
|
|
- <el-option label="是" value="1" />
|
|
|
- </el-select>
|
|
|
- </el-form-item>
|
|
|
-
|
|
|
- <el-form-item label="汇率标识" prop="inv_tag">
|
|
|
- <el-select
|
|
|
- w-180px
|
|
|
- v-model="formData.inv_tag"
|
|
|
- placeholder="请选择汇率标识"
|
|
|
- >
|
|
|
- <el-option
|
|
|
- v-for="(tag, index) in inv_tag_options"
|
|
|
- :key="index"
|
|
|
- :label="tag.label"
|
|
|
- :value="tag.value"
|
|
|
- />
|
|
|
- </el-select>
|
|
|
- </el-form-item>
|
|
|
-
|
|
|
<el-form-item label="税率" prop="tax">
|
|
|
<el-select
|
|
|
w-180px
|
|
|
v-model="formData.tax"
|
|
|
- :disabled="taxs.length === 0"
|
|
|
+ :disabled="disabledField.tax"
|
|
|
placeholder="请输入税率"
|
|
|
+ @change="handleTaxChange"
|
|
|
>
|
|
|
<el-option
|
|
|
v-for="(t, index) in taxs"
|
|
@@ -224,26 +255,57 @@ watch(
|
|
|
</el-select>
|
|
|
</el-form-item>
|
|
|
|
|
|
+ <el-form-item label="是否有优惠政策" prop="is_discount">
|
|
|
+ <el-select
|
|
|
+ :disabled="disabledField.is_discount"
|
|
|
+ w-150px
|
|
|
+ v-model="formData.is_discount"
|
|
|
+ placeholder="请选择是否包含优惠政策"
|
|
|
+ @change="handleDiscountChange"
|
|
|
+ >
|
|
|
+ <el-option label="否" value="0" />
|
|
|
+ <el-option label="是" value="1" />
|
|
|
+ </el-select>
|
|
|
+ </el-form-item>
|
|
|
+
|
|
|
<el-form-item label="增值税管理内容" prop="addTax">
|
|
|
<el-select
|
|
|
- w-200px
|
|
|
+ :disabled="disabledField.addTax"
|
|
|
+ w-230px
|
|
|
v-model="formData.addTax"
|
|
|
- :disabled="formData.is_discount === '0'"
|
|
|
placeholder="请选择增值税管理税内容"
|
|
|
>
|
|
|
<el-option
|
|
|
- v-for="(t, i) in add_tax"
|
|
|
+ v-for="(t, i) in dynamicOptions.addTax"
|
|
|
:key="i"
|
|
|
:label="t.label"
|
|
|
:value="t.value"
|
|
|
/>
|
|
|
</el-select>
|
|
|
</el-form-item>
|
|
|
+
|
|
|
+ <el-form-item label="汇率标识" prop="inv_tag">
|
|
|
+ <el-select
|
|
|
+ :disabled="disabledField.inv_tag"
|
|
|
+ w-180px
|
|
|
+ v-model="formData.inv_tag"
|
|
|
+ placeholder="请选择汇率标识"
|
|
|
+ >
|
|
|
+ <el-option
|
|
|
+ v-for="(tag, index) in dynamicOptions.invTag"
|
|
|
+ :key="index"
|
|
|
+ :label="tag.label"
|
|
|
+ :value="tag.value"
|
|
|
+ />
|
|
|
+ </el-select>
|
|
|
+ </el-form-item>
|
|
|
</div>
|
|
|
</el-form>
|
|
|
|
|
|
<div flex justify-end v-if="canChange">
|
|
|
- <el-button type="primary" @click="handleSave">保存</el-button>
|
|
|
+ <el-button type="primary" @click="handleRelatedCategories"
|
|
|
+ >保存</el-button
|
|
|
+ >
|
|
|
</div>
|
|
|
</div>
|
|
|
</div>
|