| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243 |
- //
- // GoodsVarietiesDetailViewController.swift
- // MTP2_iOS
- //
- // Created by Muchinfo on 2021/1/2.
- // Copyright © 2021 Muchinfo. All rights reserved.
- //
- import UIKit
- import IBAnimatable
- import WHToast
- import NVActivityIndicatorView
- /// 现货品种详情视图容器控制类
- class GoodsVarietiesDetailViewController: BaseViewController {
- // MARK: - 属性列表
- /// 状态视图
- @IBOutlet weak var statusView: UIView!
- /// 状态标记
- @IBOutlet weak var statusImage: UIImageView!
- /// 状态
- @IBOutlet weak var ststus: UILabel!
- /// 现货品种名称
- @IBOutlet weak var deliveryName: UILabel!
- /// 现货品种代码
- @IBOutlet weak var deliveryCode: UILabel!
- /// 单位
- @IBOutlet weak var enumdicname: UILabel!
- /// 备注
- @IBOutlet weak var remark: UILabel!
- /// 审核通过
- @IBOutlet weak var stop: UIButton! {
- didSet {
- stop.isHidden = true
- }
- }
- /// 商品品牌规格列表
- @IBOutlet weak var tableView: UITableView!
- /// 商品品牌规格列表
- @IBOutlet weak var heightLayoutConstraint: NSLayoutConstraint! {
- didSet {
- heightLayoutConstraint.constant = 0.0
- }
- }
-
- /// CellIdentifier
- let CellIdentifier = "GoodsVarieties_Cell"
-
- /// 显示数据
- var datas: [(title: String, value: String)] = [] {
- didSet {
- /// 刷新列表数据
- self.tableView.reloadData()
- /// 高度约束
- heightLayoutConstraint.constant = CGFloat(datas.count)*55.0
- }
- }
-
- /// 现货品种信息
- var deliveryGoodsDetail: MoDeliveryGoodsDetail?
-
- // MARK: - 生命周期
- override func viewDidLoad() {
- super.viewDidLoad()
- // Do any additional setup after loading the view.
- /// loding
- self.addLoadingView()
- }
-
- override func loadView() {
- super.loadView()
- /// 显示套保计划详细信息
- showWrStandardInfos()
- }
-
- /// 显示现货品种详细信息
- fileprivate func showWrStandardInfos() {
- /// 异常
- guard let commonManager = MTP2BusinessCore.shared.commonManager,
- let obj = deliveryGoodsDetail?.data else { return }
- /// 现货品种名称
- deliveryName.text = obj.deliverygoodsname.isBlank()
- /// 现货品种代码
- deliveryCode.text = obj.deliverygoodscode.isBlank()
- /// 单位
- let ename = (try? DatabaseHelper.getEnumInfo(enumdiccode: "goodsunit")?.first(where: {$0.enumitemname == obj.goodsunitid})?.enumdicname) ?? "--"
- /// 单位
- enumdicname.text = ename
- /// 状态
- ststus.text = obj.isvalid == 0 ? "停用" : "正常"
- ststus.textColor = .fromHex(rgbValue: obj.isvalid == 1 ? 0x4DBB33 : 0xFE9A68)
- /// 视图颜色
- statusView.backgroundColor = obj.isvalid == 1 ? .D3FFE1() : .FFEBDD()
- /// 标记
- statusImage.image = UIImage(named: obj.isvalid == 1 ? "status_success" : "clock")
- /// 按钮状态
- stop.setTitle(obj.isvalid == 0 ? "恢复" : "停用", for: .normal)
- /// 备注
- remark.text = obj.remark.isBlank()
- /// 查询现货品种明细
- requestWrStandardDetail()
- /// 该账户没权限
- stop.isHidden = !commonManager.isContainTraderMenu(key: obj.isvalid == 1 ? "client_deliverygoods_spot_disable" : "client_deliverygoods_spot_restore")
- }
-
- // MARK: - 交互相关
- /// onButtonPressed
- /// - Parameter sender: sender
- @IBAction fileprivate func onButtonPressed(_ sender: UIControl) {
- switch sender {
- case stop: /// 停用
- self.doRequestStopWrStandard()
- default: break
- }
- }
-
- // MARK: - 接口请求
- /// 查询现货品种明细
- fileprivate func requestWrStandardDetail() {
- /// 异常
- guard let contractManager = MTP2BusinessCore.shared.contractManager,
- let id = deliveryGoodsDetail?.data?.deliverygoodsid else {
- return
- }
-
- /// startAnimating
- _anim?.startAnimating()
-
- /// 查询详情
- contractManager.queryDeliveryGoodsDetail(deliverygoodsid: id, qrytradegoods: nil) { (isComplete, er, objs) in
- DispatchQueue.main.async {
- /// stopAnimating
- self._anim?.stopAnimating()
-
- if !isComplete {
- WHToast.showMessage("现货品种详情查询失败", duration: 1.5, finishHandler: {})
- return
- }
-
- guard let obj = objs?.first else {
- WHToast.showMessage("详细数据为空", duration: 1.5, finishHandler: {})
- return
- }
-
- /// 详细数据
- var details: [(title: String, value: String)] = []
- /// 品牌数据
- if obj.gblist.count != 0 {
- for (index, obj) in obj.gblist.enumerated() {
- details.append((title: "品牌\(index+1)", value: obj.brandname.isBlank()))
- }
- }
-
- /// 商品数据数据
- if obj.gmlist.count != 0 {
- for (index, obj) in obj.gmlist.enumerated() {
- details.append((title: "商品\(index+1)", value: obj.wrstandardname.isBlank()))
- details.append((title: "单位\(index+1)", value: obj.enumdicname.isBlank()))
- details.append((title: "标仓系数\(index+1)", value: "\(obj.convertfactor)"))
- }
- }
-
- /// 套保信息
- if obj.mgList.count != 0 {
- for (index, objmg) in obj.mgList.enumerated() {
- if let mg = objmg.mg {
- details.append((title: "套保品种\(index+1)", value: mg.middlegoodsname.isBlank()))
- details.append((title: "单位\(index+1)", value: mg.enumdicname.isBlank()))
- details.append((title: "套保系数\(index+1)", value: "\(objmg.convertratio)"))
- }
- }
- }
- /// 刷新数据
- self.datas = details
- }
- }
- }
-
- /// 停用现货商品
- fileprivate func doRequestStopWrStandard() {
- /// 异常
- guard let contractManager = MTP2BusinessCore.shared.contractManager,
- let obj = deliveryGoodsDetail?.data else {
- return
- }
- /// 开启Loading
- NVActivityIndicatorPresenter.sharedInstance.startAnimating(animActivityData("请求中"))
-
- /// 发送请求
- contractManager.requestDeliveryGoodsCancel(deliveryGoodsid: UInt64(obj.deliverygoodsid), isvalid: obj.isvalid == 0 ? 1 : 0) { (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) {
- /// 执行回调
- if let block = self.popBlock { block(OperatorType.update) }
- /// 返回上层视图
- self.navigationController?.popViewController(animated: true)
- }
- }
- }
- }
- }
- extension GoodsVarietiesDetailViewController: UITableViewDelegate, UITableViewDataSource {
-
- func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
- return datas.count
- }
-
- func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
- let cell = tableView.dequeueReusableCell(withIdentifier: CellIdentifier, for: indexPath) as! GoodsVarietiesDetailCell
- cell.model = self.datas[indexPath.row]
- return cell
- }
-
- func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
- return 55.0
- }
- }
- class GoodsVarietiesDetailCell: BaseTableViewCell<(title: String, value: String)> {
- /// title
- @IBOutlet weak var title: UILabel!
- /// value
- @IBOutlet weak var value: UILabel!
-
- override var model: (title: String, value: String)? {
- didSet {
- guard let obj = model else { return }
- title.text = obj.title
- value.text = obj.value
- }
- }
- }
|