PacketDetailViewController.swift 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. //
  2. // PacketDetailViewController.swift
  3. // MTP2_iOS
  4. //
  5. // Created by Handy_Cao on 2020/10/29.
  6. // Copyright © 2020 Muchinfo. All rights reserved.
  7. //
  8. import UIKit
  9. import WHToast
  10. import SDWebImage
  11. /// 包裹明细视图容器控制类
  12. class PacketDetailViewController: BaseViewController {
  13. // MARK: - 属性列表
  14. /// 公司名称
  15. @IBOutlet weak var company: UILabel!
  16. /// 状态
  17. @IBOutlet weak var status: UILabel!
  18. /// 标题
  19. @IBOutlet weak var goodsName: UILabel!
  20. /// 商品图片
  21. @IBOutlet weak var goodsImage: UIImageView!
  22. /// 单号
  23. @IBOutlet weak var orderNo: UILabel!
  24. /// 价格
  25. @IBOutlet weak var price: UILabel!
  26. /// 金额
  27. @IBOutlet weak var amount: UILabel!
  28. /// 数量
  29. @IBOutlet weak var qty: UILabel!
  30. /// 物流单号
  31. @IBOutlet weak var trackingNo: UILabel!
  32. /// 收货人
  33. @IBOutlet weak var receiveName: UILabel!
  34. /// 收货人电话号码
  35. @IBOutlet weak var receiveMobile: UILabel!
  36. /// 收货人地址
  37. @IBOutlet weak var receiveAddress: UILabel!
  38. /// 复制
  39. @IBOutlet weak var copyButton: UIButton!
  40. /// 确认收获按钮
  41. @IBOutlet weak var submit: IBButton!
  42. ///
  43. @IBOutlet weak var logisticsView: UIView!
  44. /// 数据信息
  45. var obj: MoHsbyMyPackages? {
  46. didSet {
  47. DispatchQueue.main.asyncAfter(deadline: DispatchTime.now()+0.5) {
  48. /// 显示详情
  49. self.showPacketDetail()
  50. }
  51. }
  52. }
  53. // MARK: - 生命周期
  54. override func viewDidLoad() {
  55. super.viewDidLoad()
  56. // Do any additional setup after loading the view.
  57. }
  58. // MARK: - 初始化
  59. /// UI界面初始化
  60. fileprivate func buildView() {
  61. /// addLoadingView
  62. self.addLoadingView()
  63. }
  64. // MARK: - 数据显示
  65. fileprivate func showPacketDetail() {
  66. /// 异常
  67. guard let model = obj else { return }
  68. /// 状态
  69. status.text = model.takeorderstatus.description
  70. /// 供应商名称
  71. company.text = model.vendorname
  72. /// 确认收货按钮
  73. submit.isHidden = !(model.takeorderstatus == .UNRECEIVED)
  74. /// 标题
  75. goodsName.text = model.goodsname
  76. /// 单号
  77. orderNo.text = model.goodscode
  78. /// 价格
  79. price.text = "\(model.currencysign) \(model.averageprice.toDownString(reserve: model.decimalplace))"
  80. /// 金额
  81. amount.text = "金额:\(model.currencysign) \(model.amount)"
  82. /// 数量
  83. qty.text = "×\(model.qty)"
  84. /// 物流单号
  85. trackingNo.text = "物流单号:\(model.takeremark)"
  86. /// 收货人
  87. receiveName.text = model.recivername
  88. /// 收货人电话号码
  89. receiveMobile.text = model.phonenum
  90. /// 收货人地址
  91. receiveAddress.text = model.address
  92. /// 隐藏视图
  93. logisticsView.isHidden = model.takeorderstatus == .UNSEND
  94. /// 商品图片
  95. guard let url = StringUtils.getImageUrl(model.picurls) else { return }
  96. goodsImage.sd_setImage(with: url, placeholderImage: UIImage(named: "placeholder_image"), options: .queryDiskDataSync, context: nil)
  97. }
  98. // MARK: - 交互相关
  99. /// 按钮点击响应事件
  100. /// - Parameter sender: sender
  101. @IBAction func onButtonPressed(_ sender: UIControl) {
  102. switch sender {
  103. case copyButton: /// 赋值按钮
  104. let paste = UIPasteboard.general
  105. paste.string = obj?.takeremark
  106. WHToast.showSuccess(withMessage: "复制成功", duration: 1.5, finishHandler: {})
  107. default:
  108. /// 异常
  109. guard let model = obj else { return }
  110. /// show alert
  111. self.showAlertController(title: "提示", message: "确定要收货吗?", cancelTitle: "取消", sureTitle: "确认收货") {} sureBlock: {
  112. /// 确认提货
  113. self.requestSetHsbyMyPackagesStatus(model.takeorderid)
  114. }
  115. }
  116. }
  117. // MARK: - 接口请求
  118. /// 设置我的包裹已收货状态
  119. /// - Parameter takeOrderID: 提货单号
  120. fileprivate func requestSetHsbyMyPackagesStatus(_ takeOrderID: String?) {
  121. /// 异常
  122. guard let orderManager = MTP2BusinessCore.shared.orderManager else { return }
  123. /// startAnimating
  124. _anim?.startAnimating()
  125. /// 发送请求
  126. orderManager.requestSetHsbyMyPackagesStatus(takeOrderID ?? "") { (isComplete, error) in
  127. DispatchQueue.main.async {
  128. /// stopAnimating
  129. self._anim?.stopAnimating()
  130. if isComplete {
  131. WHToast.showSuccess(withMessage: "确认收货成功!", duration: 1.5, finishHandler: {
  132. /// 返回上层视图
  133. self.navigationController?.popViewController(animated: true)
  134. })
  135. } else { /// 查询失败
  136. WHToast.showError(withMessage: "确认收货失败,原因:\(error?.retMsg ?? "未知错误")", duration: 1.5, finishHandler: {})
  137. }
  138. }
  139. }
  140. }
  141. /*
  142. // MARK: - Navigation
  143. // In a storyboard-based application, you will often want to do a little preparation before navigation
  144. override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
  145. // Get the new view controller using segue.destination.
  146. // Pass the selected object to the new view controller.
  147. }
  148. */
  149. }