123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208 |
- //
- // OrderDetailViewController.swift
- // CommonFrame
- //
- // Created by Virgil on 2019/4/19.
- // Copyright © 2019 Virgil. All rights reserved.
- //
- import UIKit
- class OrderDetailViewController: BaseViewController, UITableViewDelegate, UITableViewDataSource {
- @IBOutlet weak var viewTopHeight: NSLayoutConstraint!
- @IBOutlet weak var viewTop: UIView!
- @IBOutlet weak var tableViewHeight: NSLayoutConstraint!
- @IBOutlet weak var tableView: UITableView!
- @IBOutlet weak var btnPay: UIButton!
- @IBOutlet weak var lblAddress: UILabel!
- @IBOutlet weak var lblPhone: UILabel!
- @IBOutlet weak var lblName: UILabel!
- // @IBOutlet weak var lblDate: UILabel!
- // @IBOutlet weak var lblMoney: UILabel!
- // @IBOutlet weak var lblNo: UILabel!
- var orderId = ""
- var arrTitle = ["订单号", "订单金额", "下单时间", "订单状态", "付款方式", "快递公司", "快递单号"]
- var arrContent = ["", "", "", "", "", "", "", ""]
- override func viewDidLoad() {
- super.viewDidLoad()
- self.title = "订单详情"
- initNavLeftBackButton()
- tableView.register(UINib(nibName: "OrderDetailTableViewCell", bundle: nil), forCellReuseIdentifier: "OrderDetailTableViewCell")
- tableView.delegate = self
- tableView.dataSource = self
- tableView.separatorStyle = .none
- tableView.showsVerticalScrollIndicator = false
- tableView.estimatedRowHeight = 100
- }
- var count = 0
- func initData() {
- lblName.text = "收货人:\(getString(key: "linkname"))"
- lblPhone.text = "手机号:\(getString(key: "linkphone"))"
- lblAddress.text = "收货地址:\(getString(key: "linkaddress"))"
- arrContent[0] = getString(key: "order_code")
- arrContent[1] = "¥\(getDoubleValue(key: "total"))"
- arrContent[2] = getString(key: "createtime")
- let delivery_type = getIntValue(key: "delivery_type")
- let paytype = getIntValue(key: "paytype")
- if paytype == 2 {
- arrContent[4] = "微信"
- } else {
- arrContent[4] = "支付宝"
- }
- let status = getIntValue(key: "status")
- if status == 0 {
- count = 4
- arrContent[3] = "未支付"
- btnPay.isHidden = false
- } else if status == 1 {
- count = 5
- arrContent[3] = "已支付,待发货"
- btnPay.isHidden = true
- } else if status == 2 {
- count = 7
- arrContent[3] = "已发货"
- btnPay.isHidden = false
- btnPay.setTitle("确认收货", for: .normal)
- } else if status == 3 {
- count = 7
- arrContent[3] = "已确认收货"
- btnPay.isHidden = true
- }
- if delivery_type == 1 {
- viewTopHeight.constant = 0
- if status == 0 {
- count = 4
- } else {
- count = 5
- }
- }
- btnPay.setCornerRadius(size: btnPay.height() / 2)
- arrContent[5] = getString(key: "courier_name")
- arrContent[6] = getString(key: "courier_code")
- tableViewHeight.constant = 45 * CGFloat(count)
- tableView.reloadData()
- }
- @IBAction func btnPayClick(_ sender: Any) {
- let status = getIntValue(key: "status")
- if status == 0 {
- let vc = PayShoppingMallViewController()
- vc.fromType = 1
- vc.orderId = dicData.getString(key: "id")
- vc.money = String.init(format: "%.2f", dicData.getDouble(key: "total"))
- toViewController(viewController: vc)
- } else if status == 2 {
- submitData()
- }
- }
- // MARK: =============加载数据===============
- func loadData() {
- let url = RequestURL.getProductOrderMain
- let params = NSMutableDictionary()
- params.setValue(orderId, forKey: "id")
- TloadDataInfo(url: url, params: params, tag: 1002)
- }
- func submitData() {
- let url = RequestURL.confirmOrder
- let params = NSMutableDictionary()
- params.setValue(orderId, forKey: "id")
- submitData(url: url, params: params, tag: 1001)
- }
- override func returnData(tag: Int) {
- if tag == 1001 {
- SVProgressHUD.showSuccess(withStatus: "确认收货成功")
- loadData()
- } else if tag == 1002 {
- let dicPro = dicData["productOrderlist"] as! NSArray
- dicData.setDic(dic: dicPro[0] as! NSDictionary)
- initData()
- }
- }
- override func returnError(tag: Int, type: String) {
- }
- // MARK: TABLEVLEW 实现
- func numberOfSections(in tableView: UITableView) -> Int {
- return 1
- }
- func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
- return count
- }
- func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
- return 45
- }
- func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
- let cell = tableView.dequeueReusableCell(withIdentifier: "OrderDetailTableViewCell", for: indexPath as IndexPath) as! OrderDetailTableViewCell
- cell.lblTitle.text = arrTitle[indexPath.row]
- cell.lblContent.isHidden = false
- cell.btnContent.isHidden = true
- if arrTitle[indexPath.row] == "订单金额" {
- let strPrice = arrContent[indexPath.row]
- cell.lblContent.attributedText = CommonViewUntils.getAttributedStringForFont(str: strPrice, rangs: [NSRange.init(location: 0, length: 1), NSRange.init(location: 1, length: strPrice.length() - 1)], fonts: [UIFont.systemFont(ofSize: 10), UIFont.systemFont(ofSize: 14)])
- } else if arrTitle[indexPath.row] == "快递单号" {
- if arrContent[indexPath.row] != "" {
- cell.lblContent.isHidden = true
- cell.btnContent.isHidden = false
- cell.btnContent.tag = indexPath.row
- cell.btnContent.addTarget(self, action: #selector(btnContentClick), for: .touchUpInside)
- cell.btnContent.setAttributedTitle(CommonViewUntils.getAttributedStringForFontUnderline(str: arrContent[indexPath.row], color: CommonUntils.getUIColorFromRGB(rgbValue: 0x2A92F7, alpha: 1.0), font: UIFont.systemFont(ofSize: 14)), for: .normal)
- }
- } else {
- cell.lblContent.text = arrContent[indexPath.row]
- }
- return cell
- }
- @objc func btnContentClick(btn: UIButton) {
- let vc = CommonWebViewViewController()
- vc.strTitle = "快递详情"
- vc.url = "https://m.kuaidi100.com/result.jsp?nu=\(arrContent[btn.tag])"
- toViewController(viewController: vc)
- }
- func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
- // let view = UIViewController()
- // view.oneGoId = self.arrData[indexPath.row]["ItemId"] as! Int
- // self.navigationController?.pushViewController(view, animated: true)
- }
- override func viewWillAppear(_ animated: Bool) {
- super.viewWillAppear(animated)
- loadData()
- }
- override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
- super.init(nibName: "OrderDetailViewController", bundle: nil)
- }
- required init?(coder aDecoder: NSCoder) {
- fatalError("init(coder:) has not been implemented")
- }
- }
|