consultation-order-panel.component.ts 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. import { Component, EventEmitter, OnInit, Output } from '@angular/core';
  2. import { FormBuilder, FormGroup, Validators, ReactiveFormsModule } from '@angular/forms';
  3. import { CommonModule } from '@angular/common';
  4. import { TeamAssignmentModalComponent, Designer } from '../team-assignment-modal/team-assignment-modal.component';
  5. import { FormsModule } from '@angular/forms';
  6. import { MatChipsModule } from '@angular/material/chips';
  7. import { MatIconModule } from '@angular/material/icon';
  8. // 定义客户信息接口
  9. interface Customer {
  10. id: string;
  11. name: string;
  12. phone: string;
  13. wechat?: string;
  14. avatar?: string;
  15. customerType?: string;
  16. source?: string;
  17. remark?: string;
  18. demandType?: string;
  19. preferenceTags?: string[];
  20. followUpStatus?: string;
  21. }
  22. @Component({
  23. selector: 'app-consultation-order-panel',
  24. standalone: true,
  25. imports: [
  26. CommonModule,
  27. ReactiveFormsModule,
  28. FormsModule,
  29. MatChipsModule,
  30. MatIconModule,
  31. TeamAssignmentModalComponent
  32. ],
  33. templateUrl: './consultation-order-panel.component.html',
  34. styleUrls: ['./consultation-order-panel.component.scss']
  35. })
  36. export class ConsultationOrderPanelComponent {
  37. @Output() orderCreated = new EventEmitter<any>();
  38. @Output() projectCreated = new EventEmitter<any>(); // 新增项目创建成功事件
  39. // 搜索客户关键词
  40. searchKeyword = '';
  41. // 搜索结果列表
  42. searchResults: Customer[] = [];
  43. // 选中的客户
  44. selectedCustomer: Customer | null = null;
  45. // 表单提交状态
  46. isSubmitting = false;
  47. // 项目需求卡片展开状态 - 默认展开以便用户填写必填字段
  48. isRequirementCardExpanded = true;
  49. // 需求表单
  50. requirementForm: FormGroup;
  51. // 客户表单
  52. customerForm: FormGroup;
  53. // 团队分配弹窗相关
  54. showTeamAssignmentModal = false;
  55. selectedDesigner: Designer | null = null;
  56. // 样式选项
  57. styleOptions = [
  58. '现代简约', '北欧风', '工业风', '新中式', '法式轻奢', '日式', '美式', '混搭'
  59. ];
  60. // 项目小组选项
  61. projectGroupOptions = [
  62. '设计一组', '设计二组', '设计三组', '高端定制组', '软装设计组'
  63. ];
  64. // 偏好标签选项
  65. preferenceTagOptions = [
  66. '柔和色系', '明亮色系', '深色系', '中性色系',
  67. '环保材料', '实木', '大理石', '瓷砖', '地板', '墙纸',
  68. '现代简约', '北欧风格', '中式风格', '美式风格', '工业风',
  69. '智能家电', '收纳空间', '开放式厨房', '大窗户'
  70. ];
  71. preferenceTags: string[] = [];
  72. // 新标签输入
  73. newTag = '';
  74. // 角色上下文
  75. roleContext: 'customer-service' | 'designer' | 'team-leader' = 'customer-service';
  76. constructor(private fb: FormBuilder) {
  77. // 初始化需求表单
  78. this.requirementForm = this.fb.group({
  79. decorationType: ['', Validators.required],
  80. downPayment: ['', [Validators.required, Validators.min(0)]],
  81. firstDraftDate: ['', Validators.required],
  82. style: [''],
  83. projectGroup: [''],
  84. budget: ['', Validators.required],
  85. area: ['', [Validators.required, Validators.min(1)]],
  86. smallImageTime: [''],
  87. largeImageTime: [''],
  88. houseType: [''],
  89. floor: ['', Validators.min(1)],
  90. preferredDesigner: [''],
  91. specialRequirements: [''],
  92. referenceCases: [[]],
  93. priceDetails: [''],
  94. // 新增字段
  95. spaceRequirements: [''],
  96. designAngles: [''],
  97. specialAreaHandling: [''],
  98. materialRequirements: [''],
  99. lightingRequirements: ['']
  100. });
  101. // 初始化客户表单
  102. this.customerForm = this.fb.group({
  103. name: ['', Validators.required],
  104. phone: ['', [Validators.required, Validators.pattern(/^(1[3-9]\d{9}|1[3-9]\d{1}\*{4}\d{4})$/)]],
  105. wechat: [''],
  106. customerType: ['新客户'],
  107. source: [''],
  108. remark: [''],
  109. demandType: [''],
  110. followUpStatus: ['']
  111. });
  112. }
  113. // 搜索客户
  114. searchCustomer() {
  115. if (this.searchKeyword.length >= 2) {
  116. // 模拟搜索结果
  117. this.searchResults = [
  118. {
  119. id: '1',
  120. name: '张先生',
  121. phone: '138****5678',
  122. customerType: '老客户',
  123. source: '官网咨询',
  124. avatar: "data:image/svg+xml,%3Csvg width='64' height='40' xmlns='http://www.w3.org/2000/svg'%3E%3Crect width='100%25' height='100%25' fill='%23E6E6E6'/%3E%3Ctext x='50%25' y='50%25' font-family='Arial' font-size='13.333333333333334' font-weight='bold' text-anchor='middle' fill='%23555555' dy='0.3em'%3EIMG%3C/text%3E%3C/svg%3E"
  125. },
  126. {
  127. id: '2',
  128. name: '李女士',
  129. phone: '139****1234',
  130. customerType: 'VIP客户',
  131. source: '推荐介绍',
  132. avatar: "data:image/svg+xml,%3Csvg width='65' height='40' xmlns='http://www.w3.org/2000/svg'%3E%3Crect width='100%25' height='100%25' fill='%23DCDCDC'/%3E%3Ctext x='50%25' y='50%25' font-family='Arial' font-size='13.333333333333334' font-weight='bold' text-anchor='middle' fill='%23555555' dy='0.3em'%3EIMG%3C/text%3E%3C/svg%3E"
  133. }
  134. ];
  135. }
  136. }
  137. // 选择客户
  138. selectCustomer(customer: Customer) {
  139. this.selectedCustomer = customer;
  140. // 填充客户表单
  141. this.customerForm.patchValue({
  142. name: customer.name,
  143. phone: customer.phone,
  144. wechat: customer.wechat || '',
  145. customerType: customer.customerType || '新客户',
  146. source: customer.source || '',
  147. remark: customer.remark || ''
  148. });
  149. // 清空搜索结果
  150. this.searchResults = [];
  151. this.searchKeyword = '';
  152. }
  153. // 清除选中的客户
  154. clearSelectedCustomer() {
  155. this.selectedCustomer = null;
  156. this.customerForm.reset({
  157. customerType: '新客户'
  158. });
  159. }
  160. // 添加偏好标签
  161. addPreferenceTag(tag: string): void {
  162. if (tag && !this.preferenceTags.includes(tag)) {
  163. this.preferenceTags.push(tag);
  164. this.newTag = ''; // 清空输入框
  165. }
  166. }
  167. // 删除偏好标签
  168. removePreferenceTag(tag: string): void {
  169. const index = this.preferenceTags.indexOf(tag);
  170. if (index >= 0) {
  171. this.preferenceTags.splice(index, 1);
  172. }
  173. }
  174. // 检查表单是否有效
  175. isFormValid(): boolean {
  176. return this.customerForm.valid && this.requirementForm.valid;
  177. }
  178. // 提交表单
  179. submitForm() {
  180. if (this.isFormValid()) {
  181. this.isSubmitting = true;
  182. const formData = {
  183. customerInfo: this.customerForm.value,
  184. requirementInfo: this.requirementForm.value,
  185. preferenceTags: this.preferenceTags,
  186. roleContext: this.roleContext, // 添加角色上下文信息
  187. createdAt: new Date()
  188. };
  189. // 直接触发订单创建事件,不需要延迟
  190. this.orderCreated.emit(formData);
  191. // 立即显示团队分配弹窗
  192. this.showTeamAssignmentModal = true;
  193. }
  194. }
  195. // 关闭团队分配弹窗
  196. closeTeamAssignmentModal() {
  197. this.showTeamAssignmentModal = false;
  198. }
  199. // 确认团队分配
  200. confirmTeamAssignment(designer: Designer) {
  201. this.selectedDesigner = designer;
  202. this.showTeamAssignmentModal = false;
  203. this.isSubmitting = false; // 重置提交状态
  204. // 发出项目创建成功事件
  205. const projectData = {
  206. customerInfo: this.customerForm.value,
  207. requirementInfo: this.requirementForm.value,
  208. preferenceTags: this.preferenceTags,
  209. assignedDesigner: designer,
  210. createdAt: new Date()
  211. };
  212. this.projectCreated.emit(projectData);
  213. // 重置表单
  214. this.customerForm.reset({
  215. customerType: '新客户'
  216. });
  217. this.requirementForm.reset();
  218. this.preferenceTags = [];
  219. this.selectedCustomer = null;
  220. }
  221. }