|
@@ -1,7 +1,31 @@
|
|
<template>
|
|
<template>
|
|
<div class="w-full h-full flex flex-col">
|
|
<div class="w-full h-full flex flex-col">
|
|
<div class="flex-1 overflow-y-auto">
|
|
<div class="flex-1 overflow-y-auto">
|
|
- <CustomerForm ref="formFormRef" :formJson="formJson" :formValue="formVal"></CustomerForm>
|
|
|
|
|
|
+ <FoldingPanel :title="Object.keys(formVal).length > 0 ? '修改销售订单' : '新建销售订单'">
|
|
|
|
+ <template #foldContainer>
|
|
|
|
+ <CustomerForm ref="formFormRef" :formJson="formJson" :formValue="formVal"></CustomerForm>
|
|
|
|
+ </template>
|
|
|
|
+ </FoldingPanel>
|
|
|
|
+
|
|
|
|
+ <template v-for="(item, index) in businessItemProductList">
|
|
|
|
+ <FoldingPanel :title="`相关产品(${index + 1})`">
|
|
|
|
+ <template #foldingRight>
|
|
|
|
+ <div class="flex items-center">
|
|
|
|
+ <van-button icon="plus" color="#FF8B32" size="mini" class="relatedAddButton"
|
|
|
|
+ @click="addBusinessItemProductList()">添加</van-button>
|
|
|
|
+ <van-button icon="plus" color="#075985" size="mini" class="relatedAddButton"
|
|
|
|
+ @click.stop="resetBusinessItemProductList(index)"
|
|
|
|
+ v-if="businessItemProductList.length == 1">重置</van-button>
|
|
|
|
+ <van-button icon="plus" color="#EE0A24" size="mini" class="relatedAddButton"
|
|
|
|
+ @click.stop="deleteBusinessItemProductList(index)"
|
|
|
|
+ v-if="businessItemProductList.length > 1">删除</van-button>
|
|
|
|
+ </div>
|
|
|
|
+ </template>
|
|
|
|
+ <template #foldContainer>
|
|
|
|
+ <NewAndModifiedRelatedProducts :form="item" />
|
|
|
|
+ </template>
|
|
|
|
+ </FoldingPanel>
|
|
|
|
+ </template>
|
|
</div>
|
|
</div>
|
|
<div class="mar-20px ">
|
|
<div class="mar-20px ">
|
|
<van-button type="primary" @click="onSubmit" class="w-full">
|
|
<van-button type="primary" @click="onSubmit" class="w-full">
|
|
@@ -14,8 +38,16 @@
|
|
<script setup>
|
|
<script setup>
|
|
import { ref, onActivated } from 'vue';
|
|
import { ref, onActivated } from 'vue';
|
|
import { useLifecycle } from '@hooks/useCommon.js';
|
|
import { useLifecycle } from '@hooks/useCommon.js';
|
|
|
|
+import { SELL_AND_OBTAIN_RELATED_PRODUCTS, ORDER_ADDITION_EDITING } from "@hooks/useApi"
|
|
|
|
+import { defaultRelatedProductDataFields } from "@utility/defaultData"
|
|
|
|
+import dayjs from 'dayjs';
|
|
|
|
+import requests from "@common/requests";
|
|
|
|
+import useToast from "@hooks/useToast"
|
|
|
|
+import FoldingPanel from '@components/common/foldingPanel.vue';
|
|
import CustomerForm from '@components/common/formForm/formView.vue'
|
|
import CustomerForm from '@components/common/formForm/formView.vue'
|
|
|
|
+import NewAndModifiedRelatedProducts from '@pages/pageComponents/order/newAndModifiedRelatedProducts.vue'
|
|
|
|
|
|
|
|
+const { toastText, toastSuccess, toastFail, toastLoading } = useToast()
|
|
const props = defineProps({
|
|
const props = defineProps({
|
|
formJson: { required: true },
|
|
formJson: { required: true },
|
|
formValue: { required: true },
|
|
formValue: { required: true },
|
|
@@ -23,24 +55,102 @@ const props = defineProps({
|
|
|
|
|
|
const formFormRef = ref(null)
|
|
const formFormRef = ref(null)
|
|
const formVal = ref({})
|
|
const formVal = ref({})
|
|
-
|
|
|
|
|
|
+const businessItemProductList = ref([{ ...defaultRelatedProductDataFields }])
|
|
function onSubmit() {
|
|
function onSubmit() {
|
|
formFormRef.value.getJsonData().then((res) => {
|
|
formFormRef.value.getJsonData().then((res) => {
|
|
- console.log('表单验证成功', res, JSON.stringify(res));
|
|
|
|
|
|
+ const flagVal = judgmentaAmounteEqual(res.data, businessItemProductList.value)
|
|
|
|
+ if (flagVal || !res.data) {
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ let newList = businessItemProductList.value.filter(item => item.productId)
|
|
|
|
+ for (let i in newList) {
|
|
|
|
+ newList[i].sealPrice = newList[i].sellingPrice
|
|
|
|
+ newList[i].discount = newList[i].discount
|
|
|
|
+ newList[i].num = newList[i].quantity
|
|
|
|
+ }
|
|
|
|
+ const formVal = {
|
|
|
|
+ ...props.formValue,
|
|
|
|
+ ...res.data,
|
|
|
|
+ orderProductDetailString: JSON.stringify(newList),
|
|
|
|
+ }
|
|
|
|
+ toastLoading('保存中', 0)
|
|
|
|
+ requests.post(ORDER_ADDITION_EDITING, { ...formVal }).then(() => {
|
|
|
|
+ toastSuccess('保存成功')
|
|
|
|
+ setTimeout(() => {
|
|
|
|
+ history.back();
|
|
|
|
+ }, 2000)
|
|
|
|
+ }).catch((err) => {
|
|
|
|
+ toastFail('保存失败:' + err.msg)
|
|
|
|
+ })
|
|
|
|
+ })
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+function judgmentaAmounteEqual(mob, arr) {
|
|
|
|
+ if (!arr || arr.length <= 0) {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ let flag = false;
|
|
|
|
+ const { price = 0, receivedPayment = 0, } = mob
|
|
|
|
+ if (+price < +receivedPayment) {
|
|
|
|
+ toastText('已回款金额不能大于订单金额')
|
|
|
|
+ flag = true
|
|
|
|
+ }
|
|
|
|
+ return flag
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+function addBusinessItemProductList() {
|
|
|
|
+ businessItemProductList.value.push({ ...defaultRelatedProductDataFields })
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+function resetBusinessItemProductList(index) {
|
|
|
|
+ businessItemProductList.value.splice(index, 1, { ...defaultRelatedProductDataFields })
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+function deleteBusinessItemProductList(index) {
|
|
|
|
+ businessItemProductList.value.splice(index, 1)
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+function getBusinessOpportunityDetails(row) {
|
|
|
|
+ const { id } = row
|
|
|
|
+ if (!id) {
|
|
|
|
+ businessItemProductList.value = [{ ...defaultRelatedProductDataFields }]
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ requests.post(SELL_AND_OBTAIN_RELATED_PRODUCTS, { id }).then(({ data }) => {
|
|
|
|
+ if ((data || []).length === 0) {
|
|
|
|
+ businessItemProductList.value = [{ ...defaultRelatedProductDataFields }]
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ const list = data.map((item) => {
|
|
|
|
+ const { id, productName, productCode, unit, unitName, typeName, type, price, inventory, orderProductDetail } = item
|
|
|
|
+ return {
|
|
|
|
+ id, productId: id, productName, productCode, unit, unitName, typeName, type, price, inventory,
|
|
|
|
+ productType: typeName,
|
|
|
|
+ quantity: +orderProductDetail?.num,
|
|
|
|
+ discount: +orderProductDetail?.discount,
|
|
|
|
+ sellingPrice: +orderProductDetail?.sealPrice,
|
|
|
|
+ totalPrice: +orderProductDetail?.totalPrice
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ businessItemProductList.value = list
|
|
})
|
|
})
|
|
|
|
+ console.log(row, '<===== 相关数据')
|
|
}
|
|
}
|
|
|
|
|
|
useLifecycle({
|
|
useLifecycle({
|
|
load: () => {
|
|
load: () => {
|
|
formVal.value = props.formValue
|
|
formVal.value = props.formValue
|
|
|
|
+ getBusinessOpportunityDetails(formVal.value)
|
|
},
|
|
},
|
|
init: () => {
|
|
init: () => {
|
|
formVal.value = props.formValue
|
|
formVal.value = props.formValue
|
|
|
|
+ getBusinessOpportunityDetails(formVal.value)
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
|
|
onActivated(() => {
|
|
onActivated(() => {
|
|
-
|
|
|
|
|
|
+
|
|
})
|
|
})
|
|
</script>
|
|
</script>
|
|
|
|
|