|
|
@@ -1,4 +1,4 @@
|
|
|
-import { Component, OnInit, Input } from '@angular/core';
|
|
|
+import { Component, OnInit, Input, Output, EventEmitter, HostBinding } from '@angular/core';
|
|
|
import { CommonModule } from '@angular/common';
|
|
|
import { Router, ActivatedRoute } from '@angular/router';
|
|
|
import { IonicModule } from '@ionic/angular';
|
|
|
@@ -32,7 +32,11 @@ export class CustomerProfileComponent implements OnInit {
|
|
|
// 输入参数(支持组件复用)
|
|
|
@Input() customer: FmodeObject | null = null;
|
|
|
@Input() currentUser: FmodeObject | null = null;
|
|
|
-
|
|
|
+ // 新增:嵌入模式与项目过滤
|
|
|
+ @Input() embeddedMode: boolean = false;
|
|
|
+ @Input() projectIdFilter: string | null = null;
|
|
|
+ @Output() close = new EventEmitter<void>();
|
|
|
+ @HostBinding('class.embedded') get embeddedClass() { return this.embeddedMode; }
|
|
|
// 路由参数
|
|
|
cid: string = '';
|
|
|
contactId: string = '';
|
|
|
@@ -47,6 +51,7 @@ export class CustomerProfileComponent implements OnInit {
|
|
|
// 加载状态
|
|
|
loading: boolean = true;
|
|
|
error: string | null = null;
|
|
|
+ refreshing: boolean = false;
|
|
|
|
|
|
// 客户数据
|
|
|
contactInfo: FmodeObject | null = null;
|
|
|
@@ -316,28 +321,32 @@ export class CustomerProfileComponent implements OnInit {
|
|
|
*/
|
|
|
async loadFollowUpRecords() {
|
|
|
try {
|
|
|
- // 查询沟通记录
|
|
|
- const query = new Parse.Query('Communication');
|
|
|
- query.equalTo('project.customer', this.contactInfo!.toPointer());
|
|
|
+ // 使用 ContactFollow 表,默认按项目过滤
|
|
|
+ const query = new Parse.Query('ContactFollow');
|
|
|
+ query.equalTo('contact', this.contactInfo!.toPointer());
|
|
|
+ query.notEqualTo('isDeleted', true);
|
|
|
+ if (this.projectIdFilter) {
|
|
|
+ const project = new Parse.Object('Project');
|
|
|
+ project.id = this.projectIdFilter;
|
|
|
+ query.equalTo('project', project.toPointer());
|
|
|
+ }
|
|
|
query.descending('createdAt');
|
|
|
- query.limit(20);
|
|
|
-
|
|
|
- const communications = await query.find();
|
|
|
-
|
|
|
- this.profile.followUpRecords = communications.map((comm: any) => ({
|
|
|
- time: comm.get('createdAt'),
|
|
|
- type: comm.get('communicationType') || 'message',
|
|
|
- content: comm.get('content') || '',
|
|
|
- operator: comm.get('sender')?.get('name') || '系统'
|
|
|
+ query.limit(50);
|
|
|
+
|
|
|
+ const records = await query.find();
|
|
|
+ this.profile.followUpRecords = records.map((rec: any) => ({
|
|
|
+ time: rec.get('createdAt'),
|
|
|
+ type: rec.get('type') || 'message',
|
|
|
+ content: rec.get('content') || '',
|
|
|
+ operator: rec.get('sender')?.get('name') || '系统'
|
|
|
}));
|
|
|
|
|
|
- // 如果没有沟通记录,从ContactInfo.data.follow_user获取
|
|
|
+ // 若无 ContactFollow 记录,则兼容 data.follow_user
|
|
|
if (this.profile.followUpRecords.length === 0) {
|
|
|
const data = this.contactInfo!.get('data') || {};
|
|
|
const followUsers = data.follow_user || [];
|
|
|
-
|
|
|
this.profile.followUpRecords = followUsers.map((fu: any) => ({
|
|
|
- time: new Date(fu.createtime * 1000),
|
|
|
+ time: fu.createtime ? new Date(fu.createtime * 1000) : new Date(),
|
|
|
type: 'follow',
|
|
|
content: `${fu.userid} 添加客户`,
|
|
|
operator: fu.userid
|
|
|
@@ -376,6 +385,11 @@ export class CustomerProfileComponent implements OnInit {
|
|
|
* 返回
|
|
|
*/
|
|
|
goBack() {
|
|
|
+ // 嵌入模式下不跳转,触发关闭
|
|
|
+ if (this.embeddedMode) {
|
|
|
+ this.close.emit();
|
|
|
+ return;
|
|
|
+ }
|
|
|
this.router.navigate(['/wxwork', this.cid, 'project-loader']);
|
|
|
}
|
|
|
|
|
|
@@ -449,4 +463,43 @@ export class CustomerProfileComponent implements OnInit {
|
|
|
if (budget.min === budget.max) return `¥${budget.min}`;
|
|
|
return `¥${budget.min} - ¥${budget.max}`;
|
|
|
}
|
|
|
+
|
|
|
+ /** 刷新客户数据(基于 external_userid 拉取企微数据并保存) */
|
|
|
+ async refreshContactData() {
|
|
|
+ try {
|
|
|
+ if (!this.contactInfo) return;
|
|
|
+ const externalUserId = this.contactInfo.get('external_userid');
|
|
|
+ const companyId = this.currentUser?.get('company')?.id || this.contactInfo.get('company')?.id || localStorage.getItem('company');
|
|
|
+ if (!externalUserId || !companyId) {
|
|
|
+ alert('无法刷新:缺少企业或external_userid');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ this.refreshing = true;
|
|
|
+ const corp = new WxworkCorp(companyId);
|
|
|
+ const extData = await corp.externalContact.get(externalUserId);
|
|
|
+ const ext = (extData && extData.external_contact) ? extData.external_contact : {};
|
|
|
+ const follow = (extData && extData.follow_user) ? extData.follow_user : [];
|
|
|
+
|
|
|
+ if (ext.name) this.contactInfo.set('name', ext.name);
|
|
|
+ const prev = this.contactInfo.get('data') || {};
|
|
|
+ const mapped = {
|
|
|
+ ...prev,
|
|
|
+ external_contact: ext,
|
|
|
+ follow_user: follow,
|
|
|
+ name: ext.name,
|
|
|
+ avatar: ext.avatar,
|
|
|
+ gender: ext.gender,
|
|
|
+ type: ext.type
|
|
|
+ } as any;
|
|
|
+ this.contactInfo.set('data', mapped);
|
|
|
+ await this.contactInfo.save();
|
|
|
+
|
|
|
+ await this.buildCustomerProfile();
|
|
|
+ } catch (e) {
|
|
|
+ console.warn('刷新客户数据失败:', e);
|
|
|
+ alert('刷新失败,请稍后重试');
|
|
|
+ } finally {
|
|
|
+ this.refreshing = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|