ContractProductList.vue 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <template>
  2. <el-table :data="list" :show-overflow-tooltip="true" :stripe="true">
  3. <el-table-column align="center" label="产品名称" prop="name" width="160" />
  4. <el-table-column align="center" label="产品类型" prop="categoryName" width="160" />
  5. <el-table-column align="center" label="产品单位" prop="unit">
  6. <template #default="scope">
  7. <dict-tag :type="DICT_TYPE.CRM_PRODUCT_UNIT" :value="scope.row.unit" />
  8. </template>
  9. </el-table-column>
  10. <el-table-column align="center" label="产品编码" prop="no" />
  11. <el-table-column
  12. :formatter="fenToYuanFormat"
  13. align="center"
  14. label="价格(元)"
  15. prop="price"
  16. width="100"
  17. />
  18. <el-table-column align="center" label="数量" prop="count" width="200" />
  19. <el-table-column align="center" label="折扣(%)" prop="discountPercent" width="200" />
  20. <el-table-column align="center" label="合计" prop="totalPrice" width="100">
  21. <template #default="{ row }: { row: ProductApi.ProductExpandVO }">
  22. {{ getTotalPrice(row) }}
  23. </template>
  24. </el-table-column>
  25. </el-table>
  26. </template>
  27. <script lang="ts" setup>
  28. import { DICT_TYPE } from '@/utils/dict'
  29. import { fenToYuanFormat } from '@/utils/formatter'
  30. import * as ProductApi from '@/api/crm/product'
  31. import { floatToFixed2, yuanToFen } from '@/utils'
  32. defineOptions({ name: 'ContractProductList' })
  33. const props = withDefaults(defineProps<{ modelValue: ProductApi.ProductExpandVO[] }>(), {
  34. modelValue: () => []
  35. })
  36. const list = ref<ProductApi.ProductExpandVO[]>([]) // 列表数量
  37. /** 计算 totalPrice */
  38. const getTotalPrice = computed(() => (row: ProductApi.ProductExpandVO) => {
  39. const totalPrice =
  40. (Number(row.price) / 100) * Number(row.count) * (1 - Number(row.discountPercent) / 100)
  41. row.totalPrice = isNaN(totalPrice) ? 0 : yuanToFen(totalPrice)
  42. return isNaN(totalPrice) ? 0 : totalPrice.toFixed(2)
  43. })
  44. const isSetListValue = ref(false) // 判断是否已经给 list 赋值过,用于编辑表单商品回显
  45. // 编辑时合同商品回显
  46. watch(
  47. () => props.modelValue,
  48. (val) => {
  49. if (!val || val.length === 0 || isSetListValue.value) {
  50. return
  51. }
  52. list.value = [
  53. ...props.modelValue.map((item) => {
  54. item.totalPrice = floatToFixed2(item.totalPrice) as unknown as number
  55. return item
  56. })
  57. ]
  58. isSetListValue.value = true
  59. },
  60. { immediate: true, deep: true }
  61. )
  62. </script>