311 lines
12 KiB
Vue
311 lines
12 KiB
Vue
<template>
|
||
<el-form
|
||
ref="formRef"
|
||
:model="formData"
|
||
:rules="formRules"
|
||
v-loading="formLoading"
|
||
label-width="0px"
|
||
:inline-message="true"
|
||
>
|
||
<el-table :data="formData" class="-mt-10px">
|
||
<el-table-column label="序号" type="index" width="80" />
|
||
<el-table-column label="产品名称" min-width="240">
|
||
<template #default="{ row, $index }">
|
||
<el-form-item :prop="`${$index}.productName`" :rules="formRules.productName" class="mb-0px!">
|
||
<el-input v-model="row.productName" placeholder="请输入产品名称" disabled />
|
||
</el-form-item>
|
||
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column label="产品类型" min-width="150">
|
||
<template #default="{ row, $index }">
|
||
<el-form-item :prop="`${$index}.category`" :rules="formRules.category" class="mb-0px!">
|
||
<el-select v-model="row.category" placeholder="请选择状态" disabled class="!w-240px">
|
||
<el-option
|
||
v-for="dict in getIntDictOptions(DICT_TYPE.CRM_PRODUCT_CATEGORY)"
|
||
:key="dict.value"
|
||
:label="dict.label"
|
||
:value="dict.value"
|
||
/>
|
||
</el-select>
|
||
</el-form-item>
|
||
</template>
|
||
</el-table-column>
|
||
|
||
<el-table-column label="产品明细" min-width="220">
|
||
<template #default="{ row, $index }">
|
||
<el-form-item :prop="`${$index}.detailType`" :rules="formRules.detailType" class="mb-0px!">
|
||
<el-select v-model="row.detailType" placeholder="请选择状态" class="!w-240px">
|
||
<el-option
|
||
v-for="dict in getIntDictOptions(DICT_TYPE.CRM_PRODUCT_DETAIL_TYPE)"
|
||
:key="dict.value"
|
||
:label="dict.label"
|
||
:value="dict.value"
|
||
/>
|
||
</el-select>
|
||
</el-form-item>
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column label="产品单位" min-width="150">
|
||
<template #default="{ row, $index }">
|
||
<el-form-item :prop="`${$index}.productUnit`" :rules="formRules.productUnit" class="mb-0px!">
|
||
<el-select v-model="row.productUnit" placeholder="请选择状态" disabled class="!w-240px">
|
||
<el-option
|
||
v-for="dict in getIntDictOptions(DICT_TYPE.CRM_PRODUCT_UNIT)"
|
||
:key="dict.value"
|
||
:label="dict.label"
|
||
:value="dict.value"
|
||
/>
|
||
</el-select>
|
||
</el-form-item>
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column label="线上价格(元)" min-width="120">
|
||
<template #default="{ row, $index }">
|
||
<el-form-item :prop="`${$index}.onlinePrice`" :rules="formRules.onlinePrice" class="mb-0px!">
|
||
<el-input v-model="row.onlinePrice" placeholder="请输入线上价格" />
|
||
</el-form-item>
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column label="线下价格(元)" min-width="120">
|
||
<template #default="{ row, $index }">
|
||
<el-form-item :prop="`${$index}.offlinePrice`" :rules="formRules.offlinePrice" class="mb-0px!">
|
||
<el-input v-model="row.offlinePrice" placeholder="请输入线下价格" />
|
||
</el-form-item>
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column label="总计价格(元)" min-width="120">
|
||
<template #default="{ row, $index }">
|
||
<el-form-item :prop="`${$index}.totalPrice`" :rules="formRules.totalPrice" class="mb-0px!">
|
||
<el-input v-model="row.totalPrice" placeholder="请输入总计价格" disabled />
|
||
</el-form-item>
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column label="产品票据" min-width="150">
|
||
<template #default="{ row, $index }">
|
||
<el-form-item :prop="`${$index}.productInvoice`" :rules="formRules.productInvoice" class="mb-0px!">
|
||
<el-select v-model="row.productInvoice" placeholder="请选择状态" clearable class="!w-240px">
|
||
<el-option
|
||
v-for="dict in getIntDictOptions(DICT_TYPE.CRM_PRODUCT_INVOICE)"
|
||
:key="dict.value"
|
||
:label="dict.label"
|
||
:value="dict.value"
|
||
/>
|
||
</el-select>
|
||
</el-form-item>
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column label="产品开具项目" min-width="220">
|
||
<template #default="{ row, $index }">
|
||
<el-form-item :prop="`${$index}.productInvoiceItem`" :rules="formRules.productInvoiceItem" class="mb-0px!">
|
||
<el-select v-model="row.productInvoiceItem" placeholder="请选择状态" clearable class="!w-240px">
|
||
<el-option
|
||
v-for="dict in getIntDictOptions(DICT_TYPE.CRM_PRODUCT_INVOICE_ITEMS)"
|
||
:key="dict.value"
|
||
:label="dict.label"
|
||
:value="dict.value"
|
||
/>
|
||
</el-select>
|
||
</el-form-item>
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column label="服务费票据" min-width="150">
|
||
<template #default="{ row, $index }">
|
||
<el-form-item :prop="`${$index}.serviceInvoice`" :rules="formRules.serviceInvoice" class="mb-0px!">
|
||
<el-select v-model="row.serviceInvoice" placeholder="请选择状态" clearable class="!w-240px">
|
||
<el-option
|
||
v-for="dict in getIntDictOptions(DICT_TYPE.CRM_SERVICE_FEE_INVOICE)"
|
||
:key="dict.value"
|
||
:label="dict.label"
|
||
:value="dict.value"
|
||
/>
|
||
</el-select>
|
||
</el-form-item>
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column label="服务开具项目" min-width="240">
|
||
<template #default="{ row, $index }">
|
||
<el-form-item :prop="`${$index}.serviceInvoiceItem`" :rules="formRules.serviceInvoiceItem" class="mb-0px!">
|
||
<el-select v-model="row.serviceInvoiceItem" placeholder="请选择状态" clearable class="!w-240px">
|
||
<el-option
|
||
v-for="dict in getIntDictOptions(DICT_TYPE.CRM_SERVICE_FEE_INVOICE_ITEMS)"
|
||
:key="dict.value"
|
||
:label="dict.label"
|
||
:value="dict.value"
|
||
/>
|
||
</el-select>
|
||
</el-form-item>
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column align="center" fixed="right" label="操作" width="60">
|
||
<template #default="{ $index }">
|
||
<el-button @click="handleDelete($index)" link>—</el-button>
|
||
</template>
|
||
</el-table-column>
|
||
</el-table>
|
||
</el-form>
|
||
<el-row justify="center" class="mt-3">
|
||
<!-- <el-button @click="handleAdd" round>+ 添加CRM 报价产品关联</el-button> -->
|
||
</el-row>
|
||
</template>
|
||
<script setup lang="ts">
|
||
import { QuotationApi } from '@/api/crm/quotation'
|
||
import { BillTemplateApi, BillTemplateVO } from '@/api/crm/billtemplate'
|
||
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
|
||
import * as BusinessApi from '@/api/crm/business'
|
||
|
||
const props = defineProps<{
|
||
quotationId: undefined, // 报价编号(主表的关联字段)
|
||
businessId: undefined,
|
||
billTemplateId: undefined,
|
||
products: undefined
|
||
}>()
|
||
const formLoading = ref(false) // 表单的加载中
|
||
const formData = ref([])
|
||
const formRules = reactive({
|
||
quotationId: [{ required: true, message: '报价编号不能为空', trigger: 'blur' }],
|
||
productId: [{ required: true, message: '产品编号不能为空', trigger: 'blur' }],
|
||
productName: [{ required: true, message: '产品名称不能为空', trigger: 'blur' }],
|
||
category: [{ required: true, message: '产品类型不能为空', trigger: 'blur' }],
|
||
detailType: [{ required: true, message: '产品明细类型不能为空', trigger: 'blur' }],
|
||
productUnit: [{ required: true, message: '产品单位不能为空', trigger: 'blur' }],
|
||
onlinePrice: [{ required: true, message: '线上价格不能为空', trigger: 'blur' }],
|
||
offlinePrice: [{ required: true, message: '线下价格不能为空', trigger: 'blur' }],
|
||
totalPrice: [{ required: true, message: '总计价格不能为空', trigger: 'blur' }],
|
||
productInvoiceItem: [{ required: true, message: '产品开具项目不能为空', trigger: 'blur' }],
|
||
serviceInvoice: [{ required: true, message: '服务费票据不能为空', trigger: 'blur' }],
|
||
serviceInvoiceItem: [{ required: true, message: '服务开具项目不能为空', trigger: 'blur' }],
|
||
productInvoice: [{ required: true, message: '产品票据不能为空', trigger: 'blur' }],
|
||
})
|
||
const formRef = ref() // 表单 Ref
|
||
|
||
/** 监听主表的关联字段的变化,加载对应的子表数据 */
|
||
watch(
|
||
() => props.businessId,
|
||
async (val) => {
|
||
// 1. 重置表单
|
||
formData.value = []
|
||
// 2. val 非空,则加载数据
|
||
if (!val) {
|
||
return;
|
||
}
|
||
try {
|
||
formLoading.value = true
|
||
console.log('%csrc/views/crm/quotation/components/QuotationProductForm.vue:214 1111', 'color: #007acc;', 2222);
|
||
// if(val.quotationId) {
|
||
// formData.value = await QuotationApi.getQuotationProductListByQuotationId(val.quotationId)
|
||
// } else if(val.businessId) {
|
||
const business = await BusinessApi.getBusiness(val);
|
||
formData.value = business.products
|
||
// }
|
||
} finally {
|
||
formLoading.value = false
|
||
}
|
||
},
|
||
// { immediate: true }
|
||
)
|
||
|
||
watch(
|
||
() => props.billTemplateId,
|
||
async (val) => {
|
||
// 2. val 非空,则加载数据
|
||
if (!val) {
|
||
return;
|
||
}
|
||
try {
|
||
formLoading.value = true
|
||
// if(val.quotationId) {
|
||
// formData.value = await QuotationApi.getQuotationProductListByQuotationId(val.quotationId)
|
||
// } else if(val.businessId) {
|
||
const business = await BillTemplateApi.getTemplateProduct({
|
||
businessId: props.businessId,
|
||
billTemplateId: val,
|
||
});
|
||
for(let i = 0; i < business.length; i++) {
|
||
let data = business[i]
|
||
let foundItem = formData.value.find(item => item.productId == data.productId);
|
||
if (foundItem) {
|
||
foundItem.productInvoice = data.productInvoice
|
||
foundItem.productInvoiceItem = data.productInvoiceItems
|
||
foundItem.serviceInvoice = data.serviceFeeInvoice
|
||
foundItem.serviceInvoiceItem = data.serviceFeeInvoiceItems
|
||
}
|
||
}
|
||
// formData.value = business
|
||
// }
|
||
} finally {
|
||
formLoading.value = false
|
||
}
|
||
},
|
||
// { immediate: true }
|
||
)
|
||
// 监听合同产品变化,计算合同产品总价
|
||
watch(
|
||
() => formData.value,
|
||
(val) => {
|
||
if (!val || val.length === 0) {
|
||
return;
|
||
}
|
||
// 循环处理
|
||
val.forEach((item) => {
|
||
if (item.offlinePrice != null && item.onlinePrice != null) {
|
||
item.totalPrice = Number((Number(item.offlinePrice) + Number(item.onlinePrice)).toFixed(2));
|
||
} else {
|
||
item.totalPrice = 0;
|
||
}
|
||
});
|
||
},
|
||
{ deep: true }
|
||
);
|
||
|
||
watch(
|
||
() => props.products,
|
||
(val) => {
|
||
if (!val || val.length === 0) {
|
||
return;
|
||
}
|
||
nextTick(() => {
|
||
formData.value = val
|
||
})
|
||
},
|
||
{ immediate: true }
|
||
|
||
);
|
||
/** 新增按钮操作 */
|
||
const handleAdd = () => {
|
||
const row = {
|
||
quotationId: undefined,
|
||
productId: undefined,
|
||
productName: undefined,
|
||
detailType: undefined,
|
||
productUnit: undefined,
|
||
onlinePrice: undefined,
|
||
offlinePrice: undefined,
|
||
totalPrice: undefined,
|
||
productInvoice: undefined,
|
||
productInvoiceItem: undefined,
|
||
serviceInvoice: undefined,
|
||
serviceFeeInvoiceItems: undefined
|
||
}
|
||
row.quotationId = props.quotationId
|
||
formData.value.push(row)
|
||
}
|
||
|
||
/** 删除按钮操作 */
|
||
const handleDelete = (index) => {
|
||
formData.value.splice(index, 1)
|
||
}
|
||
|
||
/** 表单校验 */
|
||
const validate = () => {
|
||
return formRef.value.validate()
|
||
}
|
||
|
||
/** 表单值 */
|
||
const getData = () => {
|
||
return formData.value
|
||
}
|
||
|
||
defineExpose({ validate, getData })
|
||
</script>
|