364 lines
15 KiB
JavaScript
364 lines
15 KiB
JavaScript
/* * 版 本 PIT-ADMS V7.0.3 敏捷开发框架
|
||
* Copyright (c) 2013-2018 Hexagon PPM
|
||
* 创建人:chenkai
|
||
* 日 期:2022-02-24
|
||
* 描 述:属性设置
|
||
*/
|
||
var refreshGirdData;
|
||
var PropertyGID = "";
|
||
var ObjectTypeID = request('ObjectTypeID');
|
||
var selectData = [];
|
||
var ProjectId = request('ProjectId');
|
||
var bootstrap = function ($, learun) {
|
||
"use strict";
|
||
var page = {
|
||
init: function () {
|
||
page.bind();
|
||
page.initGird();
|
||
},
|
||
bind: function () {
|
||
// 初始化左侧树形数据(属性组)
|
||
$('#dataTree').lrtree({
|
||
url: top.$.rootUrl + '/ZZDT_EC/ec_property/GetTree?ProjectId=' + ProjectId,
|
||
nodeClick: function (item) {
|
||
$("#titleinfo").html(item.text);
|
||
PropertyGID = item.value;
|
||
table.ajax.reload(); // 重新发起请求,加载新数据; /*选择左侧组后,相当于去触发这个搜索方法*/
|
||
}
|
||
});
|
||
|
||
////获取当前选中的数据()
|
||
//$.ajax({
|
||
// url: top.$.rootUrl + '/ZZDT_EC/ec_property/GetObjectTypePById',
|
||
// data: { objectTypeID: ObjectTypeID, ProjectId: ProjectId },
|
||
// async: false,
|
||
// type: "GET",
|
||
// dataType: "json",
|
||
// success: function (data) {
|
||
// if (data.code == 200 && data.data.length > 0)
|
||
// selectData = data.data;
|
||
// },
|
||
// error: function () {
|
||
// },
|
||
// complete: function (data) {
|
||
// }
|
||
//});
|
||
|
||
////查询
|
||
//$('#btn_Search').on('click', function () {
|
||
// page.search();
|
||
//});
|
||
// 刷新
|
||
$('#lr_refresh').on('click', function () {
|
||
location.reload();
|
||
});
|
||
// 保存
|
||
$('#lr_save').on('click', function () {
|
||
|
||
//var selectedRows = table.$('input.row-select:checked').closest('tr'); // 获取勾选的行
|
||
// 获取所有勾选的行
|
||
//var selectedRows = table.rows().data().toArray().filter(function (row) {
|
||
// return row.IsChecked === true; // 仅获取 isChecked 为 true 的行
|
||
//});
|
||
var selectedRows = table.rows().data().toArray(); // 获取所有行数据
|
||
|
||
//if (selectedRows.length > 0) {
|
||
console.log('需要的属性有 ' + selectedRows.length + ' 个');
|
||
// 构造 POST 请求的数据
|
||
var postData = selectedRows.map(function (row) {
|
||
return {
|
||
PropertyGID: PropertyGID,
|
||
PropertyID: row.PropertyID, // 这里根据你的数据模型,提取需要的字段
|
||
IsRequired: row.IsRequired,
|
||
IsChecked: row.IsChecked,
|
||
ObjectTypeID: ObjectTypeID
|
||
};
|
||
});
|
||
console.log('postData: ' + postData);
|
||
// 发起 AJAX POST 请求,提交数据
|
||
$.ajax({
|
||
url: top.$.rootUrl + '/ZZDT_EC/ec_property/SaveObjectTypeP?objectTypeID=' + ObjectTypeID + "&ProjectId=" + ProjectId, // 只保存是否必填,是否需要
|
||
method: 'POST',
|
||
contentType: 'application/json',
|
||
|
||
data: JSON.stringify(postData)
|
||
,
|
||
success: function (response) {
|
||
alert('保存成功!');
|
||
},
|
||
error: function (error) {
|
||
console.error('保存失败', error);
|
||
alert('保存失败,请重试!');
|
||
}
|
||
});
|
||
});
|
||
//联动
|
||
$('#lr_dependent_set').click(function () {
|
||
var selectedRowData = table.row('.selected').data();
|
||
|
||
// 判断是否有选中行
|
||
if (!selectedRowData) {
|
||
alert("请先选择一行!");
|
||
} else {
|
||
// 有选中行,执行其他操作
|
||
console.log(selectedRowData);
|
||
|
||
learun.layerForm({
|
||
id: 'PropertyDependentForm', // 唯一标识符,用于控制窗口
|
||
title: selectedRowData.PropertyName + ' 属性联动设置', // 弹出层标题
|
||
url: top.$.rootUrl + '/ZZDT_EC/ec_property/PropertyDependent?PropertyID=' + selectedRowData.PropertyID + "&ProjectId=" + ProjectId + "&ObjectTypeID=" + ObjectTypeID + "&IsRequired=" + selectedRowData.IsRequired + "&IsChecked=" + selectedRowData.IsChecked, // 弹出视图的路径
|
||
width: 600, // 弹出层宽度
|
||
height: 400, // 弹出层高度
|
||
callBack: function (id) {
|
||
return top[id].Save();//FORM里有一个Save函数
|
||
}
|
||
});
|
||
|
||
|
||
}
|
||
// 重新绘制表格以显示更改后的数据
|
||
table.rows().invalidate().draw();
|
||
});
|
||
|
||
$('#lr_propertyImport').on('click', function () {
|
||
//批量导入
|
||
var format = 'xlsx';
|
||
var uploadKeyValue = Guid.NewGuid().toString();
|
||
learun.layerForm({
|
||
id: 'importfile',
|
||
title: '对象类型 - 必填属性导入',
|
||
url: top.$.rootUrl + '/LR_SystemModule/Annexes/UploadForm?keyVaule=' + uploadKeyValue + "&multiple=false" + "&format=" + format,
|
||
width: 600,
|
||
height: 400,
|
||
maxmin: true,
|
||
btn: ['确认'],
|
||
callBack: function (id) {
|
||
learun.layerClose('importfile');
|
||
//MuliteImport(uploadKeyValue);
|
||
|
||
learun.loading(true, "批量导入数据中...");
|
||
$.ajax({
|
||
type: 'POST',
|
||
url: top.$.rootUrl + "/ZZDT_EC/ec_objecttype/ImportPropsIfNeed?rdo=" + Math.random(),
|
||
data: { fileId: fileId, ProjectId: ProjectId },
|
||
traditional: true,
|
||
success: function (data) {
|
||
var data = JSON.parse(data);
|
||
if (data.code == '200') {
|
||
location.reload();
|
||
}
|
||
learun.alert.success(data.info);
|
||
},
|
||
error: function (msg) {
|
||
learun.alert.error(msg);
|
||
}, complete: function (data) {
|
||
learun.loading(false);
|
||
}
|
||
});
|
||
|
||
}
|
||
});
|
||
|
||
});
|
||
//属性必填矩阵导出
|
||
$('#lr_propertyExport').on('click', function () {
|
||
|
||
learun.loading(true, "导出中...");
|
||
var iframeUrl = top.$.rootUrl + '/ZZDT_EC/ec_objecttype/ExportPropsIfNeed?ProjectId=' + ProjectId;
|
||
|
||
var body = document.getElementsByTagName("body")[0];
|
||
var downloadIframe = document.createElement("iframe");
|
||
downloadIframe.setAttribute("src", iframeUrl);
|
||
downloadIframe.setAttribute("style", "display:none;")
|
||
body.appendChild(downloadIframe);
|
||
learun.loading(false);
|
||
});
|
||
|
||
},
|
||
// 初始化列表
|
||
initGird: function () {
|
||
|
||
$('#PropertyName').css('width', '100px'); // 200px 是示例宽度
|
||
|
||
//$('#gridtable').jfGrid({
|
||
// url: top.$.rootUrl + '/ZZDT_EC/ec_property/GetPageList2',
|
||
// headData: [
|
||
// { label: "属性名称", name: "PropertyName", width: 400, align: "left", sort: false },
|
||
// { label: "是否必填", name: "IsRequired", width: 100, align: "left", sort: false, editType: 'input' },
|
||
// { name: "", width: 1, sort: false }
|
||
// ],
|
||
// mainId: 'PropertyID',
|
||
// isPage: true,
|
||
// isMultiselect: true, /*控制前面那个勾*/
|
||
// isEidt: true,
|
||
// onSelectRow: function (rowData, isSelect) {
|
||
// selectData = $.grep(selectData, function (item) {
|
||
// return item.PropertyID != rowData.PropertyID;
|
||
// });
|
||
// if (isSelect) {
|
||
// var param = {};
|
||
// param.ObjectTypePID = top.learun.newGuid();
|
||
// param.PropertyID = rowData.PropertyID;
|
||
// param.ObjectTypeID = ObjectTypeID;
|
||
// selectData.push(param);
|
||
// }
|
||
// },
|
||
// onRenderComplete: function (data) {
|
||
// //默认已经选中的
|
||
// for (var i = 0; i < data.length; i++) {
|
||
// if (selectData) {
|
||
// var gdata = $.grep(selectData, function (item) {
|
||
// return item.PropertyID == data[i].PropertyID
|
||
// });
|
||
// if (gdata && gdata.length > 0) {
|
||
// $('#gridtable').jfGridSet("selectRow", data[i].PropertyID);
|
||
// }
|
||
// }
|
||
// }
|
||
// }
|
||
//});
|
||
//page.search();
|
||
},
|
||
//search: function (param) {
|
||
// param = param || {};
|
||
// param.PropertyGID = PropertyGID;
|
||
// param.ObjectTypeID = ObjectTypeID;
|
||
// param.ProjectId = ProjectId;
|
||
// param.PropertyName = $("#PropertyName").val();
|
||
// $('#gridtable').jfGridSet('reload', { queryJson: JSON.stringify(param) });
|
||
//}
|
||
};
|
||
refreshGirdData = function () {
|
||
//$('#gridtable').jfGridSet('reload');
|
||
};
|
||
page.init();
|
||
|
||
|
||
var table = $('#example').DataTable({
|
||
paging: false, // 禁用分页
|
||
scrollY: '390px', // 设置表格的最大高度,超出部分将出现滚动条
|
||
scrollCollapse: true, // 当内容较少时,允许缩小表格高度
|
||
language: {
|
||
info: "" // 不显示任何信息
|
||
},
|
||
ajax: {
|
||
url: top.$.rootUrl + '/ZZDT_EC/ec_property/GetPageList2', // 替换为你的服务器端URL
|
||
method: 'GET',
|
||
data: function (d) {
|
||
// 将额外的参数传递到服务器请求中
|
||
return $.extend({}, d, {
|
||
ProjectId: ProjectId, // 假设你有一个用户ID的输入框
|
||
ObjectTypeID: ObjectTypeID, // 或者根据你的需求传递固定参数
|
||
PropertyGID: PropertyGID
|
||
});
|
||
},
|
||
dataSrc: function (json) {
|
||
// 提取data字段中的数据
|
||
return json.data;
|
||
}
|
||
},
|
||
columns: [
|
||
{
|
||
data: 'IsChecked',
|
||
render: function (data, type, row) {
|
||
// 根据 `isChecked` 字段的值来设置复选框的初始状态
|
||
return '<input type="checkbox" class="row-select" ' + (data ? 'checked' : '') + '>';
|
||
},
|
||
title: '是否绑定到对象',
|
||
orderable: false, // 复选框列不参与排序,
|
||
width: 100
|
||
},
|
||
{ data: 'PropertyName', title: '属性名' }, // 显示name字段
|
||
//{
|
||
// data: 'IsRequired', // 显示IsRequired字段
|
||
// render: function (data, type, row) {
|
||
// return data ? '是' : '否'; // 将布尔值转换为'Yes'或'No'
|
||
// },
|
||
// title: '是否必填(1或0)'
|
||
//},
|
||
{
|
||
data: 'IsRequired',
|
||
render: function (data, type, row) {
|
||
// 渲染为固定的下拉列表
|
||
return `
|
||
<select class="is-required-select">
|
||
<option value="-1" ${data == -1 ? 'selected' : ''}>无需检查</option>
|
||
<option value="1" ${data == 1 ? 'selected' : ''}>即时更新版</option>
|
||
<option value="2" ${data == 2 ? 'selected' : ''}>送审图</option>
|
||
<option value="3" ${data == 3 ? 'selected' : ''}>清洁版</option>
|
||
<option value="4" ${data == 4 ? 'selected' : ''}>施工图</option>
|
||
<option value="5" ${data == 5 ? 'selected' : ''}>完工图</option>
|
||
</select>
|
||
`;
|
||
},
|
||
title: '是否必填',
|
||
orderable: false // 禁止排序
|
||
},
|
||
{ data: 'PropertyID', visible: false } // 不显示propertyId,但用于主键
|
||
]
|
||
});
|
||
|
||
//查询
|
||
$('#btn_Search').on('click', function () {
|
||
table.search($("#PropertyName").val()).draw();
|
||
});
|
||
|
||
// 点击行时高亮选中
|
||
$('#example tbody').on('click', 'tr', function (event) {
|
||
if (!$(event.target).is('input')) { // 如果点击的不是复选框
|
||
$(this).toggleClass('selected').siblings().removeClass('selected'); // 选中行
|
||
}
|
||
});
|
||
|
||
// 切换是否 必填
|
||
//$('#modifyRow').click(function () {
|
||
// var selectedRows = table.rows('.selected').data();
|
||
|
||
// // 遍历选中的行,修改 IsRequired 值
|
||
// selectedRows.each(function (rowData, index) {
|
||
// // 切换 IsRequired 值:如果是 1 切换为 0,反之亦然
|
||
// console.log('选中行 ' + rowData.IsChecked + ' ' + rowData.IsRequired)
|
||
// //rowData.IsRequired = rowData.IsRequired ? 0 : 1;
|
||
|
||
// // 可选:你也可以在这里发送 AJAX 请求,通知服务器更新数据
|
||
// // $.ajax({
|
||
// // url: 'https://your-server-endpoint.com/api/update',
|
||
// // method: 'POST',
|
||
// // data: { id: rowData.propertyId, IsRequired: rowData.IsRequired },
|
||
// // success: function(response) {
|
||
// // console.log('Update successful', response);
|
||
// // }
|
||
// // });
|
||
// });
|
||
|
||
// // 重新绘制表格以显示更改后的数据
|
||
// table.rows().invalidate().draw();
|
||
//});
|
||
|
||
// 当复选框状态发生变化时,更新 `isChecked` 值,即该属性是否关联到该对象类型
|
||
table.on('change', 'input.row-select', function () {
|
||
var row = $(this).closest('tr');
|
||
var rowData = table.row(row).data();
|
||
console.log('isChecked 改动');
|
||
// 根据复选框状态更新 `isChecked` 值
|
||
rowData.IsChecked = $(this).prop('checked');
|
||
|
||
|
||
});
|
||
|
||
// 监听下拉列表的变化
|
||
table.on('change', 'select.is-required-select', function () {
|
||
var row = $(this).closest('tr'); // 获取当前行
|
||
var rowData = table.row(row).data(); // 获取当前行的数据
|
||
console.log('isRequired 改动');
|
||
// 更新 IsRequired 的值为下拉列表选中的值
|
||
rowData.IsRequired = $(this).val();
|
||
|
||
console.log('更新后的 IsRequired 值为:', rowData.IsRequired);
|
||
});
|
||
|
||
}
|
||
|
||
|
||
|