| | |
| | | |
| | | data: { |
| | | contractChangeDetailsInfo: { |
| | | contractDetails: [] |
| | | |
| | | contractDetails: [], |
| | | currentContract: null |
| | | } |
| | | }, |
| | | _initMethod: function () { |
| | | vc.component._listContractDetails() |
| | | // 先尝试从localStorage获取数据 |
| | | var storedContract = localStorage.getItem('advertisementContractCurrentItem'); |
| | | if (storedContract) { |
| | | try { |
| | | vc.component.contractChangeDetailsInfo.currentContract = JSON.parse(storedContract); |
| | | console.log('从localStorage获取的合同数据:', vc.component.contractChangeDetailsInfo.currentContract); |
| | | } catch (e) { |
| | | console.error('解析localStorage数据失败:', e); |
| | | } |
| | | } |
| | | |
| | | // 同时从API获取数据以确保数据最新 |
| | | vc.component._listContractDetails(); |
| | | }, |
| | | _initEvent: function () { |
| | | |
| | |
| | | }, |
| | | methods: { |
| | | _listContractDetails: function () { |
| | | var contractId = vc.getParam('contractId'); |
| | | if (!contractId) { |
| | | console.log('没有contractId参数'); |
| | | return; |
| | | } |
| | | |
| | | var param = { |
| | | params: { |
| | | page:1, |
| | | row:10, |
| | | contractId:vc.getParam('contractId') |
| | | page: 1, |
| | | row: 10, |
| | | contractId: contractId |
| | | } |
| | | }; |
| | | //发送get请求 |
| | | vc.http.apiGet('/contract/queryContract', |
| | | param, |
| | | function (json, res) { |
| | | var _contractManageInfo = JSON.parse(json); |
| | | |
| | | console.log('合同详情数据:', _contractManageInfo); |
| | | vc.component.contractChangeDetailsInfo.contractDetails = _contractManageInfo.data; |
| | | |
| | | |
| | | try { |
| | | var _contractManageInfo = JSON.parse(json); |
| | | console.log('API返回的合同详情数据:', _contractManageInfo); |
| | | |
| | | if (_contractManageInfo.code === 0 && _contractManageInfo.data && _contractManageInfo.data.length > 0) { |
| | | vc.component.contractChangeDetailsInfo.contractDetails = _contractManageInfo.data; |
| | | // 更新currentContract为API返回的最新数据 |
| | | vc.component.contractChangeDetailsInfo.currentContract = _contractManageInfo.data[0]; |
| | | console.log('设置当前合同数据:', vc.component.contractChangeDetailsInfo.currentContract); |
| | | } else { |
| | | console.log('API返回数据为空或格式不正确'); |
| | | } |
| | | } catch (e) { |
| | | console.error('解析API响应失败:', e); |
| | | } |
| | | }, function (errInfo, error) { |
| | | console.log('请求失败处理:', errInfo); |
| | | } |
| | |
| | | }, |
| | | _goBack: function () { |
| | | vc.goBack(); |
| | | }, |
| | | // 辅助函数:安全获取嵌套对象属性 |
| | | _getSafe: function (obj, path, defaultValue) { |
| | | if (!obj) return defaultValue; |
| | | var keys = path.split('.'); |
| | | var result = obj; |
| | | for (var i = 0; i < keys.length; i++) { |
| | | if (result === null || result === undefined) return defaultValue; |
| | | result = result[keys[i]]; |
| | | } |
| | | return result === undefined ? defaultValue : result; |
| | | } |
| | | } |
| | | }); |