| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198 |
- import { Component, Input, Output, EventEmitter, OnInit } from '@angular/core';
- import { CommonModule } from '@angular/common';
- import { FormsModule } from '@angular/forms';
- import { AIQuotationService, AIQuotationParams, AIQuotationResult } from '../../../../../services/ai-quotation.service';
- export interface QuotationItem {
- id: string;
- category: string;
- name: string;
- quantity: number;
- unit: string;
- unitPrice: number;
- description: string;
- }
- export interface QuotationData {
- items: QuotationItem[];
- totalAmount: number;
- materialCost: number;
- laborCost: number;
- designFee: number;
- managementFee: number;
- }
- @Component({
- selector: 'app-quotation-details',
- standalone: true,
- imports: [CommonModule, FormsModule],
- templateUrl: './quotation-details.component.html',
- styleUrls: ['./quotation-details.component.scss']
- })
- export class QuotationDetailsComponent implements OnInit {
- @Input() initialData?: QuotationData;
- @Output() dataChange = new EventEmitter<QuotationData>();
- quotationData: QuotationData = {
- items: [],
- totalAmount: 0,
- materialCost: 0,
- laborCost: 0,
- designFee: 0,
- managementFee: 0
- };
- // AI报价相关
- showAIModal = false;
- aiLoading = false;
- aiParams: AIQuotationParams = {
- area: 100,
- style: '现代简约',
- level: '舒适型',
- specialRequirements: ''
- };
- // 选项数据
- styleOptions: string[] = [];
- levelOptions: string[] = [];
- constructor(private aiQuotationService: AIQuotationService) {}
- ngOnInit() {
- if (this.initialData) {
- this.quotationData = { ...this.initialData };
- }
-
- // 初始化选项数据
- this.styleOptions = this.aiQuotationService.getStyleOptions();
- this.levelOptions = this.aiQuotationService.getLevelOptions();
- }
- // 添加报价项目
- addQuotationItem() {
- const newItem: QuotationItem = {
- id: Date.now().toString(),
- category: '客餐厅',
- name: '',
- quantity: 1,
- unit: '㎡',
- unitPrice: 0,
- description: ''
- };
-
- this.quotationData.items.push(newItem);
- this.calculateTotal();
- this.emitDataChange();
- }
- // 删除报价项目
- removeQuotationItem(index: number) {
- this.quotationData.items.splice(index, 1);
- this.calculateTotal();
- this.emitDataChange();
- }
- // 复制报价项目
- duplicateQuotationItem(index: number) {
- const originalItem = this.quotationData.items[index];
- const duplicatedItem: QuotationItem = {
- ...originalItem,
- id: Date.now().toString(),
- name: originalItem.name + ' (副本)'
- };
-
- this.quotationData.items.splice(index + 1, 0, duplicatedItem);
- this.calculateTotal();
- this.emitDataChange();
- }
- // 计算总金额
- calculateTotal() {
- const materialCost = this.quotationData.items.reduce((sum, item) => sum + (item.quantity * item.unitPrice), 0);
- this.quotationData.materialCost = materialCost;
- this.quotationData.laborCost = materialCost * 0.3; // 人工费按材料费30%计算
- this.quotationData.designFee = materialCost * 0.05; // 设计费按材料费5%计算
- this.quotationData.managementFee = materialCost * 0.08; // 管理费按材料费8%计算
- this.quotationData.totalAmount = this.quotationData.materialCost + this.quotationData.laborCost + this.quotationData.designFee + this.quotationData.managementFee;
- }
- // 获取总金额
- getTotalAmount(): number {
- return this.quotationData.totalAmount;
- }
- // 获取材料费用
- getMaterialCost(): number {
- return this.quotationData.materialCost;
- }
- // 获取人工费用
- getLaborCost(): number {
- return this.quotationData.laborCost;
- }
- // 格式化金额显示
- formatAmount(amount: number): string {
- return amount.toLocaleString('zh-CN', { minimumFractionDigits: 2, maximumFractionDigits: 2 });
- }
- // 项目数据变化处理
- onItemChange() {
- this.calculateTotal();
- this.emitDataChange();
- }
- // 发送数据变化事件
- private emitDataChange() {
- this.dataChange.emit({ ...this.quotationData });
- }
- // 显示AI报价模态框
- showAIQuotation() {
- this.showAIModal = true;
- }
- // 关闭AI报价模态框
- closeAIModal() {
- this.showAIModal = false;
- this.aiLoading = false;
- }
- // 生成AI报价
- generateAIQuotation() {
- if (!this.aiParams.area || !this.aiParams.style || !this.aiParams.level) {
- return;
- }
- this.aiLoading = true;
-
- this.aiQuotationService.generateQuotation(this.aiParams).subscribe({
- next: (result: AIQuotationResult) => {
- // 将AI生成的项目转换为报价项目
- const aiItems: QuotationItem[] = result.items.map(item => ({
- id: Date.now().toString() + Math.random().toString(36).substr(2, 9),
- category: item.category,
- name: item.name,
- quantity: item.quantity,
- unit: item.unit,
- unitPrice: item.unitPrice,
- description: item.description || ''
- }));
- // 替换当前报价项目
- this.quotationData.items = aiItems;
- this.calculateTotal();
- this.emitDataChange();
-
- this.aiLoading = false;
- this.closeAIModal();
- },
- error: (error) => {
- console.error('AI报价生成失败:', error);
- this.aiLoading = false;
- }
- });
- }
- }
|