CNLiveMineShopViewController.swift 22.4 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 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430
//
//  CNLiveMineShopViewController.swift
//  metaCode
//
//  Created by open on 2023/10/11.
//

import UIKit
import Foundation
import SnapKit
import APButton

enum CNLiveMineShopResultShowType {
    case one   //营业执照
    case two   //法人身份证
    case three //经营信息
}
class CNLiveMineShopViewController : CNLiveBaseViewController, UITextViewDelegate {
    
    lazy var mainScrollView: UIScrollView = {
        let mainScrollView = UIScrollView.init(frame: CGRectMake(0, get_system_nav_height(), KSreenWidth, KSreenHeight - get_system_nav_height() - get_system_tabbar_ui_offsetHeight() - 70))
        mainScrollView.backgroundColor = HexColor("#F7F8FA")
        mainScrollView.showsHorizontalScrollIndicator = true
        mainScrollView.isScrollEnabled = true
        return mainScrollView
    }()
    
    lazy var oneView: MineInputShopHeaderView = {
        let oneView = MineInputShopHeaderView.init(frame: CGRectMake(10, 0, KSreenWidth - 20, 0), array: oneArray as! Array<Any>, showType: .one)
        oneView.backgroundColor = HexColor("#F7F8FA")
        return oneView
    }()
    
    lazy var twoView: MineInputShopHeaderView = {
        let twoView = MineInputShopHeaderView.init(frame: CGRectMake(10, 0, KSreenWidth - 20, 0), array: twoArray as! Array<Any>, showType: .two)
        twoView.backgroundColor = HexColor("#F7F8FA")
        return twoView
    }()
    
    lazy var threeView: MineInputShopHeaderView = {
        let threeView = MineInputShopHeaderView.init(frame: CGRectMake(10, 0, KSreenWidth - 20, 0), array: threeArray as! Array<Any>, showType: .three)
        threeView.backgroundColor = HexColor("#F7F8FA")
        return threeView
    }()
    
    lazy var textView: UITextView = {
        let attributedString = NSMutableAttributedString(string: "我同意并已阅读《中国网+内容安全协议》",
                                                         attributes: [.foregroundColor: HexColor("#999999") as Any, .font: Font_10])
        let p_Range = NSRange(attributedString.string.range(of: "《中国网+内容安全协议》")!, in: attributedString.string)
        attributedString.addAttribute(.link, value: "delegate://", range: p_Range)
        let textView: UITextView = UITextView.init()
        textView.backgroundColor = .clear
        textView.isEditable = false
        textView.isScrollEnabled = false
        textView.delegate = self
        textView.attributedText = attributedString
        return textView
    }()
    
