|
|
@ -16,18 +16,20 @@ class RedeemViewController: UIViewController { |
|
|
|
|
|
|
|
private var model: RewardProduct? { |
|
|
|
didSet { |
|
|
|
guard |
|
|
|
let newModel = model, |
|
|
|
let imageURL = newModel.productNumber?.imageURLInResource else { return } |
|
|
|
|
|
|
|
self.selectedItemImageView.image = UIImage(named: imageURL) |
|
|
|
// FIXME: 이미지 추가 되면 바꿀것/ |
|
|
|
// guard |
|
|
|
// let newModel = model, |
|
|
|
// let imageData = newModel.imageData, |
|
|
|
// let data = Data(base64Encoded: imageData) else { return } |
|
|
|
// self.selectedItemImageView.image = UIImage(data: data) |
|
|
|
|
|
|
|
guard let newModel = model else { return } |
|
|
|
self.selectedItemNameLabel.text = newModel.productName |
|
|
|
self.selectedItemPriceLabel.text = newModel.pointPrice |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private var redeemModel: Redeem? |
|
|
|
|
|
|
|
private enum AddressType: Int { |
|
|
|
case branch = 0 |
|
|
|
case custom |
|
|
@ -60,6 +62,9 @@ class RedeemViewController: UIViewController { |
|
|
|
self.userNameTextField.text = name |
|
|
|
self.userPhoneNumberTextField.text = phoneNumber |
|
|
|
|
|
|
|
self.userNameTextField.sendActions(for: .editingChanged) |
|
|
|
self.userPhoneNumberTextField.sendActions(for: .editingChanged) |
|
|
|
|
|
|
|
self.userInfoView.isHidden = false |
|
|
|
self.selectAddressInfoLabel.isHidden = false |
|
|
|
self.addressSegmentView.isHidden = false |
|
|
@ -98,14 +103,14 @@ class RedeemViewController: UIViewController { |
|
|
|
} |
|
|
|
|
|
|
|
self.submitButton.isHidden = false |
|
|
|
self.perform(#selector(self.moveToBottom), with: nil, afterDelay: 0.1) |
|
|
|
self.perform(#selector(self.moveToBottom), with: nil, afterDelay: 0.3) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private var selectedBranch: GmeContacts? { |
|
|
|
private var selectedBranch: Branch? { |
|
|
|
didSet{ |
|
|
|
self.branchTextField.text = self.selectedBranch?.title |
|
|
|
self.branchTextField.text = self.selectedBranch?.agentName |
|
|
|
self.branchTextField.sendActions(for: .editingChanged) |
|
|
|
} |
|
|
|
} |
|
|
@ -118,8 +123,9 @@ class RedeemViewController: UIViewController { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private var branchesPickerView = UIPickerView() |
|
|
|
private var branches: [GmeContacts]? |
|
|
|
private lazy var branchesPickerView = UIPickerView() |
|
|
|
|
|
|
|
private var branches: [Branch]? |
|
|
|
|
|
|
|
|
|
|
|
// MARK: IBOutlets |
|
|
@ -132,8 +138,8 @@ class RedeemViewController: UIViewController { |
|
|
|
@IBOutlet private weak var userInfoSegmentedControl: UISegmentedControl! |
|
|
|
@IBOutlet private weak var addressSegmentedControl: UISegmentedControl! |
|
|
|
|
|
|
|
@IBOutlet weak var userNameTextField: UITextField! |
|
|
|
@IBOutlet weak var userPhoneNumberTextField: UITextField! |
|
|
|
@IBOutlet private weak var userNameTextField: UITextField! |
|
|
|
@IBOutlet private weak var userPhoneNumberTextField: UITextField! |
|
|
|
|
|
|
|
@IBOutlet private weak var branchTextField: UITextField! |
|
|
|
@IBOutlet private weak var detailAddressTextField: UITextField! |
|
|
@ -174,12 +180,29 @@ class RedeemViewController: UIViewController { |
|
|
|
} |
|
|
|
|
|
|
|
@IBAction |
|
|
|
func touchBranches(_ sender: UIButton) { |
|
|
|
private func touchBranches(_ sender: UIButton) { |
|
|
|
self.presenter?.showBranchesVC() |
|
|
|
} |
|
|
|
|
|
|
|
@IBAction func touchSubmitButton(_ sender: UIButton) { |
|
|
|
self.presenter?.submit(with: redeemModel) |
|
|
|
@IBAction |
|
|
|
private func touchSubmitButton(_ sender: UIButton) { |
|
|
|
let recvType = selectedAddressType == .custom ? "1" : "2" |
|
|
|
let address = "\(self.detailAddressTextField.text ?? ""), \(self.addressTextField.text ?? "")" |
|
|
|
|
|
|
|
let model = Redeem( |
|
|
|
userID: UserDefaults.standard.string(forKey: UserKeys.email), |
|
|
|
productCode: self.model?.productNumber, |
|
|
|
usePoint: self.model?.pointPrice, |
|
|
|
orderType: "1", |
|
|
|
recvType: recvType, |
|
|
|
branchCode: self.selectedBranch?.agentID, |
|
|
|
recvAddress: address, |
|
|
|
recvZipCode: self.selectedAddress?.zipNo, |
|
|
|
recvPhoneNumber: self.userPhoneNumberTextField.text, |
|
|
|
recvName: self.userNameTextField.text |
|
|
|
) |
|
|
|
|
|
|
|
self.presenter?.submit(with: model) |
|
|
|
} |
|
|
|
|
|
|
|
// MARK: Other Functions |
|
|
@ -189,6 +212,8 @@ class RedeemViewController: UIViewController { |
|
|
|
self.branchesPickerView.delegate = self |
|
|
|
self.branchesPickerView.dataSource = self |
|
|
|
|
|
|
|
self.userNameTextField.addTarget(self, action: #selector(self.editingChanged(_:)), for: .editingChanged) |
|
|
|
self.userPhoneNumberTextField.addTarget(self, action: #selector(self.editingChanged(_:)), for: .editingChanged) |
|
|
|
self.branchTextField.addTarget(self, action: #selector(self.editingChanged(_:)), for: .editingChanged) |
|
|
|
self.detailAddressTextField.addTarget(self, action: #selector(self.editingChanged(_:)), for: .editingChanged) |
|
|
|
|
|
|
@ -206,7 +231,7 @@ extension RedeemViewController: RedeemViewInterface { |
|
|
|
self.model = model |
|
|
|
} |
|
|
|
|
|
|
|
func setBranches(with model: [GmeContacts]?) { |
|
|
|
func setBranches(with model: [Branch]?) { |
|
|
|
self.branches = model |
|
|
|
} |
|
|
|
|
|
|
@ -221,6 +246,14 @@ extension RedeemViewController: RedeemViewInterface { |
|
|
|
func submitFailure(with error: Error) { |
|
|
|
self.alert(message: error.localizedDescription) |
|
|
|
} |
|
|
|
|
|
|
|
func startLoading(){ |
|
|
|
self.showProgressHud() |
|
|
|
} |
|
|
|
|
|
|
|
func endLoading(){ |
|
|
|
self.hideProgressHud() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// MARK: - UIPickerViewDataSource, UIPickerViewDelegate |
|
|
@ -235,7 +268,7 @@ extension RedeemViewController: UIPickerViewDataSource, UIPickerViewDelegate { |
|
|
|
} |
|
|
|
|
|
|
|
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? { |
|
|
|
return self.branches?[row].title |
|
|
|
return self.branches?[row].agentName |
|
|
|
} |
|
|
|
|
|
|
|
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) { |
|
|
@ -321,25 +354,30 @@ extension RedeemViewController { |
|
|
|
|
|
|
|
@objc |
|
|
|
private func editingChanged(_ textField: UITextField){ |
|
|
|
let isValid: Bool |
|
|
|
let count = textField.text?.count ?? 0 |
|
|
|
guard |
|
|
|
let name = self.userNameTextField.text, |
|
|
|
let phoneNumber = self.userPhoneNumberTextField.text, |
|
|
|
let branch = self.branchTextField.text, |
|
|
|
let detail = self.detailAddressTextField.text, |
|
|
|
let address = self.addressTextField.text else { return } |
|
|
|
|
|
|
|
var isValid = name.count > 0 && phoneNumber.count > 0 |
|
|
|
|
|
|
|
switch textField{ |
|
|
|
case self.branchTextField: |
|
|
|
isValid = count > 0 |
|
|
|
case self.detailAddressTextField: |
|
|
|
isValid = count > 3 && (self.addressTextField.text?.count ?? 0) > 0 |
|
|
|
default: |
|
|
|
isValid = false |
|
|
|
break |
|
|
|
switch self.selectedAddressType { |
|
|
|
case .branch: |
|
|
|
isValid = isValid && branch.count > 0 |
|
|
|
case .custom: |
|
|
|
isValid = isValid && address.count > 0 && detail.count > 0 |
|
|
|
} |
|
|
|
|
|
|
|
self.submitButton.isEnabled = isValid |
|
|
|
self.submitButton.backgroundColor = isValid ? AppConstants.themeRedColor : .lightGray |
|
|
|
} |
|
|
|
|
|
|
|
@objc func moveToBottom(){ |
|
|
|
@objc private func moveToBottom(){ |
|
|
|
if scrollView.contentSize.height - scrollView.bounds.size.height > 0 { |
|
|
|
let bottomOffset = CGPoint(x: 0, y: scrollView.contentSize.height - scrollView.bounds.size.height) |
|
|
|
self.scrollView.setContentOffset(bottomOffset, animated: true) |
|
|
|
} |
|
|
|
} |
|
|
|
} |