123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423 |
- //
- // CreatShopOrderViewController.swift
- // xingchuangke
- //
- // Created by machaochao on 2020/10/13.
- // Copyright © 2020 Virgil. All rights reserved.
- //
- import UIKit
- class CreatShopOrderViewController: BaseViewController, UIScrollViewDelegate {
- @IBOutlet weak var viewExpress: UIView!
- @IBOutlet weak var btnExpress2: UIButton!
- @IBOutlet weak var btnExpress1: UIButton!
- @IBOutlet weak var btnExpressBtn3: UIButton!
- @IBOutlet weak var view1: UIView!
- @IBOutlet weak var btnAddress: UIButton!
- @IBOutlet weak var lblPhone: UILabel!
- @IBOutlet weak var lblAddress: UILabel!
- @IBOutlet weak var lblName: UILabel!
- let scrollView = UIScrollView.init()
- override func viewDidLoad() {
- super.viewDidLoad()
- initNavLeftBackButton()
- self.title = "确认订单"
- loadAddressList()
- btnExpress1.setCornerRadius(size: 3)
- btnExpress2.setCornerRadius(size: 3)
- btnExpressBtn3.setCornerRadius(size: 3)
- viewExpress.setCornerRadius(size: 8)
- btnExpress1.setTitleColor(.white, for: .normal)
- btnExpress2.setTitleColor(.white, for: .normal)
- btnExpressBtn3.setTitleColor(.white, for: .normal)
- self.creatGoodsList()
- // Do any additional setup after loading the view.
- }
- var dicAddress = NSDictionary()
- var name = ""
- var phone = ""
- var address1 = ""
- var address2 = ""
- ///0:顺丰1到付 2:自提
- var expressType = 0
- @IBAction func btnMenuClick(_ sender: AnyObject) {
- switch (sender as! UIButton).tag {
- case 1001: // 选择地址
- let vc = AddressListViewController()
- toViewController(viewController: vc)
- break
- case 1002: // 提交订单
- break
- case 1005: //
- break
- case 1006: //快递寄付
- self.expressType = 0
- // if(name == "" && expressType == 0)
- // {
- // SVProgressHUD.showError(withStatus: "请选择收货地址")
- // return;
- // }
- // if(name == "" && expressType == 2)
- // {
- // SVProgressHUD.showError(withStatus: "请选择收货地址")
- // return;
- // }
- btnExpress1.isSelected = true
- btnExpress2.isSelected = false
- btnExpressBtn3.isSelected = false
- btnExpress1.backgroundColor = CommonUntils.getUIColorFromRGB(rgbValue: 0x36a5fe, alpha: 1.0)
- btnExpress2.backgroundColor = CommonUntils.getUIColorFromRGB(rgbValue: 0xdddddd, alpha: 1.0)
- btnExpressBtn3.backgroundColor = CommonUntils.getUIColorFromRGB(rgbValue: 0xdddddd, alpha: 1.0)
- self.view1.isHidden = false
- self.view1.setSizeHeight(height: 90.0)
- self.scrollView.mj_y = view1.bottom()+10
- self.scrollView.setSizeHeight(height: kScreenHeight-self.view1.bottom()-20-45-navheight)
- self.getFreight()
- break
- case 1007: // 顺丰到付
- self.expressType = 2
- // if(name == "" && expressType == 0)
- // {
- // SVProgressHUD.showError(withStatus: "请选择收货地址")
- // return;
- // }
- // if(name == "" && expressType == 2)
- // {
- // SVProgressHUD.showError(withStatus: "请选择收货地址")
- // return;
- // }
- btnExpress1.isSelected = false
- btnExpress2.isSelected = true
- btnExpressBtn3.isSelected = false
- btnExpress1.backgroundColor = CommonUntils.getUIColorFromRGB(rgbValue: 0xdddddd, alpha: 1.0)
- btnExpress2.backgroundColor = CommonUntils.getUIColorFromRGB(rgbValue: 0x36a5fe, alpha: 1.0)
- btnExpressBtn3.backgroundColor = CommonUntils.getUIColorFromRGB(rgbValue: 0xdddddd, alpha: 1.0)
- self.view1.isHidden = false
- self.view1.setSizeHeight(height: 90.0)
- self.scrollView.mj_y = view1.bottom()+10
- self.scrollView.setSizeHeight(height: kScreenHeight-self.view1.bottom()-20-45-navheight)
- let strPrice2 = "¥\(String.init(format: "%.2f", self.allPrice))"
- self.hejiLable.text = strPrice2
- self.freight = 0.0
- break
- case 1008: // 上门自提
- self.expressType = 1
- btnExpress1.isSelected = false
- btnExpress2.isSelected = true
- btnExpressBtn3.isSelected = false
- btnExpress1.backgroundColor = CommonUntils.getUIColorFromRGB(rgbValue: 0xdddddd, alpha: 1.0)
- btnExpress2.backgroundColor = CommonUntils.getUIColorFromRGB(rgbValue: 0xdddddd, alpha: 1.0)
- btnExpressBtn3.backgroundColor = CommonUntils.getUIColorFromRGB(rgbValue: 0x36a5fe, alpha: 1.0)
- self.view1.setSizeHeight(height: 0.0)
- self.view1.isHidden = true
- self.scrollView.mj_y = viewExpress.bottom()+10
- self.scrollView.setSizeHeight(height: kScreenHeight-self.viewExpress.bottom()-20-45-navheight)
- let strPrice2 = "¥\(String.init(format: "%.2f", self.allPrice))"
- self.hejiLable.text = strPrice2
- self.freight = 0.0
- break
- default:
- break
- }
- }
- var goodsArray = NSArray.init()
- let hejiLable = UILabel.init()
- var allPrice: Float = 0
- var num: Int = 0
- var idstr = ""
- func creatGoodsList() {
- scrollView.delegate = self //设置代理
- let height = kScreenHeight-self.view1.bottom()-10-45-10-navheight
-
- scrollView.frame = CGRect(x: 0, y: self.view1.bottom()+10, width: kScreenWidth, height:height)//设置scrollview的大小
- scrollView.backgroundColor = self.view.backgroundColor//设置背景颜色
- scrollView.isPagingEnabled = true //是否支持分页
- scrollView.bounces = false //是否支持回弹效果
- scrollView.showsVerticalScrollIndicator = false //垂直滑动线隐藏
- scrollView.showsHorizontalScrollIndicator = false //水平滑动线隐藏
- //scrollView.contentInset = UIEdgeInsetsMake(10, 10, 10, 10) //设置内边距
- scrollView.contentSize = CGSize(width: kScreenWidth, height: CGFloat(goodsArray.count*100))
- self.view.addSubview(scrollView)
- for i in 0..<goodsArray.count {
- let goodsModel = goodsArray[i]as! YCOrderGoodsModel
- let viewb = UIView.init()
- viewb.frame = CGRect(x: 5, y: 10+100*i, width: Int(SCREEN_WIDTH-10), height: 90)
- viewb.backgroundColor = .white
- scrollView.addSubview(viewb)
- let imageView = UIImageView.init()
- imageView.frame = CGRect(x: 16, y: 16, width: 74, height: 74)
- imageView.sd_setImage(with: NSURL.init(string: goodsModel.goodsIconUrl!) as URL?)
- viewb.addSubview(imageView)
- let label = UILabel.init()
- label.frame = CGRect(x: 90, y: 0, width: Int(kScreenWidth-90), height: 30)
- label.textColor = .black
- label.text = goodsModel.goodsName
- viewb.addSubview(label)
- let labelT = UILabel.init()
- labelT.frame = CGRect(x: 90, y: 30, width: Int(kScreenWidth-90), height: 30)
- labelT.textColor = .gray
- labelT.text = "\(goodsModel.goodsCount!)件"
- viewb.addSubview(labelT)
- let labelTT = UILabel.init()
- labelTT.frame = CGRect(x: 90, y: 60, width: Int(kScreenWidth-90), height: 30)
- labelTT.textColor = .black
- labelTT.textColor = .red
- let price: String = goodsModel.goodsPrice!
- let priceNum: Float = Float(price)!
- let ccount: Int = goodsModel.goodsCount!
- self.num+=ccount
- self.allPrice += priceNum*Float(ccount)
- labelTT.text = "¥\(priceNum*Float(ccount))"
- viewb.addSubview(labelTT)
- if i == 0 {
- self.idstr = goodsModel.productId!
- } else {
- self.idstr = "\(self.idstr),\(goodsModel.productId!)"
- }
- }
- let bottomView = UIView.init()
- bottomView.frame = CGRect(x: 0, y: SCREEN_HEIGHT-45-navheight, width: SCREEN_WIDTH, height: 45)
- bottomView.backgroundColor = .white
- self.view.addSubview(bottomView)
- let label12 = UILabel.init()
- label12.frame = CGRect(x: 0, y: 0, width: 50, height: 45)
- label12.text = "合计:"
- bottomView.addSubview(label12)
- hejiLable.frame = CGRect(x: 50, y: 0, width: 150, height: 45)
- hejiLable.text = "\(self.allPrice)元"
- hejiLable.textColor = .red
- bottomView.addSubview(hejiLable)
- let jiesuanBtn = UIButton.init()
- jiesuanBtn.frame = CGRect(x: SCREEN_WIDTH-100, y: 0, width: 100, height: 45)
- jiesuanBtn.backgroundColor = .red
- jiesuanBtn.setTitle("提交订单", for: .normal)
- jiesuanBtn.addTarget(self, action: #selector(shopCarSettl), for: .touchUpInside)
- bottomView.addSubview(jiesuanBtn)
- }
- @objc func shopCarSettl() {
- if name == "" && expressType == 0 {
- SVProgressHUD.showError(withStatus: "请选择收货地址")
- return
- }
- if name == "" && expressType == 2 {
- SVProgressHUD.showError(withStatus: "请选择收货地址")
- return
- }
- let url = RequestURL.addProductOrderMain
- let params = NSMutableDictionary()
- params.setValue(self.idstr, forKey: "productIds")
- // params.setValue(num, forKey: "num")
- params.setValue(expressType, forKey: "deliveryType")
- params.setValue(CommonValue.getUserId(), forKey: "accountId")
- params.setValue(self.allPrice, forKey: "total")
- params.setValue(self.freight, forKey: "freight")
- if expressType == 0 || expressType == 2 {
- if lblName.text!.length() > 4 {
- params.setValue(lblName.text!.substringFrom(index: 4), forKey: "linkname")
- } else {
- params.setValue("", forKey: "linkname")
- }
- if lblAddress.text!.length() > 5 {
- params.setValue(lblAddress.text!.substringFrom(index: 5), forKey: "linkaddress")
- } else {
- params.setValue("", forKey: "linkaddress")
- }
- if lblPhone.text!.length() > 5 {
- params.setValue(lblPhone.text!.substringFrom(index: 5), forKey: "linkphone")
- } else {
- params.setValue("", forKey: "linkphone")
- }
- } else {
- params.setValue("", forKey: "linkname")
- params.setValue("", forKey: "linkaddress")
- params.setValue("", forKey: "linkphone")
- }
- print(params)
- let http = AFHTTPSessionManager()
- http.post(url, parameters: params, progress: { (_) in
- }, success: { (operation, json) in
- print(json as Any)
- let success = (json as! NSDictionary).object(forKey: "statusCode") as! Int
- if success == 200 {
- let orderId = (json as! NSDictionary).object(forKey: "data") as! String
- let vc = PayShoppingMallViewController()
- vc.orderId = orderId
- if self.expressType == 0 {
- vc.money = "\(String.init(format: "%.2f", Float(self.freight)+self.allPrice))"
- } else {
- vc.money = "\(String.init(format: "%.2f", self.allPrice))"
- }
- self.toViewController(viewController: vc)
- }
- }) { (_, _) in
- }
- // submitData(url: url, params: params, tag: 1001)
- }
- var freight = 0.0
- func getFreight() {
- print(dicData)
- if name == ""{
- return
- }
- let params = NSMutableDictionary()
- params.setValue(dicAddress["province_name"], forKey: "province")
- params.setValue(dicAddress["city_name"], forKey: "city")
- params.setValue(self.weight, forKey: "weight")
- let http = AFHTTPSessionManager()
- http.post(RequestURL.getFreight, parameters: params, progress: { (_) in
- }, success: { (operation, json) in
- print(json as Any)
- let success = (json as! NSDictionary).object(forKey: "statusCode") as! Int
- if success == 200 {
- let Freight = (json as! NSDictionary).object(forKey: "data") as! Float
- self.freight = Double(Freight)
- let strPrice2 = "¥\(String.init(format: "%.2f", self.allPrice+Freight))含运费:\(Freight)元"
- let str4 = "¥\(String.init(format: "%.2f", self.allPrice+Freight))"
- self.hejiLable.attributedText = CommonViewUntils.getAttributedStringForFont(str: strPrice2, rangs: [NSRange.init(location: str4.length(), length: strPrice2.length()-str4.length()), NSRange.init(location: str4.length(), length: strPrice2.length() - str4.length())], fonts: [UIFont.systemFont(ofSize: 10), UIFont.systemFont(ofSize: 10)])
- }
- }) { (_, _) in
- }
- }
- var weight: Double = 0.0
- func getWeight() {
- if self.expressType == 0 {
- } else {
- return
- }
- let url = RequestURL.getGoPayProductList
- let params = NSMutableDictionary()
- params.setValue(self.idstr, forKey: "DATA_IDS")
- params.setValue(CommonValue.getUserId(), forKey: "userId")
- let http = AFHTTPSessionManager()
- http.get(url, parameters: params, progress: { (_) in
- }, success: { (operation, json) in
- print(json as Any)
- let success = (json as! NSDictionary).object(forKey: "statusCode") as! Int
- if success == 200 {
- let dic = (json as! NSDictionary).object(forKey: "data") as! NSDictionary
- self.weight = dic["sum"]as!Double
- self.getFreight()
- }
- }) { (_, _) in
- }
- }
- /*
- // 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.
- }
- */
- override func viewWillAppear(_ animated: Bool) {
- super.viewWillAppear(animated)
- self.loadAddressList()
- let strPrice2 = "¥\(String.init(format: "%.2f", self.allPrice))"
- self.hejiLable.text = strPrice2
- self.getWeight()
- }
- override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
- super.init(nibName: "CreatShopOrderViewController", bundle: nil)
- }
- required init?(coder aDecoder: NSCoder) {
- fatalError("init(coder:) has not been implemented")
- }
- func loadAddressList() {
- let params = NSMutableDictionary()
- params.setValue(CommonValue.getUserId(), forKey: "userId")
- params.setValue(1, forKey: "currentPage")
- params.setValue(1, forKey: "showCount")
- let http = AFHTTPSessionManager()
- http.get(RequestURL.getUserAddressList, parameters: params, progress: { (_) in
- }, success: { (operation, json) in
- print(json as Any)
- let success = (json as! NSDictionary).object(forKey: "statusCode") as! Int
- if success == 200 {
- let dic = (json as! NSDictionary).object(forKey: "data") as! NSDictionary
- let addressArray = dic["addressList"]as!NSArray
- if addressArray.count>0 {
- let defaultAddressDic = addressArray[0] as! NSDictionary
- self.dicAddress = defaultAddressDic
- if defaultAddressDic["is_default"]as!String == "1"{
- self.btnAddress.setTitle("", for: .normal)
- self.lblName.text = "收货人:\(defaultAddressDic["link_name"]as!String)"
- self.name = defaultAddressDic["link_name"]as!String
- self.lblPhone.text = "联系方式:\(defaultAddressDic["link_phone"]as!String)"
- self.lblAddress.text = "收货地址:\(defaultAddressDic["province_name"]as!String)\(defaultAddressDic["city_name"]as!String)\(defaultAddressDic["area_name"]as!String)\(defaultAddressDic["address"]as!String)"
- } else {
- self.btnAddress.setTitle("请选择地址", for: .normal)
- self.lblName.text = ""
- self.lblPhone.text = ""
- self.lblAddress.text = ""
- self.name = ""
- }
- } else {
- self.btnAddress.setTitle("请选择地址", for: .normal)
- self.lblName.text = ""
- self.lblPhone.text = ""
- self.lblAddress.text = ""
- self.name = ""
- }
- }
- }) { (_, _) in
- }
- }
- }
|