(function (vc) { vc.extends({ data: { editOwnerInfo: { ownerId: '', memberId: '', ownerTypeCd: '', name: '', age: '', link: '', address: '', sex: '', remark: '', ownerPhoto: '', ownerPhotoUrl: '', idCard: '', card: '', flag: '', personType:'P', personRole:'1', concactPerson:'', concactLink:'', attrs: [], areaId: '', //国籍字段 areas: '', //存储国籍的列表 }, selectedAreaLabel: '', }, _initMethod: function () { vc.getDict('international_area_code_dictionary', 'link_area_type', function (_data) { $that.editOwnerInfo.areas = _data; }); $that._loadEditOwnerAttrSpec(); }, _initEvent: function () { vc.on('editOwner', 'openEditOwnerModal', function (_owner) { //清理 上次数据 $that.clearEditOwnerInfo(); vc.copyObject(_owner, $that.editOwnerInfo); //根据memberId 查询 照片信息 $that.editOwnerInfo.ownerPhoto = _owner.faceUrl; $that.editOwnerInfo.ownerPhotoUrl = _owner.faceUrl; $that.editOwnerInfo.areaId = _owner.areaId; $('#editOwnerModel').modal('show'); if (_owner.hasOwnProperty('ownerAttrDtos')) { let _ownerAttrDtos = _owner.ownerAttrDtos; _ownerAttrDtos.forEach(item => { $that.editOwnerInfo.attrs.forEach(attrItem => { if (item.specCd == attrItem.specCd) { attrItem.attrId = item.attrId; attrItem.value = item.value; } }) }) } }); }, methods: { editOwnerValidate: function () { return vc.validate.validate({ editOwnerInfo: $that.editOwnerInfo }, { 'editOwnerInfo.name': [ { limit: "required", param: "", errInfo: "名称不能为空" }, { limit: "maxin", param: "2,64", errInfo: "名称长度必须在2位至64位" } ], 'editOwnerInfo.sex': [ { limit: "required", param: "", errInfo: "性别不能为空" } ], 'editOwnerInfo.link': [ { limit: "required", param: "", errInfo: "手机号不能为空" } ], 'editOwnerInfo.remark': [ { limit: "maxLength", param: "200", errInfo: "备注长度不能超过200位" } ] }); }, editOwnerMethod: function () { if (!$that.editOwnerValidate()) { vc.toast(vc.validate.errInfo); return; } if ($that.editOwnerInfo.areaId) { const matched = $that.editOwnerInfo.areas.find(item => item.statusCd === $that.editOwnerInfo.areaId); if (matched) { $that.editOwnerInfo.areaId = matched.statusCd; } } $that.editOwnerInfo.communityId = vc.getCurrentCommunity().communityId; vc.http.apiPost( '/owner.editOwner', JSON.stringify($that.editOwnerInfo), { emulateJSON: true }, function (json, res) { //vm.menus = vm.refreshMenuActive(JSON.parse(json),0); let _json = JSON.parse(json); if (_json.code == 0) { //关闭model $('#editOwnerModel').modal('hide'); vc.emit('listOwner', 'listOwnerData', $that.editOwnerInfo); vc.toast("修改成功"); return; } else { vc.toast(_json.msg); } }, function (errInfo, error) { console.log('请求失败处理'); vc.toast(errInfo); }); }, clearEditOwnerInfo: function () { let _attrs = $that.editOwnerInfo.attrs; let _areas = $that.editOwnerInfo.areas; _attrs.forEach(item => { item.value = ''; }) $that.editOwnerInfo = { ownerId: '', memberId: '', ownerTypeCd: '', name: '', age: '', link: '', address: '', sex: '', remark: '', ownerPhoto: '', ownerPhotoUrl: '', idCard: '', personType:'P', personRole:'1', concactPerson:'', concactLink:'', attrs: _attrs, areaId: '', areas: _areas, }; }, _uploadEditPhoto: function (event) { $("#uploadEditOwnerPhoto").trigger("click") }, _chooseEditPhoto: function (event) { let photoFiles = event.target.files; if (photoFiles && photoFiles.length > 0) { // 获取目前上传的文件 var file = photoFiles[0]; // 文件大小校验的动作 if (file.size > 1024 * 1024 * 1) { vc.toast("图片大小不能超过 2MB!") return false; } // 改为异步上传图片 this._doUploadImageEditOwner(file); } }, // 异步上传图片 _doUploadImageEditOwner: function (_file) { var param = new FormData(); param.append("uploadFile", _file); param.append('communityId', vc.getCurrentCommunity().communityId); //发送get请求 vc.http.upload('uploadFile', 'uploadImage', param, { emulateJSON: true, //添加请求头 headers: { "Content-Type": "multipart/form-data" } }, function (json, res) { if (res.status != 200) { vc.toast("上传文件失败"); return; } let data = JSON.parse(json); $that.editOwnerInfo.ownerPhoto = data.fileId; $that.editOwnerInfo.ownerPhotoUrl = data.url; }, function (errInfo, error) { console.log('请求失败处理'); vc.toast(errInfo); } ); }, _loadEditOwnerAttrSpec: function () { $that.editOwnerInfo.attrs = []; vc.getAttrSpec('building_owner_attr', function (data) { data.forEach(item => { item.value = ''; item.values = []; $that._loadEditAttrValue(item.specCd, item.values); if (item.specShow == 'Y') { $that.editOwnerInfo.attrs.push(item); } }); }); }, _loadEditAttrValue: function (_specCd, _values) { vc.getAttrValue(_specCd, function (data) { data.forEach(item => { if (item.valueShow == 'Y') { _values.push(item); } }); }); }, _closeEditOwnerModal: function () { $('#editOwnerModel').modal('hide'); }, watch: { 'editOwnerInfo.areaId': function (newVal) { const matched = this.editOwnerInfo.areas.find(item => item.statusCd === newVal); this.selectedAreaLabel = matched ? `+${matched.statusCd} (${matched.name})` : ''; } }, } }); })(window.vc);