angular.module('push')
.controller('EditDataCtrl', function ($scope, $ionicPopup, $ionicActionSheet, $stateParams, AccountService, UtilService, UserService, AreaService, ConfigService, $ionicHistory) {
//TODO
if($scope.app){
$scope.setStatusBar(0);
}
$scope.userInfo = UserService.user.user;
if ($scope.userInfo.orgType == 1) {
$scope.orgname = '企业';
}
if ($scope.userInfo.orgType == 2) {
$scope.orgname = '学校';
}
// 编辑头像
$scope.show_header = function () {
// 弹出头像选择框
$ionicActionSheet.show({
cancelOnStateChange: true,
cssClass: 'action_s',
cancelText: '取消',
buttons: [
{text: "拍照"},
{text: "从相册上传"}
],
buttonClicked: function (index) {
if (index == 0) {
openCamera(1);
} else {
openCamera(0);
}
return true;
},
destructiveButtonClicked: function () {
return true;
}
});
};
var openCamera = function (srcType) {
var options = {
// Some common settings are 20, 50, and 100
quality: 50,
destinationType: Camera.DestinationType.FILE_URI,
// In this app, dynamically set the picture source, Camera or photo gallery
sourceType: srcType,
encodingType: Camera.EncodingType.JPEG,
mediaType: Camera.MediaType.PICTURE,
allowEdit: false,
correctOrientation: true //Corrects Android orientation quirks
};
navigator.camera.getPicture(function (imageData) {
$scope.imgurl = imageData;
$scope.showLoadingToast();
UtilService.uploadFile([imageData], 0, "image/jpeg").then(function (response) {
AccountService.setuserName(response[0].userPhoto, 3).then(function (res) {
$scope.userInfo.photo = res.photo;
UserService.user.user.photo = res.photo;
}, function () {
});
$scope.hideLoadingToast();
}, function () {
$scope.hideLoadingToast();
});
}, function (message) {
}, options);
};
$scope.user = {
oldpwd: "",
newpwd: "",
twopwd: ""
};
//修改密码
$scope.updatepwd = function () {
if ($scope.user.oldpwd == "") {
UtilService.showMess("旧密码不能为空!");
} else if ($scope.user.newpwd == "") {
UtilService.showMess("新密码不能为空!");
} else if ($scope.user.newpwd.length < 6 || $scope.user.newpwd.length > 20) {
UtilService.showMess("请输入6-20位英文数字组合的新密码!");
} else if ($scope.user.twopwd == "") {
UtilService.showMess("重复密码不能为空!");
} else if ($scope.user.twopwd.length < 6 || $scope.user.twopwd.length > 20) {
UtilService.showMess("请输入6-20位英文数字组合的重复密码!");
} else {
if ($scope.user.newpwd != $scope.user.twopwd) {
UtilService.showMess("两次密码不同!");
} else {
$scope.showLoadingToast();
AccountService.setuserPwd($scope.user.oldpwd, $scope.user.newpwd, 2).then(function (response) {
if (response.status) {
UtilService.showMess("恭喜,修改密码成功!");
logout();
} else {
UtilService.showMess("旧密码输入错误!");
}
$scope.hideLoadingToast();
}, function (response) {
$scope.hideLoadingToast();
});
}
}
};
//退出登录
var logout = function () {
ConfigService.islogin = false;
UserService.user = {};
UserService.id = "0";
ConfigService.comefrom = "320412000";
$ionicHistory.clearCache();
$scope.go('tab.account');
};
// 编辑用户名
$scope.showPopup = function () {
$scope.data = {
name: $scope.userInfo.userName
};
// 调用$ionicPopup弹出编辑用户名
var myShow = $ionicPopup.show({
template: "
" +
"" +
"2-15个字,支持中英文、数字" +
"
",
title: "编辑用户名",
scope: $scope,
buttons: [
{
text: "取消"
},
{
text: '确认',
type: "button-positive",
onTap: function (e) {
if (!UtilService.isDefined($scope.data.name)) {
UtilService.showMess("用户名不能为空");
return $scope.data.name;
}
AccountService.setuserName($scope.data.name, 1);
$scope.userInfo.userName = $scope.data.name;
return $scope.data.name;
}
}
]
})
.then(function (res) {
$scope.organizationName = [res].join(" ");
});
};
// 编辑个性签名
$scope.showSignature = function () {
$scope.data = {
intro: $scope.userInfo.intro
};
// 调用$ionicPopup弹出编辑个性签名
$ionicPopup.show({
template: "" +
"" +
"126个字以内" +
"
",
title: "编辑个性签名",
scope: $scope,
buttons: [
{
text: "取消"
},
{
text: '确认',
type: "button-positive",
onTap: function (e) {
if (!UtilService.isDefined($scope.data.intro)) {
UtilService.showMess("个性签名不能为空");
return $scope.data.intro;
}
AccountService.setuserName($scope.data.intro, 4);
$scope.userInfo.intro = $scope.data.intro;
return $scope.data.intro;
}
}
]
})
.then(function (res) {
$scope.organizationBrief = [res].join(" ");
});
};
// 编辑机构名
$scope.show_org = function () {
$scope.data = {
orgName: $scope.userInfo.orgName
};
// 调用$ionicPopup弹出编辑机构名
$ionicPopup.show({
template: "" +
"" +
"13个字以内" +
"
",
title: "编辑机构名",
scope: $scope,
buttons: [
{
text: "取消"
},
{
text: '确认',
type: "button-positive",
onTap: function (e) {
AccountService.setuserName($scope.data.orgName, 5);
$scope.userInfo.orgName = $scope.data.orgName;
return $scope.data.orgName;
}
}
]
})
.then(function (res) {
$scope.organizationBrief = [res].join(" ");
});
};
// 编辑机构类型
$scope.show_style = function () {
$scope.data = {
orgType: $scope.userInfo.orgType
};
// 调用$ionicPopup弹出编辑机构类型
$ionicPopup.show({
template: "" +
" " +
"" +
"
",
title: "编辑机构类型",
scope: $scope,
buttons: [
{
text: "取消"
},
{
text: '确认',
type: "button-positive",
onTap: function (e) {
AccountService.setuserName($scope.data.orgType, 6);
$scope.userInfo.orgType = $scope.data.orgType;
if ($scope.userInfo.orgType == 1) {
$scope.orgname = '企业';
}
if ($scope.userInfo.orgType == 2) {
$scope.orgname = '学校';
}
return $scope.data.orgType;
}
}
]
})
.then(function (res) {
$scope.organizationBrief = [res].join(" ");
});
};
// 编辑联系人
$scope.show_link = function () {
$scope.data = {
linkman: $scope.userInfo.linkman
};
// 调用$ionicPopup弹出编辑联系人
$ionicPopup.show({
template: "" +
"" +
"5个字以内" +
"
",
title: "编辑联系人",
scope: $scope,
buttons: [
{
text: "取消"
},
{
text: '确认',
type: "button-positive",
onTap: function (e) {
AccountService.setuserName($scope.data.linkman, 8);
$scope.userInfo.linkman = $scope.data.linkman;
return $scope.data.linkman;
}
}
]
})
.then(function (res) {
$scope.organizationBrief = [res].join(" ");
});
};
// 编辑联系电话
$scope.show_tel = function () {
$scope.data = {
contactNumber: $scope.userInfo.contactNumber
};
// 调用$ionicPopup弹出编辑联系电话
$ionicPopup.show({
template: "" +
"" +
"请输入正确手机号或固定电话,固定电话请加区号" +
"
",
title: "编辑联系电话",
scope: $scope,
buttons: [
{
text: "取消"
},
{
text: '确认',
type: "button-positive",
onTap: function (e) {
AccountService.setuserName($scope.data.contactNumber, 9);
$scope.userInfo.contactNumber = $scope.data.contactNumber;
return $scope.data.contactNumber;
}
}
]
})
.then(function (res) {
$scope.organizationBrief = [res].join(" ");
});
};
// 编辑联系邮箱
$scope.show_email = function () {
$scope.data = {
contactEmail: $scope.userInfo.contactEmail
};
// 调用$ionicPopup弹出编辑联系邮箱
$ionicPopup.show({
template: "" +
"" +
"请输入正确邮箱,包含@.元素" +
"
",
title: "编辑联系邮箱",
scope: $scope,
buttons: [
{
text: "取消"
},
{
text: '确认',
type: "button-positive",
onTap: function (e) {
AccountService.setuserName($scope.data.contactEmail, 9);
$scope.userInfo.contactEmail = $scope.data.contactEmail;
return $scope.data.contactEmail;
}
}
]
})
.then(function (res) {
$scope.organizationBrief = [res].join(" ");
});
};
//修改简介
$scope.editIntro = function () {
AccountService.setuserName($scope.intro, 10).then(function (response) {
}, function () {
});
};
if (angular.isDefined(AreaService.cityid) && AreaService.cityid.length > 0) {
AccountService.setuserName(AreaService.cityid, 7).then(function (response) {
$scope.userInfo.region = AreaService.cityname;
AreaService.cityid = "";
AreaService.cityname = "";
}, function () {
});
}
if (angular.isDefined(AreaService.infobook) && AreaService.infobook.length > 0) {
AccountService.setuserName(AreaService.infobook, 10).then(function (response) {
$scope.userInfo.data = AreaService.infobook;
AreaService.infobook = "";
}, function () {
});
}
$scope.goProvince = function () {
ConfigService.cityflg = 2;
$scope.go('chooseProvince');
};
//显示二维码
$scope.showMyMessage = function () {
$(".fixedTwo").css("display", "block");
};
//隐藏二维码
$scope.hiddenTwoCode = function () {
$(".fixedTwo").css("display", "none");
};
});