浏览代码

Merge remote-tracking branch 'origin/master'

yusm 5 月之前
父节点
当前提交
72e528a529

+ 1 - 1
fhKeeper/formulahousekeeper/customerBuler-crm-h5/src/hooks/useApi.js

@@ -36,4 +36,4 @@ export const ORDER_ADDITION_EDITING = `/order/addOrUpdate` // 订单新增编辑
 
 export const GET_BUSINESS_OPPORTUNITY_DETAILS = `/business-opportunity/getInfo` // 商机详情
 
-
+export const SELL_AND_OBTAIN_RELATED_PRODUCTS = `/order/productWithOrder` // 销售订单关联产品

+ 4 - 3
fhKeeper/formulahousekeeper/customerBuler-crm-h5/src/pages/pageComponents/business/addEditor.vue

@@ -57,11 +57,12 @@ function onSubmit() {
     if(!res.data) {
       return
     }
-    const flagVal = judgmentaAmounteEqual(res.data, businessItemProductList.value)
+    const newList = businessItemProductList.value.filter(item => item.productId)
+    const flagVal = judgmentaAmounteEqual(res.data, newList)
     if(flagVal) {
       return
     }
-    businessItemProductList.value.forEach((item) => {
+    newList.forEach((item) => {
       item.typeName = item.productType
       delete item.id
     })
@@ -69,7 +70,7 @@ function onSubmit() {
       ...props.formValue,
       ...res.data,
       expectedTransactionDate: res.data.expectedTransactionDate ? dayjs(new Date(res.data.expectedTransactionDate)).format('YYYY-MM-DD') : '',
-      businessItemProductList: businessItemProductList.value ? JSON.stringify(businessItemProductList.value) : []
+      businessItemProductList: newList ? JSON.stringify(newList) : []
     }
     toastLoading('保存中', 0)
     requests.post(NEW_BUSINESS_OPPORTUNITY_EDITING, { ...newForm }).then(() => {

+ 114 - 4
fhKeeper/formulahousekeeper/customerBuler-crm-h5/src/pages/pageComponents/order/addEditor.vue

@@ -1,7 +1,31 @@
 <template>
   <div class="w-full h-full flex flex-col">
     <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 class="mar-20px ">
       <van-button type="primary" @click="onSubmit" class="w-full">
@@ -14,8 +38,16 @@
 <script setup>
 import { ref, onActivated } from 'vue';
 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 NewAndModifiedRelatedProducts from '@pages/pageComponents/order/newAndModifiedRelatedProducts.vue'
 
+const { toastText, toastSuccess, toastFail, toastLoading } = useToast()
 const props = defineProps({
   formJson: { required: true },
   formValue: { required: true },
@@ -23,24 +55,102 @@ const props = defineProps({
 
 const formFormRef = ref(null)
 const formVal = ref({})
-
+const businessItemProductList = ref([{ ...defaultRelatedProductDataFields }])
 function onSubmit() {
   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({
   load: () => {
     formVal.value = props.formValue
+    getBusinessOpportunityDetails(formVal.value)
   },
   init: () => {
     formVal.value = props.formValue
+    getBusinessOpportunityDetails(formVal.value)
   }
 });
 
 onActivated(() => {
-  
+
 })
 </script>