254 lines
11 KiB
JavaScript
254 lines
11 KiB
JavaScript
(function (factory) {
|
||
var nameSpace = 'field_88661234567890123457';
|
||
if (!window[nameSpace]) {
|
||
var Builder = factory();
|
||
window[nameSpace] = { instance: {} };
|
||
window[nameSpace].init = function (options) {
|
||
window[nameSpace].instance[options.privateId] = new Builder(options);
|
||
};
|
||
}
|
||
})(function () {
|
||
function App(options) {
|
||
var self = this;
|
||
self.adaptation = options.adaptation;
|
||
self.privateId = options.privateId;
|
||
self.preUrl = options.url_prefix;
|
||
self.adaptation.formMessage = options.formMessage;
|
||
self.messageObj = options.getData;
|
||
self.folderId = ''; // 网盘文件夹ID,从弹框返回时更新
|
||
self.initDom();
|
||
self.events();
|
||
}
|
||
App.prototype = {
|
||
initDom: function () {
|
||
var self = this;
|
||
self.appendChildDom();
|
||
},
|
||
|
||
events: function () {
|
||
var self = this;
|
||
self.adaptation.ObserverEvent.listen('Event' + self.privateId, function () {
|
||
self.messageObj = self.adaptation.childrenGetData(self.privateId);
|
||
self.appendChildDom();
|
||
});
|
||
},
|
||
|
||
appendChildDom: function () {
|
||
var self = this;
|
||
const params = new URLSearchParams(window.location.search);
|
||
console.log(params)
|
||
const openFrom = params.get('openFrom'); // 返回"2025"
|
||
const type = params.get('type');
|
||
console.log(openFrom)
|
||
console.log(type)
|
||
var edit = !((openFrom != null && (openFrom =='listPending' || openFrom =='listDone' || openFrom =='listSent'))||(type != null && type =='browse'));
|
||
console.log(edit)
|
||
var domStructure = '<section class="cap4-attach is-one">' +
|
||
'<div class="cap4-attach__left field-title" style="width: 70px;">'+
|
||
'<div class="cap4-attach__label" style="text-align: right;">'+
|
||
'<span class="label-margin" style="font-family: "Microsoft YaHei"; font-size: 14px; font-weight: normal; font-style: normal; text-decoration: none; text-align: right; color: rgb(51, 51, 51); background: transparent;">'
|
||
+ self.messageObj.display.escapeHTML()
|
||
+ '</span></div></div>'
|
||
+ '<div class="cap4-attach__right field-content-wrapper" style="margin-left: 77px;">'
|
||
+'<div class="cap4-attach__cnt field-content" style="border: 1px solid rgb(212, 212, 212); width: 100%;">'
|
||
+'<div class="cap4-attach__items ' + self.privateId + '"></div>'
|
||
+ (edit ? '<div class="cap4-attach__picker ' + self.privateId + '"><div class="icon CAP cap-icon-fujian" style="height: 100%;"></div></idv>' : '')
|
||
+ '</div>'
|
||
+ '</section>';
|
||
document.querySelector('#' + self.privateId).innerHTML = domStructure;
|
||
var fileRef = function() {
|
||
self.redirectToNewPage(self.privateId, self.messageObj, self.adaptation)
|
||
}
|
||
var attachArea = document.querySelector('.cap4-attach__items' + '.' + self.privateId);
|
||
attachArea.innerHTML = "";
|
||
if (self.messageObj.value) {
|
||
console.log(self.messageObj.value)
|
||
var values = JSON.parse(self.messageObj.value);
|
||
var outFileDiv = document.createElement('div');
|
||
attachArea.appendChild(outFileDiv);
|
||
values.forEach(function(item) {
|
||
// 创建一个新的 div 来包含超链接和文件名
|
||
var fileDiv = document.createElement('div');
|
||
fileDiv.className = "cap4-attach__att1 not-custome-btn";
|
||
// 创建超链接元素
|
||
var fileRightDiv = document.createElement('div');
|
||
fileRightDiv.className = "cap4-attach__att";
|
||
var innerArea = '<div class="cap4-attach__aleft"><i class="icon iconfont emptyfile" style="color: rgb(127, 142, 180);"></i></div>'
|
||
+'<div class="cap4-attach__aright" style="border: 0px solid rgb(212, 212, 212);">'
|
||
+'<span style="color: rgb(255, 65, 65);"></span>'
|
||
+ '<span class="goToNewPage" style="word-break: break-all;" data-href="'+ item.previewUrl + '">'+item.name+'</span>'+ (edit ? '<em class="ico16 affix_del_16 '+ self.privateId+'"></em>' : '')
|
||
+'</div>'
|
||
fileRightDiv.innerHTML = innerArea;
|
||
fileDiv.appendChild(fileRightDiv);
|
||
outFileDiv.appendChild(fileDiv);
|
||
|
||
});
|
||
}
|
||
|
||
var content = self.messageObj.formdata.content;
|
||
const picker = document.querySelector('.cap4-attach__picker' + '.' + self.privateId);
|
||
if(picker) {
|
||
document.querySelector('.cap4-attach__picker' + '.' + self.privateId).removeEventListener(
|
||
'click', fileRef);
|
||
document.querySelector('.cap4-attach__picker' + '.' + self.privateId).addEventListener(
|
||
'click', fileRef);
|
||
}
|
||
const goNewPages = document.querySelectorAll('.goToNewPage');
|
||
if(goNewPages.length > 0){
|
||
goNewPages.forEach(element => {
|
||
element.addEventListener('click', function(e) {
|
||
console.log(e.currentTarget.dataset.href)
|
||
window.open(e.currentTarget.dataset.href, '_blank'); //
|
||
});
|
||
});
|
||
}
|
||
const deleteList = document.querySelectorAll('.ico16.' + self.privateId);
|
||
if (deleteList.length > 0) {
|
||
deleteList.forEach(element => {
|
||
element.addEventListener('click', function (e) {
|
||
console.log("触发删除操作");
|
||
|
||
let current = e.target;
|
||
while (current && current !== document.documentElement) {
|
||
if (
|
||
current.classList.contains('cap4-attach__att1') &&
|
||
current.classList.contains('not-custome-btn')
|
||
) {
|
||
console.log("开始清除");
|
||
current.remove();
|
||
break;
|
||
}
|
||
current = current.parentElement;
|
||
}
|
||
});
|
||
});
|
||
}
|
||
//渲染隐藏权限
|
||
if (self.messageObj.auth === 'hide') {
|
||
document.querySelector('#' + self.privateId).innerHTML =
|
||
'<div class="cap4-text__browse" style="line-height: 1.8; color: rgb(0, 0, 0) !important;">***</div>';
|
||
}
|
||
},
|
||
|
||
/** 打开致远弹框 */
|
||
redirectToNewPage: function (privateId, messageObj, adaptation) {
|
||
var self = this;
|
||
// 拼接folderId参数到弹框URL
|
||
var tableName = messageObj.formdata.alldata.tableInfo.formmain.tableName
|
||
var targetObj = messageObj.formdata.formmains[adaptation.formMessage.tableName];
|
||
var oldValue = targetObj[privateId].showValue;
|
||
if (!targetObj) return;
|
||
var assetNo;
|
||
for (var key in targetObj) {
|
||
if (targetObj.hasOwnProperty(key) && !/^auxiliary/.test(key)) {
|
||
if (targetObj[key].display === "资产编号") {
|
||
assetNo = targetObj[key].showValue;
|
||
}
|
||
}
|
||
}
|
||
|
||
var dialogUrl = self.preUrl + '/html/fileUpload.html?bizId=' + assetNo;
|
||
var dialog = $.dialog({
|
||
id: 'fileRefDialog',
|
||
url: dialogUrl,
|
||
width: 1080,
|
||
height: 720,
|
||
title: '关联附件',
|
||
type: 'panel',
|
||
checkMax: true,
|
||
transParams: { oldValue: oldValue},
|
||
closeParam: { show: false, autoClose: false, handler: function () {} },
|
||
buttons: [{
|
||
text: '确认',
|
||
handler: function () {
|
||
var result = dialog.getReturnValue();
|
||
console.log(result)
|
||
if (result) {
|
||
try {
|
||
var data = JSON.parse(result);
|
||
var selected = data.files || [];
|
||
|
||
if (selected.length > 0) {
|
||
// 合并到已有文件列表
|
||
|
||
messageObj = adaptation.childrenGetData(privateId);
|
||
saveFiles(selected, messageObj.id, messageObj.display, privateId,messageObj, adaptation,tableName);
|
||
}
|
||
} catch (e) {
|
||
console.error('解析返回值失败:', e);
|
||
}
|
||
}
|
||
dialog.close();
|
||
}
|
||
}, {
|
||
text: '取消',
|
||
handler: function () { dialog.close(); }
|
||
}]
|
||
});
|
||
},
|
||
|
||
|
||
};
|
||
/** 保存文件列表到表单 */
|
||
function saveFiles(files, fieldName, fieldDisplay, privateId, messageObj, adaptation,tableName) {
|
||
var self = this;
|
||
var param = new Object();
|
||
param.masterId = messageObj.formdata.content.contentDataId;
|
||
param.formId = messageObj.formdata.content.contentTemplateId;
|
||
param.fieldDisplay = fieldDisplay;
|
||
param.value = files;
|
||
param.isFile = 'true';
|
||
$.ajax({
|
||
type: "POST",
|
||
url: '/seeyon/rest/assetsRegion/formBackFill',
|
||
data: JSON.stringify(param),
|
||
dataType: "json",
|
||
contentType: 'application/json;charset=UTF-8',
|
||
success: function(res) {
|
||
// 后台解析数据后 将数据填写到表单中
|
||
if (res.code == 0) {
|
||
var backfill = {};
|
||
backfill.tableName = tableName;
|
||
// 回填主表
|
||
backfill.tableCategory = 'formmain';
|
||
// 后台组装的data数据
|
||
console.log(res.data)
|
||
backfill.updateData = res.data;
|
||
adaptation.backfillFormControlData(backfill, privateId);
|
||
} else {
|
||
// 报错
|
||
$.alert(res.message);
|
||
}
|
||
},
|
||
complete: function() {},
|
||
error: function(e) {
|
||
top.$.error(e.responseText);
|
||
}
|
||
});
|
||
}
|
||
var dynamicLoading = {
|
||
css: function(path) {
|
||
if (!path || path.length === 0) {
|
||
throw new Error('argument "path" is required !');
|
||
}
|
||
var head = document.getElementsByTagName('head')[0];
|
||
var link = document.createElement('link');
|
||
link.href = path;
|
||
link.rel = 'stylesheet';
|
||
link.type = 'text/css';
|
||
head.appendChild(link);
|
||
},
|
||
js: function(path) {
|
||
if (!path || path.length === 0) {
|
||
throw new Error('argument "path" is required !');
|
||
}
|
||
var head = document.getElementsByTagName('head')[0];
|
||
var script = document.createElement('script');
|
||
script.src = path;
|
||
script.type = 'text/javascript';
|
||
head.appendChild(script);
|
||
}
|
||
}
|
||
return App;
|
||
});
|