|
@@ -8,15 +8,29 @@
|
|
|
|
|
|
import UIKit
|
|
|
import RxSwift
|
|
|
+import SwiftyJSON
|
|
|
|
|
|
class OrderApplyRefundController: BaseViewController {
|
|
|
|
|
|
- var orderModel: OrderModel?
|
|
|
+ var orderDetailModel: OrderModel? {
|
|
|
+ didSet {
|
|
|
+ self.productArr = self.orderDetailModel?.detail
|
|
|
+ self.tableView.reloadData()
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 商品数组
|
|
|
+ var productArr: Array<OrderModelDetailModel>?
|
|
|
+ // 当前是否全选
|
|
|
+ var isAllSelected: Int?
|
|
|
|
|
|
// 退款原因数组
|
|
|
var refundReasonArr: Array<String>?
|
|
|
// 选中の退款原因
|
|
|
- var selRefundReason: String?
|
|
|
+ var selRefundReason: String? = ""
|
|
|
+
|
|
|
+ // 上传图片数组
|
|
|
+ var goodsImageArr = Array<UIImage>()
|
|
|
|
|
|
override func viewDidLoad() {
|
|
|
super.viewDidLoad()
|
|
@@ -35,7 +49,7 @@ class OrderApplyRefundController: BaseViewController {
|
|
|
commitButton.backgroundColor = kFFA42FColor
|
|
|
self.view.addSubview(commitButton)
|
|
|
commitButton.rx.tap.subscribe(onNext: { [weak self] (data) in
|
|
|
- print("点击了--提交申请退款")
|
|
|
+ self?.applyOrderRefund()
|
|
|
|
|
|
}).disposed(by: disposeBag)
|
|
|
commitButton.snp.makeConstraints { (make) in
|
|
@@ -80,12 +94,13 @@ class OrderApplyRefundController: BaseViewController {
|
|
|
extension OrderApplyRefundController : UITableViewDelegate, UITableViewDataSource {
|
|
|
|
|
|
func numberOfSections(in tableView: UITableView) -> Int {
|
|
|
- return 1+4
|
|
|
+ return 5
|
|
|
}
|
|
|
|
|
|
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
|
|
if section == 0 {
|
|
|
- return 2+3
|
|
|
+ let count = productArr?.count ?? 0
|
|
|
+ return count + 3
|
|
|
} else {
|
|
|
return 1
|
|
|
}
|
|
@@ -97,15 +112,30 @@ extension OrderApplyRefundController : UITableViewDelegate, UITableViewDataSourc
|
|
|
switch indexPath.row {
|
|
|
case 0:
|
|
|
let titleCell = OrderShopAndStatusTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
|
|
|
+ titleCell.orderModel = orderDetailModel
|
|
|
return titleCell
|
|
|
case 1:
|
|
|
let dtCell = OrderDeliveryModeAndTimeTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
|
|
|
+ dtCell.orderModel = orderDetailModel
|
|
|
return dtCell
|
|
|
- case 4:
|
|
|
+ case 2+(productArr!.count):
|
|
|
let actCell = OrderApplyRefundAccountCell.cellWith(tableView: tableView, indexPath: indexPath)
|
|
|
+ actCell.isAllSelected = isAllSelected
|
|
|
+ actCell.refundPrice = self.calculateRefundAmount()
|
|
|
+ actCell.allSelectBlock = {
|
|
|
+ [weak self] (isAllSel) in
|
|
|
+ self?.isAllSelected = isAllSel
|
|
|
+ self?.allSelectedAction(isAllSel)
|
|
|
+ }
|
|
|
return actCell
|
|
|
default:
|
|
|
let productCell = OrderApplyRefundProductCell.cellWith(tableView: tableView, indexPath: indexPath)
|
|
|
+ productCell.orderModelDetailModel = productArr![indexPath.row-2]
|
|
|
+ productCell.productSelBlock = {
|
|
|
+ [weak self] (isSel) in
|
|
|
+ self?.productArr![indexPath.row-2].isSelect = isSel
|
|
|
+ self?.judgeAllSelectedStatus()
|
|
|
+ }
|
|
|
return productCell
|
|
|
}
|
|
|
case 1:
|
|
@@ -123,16 +153,49 @@ extension OrderApplyRefundController : UITableViewDelegate, UITableViewDataSourc
|
|
|
return reasonCell
|
|
|
case 2:
|
|
|
let phoneCell = OrderApplyRefundPhoneCell.cellWith(tableView: tableView, indexPath: indexPath)
|
|
|
+ phoneCell.orderModel = orderDetailModel
|
|
|
return phoneCell
|
|
|
case 3:
|
|
|
let noteCell = OrderApplyRefundNoteInfoCell.cellWith(tableView: tableView, indexPath: indexPath)
|
|
|
+ noteCell.orderModel = orderDetailModel
|
|
|
return noteCell
|
|
|
case 4:
|
|
|
let photoCell = OrderApplyRefundPhotoCell.cellWith(tableView: tableView, indexPath: indexPath)
|
|
|
- photoCell.imgCount = 0
|
|
|
+ photoCell.goodsImageArr = self.goodsImageArr
|
|
|
photoCell.frame = tableView.bounds
|
|
|
photoCell.layoutIfNeeded()
|
|
|
photoCell.reloadData()
|
|
|
+ photoCell.choosePicBlock = {
|
|
|
+ [weak self] in
|
|
|
+ // 添加图片
|
|
|
+ UIAlertController.showConfirmActionSheet(camera: { (action) in
|
|
|
+ PhotoAndCameraManager.shared().authorizeCamera()
|
|
|
+ PhotoAndCameraManager.shared().photoAndCameraManagerImageBlock = { [weak self] (image) in
|
|
|
+ if self?.goodsImageArr.count ?? 0 < 3 {
|
|
|
+ self?.goodsImageArr.append(image)
|
|
|
+ self?.tableView.reloadData()
|
|
|
+ } else {
|
|
|
+ print("------超过最大数量")
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }) { (action) in
|
|
|
+ PhotoAndCameraManager.shared().authorizePhoto()
|
|
|
+ PhotoAndCameraManager.shared().photoAndCameraManagerImageBlock = { [weak self] (image) in
|
|
|
+ if self?.goodsImageArr.count ?? 0 < 3 {
|
|
|
+ self?.goodsImageArr.append(image)
|
|
|
+ self?.tableView.reloadData()
|
|
|
+ } else {
|
|
|
+ print("------超过最大数量")
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ photoCell.delPicTransBlock = {
|
|
|
+ [weak self] (idxRow) in
|
|
|
+ self?.goodsImageArr.remove(at: idxRow!)
|
|
|
+ self?.tableView.reloadData()
|
|
|
+ }
|
|
|
return photoCell
|
|
|
default:
|
|
|
return UITableViewCell()
|
|
@@ -163,6 +226,39 @@ extension OrderApplyRefundController : UITableViewDelegate, UITableViewDataSourc
|
|
|
|
|
|
// MARK: - 逻辑处理
|
|
|
extension OrderApplyRefundController {
|
|
|
+ // 全选点击事件
|
|
|
+ func allSelectedAction(_ isSelected: Int) {
|
|
|
+ for productMdl in productArr ?? [] {
|
|
|
+ productMdl.isSelect = isSelected
|
|
|
+ }
|
|
|
+ tableView.reloadSections([0], with: UITableView.RowAnimation.none)
|
|
|
+ }
|
|
|
+
|
|
|
+ // 校验商品是否全选
|
|
|
+ func judgeAllSelectedStatus() -> Void {
|
|
|
+ var isAllSel: Int = 1
|
|
|
+ for productMdl in productArr ?? [] {
|
|
|
+ if productMdl.isSelect == 0 {
|
|
|
+ isAllSel = 0
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ self.isAllSelected = isAllSel
|
|
|
+ tableView.reloadSections([0], with: UITableView.RowAnimation.none)
|
|
|
+ }
|
|
|
+
|
|
|
+ // 计算退款金额
|
|
|
+ func calculateRefundAmount() -> Int {
|
|
|
+ var totalPrice: Int = 0
|
|
|
+ for productMdl in productArr ?? [] {
|
|
|
+ if productMdl.isSelect == 1 {
|
|
|
+ totalPrice += productMdl.amount! * productMdl.productPrice!
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return totalPrice
|
|
|
+ }
|
|
|
+
|
|
|
/// 获取退款原因
|
|
|
func refundReasonApi() {
|
|
|
SwiftMoyaNetWorkServiceProduct.shared().productRefundReasonApi { [weak self] (refundModel) -> (Void) in
|
|
@@ -170,4 +266,51 @@ extension OrderApplyRefundController {
|
|
|
self?.refundReasonArr = refundModel.refundReason
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ // 申请退款
|
|
|
+ func applyOrderRefund() {
|
|
|
+
|
|
|
+ if productArr?.isEmpty ?? true {
|
|
|
+ SwiftProgressHUD.shared().showText("请选择退款商品")
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if selRefundReason?.count == 0 {
|
|
|
+ SwiftProgressHUD.shared().showText("请输入退款原因")
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if productArr?.count == 0 {
|
|
|
+ SwiftProgressHUD.shared().showText("请拍照上传问题")
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 子订单id参数
|
|
|
+ var subIdArr: Array<Int> = []
|
|
|
+ for productMdl in productArr ?? [] {
|
|
|
+ if productMdl.isSelect == 1 {
|
|
|
+ subIdArr.append(productMdl.id!)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ let detailJsonStr = JSON(subIdArr).description
|
|
|
+
|
|
|
+ // 多图上传
|
|
|
+ SwiftMoyaNetWorkServiceConfig.shared().configUploadMultiImgApi(imageArray: goodsImageArr) { [weak self] (imgUrlArr) -> (Void) in
|
|
|
+ let imgJsonStr = JSON(imgUrlArr).description
|
|
|
+
|
|
|
+ self?.orderPurchaseRefundApi(purchaseId: (self?.orderDetailModel!.purchaseNo)!, mobile: (self?.orderDetailModel!.mobile!)!, refundReason: (self?.selRefundReason!)!, refund_remark: self?.orderDetailModel!.remark ?? "", detail: detailJsonStr, imgs: imgJsonStr)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ func orderPurchaseRefundApi(purchaseId:String = "",mobile:String = "",refundReason:String = "",refund_remark:String = "",detail:String = "",imgs:String = "") {
|
|
|
+ SwiftMoyaNetWorkServiceOrder.shared().orderPurchaseRefundApi(purchaseId: purchaseId, mobile: mobile, refundReason: refundReason, refund_remark: refund_remark, detail: detail, imgs: imgs) { (orderApplyRefundModel) -> (Void) in
|
|
|
+ let applyRefundMdl = orderApplyRefundModel as! OrderApplyRefundModel
|
|
|
+
|
|
|
+ let vc = OrderRefunddetailsViewController()
|
|
|
+ vc.refundNo = applyRefundMdl.refundNo
|
|
|
+ self.navigationController?.pushViewController(vc, animated: true)
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|