123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586 |
- //
- // OderDetailHeadView.swift
- // ADHTuanCan
- //
- // Created by 敖德亨 on 2023/11/4.
- //
- import UIKit
- class OderDetailHeadView: UIView {
-
- @IBOutlet weak var btnView: UIView!
-
- /// 时间提示View
- @IBOutlet weak var timeView: UIView!
-
- /// 介绍状态View
- @IBOutlet weak var detailView: UIView!
-
- /// 配送中View
- @IBOutlet weak var deliveringView: UIView!
-
- /// 介绍状态
- @IBOutlet weak var tipLab: UILabel!
-
- /// 二级介绍状态
- @IBOutlet weak var secTipLab: UILabel!
-
-
- /// 订单取消TypeLab
- @IBOutlet weak var cancelLab: UILabel!
-
- /// 配送
- @IBOutlet weak var deliveryView: UIView!
-
- /// 超时取消
- @IBOutlet weak var timeOutView: UIView!
-
- /// 去支付BtnV
- @IBOutlet weak var payBtnView: UIView!
-
- /// 地址BtnV
- @IBOutlet weak var addressBtnView: UIView!
-
- /// 再次购买BtnV
- @IBOutlet weak var buyAgainBtnView: UIView!
-
- /// 确认收货BtnV
- @IBOutlet weak var receivingBtnView: UIView!
-
- /// 去评价BtnV
- @IBOutlet weak var evaluateBtnView: UIView!
-
- /// 联系商家BtnV
- @IBOutlet weak var callBtnView: UIView!
-
- /// 取消订单BtnV
- @IBOutlet weak var cancelBtnView: UIView!
-
- /// 订单状态
- @IBOutlet weak var typeLab: UILabel!
-
- /// 下单时间
- @IBOutlet weak var makeOrdrtTime: UILabel!
-
- /// 配送时间
- @IBOutlet weak var deliveryTme: UILabel!
-
- /// 地址
- @IBOutlet weak var addressLab: UILabel!
-
- /// 邮编
- @IBOutlet weak var postCodeLab: UILabel!
-
- /// 电话
- @IBOutlet weak var phoneLab: UILabel!
-
- /// 收货人
- @IBOutlet weak var nameLab: UILabel!
-
- /// 1去支付 2修改地址 3再来一单 4确认收货 5去评价 6联系商家 7取消订单
- var headBtnBlock : ((Int)->Void)?
-
- var dataModel : OrderOutDetailModel?
-
-
- //进入后台时存储当前时间
- var becomeDeathTime: Date!
- //进入前台时存储当前时间
- var becomeActiveTime: Date!
-
- /// 计时器
- var codeTimer: DispatchSourceTimer!
-
- var time = 60
-
- var minutes = 0
-
- var second = 0
-
- override func awakeFromNib() {
- super.awakeFromNib()
- }
-
- func configModel(model : OrderOutDetailModel){
-
- self.dataModel = model
-
- self.makeOrdrtTime.text = "\(model.createTime ?? "")"
- self.deliveryTme.text = "\(model.deliveryTime ?? "")"
- self.addressLab.text = "\(model.detailAddress ?? "")"
- self.addressLab.sizeToFit()
- self.postCodeLab.text = "\(model.postcode ?? "")"
- self.phoneLab.text = "\(model.phoneNum ?? "")"
- self.nameLab.text = "\(model.receiving ?? "")"
- self.addressLab.sizeToFit()
-
-
- self.timeView.isHidden = true
- self.detailView.isHidden = true
- self.deliveryView.isHidden = true
- self.timeOutView.isHidden = true
- self.deliveringView.isHidden = true
-
- self.setBtnView()
-
-
- self.minutes = model.minutes ?? 0
- self.second = model.seconds ?? 0
-
- self.time = self.minutes * 60 + self.second
-
- if self.time > 0{
- self.codeCountdown(isCodeTimer: true)
- }
- }
-
- func setBtnView(){
-
- // ///改收货地址按钮,为0隐藏,为1显示
- // var alterAddress : String?
- // ///取消订单按钮,为0隐藏,为1显示
- // var cancel : String?
- // ///联系商家按钮,为0隐藏,为1显示
- // var contact : String?
- // ///确认收货按钮,为0隐藏,为1显示
- // var toConfirm : String?
- // /// 去支付按钮,为0隐藏,为1显示
- // var toPay : String?
- // ///去评价按钮,为0隐藏,为1显示
- // var toReview : String?
-
- self.buyAgainBtnView.isHidden = true
- var isShowBtn : Bool = false
-
- if self.dataModel?.alterAddress === 1{
- self.addressBtnView.isHidden = false
- isShowBtn = true
- }else{
- self.addressBtnView.isHidden = true
- }
-
- if self.dataModel?.cancel === 1{
- self.cancelBtnView.isHidden = false
- isShowBtn = true
- }else{
- self.cancelBtnView.isHidden = true
- }
-
- if self.dataModel?.toConfirm === 1{
- self.receivingBtnView.isHidden = false
- isShowBtn = true
- }else{
- self.receivingBtnView.isHidden = true
- }
-
- if self.dataModel?.toPay === 1{
- self.payBtnView.isHidden = false
- isShowBtn = true
- }else{
- self.payBtnView.isHidden = true
- }
-
- if self.dataModel?.toReview === 1{
- self.evaluateBtnView.isHidden = false
- isShowBtn = true
- }else{
- self.evaluateBtnView.isHidden = true
- }
-
- if self.dataModel?.contact === 1{
- self.callBtnView.isHidden = false
- isShowBtn = true
- }else{
- self.callBtnView.isHidden = true
- }
-
-
- let labHeight : CGFloat = (self.addressLab.frame.size.height)
- var btnViewHeight : CGFloat = 0
-
- if isShowBtn{
- self.btnView.isHidden = false
- btnViewHeight = 100
- }else{
- self.btnView.isHidden = true
- btnViewHeight = 0
- }
-
- if self.addressLab.text.isNotEmptyStr{
- self.setFrameSize(CGSize.init(width: kSCREEN_WIDTH, height:135 + labHeight + 30 + 100 + btnViewHeight + 100))
- }else{
- self.setFrameSize(CGSize.init(width: kSCREEN_WIDTH, height:155 + 30 + 100 + 100 + 100 + btnViewHeight))
- }
-
-
- let status : String = "\(self.dataModel!.orderStatus ?? "")"
- if status === 1{
- self.timeView.isHidden = false
- self.detailView.isHidden = false
- self.deliveryView.isHidden = true
- self.timeOutView.isHidden = true
- self.deliveringView.isHidden = true
- self.typeLab.text = LanguagesUtil.createTextBy(Ctext: "待支付", Etext: "Wait for payment")
- self.tipLab.text = LanguagesUtil.createTextBy(Ctext: "待支付,请立即支付", Etext: "Please pay as soon as possible")
- if self.addressLab.text.isNotEmptyStr{
- self.setFrameSize(CGSize.init(width: kSCREEN_WIDTH, height: 60 + self.timeView.height + self.detailView.height + 135 + labHeight + btnViewHeight + 70))
-
- }else{
- self.setFrameSize(CGSize.init(width: kSCREEN_WIDTH, height: 60 + self.timeView.height + self.detailView.height + 155 + btnViewHeight + 70))
- }
-
- }
- if status === 2{
- //待接单
- self.timeView.isHidden = true
- self.detailView.isHidden = false
- self.deliveryView.isHidden = true
- self.timeOutView.isHidden = true
- self.deliveringView.isHidden = true
- self.typeLab.text = LanguagesUtil.createTextBy(Ctext: "待商家接单", Etext: "Waiting fo accept the order")
- self.tipLab.text = LanguagesUtil.createTextBy(Ctext: "已成功下单,感谢您对KINA SENG的信任", Etext: "Order has been successfully placed, thank you for your trust in KINA SENG")
- self.secTipLab.text = ""
- if self.addressLab.text.isNotEmptyStr{
- self.setFrameSize(CGSize.init(width: kSCREEN_WIDTH, height: 60 + self.detailView.height + 135 + labHeight + btnViewHeight + 70))
-
- }else{
- self.setFrameSize(CGSize.init(width: kSCREEN_WIDTH, height: 60 + self.detailView.height + 155 + btnViewHeight + 70))
- }
- }
- if status === 3{
- //待配送
- self.timeView.isHidden = true
- self.detailView.isHidden = true
- self.deliveryView.isHidden = false
- self.timeOutView.isHidden = true
- self.deliveringView.isHidden = true
- self.typeLab.text = LanguagesUtil.createTextBy(Ctext: "订单待配送", Etext: "Waiting for delivery")
- self.tipLab.text = LanguagesUtil.createTextBy(Ctext: "", Etext: "")
-
- if self.addressLab.text.isNotEmptyStr{
- self.setFrameSize(CGSize.init(width: kSCREEN_WIDTH, height: 60 + self.deliveryView.height + 135 + labHeight + btnViewHeight + 70))
-
- }else{
- self.setFrameSize(CGSize.init(width: kSCREEN_WIDTH, height: 60 + self.deliveryView.height + 155 + btnViewHeight + 70))
- }
- }
- if status === 4{
- //已完成未评价
- self.timeView.isHidden = true
- self.detailView.isHidden = false
- self.deliveryView.isHidden = true
- self.timeOutView.isHidden = true
- self.deliveringView.isHidden = true
- self.typeLab.text = LanguagesUtil.createTextBy(Ctext: "订单已完成", Etext: "Order completed")
- self.tipLab.text = LanguagesUtil.createTextBy(Ctext: "感谢您对KINA SENG的信任,欢迎再次光临", Etext: "Thank you for your trust in KINA SENG and welcome to visit us again")
- self.secTipLab.text = ""
- if self.addressLab.text.isNotEmptyStr{
- self.setFrameSize(CGSize.init(width: kSCREEN_WIDTH, height: 60 + self.detailView.height + 135 + labHeight + btnViewHeight + 70))
-
- }else{
- self.setFrameSize(CGSize.init(width: kSCREEN_WIDTH, height: 60 + self.detailView.height + 155 + btnViewHeight + 70))
- }
- }
- if status === 5{
- //已取消
- self.timeView.isHidden = true
- self.detailView.isHidden = true
- self.deliveryView.isHidden = true
- self.timeOutView.isHidden = false //超时
- self.deliveringView.isHidden = true
- self.typeLab.text = LanguagesUtil.createTextBy(Ctext: "订单已取消", Etext: "Order cancelled")
- self.cancelLab.text = LanguagesUtil.createTextBy(Ctext: "该订单已经取消,期待您的下次光临", Etext: "The order has been cancelled and we look forward to your next visit")
-
- if self.addressLab.text.isNotEmptyStr{
- self.setFrameSize(CGSize.init(width: kSCREEN_WIDTH, height: 60 + self.timeOutView.height + 135 + labHeight + btnViewHeight + 70))
-
- }else{
- self.setFrameSize(CGSize.init(width: kSCREEN_WIDTH, height: 60 + self.timeOutView.height + 155 + btnViewHeight + 70))
- }
- }
- if status === 6{
- //退款中
- self.timeView.isHidden = true
- self.detailView.isHidden = true
- self.deliveryView.isHidden = true
- self.timeOutView.isHidden = false
- self.deliveringView.isHidden = true
- self.typeLab.text = LanguagesUtil.createTextBy(Ctext: "订单退款中", Etext: "Order refund process")
-
- if self.addressLab.text.isNotEmptyStr{
- self.setFrameSize(CGSize.init(width: kSCREEN_WIDTH, height: 60 + self.timeOutView.height + 135 + labHeight + btnViewHeight + 70))
-
- }else{
- self.setFrameSize(CGSize.init(width: kSCREEN_WIDTH, height: 60 + self.timeOutView.height + 155 + btnViewHeight + 70))
- }
- }
- if status === 7{
- //已退款
- self.timeView.isHidden = true
- self.detailView.isHidden = true
- self.deliveryView.isHidden = true
- self.timeOutView.isHidden = false
- self.deliveringView.isHidden = true
- self.typeLab.text = LanguagesUtil.createTextBy(Ctext: "订单已退款", Etext: "Order refunded")
-
- if self.addressLab.text.isNotEmptyStr{
- self.setFrameSize(CGSize.init(width: kSCREEN_WIDTH, height: 60 + self.timeOutView.height + 135 + labHeight + btnViewHeight + 70))
-
- }else{
- self.setFrameSize(CGSize.init(width: kSCREEN_WIDTH, height: 60 + self.timeOutView.height + 155 + btnViewHeight + 70))
- }
- }
- if status === 8{
- //完成已评价
- self.timeView.isHidden = true
- self.detailView.isHidden = false
- self.deliveryView.isHidden = true
- self.timeOutView.isHidden = true
- self.deliveringView.isHidden = true
- self.secTipLab.text = ""
- self.typeLab.text = LanguagesUtil.createTextBy(Ctext: "订单已完成", Etext: "Order completed")
- self.tipLab.text = LanguagesUtil.createTextBy(Ctext: "感谢您对KINA SENG的信任,欢迎再次光临", Etext: "Thank you for your trust in KINA SENG and welcome to visit us again")
-
- if self.addressLab.text.isNotEmptyStr{
- self.setFrameSize(CGSize.init(width: kSCREEN_WIDTH, height: 60 + self.detailView.height + 135 + labHeight + btnViewHeight + 70))
-
- }else{
- self.setFrameSize(CGSize.init(width: kSCREEN_WIDTH, height: 60 + self.detailView.height + 155 + btnViewHeight + 70))
- }
- }
-
- if status === 9{
- //已支付定金
- self.timeView.isHidden = true
- self.detailView.isHidden = false
- self.deliveryView.isHidden = true
- self.timeOutView.isHidden = true
- self.deliveringView.isHidden = true
-
- self.typeLab.text = LanguagesUtil.createTextBy(Ctext: "已支付定金", Etext: "Deposit paid")
-
- if self.dataModel?.isComplete === 1{
- self.tipLab.text = LanguagesUtil.createTextBy(Ctext: "定金尾款已结清", Etext: "The balance of the deposit has been settled")
- }else{
- self.tipLab.text = LanguagesUtil.createTextBy(Ctext: "请尽快支付剩余尾款:\(self.dataModel?.residual ?? "")", Etext: "Please pay the balance as soon as possible : \(self.dataModel?.residual ?? "")")
- }
-
- if self.addressLab.text.isNotEmptyStr{
- self.setFrameSize(CGSize.init(width: kSCREEN_WIDTH, height: 60 + self.detailView.height + 135 + labHeight + btnViewHeight + 70))
-
- }else{
- self.setFrameSize(CGSize.init(width: kSCREEN_WIDTH, height: 60 + self.detailView.height + 155 + btnViewHeight + 70))
- }
- }
-
- if status === 10{
- //延迟付款
- self.timeView.isHidden = true
- self.detailView.isHidden = false
- self.deliveryView.isHidden = true
- self.timeOutView.isHidden = true
- self.deliveringView.isHidden = true
-
- self.typeLab.text = LanguagesUtil.createTextBy(Ctext: "延迟付款", Etext: "Delayed payment")
-
- self.tipLab.text = LanguagesUtil.createTextBy(Ctext: "待支付,请立即支付", Etext: "Please pay as soon as possible")
-
- if self.addressLab.text.isNotEmptyStr{
- self.setFrameSize(CGSize.init(width: kSCREEN_WIDTH, height: 60 + self.detailView.height + 135 + labHeight + btnViewHeight + 70))
-
- }else{
- self.setFrameSize(CGSize.init(width: kSCREEN_WIDTH, height: 60 + self.detailView.height + 155 + btnViewHeight + 70))
- }
- }
-
- if status === 11{
- //延迟付款
- self.timeView.isHidden = true
- self.detailView.isHidden = true
- self.deliveryView.isHidden = true
- self.timeOutView.isHidden = true
- self.deliveringView.isHidden = false
-
- self.typeLab.text = LanguagesUtil.createTextBy(Ctext: "配送中", Etext: "On delivery")
-
- if self.addressLab.text.isNotEmptyStr{
- self.setFrameSize(CGSize.init(width: kSCREEN_WIDTH, height: 60 + self.detailView.height + 135 + labHeight + btnViewHeight + 70))
-
- }else{
- self.setFrameSize(CGSize.init(width: kSCREEN_WIDTH, height: 60 + self.detailView.height + 155 + btnViewHeight + 70))
- }
- }
- }
-
- /// 去支付
- /// - Parameter sender: <#sender description#>
- @IBAction func goToPayAction(_ sender: UIButton) {
- if self.headBtnBlock != nil{
- self.headBtnBlock!(1)
- }
- }
- /// 修改地址
- /// - Parameter sender: <#sender description#>
- @IBAction func addressAction(_ sender: UIButton) {
- if self.headBtnBlock != nil{
- self.headBtnBlock!(2)
- }
- }
-
- /// 再来一单
- /// - Parameter sender: <#sender description#>
- @IBAction func oneMoreAgain(_ sender: UIButton) {
- if self.headBtnBlock != nil{
- self.headBtnBlock!(3)
- }
- }
-
- /// 确认收货
- /// - Parameter sender: <#sender description#>
- @IBAction func confirmReceipt(_ sender: UIButton) {
- if self.headBtnBlock != nil{
- self.headBtnBlock!(4)
- }
- }
-
- /// 去评价
- /// - Parameter sender: <#sender description#>
- @IBAction func goToEvaluate(_ sender: UIButton) {
- if self.headBtnBlock != nil{
- self.headBtnBlock!(5)
- }
- }
-
- /// 联系商家
- /// - Parameter sender: <#sender description#>
- @IBAction func phoneCall(_ sender: UIButton) {
- if self.headBtnBlock != nil{
- self.headBtnBlock!(6)
- }
-
- }
-
- /// 取消订单
- /// - Parameter sender: <#sender description#>
- @IBAction func cancelOrderAction(_ sender: UIButton) {
- if self.headBtnBlock != nil{
- self.headBtnBlock!(7)
- }
- }
-
-
- func addNotification(isAdd:Bool) {
-
- if isAdd {
- //注册进入前台的通知
- NotificationCenter.default.addObserver(self, selector: #selector(becomeActive), name: UIApplication.didBecomeActiveNotification, object: nil)
- //注册进入后台的通知
- NotificationCenter.default.addObserver(self, selector: #selector(becomeDeath), name: UIApplication.willResignActiveNotification, object: nil)
-
- } else {
- //移除通知
- NotificationCenter.default.removeObserver(self, name: UIApplication.didBecomeActiveNotification, object: nil)
- NotificationCenter.default.removeObserver(self, name: UIApplication.willResignActiveNotification, object: nil)
- }
- }
-
-
- @objc func becomeActive() {
- //存储进入前台时的时间
- becomeActiveTime = Date()
- if becomeDeathTime != nil {
- //计算出退出后台到进入前台的时间差
- let difference:Int = Int(becomeActiveTime.timeIntervalSince(becomeDeathTime))
- //DispatchSourceTimer退出后台时是暂停的,返回前台时,需要减去时间差
- time = time - difference
- }
- }
-
- @objc func becomeDeath() {
- //存储进入后台时的时间
- becomeDeathTime = Date()
- }
-
-
- //计时器**和注销的方法
- func codeCountdown(isCodeTimer:Bool) {
-
- if isCodeTimer {
- //添加监控退出到后台以及进入前台的通知
- addNotification(isAdd: true)
- //子线程创建计时器
- codeTimer = DispatchSource.makeTimerSource(flags: .init(rawValue: 0), queue: DispatchQueue.global())
- //dealine:开始执行时间 repeating:重复时间
- codeTimer.schedule(deadline: .now(), repeating: .milliseconds(1000))
- //添加计时器的事件
- codeTimer.setEventHandler { [self] in
- time = time - 1
- if time < 0 {
- //注销计时器
- codeTimer.cancel()
- //主线程更新UI
- DispatchQueue.main.async {
- self.typeLab.text = LanguagesUtil.createTextBy(Ctext: "剩余时间:", Etext: "Time remaining:")
-
- time = 0
-
- //刷新详情
- if self.headBtnBlock != nil{
- self.headBtnBlock!(100)
- }
- NotificationCenter.default.post(name: NSNotification.Name("刷新订单列表"), object: self, userInfo:nil)
- //移除通知
- addNotification(isAdd: false)
- }
- return
- }
-
- DispatchQueue.main.async {
-
- //分钟转换
- let min = self.time/60
- var minStr = "00"
- if min > 9{
- minStr = "\(min)"
- }else{
- minStr = "0\(min)"
- }
-
- //秒转换
- let sec = self.time % 60
- var secStr = "00"
- if sec > 9{
- secStr = "\(sec)"
- }else{
- secStr = "0\(sec)"
- }
-
-
-
- self.typeLab.text = LanguagesUtil.createTextBy(Ctext: "剩余时间:\(minStr):\(secStr)", Etext: "Time remaining:\(minStr):\(secStr)")
- }
- }
-
- //计时器**
- codeTimer.activate()
-
- }else{
- if codeTimer != nil {
- codeTimer.cancel()
- addNotification(isAdd: false)
- time = 0
- self.typeLab.text = LanguagesUtil.createTextBy(Ctext: "待支付", Etext: "Wait for payment")
- }
- }
- }
- }
|