| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- //
- // WareHouseDetailViewController.swift
- // MTP2_iOS
- //
- // Created by Muchinfo on 2021/2/26.
- // Copyright © 2021 Muchinfo. All rights reserved.
- //
- import UIKit
- import WHToast
- import NVActivityIndicatorView
- /// 仓库信息详情视图容器控制类
- class WareHouseDetailViewController: BaseViewController {
-
- // MARK: - 属性列表
- /// 状态视图
- @IBOutlet weak var statusView: UIView!
- /// 状态标记
- @IBOutlet weak var statusImage: UIImageView!
- /// 状态
- @IBOutlet weak var status: UILabel!
- /// 仓库名称
- @IBOutlet weak var wareHouseName: UILabel!
- /// 仓库简称
- @IBOutlet weak var wareHouseShortName: UILabel!
- /// 仓库类型
- @IBOutlet weak var type: UILabel!
- /// 联系人
- @IBOutlet weak var contractName: UILabel!
- /// 联系电话
- @IBOutlet weak var contractNum: UILabel!
- /// 详细地址
- @IBOutlet weak var detailAddress: UILabel!
- /// 地区
- @IBOutlet weak var address: UILabel!
- /// 停用或者恢复按钮
- @IBOutlet weak var submit: UIButton!
-
- /// 操作类型
- var operatorType: OperatorType = .stop
- /// 仓库信息
- var moWareHouse: MoWarehouse?
-
- // MARK: - 生命周期
- override func viewDidLoad() {
- super.viewDidLoad()
- // Do any additional setup after loading the view.
- }
-
- override func buildView() {
- super.buildView()
-
- /// loding.....
- addLoadingView()
-
- /// 异常
- guard let commonManager = MTP2BusinessCore.shared.commonManager,
- let obj = moWareHouse else {
- return
- }
- /// 查询省市区
- queryProvincesAndCitys()
- /// 状态
- status.text = obj.warehousestatus.description
- /// 仓库名称
- wareHouseName.text = obj.warehousename.isBlank()
- /// 仓库简称
- wareHouseShortName.text = obj.warehousecode.isBlank()
- /// 仓库类型
- type.text = obj.warehousetype.description
- /// 联系人
- contractName.text = obj.contactname.isBlank()
- /// 联系电话
- contractNum.text = obj.contactnum.isBlank()
- /// 详细地址
- detailAddress.text = obj.address.isBlank()
- /// 状态
- submit.setTitle(obj.warehousestatus == .normal ? "停用" : "恢复", for: .normal)
- status.textColor = .fromHex(rgbValue: obj.warehousestatus == .normal ? 0x4DBB33 : 0xFE9A68)
- /// 图标
- statusImage.image = UIImage(named: obj.warehousestatus == .normal ? "status_success" : "clock")
- /// 判断其权限控制
- submit.isHidden = !commonManager.isContainTraderMenu(key: obj.warehousestatus == .normal ? "client_warehouse_stop" : "client_warehouse_restore")
- }
-
- // MARK: - 交互相关
- @IBAction func onButtonPressed(_ sender: UIButton) {
- switch sender {
- case submit: /// 停用 或者恢复
- doSubmit()
- default: break
- }
- }
-
- // MARK: - 接口请求
- /// 查询对应的省市区
- func queryProvincesAndCitys() {
- /// 异常
- guard let obj = moWareHouse else { return }
- /// 对应的省
- let province = (try? DatabaseHelper.getAllDivisions())?.first(where: {$0.autoid == obj.provinceid})
- /// 对应的市
- let city = (try? DatabaseHelper.getAllDivisions())?.first(where: {$0.autoid == obj.cityid})
- /// 对应的区
- let district = (try? DatabaseHelper.getAllDivisions())?.first(where: {$0.autoid == obj.districtid})
- /// 地址信息
- address.text = "\(province?.divisionname ?? "") \(city?.divisionname ?? "") \(district?.divisionname ?? "")"
- }
-
- /// 接口请求
- fileprivate func doSubmit() {
- /// 异常
- guard let wareHouseManager = MTP2BusinessCore.shared.wareHouseManager,
- let obj = moWareHouse else {
- return
- }
- /// 开启Loading
- NVActivityIndicatorPresenter.sharedInstance.startAnimating(animActivityData("请求中..."))
- /// 修改状态请求
- wareHouseManager.requestWarehouseApplyReq(warehouseid: obj.autoid, warehousestatus: obj.warehousestatus == .normal ? 2 : 1) { (isComplete, er) in
- DispatchQueue.main.async {
- /// dismisss loding.....
- NVActivityIndicatorPresenter.sharedInstance.stopAnimating()
- /// 失败
- if !isComplete {
- WHToast.showMessage("请求失败,原因:\(ErrorUtils.desc(er?.retCode))", duration: 1.5, finishHandler: {})
- return
- }
- WHToast.showSuccess(withMessage: "请求成功", duration: 1.5, finishHandler: {
- if let bolck = self.popBlock {
- /// 执行回调
- bolck(obj.warehousestatus == .normal ? OperatorType.stop : OperatorType.reused)
- }
- /// 返回上层视图
- self.navigationController?.popViewController(animated: true)
- })
- }
- }
- }
- }
|