Files
PropertyDeployment/resources/Web/MicroCommunityWeb/html/components/property/addOwner/addOwner.js
2025-12-09 20:22:03 +08:00

231 lines
8.8 KiB
JavaScript

(function (vc) {
vc.extends({
data: {
addOwnerInfo: {
name: '',
age: '',
link: '',
address: '',
sex: '0',
ownerTypeCd: '',
remark: '',
ownerId: '',
ownerPhoto: '',
ownerPhotoUrl: '',
idCard: '',
personType: 'P',
personRole: '1',
concactPerson: '',
concactLink: '',
attrs: [],
areaId: '', // 存储选中的国籍值,改为字符串
areas: [], // 存储所有国籍选项数据
},
selectedAreaLabel: '',
},
_initMethod: function () {
// 按照字典添加国籍下拉框
vc.getDict('international_area_code_dictionary', 'link_area_type', function (_data) {
$that.addOwnerInfo.areas = _data;
});
},
_initEvent: function () {
vc.on('addOwner', 'openAddOwnerModal', function (_ownerId) {
if (_ownerId != null || _ownerId != -1) {
$that.addOwnerInfo.ownerId = _ownerId;
}
$('#addOwnerModel').modal('show');
$that._loadOwnerAttrSpec();
});
},
methods: {
addOwnerValidate: function () {
return vc.validate.validate({
addOwnerInfo: $that.addOwnerInfo
}, {
'addOwnerInfo.name': [
{
limit: "required",
param: "",
errInfo: "姓名不能为空"
},
{
limit: "maxin",
param: "2,64",
errInfo: "姓名长度必须在2位至64位"
}
],
'addOwnerInfo.link': [
{
limit: "required",
param: "",
errInfo: "手机号不能为空"
},
{
limit: "maxLength",
param: "64",
errInfo: "手机号长度不能超过64位"
}
],
'addOwnerInfo.idCard': [
{
limit: "maxLength",
param: "64",
errInfo: "身份证格式不对"
}
],
'addOwnerInfo.sex': [
{
limit: "required",
param: "",
errInfo: "性别不能为空"
}
],
'addOwnerInfo.remark': [
{
limit: "maxLength",
param: "200",
errInfo: "备注长度不能超过200位"
}
]
});
},
saveOwnerInfo: function () {
if (!$that.addOwnerValidate()) {
vc.toast(vc.validate.errInfo);
return;
}
// if ($that.addOwnerInfo.ownerTypeCd && $that.addOwnerInfo.ownerTypeCd != '1001') {
// _url = "/owner.saveOwnerMember"
// }
$that.addOwnerInfo.communityId = vc.getCurrentCommunity().communityId;
vc.http.apiPost("/owner.saveOwner",
JSON.stringify($that.addOwnerInfo), {
emulateJSON: true
},
function (json, res) {
//vm.menus = vm.refreshMenuActive(JSON.parse(json),0);
let _json = JSON.parse(json);
if (_json.code == 0) {
//关闭model
$('#addOwnerModel').modal('hide');
//$that.clearAddOwnerInfo();
vc.toast("添加成功");
vc.emit('listOwner', 'listOwnerData', $that.addOwnerInfo);
return;
} else {
vc.toast(_json.msg);
}
},
function (errInfo, error) {
console.log('请求失败处理');
vc.toast(errInfo);
});
},
clearAddOwnerInfo: function () {
$that.addOwnerInfo = {
name: '',
age: '',
link: '',
address: '',
sex: '0',
ownerTypeCd: '',
remark: '',
ownerId: '',
ownerPhoto: '',
ownerPhotoUrl: '',
idCard: '',
videoPlaying: true,
mediaStreamTrack: null,
attrs: []
};
},
_uploadPhoto: function (event) {
//$that.addOwnerInfo.ownerPhoto = "";
$("#uploadOwnerPhoto").trigger("click")
},
_choosePhoto: function (event) {
let photoFiles = event.target.files;
if (photoFiles && photoFiles.length > 0) {
// 获取目前上传的文件
let file = photoFiles[0]; // 文件大小校验的动作
if (file.size > 1024 * 1024 * 1) {
vc.toast("图片大小不能超过 1MB!")
return false;
}
// 改为异步上传图片
$that._doUploadImageAddOwner(file);
}
},
// 异步上传图片
_doUploadImageAddOwner: function (_file) {
let 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) {
let data = JSON.parse(json);
console.log(data);
$that.addOwnerInfo.ownerPhoto = data.fileId;
$that.addOwnerInfo.ownerPhotoUrl = data.url;
},
function (errInfo, error) {
console.log('请求失败处理');
vc.toast(errInfo);
}
);
},
_reOpenVedio: function () {
$that.addOwnerInfo.ownerPhoto = "";
$that.addOwnerInfo.ownerPhotoUrl = "";
},
_loadOwnerAttrSpec: function () {
$that.addOwnerInfo.attrs = [];
vc.getAttrSpec('building_owner_attr', function (data) {
data.forEach(item => {
item.value = '';
if (item.specShow == 'Y') {
item.values = [];
$that._loadAttrValue(item.specCd, item.values);
$that.addOwnerInfo.attrs.push(item);
}
});
});
},
_loadAttrValue: function (_specCd, _values) {
vc.getAttrValue(_specCd, function (data) {
data.forEach(item => {
if (item.valueShow == 'Y') {
_values.push(item);
}
});
});
},
_closeSaveOwnerModal: function () {
$('#addOwnerModel').modal('hide');
},
watch: {
'addOwnerInfo.areaId': function (newVal) {
const matched = this.addOwnerInfo.areas.find(item => item.statusCd === newVal);
this.selectedAreaLabel = matched
? `+${matched.statusCd} (${matched.name})`
: '';
}
},
}
});
})(window.vc);