CNLiveMineInfoViewController.swift
11.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
//
// CNLiveMineInfoViewController.swift
// metaCode
//
// Created by open on 2023/6/9.
// 我的-修改头像页面 / 我的-数字简历-简历头像
import Foundation
import HXPHPicker
import Kingfisher
import APButton
typealias ClickInfoResultBlock = (_ image: UIImage) -> Void
/// 头像类型
enum CNLiveMineIconType {
///我的个人头像
case mineIcon
///我的简历头像
case mineViateIcon
}
class CNLiveMineInfoViewController: CNLiveBaseViewController, PhotoPickerControllerDelegate {
var mineIconType:CNLiveMineIconType = .mineIcon
var viateIconUrl:String = ""
lazy var imageView: UIImageView = {
let imageView = UIImageView.init()
imageView.backgroundColor = .clear
imageView.contentMode = .scaleAspectFill
imageView.clipsToBounds = true
imageView.image = UIImage(named: "mine_header_icon_defult_ava")
if self.mineIconType == .mineIcon{
imageView.kf.indicatorType = .activity
imageView.kf.setImage(with: URL(string: UserInfoManager.shared.userInfo.bigFaceUrl), placeholder: UIImage(named: "mine_header_icon_defult_ava"))
}else if self.mineIconType == .mineViateIcon{
imageView.kf.setImage(with: URL(string: self.viateIconUrl), placeholder: UIImage(named: "mine_header_icon_defult_ava"))
}
return imageView
}()
lazy var changeBtn: UIButton = {
let changeBtn = UIButton.init(type: .custom)
changeBtn.setTitle("更换头像", for: .normal)
changeBtn.setTitleColor(.white, for: .normal)
changeBtn.titleLabel?.font = BoldFont_19_Fit
changeBtn.layer.cornerRadius = 20
changeBtn.layer.masksToBounds = true
changeBtn.addTarget(self, action: #selector(changeAvatarAction), for: .touchUpInside)
return changeBtn
}()
lazy var sendBtn: APButton = {
let sendBtn = APButton()
sendBtn.setTitle("确认", for: .normal)
sendBtn.setTitleColor(.white, for: .normal)
sendBtn.titleLabel?.font = BoldFont_19_Fit
sendBtn.layer.cornerRadius = 20
sendBtn.layer.masksToBounds = true
sendBtn.isHidden = true
sendBtn.activityIndicator.color = .white
sendBtn.addTarget(self, action: #selector(changeSendAction), for: .touchUpInside)
return sendBtn
}()
lazy var cancelBtn: UIButton = {
let cancelBtn = UIButton.init(type: .custom)
cancelBtn.setTitle("取消", for: .normal)
cancelBtn.setTitleColor(.black, for: .normal)
cancelBtn.backgroundColor = .white
cancelBtn.layer.cornerRadius = 20
cancelBtn.layer.masksToBounds = true
cancelBtn.isHidden = true
cancelBtn.addTarget(self, action: #selector(changeCancelAction), for: .touchUpInside)
return cancelBtn
}()
var _select_image: UIImage!
var reslut: ClickInfoResultBlock
init(mineIconType:CNLiveMineIconType,viateIconUrl: String,result: @escaping ClickInfoResultBlock) {
self.mineIconType = mineIconType
self.viateIconUrl = viateIconUrl
self.reslut = result
super.init(nibName:nil, bundle:nil)
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .black
setNeedsStatusBarAppearanceUpdate()
navigationBarHidden = false
topNavView.backgroundColor = .clear
//先设置一个默认返回按钮
let leftBtn_array : Array<UIButton> = [UIButton.backItem(imageName: "mine_header_icon_white_back", target: self, action: #selector(changeCancelAction))]
leftNavBtns = leftBtn_array
view.addSubview(imageView)
imageView.snp.makeConstraints { make in
make.center.equalToSuperview()
make.left.right.equalToSuperview()
make.height.equalTo(KSreenWidth)
}
view.addSubview(changeBtn)
changeBtn.snp.makeConstraints { make in
make.centerX.equalToSuperview()
make.bottom.equalToSuperview().offset(-get_system_tabbar_ui_offsetHeight()-20)
make.width.equalTo(200)
make.height.equalTo(40)
}
changeBtn.setGradient(colors: [UIColor(red: 103/255.0, green: 197/255.0, blue: 255/255.0, alpha: 1),UIColor(red: 96/255.0, green: 154/255.0, blue: 255/255.0, alpha: 1)], startPoint: CGPoint(x: 0, y: 0.5), endPoint: CGPoint(x: 1, y: 0.5))
view.addSubview(cancelBtn)
cancelBtn.snp.makeConstraints { make in
make.bottom.equalToSuperview().offset(-get_system_tabbar_ui_offsetHeight()-20)
make.left.equalToSuperview().offset(20)
make.height.equalTo(40)
make.width.equalTo((KSreenWidth - 60) * 0.35)
}
view.addSubview(sendBtn)
sendBtn.snp.makeConstraints { make in
make.centerY.equalTo(cancelBtn)
make.left.equalTo(cancelBtn.snp.right).offset(20)
make.height.equalTo(40)
make.width.equalTo((KSreenWidth - 60)*0.65)
}
sendBtn.setGradient(colors: [UIColor(red: 103/255.0, green: 197/255.0, blue: 255/255.0, alpha: 1),UIColor(red: 96/255.0, green: 154/255.0, blue: 255/255.0, alpha: 1)], startPoint: CGPoint(x: 0, y: 0.5), endPoint: CGPoint(x: 1, y: 0.5))
}
override var preferredStatusBarStyle: UIStatusBarStyle {
return .lightContent
}
@objc func changeCancelAction() {
self.navigationController?.popViewController(animated: true)
}
@objc func changeSendAction() {
sendBtn.startAnimating()
if self.mineIconType == .mineIcon{
CNLiveMineViewModel.requestUploadIconAction(_select_image) { [weak self] type, statue in
if statue {
self?.sendBtn.stopAnimating()
//再这里进行图片上传
self!.reslut(self!._select_image)
self!.navigationController?.popViewController(animated: true)
}
}
}else{
//我的数字简历-更换头像
//上传头像
let uploadKey = UploadManager.uploadViateImage(imageData: _select_image.jpegData(compressionQuality: 1.0)! as NSData, progressBlock: {key, progress in
print("获取进度==>\(progress)")
}, successBlock: { [weak self] key,url in
//保存imgUrl到简历接口
self?.updateViate(key: "jianli_icon", value: url)
})
}
}
@objc func changeAvatarAction() {
var crop = PhotoCroppingConfiguration.init()
crop.isRoundCrop = true
let configuration = PhotoEditorConfiguration()
configuration.state = .cropping
configuration.cropping = crop
configuration.fixedCropState = true
let config = PhotoTools.getWXPickerConfig()
config.selectMode = .single
config.selectOptions = .photo
config.photoEditor = configuration
config.maximumSelectedPhotoCount = 1
let pickerController = PhotoPickerController(picker: config)
pickerController.pickerDelegate = self
pickerController.isOriginal = false
self.navigationController?.present(pickerController, animated: true, completion: nil)
}
func updateViate(key:String,value:Any){
if let userDic = UserDefaults.standard.dictionary(forKey: UserInfoManager.shared.userInfo.uid){
var jianli_city = userDic["jianli_city"] as? String
if key == "jianli_city"{
jianli_city = (value as! String)
}
var jianli_vitaeId = userDic["jianli_vitaeId"] as? String
if key == "jianli_vitaeId"{
jianli_vitaeId = (value as! String)
}
var vsid = userDic["vsid"] as? String
if key == "vsid"{
vsid = (value as! String)
}
var jianli_profession = userDic["jianli_profession"] as? String ?? ""
if key == "jianli_profession"{
jianli_profession = value as! String
}
var jianli_professionId = userDic["jianli_professionId"] as? String
if key == "jianli_professionId"{
jianli_professionId = (value as! String)
}
var jianli_icon = userDic["jianli_icon"] as? String ?? ""
if key == "jianli_icon"{
jianli_icon = value as! String
}
var jianli_phone = userDic["jianli_phone"] as? String ?? ""
if key == "jianli_phone"{
jianli_phone = value as! String
}
var jianli_selfIntroduction = userDic["jianli_selfIntroduction"] as? String
if key == "jianli_selfIntroduction"{
jianli_selfIntroduction = (value as! String)
}
var jianli_workTime = userDic["jianli_workTime"] as? String
if key == "jianli_workTime"{
jianli_workTime = (value as! String)
}
var jianli_showAge = userDic["jianli_showAge"] as? Bool ?? false
if key == "jianli_showAge"{
jianli_showAge = value as! Bool
}
var jianli_showAddress = userDic["jianli_showAddress"] as? Bool ?? false
if key == "jianli_showAddress"{
jianli_showAddress = value as! Bool
}
var jianli_showAwards = userDic["jianli_showAwards"] as? Bool ?? false
if key == "jianli_showAwards"{
jianli_showAwards = value as! Bool
}
var jianli_showPhone = userDic["jianli_showPhone"] as? Bool ?? false
if key == "jianli_showPhone"{
jianli_showPhone = value as! Bool
}
var jianli_updateTime = userDic["jianli_updateTime"] as? String ?? ""
if key == "jianli_updateTime"{
jianli_updateTime = value as! String
}
CNLiveVitaeViewModel.saveVitae(city: jianli_city ?? "", icon: jianli_icon, isSave: false, id: jianli_vitaeId ?? "", phone: jianli_phone, profession: jianli_profession , professionId: jianli_professionId ?? "", selfIntroduction: jianli_selfIntroduction ?? "", showAddress: jianli_showAddress, showAge: jianli_showAge, showAwards: jianli_showAwards, showPhone:jianli_showPhone, updateTime: jianli_updateTime, vsid: vsid ?? "", workTime: jianli_workTime ?? ""){ result, respStatue in
if respStatue == .success{
self.sendBtn.stopAnimating()
//再这里进行图片上传
self.reslut(self._select_image)
self.navigationController?.popViewController(animated: true)
}else{
self.sendBtn.stopAnimating()
}
}
}else{
let tempDic = NSMutableDictionary()
UserDefaults.standard.setValue(tempDic, forKey: UserInfoManager.shared.userInfo.uid)
UserDefaults.standard.synchronize()
}
}
}
extension CNLiveMineInfoViewController {
func pickerController(_ pickerController: PhotoPickerController,
didFinishSelection result: PickerResult) {
result.getImage { [weak self] (image, photoAsset, index) in
if let image = image {
self!._select_image = image
}else {
print("failed")
}
} completionHandler: { [weak self] (images) in
self!.imageView.image = images.first
self!.cancelBtn.isHidden = false
self!.sendBtn.isHidden = false
self!.changeBtn.isHidden = true
}
}
}