CustomerViewController.swift 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. //
  2. // CustomerViewController.swift
  3. // MTP2_iOS
  4. //
  5. // Created by Handy_Cao on 2020/11/6.
  6. // Copyright © 2020 Muchinfo. All rights reserved.
  7. //
  8. import UIKit
  9. import WHToast
  10. import SDWebImage
  11. /// 客服视图容器控制类
  12. class CustomerViewController: BaseViewController {
  13. // MARK: - 属性列表
  14. /// 关闭按钮
  15. @IBOutlet weak var closed: UIButton!
  16. /// 复制按钮
  17. @IBOutlet weak var copyButton: UIButton!
  18. /// 电话号码
  19. @IBOutlet weak var mobile: UIButton!
  20. /// 供应商
  21. @IBOutlet weak var vendorname: UILabel!
  22. /// 供应商
  23. @IBOutlet weak var image: UIImageView!
  24. /// 商品详情数据
  25. var goodsDetail: MoGoodsInfo? {
  26. didSet {
  27. DispatchQueue.main.asyncAfter(deadline: DispatchTime.now()+0.5) {
  28. /// 显示商品详情信息
  29. self.showGoodsDetail()
  30. }
  31. }
  32. }
  33. // MARK: - 生命周期
  34. override func viewDidLoad() {
  35. super.viewDidLoad()
  36. // Do any additional setup after loading the view.
  37. }
  38. // MARK: - 数据显示
  39. /// 显示商品详情信息
  40. fileprivate func showGoodsDetail() {
  41. guard let obj = goodsDetail else { return }
  42. /// 电话号码
  43. mobile.setTitle(obj.vendorphone, for: .normal)
  44. /// 供应商
  45. vendorname.text = obj.vendorname
  46. /// 背景图片
  47. guard let url = StringUtils.getImageUrl(obj.vendorattr) else { return }
  48. image.sd_setImage(with: url, placeholderImage: UIImage(named: "placeholder_image"), options: .queryDiskDataSync, context: nil)
  49. }
  50. // MARK: - 交互相关
  51. /// onButtonPressed
  52. /// - Parameter sender: sender
  53. @IBAction func onButtonPressed(_ sender: UIButton) {
  54. switch sender {
  55. case closed: /// 关闭按钮
  56. self.dismiss(animated: true, completion: {})
  57. case copyButton: /// 复制按钮
  58. let pasteboard = UIPasteboard.general
  59. pasteboard.string = mobile.currentTitle
  60. WHToast.showSuccess(withMessage: "复制成功", duration: 1.5, finishHandler: {})
  61. default:
  62. guard let obj = goodsDetail else { return }
  63. let phone = "telprompt://" + obj.vendorphone
  64. if UIApplication.shared.canOpenURL(URL(string: phone)!) {
  65. UIApplication.shared.open(URL(string: phone)!, options: [:], completionHandler: nil)
  66. }
  67. }
  68. }
  69. /// onTapGestureRecognizer
  70. /// - Parameter sender: sender
  71. @IBAction fileprivate func onTapGestureRecognizer(_ sender: UITapGestureRecognizer) {
  72. self.dismiss(animated: true, completion: {})
  73. }
  74. /*
  75. // MARK: - Navigation
  76. // In a storyboard-based application, you will often want to do a little preparation before navigation
  77. override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
  78. // Get the new view controller using segue.destination.
  79. // Pass the selected object to the new view controller.
  80. }
  81. */
  82. }