(function (vc) {
|
var DEFAULT_PAGE = 1;
|
var DEFAULT_ROWS = 10;
|
vc.extends({
|
data: {
|
advertisementSummaryInfo: {
|
contracts: [],
|
total: 0,
|
records: 0,
|
moreCondition: false,
|
conditions: {
|
contractNameLike: '',
|
contractCode: '',
|
contractType: '',
|
state: ''
|
},
|
contractTypes: [],
|
importExcelFile: ''
|
},
|
// 广告合同信息管理相关数据
|
adContractInfo: {
|
dataList: [],
|
conditions: {
|
mpId: '',
|
id: '',
|
contractId: '',
|
adType: '',
|
subType: '',
|
cooperationForm: '',
|
buildingElevatorCount: '',
|
onlineQuantity: '',
|
facilityLocation: ''
|
},
|
page: 1,
|
row: 10,
|
total: 0,
|
formData: {
|
id: '',
|
contractId: '',
|
adType: '',
|
subType: '',
|
cooperationForm: '',
|
buildingElevatorCount: '',
|
onlineQuantity: '',
|
facilityLocation: ''
|
},
|
isEdit: false,
|
statistics: {
|
totalCount: 0,
|
adTypeCount: {},
|
subTypeCount: {}
|
}
|
},
|
// 广告类型枚举
|
AD_TYPES: {
|
'电梯广告': {
|
subTypes: ['电梯广告-联讯', '电梯广告-业委会'],
|
description: '电梯内广告'
|
},
|
'租房': {
|
subTypes: ['租房-租赁', '租房-水电'],
|
description: '房屋租赁相关广告'
|
},
|
'快递柜': {
|
subTypes: [],
|
description: '快递柜广告'
|
},
|
'场地代收电费': {
|
subTypes: [],
|
description: '场地电费代收服务广告'
|
},
|
'充电桩代收电费': {
|
subTypes: [],
|
description: '充电桩电费代收服务广告'
|
},
|
'场地使用机房基站': {
|
subTypes: [],
|
description: '场地使用机房基站相关广告'
|
},
|
'净水自贩机': {
|
subTypes: [],
|
description: '净水自动贩卖机广告'
|
},
|
'机房基站': {
|
subTypes: [],
|
description: '机房基站相关广告'
|
},
|
'其他广告': {
|
subTypes: ['车辆识别系统', '智能柜', '代收电费', '机房基站-电费', '充电站(桩)', '信号接入', '充电桩代收电费-变更', '自助饮料机', '回收柜', '车辆系统', '监控设备', '换电柜', '自助贩卖机', '门禁系统', '新能源充电桩'],
|
description: '其他类型广告'
|
}
|
}
|
},
|
_initMethod: function () {
|
vc.component._listContracts(DEFAULT_PAGE, DEFAULT_ROWS);
|
vc.component._listContractTypes();
|
},
|
_initEvent: function () {
|
vc.on('advertisementSummary', 'listContract', function (_param) {
|
vc.component._listContracts(DEFAULT_PAGE, DEFAULT_ROWS);
|
});
|
vc.on('pagination', 'page_event', function (_currentPage) {
|
vc.component._listContracts(_currentPage, DEFAULT_ROWS);
|
});
|
},
|
methods: {
|
_listContracts: function (_page, _rows) {
|
try {
|
if (!vc.component || !vc.component.advertisementSummaryInfo) {
|
return;
|
}
|
vc.component.advertisementSummaryInfo.conditions.page = _page;
|
vc.component.advertisementSummaryInfo.conditions.row = _rows;
|
var param = {
|
params: vc.component.advertisementSummaryInfo.conditions
|
};
|
param.params.contractNameLike = param.params.contractNameLike.trim();
|
param.params.contractCode = param.params.contractCode.trim();
|
//发送get请求
|
vc.http.apiGet('/contract/queryContract',
|
param,
|
function (json, res) {
|
try {
|
if (!vc.component || !vc.component.advertisementSummaryInfo) {
|
return;
|
}
|
var _advertisementSummaryInfo = JSON.parse(json);
|
vc.component.advertisementSummaryInfo.total = _advertisementSummaryInfo.total;
|
vc.component.advertisementSummaryInfo.records = _advertisementSummaryInfo.records;
|
vc.component.advertisementSummaryInfo.contracts = _advertisementSummaryInfo.data;
|
vc.emit('pagination', 'init', {
|
total: vc.component.advertisementSummaryInfo.records,
|
dataCount: vc.component.advertisementSummaryInfo.total,
|
currentPage: _page
|
});
|
} catch (e) {
|
console.error('处理合同数据失败:', e);
|
}
|
},
|
function (errInfo, error) {
|
console.log('请求失败处理:', errInfo, error);
|
}
|
);
|
} catch (e) {
|
console.error('执行合同查询失败:', e);
|
}
|
},
|
_listContractTypes: function () {
|
let param = {
|
params: {
|
page: 1,
|
row: 50
|
}
|
};
|
//发送get请求
|
vc.http.apiGet('/contract/queryContractType',
|
param,
|
function (json, res) {
|
try {
|
let _contractTypeManageInfo = JSON.parse(json);
|
if (vc.component && vc.component.advertisementSummaryInfo) {
|
vc.component.advertisementSummaryInfo.contractTypes = _contractTypeManageInfo.data;
|
}
|
} catch (e) {
|
console.error('处理合同类型数据失败:', e);
|
}
|
},
|
function (errInfo, error) {
|
console.log('请求失败处理:', errInfo, error);
|
}
|
);
|
},
|
_openAddContractModal: function () {
|
vc.jumpToPage('/#/pages/admin/addContract')
|
},
|
_openEditContractModel: function (_contract) {
|
// 跳转到合同详情页面
|
vc.jumpToPage('/#/pages/admin/contractDetailView?contractId=' + _contract.contractId);
|
},
|
_openDeleteContractModel: function (_contract) {
|
// 跳转到合同管理页面进行删除操作
|
vc.jumpToPage('/#/pages/admin/contractManage/contractManage');
|
},
|
//查询
|
_queryContractMethod: function () {
|
vc.component._listContracts(DEFAULT_PAGE, DEFAULT_ROWS);
|
},
|
//重置
|
_resetContractMethod: function () {
|
vc.component.advertisementSummaryInfo.conditions.contractNameLike = "";
|
vc.component.advertisementSummaryInfo.conditions.contractCode = "";
|
vc.component.advertisementSummaryInfo.conditions.contractType = "";
|
vc.component.advertisementSummaryInfo.conditions.state = "";
|
vc.component._listContracts(DEFAULT_PAGE, DEFAULT_ROWS);
|
},
|
_moreCondition: function () {
|
if (vc.component.advertisementSummaryInfo.moreCondition) {
|
vc.component.advertisementSummaryInfo.moreCondition = false;
|
} else {
|
vc.component.advertisementSummaryInfo.moreCondition = true;
|
}
|
},
|
// 打开导入弹窗
|
_openImportContractModal: function () {
|
$('#importContractModel').modal('show');
|
},
|
// 获取Excel模板文件
|
_getExcelTemplate: function (e) {
|
vc.component.advertisementSummaryInfo.importExcelFile = e.target.files[0];
|
},
|
// 导出合同模板
|
_exportContractTemplate: function () {
|
// 广告合同模板(对应 sheet:广告合同汇总表)
|
let templateUrl = '/import/广告合同汇总表.xlsx';
|
|
// 直接下载模板文件
|
window.open(templateUrl, '_blank');
|
},
|
// 导入合同数据
|
_importContractData: function () {
|
var fileInput = document.getElementById('importExcelFile');
|
var file = fileInput.files[0];
|
if (!file) {
|
vc.toast("请选择文件");
|
return;
|
}
|
|
// 验证文件类型
|
var fileName = file.name;
|
var fileExtension = fileName.substring(fileName.lastIndexOf('.') + 1).toLowerCase();
|
if (fileExtension !== 'xlsx' && fileExtension !== 'xls') {
|
vc.toast("请选择Excel文件");
|
return;
|
}
|
|
// 移除文件大小限制检查
|
// // 验证文件大小
|
// if (file.size > 20 * 1024 * 1024) {
|
// vc.toast("文件大小不能超过20MB");
|
// return;
|
// }
|
|
// 打印所有参数,便于调试
|
console.log('导入参数:');
|
console.log('communityId:', vc.getCurrentCommunity().communityId);
|
console.log('file:', file);
|
console.log('importAdapt:', 'importContractV2');
|
|
// 使用实际的userId,如果没有则使用默认值
|
let userId = vc.getData() && vc.getData().userInfo && vc.getData().userInfo.userId ? vc.getData().userInfo.userId : '-1';
|
console.log('userId:', userId);
|
|
// 构建表单数据,与车辆导入保持一致
|
var formData = new FormData();
|
formData.append("uploadFile", file); // 添加Excel文件
|
formData.append('communityId', vc.getCurrentCommunity().communityId); // 添加小区ID
|
formData.append('importAdapt', "importContractV2"); // 指定使用的导入适配器
|
formData.append('userId', userId); // 添加userId参数
|
formData.append('USER-ID', userId); // 添加USER-ID参数(大写形式),与车辆导入保持一致
|
|
// 发送导入请求,与车辆导入保持一致
|
vc.http.upload(
|
'assetImport', // 模块名
|
'importData', // 方法名
|
formData, // 参数
|
{
|
// 移除emulateJSON,避免与Content-Type冲突
|
timeout: 60000, // 增加超时设置,60秒
|
headers: {
|
"Content-Type": "multipart/form-data"
|
}
|
},
|
function(json, res) {
|
// 成功回调
|
let _json = JSON.parse(json);
|
if (_json.code == 0) {
|
// 导入成功
|
vc.toast("处理成功");
|
$('#importContractModel').modal('hide'); // 关闭模态框
|
// 清空表单数据
|
vc.component.advertisementSummaryInfo.importExcelFile = '';
|
// 跳转到导入日志详情页面
|
vc.jumpToPage('/#/pages/property/assetImportLogDetail?logId=' + _json.data.logId + '&logType=importContractV2');
|
return;
|
}
|
// 导入失败,显示错误信息
|
let errorMsg = _json.msg;
|
// 优化SocketException错误信息
|
if (errorMsg && errorMsg.includes('java.net.SocketException')) {
|
errorMsg = '导入失败: 网络连接异常,请检查网络连接或稍后重试';
|
}
|
vc.toast(errorMsg, 10000);
|
},
|
function(errInfo, error) {
|
// 失败回调
|
console.log('请求失败处理:', errInfo, error);
|
// 确保即使 errInfo 为空,也能显示错误信息
|
let errorMsg = errInfo;
|
if (!errorMsg || errorMsg.trim() === '') {
|
errorMsg = '导入失败,请检查文件格式或联系管理员';
|
} else {
|
// 优化错误信息显示
|
if (errorMsg.includes('java.net.SocketException')) {
|
errorMsg = '导入失败: 网络连接异常,请检查网络连接或稍后重试';
|
} else if (errorMsg.includes('timeout')) {
|
errorMsg = '导入失败: 请求超时,请检查网络连接或稍后重试';
|
}
|
}
|
vc.toast(errorMsg, 10000);
|
// 关闭模态框
|
$('#importContractModel').modal('hide');
|
// 清空表单数据
|
vc.component.advertisementSummaryInfo.importExcelFile = '';
|
}
|
);
|
},
|
// 导出合同数据
|
_exportContractData: function () {
|
// 构建导出参数
|
var params = vc.component.advertisementSummaryInfo.conditions;
|
params.contractNameLike = params.contractNameLike.trim();
|
params.contractCode = params.contractCode.trim();
|
|
// 构建导出URL
|
let exportUrl = '/contract/exportContractData?';
|
|
// 添加参数
|
let paramStr = '';
|
for (let key in params) {
|
if (params[key] && params[key] !== '') {
|
if (paramStr) {
|
paramStr += '&';
|
}
|
paramStr += key + '=' + encodeURIComponent(params[key]);
|
}
|
}
|
|
exportUrl += paramStr;
|
|
// 直接下载导出文件
|
window.open(exportUrl, '_blank');
|
},
|
|
// 广告合同信息管理相关方法
|
// 查询广告合同信息
|
_queryAdContractInfo: function() {
|
var that = this;
|
var params = {
|
page: that.adContractInfo.page,
|
row: that.adContractInfo.row,
|
mpId: that.adContractInfo.conditions.mpId,
|
id: that.adContractInfo.conditions.id,
|
contractId: that.adContractInfo.conditions.contractId,
|
adType: that.adContractInfo.conditions.adType,
|
subType: that.adContractInfo.conditions.subType,
|
cooperationForm: that.adContractInfo.conditions.cooperationForm,
|
buildingElevatorCount: that.adContractInfo.conditions.buildingElevatorCount,
|
onlineQuantity: that.adContractInfo.conditions.onlineQuantity,
|
facilityLocation: that.adContractInfo.conditions.facilityLocation
|
};
|
|
vc.http.apiGet('/app/adContractInfo/queryAdContractInfo', {
|
params: params
|
}, function(json, res) {
|
var _json = JSON.parse(json);
|
if (_json.code === '0000') {
|
that.adContractInfo.dataList = _json.data || [];
|
that.adContractInfo.total = _json.total || 0;
|
} else {
|
vc.toast(_json.msg || '查询失败');
|
}
|
}, function(errInfo, error) {
|
vc.toast('查询失败,请检查网络连接');
|
});
|
},
|
|
// 根据ID查询单条广告合同信息
|
_getAdContractInfoById: function(id) {
|
var that = this;
|
var params = {
|
id: id
|
};
|
|
vc.http.apiGet('/app/adContractInfo/getAdContractInfoById', {
|
params: params
|
}, function(json, res) {
|
var _json = JSON.parse(json);
|
if (_json.code === '0000') {
|
// 这里可以处理返回的数据,比如填充表单或显示详情
|
that.adContractInfo.formData = _json.data || {};
|
} else {
|
vc.toast(_json.msg || '查询失败');
|
}
|
}, function(errInfo, error) {
|
vc.toast('查询失败,请检查网络连接');
|
});
|
},
|
|
// 根据合同ID查询广告合同信息
|
_getAdContractInfoByContractId: function(contractId) {
|
var that = this;
|
var params = {
|
contractId: contractId
|
};
|
|
vc.http.apiGet('/app/adContractInfo/getAdContractInfoByContractId', {
|
params: params
|
}, function(json, res) {
|
var _json = JSON.parse(json);
|
if (_json.code === '0000') {
|
that.adContractInfo.dataList = _json.data || [];
|
that.adContractInfo.total = _json.data ? _json.data.length : 0;
|
that.adContractInfo.conditions.contractId = contractId;
|
} else {
|
vc.toast(_json.msg || '查询失败');
|
}
|
}, function(errInfo, error) {
|
vc.toast('查询失败,请检查网络连接');
|
});
|
},
|
|
// 统计广告合同信息
|
_queryAdContractInfoStatistics: function() {
|
var that = this;
|
var params = {
|
contractId: that.adContractInfo.conditions.contractId,
|
adType: that.adContractInfo.conditions.adType,
|
subType: that.adContractInfo.conditions.subType
|
};
|
|
vc.http.apiGet('/app/adContractInfo/queryAdContractInfoStatistics', {
|
params: params
|
}, function(json, res) {
|
var _json = JSON.parse(json);
|
if (_json.code === '0000') {
|
that.adContractInfo.statistics = _json.data || {
|
totalCount: 0,
|
adTypeCount: {},
|
subTypeCount: {}
|
};
|
$('#adContractInfoStatisticsModal').modal('show');
|
} else {
|
vc.toast(_json.msg || '统计失败');
|
}
|
}, function(errInfo, error) {
|
vc.toast('统计失败,请检查网络连接');
|
});
|
},
|
|
// 保存广告合同信息
|
_saveAdContractInfo: function() {
|
var that = this;
|
var formData = that.adContractInfo.formData;
|
|
// 表单验证
|
if (!that._validateAdContractForm(formData)) {
|
return;
|
}
|
|
var url = that.adContractInfo.isEdit ? '/app/adContractInfo/updateAdContractInfo' : '/app/adContractInfo/saveAdContractInfo';
|
|
vc.http.apiPost(url, JSON.stringify(formData), {
|
headers: {
|
'Content-Type': 'application/json'
|
}
|
}, function(json, res) {
|
var _json = JSON.parse(json);
|
if (_json.code === '0000') {
|
vc.toast(_json.msg || '保存成功');
|
$('#adContractInfoModal').modal('hide');
|
that._queryAdContractInfo();
|
} else {
|
vc.toast(_json.msg || '保存失败');
|
}
|
}, function(errInfo, error) {
|
vc.toast('保存失败,请检查网络连接');
|
});
|
},
|
|
// 删除广告合同信息
|
_deleteAdContractInfo: function(id) {
|
var that = this;
|
if (confirm('确定要删除这条广告合同信息吗?')) {
|
vc.http.apiPost('/app/adContractInfo/deleteAdContractInfo', JSON.stringify({id: id}), {
|
headers: {
|
'Content-Type': 'application/json'
|
}
|
}, function(json, res) {
|
var _json = JSON.parse(json);
|
if (_json.code === '0000') {
|
vc.toast(_json.msg || '删除成功');
|
that._queryAdContractInfo();
|
} else {
|
vc.toast(_json.msg || '删除失败');
|
}
|
}, function(errInfo, error) {
|
vc.toast('删除失败,请检查网络连接');
|
});
|
}
|
},
|
|
// 表单验证
|
_validateAdContractForm: function(formData) {
|
if (!formData.contractId) {
|
vc.toast('请输入合同ID');
|
return false;
|
}
|
if (!formData.adType) {
|
vc.toast('请选择广告类型');
|
return false;
|
}
|
if (!formData.subType) {
|
vc.toast('请选择广告子类型');
|
return false;
|
}
|
if (!formData.cooperationForm) {
|
vc.toast('请输入合作内容形式');
|
return false;
|
}
|
return true;
|
},
|
|
// 重置查询条件
|
_resetAdContractQuery: function() {
|
this.adContractInfo.conditions = {
|
mpId: '',
|
id: '',
|
contractId: '',
|
adType: '',
|
subType: '',
|
cooperationForm: '',
|
buildingElevatorCount: '',
|
onlineQuantity: '',
|
facilityLocation: ''
|
};
|
this.adContractInfo.page = 1;
|
this._queryAdContractInfo();
|
},
|
|
// 切换页码
|
_changeAdContractPage: function(page) {
|
if (page < 1) return;
|
this.adContractInfo.page = page;
|
this._queryAdContractInfo();
|
},
|
|
// 打开添加弹窗
|
_openAddAdContractModal: function() {
|
this.adContractInfo.formData = {
|
id: '',
|
contractId: '',
|
adType: '',
|
subType: '',
|
cooperationForm: '',
|
buildingElevatorCount: '',
|
onlineQuantity: '',
|
facilityLocation: ''
|
};
|
this.adContractInfo.isEdit = false;
|
$('#adContractInfoModal').modal('show');
|
},
|
|
// 打开编辑弹窗
|
_openEditAdContractModal: function(item) {
|
this.adContractInfo.formData = JSON.parse(JSON.stringify(item));
|
this.adContractInfo.isEdit = true;
|
$('#adContractInfoModal').modal('show');
|
},
|
|
// 获取广告子类型列表
|
_getSubTypes: function(adType) {
|
if (!adType || !this.AD_TYPES[adType]) {
|
return [];
|
}
|
return this.AD_TYPES[adType].subTypes;
|
}
|
}
|
});
|
})(window.vc);
|