UNPKG

@etsoo/smarterp-crm

Version:

TypeScript APIs for SmartERP Customer Relationship Management (CRM)

171 lines (170 loc) 4.55 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CrmApp = void 0; exports.useRequiredCrmContext = useRequiredCrmContext; const appscript_1 = require("@etsoo/appscript"); const PersonApi_1 = require("./PersonApi"); const react_1 = require("@etsoo/react"); const materialui_1 = require("@etsoo/materialui"); const PersonTitle_1 = require("./dto/person/PersonTitle"); const MaritalStatus_1 = require("./dto/person/MaritalStatus"); const PersonDegree_1 = require("./dto/person/PersonDegree"); const PersonEducation_1 = require("./dto/person/PersonEducation"); const PersonProfileApi_1 = require("./PersonProfileApi"); /** * Get CRM app context hook * @returns CRM app */ function useRequiredCrmContext() { // Get the app context const app = (0, react_1.useRequiredContext)(materialui_1.ReactAppContext); // Check the app type if ("crm" in app) { return app.crm; } else { return app; } } /** * CRM application * CRM应用程序 */ class CrmApp { app; api; _personApi; /** * Person API * 人员接口 */ get personApi() { return (this._personApi ??= new PersonApi_1.PersonApi(this.app, this.api)); } _personProfileApi; /** * Person profile API * 人员档案接口 */ get personProfileApi() { return (this._personProfileApi ??= new PersonProfileApi_1.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(appscript_1.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_1.MaritalStatus[status]; return this.app.get("marital" + key) ?? key; } /** * Get marital statuses * 获取婚姻状况列表 * @param status */ getMaritalStatuses() { return this.app.getEnumList(MaritalStatus_1.MaritalStatus, "marital"); } /** * Get person degree * 获取人员学历 * @param degree */ getPersonDegree(degree) { if (degree == null) return undefined; const key = PersonDegree_1.PersonDegree[degree]; return this.app.get("degree" + key) ?? key; } /** * Get person degree list * 获取人员学历列表 */ getPersonDegrees() { return this.app.getEnumList(PersonDegree_1.PersonDegree, "degree"); } /** * Get person education * 获取人员学历 * @param education */ getPersonEducation(education) { if (education == null) return undefined; const key = PersonEducation_1.PersonEducation[education]; return this.app.get("education" + key) ?? key; } /** * Get person education list * 获取人员学历列表 */ getPersonEducations() { return this.app.getEnumList(PersonEducation_1.PersonEducation, "education"); } /** * Get person title * 获取人员头衔 * @param title */ getPersonTitle(title) { if (title == null) return undefined; const key = PersonTitle_1.PersonTitle[title]; return this.app.get("personTitle" + key) ?? key; } /** * Get person titles * 获取人员头衔 */ getPersonTitles() { return this.app.getEnumList(PersonTitle_1.PersonTitle, "personTitle"); } } exports.CrmApp = CrmApp;