CNLiveVitaeAddWorkController.swift 16.1 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 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405
//
//  CNLiveVitaeAddWorkController.swift
//  metaCode
//
//  Created by zx on 2024/7/29.
//  数字简历-添加工作记录页面/添加获奖情况页面

import Foundation
import SnapKit

///数字简历工作/获奖类型
enum CNLiveViateWorkAwardType {
    ///工作记录
    case work
    ///获奖情况
    case award
}

class CNLiveVitaeAddWorkController:CNLiveBaseViewController,UITableViewDataSource, UITableViewDelegate{
    
    var workAwardType:CNLiveViateWorkAwardType = .work
    
    var hangHeight:CGFloat = (KSreenWidth-90)/3.0+10
    var secCell:CNLiveVitaeAddWorkSecCell?
    var seleArr:Array<String>?
    var seleVideoUrl:String = ""
    
    var isFirstEdit = true
    //简历workModel
    var _workModel : CNLiveVitaeWorksModel?
    var workModel : CNLiveVitaeWorksModel? {
        get{
            _workModel
        }
        set{
            _workModel = newValue!
        }
    }
    //简历awardModel
    var _awardModel : CNLiveVitaeAwardsModel?
    var awardModel : CNLiveVitaeAwardsModel? {
        get{
            _awardModel
        }
        set{
            _awardModel = newValue!
        }
    }
    
    let kCNLiveVitaeAddWorkFirCellIdentifier = "kCNLiveVitaeAddWorkFirCellIdentifier"
    let kCNLiveVitaeAddWorkSecCellIdentifier = "kCNLiveVitaeAddWorkSecCellIdentifier"
    let kCNLiveVitaeAddWorkThreeCellIdentifier = "kCNLiveVitaeAddWorkThreeCellIdentifier"

    lazy var tableView : UITableView = {
        let tableView = UITableView(frame: .zero, style: .plain)
        tableView.dataSource = self
        tableView.delegate = self
        tableView.separatorStyle = .none
        tableView.tableFooterView = UIView.init()
        tableView.register(CNLiveVitaeAddWorkFirCell.self, forCellReuseIdentifier: kCNLiveVitaeAddWorkFirCellIdentifier)
        tableView.register(CNLiveVitaeAddWorkSecCell.self, forCellReuseIdentifier: kCNLiveVitaeAddWorkSecCellIdentifier)
        tableView.register(CNLiveVitaeAddWorkThreeCell.self, forCellReuseIdentifier: kCNLiveVitaeAddWorkThreeCellIdentifier)
        tableView.backgroundColor = .clear
        return tableView
    }()
    lazy var bottomZhiNanWhiteView :UIView = {
        let bottomNavView = UIView()
        bottomNavView.backgroundColor = .white
        return bottomNavView
    }()
    lazy var addWorkBtn: UIButton = {
        let  nextBtn = UIButton(type: .custom)
        nextBtn.setTitle("确认提交", for: .normal)
        nextBtn.setTitleColor(.white, for: .normal)
        nextBtn.backgroundColor = HexColor("#1961FE")
        nextBtn.layer.cornerRadius = 20
        nextBtn.clipsToBounds = true
        nextBtn.addTarget(self, action: #selector(addWorkBtnAction), for: .touchUpInside)
        return nextBtn
    }()
    lazy var chengNuoTitleLabel: UILabel = {
        let titleLabel = UILabel()
        titleLabel.textColor = HexColor("#B4B4B4")
        titleLabel.textAlignment = .center
        titleLabel.numberOfLines = 2
        titleLabel.text = "我承诺以上所填写资料均完全真实,如被证实有虚假成分,本人愿意承担一切责任"
        titleLabel.font = Font_12
        return titleLabel
    }()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        if self.workAwardType == .work{
            titleName = "新增工作记录"
        }else{
            titleName = "新增获奖情况"
        }
        navigationBarHidden = false
        self.initUI()
        
        if self.workModel != nil || self.awardModel != nil{
            self.tableView.reloadData()
        }
    }
    
