// // PacketDetailViewController.swift // MTP2_iOS // // Created by Handy_Cao on 2020/10/29. // Copyright © 2020 Muchinfo. All rights reserved. // import UIKit import WHToast import SDWebImage /// 包裹明细视图容器控制类 class PacketDetailViewController: BaseViewController { // MARK: - 属性列表 /// 公司名称 @IBOutlet weak var company: UILabel! /// 状态 @IBOutlet weak var status: UILabel! /// 标题 @IBOutlet weak var goodsName: UILabel! /// 商品图片 @IBOutlet weak var goodsImage: UIImageView! /// 单号 @IBOutlet weak var orderNo: UILabel! /// 价格 @IBOutlet weak var price: UILabel! /// 金额 @IBOutlet weak var amount: UILabel! /// 数量 @IBOutlet weak var qty: UILabel! /// 物流单号 @IBOutlet weak var trackingNo: UILabel! /// 收货人 @IBOutlet weak var receiveName: UILabel! /// 收货人电话号码 @IBOutlet weak var receiveMobile: UILabel! /// 收货人地址 @IBOutlet weak var receiveAddress: UILabel! /// 复制 @IBOutlet weak var copyButton: UIButton! /// 确认收获按钮 @IBOutlet weak var submit: IBButton! /// @IBOutlet weak var logisticsView: UIView! /// 数据信息 var obj: MoHsbyMyPackages? { didSet { DispatchQueue.main.asyncAfter(deadline: DispatchTime.now()+0.5) { /// 显示详情 self.showPacketDetail() } } } // MARK: - 生命周期 override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. } // MARK: - 初始化 /// UI界面初始化 fileprivate func buildView() { /// addLoadingView self.addLoadingView() } // MARK: - 数据显示 fileprivate func showPacketDetail() { /// 异常 guard let model = obj else { return } /// 状态 status.text = model.takeorderstatus.description /// 供应商名称 company.text = model.vendorname /// 确认收货按钮 submit.isHidden = !(model.takeorderstatus == .UNRECEIVED) /// 标题 goodsName.text = model.goodsname /// 单号 orderNo.text = model.goodscode /// 价格 price.text = "\(model.currencysign) \(model.averageprice.toDownString(reserve: model.decimalplace))" /// 金额 amount.text = "金额:\(model.currencysign) \(model.amount)" /// 数量 qty.text = "×\(model.qty)" /// 物流单号 trackingNo.text = "物流单号:\(model.takeremark)" /// 收货人 receiveName.text = model.recivername /// 收货人电话号码 receiveMobile.text = model.phonenum /// 收货人地址 receiveAddress.text = model.address /// 隐藏视图 logisticsView.isHidden = model.takeorderstatus == .UNSEND /// 商品图片 guard let url = StringUtils.getImageUrl(model.picurls) else { return } goodsImage.sd_setImage(with: url, placeholderImage: UIImage(named: "placeholder_image"), options: .queryDiskDataSync, context: nil) } // MARK: - 交互相关 /// 按钮点击响应事件 /// - Parameter sender: sender @IBAction func onButtonPressed(_ sender: UIControl) { switch sender { case copyButton: /// 赋值按钮 let paste = UIPasteboard.general paste.string = obj?.takeremark WHToast.showSuccess(withMessage: "复制成功", duration: 1.5, finishHandler: {}) default: /// 异常 guard let model = obj else { return } /// show alert self.showAlertController(title: "提示", message: "确定要收货吗?", cancelTitle: "取消", sureTitle: "确认收货") {} sureBlock: { /// 确认提货 self.requestSetHsbyMyPackagesStatus(model.takeorderid) } } } // MARK: - 接口请求 /// 设置我的包裹已收货状态 /// - Parameter takeOrderID: 提货单号 fileprivate func requestSetHsbyMyPackagesStatus(_ takeOrderID: String?) { /// 异常 guard let orderManager = MTP2BusinessCore.shared.orderManager else { return } /// startAnimating _anim?.startAnimating() /// 发送请求 orderManager.requestSetHsbyMyPackagesStatus(takeOrderID ?? "") { (isComplete, error) in DispatchQueue.main.async { /// stopAnimating self._anim?.stopAnimating() if isComplete { WHToast.showSuccess(withMessage: "确认收货成功!", duration: 1.5, finishHandler: { /// 返回上层视图 self.navigationController?.popViewController(animated: true) }) } else { /// 查询失败 WHToast.showError(withMessage: "确认收货失败,原因:\(error?.retMsg ?? "未知错误")", 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. } */ }