订单表单页,明细模块的订阅事件

 销售单价的订阅事件

<script setup>
const [listData, index, headerInfo, emits, props, BigNumber, form, callback] = arguments

if (callback.triggerAllEvevt) {
  // 如果是执行的全量订阅事件, 一行只需执行一个单元格的订阅事件就行,当前单元格的订阅事件不执行
  return
}
if (listData.length === 0) {
  emits('dataValChangeEffectForm', [
    { instanceCode: 'C_FID_yjjrmizgyl', value: 0 },
    { instanceCode: 'C_FID_ztaiyxmp2n', value: 0 },
    { instanceCode: 'C_FID_ev1di6fflq', value: 0 },
    { instanceCode: 'C_FID_t3zs56rxeh', value: 0 }
  ])
  return
}

function getInsCode(apiName) {
  return props.tableColumns.find((v) => v.apiName === apiName)?.instanceCode
}

// 数量
let num = getInsCode('c_amount')
let numKey = listData[index][num]?.key || 0
// 指导价格(单价,价目表价格,原价)
let guidePrice = getInsCode('c_guiding_price')
let guidePriceKey = listData[index][guidePrice]?.key || 0
// 销售单价
let salesUnitPrice = getInsCode('c_selling_price')
let salesUnitPriceKey = listData[index][salesUnitPrice]?.key || 0

// 销售总价
let totalPrice = getInsCode('c_total_prices')
let totalPriceKey = listData[index][totalPrice]?.key || 0
// 增值税税率
let taxRate = getInsCode('c_value_added_tax_rate')
let taxRateKey = listData[index][taxRate]?.key || 0
// 增值税税额
let tax = getInsCode('c_value_added_tax')
let taxKey = listData[index][tax]?.key || 0
// 折扣额
let discountAmount = getInsCode('c_discount')
let discountAmountKey = listData[index][discountAmount]?.key || 0
// 折扣率
let discountRate = getInsCode('c_discount_rate')
// 原价合计
let originalCost = getInsCode('c_original_cost')
let originalCostKey = listData[index][originalCost]?.key || 0

// 当前行的子项集合
let theRowChildren = listData.filter((item) => item.parentId === listData[index]?.id?.key)

// if (!listData[index]?.parentId && theRowChildren.length) {
//   // 当前为父产品 且 有子项(排除独立售卖产品)
//   listData[index][guidePrice] = {key: null, value: null} // 清空单价
//   listData[index][salesUnitPrice] = {key: null, value: null} // 清空销售单价
//   listData[index][product_cost_unit_price] = {key: null, value: null} // 清空成本单价(含税)
//   return emits('emitEditTableData', callback.intoTree(listData, 'id.key'))
// }

// 销售总价 = 数量*销售单价
let _total1 = new BigNumber(numKey || 0).times(salesUnitPriceKey).toFixed(2)
listData[index][totalPrice] = { ...listData[index][totalPrice], key: _total1, value: _total1 }

// 原价合计 = 指导价格*数量
let _total2 = new BigNumber(numKey).times(guidePriceKey).toFixed(2)
listData[index][originalCost] = { ...listData[index][originalCost], key: _total2, value: _total2 }

// 折扣额 = (指导价格-销售单价)*数量
let _total3 = new BigNumber(_total2).minus(_total1).toFixed(2)
listData[index][discountAmount] = {
  ...listData[index][discountAmount],
  key: _total3,
  value: _total3
}

/**
 * 折扣率 = 销售单价除以原价单价(指导价格)
 */
let _total5 = guidePriceKey ? new BigNumber(salesUnitPriceKey).div(guidePriceKey).times(100).toFixed(2) : null
listData[index][discountRate] = {
  ...listData[index][discountRate],
  key: _total5,
  value: _total5
}

// 增值税税额 = 销售总价/(1+增值税税率)* 增值税税率
let _total4 = new BigNumber(_total1)
  .div(new BigNumber(taxRateKey).div(100).plus(1))
  .times(new BigNumber(taxRateKey).div(100))
  .toFixed(2)
