报价单批量编辑

有复选框的

<template>
  <tenant-expansion-component ref="sdkComponent" code="tenant_sdk_CPT_xs1114sda" @confirm="handleModify" />
</template>
<script setup>
import { ElMessageBox } from 'element-plus'
import { ref, provide, nextTick } from 'vue'
import FormResult from 'FormResult'

const props = defineProps({
  BigNumber: {
    type: Function,
    default: () => {}
  }
})

const BigNumber = props.BigNumber

const visible = ref(false)
let infoC = {}
let callbackC = {}
const sdkComponent = ref()

const code = {
  product: 'C_FID_frv75eyvrf', // 产品
  remark: 'C_FID_kwlkawb2i7', // 备注
  num: 'C_FID_hzwomx4xhu', // 数量
  unitPrice: 'C_FID_o6vpyvwd9u', // 销售单价
  relationship: 'C_FID_hvwwzmxlqf', // 与主产品关系
  times: 'C_FID_slcq9w8eeb' // 主子产品倍率
}

const fileds = [
  { instanceCode: code.unitPrice, name: '销售单价', type: 'number' },
  { instanceCode: code.num, name: '数量', type: 'number' },
  { instanceCode: code.remark, name: '备注', type: 'input' }
]

let errorMsg = []

const init = (info, callback) => {
  infoC = info
  callbackC = callback
  errorMsg = []
  console.log('init', info, callback)
  sdkComponent.value.dynamic?.open({
    fileds: fileds
  })
}

const updateNumericField = (list, data, fieldCode, decimalPlaces = 2) => {
  const { amplitudeType, amplitudeVal, ratioVal, editType } = data
  list.forEach((item, index) => {
    if(!infoC.batchIds.includes(item.id?.key)) return
    if(item[code.relationship]?.key == 'C_ST_0') return errorMsg.push({ name: item[code.product]?.value})
    let newVal
    const currentValue = item[fieldCode]?.key || 0
    if (editType === 'fixed') {
      newVal = data.fixedVal <= 0 ? 1 : data.fixedVal
    } else if (editType === 'value') {
      newVal = new BigNumber(currentValue)
        .plus(new BigNumber(amplitudeVal).times(amplitudeType === 'add' ? 1 : -1))
        .toFixed(decimalPlaces)
    } else if (editType === 'ratio') {
      newVal = new BigNumber(currentValue)
        .times(new BigNumber(ratioVal).div(100))
        .times(amplitudeType === 'add' ? 1 : -1)
        .plus(currentValue)
        .toFixed(decimalPlaces)
    }
    // 对于数量字段,最小值为1
    if (fieldCode === code.num && newVal <= 0) {
      newVal = '1'
    }
    item[fieldCode] = { key: newVal, value: newVal }
  })

  return list
}

/**
 * data: {
      instanceCode: '',
      editType: 'fixed', // 调整方式 固定值 fixed / 按数值调整 value / 按比例调整 ratio
      amplitudeType:'add', // 调整类型 上调 add / 下调 minus
      fixedVal: '', // 固定值
      amplitudeVal: '', // 数值值
      ratioVal: '', // 比例值
    }
 */
const handleModify = (data) => {
  const { listData } = callbackC
  let list = data.flatListData(JSON.parse(JSON.stringify(listData.value)))

  if (data.instanceCode === code.unitPrice) {
    list.forEach((item) => {
      let val
      if (data.editType === 'fixed') {
        val = data.fixedVal
      } else if (data.editType === 'value') {
        val = new BigNumber(item[code.unitPrice]?.key || 0)
          .plus(new BigNumber(data.amplitudeVal).times(data.amplitudeType === 'add' ? 1 : -1))
          .toFixed(2)
      } else if (data.editType === 'ratio') {
        val = new BigNumber(item[code.unitPrice]?.key || 0)
          .times(
            new BigNumber(data.ratioVal)
              .div(100)
              .times(data.amplitudeType === 'add' ? 1 : -1)
              .plus(1)
          )
          .toFixed(2)
      }
      if(infoC.batchIds.includes(item.id?.key)) {

        item[code.unitPrice] = { ...item[code.unitPrice], key: val, value: val }
      }
    })
  } else if (data.instanceCode === code.num) {
    updateNumericField(list, data, code.num, 0)
  } else if (data.instanceCode === code.remark) {
    const val = data.fixedVal
    list.forEach((item) => {
      if(infoC.batchIds.includes(item.id?.key)) {
        
        item[code.remark] = { ...item[code.remark], key: val, value: val }
      }
    })
  }

  if (errorMsg.length) {
    const prdNames = errorMsg.map(item => `<span style="color:red;">${item.name}</span>`).join('')
    ElMessageBox.alert(`${prdNames} 为组件产品,不能单独修改数量,但会跟随主产品的数量改变而改变`, '提示', {
      confirmButtonText: '确定',
      dangerouslyUseHTMLString: true,
      type: 'warning',
    })
  }

  callbackC.emitEditTableData(callbackC.intoTree(list, 'id.key'))
  callbackC?.dataValueChangeTrigger?.(code.num)
  // 清空选中项
  callbackC.toggleSelection?.()


}

