ContractProductList.vue 2.4 KB

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