listData[index][tax] = { ...listData[index][tax], key: _total4, value: _total4 }

// callback?.emitEditTableData?.()
emits('emitEditTableData', callback.intoTree(listData, 'id.key'))

/* 计算去除组件产品后的所有产品的合计----------- */

// orderTotalPrice 订单金额
// originTotalPrice 原价合计
// diffTotalRate 整单折扣
// allTotalPrice 总折扣额
let orderTotalPrice = 0
let originTotalPrice = 0
let diffTotalRate = 100
let allTotalPrice = 0
// 与主产品关系是否是组件item.C_FID_hvwwzmxlqf?.key == 'C_ST_0'
listData.forEach((cur) => {
  if (cur.C_FID_hvwwzmxlqf?.key !== 'C_ST_0') {
    orderTotalPrice = new BigNumber(orderTotalPrice).plus(Number(cur[totalPrice]?.key || 0))
    originTotalPrice = new BigNumber(originTotalPrice).plus(Number(cur[originalCost]?.key || 0))
  }
})

allTotalPrice = new BigNumber(originTotalPrice).minus(orderTotalPrice).toFixed(2)
diffTotalRate = originTotalPrice != 0 ? new BigNumber(orderTotalPrice).div(originTotalPrice).times(100).toFixed(2) : null

emits('dataValChangeEffectForm', [
  { instanceCode: 'C_FID_yjjrmizgyl', value: orderTotalPrice.toFixed(2) }, // 订单金额
  { instanceCode: 'C_FID_ztaiyxmp2n', value: originTotalPrice.toFixed(2) }, // 原价合计
  { instanceCode: 'C_FID_ev1di6fflq', value: allTotalPrice }, // 总折扣额
  { instanceCode: 'C_FID_t3zs56rxeh', value: diffTotalRate } // 整单折扣
])

// emits('emitEditTableData', callback.intoTree(listData, 'id.key'))
</script>

 数量的订阅事件

<script setup>
const [listData, index, headerInfo, emits, props, BigNumber, form, callback] = arguments

function getInsCode(apiName) {
  return props.tableColumns.find((v) => v.apiName === apiName)?.instanceCode
}

// 数量
const num = getInsCode('c_num')
const numVal = listData[index][num]?.key || 0

// 销售单价
const salesUnitPrice = getInsCode('c_sales_unit_price')

// 与主产品关系
const relationship = getInsCode('c_type')

// 主子数量倍率
const quantityMultiplier = getInsCode('c_count')
const quantityMultiplierVal = listData[index][quantityMultiplier]?.key || 1

/* ---------------------------------计算主表合计---------------------------------- */

// 当前行的子项集合
let theRowChildren = []
// 当前行的组件子项集合
let theRowCompChildren = []
// 总数量
let totalCount = 0

// 与主产品关系是否是组件 item[relationship]?.key == 'C_ST_0'
listData.forEach((cur, cIndex) => {
  if (cur.parentId === listData[index]?.id?.key) {
    // 记录子项
    theRowChildren.push(cur)
    // 记录组件子项
    cur[relationship]?.key == 'C_ST_0' && theRowCompChildren.push({ ...cur, originIndex: cIndex })
  }
})

/*----------------------------------计算数量相关-----------------------------------*/

if (!callback.triggerAllEvevt) {
  // 如果不是执行的全量订阅事件(只是修改了数量) 才需要进行数量计算
  if (!listData[index]?.parentId && theRowCompChildren.length) {
    // 主产品 且 有组件子项(排除独立售卖产品)
    theRowCompChildren.forEach((item) => {
      const newNum = new BigNumber(numVal || 1).times(item[quantityMultiplier]?.key).toNumber()
      listData[item.originIndex][num] = { key: newNum, value: newNum }
      callback?.dataValueChangeTrigger?.(num, item.originIndex)
    })
  }
}

callback?.dataValueChangeTrigger?.(salesUnitPrice, index)
</script>

 

posted @ 2025-08-11 15:38  wjs0509  阅读(12)  评论(0)    收藏  举报