    deinit {}
    func initUI(){
        self.view.backgroundColor = HexColor("#F6F7FB")
        
        self.view.addSubview(self.tableView)
        self.tableView.snp.makeConstraints { make in
            make.top.equalTo(KNavigationHeight)
            make.left.right.equalToSuperview()
            make.height.equalToSuperview().offset(-KNavigationHeight-60-63)
        }
        
        self.view.addSubview(self.chengNuoTitleLabel)
        self.chengNuoTitleLabel.snp.makeConstraints { make in
            make.top.equalTo(self.tableView.snp.bottom).offset(15)
            make.left.equalTo(15)
            make.right.equalToSuperview().offset(-15)
            make.bottom.equalToSuperview().offset(-75)
        }

        self.view.addSubview(self.bottomZhiNanWhiteView)
        self.bottomZhiNanWhiteView.snp.makeConstraints { make in
            make.height.equalTo(60)
            make.bottom.left.right.equalToSuperview()
        }
        
        self.bottomZhiNanWhiteView.addSubview(self.addWorkBtn)
        self.addWorkBtn.snp.makeConstraints { make in
            make.left.equalTo(15)
            make.right.equalToSuperview().offset(-15)
            make.top.equalTo(10)
            make.height.equalTo(40)
        }
        
        
    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        if self.workAwardType == .work{
            return 3
        }else{
            return 2
        }
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        if indexPath.row == 0{
            //firCell
            guard let cell = tableView.dequeueReusableCell(withIdentifier: kCNLiveVitaeAddWorkFirCellIdentifier) as? CNLiveVitaeAddWorkFirCell
            else {
                let cell = CNLiveVitaeAddWorkFirCell()
                return cell
            }
            if self.workAwardType == .work{
                if self.workModel != nil{
                    cell.workModel = self.workModel!
                }
                cell.workAwardType = .work
            }else{
                if self.awardModel != nil{
                    cell.awardModel = self.awardModel!
                }
                cell.workAwardType = .award
            }
            
            return cell
        }else if indexPath.row == 1{
            //SecCell
            guard let cell = tableView.dequeueReusableCell(withIdentifier: kCNLiveVitaeAddWorkSecCellIdentifier) as? CNLiveVitaeAddWorkSecCell
            else {
                let cell = CNLiveVitaeAddWorkSecCell()
                return cell
            }
            if self.workAwardType == .work{
                
                if self.workModel != nil && self.isFirstEdit == true{
                    cell.workModel = self.workModel!
                    self.isFirstEdit = false
                }
            }else{
                if self.awardModel != nil && self.isFirstEdit == true{
                    cell.awardModel = self.awardModel!
                    self.isFirstEdit = false
                }
            }
            cell.uploadImageSuceessBlock = { imageUrl in
                
            }
            cell.selectUploadImageView?.changeUploadDataCallBack = { imageUrls , videoUrl in
                self.seleVideoUrl = videoUrl
                self.seleArr = imageUrls
            }
            
            cell.updateAddWorkSecCellHeightBlock = {cell, hangHeight in
                self.hangHeight = hangHeight
                self.secCell = cell
                let arr = cell.selectUploadImageView?.getCurrentSelectImageUrls()
                let videoUrl = cell.selectUploadImageView?.getCurrentSelectVideoUrl()
                self.seleVideoUrl = videoUrl ?? ""
                self.seleArr = arr
                self.tableView.reloadData()
            }
                
            return cell
        }else if indexPath.row == 2{
            //ThreeCell
            guard let cell = tableView.dequeueReusableCell(withIdentifier: kCNLiveVitaeAddWorkThreeCellIdentifier) as? CNLiveVitaeAddWorkThreeCell
            else {
                let cell = CNLiveVitaeAddWorkThreeCell()
                return cell
            }
            if self.workModel != nil{
                cell.workModel = self.workModel!
            }
            return cell
        }else{
            return UITableViewCell()
        }
    }
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        
    }
    
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        if indexPath.row == 0{
            if self.workAwardType == .work{
                return 276+15
            }else{
                return 184+15
            }
        }else if indexPath.row == 1{
            if self.secCell == nil{
                return self.hangHeight+268+15
            }else{
                return self.hangHeight
            }
        }else if indexPath.row == 2{
            return 123+15
        }else{
            return 60
        }
    }
    
    //确认提交证书
    @objc func addWorkBtnAction() {
        
        if self.workAwardType == .work{
            let firCell = self.tableView.cellForRow(at: IndexPath(row: 0, section: 0)) as? CNLiveVitaeAddWorkFirCell
            let secCell = self.tableView.cellForRow(at: IndexPath(row: 1, section: 0)) as? CNLiveVitaeAddWorkSecCell
            let threeCell = self.tableView.cellForRow(at: IndexPath(row: 2, section: 0)) as? CNLiveVitaeAddWorkThreeCell

            //判断非空
            if firCell?.weizhiRightTitleLabel.text?.count == 0 || firCell?.weizhiRightTitleLabel.text == "请选择"{
                showMessage(message: "请选择职业")
                return
            }
            if firCell?.phoneTextFiled.text?.count == 0 || firCell?.phoneTextFiled.text == "请填写"{
                showMessage(message: "请填写岗位名称")
                return
            }
            if firCell?.canjiaRightTitleLabel.text?.count == 0 || firCell?.canjiaRightTitleLabel.text == "请选择"{
                showMessage(message: "请选择开始时间")
                return
            }
            if firCell?.endTimeRightTitleLabel.text?.count == 0 || firCell?.endTimeRightTitleLabel.text == "请选择"{
                showMessage(message: "请选择结束时间")
                return
            }
            if secCell?.huoJiangtextView.text?.count == 0 || secCell?.huoJiangtextView.text == "获奖描述"{
                showMessage(message: "请填写经历描述")
                return
            }
            
            var newString = ""
            if self.seleArr?.count ?? 0 > 0{
                if self.seleVideoUrl.count > 0{
                    self.seleArr!.append(self.seleVideoUrl)
                }
                newString = self.seleArr!.joined(separator: ",")
            }else{
                if self.seleArr == nil || self.seleArr?.count ?? 0 == 0{
                    if self.seleVideoUrl.count == 0{
                        //
                        showMessage(message: "请上传凭证")
                        return
                    }else{
                        if self.seleVideoUrl.count > 0{
                            newString = self.seleVideoUrl
                        }
                    }
                }else{
                    
                }
            }
            let danWei = threeCell?.phoneTextFiled.text ?? ""
            let workDiDian = threeCell?.weizhiRightTitleLabel.text ?? ""
            if let userDic = UserDefaults.standard.dictionary(forKey: UserInfoManager.shared.userInfo.uid){
                let jianli_vitaeId = userDic["jianli_vitaeId"] as? String
                let vsid = userDic["vsid"] as? String
                let startTime = self.convertDateStringToMillisecondsString(dateString: firCell?.canjiaRightTitleLabel.text ?? "")
                let endTime = self.convertDateStringToMillisecondsString(dateString: firCell?.endTimeRightTitleLabel.text ?? "")
                //提交工作记录
                var id = ""
                if self.workModel != nil{
                    id = self.workModel!.id
                }
                CNLiveVitaeViewModel.saveWork(city: workDiDian, companyName: danWei, imgs: newString, jobDuties: secCell?.huoJiangtextView.text ?? "", startWorkingDate:startTime ?? "" , endWorkingDate: endTime ?? "" , position: firCell?.phoneTextFiled.text ?? "", profession: firCell?.weizhiRightTitleLabel.text ?? "", vsid: vsid ?? "", vitaeId: jianli_vitaeId ?? "", id: id) { result, status in
                    if status == .success{
                        self.navigationController?.viewControllers.forEach({ item in
                            if (item.isKind(of: CNLiveDigitalResumeController.self)) {
                                self.navigationController?.popToViewController(item, animated: true)
                            }
                        })
                    }
                }
            }
        }else{
        //获奖
            let firCell = self.tableView.cellForRow(at: IndexPath(row: 0, section: 0)) as? CNLiveVitaeAddWorkFirCell
            let secCell = self.tableView.cellForRow(at: IndexPath(row: 1, section: 0)) as? CNLiveVitaeAddWorkSecCell
            //判断非空
            if firCell?.phoneTextFiled.text?.count == 0 || firCell?.phoneTextFiled.text == "请填写"{
                showMessage(message: "请填写获奖名称")
                return
            }
            if firCell?.canjiaRightTitleLabel.text?.count == 0 || firCell?.canjiaRightTitleLabel.text == "请选择"{
                showMessage(message: "请选择开始时间")
                return
            }
            if secCell?.huoJiangtextView.text?.count == 0 || secCell?.huoJiangtextView.text == "描述"{
                showMessage(message: "请填写描述")
                return
            }
            
            var newString = ""
            if self.seleArr?.count ?? 0 > 0{
                if self.seleVideoUrl.count > 0{
                    self.seleArr!.append(self.seleVideoUrl)
                }
                newString = self.seleArr!.joined(separator: ",")
            }else{
                if self.seleArr == nil || self.seleArr?.count ?? 0 == 0{
                    if self.seleVideoUrl.count == 0{
                        //
                        showMessage(message: "请上传凭证")
                        return
                    }else{
                        if self.seleVideoUrl.count > 0{
                            newString = self.seleVideoUrl
                        }
                    }
                }else{
                    
                }
            }

            if let userDic = UserDefaults.standard.dictionary(forKey: UserInfoManager.shared.userInfo.uid){
                let jianli_vitaeId = userDic["jianli_vitaeId"] as? String
                let vsid = userDic["vsid"] as? String
                let startTime = self.convertDateStringToMillisecondsString(dateString: firCell?.canjiaRightTitleLabel.text ?? "")
                //提交工作记录
                var id = ""
                if self.awardModel != nil{
                    id = self.awardModel!.id
                }
                CNLiveVitaeViewModel.saveAward(company: firCell?.banfaTextFiled.text ?? "", description: secCell?.huoJiangtextView.text ?? "", time: startTime ?? "", title: firCell?.phoneTextFiled.text ?? "", imgs: newString, vsid: vsid ?? "", vitaeId: jianli_vitaeId ?? "", id: id) { result, status in
                    if status == .success{
                        self.navigationController?.viewControllers.forEach({ item in
                            if (item.isKind(of: CNLiveDigitalResumeController.self)) {
                                self.navigationController?.popToViewController(item, animated: true)
                            }
                        })
                    }

                }
                
            }
        }

    }
    
    func convertDateStringToMillisecondsString(dateString: String, dateFormat: String = "yyyy.MM.dd") -> String? {
        // 创建DateFormatter实例并设置日期格式
        let formatter = DateFormatter()
        formatter.dateFormat = dateFormat
        formatter.timeZone = TimeZone(secondsFromGMT: 0) // 确保使用UTC时区
          
        // 使用DateFormatter解析日期字符串
        if let date = formatter.date(from: dateString) {
            // 获取时间戳(秒)并转换为毫秒
            let milliseconds = Int64(date.timeIntervalSince1970 * 1000)
              
            // 将毫秒值转换为字符串
            return String(milliseconds)
        }
          
        // 如果日期字符串无法被解析,则返回nil
        return nil
    }
}