// // MyUnusedViewController.swift // MTP2_iOS // // Created by Handy_Cao on 2020/10/30. // Copyright © 2020 Muchinfo. All rights reserved. // import UIKit import JXSegmentedView import WHToast import NVActivityIndicatorView import SwiftDate /// 我的闲置视图容器控制类 class MyUnusedViewController: BaseViewController { // MARK: - 属性列表 /// 商品切换按钮 @IBOutlet weak var goods: UIButton! /// 发布价格 @IBOutlet weak var orderPrice: IBNumberEditText! { didSet { orderPrice.valueType = 2 orderPrice.currentIntNumbers = 0 orderPrice.delegate = self } } /// 价格范围 @IBOutlet weak var priceRange: UILabel! /// 发布数量 @IBOutlet weak var orderQty: IBNumberEditText! { didSet { orderQty.valueType = 1 orderQty.delegate = self } } /// 可用数量 @IBOutlet weak var enableQty: UILabel! /// 提货按钮 @IBOutlet weak var submit: UIButton! /// 刷新按钮 @IBOutlet weak var refresh: UIButton! /// 有效期按钮 @IBOutlet weak var valid: UIButton! { didSet { valid.isUserInteractionEnabled = false } } /// 有效期 @IBOutlet weak var validStackView: UIStackView! /// 分段控制器 @IBOutlet weak var segmentedView: JXSegmentedView! { didSet { segmentedView.delegate = self segmentedView.dataSource = dataSource segmentedView.indicators = [self.indicator] } } /// segmentedDataSource let dataSource: JXSegmentedTitleDataSource = { var items: [String] = ["待成交", "待收款", "已完成"] $0.titles = items $0.titleNormalColor = UIColorFromHex(rgbValue: 0x333333) $0.titleNormalFont = .font_14 $0.titleSelectedColor = UIColorFromHex(rgbValue: 0x60a1e3) $0.titleSelectedFont = .font_14 $0.isTitleColorGradientEnabled = true return $0 } (JXSegmentedTitleDataSource()) /// 买家委托单列表 @IBOutlet weak var orderTableView: UITableView! { didSet { orderDelegate = OrderDelegate(self) orderTableView.delegate = orderDelegate orderTableView.dataSource = orderDelegate } } /// 单据视图 @IBOutlet weak var orderView: UIView! /// orderTableViewHeightConstraint @IBOutlet weak var orderTableViewHeightConstraint: NSLayoutConstraint! { didSet { orderTableViewHeightConstraint.constant = 0.0 } } /// 列表 @IBOutlet weak var tableView: UITableView! { didSet { myUnusedDelegate = MyUnusedDelegate(self) tableView.delegate = myUnusedDelegate tableView.dataSource = myUnusedDelegate } } /// tableViewHeightConstraint @IBOutlet weak var tableViewHeightConstraint: NSLayoutConstraint! { didSet { tableViewHeightConstraint.constant = 0.0 } } /// 提示信息 @IBOutlet weak var tips: UILabel! /// OrderCellIdentifier let OrderCellIdentifier = "Trade_Cell" /// CellIdentifier let CellIdentifier = "SellMyDetail_Cell" /// orderDelegate fileprivate var orderDelegate: OrderDelegate? /// myUnusedDelegate fileprivate var myUnusedDelegate: MyUnusedDelegate? /// 我的商品数据 var myGoods: MoHsbyMyGoods? { didSet { /// 异常 guard let obj = myGoods, let goodsManager = MTP2BusinessCore.shared.goodsManager, let last = goodsManager.goodsInfos.first(where: {$0.goodsid == obj.goodsid})?.getLast() else { return } /// 显示商品信息 showGoodsInfo(obj) /// 行情订阅 self.subscriptQuote() /// 挂牌点选 if obj.trademode == .TRADEMODE_LISTING_SELECT { /// 侦听行情推送广播 MTP2BusinessCore.shared.broadcastManager?.addBroadcastListener(owner: self, action: .ReceiveTradeQuote, block: { [unowned self] (notify) in DispatchQueue.main.async { /// 异常情况 guard let goodsQuoteInfo = notify.object as? [(goodsHqCode: String, exchHqCode: String)], goodsQuoteInfo.count != 0 else { return } /// 更新商品行情信息 goodsQuoteInfo.forEach { if $0.goodsHqCode == obj.goodscode { if last != self.orderPrice.currentDoubleNumbers { /// 查询数据 self.requestQueryHsbyGoodsOrderDetails(self.orderPrice.currentDoubleNumbers.toString(reserve: 2)) } } } } }) } /// 隐藏 orderView.isHidden = obj.trademode == .TRADEMODE_TRADEMODE_HSBY_SHOP /// 挂牌点选默认当日有效 valid.isUserInteractionEnabled = obj.trademode != .TRADEMODE_LISTING_SELECT /// 小数位 orderPrice.decimalPlace = obj.decimalplace } } /// 委托单数据 var orderDetails: [MoHsbyGoodsOrderDetail] = [] { didSet { /// 刷新列表数据 orderTableView.reloadData() /// 重新设置高度约束 orderTableViewHeightConstraint.constant = CGFloat(orderDetails.count)*50.0 /// 是否隐藏提示 tips.isHidden = orderDetails.count != 0 } } /// 我的闲置单据信息 var sellMyDetails: [MoHsbySellMyDetail] = [] { didSet { /// 刷新列表数据 tableView.reloadData() switch self.segmentedView.selectedIndex { case 0: /// 重新设置高度约束 tableViewHeightConstraint.constant = CGFloat(sellMyDetails.count)*200.0 default: /// 重新设置高度约束 tableViewHeightConstraint.constant = CGFloat(sellMyDetails.count)*180.0 } } } /// 委托数量 var qty: Int = 0 { didSet { orderQty.currentIntNumbers = qty } } /// 有效期 var validType: EValidType = .VALIDTYPE_DR { didSet { switch validType { case .VALIDTYPE_DR: self.valid.setTitle("当日有效", for: .normal) case .VALIDTYPE_YZ: self.valid.setTitle("一直有效", for: .normal) default: self.valid.setTitle("3天有效", for: .normal) } } } /// 交易日查询 var run: MoMarketRun? { get { /// 结算计划 return MTP2BusinessCore.shared.goodsManager?.marketRun } } // MARK: - 生命周期 override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view.e /// 数据初始化 initData() } override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) /// 隐藏导航栏 self.navigationController?.setNavigationBarHidden(false, animated: true) } deinit { /// 移出行情广播 MTP2BusinessCore.shared.broadcastManager?.removeBroadcastListener(owner: self, forName: .ReceiveTradeQuote) } // MARK: - 初始化 /// 数据初始化 fileprivate func initData() { /// 默认查询我的闲置 self.requestQueryHsbySellMyDetails(0) } // MARK: - 交互相关 /// 按钮点击响应事件 /// - Parameter sender: sender @IBAction fileprivate func onButtonPressed(_ sender: UIControl) { switch sender { case goods: /// 商品切换 self.performSegue(withIdentifier: "ShowMyGoods", sender: nil) case submit: let isListing = !orderTableView.visibleCells.contains { (cell) -> Bool in return (cell as? TradeCell)?.isCheck ?? false } /// 有对手委托单得时候必须选一个 if isListing, orderDetails.count != 0 { WHToast.showError(withMessage: "请选择买家", duration: 1.5, finishHandler: {}) return } if isListing { /// 买挂牌 doListingTrade() } else { /// 买摘牌 doDeListingTrade() } case refresh: /// 刷新按钮 let orderPrice = self.orderPrice.currentDoubleNumbers /// 更新单据 self.requestQueryHsbyGoodsOrderDetails(orderPrice.toString(reserve: 2)) case valid: /// 有效期 let titles: [String] = ["当日有效", "3天有效", "一直有效"] self.showActionSheetController(title: "有效期", message: nil, cancelTitle: "取消", cancelBlock: {}, actionSheetTitles: titles) { (index, action) in switch index { case 0: /// 档期有效 self.validType = EValidType.VALIDTYPE_DR case 1: /// 3天有效 self.validType = EValidType.VALIDTYPE_ZDRQ if self.run == nil { /// 查询市场结算计划 self.queryMarketRun() } default: /// 一直有效 self.validType = EValidType.VALIDTYPE_YZ } } default: break } } // MARK: - 数据显示 /// 显示商品数据信息 /// - Parameter obj: obj func showGoodsInfo(_ myGoods: MoHsbyMyGoods?) { /// 异常 guard let obj = myGoods else { return } if obj.trademode == .TRADEMODE_LISTING_SELECT { /// 获取商品 guard let goodsInfo = MTP2BusinessCore.shared.goodsManager?.goodsInfos.first(where: {obj.goodsid == $0.goodsid}) else { return } /// 默认为一直有效 self.validType = .VALIDTYPE_DR /// 步进值 self.orderPrice.incrementDoubleNum = obj.stepvalue /// 小数位 self.orderPrice.decimalPlace = obj.decimalplace /// 最小值 self.orderPrice.minDoubleNum = obj.limitdown /// 最大值 self.orderPrice.maxDoubleNum = obj.limitup /// 委托价格 self.orderPrice.currentDoubleNumbers = goodsInfo.getLast() /// 最大可发布数量 self.orderQty.maxIntNum = obj.buymaxqty == 0 ? obj.enableqty : min(obj.enableqty, obj.buymaxqty) /// 最小数量 self.orderQty.minIntNum = obj.lotsize /// 当前数量 self.orderQty.currentIntNumbers = obj.lotsize /// 下单递增数量 self.orderQty.incrementIntNum = obj.lotsize /// 价格范围 self.priceRange.text = "\(obj.limitdown) <= 价格范围 <= \(obj.limitup)" /// 可发不数量 self.enableQty.text = "可发布数量 \(obj.enableqty)" /// 不允许操作 self.orderPrice.isUserInteractionEnabled = true } else { /// 最大可发布数量 self.orderQty.maxIntNum = obj.enableqty /// 不允许操作 self.orderPrice.isUserInteractionEnabled = false /// 最小数量 self.orderQty.minIntNum = obj.lotsize /// 当前数量 self.orderQty.currentIntNumbers = obj.lotsize /// 下单递增数量 self.orderQty.incrementIntNum = obj.lotsize /// 默认为一直有效 self.validType = .VALIDTYPE_YZ /// 小数位 self.orderPrice.decimalPlace = obj.decimalplace /// 步进值 self.orderPrice.incrementDoubleNum = obj.stepvalue ///  设置大小范围 self.orderPrice.minDoubleNum = Double.zero /// 最大值 self.orderPrice.maxDoubleNum = 10000000000.00 /// 委托价格 self.orderPrice.currentDoubleNumbers = obj.goodsprice } /// 商品名称 self.goods.setTitle("\(obj.goodscode) \(obj.goodsname) ▸", for: .normal) /// 可发不数量 self.enableQty.text = "可发布数量 \(obj.enableqty)" /// 隐藏 self.priceRange.isHidden = obj.trademode != .TRADEMODE_LISTING_SELECT } // MARK: - 接口请求 /// 买挂牌提交请求方法 fileprivate func doListingTrade() { /// 异常 guard let obj = myGoods, let tradeManager = MTP2BusinessCore.shared.tradeManager, check() else { return } /// 构建交易参数 let tradeParam = MoTradeParam() /// 买卖方向 tradeParam.buyOrSell = .ORDERDIRECTION_SELL /// 数量 tradeParam.orderQty = Double(orderQty.currentIntNumbers) /// 挂牌价格 tradeParam.orderPrice = orderPrice.currentDoubleNumbers /// 挂牌点选类型 tradeParam.delistingType = .DELISTINGTYPE_SELECTED /// 点选成交 tradeParam.listingSelectType = .LISTINGSELECTTYPE_LISTING /// 有效类型 tradeParam.validType = self.validType /// 下单类型 tradeParam.buildType = .BUILDTYPE_CLOSE /// 时间有效类型 tradeParam.timevalidType = self.validType /// 市场编号 tradeParam.marketID = obj.marketid /// 商品ID tradeParam.goodsID = obj.goodsid /// 指定时间 if tradeParam.validType == .VALIDTYPE_ZDRQ, let tradeDate = self.run?.tradedate { tradeParam.validTime = ((tradeDate.toDate(formatter: "yyyyMMdd") ?? Date())+3.days).getString(formatter: "yyyy-MM-dd 00:00:00") } /// 开启Loading NVActivityIndicatorPresenter.sharedInstance.startAnimating(ActivityData(message: "发布中......".localized, type: .ballClipRotate, color: UIColor.loding(), backgroundColor: .clear), NVActivityIndicatorView.DEFAULT_FADE_IN_ANIMATION) /// 发送请求 tradeManager.tradeCommision(tradeParam: tradeParam) { [weak self] (isSuccess, error, orderNo) in DispatchQueue.main.async { /// dismisss loding..... NVActivityIndicatorPresenter.sharedInstance.stopAnimating(NVActivityIndicatorView.DEFAULT_FADE_OUT_ANIMATION) if isSuccess { /// 返回上次视图 WHToast.showSuccess(withMessage: "发布请求成功", duration: 1.5) { self?.navigationController?.popViewController(animated: true) } } else { WHToast.showError(withMessage: "发布请求失败,\(ErrorUtils.getDesc(errorCode: error?.retCode ?? -99999) ?? "未知错误")", duration: 1.5, finishHandler: {}) } } } } /// 买摘牌提交请求方法 fileprivate func doDeListingTrade() { /// 异常 guard let obj = myGoods, let tradeManager = MTP2BusinessCore.shared.tradeManager, check() else { return } /// 构建交易参数 let tradeParam = MoTradeParam() /// 买卖方向 tradeParam.buyOrSell = .ORDERDIRECTION_SELL /// 挂牌点选类型 tradeParam.delistingType = .DELISTINGTYPE_SELECTED /// 点选成交 tradeParam.listingSelectType = .LISTINGSELECTTYPE_DELISTING /// 有效类型 tradeParam.validType = self.validType /// 下单类型 tradeParam.buildType = .BUILDTYPE_CLOSE /// 时间有效类型 tradeParam.timevalidType = self.validType /// 市场编号 tradeParam.marketID = obj.marketid /// 商品ID tradeParam.goodsID = obj.goodsid /// 指定时间 if tradeParam.validType == .VALIDTYPE_ZDRQ, let tradeDate = self.run?.tradedate { tradeParam.validTime = ((tradeDate.toDate(formatter: "yyyyMMdd") ?? Date())+3.days).getString(formatter: "yyyy-MM-dd 00:00:00") } /// 开启Loading NVActivityIndicatorPresenter.sharedInstance.startAnimating(ActivityData(message: "发布中......".localized, type: .ballClipRotate, color: UIColor.loding(), backgroundColor: .clear), NVActivityIndicatorView.DEFAULT_FADE_IN_ANIMATION) let group = DispatchGroup() /// 数据构建 for cell in orderTableView.visibleCells { if let cell = cell as? TradeCell, cell.isCheck { /// 挂牌价格 tradeParam.orderPrice = cell.model?.orderprice ?? 0.0 /// 关联单号 tradeParam.relatedID = UInt64(cell.model?.orderid ?? "0") ?? 0 /// 数量 tradeParam.orderQty = Double(cell.qtyField.currentIntNumbers) group.enter() tradeManager.tradeCommision(tradeParam: tradeParam) { (isSuccess, error, orderNo) in group.leave() } } } group.notify(queue: DispatchQueue.main) { /// dismisss loding..... NVActivityIndicatorPresenter.sharedInstance.stopAnimating(NVActivityIndicatorView.DEFAULT_FADE_OUT_ANIMATION) WHToast.showSuccess(withMessage: "委托成功,请刷新后查看!", duration: 1.5, finishHandler: { self.navigationController?.popViewController(animated: true) }) } } /// 查询商品对应委托单的数据信息 /// - Parameter price: 价格 fileprivate func requestQueryHsbyGoodsOrderDetails(_ price: String?) { /// 异常 guard let orderManager = MTP2BusinessCore.shared.orderManager, let obj = myGoods else { return } /// startAnimating self._anim?.startAnimating() /// 发送请求 orderManager.requestQueryHsbyGoodsOrderDetails(obj.goodsid, buyOrSell: .ORDERDIRECTION_BUY, price, 3) { (isComplete, error, orderDetails) in DispatchQueue.main.async { /// stopAnimating self._anim?.stopAnimating() if isComplete { /// 更新数据 self.orderDetails = orderDetails ?? [] } else { self.orderDetails = [] WHToast.showError(withMessage: "数据更新失败,原因:\(error?.retMsg ?? "未知错误")", duration: 1.5, finishHandler: {}) } } } } /// 查询交易日时间 fileprivate func queryMarketRun() { /// 异常 guard let goodsManger = MTP2BusinessCore.shared.goodsManager, let obj = myGoods else { return } /// startAnimating self._anim?.startAnimating() /// 获取交易日时间 goodsManger.requestQueryMarketRun(obj.marketid) { (isComplete, error, marketRun) in } } /// 查询"我的闲置"单据信息 /// - Parameter orderType: 单据类型:0 - 已发布(默认), 1 - 已完成 fileprivate func requestQueryHsbySellMyDetails(_ orderType: Int) { /// 异常 guard let orderManager = MTP2BusinessCore.shared.orderManager else { return } /// startAnimating self._anim?.startAnimating() /// 发送请求 orderManager.requestQueryHsbySellMyDetails(orderType, callback: { (isComplete, error, sellMyDetails) in DispatchQueue.main.async { /// stopAnimating self._anim?.stopAnimating() if isComplete { /// 更新数据 self.sellMyDetails = sellMyDetails ?? [] } else { self.sellMyDetails = [] WHToast.showError(withMessage: "数据更新失败,原因:\(error?.retMsg ?? "未知错误")", duration: 1.5, finishHandler: {}) } } }) } /// 获取待收款单据数据信息 fileprivate func requestQueryMyCollectionOrders() { /// 数据异常 guard let orderManager = MTP2BusinessCore.shared.orderManager else { return } /// startAnimating _anim?.startAnimating() /// 发送请求 orderManager.requestQueryMyCollectionOrders(callback: { (isComplete, error, collectionOrders) in DispatchQueue.main.async { /// stopAnimating self._anim?.stopAnimating() /// 单据数据信息 self.sellMyDetails = collectionOrders ?? [] if !isComplete { WHToast.showError(withMessage: "待付款单据数据信息查询失败,请稍候再试!", duration: 1.5, finishHandler: {}) } } }) } /// 撤单 /// /// - Parameter orderId: 单号 /// - Parameter accountId: accountId /// - Parameter goodsID: goodsID /// - Parameter marketID: marketID fileprivate func cancelOrder(_ orderId: String?, _ accountId: Int64?, _ goodsID: String?, _ marketID: Int?) { /// 数据异常 guard let tradeManager = MTP2BusinessCore.shared.tradeManager else { return } /// alert showCommitAlertController(title: "tips".localized, 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: { if self.segmentedView.selectedIndex == 1 { /// 待付款 self.requestQueryMyCollectionOrders() } else { /// 查询数据信息 self.requestQueryHsbySellMyDetails(self.segmentedView.selectedIndex) } }) } else { WHToast.showError(withMessage: "撤单失败,原因:\(ErrorUtils.getDesc(errorCode: errorInfo?.retCode ?? -60001) ?? "未知错误")", duration: 1.5, finishHandler: {}) } } }) } } /// 合规性校验 /// - Returns: Bool fileprivate func check() -> Bool { /// 请选择商品 guard let obj = myGoods else { WHToast.showError(withMessage: "请选择商品", duration: 1.5, finishHandler: {}) return false } /// 请输入委托价格 guard orderPrice.currentDoubleNumbers != 0.0 else { WHToast.showError(withMessage: "请输入委托价格", duration: 1.5, finishHandler: {}) return false } /// 挂牌点选 if obj.trademode == .TRADEMODE_LISTING_SELECT { /// 委托价格不在范围内 if orderPrice.currentDoubleNumbers < (obj.limitdown) || (orderPrice.currentDoubleNumbers > obj.limitup) { WHToast.showError(withMessage: "\(obj.limitdown)<=委托价格<=\(obj.limitup)", duration: 1.5, finishHandler: {}) return false } } /// 请输入交易数量 if orderQty.currentIntNumbers == 0 { WHToast.showError(withMessage: "请输入交易数量", duration: 1.5, finishHandler: {}) return false } return true } // MARK: - 订阅行情相关 var uuid: String = UUID().uuidString /// 行情订阅 private func subscriptQuote() { var goodsCodes = Set() if let goods = self.myGoods { goodsCodes = [goods.goodscode] } guard let quoteSubscriptManager = MTP2BusinessCore.shared.quoteSubscriptManager else { return } quoteSubscriptManager.updateQuoteSubcriptGoods(uuid: uuid, goodsCode: goodsCodes) } // 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. if segue.identifier == "ShowMyGoods" { (segue.destination as? MyGoodsViewController)?.block = { (_ model: MoHsbyMyGoods?) in /// 执行回调后 self.myGoods = model } } else if segue.identifier == "ShowMyUnusedDetail" { /// 我的闲置详情 (segue.destination as? MyUnusedDetailViewController)?.takeInfo = (sender as? OrderCell)?.model } } } // MARK: - JXSegmentedViewDelegate extension MyUnusedViewController: JXSegmentedViewDelegate { func segmentedView(_ segmentedView: JXSegmentedView, didSelectedItemAt index: Int) { if index == 1 { /// 待付款 self.requestQueryMyCollectionOrders() } else { /// 查询我的闲置单据数据 self.requestQueryHsbySellMyDetails(index) } } } // MARK: - IBNumberEditTextDelegate extension MyUnusedViewController: IBNumberEditTextDelegate { func numberInputViewDidEndEditing(_ numberInputView: IBNumberEditText) { if numberInputView == orderPrice { let orderPrice = numberInputView.currentDoubleNumbers /// 更新单据 self.requestQueryHsbyGoodsOrderDetails(orderPrice.toString(reserve: 2)) } else { /// 如果大于最大数量 默认设置最大数量 if numberInputView.currentIntNumbers > numberInputView.maxIntNum { numberInputView.currentIntNumbers = numberInputView.maxIntNum } } } func numberInputView(_ numberInputView: IBNumberEditText, _ buttonType: NumberInputViewButtonType) { if numberInputView == orderPrice { let orderPrice = numberInputView.currentDoubleNumbers /// 更新单据 self.requestQueryHsbyGoodsOrderDetails(orderPrice.toString(reserve: 2)) } else { /// 如果大于最大数量 默认设置最大数量 if numberInputView.currentIntNumbers > numberInputView.maxIntNum { numberInputView.currentIntNumbers = numberInputView.maxIntNum } } } func IBNumberEditText(textField: UITextField) {} } class OrderDelegate: NSCoder, UITableViewDelegate, UITableViewDataSource { let owner: MyUnusedViewController init(_ owner: MyUnusedViewController) { self.owner = owner } func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return self.owner.orderDetails.count } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: owner.OrderCellIdentifier, for: indexPath) as! TradeCell cell.model = self.owner.orderDetails[indexPath.row] cell.block = { (_ model: MoHsbyGoodsOrderDetail?, _ isCheck: Bool, _ qty: Int) in /// 设置数量 DispatchQueue.main.asyncAfter(deadline: DispatchTime.now()+0.2) { var qty: Int = 0 self.owner.orderTableView.visibleCells.forEach { (cell) in if (cell as! TradeCell).isCheck { qty += (cell as! TradeCell).qtyField.currentIntNumbers } } self.owner.qty = qty /// 输入框是否可用 self.owner.orderQty.isUserInteractionEnabled = !self.owner.orderTableView.visibleCells.contains(where: { (cell) -> Bool in return (cell as! TradeCell).isCheck }) } } return cell } func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { return 50.0 } } // MARK: - UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout class MyUnusedDelegate: NSCoder, UITableViewDelegate, UITableViewDataSource{ let owner: MyUnusedViewController init(_ owner: MyUnusedViewController) { self.owner = owner } func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return owner.sellMyDetails.count } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: owner.CellIdentifier, for: indexPath) as! SellMyDetailCell cell.model = owner.sellMyDetails[indexPath.row] cell.cancelBlock = { (_ orderId: String?, _ accountId: Int64?, _ goodsID: String?, _ marketID: Int?) in /// 撤销 self.owner.cancelOrder(orderId, accountId, goodsID, marketID) } return cell } func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { /// 待付款 if self.owner.segmentedView.selectedIndex == 1 { return 180.0 } else { return owner.sellMyDetails[indexPath.row].ordertype == 1 ? 180.0 : 200.0 } } } // MARK: - OrderCell class SellMyDetailCell: BaseTableViewCell { /// 供应商名称 @IBOutlet weak var company: UILabel! /// 状态 @IBOutlet weak var status: UILabel! /// 单号 @IBOutlet weak var orderNo: UILabel! /// 商品图片 @IBOutlet weak var goodsImage: UIImageView! /// 价格 @IBOutlet weak var price: UILabel! /// 标题 @IBOutlet weak var title: UILabel! /// 数量 @IBOutlet weak var qty: UILabel! /// 金额 @IBOutlet weak var amount: UILabel! /// 待付款金额 @IBOutlet weak var payamount: UILabel! /// 撤销 @IBOutlet weak var cancel: IBButton! /// 撤销 @IBOutlet weak var stackView: UIStackView! /// 数据 override var model: MoHsbySellMyDetail? { didSet { /// 数据异常 guard let obj = model else { return } if let collectionOrder = model as? MoMyCollectionOrders { /// 隐藏付款金额 payamount.isHidden = false /// 隐藏金额 amount.isHidden = true /// 金额详情 payamount.text = "总价:\(collectionOrder.tradeamount.toDownString(reserve: obj.decimalplace)) 优惠:\(collectionOrder.offamount.toDownString(reserve: obj.decimalplace)) 实付款:\(collectionOrder.payamount.toDownString(reserve: obj.decimalplace))" /// 数量 qty.text = obj.tradeqty.description /// 等待对方付款 status.text = "等待对方付款" /// 只有已发布的商品才可以撤销单据 stackView.isHidden = true } else { /// 隐藏付款金额 payamount.isHidden = true /// 待付款数量 amount.text = "金额:\(obj.currencysign) \((Double(obj.qty-obj.cancelqty-obj.tradeqty)*obj.price*obj.agreeunit).toDownString(reserve: obj.decimalplace))" /// 状态 if obj.buyorsell == EOrderDirection.ORDERDIRECTION_BUY { /// 已完成 status.text = "已完成" /// 只有已发布的商品才可以撤销单据 stackView.isHidden = true } else { status.text = obj.ordertype == 0 ? "已发布" : "已完成" /// 只有已发布的商品才可以撤销单据 stackView.isHidden = !(obj.ordertype == 0) } /// 数量 qty.text = obj.qty.description } /// 单号 orderNo.text = obj.goodscode /// 商品名称 title.text = obj.goodsname /// 价格 price.text = "\(obj.currencysign) \(obj.price.toDownString(reserve: obj.decimalplace))" /// 商品图片 guard let url = StringUtils.getImageUrl(obj.picurls) else { return } goodsImage.sd_setImage(with: url, placeholderImage: UIImage(named: "placeholder_image"), options: .queryDiskDataSync, context: nil) /// 我的闲置显示的是委托时间 company.text = DateUtils.getTDateString(obj.time, "yyyy-MM-dd HH:mm:ss") } } /// 撤销回调块 var cancelBlock: ((_ orderId: String?, _ accountId: Int64?, _ goodsID: String?, _ marketID: Int?) -> Void)? /// 支付回调块 var payBlock: ((_ orderId: String?, _ accountId: Int64?, _ goodsID: String?, _ marketID: Int?, _ amount: Double) -> Void)? /// 按钮点击响应事件 /// - Parameter sender: sender @IBAction private func onButtonPressed(_ sender: IBButton) { switch sender { case cancel: /// 撤销 if let cancel = cancelBlock { cancel(model?.orderid, model?.accountid ?? 0, model?.goodsid.description, model?.marketid) } default: break } } }