import { IuserInfo } from '../../aim/face'; import { IformSubmitConfig } from '../../aim/form'; import { PlusOperateForm, PlusCommonWidget, PlusOperatePage, PlusCommonEvent, PlusOperateSync, PlusOperateData } from '../../main/index'; import Config from './config'; /** * 业务逻辑支持类 该类自由编辑 尽量使用static方法 * * @export * @class CurrentSupport */ import top_support from '../top/support'; import logic_support from './logic'; //import report_util from '../../../code/current/util/report_util'; export default class { /** * 初始化应用的操作代码 * * @static * @param {any} that */ static initApplication(that, data_items) { PlusOperateSync.initProjectDefine(Config.upConfig()); //初始化dataitem的数据结构 data_items是临时代码 后续改 PlusOperateData.dataItem.initDataItem(data_items.upDataItem()); //初始化同步逻辑操作 PlusOperateSync.initSyncListener(logic_support.syncListenerPromise); //同步http文件 临时代码 //PlusOperateSync.syncHttpFiles(Config.upConfig().httpSync); let bFlagLogin = logic_support.checkLogin(); if (bFlagLogin) { //this.formDataSyncPromise().done(); this.syncData(); } } static apiCall(sApiName: string, oParam?) { return logic_support.fetchApiPromise( sApiName, oParam) } /** * 触发一个同步操作逻辑 * * @static * @param {any} sType */ static syncData(sType?) { PlusOperateSync.autoSyncEmit(sType); } static syncCount(that) { top_support.topState(that, logic_support.upSyncCount()); } static templateDataRefresh(that, sTemplate, oData, iType) { PlusCommonEvent.noticeListRefresh(sTemplate, { eventArray: oData, eventValue: 'set' }); } static flatListDataRefresh(that, sTemplate, oData) { let oTemplateData = {}; oTemplateData[Config.upConfig().templateStart + sTemplate] = oData; that.setState(oTemplateData); } static userLoginCheck(that) { //开始form的数据同步接口 let bFlagLogin = logic_support.checkLogin(); if (!bFlagLogin) { top_support.pageNav('pages_system_login_index?base_jump=reset', that); } } static userLoginOut(that) { //退出登录首先强制同步数据 this.syncData('force'); PlusCommonEvent.noticeSubscribeUpdate('system_setting_logout_button', { eventState: 12, eventValue: '执行退出逻辑中' }); PlusCommonEvent.onceSyncResult((oEventResult) => { if (oEventResult.eventValue === "success") { logic_support.loginOut(); top_support.pageNav('pages_system_login_index?base_jump=reset', that); } else { PlusCommonWidget.msgAlert('退出出现异常,请检查网络或联系技术人员'); PlusCommonEvent.noticeSubscribeUpdate('system_setting_logout_button', { eventState: 1, }); } }); } static userLoginInfo(): IuserInfo { return logic_support.upUserInfo(); } static userLoginFetch(sFormName, that) { // 临时测试代码 直接登录 //top_support.pageNav('pages_demo_list_index', that); logic_support.fetchApiPromise( "api/genapp/post/clientuserlogin", PlusOperateForm.upFormDataObject(sFormName)) .then((oResult) => { logic_support.userLoginSuccess(oResult, that); logic_support.checkLogin(); /* this.formDataSyncPromise().then(() => { top_support.pageNav('root_layout_main?base_jump=reset', that); }); */ PlusCommonEvent.noticeSubscribeUpdate('system_login_button', { eventState: 12, eventValue: '同步数据中' }); }) .then(() => { return PlusOperateSync.syncHttpFiles(Config.upConfig().httpSync) }) .then( () => { PlusCommonEvent.onceSyncResult((oEventResult) => { if (oEventResult.eventValue === "success") { top_support.pageNav('root_layout_main?base_jump=reset', that); } else { PlusCommonWidget.msgAlert('同步出现异常,请联系技术人员'); } }); this.syncData('force'); } ) .catch((error) => { console.warn(error); if (error != 'apierr') { PlusCommonWidget.msgAlert('登录出现异常,请检查网络情况或者联系技术人员'); } }) ; } /** * 基本的form提交操作 所有提交应底层调用本操作逻辑 * * @static * @param {any} that * @param {string} sFormName * @param {IformSubmitConfig} oSet */ static _formSubmit(that, sFormName: string, oSet: IformSubmitConfig) { //设置form用户的显示名称 oSet.formFounder = this.userLoginInfo().userShowName; let oResult = PlusOperateForm.submitFormData(sFormName, that, oSet); if (oResult.flagSuccess) { this.syncData(); top_support.pageBack(that); } else { top_support.msgAlert(oResult.errorMessage); } } /** * 常规的form表单提交操作 * * @static * @param {any} that * @param {any} sFormName * @param {any} sMacroName */ static formDataSubmit(that, sFormName, sMacroName) { this._formSubmit(that, sFormName, { noticeListName: sMacroName }); } static formDataList(sFormCode, sFiter) { let datas = PlusOperateData.formData.upFormData(sFormCode, sFiter); return datas; } static formDataSyncPromise() { //该方法已被取代 //return logic_support.syncFormDataPromise().catch(() => {}); } static peopleInfoSelect(sKey, that) { let oPeopleData = PlusOperateData.formData.upFormDataByKey('patientinfo', sKey); this.peopleInfoVariable(sKey, oPeopleData.data); top_support.pageNav('pages_aform_people_index?base_leader=' + sKey, that); } /** * 单选人操作 * * @static * @param {any} sKey * @param {any} that */ static peopleSignSelect(sKey, that) { let oPeopleData = PlusOperateData.formData.upFormDataByKey('patientinfo', sKey); let oUrlInfo = PlusOperatePage.upUrlInfo(undefined, that); let oMap = new Map(); for (var p in oPeopleData.data) { oMap.set(p, oPeopleData.data[p]); } PlusCommonEvent.noticeDisplayRefresh(oUrlInfo.baseField, { eventValue: sKey, eventObject: { baseKey: sKey, dataInfo: oMap } }); top_support.pageBack(that); } static peopleInfoVariable(sKey, oData) { if (oData === undefined) { oData = PlusOperateData.formData.upFormDataByKey('patientinfo', sKey).data; } PlusOperateData.systemVariable.inValue(Config.upConfig().variableStart + 'people_select', { key: sKey, data: oData }); } /** * 获取当前页的basekey * * @static * @returns */ static upFormCurrentKey(sFormCode) { return PlusOperateForm.upFormInfo(sFormCode).baseKey; } static peopleCodeQuery() { let oPeopleKey = this.peopleInfoKey(); //let oPeopleKey = PlusOperateForm.upFormInfo('patientinfo').baseKey; return 'leaderCode="' + oPeopleKey + '" '; } /** * 用户添加页面初始化 * * @static * @param {any} that */ static peopleAddInit(that) { let oPeopleKey = PlusOperateForm.upFormInfo('patientinfo').baseKey; let oUrlInfo = top_support.upUrlInfo(that); if (oUrlInfo.baseType === undefined || oUrlInfo.baseType === 'add') { this.peopleInfoVariable(oPeopleKey, {}); } } static peopleInfoKey() { let sReturn = ''; let oPeopleInfo: any = this.peopleInfoUp(); if (oPeopleInfo) { sReturn = oPeopleInfo.key; } return sReturn; } static peopleInfoShow() { let sReturn = ''; let oPeopleInfo: any = this.peopleInfoUp(); let bFlagSign = oPeopleInfo.data.sign_f_hide ? true : false; sReturn = oPeopleInfo.data.name_patient + (oPeopleInfo.data.sex_patient_f_text ? ('-' + oPeopleInfo.data.sex_patient_f_text) : '') + '/' + oPeopleInfo.data.age + '岁' + (bFlagSign ? "(已签约)" : ''); return sReturn; } static peopleSignLink() { let oPeopleInfo: any = this.peopleInfoUp(); let bFlagSign = oPeopleInfo.data.sign_f_hide ? true : false; return oPeopleInfo.data.sign_f_hide ? ('pages_form_signservice_index?base_type=book&base_key=' + oPeopleInfo.data.sign_f_hide) : 'pages_apply_tip_index?base_type=no_sign'; } static peopleInfoUp() { return PlusOperateData.systemVariable.upValue(Config.upConfig().variableStart + 'people_select'); } /** * 选择了用户的form表单提交操作 * * @static * @param {any} that * @param {any} sFormName * @param {any} sMacroName */ static peopleFormSubmit(that, sFormName, sMacroName?) { //let oPeopleInfo = this.peopleInfoUp(); let cUrlInfo = PlusOperatePage.upUrlInfo(undefined, that); let sLeaderKey = ''; if (cUrlInfo.baseLeader != undefined) { sLeaderKey = cUrlInfo.baseLeader; } else { sLeaderKey = this.peopleInfoKey(); } this._formSubmit(that, sFormName, { leaderKey: sLeaderKey, noticeListName: sMacroName }); } static peopleFlatList(sFormCode) { //let oPeopleInfo = this.peopleInfoUp(); let datas = PlusOperateData.formData.upFormData(sFormCode, { filter: 'leaderCode="' + this.peopleInfoKey() + '"' }); return datas; } static childFormLink(that, sReportPageName, sFormName, sFieldName, sPageFieldValue?) { let sItemName = PlusOperateForm.upItemName(sFormName, sFieldName); if (sPageFieldValue == undefined) { sPageFieldValue = PlusOperateForm.upFormFieldExtendPage(sItemName); } let sPageUrl = sReportPageName + (sReportPageName.indexOf('?') > -1 ? '&' : '?') + 'base_field=' + sItemName + (sPageFieldValue ? '&base_type=edit&base_key=' + sPageFieldValue : ''); top_support.pageNav(sPageUrl, that); } /** * 子页面的提交操作 * * @static * @param {any} that * @param {any} sFormName */ static childFormSubmit(that, sFormName) { let oUrlInfo = PlusOperatePage.upUrlInfo(undefined, that); let oFormInfo = PlusOperateForm.upFormInfo(sFormName); if (oUrlInfo.baseField) { PlusCommonEvent.noticeDisplayRefresh(oUrlInfo.baseField, { eventValue: oFormInfo.baseKey, eventObject: oFormInfo }); } this.peopleFormSubmit(that, sFormName); } static oneLinkKey(sType, sFormName) { let sKey = 'key'; if (sType === "user") { sKey = this.userLoginInfo().userCode; } else if (sType === "people") { sKey = this.peopleInfoKey(); } return Config.upConfig().oneKeyStart + sType + '_' + sFormName + '_' + sKey; } /** * 页面跳转链接 * * @static * @param {any} that * @param {any} sReportPageName * @param {any} sFormName * @param {any} sFieldName */ static reportPressLink(that, sReportPageName, sFormName, sFieldName) { let sItemName = PlusOperateForm.upItemName(sFormName, sFieldName); let sPageFieldValue = PlusOperateForm.upFormFieldExtendPage(sItemName); top_support.pageNav(sReportPageName + '?base_field=' + sItemName + (sPageFieldValue ? '&base_type=edit&base_key=' + sPageFieldValue : ''), that); } static upCodeVersion() { return Config.upConfig().codeVersionName; } }