|
@@ -12,21 +12,30 @@ function _page () {
|
|
|
return mjs.$this;
|
|
return mjs.$this;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-function _textValue (compId) {
|
|
|
|
|
- if (!compId) return "";
|
|
|
|
|
- const comp = _page().$(compId);
|
|
|
|
|
- if (!comp || typeof comp.getValue !== "function") return "";
|
|
|
|
|
- const value = comp.getValue();
|
|
|
|
|
|
|
+function _scalarValue (value) {
|
|
|
if (Array.isArray(value)) {
|
|
if (Array.isArray(value)) {
|
|
|
- const first = value[0];
|
|
|
|
|
- return first && (first.value || first.label || first.name) || "";
|
|
|
|
|
|
|
+ return _scalarValue(value[0]);
|
|
|
}
|
|
}
|
|
|
if (value && typeof value === "object") {
|
|
if (value && typeof value === "object") {
|
|
|
- return value.value || value.label || value.name || "";
|
|
|
|
|
|
|
+ return value.value || value.label || value.name || value.zh_CN || value.en_US || "";
|
|
|
}
|
|
}
|
|
|
return String(value || "");
|
|
return String(value || "");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+function _textValue (compId, page = _page()) {
|
|
|
|
|
+ if (!compId) return "";
|
|
|
|
|
+ const comp = page && page.$(compId);
|
|
|
|
|
+ if (comp && typeof comp.getValue === "function") {
|
|
|
|
|
+ try {
|
|
|
|
|
+ const value = _scalarValue(comp.getValue());
|
|
|
|
|
+ if (_hasValue(value)) return value;
|
|
|
|
|
+ } catch (error) {
|
|
|
|
|
+ console.warn("读取页面组件值失败:", compId, error);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return "";
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
function _hasValue (value) {
|
|
function _hasValue (value) {
|
|
|
if (Array.isArray(value)) return value.length > 0;
|
|
if (Array.isArray(value)) return value.length > 0;
|
|
|
return value !== null && value !== undefined && String(value).trim() !== "";
|
|
return value !== null && value !== undefined && String(value).trim() !== "";
|
|
@@ -66,44 +75,18 @@ async function _postRaw (url, params = {}, body = {}) {
|
|
|
return response && response.data;
|
|
return response && response.data;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-/**
|
|
|
|
|
- * 调用宜搭图片生成接口并保留 ApiResponse 外层结构。
|
|
|
|
|
- * 该接口返回 success/message/data,不使用合同确认接口的 code/data 结构。
|
|
|
|
|
- * @param {string} url 请求地址
|
|
|
|
|
- * @param {Object} body 请求参数
|
|
|
|
|
- * @returns {Promise<Object>} 宜搭图片生成响应
|
|
|
|
|
- */
|
|
|
|
|
-async function _postYidaEnvelope (url, body = {}) {
|
|
|
|
|
- const response = await mjs.request.xhr.doPost(url, {}, body, {
|
|
|
|
|
- ..._requestConfig(),
|
|
|
|
|
- ignoreResponse: true,
|
|
|
|
|
- });
|
|
|
|
|
- const result = response && response.data;
|
|
|
|
|
- if (!result || result.success !== true) {
|
|
|
|
|
- throw new Error(result && (result.message || result.msg) || "合同生成接口调用失败");
|
|
|
|
|
- }
|
|
|
|
|
- return result;
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
function _componentValue (componentId) {
|
|
function _componentValue (componentId) {
|
|
|
if (!componentId) return "";
|
|
if (!componentId) return "";
|
|
|
const component = _page().$(componentId);
|
|
const component = _page().$(componentId);
|
|
|
return component && typeof component.getValue === "function" ? component.getValue() : "";
|
|
return component && typeof component.getValue === "function" ? component.getValue() : "";
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-function _safeSetValue (componentId, value) {
|
|
|
|
|
- if (!componentId) return;
|
|
|
|
|
- const component = _page().$(componentId);
|
|
|
|
|
- if (component && typeof component.setValue === "function") component.setValue(value);
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
function _contractState (page) {
|
|
function _contractState (page) {
|
|
|
if (!page.__mankalongContractState) {
|
|
if (!page.__mankalongContractState) {
|
|
|
page.__mankalongContractState = {
|
|
page.__mankalongContractState = {
|
|
|
generated: false,
|
|
generated: false,
|
|
|
generating: false,
|
|
generating: false,
|
|
|
confirming: false,
|
|
confirming: false,
|
|
|
- resetTimer: null,
|
|
|
|
|
};
|
|
};
|
|
|
}
|
|
}
|
|
|
return page.__mankalongContractState;
|
|
return page.__mankalongContractState;
|
|
@@ -112,7 +95,16 @@ function _contractState (page) {
|
|
|
function _setButtonBehavior (page, componentId, behavior) {
|
|
function _setButtonBehavior (page, componentId, behavior) {
|
|
|
if (!componentId) return;
|
|
if (!componentId) return;
|
|
|
const button = page.$(componentId);
|
|
const button = page.$(componentId);
|
|
|
- if (button && typeof button.setBehavior === "function") button.setBehavior(behavior);
|
|
|
|
|
|
|
+ if (button && typeof button.set === "function") button.set("behavior", behavior);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+function _contractPage (options = {}) {
|
|
|
|
|
+ // ppExt: page 及 mjs.$this 仅兼容已发布旧页面;新增宜搭调用必须显式传 options.$this。
|
|
|
|
|
+ const page = options.$this || options.page || _page();
|
|
|
|
|
+ if (!page || typeof page.$ !== "function") {
|
|
|
|
|
+ throw new Error("宜搭页面 $this 未传入");
|
|
|
|
|
+ }
|
|
|
|
|
+ return page;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function _normalizeError (error, fallback) {
|
|
function _normalizeError (error, fallback) {
|
|
@@ -161,10 +153,34 @@ export default {
|
|
|
* 把已生成文件同步到 OSS。
|
|
* 把已生成文件同步到 OSS。
|
|
|
* @param {string} fileUrl 文件地址
|
|
* @param {string} fileUrl 文件地址
|
|
|
* @param {string} subDirectory contract 下的二级目录
|
|
* @param {string} subDirectory contract 下的二级目录
|
|
|
|
|
+ * @param {string} contractName 合同名称
|
|
|
|
|
+ * @param {string} contractNumber 合同编号
|
|
|
* @returns {Promise<Array>} 宜搭附件数组
|
|
* @returns {Promise<Array>} 宜搭附件数组
|
|
|
*/
|
|
*/
|
|
|
- async syncContractToOss (fileUrl, subDirectory) {
|
|
|
|
|
- return _post("/contract/confirm", { fileUrl, subDirectory });
|
|
|
|
|
|
|
+ async syncContractToOss (fileUrl, subDirectory, contractName, contractNumber) {
|
|
|
|
|
+ return _post("/contract/confirm", { fileUrl, subDirectory, contractName, contractNumber });
|
|
|
|
|
+ },
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 读取合同业务唯一标识。合同确认链路必须直接从页面组件读取。
|
|
|
|
|
+ * @param {string} componentId 唯一标识组件 ID
|
|
|
|
|
+ * @returns {string} 合同业务唯一标识
|
|
|
|
|
+ */
|
|
|
|
|
+ getContractUniqueId (componentId) {
|
|
|
|
|
+ if (!componentId) throw new Error("合同唯一标识组件 ID 未配置");
|
|
|
|
|
+ const page = _page();
|
|
|
|
|
+ const component = page && page.$(componentId);
|
|
|
|
|
+ if (!component || typeof component.getValue !== "function") {
|
|
|
|
|
+ throw new Error(`合同唯一标识组件不存在: ${componentId}`);
|
|
|
|
|
+ }
|
|
|
|
|
+ let value;
|
|
|
|
|
+ try {
|
|
|
|
|
+ value = _scalarValue(component.getValue());
|
|
|
|
|
+ } catch (error) {
|
|
|
|
|
+ throw new Error(`读取合同唯一标识失败: ${componentId}`);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!_hasValue(value)) throw new Error("合同唯一标识不能为空");
|
|
|
|
|
+ return value;
|
|
|
},
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -207,16 +223,16 @@ export default {
|
|
|
mappings: Array.isArray(options.mappings) ? options.mappings : [],
|
|
mappings: Array.isArray(options.mappings) ? options.mappings : [],
|
|
|
formData,
|
|
formData,
|
|
|
type,
|
|
type,
|
|
|
- unique: _componentValue(ids.uniqueId),
|
|
|
|
|
|
|
+ unique: options.uniqueId || this.getContractUniqueId(ids.uniqueId),
|
|
|
instanceId: options.instanceId || "",
|
|
instanceId: options.instanceId || "",
|
|
|
dingOrgId: options.dingOrgId || "",
|
|
dingOrgId: options.dingOrgId || "",
|
|
|
dingUid: options.dingUid || page.utils.getLoginUserId(),
|
|
dingUid: options.dingUid || page.utils.getLoginUserId(),
|
|
|
corpId: options.corpId || "",
|
|
corpId: options.corpId || "",
|
|
|
};
|
|
};
|
|
|
- const result = await _postYidaEnvelope("/api/yida/subform-to-image", body);
|
|
|
|
|
|
|
+ const result = await _post("/api/yida/subform-to-image", body);
|
|
|
const fileUrl = result && (result.message || result.downloadUrl || result.fileUrl || result.url);
|
|
const fileUrl = result && (result.message || result.downloadUrl || result.fileUrl || result.url);
|
|
|
if (fileUrl && ids.previewFrame) _page().$(ids.previewFrame).set("src", fileUrl);
|
|
if (fileUrl && ids.previewFrame) _page().$(ids.previewFrame).set("src", fileUrl);
|
|
|
- if (fileUrl && ids.previewSection) _page().$(ids.previewSection).setBehavior("NORMAL");
|
|
|
|
|
|
|
+ if (fileUrl && ids.previewSection) _setButtonBehavior(_page(), ids.previewSection, "NORMAL");
|
|
|
return fileUrl || null;
|
|
return fileUrl || null;
|
|
|
},
|
|
},
|
|
|
|
|
|
|
@@ -352,83 +368,70 @@ export default {
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 初始化曼卡龙合同页面状态。
|
|
* 初始化曼卡龙合同页面状态。
|
|
|
- * 提交页延迟清空复制流程可能带入的合同编号和合同正文,确认按钮默认禁用。
|
|
|
|
|
|
|
+ * 初始化合同按钮状态;提交页字段清空由页面原有初始化逻辑处理。
|
|
|
* @param {Object} options 页面组件 ID
|
|
* @param {Object} options 页面组件 ID
|
|
|
* @returns {Object} 当前页面合同状态
|
|
* @returns {Object} 当前页面合同状态
|
|
|
*/
|
|
*/
|
|
|
initContractPage (options = {}) {
|
|
initContractPage (options = {}) {
|
|
|
- const page = _page();
|
|
|
|
|
|
|
+ const page = _contractPage(options);
|
|
|
const ids = options.componentIds || {};
|
|
const ids = options.componentIds || {};
|
|
|
const state = _contractState(page);
|
|
const state = _contractState(page);
|
|
|
state.generated = false;
|
|
state.generated = false;
|
|
|
state.generating = false;
|
|
state.generating = false;
|
|
|
state.confirming = false;
|
|
state.confirming = false;
|
|
|
- if (state.resetTimer) clearTimeout(state.resetTimer);
|
|
|
|
|
- state.resetTimer = null;
|
|
|
|
|
|
|
|
|
|
_setButtonBehavior(page, ids.generateButton, "NORMAL");
|
|
_setButtonBehavior(page, ids.generateButton, "NORMAL");
|
|
|
_setButtonBehavior(page, ids.confirmButton, "DISABLED");
|
|
_setButtonBehavior(page, ids.confirmButton, "DISABLED");
|
|
|
|
|
+ return state;
|
|
|
|
|
+ },
|
|
|
|
|
|
|
|
- if (typeof mjs !== "undefined" && String(mjs.env) === "0") {
|
|
|
|
|
- state.resetTimer = setTimeout(() => {
|
|
|
|
|
- _safeSetValue(ids.contractNo, "");
|
|
|
|
|
- _safeSetValue(ids.attachment, []);
|
|
|
|
|
- state.generated = false;
|
|
|
|
|
- _setButtonBehavior(page, ids.confirmButton, "DISABLED");
|
|
|
|
|
- state.resetTimer = null;
|
|
|
|
|
- }, 800);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 标记页面原有合同生成流程已完成,仅更新确认按钮 UI 状态。
|
|
|
|
|
+ * @param {Object} options 页面组件 ID
|
|
|
|
|
+ * @returns {Object} 当前页面合同状态
|
|
|
|
|
+ */
|
|
|
|
|
+ markContractGenerated (options = {}) {
|
|
|
|
|
+ const page = _contractPage(options);
|
|
|
|
|
+ const state = _contractState(page);
|
|
|
|
|
+ state.generated = true;
|
|
|
|
|
+ _setButtonBehavior(page, options.componentIds && options.componentIds.confirmButton, "NORMAL");
|
|
|
return state;
|
|
return state;
|
|
|
},
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * 清理合同页面初始化定时器。
|
|
|
|
|
- * @returns {void}
|
|
|
|
|
|
|
+ * 开始页面原有合同生成流程,仅禁用生成按钮并记录进行中状态。
|
|
|
|
|
+ * @param {Object} options 页面组件 ID
|
|
|
|
|
+ * @returns {boolean} 是否允许开始生成
|
|
|
*/
|
|
*/
|
|
|
- disposeContractPage () {
|
|
|
|
|
- const page = _page();
|
|
|
|
|
- const state = page.__mankalongContractState;
|
|
|
|
|
- if (state && state.resetTimer) clearTimeout(state.resetTimer);
|
|
|
|
|
- if (state) state.resetTimer = null;
|
|
|
|
|
|
|
+ startContractGenerate (options = {}) {
|
|
|
|
|
+ const page = _contractPage(options);
|
|
|
|
|
+ const state = _contractState(page);
|
|
|
|
|
+ if (state.generating || state.confirming) return false;
|
|
|
|
|
+ state.generating = true;
|
|
|
|
|
+ _setButtonBehavior(page, options.componentIds && options.componentIds.generateButton, "DISABLED");
|
|
|
|
|
+ return true;
|
|
|
},
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * 合同生成按钮防抖:请求期间禁用生成和确认,成功后解锁确认。
|
|
|
|
|
- * @param {Object} options 生成参数
|
|
|
|
|
- * @returns {Promise<*>} 生成结果
|
|
|
|
|
|
|
+ * 结束页面原有合同生成流程,仅恢复生成按钮状态。
|
|
|
|
|
+ * @param {Object} options 页面组件 ID
|
|
|
|
|
+ * @returns {Object} 当前页面合同状态
|
|
|
*/
|
|
*/
|
|
|
- async runContractGenerate (options = {}) {
|
|
|
|
|
- const page = _page();
|
|
|
|
|
- const ids = options.componentIds || {};
|
|
|
|
|
|
|
+ finishContractGenerate (options = {}) {
|
|
|
|
|
+ const page = _contractPage(options);
|
|
|
const state = _contractState(page);
|
|
const state = _contractState(page);
|
|
|
- if (state.generating || state.confirming) return null;
|
|
|
|
|
- if (typeof options.generateContract !== "function") {
|
|
|
|
|
- throw new Error("必须传入合同生成回调");
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ state.generating = false;
|
|
|
|
|
+ _setButtonBehavior(page, options.componentIds && options.componentIds.generateButton, "NORMAL");
|
|
|
|
|
+ return state;
|
|
|
|
|
+ },
|
|
|
|
|
|
|
|
- state.generating = true;
|
|
|
|
|
- _setButtonBehavior(page, ids.generateButton, "DISABLED");
|
|
|
|
|
- _setButtonBehavior(page, ids.confirmButton, "DISABLED");
|
|
|
|
|
- try {
|
|
|
|
|
- const generated = await options.generateContract.call(page, options);
|
|
|
|
|
- const fileUrl = typeof generated === "string"
|
|
|
|
|
- ? generated
|
|
|
|
|
- : generated && (generated.downloadUrl || generated.fileUrl || generated.url);
|
|
|
|
|
- if (!fileUrl) throw new Error("合同生成接口未返回文件地址");
|
|
|
|
|
- state.generated = true;
|
|
|
|
|
- _setButtonBehavior(page, ids.confirmButton, "NORMAL");
|
|
|
|
|
- page.utils.toast({ type: "success", title: "合同生成成功,可进行合同确认" });
|
|
|
|
|
- return generated;
|
|
|
|
|
- } catch (error) {
|
|
|
|
|
- state.generated = false;
|
|
|
|
|
- _setButtonBehavior(page, ids.confirmButton, "DISABLED");
|
|
|
|
|
- const normalizedError = _normalizeError(error, "合同生成失败");
|
|
|
|
|
- page.utils.toast({ type: "error", title: normalizedError.message });
|
|
|
|
|
- throw normalizedError;
|
|
|
|
|
- } finally {
|
|
|
|
|
- state.generating = false;
|
|
|
|
|
- _setButtonBehavior(page, ids.generateButton, "NORMAL");
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 清理合同页面初始化定时器。
|
|
|
|
|
+ * @returns {void}
|
|
|
|
|
+ */
|
|
|
|
|
+ disposeContractPage (options = {}) {
|
|
|
|
|
+ const page = _contractPage(options);
|
|
|
|
|
+ delete page.__mankalongContractState;
|
|
|
},
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -437,7 +440,7 @@ export default {
|
|
|
* @returns {Promise<Object|null>} 合同确认结果
|
|
* @returns {Promise<Object|null>} 合同确认结果
|
|
|
*/
|
|
*/
|
|
|
async runContractConfirm (options = {}) {
|
|
async runContractConfirm (options = {}) {
|
|
|
- const page = _page();
|
|
|
|
|
|
|
+ const page = _contractPage(options);
|
|
|
const ids = options.componentIds || {};
|
|
const ids = options.componentIds || {};
|
|
|
const state = _contractState(page);
|
|
const state = _contractState(page);
|
|
|
if (state.generating || state.confirming) return null;
|
|
if (state.generating || state.confirming) return null;
|
|
@@ -457,40 +460,64 @@ export default {
|
|
|
* 合同确认完整流程:合同号 → 原合同生成回调 → OSS → 附件回写。
|
|
* 合同确认完整流程:合同号 → 原合同生成回调 → OSS → 附件回写。
|
|
|
* @param {Object} options 流程参数
|
|
* @param {Object} options 流程参数
|
|
|
* @param {Object} options.componentIds 页面组件 ID
|
|
* @param {Object} options.componentIds 页面组件 ID
|
|
|
- * @param {string} options.subDirectory OSS 二级目录
|
|
|
|
|
|
|
+ * OSS 二级目录使用页面传入的合同类型;未传时读取 componentIds.type(textField_mspzgras)
|
|
|
* @param {boolean} options.allowMissingInstanceId 预提交正式合成时允许暂缺流程实例 ID
|
|
* @param {boolean} options.allowMissingInstanceId 预提交正式合成时允许暂缺流程实例 ID
|
|
|
* @param {Function} options.generateContract 原合同生成回调,必须返回文件 URL 或包含 downloadUrl 的对象
|
|
* @param {Function} options.generateContract 原合同生成回调,必须返回文件 URL 或包含 downloadUrl 的对象
|
|
|
* @returns {Promise<Object>} 合同号及附件
|
|
* @returns {Promise<Object>} 合同号及附件
|
|
|
*/
|
|
*/
|
|
|
async confirmContract (options = {}) {
|
|
async confirmContract (options = {}) {
|
|
|
- const page = _page();
|
|
|
|
|
|
|
+ // fixme: MJS 方法内 this 指向模块对象;页面能力必须使用宜搭显式传入的 options.$this。
|
|
|
|
|
+ // ppExt: options.page 仅兼容已发布的旧页面调用,新代码统一传 $this。
|
|
|
|
|
+ const page = _contractPage(options);
|
|
|
const ids = options.componentIds || {};
|
|
const ids = options.componentIds || {};
|
|
|
- const closeLoading = page.utils.toast({
|
|
|
|
|
- type: "loading",
|
|
|
|
|
- title: "合同生成中",
|
|
|
|
|
- hasMask: true,
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ let closeLoading = null;
|
|
|
|
|
+ const stopLoading = () => {
|
|
|
|
|
+ if (typeof closeLoading === "function") {
|
|
|
|
|
+ closeLoading();
|
|
|
|
|
+ closeLoading = null;
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
try {
|
|
try {
|
|
|
- if (!ids.uniqueId || !ids.contractNo || !ids.mode || !ids.type || !ids.attachment) {
|
|
|
|
|
|
|
+ closeLoading = page.utils.toast({
|
|
|
|
|
+ type: "loading",
|
|
|
|
|
+ title: "合同确认中",
|
|
|
|
|
+ });
|
|
|
|
|
+ const configuredContractMode = String(options.contractMode || "").trim();
|
|
|
|
|
+ if (!ids.uniqueId || !ids.contractNo || (!configuredContractMode && !ids.mode) || !ids.type || !ids.attachment) {
|
|
|
throw new Error("合同确认组件 ID 配置不完整");
|
|
throw new Error("合同确认组件 ID 配置不完整");
|
|
|
}
|
|
}
|
|
|
if (typeof options.generateContract !== "function") {
|
|
if (typeof options.generateContract !== "function") {
|
|
|
throw new Error("必须传入 generateContract 回调");
|
|
throw new Error("必须传入 generateContract 回调");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- let contractNumber = _textValue(ids.contractNo);
|
|
|
|
|
- if (!contractNumber) {
|
|
|
|
|
|
|
+ // fixme: 设计器预览时 mjs.$this 可能不是当前按钮所在页面,优先使用页面直接读取后传入的合同类型。
|
|
|
|
|
+ const contractType = options.contractType || _textValue(ids.type, page);
|
|
|
|
|
+ if (!contractType) throw new Error("合同类型不能为空");
|
|
|
|
|
+ const subDirectory = contractType;
|
|
|
|
|
+ const contractName = _textValue(ids.name, page);
|
|
|
|
|
+ if (!contractName) throw new Error("合同名称不能为空");
|
|
|
|
|
+ // prd: 无主从合同组件的页面由调用方显式传入“主合同”,不伪造组件 ID。
|
|
|
|
|
+ const contractMode = configuredContractMode || _textValue(ids.mode, page);
|
|
|
|
|
+ if (!contractMode) throw new Error("合同主从类型不能为空");
|
|
|
|
|
+ let contractNumber = _textValue(ids.contractNo, page);
|
|
|
|
|
+ const isChildContract = contractMode === "子合同" || contractMode === "从合同";
|
|
|
|
|
+ // 子合同必须按当前唯一标识重新走分配逻辑,避免复制流程残留旧合同号时跳过后缀递增。
|
|
|
|
|
+ if (!contractNumber || isChildContract) {
|
|
|
const numberResult = await this.allocateContractNumber({
|
|
const numberResult = await this.allocateContractNumber({
|
|
|
- targetUniqueId: _textValue(ids.uniqueId),
|
|
|
|
|
- contractType: _textValue(ids.type),
|
|
|
|
|
- contractMode: _textValue(ids.mode),
|
|
|
|
|
- masterContractNumber: _textValue(ids.masterNo),
|
|
|
|
|
- contractName: _textValue(ids.name),
|
|
|
|
|
|
|
+ targetUniqueId: options.uniqueId || this.getContractUniqueId(ids.uniqueId),
|
|
|
|
|
+ contractType,
|
|
|
|
|
+ contractMode,
|
|
|
|
|
+ masterContractNumber: _textValue(ids.masterNo, page),
|
|
|
|
|
+ contractName,
|
|
|
yearMonth: options.yearMonth || "",
|
|
yearMonth: options.yearMonth || "",
|
|
|
});
|
|
});
|
|
|
contractNumber = numberResult && numberResult.contractNumber;
|
|
contractNumber = numberResult && numberResult.contractNumber;
|
|
|
if (!contractNumber) throw new Error("合同号接口未返回合同号");
|
|
if (!contractNumber) throw new Error("合同号接口未返回合同号");
|
|
|
- page.$(ids.contractNo).setValue(contractNumber);
|
|
|
|
|
|
|
+ const contractNoComp = page && page.$(ids.contractNo);
|
|
|
|
|
+ if (!contractNoComp || typeof contractNoComp.setValue !== "function") {
|
|
|
|
|
+ throw new Error("合同编号组件不存在或不支持赋值: " + ids.contractNo);
|
|
|
|
|
+ }
|
|
|
|
|
+ contractNoComp.setValue(contractNumber);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const generated = await options.generateContract.call(page, {
|
|
const generated = await options.generateContract.call(page, {
|
|
@@ -503,7 +530,7 @@ export default {
|
|
|
: generated && (generated.downloadUrl || generated.fileUrl || generated.url);
|
|
: generated && (generated.downloadUrl || generated.fileUrl || generated.url);
|
|
|
if (!fileUrl) throw new Error("原合同生成接口未返回文件地址");
|
|
if (!fileUrl) throw new Error("原合同生成接口未返回文件地址");
|
|
|
|
|
|
|
|
- const ossResult = await this.syncContractToOss(fileUrl, options.subDirectory);
|
|
|
|
|
|
|
+ const ossResult = await this.syncContractToOss(fileUrl, subDirectory, contractName, contractNumber);
|
|
|
const attachments = Array.isArray(ossResult)
|
|
const attachments = Array.isArray(ossResult)
|
|
|
? ossResult
|
|
? ossResult
|
|
|
: ossResult && Array.isArray(ossResult.data) ? ossResult.data : [];
|
|
: ossResult && Array.isArray(ossResult.data) ? ossResult.data : [];
|
|
@@ -513,38 +540,44 @@ export default {
|
|
|
throw new Error("合同附件组件不存在或不支持赋值");
|
|
throw new Error("合同附件组件不存在或不支持赋值");
|
|
|
}
|
|
}
|
|
|
attachmentComp.setValue(attachments);
|
|
attachmentComp.setValue(attachments);
|
|
|
|
|
+ stopLoading();
|
|
|
page.utils.toast({
|
|
page.utils.toast({
|
|
|
type: "success",
|
|
type: "success",
|
|
|
- title: "正式合同生成成功",
|
|
|
|
|
|
|
+ title: "合同确认成功",
|
|
|
|
|
+ duration: 3000,
|
|
|
});
|
|
});
|
|
|
return { contractNumber, attachments };
|
|
return { contractNumber, attachments };
|
|
|
} catch (error) {
|
|
} catch (error) {
|
|
|
const normalizedError = error instanceof Error
|
|
const normalizedError = error instanceof Error
|
|
|
? error
|
|
? error
|
|
|
: new Error(error && (error.message || error.msg) || String(error || "合同确认失败"));
|
|
: new Error(error && (error.message || error.msg) || String(error || "合同确认失败"));
|
|
|
|
|
+ stopLoading();
|
|
|
page.utils.toast({
|
|
page.utils.toast({
|
|
|
type: "error",
|
|
type: "error",
|
|
|
- title: normalizedError.message,
|
|
|
|
|
|
|
+ title: normalizedError.message || "合同确认失败",
|
|
|
|
|
+ duration: 5000,
|
|
|
});
|
|
});
|
|
|
throw normalizedError;
|
|
throw normalizedError;
|
|
|
- } finally {
|
|
|
|
|
- if (typeof closeLoading === "function") closeLoading();
|
|
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 提交前校验合同号和合同附件是否已经生成。
|
|
* 提交前校验合同号和合同附件是否已经生成。
|
|
|
- * @param {Object} componentIds 页面组件 ID
|
|
|
|
|
|
|
+ * @param {Object} options 页面实例与组件 ID;旧调用可直接传组件 ID
|
|
|
* @returns {boolean} 是否允许提交
|
|
* @returns {boolean} 是否允许提交
|
|
|
*/
|
|
*/
|
|
|
- beforeSubmitContract (componentIds = {}) {
|
|
|
|
|
- const number = _textValue(componentIds.contractNo);
|
|
|
|
|
- const attachmentComp = componentIds.attachment && _page().$(componentIds.attachment);
|
|
|
|
|
|
|
+ beforeSubmitContract (options = {}) {
|
|
|
|
|
+ const page = options.$this || options.page
|
|
|
|
|
+ ? _contractPage(options)
|
|
|
|
|
+ : _page();
|
|
|
|
|
+ const componentIds = options.componentIds || options;
|
|
|
|
|
+ const number = _textValue(componentIds.contractNo, page);
|
|
|
|
|
+ const attachmentComp = componentIds.attachment && page.$(componentIds.attachment);
|
|
|
const attachment = attachmentComp && typeof attachmentComp.getValue === "function"
|
|
const attachment = attachmentComp && typeof attachmentComp.getValue === "function"
|
|
|
? attachmentComp.getValue()
|
|
? attachmentComp.getValue()
|
|
|
: null;
|
|
: null;
|
|
|
if (_hasValue(number) && _hasValue(attachment)) return true;
|
|
if (_hasValue(number) && _hasValue(attachment)) return true;
|
|
|
- _page().utils.dialog({
|
|
|
|
|
|
|
+ page.utils.dialog({
|
|
|
type: "alert",
|
|
type: "alert",
|
|
|
title: "提示",
|
|
title: "提示",
|
|
|
content: "合同还未正式生成,请操作!",
|
|
content: "合同还未正式生成,请操作!",
|