// // MyUnusedDetailViewController.swift // MTP2_iOS // // Created by 曹晓亮 on 2020/12/19. // Copyright © 2020 Muchinfo. All rights reserved. // import UIKit import WHToast /// 我的闲置单据详情视图容器控制类 class MyUnusedDetailViewController: BaseViewController { // MARK: - 属性列表 /// 主滚动视图 @IBOutlet weak var scrollView: UIScrollView! /// 订单编号 @IBOutlet weak var orderNo: UILabel! /// 订单时间 @IBOutlet weak var orderTime: UILabel! /// 商品图片 @IBOutlet weak var goodsImage: UIImageView! /// 商品名称 @IBOutlet weak var goodsName: UILabel! /// 商品编号 @IBOutlet weak var goodsCode: UILabel! /// 价格 @IBOutlet weak var price: UILabel! /// 金额 @IBOutlet weak var amount: UILabel! /// 数量 @IBOutlet weak var qty: UILabel! /// 付款数量 @IBOutlet weak var payQty: UILabel! /// 数据展示列表 @IBOutlet weak var tableView: UITableView! /// tableViewHeightConstraint @IBOutlet weak var tableViewHeightConstraint: NSLayoutConstraint! { didSet { tableViewHeightConstraint.constant = 0.0 } } /// 撤销剩余数量 @IBOutlet weak var cancel: UIButton! /// cellIdentifier let cellIdentifier = "MyUnusedDetail_Cell" /// collectionOrders var collectionOrders: [MoMyCollectionOrders] = [] { didSet { /// 刷新数据 tableView.reloadData() /// 列表高度 tableViewHeightConstraint.constant = (CGFloat(collectionOrders.count)*160.0)+35.0 } } /// 数据信息 override var takeInfo: Any? { didSet { } } // MARK: - 生命周期 override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. /// UI界面初始化 buildView() } // MARK: - 初始化相关 /// UI界面初始化 fileprivate func buildView() { /// addLoadingView addLoadingView() /// 单据数据显示 showOrderInfo() } // MARK: - 显示相关 /// 单据数据显示 fileprivate func showOrderInfo() { guard let obj = takeInfo as? MoHsbySellMyDetail else { return } /// 订单编号 orderNo.text = "订单编号:\(obj.orderid)" /// 订单时间 orderTime.text = DateUtils.getTDateString(obj.ordertime, "yyyy-MM-dd HH:mm:ss") /// 商品名称 goodsName.text = obj.goodsname /// 价格 price.text = "\(obj.currencysign) \(obj.price)" /// 金额 amount.text = "金额:\(obj.amount)" /// 数量 qty.text = obj.qty.description /// 付款详情 payQty.text = "已付款数量:\(obj.orderqty) 待付款数量:\(obj.tradeqty) 剩余数量:\(obj.orderqty-obj.tradeqty-obj.cancelqty)" /// 是否隐藏撤单按钮 cancel.isHidden = !(obj.ordertype == 0) /// 商品图片 guard let url = StringUtils.getImageUrl(obj.picurls) else { return } goodsImage.sd_setImage(with: url, placeholderImage: UIImage(named: "placeholder_image"), options: .queryDiskDataSync, context: nil) /// 查询待付款单据数据信息 self.requestQueryMyCollectionOrders() } // MARK: - 交互相关 /// onButtonPressed /// - Parameter sender: sender @IBAction fileprivate func onButtonPressed(_ sender: UIButton) { switch sender { case cancel: guard let obj = takeInfo as? MoHsbySellMyDetail else { return } /// 撤销单据 cancelOrder(obj.orderid, obj.accountid, "\(obj.goodsid)", obj.marketid) default: break } } // MARK: - 接口请求 /// 获取待付款单据数据信息 fileprivate func requestQueryMyCollectionOrders() { /// 数据异常 guard let orderManager = MTP2BusinessCore.shared.orderManager else { return } /// startAnimating _anim?.startAnimating() /// 发送请求 orderManager.requestQueryMyCollectionOrders(callback: { (isComplete, error, orders) in DispatchQueue.main.async { /// stopAnimating self._anim?.stopAnimating() if isComplete { /// 单据数据信息 self.collectionOrders = orders ?? [] } else { WHToast.showError(withMessage: "待付款单据数据信息查询失败,请稍候再试!", duration: 1.5, finishHandler: {}) } } }) } /// 撤单 /// /// - Parameter orderId: 单号 fileprivate func cancelOrder(_ orderId: String?, _ accountId: Int64?, _ goodsID: String?, _ marketID: Int?) { /// 数据异常 guard let tradeManager = MTP2BusinessCore.shared.tradeManager else { return } /// alert showCommitAlertController(title: "提示", message: "确定要撤单吗?"){(_) in /// startAnimating self._anim?.startAnimating() /// 构建数据 let cancelOrderData = CancelOrderData(oldOrderId: orderId ?? "", accountId: accountId ?? 0, goodsID: goodsID ?? "", marketID: marketID ?? 0, operateType: .OPERATETYPE_ORDERCANCEL) /// 发送撤单请求 tradeManager.cancelOrder(cancelorderData: cancelOrderData, callback: { (isCompleted, errorInfo) in DispatchQueue.main.async { /// stopAnimating self._anim?.stopAnimating() if isCompleted { WHToast.showSuccess(withMessage: "撤销成功", duration: 1.5, finishHandler: { /// 返回上层视图 self.navigationController?.popViewController(animated: true) }) } else { WHToast.showError(withMessage: "撤单失败,原因:\(ErrorUtils.getDesc(errorCode: errorInfo?.retCode ?? -60001) ?? "未知错误")", duration: 1.5, finishHandler: {}) } } }) } } /* // MARK: - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation override func prepare(for segue: UIStoryboardSegue, sender: Any?) { // Get the new view controller using segue.destination. // Pass the selected object to the new view controller. } */ } // MARK: - UITableViewDelegate, UITableViewDataSource extension MyUnusedDetailViewController: UITableViewDelegate, UITableViewDataSource { func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return collectionOrders.count } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier, for: indexPath) as! MyUnusedDetailCell cell.model = collectionOrders[indexPath.row] return cell } func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { return 160.0 } } // MARK: - MyUnusedDetailCell class MyUnusedDetailCell: BaseTableViewCell { // MARK: - 属性列表 /// 订单时间 @IBOutlet weak var orderTime: UILabel! /// 订单状态 @IBOutlet weak var status: UILabel! /// 购买人 @IBOutlet weak var userName: UILabel! /// 购买价格 @IBOutlet weak var price: UILabel! /// 购买数量 @IBOutlet weak var qty: UILabel! /// 购买金额数据 @IBOutlet weak var amount: UILabel! /// 数据Model override var model: MoMyCollectionOrders? { didSet { guard let obj = model else { return } /// 订单时间 orderTime.text = DateUtils.getTDateString(obj.ordertime, "yyyy-MM-dd HH:mm") /// 订单状态 status.text = obj.payflag.description /// 购买人 userName.text = obj.buyorderid /// 购买价格 price.text = "\(obj.currencysign) \(obj.tradeprice.toDownString(reserve: obj.decimalplace))" /// 购买数量 qty.text = obj.tradeqty.description /// 购买金额数据 amount.text = "总价:\(obj.currencysign)\(obj.tradeamount) 优惠:\(obj.currencysign)\(obj.offamount) 实付款:\(obj.currencysign)\(obj.payamount)" } } }