MyUnusedDetailViewController.swift 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. //
  2. // MyUnusedDetailViewController.swift
  3. // MTP2_iOS
  4. //
  5. // Created by 曹晓亮 on 2020/12/19.
  6. // Copyright © 2020 Muchinfo. All rights reserved.
  7. //
  8. import UIKit
  9. import WHToast
  10. /// 我的闲置单据详情视图容器控制类
  11. class MyUnusedDetailViewController: BaseViewController {
  12. // MARK: - 属性列表
  13. /// 主滚动视图
  14. @IBOutlet weak var scrollView: UIScrollView!
  15. /// 订单编号
  16. @IBOutlet weak var orderNo: UILabel!
  17. /// 订单时间
  18. @IBOutlet weak var orderTime: UILabel!
  19. /// 商品图片
  20. @IBOutlet weak var goodsImage: UIImageView!
  21. /// 商品名称
  22. @IBOutlet weak var goodsName: UILabel!
  23. /// 商品代码
  24. @IBOutlet weak var goodsCode: UILabel!
  25. /// 价格
  26. @IBOutlet weak var price: UILabel!
  27. /// 金额
  28. @IBOutlet weak var amount: UILabel!
  29. /// 数量
  30. @IBOutlet weak var qty: UILabel!
  31. /// 付款数量
  32. @IBOutlet weak var payQty: UILabel!
  33. /// 数据展示列表
  34. @IBOutlet weak var tableView: UITableView!
  35. /// tableViewHeightConstraint
  36. @IBOutlet weak var tableViewHeightConstraint: NSLayoutConstraint! {
  37. didSet {
  38. tableViewHeightConstraint.constant = 0.0
  39. }
  40. }
  41. /// 撤销剩余数量
  42. @IBOutlet weak var cancel: UIButton!
  43. /// cellIdentifier
  44. let cellIdentifier = "MyUnusedDetail_Cell"
  45. /// collectionOrders
  46. var collectionOrders: [MoMyCollectionOrders] = [] {
  47. didSet {
  48. /// 刷新数据
  49. tableView.reloadData()
  50. /// 列表高度
  51. tableViewHeightConstraint.constant = (CGFloat(collectionOrders.count)*160.0)+35.0
  52. }
  53. }
  54. /// 数据信息
  55. override var takeInfo: Any? {
  56. didSet {
  57. }
  58. }
  59. // MARK: - 生命周期
  60. override func viewDidLoad() {
  61. super.viewDidLoad()
  62. // Do any additional setup after loading the view.
  63. /// UI界面初始化
  64. buildView()
  65. }
  66. // MARK: - 初始化相关
  67. /// UI界面初始化
  68. fileprivate func buildView() {
  69. /// addLoadingView
  70. addLoadingView()
  71. /// 单据数据显示
  72. showOrderInfo()
  73. }
  74. // MARK: - 显示相关
  75. /// 单据数据显示
  76. fileprivate func showOrderInfo() {
  77. guard let obj = takeInfo as? MoHsbySellMyDetail else {
  78. return
  79. }
  80. /// 订单编号
  81. orderNo.text = "订单编号:\(obj.orderid)"
  82. /// 订单时间
  83. orderTime.text = DateUtils.getTDateString(obj.ordertime, "yyyy-MM-dd HH:mm:ss")
  84. /// 商品名称
  85. goodsName.text = obj.goodsname
  86. /// 价格
  87. price.text = "\(obj.currencysign) \(obj.price)"
  88. /// 金额
  89. amount.text = "金额:\(obj.amount)"
  90. /// 数量
  91. qty.text = obj.qty.description
  92. /// 付款详情
  93. payQty.text = "已付款数量:\(obj.orderqty) 待付款数量:\(obj.tradeqty) 剩余数量:\(obj.orderqty-obj.tradeqty-obj.cancelqty)"
  94. /// 是否隐藏撤单按钮
  95. cancel.isHidden = !(obj.ordertype == 0)
  96. /// 商品图片
  97. guard let url = StringUtils.getImageUrl(obj.picurls) else { return }
  98. goodsImage.sd_setImage(with: url, placeholderImage: UIImage(named: "placeholder_image"), options: .queryDiskDataSync, context: nil)
  99. /// 查询待付款单据数据信息
  100. self.requestQueryMyCollectionOrders()
  101. }
  102. // MARK: - 交互相关
  103. /// onButtonPressed
  104. /// - Parameter sender: sender
  105. @IBAction fileprivate func onButtonPressed(_ sender: UIButton) {
  106. switch sender {
  107. case cancel:
  108. guard let obj = takeInfo as? MoHsbySellMyDetail else {
  109. return
  110. }
  111. /// 撤销单据
  112. cancelOrder(obj.orderid, obj.accountid, "\(obj.goodsid)", obj.marketid)
  113. default:
  114. break
  115. }
  116. }
  117. // MARK: - 接口请求
  118. /// 获取待付款单据数据信息
  119. fileprivate func requestQueryMyCollectionOrders() {
  120. /// 数据异常
  121. guard let orderManager = MTP2BusinessCore.shared.orderManager else { return }
  122. /// startAnimating
  123. _anim?.startAnimating()
  124. /// 发送请求
  125. orderManager.requestQueryMyCollectionOrders(callback: { (isComplete, error, orders) in
  126. DispatchQueue.main.async {
  127. /// stopAnimating
  128. self._anim?.stopAnimating()
  129. if isComplete {
  130. /// 单据数据信息
  131. self.collectionOrders = orders ?? []
  132. } else {
  133. WHToast.showError(withMessage: "待付款单据数据信息查询失败,请稍候再试!", duration: 1.5, finishHandler: {})
  134. }
  135. }
  136. })
  137. }
  138. /// 撤单
  139. ///
  140. /// - Parameter orderId: 单号
  141. fileprivate func cancelOrder(_ orderId: String?, _ accountId: Int64?, _ goodsID: String?, _ marketID: Int?) {
  142. /// 数据异常
  143. guard let tradeManager = MTP2BusinessCore.shared.tradeManager else { return }
  144. /// alert
  145. showCommitAlertController(title: "提示", message: "确定要撤单吗?"){(_) in
  146. /// startAnimating
  147. self._anim?.startAnimating()
  148. /// 构建数据
  149. let cancelOrderData = CancelOrderData(oldOrderId: orderId ?? "", accountId: accountId ?? 0, goodsID: goodsID ?? "", marketID: marketID ?? 0, operateType: .OPERATETYPE_ORDERCANCEL)
  150. /// 发送撤单请求
  151. tradeManager.cancelOrder(cancelorderData: cancelOrderData, callback: { (isCompleted, errorInfo) in
  152. DispatchQueue.main.async {
  153. /// stopAnimating
  154. self._anim?.stopAnimating()
  155. if isCompleted {
  156. WHToast.showSuccess(withMessage: "撤销成功", duration: 1.5, finishHandler: {
  157. /// 返回上层视图
  158. self.navigationController?.popViewController(animated: true)
  159. })
  160. } else {
  161. WHToast.showError(withMessage: "撤单失败,原因:\(ErrorUtils.getDesc(errorCode: errorInfo?.retCode ?? -60001) ?? "未知错误")", duration: 1.5, finishHandler: {})
  162. }
  163. }
  164. })
  165. }
  166. }
  167. /*
  168. // MARK: - Navigation
  169. // In a storyboard-based application, you will often want to do a little preparation before navigation
  170. override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
  171. // Get the new view controller using segue.destination.
  172. // Pass the selected object to the new view controller.
  173. }
  174. */
  175. }
  176. // MARK: - UITableViewDelegate, UITableViewDataSource
  177. extension MyUnusedDetailViewController: UITableViewDelegate, UITableViewDataSource {
  178. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  179. return collectionOrders.count
  180. }
  181. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  182. let cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier, for: indexPath) as! MyUnusedDetailCell
  183. cell.model = collectionOrders[indexPath.row]
  184. return cell
  185. }
  186. func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
  187. return 160.0
  188. }
  189. }
  190. // MARK: - MyUnusedDetailCell
  191. class MyUnusedDetailCell: BaseTableViewCell<MoMyCollectionOrders> {
  192. // MARK: - 属性列表
  193. /// 订单时间
  194. @IBOutlet weak var orderTime: UILabel!
  195. /// 订单状态
  196. @IBOutlet weak var status: UILabel!
  197. /// 购买人
  198. @IBOutlet weak var userName: UILabel!
  199. /// 购买价格
  200. @IBOutlet weak var price: UILabel!
  201. /// 购买数量
  202. @IBOutlet weak var qty: UILabel!
  203. /// 购买金额数据
  204. @IBOutlet weak var amount: UILabel!
  205. /// 数据Model
  206. override var model: MoMyCollectionOrders? {
  207. didSet {
  208. guard let obj = model else {
  209. return
  210. }
  211. /// 订单时间
  212. orderTime.text = DateUtils.getTDateString(obj.ordertime, "yyyy-MM-dd HH:mm")
  213. /// 订单状态
  214. status.text = obj.payflag.description
  215. /// 购买人
  216. userName.text = obj.buyorderid
  217. /// 购买价格
  218. price.text = "\(obj.currencysign) \(obj.tradeprice.toDownString(reserve: obj.decimalplace))"
  219. /// 购买数量
  220. qty.text = obj.tradeqty.description
  221. /// 购买金额数据
  222. amount.text = "总价:\(obj.currencysign)\(obj.tradeamount) 优惠:\(obj.currencysign)\(obj.offamount) 实付款:\(obj.currencysign)\(obj.payamount)"
  223. }
  224. }
  225. }