    lazy var selectButton: HotButton = {
        let selectButton = HotButton(type: .custom)
        selectButton.backgroundColor = .clear
        selectButton.setImage(UIImage(named: "Login_body_choose_btn_nomal"), for: .normal)
        selectButton.setImage(UIImage(named: "Login_body_choose_btn_nomal"), for: .highlighted)
        selectButton.setImage(UIImage(named: "Login_body_choose_btn_select"), for: .selected)
        selectButton.contentMode = .scaleAspectFill
        selectButton.addTarget(self, action: #selector(changeSelectBtnMothod), for: .touchUpInside)
        return selectButton
    }()
    
    lazy var nextButton: APButton = {
        let nextButton = APButton()
        nextButton.setTitleColor(.white, for: .normal)
        nextButton.titleLabel?.font = BoldFont_16_Fit
        nextButton.layer.cornerRadius = 20
        nextButton.layer.masksToBounds = true
        nextButton.activityIndicator.color = .white
        nextButton.addTarget(self, action: #selector(sendInfoActionMothod), for: .touchUpInside)
        return nextButton
    }()
    
    var _listModel:StandListModel!
    var _tempArray:NSMutableArray!
    var _showType:CNLiveMineShopResultShowType!
    init(showType: CNLiveMineShopResultShowType,listModel:StandListModel,tempArray:NSMutableArray) {
       super.init(nibName:nil, bundle:nil)
        _showType = showType
        _listModel = listModel
        _tempArray = tempArray
    }
    
    /**
     1 大输入框
     2 小输入框
     3 下弹框时间选择
     4 开关按钮
     5 竖图带提示图片选择
     */
    lazy var oneArray: NSMutableArray = {
        let dataArray = NSMutableArray()
        let array : [NSMutableDictionary] = [["title":"*商户名称","placeholder":"请填写","subTitle":"若营业执照上的名称为空或为“无字号”,请填写“个体户+经营者姓名如:个体户张三","show_type":"1","content":"","key":"commercial_name"],
            ["title":"*统一社会信用代码","placeholder":"请填写","subTitle":"","show_type":"2","content":"","key":"credit_code"],
            ["title":"*注册地址","placeholder":"请填写","subTitle":"","show_type":"2","content":"","key":"registered_address"],
            ["title":"*经营期限(开始)","placeholder":"请选择","subTitle":"","show_type":"3","content":"","key":"management_start_time"],
            ["title":"*经营期限(结束)","placeholder":"请选择","subTitle":"","show_type":"3","content":"","key":"management_stop_time"],
            ["title":"*长期经营","placeholder":"","subTitle":"","show_type":"4","content":"","key":""],
            ["title":"*营业执照","placeholder":"","subTitle":"请上传营业执照图片,格式为JPG、PNG (图片大小不超过5M)","show_type":"5","content":"","key":"business_licence_img"],
        ]
        dataArray.addObjects(from: array)
        return dataArray
    }()
    
    /**
     6 单选
     7 身份证类型
     */
    lazy var twoArray: NSMutableArray = {
        let dataArray = NSMutableArray()
        let array : [NSMutableDictionary] = [["title":"*证件类型","placeholder":"身份证","subTitle":"","show_type":"6","content":"","key":""],
            ["title":"*身份证正面","placeholder":"","subTitle":"(请拍摄本人身份证正面注意避免证件反光)","show_type":"7","content":"","key":"identification_card1_img"],
            ["title":"*身份证反面","placeholder":"","subTitle":"(请拍摄本人身份证反面注意避免证件反光)","show_type":"7","content":"","key":"identification_card2_img"],
            ["title":"*证件号码","placeholder":"请填写","subTitle":"","show_type":"2","content":"","key":"certificates_code"],
            ["title":"*证件持有人姓名","placeholder":"请填写","subTitle":"","show_type":"2","content":"","key":"certificates_name"],
            ["title":"*证件有效期(开始)","placeholder":"请选择","subTitle":"","show_type":"3","content":"","key":"identity_start_time"],
            ["title":"*证件有效期(结束)","placeholder":"请选择","subTitle":"","show_type":"3","content":"","key":"identity_stop_time"],
        ]
        dataArray.addObjects(from: array)
        return dataArray
    }()
    
    /**
     8 正方图带提示图片选择
     9 下弹框类型选择
     */
    lazy var threeArray: NSMutableArray = {
        let dataArray = NSMutableArray()
        let array : [NSMutableDictionary] = [["title":"*店铺名称","placeholder":"请填写","subTitle":"","show_type":"2","content":"","key":"store_name"],
            ["title":"*店铺电话","placeholder":"请填写","subTitle":"","show_type":"2","content":"","key":"service_phone"],
            ["title":"*经营类目","placeholder":"请选择","subTitle":"","show_type":"9","content":"","key":"category_pid","category":"","dataArray":categoryArray as NSArray],
            ["title":"*店铺LOGO","placeholder":"","subTitle":"请上传LOGO图片 (尺寸100*100,图片大小5M以内)","show_type":"5","content":"","key":"store_logo"],
            ["title":"特殊资质","placeholder":"","subTitle":"","show_type":"5","content":"","key":"aptitude_images"],
        ]
        dataArray.addObjects(from: array)
        return dataArray
    }()
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    var is_agree : Bool = false //是否同意协议
    var categoryArray: Array<NSDictionary>!
    var temp_array: NSMutableArray = NSMutableArray.init()
    override func viewDidLoad() {
        super.viewDidLoad()

        navigationBarHidden = false
        view.backgroundColor = HexColor("#F7F8FA")
        
        setupUI()
        
    }
    
    func setupUI() {
        view.addSubview(mainScrollView)
        
        view.addSubview(nextButton)
        nextButton.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.bottom.equalToSuperview().offset(-(get_system_tabbar_ui_offsetHeight()+10))
            make.left.equalToSuperview().offset(10)
            make.right.equalToSuperview().offset(-10)
            make.height.equalTo(40)
        }
        
        if _showType == .one {
            titleName = "营业执照"
            mainScrollView.addSubview(oneView)
            nextButton.setTitle("下一步", for: .normal)
            oneView.frame = CGRectMake(10, 10, KSreenWidth-20, CGFloat(oneView.temp_h+160))
            mainScrollView.contentSize = CGSizeMake(KSreenWidth, CGFloat(oneView.temp_h+170))
            nextButton.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))
        }
        if _showType == .two {
            titleName = "法人身份证"
            temp_array.addObjects(from: _tempArray as! [Any])
            mainScrollView.addSubview(twoView)
            nextButton.setTitle("下一步", for: .normal)
            twoView.frame = CGRectMake(10, 10, KSreenWidth-20, CGFloat(twoView.temp_h+160))
            mainScrollView.contentSize = CGSizeMake(KSreenWidth, CGFloat(twoView.temp_h+10))
            twoView.headerView.isHidden = true
            twoView.titleLabel.isHidden = true
            nextButton.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))
        }
        if _showType == .three {
            titleName = "经营信息"
            temp_array.addObjects(from: _tempArray as! [Any])
            showLoading(message: "")
            CNLiveMineViewModel.requestApplyGroupInAction(resultBlock: { [self] result, respStatue in
                if respStatue == .success {
                    categoryArray = result as? Array<NSDictionary>
                    mainScrollView.addSubview(threeView)
                    nextButton.setTitle("提 交", for: .normal)
                    threeView.frame = CGRectMake(10, 10, KSreenWidth-20, CGFloat(threeView.temp_h+160))
                    mainScrollView.frame = CGRectMake(0, get_system_nav_height(), KSreenWidth, KSreenHeight - get_system_nav_height() - get_system_tabbar_ui_offsetHeight() - 80)
                    mainScrollView.contentSize = CGSizeMake(KSreenWidth, CGFloat(threeView.temp_h+10))
                    threeView.headerView.isHidden = true
                    threeView.titleLabel.isHidden = true
                    view.addSubview(textView)
                    textView.snp.makeConstraints { make in
                        make.centerX.equalToSuperview()
                        make.bottom.equalTo(nextButton.snp.top).offset(-5)
                    }
                    view.addSubview(selectButton)
                    selectButton.snp.makeConstraints { make in
                        make.centerY.equalTo(textView)
                        make.right.equalTo(textView.snp.left)
                        make.size.equalTo(15)
                    }
                    setupWithSendBtnStatue(statue: false)
                } else {
                    
                }
            })
        }
    }
    
    @objc func sendInfoActionMothod() {
        if _showType == .one {
            var image: UIImage!
            var is_have_image: Bool! = false
            var temp_dict: NSMutableDictionary!
            for dict in oneArray {
                let content = (dict as! Dictionary<String, Any>)["content"]
                let title = (dict as! Dictionary<String, Any>)["title"]
                let show_type = (dict as! Dictionary<String, Any>)["show_type"]
                let index =  (title! as! String).index((title! as! String).startIndex, offsetBy: 1)
                if show_type as! String == "4" {
                    continue
                }
                if content is NSString {
                    if content as! String == "" {
                        showMessage(message: "\((title! as! String)[index...])不能为空")
                        return
                    }
                }
                if content is UIImage  && content != nil{
                    image = content as? UIImage
                    temp_dict = dict as? NSMutableDictionary
                }
                
                if title as! String == "*营业执照" && (content is NSString) && (content as! NSString).isNotBlank() {
                    is_have_image = true
                }
            }
            if is_have_image {
                temp_array.addObjects(from: oneArray as! [Any])
                self.navigationController?.pushViewController(CNLiveMineShopViewController.init(showType: .two, listModel: _listModel, tempArray: temp_array), animated: true)
                return
            }
            UploadManager.uploadImage(imageData: image.jpegData(compressionQuality: 1.0)! as NSData, progressBlock: {key, progress in
                print("获取进度==>\(progress)")
            }, successBlock: { [self] key,url in
                hiddenLoading()
                temp_dict.removeObject(forKey: "content")
                temp_dict.setObject(url, forKey: "content" as NSCopying)
                temp_array.addObjects(from: oneArray as! [Any])
                self.navigationController?.pushViewController(CNLiveMineShopViewController.init(showType: .two, listModel: _listModel, tempArray: temp_array), animated: true)
            })
        }
        if _showType == .two {
            var image_one: UIImage!
            var image_two: UIImage!
            var is_have_image_one: Bool! = false
            var is_have_image_two: Bool! = false
            var temp_dict_one: NSMutableDictionary!
            var temp_dict_two: NSMutableDictionary!
            for dict in twoArray {
                let content = (dict as! Dictionary<String, Any>)["content"]
                let title = (dict as! Dictionary<String, Any>)["title"]
                let show_type = (dict as! Dictionary<String, Any>)["show_type"]
                let index =  (title! as! String).index((title! as! String).startIndex, offsetBy: 1)
                if show_type as! String == "6" {
                    continue
                }
                if content is NSString {
                    if content as! String == "" {
                        showMessage(message: "\((title! as! String)[index...])不能为空")
                        return
                    }
                }
                if content is UIImage  && content != nil && title as! String == "*身份证正面" {
                    image_one = content as? UIImage
                    temp_dict_one = dict as? NSMutableDictionary
                }
                if content is UIImage  && content != nil && title as! String == "*身份证反面" {
                    image_two = content as? UIImage
                    temp_dict_two = dict as? NSMutableDictionary
                }
                if title as! String == "*身份证正面" && content is NSString && (content as! NSString).isNotBlank() {
                    is_have_image_one = true
                }
                if title as! String == "*身份证反面" && content is NSString && (content as! NSString).isNotBlank() {
                    is_have_image_two = true
                }
            }
            if is_have_image_one || is_have_image_two {
                temp_array.addObjects(from: twoArray as! [Any])
                self.navigationController?.pushViewController(CNLiveMineShopViewController.init(showType: .three, listModel: _listModel, tempArray: temp_array), animated: true)
                return
            }
            UploadManager.uploadImage(imageData: image_one.jpegData(compressionQuality: 1.0)! as NSData, progressBlock: {key, progress in }, successBlock: { [self] key,url in
                temp_dict_one.removeObject(forKey: "content")
                temp_dict_one.setObject(url, forKey: "content" as NSCopying)
                UploadManager.uploadImage(imageData: image_two.jpegData(compressionQuality: 1.0)! as NSData, progressBlock: {key, progress in }, successBlock: { [self] key,url in
                    hiddenLoading()
                    temp_dict_two.removeObject(forKey: "content")
                    temp_dict_two.setObject(url, forKey: "content" as NSCopying)
                    temp_array.addObjects(from: twoArray as! [Any])
                    self.navigationController?.pushViewController(CNLiveMineShopViewController.init(showType: .three, listModel: _listModel, tempArray: temp_array), animated: true)
                })
            })
        }
        if _showType == .three {
            if !is_agree {
                showMessage(message: "请先同意《中国网+内容安全协议》")
                return
            }
            var image_one: UIImage!
            var image_two: UIImage!
            var temp_dict_one: NSMutableDictionary!
            var temp_dict_two: NSMutableDictionary!
            for dict in threeArray {
                let content = (dict as! Dictionary<String, Any>)["content"]
                let title = (dict as! Dictionary<String, Any>)["title"]
                let index =  (title! as! String).index((title! as! String).startIndex, offsetBy: 1)
                if content is NSString {
                    if title as! String == "特殊资质" && content is NSString {} else {
                        if content as! String == "" {
                            showMessage(message: "\((title! as! String)[index...])不能为空")
                            return
                        }
                    }
                }
                if content is UIImage  && content != nil && title as! String == "*店铺LOGO" {
                    image_one = content as? UIImage
                    temp_dict_one = dict as? NSMutableDictionary
                }
                if content is UIImage  && content != nil && title as! String == "特殊资质" {
                    image_two = content as? UIImage
                    temp_dict_two = dict as? NSMutableDictionary
                }
            }
            UploadManager.uploadImage(imageData: image_one.jpegData(compressionQuality: 1.0)! as NSData, progressBlock: {key, progress in }, successBlock: { [self] key,url in
                temp_dict_one.removeObject(forKey: "content")
                temp_dict_one.setObject(url, forKey: "content" as NSCopying)
                if image_two == nil {
                    hiddenLoading()
                    temp_array.addObjects(from: threeArray as! [Any])
                    uploadWithMessage()
                }else{
                    UploadManager.uploadImage(imageData: image_two.jpegData(compressionQuality: 1.0)! as NSData, progressBlock: {key, progress in }, successBlock: { [self] key,url in
                        hiddenLoading()
                        temp_dict_two.removeObject(forKey: "content")
                        temp_dict_two.setObject(url, forKey: "content" as NSCopying)
                        temp_array.addObjects(from: threeArray as! [Any])
                        uploadWithMessage()
                    })
                }
            })
        }
    }
    
    @objc func uploadWithMessage() {
        let paramDict = NSMutableDictionary.init()
        for dict in temp_array {
            let content = (dict as! Dictionary<String, Any>)["content"]
            let key = (dict as! Dictionary<String, Any>)["key"]
            if (dict as! Dictionary<String, Any>)["category"] != nil {
                let category = (dict as! Dictionary<String, Any>)["category"]
                paramDict.addEntries(from: ["category":category as Any])
            }
            if key as! String != ""{
                paramDict.addEntries(from: ["\(key ?? "")":content as Any])
            }
        }
        paramDict.addEntries(from: ["uid":UserInfoManager.shared.userInfo.uid])
        showLoading(message: "")
        nextButton.startAnimating()
        CNLiveMineViewModel.requestApplyShopUserInAction(paramDict: paramDict, resultBlock: { [self] result, respStatue in
            nextButton.stopAnimating()
            if respStatue == .success {
                showMessage(message: "上传成功")
                DispatchQueue.main.asyncAfter(deadline: .now()+1) { [self] in
                    self.navigationController?.pushViewController(CNLiveMineAuthResultViewController.init(StandListModel.init(), show_type: .detail_shop), animated: true)
                }
            }
        })
    }
    
    @objc func changeSelectBtnMothod(sender : UIButton) {
        sender.isSelected = !sender.isSelected
        is_agree = sender.isSelected
        if is_agree {
            nextButton.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))
        } else {
            nextButton.setGradient(colors: [UIColor(red: 103/255.0, green: 197/255.0, blue: 255/255.0, alpha: 0.3),UIColor(red: 96/255.0, green: 154/255.0, blue: 255/255.0, alpha: 0.3)], startPoint: CGPoint(x: 0, y: 0.5), endPoint: CGPoint(x: 1, y: 0.5))
        }
    }
    
    private func setupWithSendBtnStatue(statue: Bool) {
        var alpha = 0.3
        if statue {
            alpha = 1
        }
        nextButton.setGradient(colors: [UIColor(red: 103/255.0, green: 197/255.0, blue: 255/255.0, alpha: alpha),UIColor(red: 96/255.0, green: 154/255.0, blue: 255/255.0, alpha: alpha)], startPoint: CGPoint(x: 0, y: 0.5), endPoint: CGPoint(x: 1, y: 0.5))
    }
}
extension CNLiveMineShopViewController {
    func textView(_ textView: UITextView, shouldInteractWith textAttachment: NSTextAttachment, in characterRange: NSRange, interaction: UITextItemInteraction) -> Bool {
        return false
    }
    func textView(_ textView: UITextView, shouldInteractWith URL: URL, in characterRange: NSRange, interaction: UITextItemInteraction) -> Bool {
        if URL.absoluteString == "delegate://" {
            self.navigationController?.pushViewController(CNLiveInfoShowViewController.init(show_type: .safety, is_login: true), animated: true)
            return false
        }
        return true
    }
}