@etsoo/smarterp-crm
Version:
TypeScript APIs for SmartERP Customer Relationship Management (CRM)
166 lines (165 loc) • 4.18 kB
JavaScript
import { IdentityType } from "@etsoo/appscript";
import { PersonApi } from "./PersonApi";
import { useRequiredContext } from "@etsoo/react";
import { ReactAppContext } from "@etsoo/materialui";
import { PersonTitle } from "./dto/person/PersonTitle";
import { MaritalStatus } from "./dto/person/MaritalStatus";
import { PersonDegree } from "./dto/person/PersonDegree";
import { PersonEducation } from "./dto/person/PersonEducation";
import { PersonProfileApi } from "./PersonProfileApi";
/**
* Get CRM app context hook
* @returns CRM app
*/
export function useRequiredCrmContext() {
// Get the app context
const app = useRequiredContext(ReactAppContext);
// Check the app type
if ("crm" in app) {
return app.crm;
}
else {
return app;
}
}
/**
* CRM application
* CRM应用程序
*/
export class CrmApp {
app;
api;
_personApi;
/**
* Person API
* 人员接口
*/
get personApi() {
return (this._personApi ??= new PersonApi(this.app, this.api));
}
_personProfileApi;
/**
* Person profile API
* 人员档案接口
*/
get personProfileApi() {
return (this._personProfileApi ??= new PersonProfileApi(this.app, this.api));
}
/**
* Constructor
* 构造函数
* @param app Base application
* @param api API
*/
constructor(app, api) {
this.app = app;
this.api = api;
}
/**
* Get person gender
* 获取人员性别
* @param gender Gender value
* @returns Label
*/
getPersonGender(gender) {
if (gender === "M")
return this.app.get("personMale") ?? "Male";
else if (gender === "F")
return this.app.get("personFemale") ?? "Female";
else
return undefined;
}
/**
* Get identity type
* 获取身份类型
* @param data Identity type data
*/
getIdentityType(data) {
if (data == null)
return "";
if (data.isOrg) {
return this.app.get("org");
}
const type = data.identityType;
return this.app
.getEnumList(IdentityType, "id", (id, _key) => {
if ((id & type) > 0)
return id;
})
.map((d) => d.label)
.join(", ");
}
/**
* Get marital status
* 获取婚姻状况
* @param status
*/
getMaritalStatus(status) {
if (status == null)
return undefined;
const key = MaritalStatus[status];
return this.app.get("marital" + key) ?? key;
}
/**
* Get marital statuses
* 获取婚姻状况列表
* @param status
*/
getMaritalStatuses() {
return this.app.getEnumList(MaritalStatus, "marital");
}
/**
* Get person degree
* 获取人员学历
* @param degree
*/
getPersonDegree(degree) {
if (degree == null)
return undefined;
const key = PersonDegree[degree];
return this.app.get("degree" + key) ?? key;
}
/**
* Get person degree list
* 获取人员学历列表
*/
getPersonDegrees() {
return this.app.getEnumList(PersonDegree, "degree");
}
/**
* Get person education
* 获取人员学历
* @param education
*/
getPersonEducation(education) {
if (education == null)
return undefined;
const key = PersonEducation[education];
return this.app.get("education" + key) ?? key;
}
/**
* Get person education list
* 获取人员学历列表
*/
getPersonEducations() {
return this.app.getEnumList(PersonEducation, "education");
}
/**
* Get person title
* 获取人员头衔
* @param title
*/
getPersonTitle(title) {
if (title == null)
return undefined;
const key = PersonTitle[title];
return this.app.get("personTitle" + key) ?? key;
}
/**
* Get person titles
* 获取人员头衔
*/
getPersonTitles() {
return this.app.getEnumList(PersonTitle, "personTitle");
}
}