defineExpose({
  init
})
</script>
<style lang='scss' scoped>
</style>

无复选框的(针对所有数据的)

<template>
  <tenant-expansion-component ref="sdkComponent" code="tenant_sdk_CPT_xs1114sda" @confirm="handleModify" />
</template>
<script setup>
import { ElMessage } from 'element-plus'
import { ref, provide, nextTick } from 'vue'
import FormResult from 'FormResult'

const props = defineProps({
  BigNumber: {
    type: Function,
    default: () => {}
  }
})

const BigNumber = props.BigNumber

const visible = ref(false)
let infoC = {}
let callbackC = {}
const sdkComponent = ref()

const code = {
  remark: 'C_FID_kwlkawb2i7', // 备注
  num: 'C_FID_hzwomx4xhu', // 数量
  unitPrice: 'C_FID_o6vpyvwd9u', // 销售单价
  relationship: 'C_FID_hvwwzmxlqf', // 与主产品关系
}

const fileds = [
  { instanceCode: code.unitPrice, name: '销售单价', type: 'number' },
  { instanceCode: code.num, name: '数量', type: 'number' },
  { instanceCode: code.remark, name: '备注', type: 'input' }
]

const init = (info, callback) => {
  infoC = info
  callbackC = callback
  console.log('init', info, callback)
  sdkComponent.value.dynamic?.open({
    fileds: fileds
  })
}

const updateNumericField = (list, data, fieldCode, decimalPlaces = 2) => {
  const { amplitudeType, amplitudeVal, ratioVal, editType } = data
  let theParentList = []

  list.forEach((item, index) => {
    if (!item.parentId || item[code.relationship]?.key !== 'C_ST_0') {
      theParentList.push({ ...item, originIndex: index })
    }
  })

  theParentList.forEach((item) => {
    let newVal
    const currentValue = item[fieldCode]?.key || 0

    if (editType === 'fixed') {
      newVal = data.fixedVal <= 0 ? 1 : data.fixedVal
    } else if (editType === 'value') {
      newVal = new BigNumber(currentValue)
        .plus(new BigNumber(amplitudeVal).times(amplitudeType === 'add' ? 1 : -1))
        .toFixed(decimalPlaces)
    } else if (editType === 'ratio') {
      newVal = new BigNumber(currentValue)
        .times(new BigNumber(ratioVal).div(100))
        .times(amplitudeType === 'add' ? 1 : -1)
        .plus(currentValue)
        .toFixed(decimalPlaces)
    }

    // 对于数量字段,最小值为1
    if (fieldCode === code.num && newVal <= 0) {
      newVal = '1'
    }

    list[item.originIndex][fieldCode] = { key: newVal, value: newVal }
  })

  return list
}

/**
 * data: {
      instanceCode: '',
      editType: 'fixed', // 调整方式 固定值 fixed / 按数值调整 value / 按比例调整 ratio
      amplitudeType:'add', // 调整类型 上调 add / 下调 minus
      fixedVal: '', // 固定值
      amplitudeVal: '', // 数值值
      ratioVal: '', // 比例值
    }
 */
const handleModify = (data) => {
  const { listData } = callbackC
  let list = data.flatListData(JSON.parse(JSON.stringify(listData.value)))

  if (data.instanceCode === code.unitPrice) {
    list.forEach((item) => {
      let val
      if (data.editType === 'fixed') {
        val = data.fixedVal
      } else if (data.editType === 'value') {
        val = new BigNumber(item[code.unitPrice]?.key || 0)
          .plus(new BigNumber(data.amplitudeVal).times(data.amplitudeType === 'add' ? 1 : -1))
          .toFixed(2)
      } else if (data.editType === 'ratio') {
        val = new BigNumber(item[code.unitPrice]?.key || 0)
          .times(
            new BigNumber(data.ratioVal)
              .div(100)
              .times(data.amplitudeType === 'add' ? 1 : -1)
              .plus(1)
          )
          .toFixed(2)
      }

      item[code.unitPrice] = { ...item[code.unitPrice], key: val, value: val }
    })
  } else if (data.instanceCode === code.num) {
    updateNumericField(list, data, code.num, 0)
  } else if (data.instanceCode === code.remark) {
    const val = data.fixedVal
    list.forEach((item) => {
      item[code.remark] = { ...item[code.remark], key: val, value: val }
    })
  }

  callbackC.emitEditTableData(callbackC.intoTree(list, 'id.key'))
  callbackC?.dataValueChangeTrigger?.(code.num)
}

defineExpose({
  init
})
</script>
<style lang='scss' scoped>
</style>

 

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