consultation-order.ts 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. import { Component, signal } from '@angular/core';
  2. import { CommonModule } from '@angular/common';
  3. import { FormsModule, ReactiveFormsModule, FormBuilder, FormGroup, Validators } from '@angular/forms';
  4. import { RouterModule } from '@angular/router';
  5. import { ProjectService } from '../../../services/project.service';
  6. // 定义客户信息接口
  7. interface Customer {
  8. id: string;
  9. name: string;
  10. phone: string;
  11. wechat?: string;
  12. avatar?: string;
  13. customerType?: string; // 新客户/老客户/VIP客户
  14. source?: string; // 来源渠道
  15. remark?: string;
  16. }
  17. // 定义需求信息接口
  18. interface Requirement {
  19. style: string;
  20. budget: string;
  21. area: number;
  22. houseType: string;
  23. floor: number;
  24. decorationType: string;
  25. preferredDesigner?: string;
  26. specialRequirements?: string;
  27. referenceCases?: string[];
  28. }
  29. @Component({
  30. selector: 'app-consultation-order',
  31. standalone: true,
  32. imports: [CommonModule, FormsModule, ReactiveFormsModule, RouterModule],
  33. templateUrl: './consultation-order.html',
  34. styleUrls: ['./consultation-order.scss', '../customer-service-styles.scss']
  35. })
  36. export class ConsultationOrder {
  37. // 搜索客户关键词
  38. searchKeyword = signal('');
  39. // 搜索结果列表
  40. searchResults = signal<Customer[]>([]);
  41. // 选中的客户
  42. selectedCustomer = signal<Customer | null>(null);
  43. // 报价范围
  44. estimatedPriceRange = signal<string>('');
  45. // 匹配的案例
  46. matchedCases = signal<any[]>([]);
  47. // 表单提交状态
  48. isSubmitting = signal(false);
  49. // 成功提示显示状态
  50. showSuccessMessage = signal(false);
  51. // 需求表单
  52. requirementForm: FormGroup;
  53. // 客户表单
  54. customerForm: FormGroup;
  55. // 样式选项
  56. styleOptions = [
  57. '现代简约', '北欧风', '工业风', '新中式', '法式轻奢', '日式', '美式', '混搭'
  58. ];
  59. // 户型选项
  60. houseTypeOptions = [
  61. '一室一厅', '两室一厅', '两室两厅', '三室一厅', '三室两厅', '四室两厅', '复式', '别墅', '其他'
  62. ];
  63. // 装修类型选项
  64. decorationTypeOptions = [
  65. '全包', '半包', '清包', '旧房翻新', '局部改造'
  66. ];
  67. constructor(
  68. private fb: FormBuilder,
  69. private projectService: ProjectService
  70. ) {
  71. // 初始化需求表单
  72. this.requirementForm = this.fb.group({
  73. style: ['', Validators.required],
  74. budget: ['', Validators.required],
  75. area: ['', [Validators.required, Validators.min(1)]],
  76. houseType: ['', Validators.required],
  77. floor: ['', Validators.min(1)],
  78. decorationType: ['', Validators.required],
  79. preferredDesigner: [''],
  80. specialRequirements: [''],
  81. referenceCases: [[]]
  82. });
  83. // 初始化客户表单
  84. this.customerForm = this.fb.group({
  85. name: ['', Validators.required],
  86. phone: ['', [Validators.required, Validators.pattern(/^1[3-9]\d{9}$/)]],
  87. wechat: [''],
  88. customerType: ['新客户'],
  89. source: [''],
  90. remark: ['']
  91. });
  92. // 监听表单值变化,自动计算报价和匹配案例
  93. this.requirementForm.valueChanges.subscribe(() => {
  94. this.calculateEstimatedPrice();
  95. this.matchCases();
  96. });
  97. }
  98. // 搜索客户
  99. searchCustomer() {
  100. if (this.searchKeyword().length >= 2) {
  101. // 模拟搜索结果
  102. this.searchResults.set([
  103. {
  104. id: '1',
  105. name: '张先生',
  106. phone: '138****5678',
  107. customerType: '老客户',
  108. source: '官网咨询',
  109. avatar: 'https://picsum.photos/id/64/40/40'
  110. },
  111. {
  112. id: '2',
  113. name: '李女士',
  114. phone: '139****1234',
  115. customerType: 'VIP客户',
  116. source: '推荐介绍',
  117. avatar: 'https://picsum.photos/id/65/40/40'
  118. }
  119. ]);
  120. }
  121. }
  122. // 选择客户
  123. selectCustomer(customer: Customer) {
  124. this.selectedCustomer.set(customer);
  125. // 填充客户表单
  126. this.customerForm.patchValue({
  127. name: customer.name,
  128. phone: customer.phone,
  129. wechat: customer.wechat || '',
  130. customerType: customer.customerType || '新客户',
  131. source: customer.source || '',
  132. remark: customer.remark || ''
  133. });
  134. // 清空搜索结果
  135. this.searchResults.set([]);
  136. this.searchKeyword.set('');
  137. }
  138. // 清除选中的客户
  139. clearSelectedCustomer() {
  140. this.selectedCustomer.set(null);
  141. this.customerForm.reset({
  142. customerType: '新客户'
  143. });
  144. }
  145. // 计算预估报价
  146. calculateEstimatedPrice() {
  147. const { area, decorationType, style } = this.requirementForm.value;
  148. if (area && decorationType) {
  149. // 模拟报价计算逻辑
  150. let basePrice = 0;
  151. switch (decorationType) {
  152. case '全包':
  153. basePrice = 1800;
  154. break;
  155. case '半包':
  156. basePrice = 1200;
  157. break;
  158. case '清包':
  159. basePrice = 800;
  160. break;
  161. case '旧房翻新':
  162. basePrice = 2000;
  163. break;
  164. case '局部改造':
  165. basePrice = 1500;
  166. break;
  167. default:
  168. basePrice = 1200;
  169. break;
  170. }
  171. // 风格加价
  172. const stylePremium = ['法式轻奢', '新中式', '日式'].includes(style) ? 0.2 : 0;
  173. const totalPrice = area * basePrice * (1 + stylePremium);
  174. const lowerBound = Math.floor(totalPrice * 0.9);
  175. const upperBound = Math.ceil(totalPrice * 1.1);
  176. this.estimatedPriceRange.set(
  177. `¥${lowerBound.toLocaleString()} - ¥${upperBound.toLocaleString()}`
  178. );
  179. }
  180. }
  181. // 匹配案例
  182. matchCases() {
  183. const { style, houseType, area } = this.requirementForm.value;
  184. if (style && houseType && area) {
  185. // 模拟匹配案例
  186. this.matchedCases.set([
  187. {
  188. id: '101',
  189. name: `${style}风格 ${houseType}设计`,
  190. imageUrl: `https://picsum.photos/id/${30 + Math.floor(Math.random() * 10)}/300/200`,
  191. designer: '王设计师',
  192. area: area + '㎡',
  193. similarity: 92
  194. },
  195. {
  196. id: '102',
  197. name: `${houseType} ${style}案例展示`,
  198. imageUrl: `https://picsum.photos/id/${40 + Math.floor(Math.random() * 10)}/300/200`,
  199. designer: '张设计师',
  200. area: (area + 10) + '㎡',
  201. similarity: 85
  202. }
  203. ]);
  204. }
  205. }
  206. // 选择参考案例
  207. selectReferenceCase(caseItem: any) {
  208. const currentCases = this.requirementForm.get('referenceCases')?.value || [];
  209. if (!currentCases.includes(caseItem.id)) {
  210. this.requirementForm.patchValue({
  211. referenceCases: [...currentCases, caseItem.id]
  212. });
  213. }
  214. }
  215. // 移除参考案例
  216. removeReferenceCase(caseId: string) {
  217. const currentCases = this.requirementForm.get('referenceCases')?.value || [];
  218. this.requirementForm.patchValue({
  219. referenceCases: currentCases.filter((id: string) => id !== caseId)
  220. });
  221. }
  222. // 提交表单
  223. submitForm() {
  224. if (this.requirementForm.valid && this.customerForm.valid) {
  225. this.isSubmitting.set(true);
  226. const formData = {
  227. customerInfo: this.customerForm.value,
  228. requirementInfo: this.requirementForm.value,
  229. estimatedPriceRange: this.estimatedPriceRange(),
  230. createdAt: new Date()
  231. };
  232. // 模拟提交请求
  233. setTimeout(() => {
  234. console.log('提交的表单数据:', formData);
  235. this.isSubmitting.set(false);
  236. this.showSuccessMessage.set(true);
  237. // 3秒后隐藏成功提示
  238. setTimeout(() => {
  239. this.showSuccessMessage.set(false);
  240. }, 3000);
  241. }, 1500);
  242. }
  243. }
  244. // 一键拉群
  245. createProjectGroup() {
  246. // 模拟拉群功能
  247. console.log('创建项目群');
  248. alert('项目群已创建,并邀请了相应技术组长!');
  249. }
  250. }