Browse Source

feat: 编辑订单回显以及提交逻辑优化

cuiyalong 3 tháng trước cách đây
mục cha
commit
5a210c95ea

+ 8 - 0
src/api/modules/index.js

@@ -60,6 +60,14 @@ export function ajaxCreateOrder(data) {
   })
 }
 
+export function ajaxEditOrder(data) {
+  return request({
+    url: '/jyOrderManager/order/update',
+    method: 'post',
+    data,
+  })
+}
+
 export function getWorkDay(data) {
   return request({
     url: '/jyOrderManager/order/getWorkDay',

+ 4 - 1
src/store/order.js

@@ -4,6 +4,7 @@ import {
   ajaxGetSelectOptions,
   ajaxGetProductionPrice,
   ajaxCreateOrder,
+  ajaxEditOrder,
   ajaxGetBigMemberService,
 } from "../api/modules"
 import { findProductInThreeLevel } from '@/views/create-order/hooks'
@@ -512,8 +513,10 @@ export default {
         params.orderCode = orderCode
       }
       commit('setLoadingState', { key: 'create', value: true })
+
+      let cb = orderCode ? ajaxEditOrder : ajaxCreateOrder
       try {
-        const { error_code: code, error_msg: msg, data } = await ajaxCreateOrder(params)
+        const { error_code: code, error_msg: msg, data } = await cb(params)
         commit('setLoadingState', { key: 'create', value: false })
         if (code === 0) {
           return data

+ 3 - 0
src/utils/number/index.js

@@ -30,6 +30,9 @@ export function roundToTwoDecimals(num, x = 2) {
 
 // 折扣率计算
 export function calcDiscountRate(n, d, x = 2) {
+  if (d === 0 || Number(d) === 0) {
+    return 0
+  }
   const rateT = div(n, d) * 100
   return roundToTwoDecimals(rateT, x)
 }

+ 4 - 0
src/utils/utils.js

@@ -9,6 +9,10 @@ export function toNumber(t) {
   return isNaN(cache) ? t : cache
 }
 
+export function hasValue (t) {
+  return t !== null && t !== undefined && t !== ''
+}
+
 export const getRandomString = (len) => {
   let randomString = ''
   if (len) {

+ 7 - 1
src/views/create-order/components/create.vue

@@ -43,6 +43,11 @@ import { pageFormState } from '@/views/create-order/mixins'
 // 5. 新增价格、创建订单提交字段整理 -> /schema-form/params/index.js
 // 6. 新增恢复订单字段整理 -> /schema-form/resort/index.js
 
+const successMsgMap = {
+  1: '订单暂存成功',
+  2: '订单创建成功',
+}
+
 export default {
   name: 'CreateOrderContent',
   mixins: [pageFormState],
@@ -102,7 +107,8 @@ export default {
     async doSave(save) {
       const id = await this.createOrder({ save })
       if (id) {
-        this.$toast('订单创建成功')
+        const msg = successMsgMap[save]
+        this.$toast(msg)
       }
     },
     async submit() {

+ 9 - 3
src/views/create-order/components/edit.vue

@@ -11,6 +11,11 @@ import { pageFormState } from '@/views/create-order/mixins'
 import { ajaxGetOrderDetail } from '@/api/modules'
 import { showMessage, showNotify } from '@/views/create-order/hooks/toast'
 
+const successMsgMap = {
+  1: '订单暂存成功',
+  2: '订单修改成功',
+}
+
 export default {
   name: 'EditOrderContent',
   mixins: [pageFormState],
@@ -20,9 +25,9 @@ export default {
   props: {
     type: {
       type: String,
-      default: 'create',
+      default: 'edit',
       validator(v) {
-        return ['create', 'edit', 'read'].includes(v)
+        return ['edit', 'read'].includes(v)
       }
     },
     orderCode: {
@@ -85,7 +90,8 @@ export default {
       }
       const id = await this.createOrder({ save, orderCode: this.orderCode })
       if (id) {
-        this.$toast('订单创建成功')
+        const msg = successMsgMap[save]
+        this.$toast(msg)
       }
     },
     async submit() {

+ 1 - 4
src/views/create-order/components/product-info-submodule/ContractAmount.vue

@@ -28,10 +28,7 @@
 import NumberInput from '@/views/create-order/ui/NumberInput.vue'
 import { currencyFormat } from '@/utils/str'
 import { calcDiscountRate } from '@/utils/number'
-
-function hasValue (t) {
-  return t !== null && t !== undefined && t !== ''
-}
+import { hasValue } from '@/utils/utils'
 
 export default {
   name: 'ContractAmount',

+ 1 - 1
src/views/create-order/components/product-info-submodule/CountNumber.vue

@@ -23,7 +23,7 @@ export default {
   },
   props: {
     value: {
-      type: String,
+      type: [String, Number],
       default: '',
     },
     disabled: {

+ 2 - 0
src/views/create-order/components/product-info-submodule/ValidityDateTime.vue

@@ -85,6 +85,8 @@ export default {
       this.paybackOpenServer = !!paybackOpenServer
       if (start) {
         this.datetimeStart = start
+      }
+      if (end) {
         this.datetimeEnd = end
       }
     },

+ 8 - 1
src/views/create-order/components/schema-form/params.js

@@ -143,13 +143,20 @@ export function createOrderParams(payload = {}) {
   let productArr = []
   if (Array.isArray(productInfoList) && productInfoList.length > 0) {
     productArr = productInfoList.map(product => {
-      const productType = product.productCardInfo.result?.productCode
+      const productCardInfo = product.productCardInfo
+      const productType = productCardInfo.result?.productCode
       if (productType) {
         const params = orderParams(productType).getProductArrParams({
           type: productType,
           pageForm,
           productInfo: product,
         })
+
+        // 编辑订单使用此商品明细表id对应商品,如无此id后端将做替换
+        const id = productCardInfo.id
+        if (id && params) {
+          params.id = id
+        }
         return params
       }
     })

+ 6 - 4
src/views/create-order/components/schema-form/resort/bigmember.js

@@ -29,11 +29,13 @@ export function sortBigMemberProductFrom(product) {
     Object.assign(map, sub)
 
     if (filter.comboId) {
+      // 有comboId说明是套餐,不需要回显serviceList
       map[schemaKeyMap.specification] = getCodeWithComboId(filter.comboId)
-    }
-
-    if (Array.isArray(filter.serviceIds)) {
-      map.serviceList = filter.serviceIds.map(id => Number(id))
+    } else {
+      // 无comboId或者comboId=0说明是自定义套餐,才需要回显serviceList
+      if (Array.isArray(filter.serviceIds)) {
+        map.serviceList = filter.serviceIds.map(id => Number(id))
+      }
     }
   }
 

+ 5 - 2
src/views/create-order/components/schema-form/resort/common.js

@@ -1,5 +1,6 @@
 import { productTypeMap, schemaKeyMap } from "@/views/create-order/data";
 import { div } from '@/utils/number'
+import { hasValue } from '@/utils/utils'
 import dayjs from 'dayjs'
 
 export function getFilter(product = {}) {
@@ -45,9 +46,11 @@ export function sortCommonForm(product, order) {
     map[schemaKeyMap.specification] = product.product_code
   }
 
+  const oPrice = hasValue(product.original_price) ? div(product.original_price-0, 100) : 0
+  const fPrice = hasValue(product.final_price) ? div(product.final_price-0, 100) : 0
   map.contractAmount = {
-    standardMoney: div(product.original_price, 100),
-    contractMoney: div(product.final_price, 100),
+    standardMoney: oPrice + '',
+    contractMoney: fPrice + '',
   }
 
   // 企业下

+ 1 - 1
src/views/create-order/components/schema-form/resort/index.js

@@ -132,6 +132,7 @@ export function sortOrderInfo(order = {}) {
       const config = {
         productCode,
         waitingRestoreForm: productForm,
+        id: pd.id
       }
       return new OrderProductCardItem(undefined, undefined, config)
     })
@@ -174,7 +175,6 @@ export function sortProductFormArr(type, product, order) {
     const common = sortCommonForm(product, order)
     const pForm = callback(product, order)
     Object.assign(map, common, pForm)
-    console.log(common, pForm, map)
   }
 
   return map

+ 9 - 1
src/views/create-order/components/schema-form/resort/marketing.js

@@ -1,5 +1,13 @@
+import { getFilter } from './common'
+
 export function sortMarketingProductFrom(product = {}) {
   const map = {}
-  // console.log(product)
+
+  const filter = getFilter(product)
+  if (filter) {
+    map.giftNum = filter.num || ''
+    map.ggSource = filter.source || ''
+  }
+
   return map
 }

+ 18 - 7
src/views/create-order/components/schema-form/schema-form.vue

@@ -77,6 +77,7 @@ export default {
       dataCache: {
         // 待更新列表
         waitingRefreshValueList: [],
+        forceRefreshSchema: false, // 全量更新。恢复数据使用
       },
       schema: [
         // {
@@ -227,7 +228,9 @@ export default {
       this.changeLoading(true)
       try {
         await this.getUserPowerCheck(true)
-        this.tryToRestoreForm()
+        setTimeout(() => {
+          this.tryToRestoreForm()
+        }, 200)
       } catch (error) {
         console.log(error)
       } finally {
@@ -237,7 +240,9 @@ export default {
     tryToRestoreForm() {
       const waitingRestoreForm = this.thisProductInfoListItem.productCardInfo?.waitingRestoreForm
       if (waitingRestoreForm && Object.keys(waitingRestoreForm).length > 0) {
-        this.refreshValue(waitingRestoreForm)
+        // 立即更新数据
+        this.emitInput(waitingRestoreForm)
+        this.dataCache.forceRefreshSchema = true
       }
     },
     async getUserPowerCheck(ent = false) {
@@ -317,11 +322,16 @@ export default {
     },
     // 处理并分发各个产品卡片操作的限制
     onValueChange: debounce(function(value) {
-      // 修改某些字段时候才会更新schema
-      const { needChange, changedFieldsArr } = this.needChangeSchema(value)
-      this.onChangedFields(changedFieldsArr)
-      if (!needChange) return
-      this.dynamicChangeSchema(value)
+      if (this.dataCache.forceRefreshSchema) {
+        this.dynamicChangeSchema(value)
+        console.log('强制更新规则')
+      } else {
+        // 修改某些字段时候才会更新schema
+        const { needChange, changedFieldsArr } = this.needChangeSchema(value)
+        this.onChangedFields(changedFieldsArr)
+        if (!needChange) return
+        this.dynamicChangeSchema(value)
+      }
     }, 100),
     getPriceRequest: debounce(async function getPrice(p) {
       if (this.readonly) return
@@ -728,6 +738,7 @@ export default {
           console.log('未配置更新规则')
         }
         this.checkSchemaRule(value)
+        this.dataCache.forceRefreshSchema = false
       })
     },
     commonGroupChangeSchema(value) {

+ 2 - 0
src/views/create-order/data/interface.js

@@ -57,12 +57,14 @@ export class OrderProductCardItem {
     const {
       productCode,
       waitingRestoreForm,
+      id
     } = conf
 
     this.productCardInfo = {
       info: {},
       form: {},
       waitingRestoreForm,
+      id, // 订单详情表id修改时需要此参数
       result: {
         productCode,
       },

+ 1 - 1
src/views/create-order/data/options.js

@@ -12,7 +12,7 @@ export const buySubjectOptions = [
 
 export const upgradeContentOptions = [
   {
-    label: '补充服务',
+    label: '补充权益',
     value: 1,
   },
   {