123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207 |
- //
- // OrderCommentController.swift
- // RainbowPlanet
- //
- // Created by Christopher on 2019/5/17.
- // Copyright © 2019 RainbowPlanet. All rights reserved.
- // 订单--评价Vc
- import UIKit
- import RxSwift
- import SwiftyJSON
- class OrderCommentController: BaseViewController {
-
- var orderDetailModel: OrderModel? {
- didSet {
- self.productArr = self.orderDetailModel?.detail
- self.tableView.reloadData()
- }
- }
-
- // 商品数组
- var productArr: Array<OrderModelDetailModel>?
-
- // 提交评论参数Model
- var paraMdl = OrderCommentParameterModel()
-
- override func viewDidLoad() {
- super.viewDidLoad()
- setupViews()
- setupData()
-
- }
-
- override func setupViews() {
- navigationBar.title = "评价"
-
- let commitButton = UIButton(type: UIButton.ButtonType.custom)
- commitButton.setTitle("提交", for: .normal)
- commitButton.setTitleColor(kffffffColor, for: UIControl.State.normal)
- commitButton.titleLabel?.font = kRegularFont16
- commitButton.backgroundColor = kFFA42FColor
- self.view.addSubview(commitButton)
- commitButton.rx.tap.subscribe(onNext: { [weak self] (data) in
- self?.commitProductComment()
- }).disposed(by: disposeBag)
- commitButton.snp.makeConstraints { (make) in
- make.left.right.equalToSuperview()
- make.bottom.equalToSuperview().offset(-kSafeTabBarHeight)
- make.height.equalTo(50)
- }
-
- self.view.addSubview(tableView)
- let emptyView = EmptyView.shared.diyCustomEmptyViewStyle2(iconStr: "page04", titleStr: "当前暂无数据")
- emptyView.contentViewY = kScaleValue(value: 182)
- tableView.ly_emptyView = emptyView
- tableView.ly_startLoading()
- tableView.snp.makeConstraints { (make) in
- make.top.equalToSuperview().offset(kSafeStatusBarHeight+40)
- make.bottom.equalTo(commitButton.snp_top)
- make.left.right.equalToSuperview()
- }
-
- }
-
- override func setupData() {
-
- }
-
- lazy var tableView: UITableView = {
- let tableView = UITableView(frame: CGRect.zero, style: UITableView.Style.grouped)
- tableView.separatorStyle = .none
- tableView.backgroundColor = kffffffColor
- tableView.dataSource = self
- tableView.delegate = self
- tableView.estimatedRowHeight = 0.000001
- tableView.estimatedSectionFooterHeight = 0.000001
- tableView.estimatedSectionHeaderHeight = 0.000001
- return tableView
- }()
-
- }
- // MARK: - tableView dataSource && delegate
- extension OrderCommentController : UITableViewDelegate, UITableViewDataSource {
-
- func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
- return productArr?.count ?? 0
- }
-
- func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
- let commentCell = OrderCommentTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
- commentCell.orderModelDetailModel = productArr![indexPath.row]
- commentCell.goodsImageArr = productArr![indexPath.row].imageArr
- commentCell.frame = tableView.bounds
- commentCell.layoutIfNeeded()
- commentCell.reloadData()
- commentCell.startChangedBlock = {
- [weak self] (starValue) in
- self?.productArr![indexPath.row].starValue = starValue!
- }
- commentCell.commentTextViewClosure = {
- [weak self] (text) in
- self?.productArr![indexPath.row].comment = text
- }
- commentCell.choosePicBlock = {
- [weak self] in
- // 添加图片
- UIAlertController.showConfirmActionSheet(camera: { (action) in
- PhotoAndCameraManager.shared().authorizeCamera()
- PhotoAndCameraManager.shared().photoAndCameraManagerImageBlock = { [weak self] (image) in
- if self?.productArr![indexPath.row].imageArr.count ?? 0 < 6 {
- self?.productArr![indexPath.row].imageArr.append(image)
- self?.tableView.reloadData()
- } else {
- print("------超过最大数量")
- }
-
- }
- }) { (action) in
- PhotoAndCameraManager.shared().authorizePhoto()
- PhotoAndCameraManager.shared().photoAndCameraManagerImageBlock = { [weak self] (image) in
- if self?.productArr![indexPath.row].imageArr.count ?? 0 < 6 {
- self?.productArr![indexPath.row].imageArr.append(image)
- self?.tableView.reloadData()
- } else {
- print("------超过最大数量")
- }
- }
- }
- }
- commentCell.delPicTransBlock = {
- [weak self] (idxRow) in
- self?.productArr![idxRow!].imageArr.remove(at: idxRow!)
- self?.tableView.reloadData()
- }
- return commentCell
- }
-
- func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
- return UITableView.automaticDimension
- }
-
- func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
- return 10
- }
-
- func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
- let headerSepView = UIView(frame: CGRect(x: 0, y: 0, width: kScreenWidth, height: 10))
- headerSepView.backgroundColor = kf7f8faColor
- return headerSepView
- }
-
- func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
- return 0.000001
- }
-
- func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
- return nil
- }
-
- }
- //MARK: - 逻辑处理
- extension OrderCommentController {
- // 提交评价
- func commitProductComment() {
-
- for productMdl in productArr! {
- if productMdl.starValue == 0 {
- SwiftProgressHUD.shared().showText("请给予商品评分")
- return
- }
- // if productMdl.comment == "" {
- // SwiftProgressHUD.shared().showText("请填写商品评价")
- // return
- // }
- }
-
- // 上传全部商品图片
- for (idx, productMdl) in (productArr?.enumerated())! {
- let curImageArr = productArr![idx].imageArr
-
- if curImageArr.isEmpty {
- continue
- }
-
- let sema = DispatchSemaphore(value: 0)
- // 多图上传Api
- SwiftMoyaNetWorkServiceConfig.shared().configUploadMultiImgApi(imageArray: curImageArr) { (imgUrlArr) -> (Void) in
- let imgJsonStr = JSON(imgUrlArr).description
- productMdl.imageArrUrlStr = imgJsonStr
- sema.signal()
- }
- //异步调用返回前,就会一直阻塞在这
- sema.wait()
- }
-
- self.productAddCommentApi()
- }
-
- func productAddCommentApi() {
-
- }
-
- }
|