Commit cc39e471d59ab87da32004113bba8358f3a0476a

Authored by 张旭
1 parent 6b5d3459

商品管理页面 , 上下架 , 编辑库存

Showing 19 changed files with 856 additions and 79 deletions
metaCode.xcodeproj/project.pbxproj
@@ -9,6 +9,8 @@ @@ -9,6 +9,8 @@
9 /* Begin PBXBuildFile section */ 9 /* Begin PBXBuildFile section */
10 0D39E93D7229931C86EB1161 /* Pods_metaCode_metaCodeUITests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 63D879B49B1E42F1584DD75E /* Pods_metaCode_metaCodeUITests.framework */; }; 10 0D39E93D7229931C86EB1161 /* Pods_metaCode_metaCodeUITests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 63D879B49B1E42F1584DD75E /* Pods_metaCode_metaCodeUITests.framework */; };
11 19123FC12ABC11170075C883 /* CNWebViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 19123FC02ABC11170075C883 /* CNWebViewController.swift */; }; 11 19123FC12ABC11170075C883 /* CNWebViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 19123FC02ABC11170075C883 /* CNWebViewController.swift */; };
  12 + 1917328E2B032583007BCC04 /* CNLiveRoundedRectView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1917328D2B032583007BCC04 /* CNLiveRoundedRectView.swift */; };
  13 + 191732902B0348F6007BCC04 /* CNLiveSwitchView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1917328F2B0348F6007BCC04 /* CNLiveSwitchView.swift */; };
12 192336EB2AD9224300D47CD4 /* CNUpSlideViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 192336EA2AD9224300D47CD4 /* CNUpSlideViewController.swift */; }; 14 192336EB2AD9224300D47CD4 /* CNUpSlideViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 192336EA2AD9224300D47CD4 /* CNUpSlideViewController.swift */; };
13 1926C28F2AE0D76C00C71DC3 /* CNLiveDownSlideViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1926C28E2AE0D76C00C71DC3 /* CNLiveDownSlideViewModel.swift */; }; 15 1926C28F2AE0D76C00C71DC3 /* CNLiveDownSlideViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1926C28E2AE0D76C00C71DC3 /* CNLiveDownSlideViewModel.swift */; };
14 1926C2912AE0FD4500C71DC3 /* CNLiveDownSlideModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1926C2902AE0FD4500C71DC3 /* CNLiveDownSlideModel.swift */; }; 16 1926C2912AE0FD4500C71DC3 /* CNLiveDownSlideModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1926C2902AE0FD4500C71DC3 /* CNLiveDownSlideModel.swift */; };
@@ -174,6 +176,8 @@ @@ -174,6 +176,8 @@
174 0EC910AB9EBD717B04432BC4 /* Pods-metaCode-metaCodeUITests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-metaCode-metaCodeUITests.debug.xcconfig"; path = "Target Support Files/Pods-metaCode-metaCodeUITests/Pods-metaCode-metaCodeUITests.debug.xcconfig"; sourceTree = "<group>"; }; 176 0EC910AB9EBD717B04432BC4 /* Pods-metaCode-metaCodeUITests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-metaCode-metaCodeUITests.debug.xcconfig"; path = "Target Support Files/Pods-metaCode-metaCodeUITests/Pods-metaCode-metaCodeUITests.debug.xcconfig"; sourceTree = "<group>"; };
175 170BC5D0622EA2969D110A3B /* Pods-metaCode.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-metaCode.release.xcconfig"; path = "Target Support Files/Pods-metaCode/Pods-metaCode.release.xcconfig"; sourceTree = "<group>"; }; 177 170BC5D0622EA2969D110A3B /* Pods-metaCode.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-metaCode.release.xcconfig"; path = "Target Support Files/Pods-metaCode/Pods-metaCode.release.xcconfig"; sourceTree = "<group>"; };
176 19123FC02ABC11170075C883 /* CNWebViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CNWebViewController.swift; sourceTree = "<group>"; }; 178 19123FC02ABC11170075C883 /* CNWebViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CNWebViewController.swift; sourceTree = "<group>"; };
  179 + 1917328D2B032583007BCC04 /* CNLiveRoundedRectView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CNLiveRoundedRectView.swift; sourceTree = "<group>"; };
  180 + 1917328F2B0348F6007BCC04 /* CNLiveSwitchView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CNLiveSwitchView.swift; sourceTree = "<group>"; };
177 192336EA2AD9224300D47CD4 /* CNUpSlideViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CNUpSlideViewController.swift; sourceTree = "<group>"; }; 181 192336EA2AD9224300D47CD4 /* CNUpSlideViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CNUpSlideViewController.swift; sourceTree = "<group>"; };
178 1926C28E2AE0D76C00C71DC3 /* CNLiveDownSlideViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CNLiveDownSlideViewModel.swift; sourceTree = "<group>"; }; 182 1926C28E2AE0D76C00C71DC3 /* CNLiveDownSlideViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CNLiveDownSlideViewModel.swift; sourceTree = "<group>"; };
179 1926C2902AE0FD4500C71DC3 /* CNLiveDownSlideModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CNLiveDownSlideModel.swift; sourceTree = "<group>"; }; 183 1926C2902AE0FD4500C71DC3 /* CNLiveDownSlideModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CNLiveDownSlideModel.swift; sourceTree = "<group>"; };
@@ -374,6 +378,8 @@ @@ -374,6 +378,8 @@
374 19565ECE2AF8D8F6007D6727 /* CNLiveShopGoodsListCell.swift */, 378 19565ECE2AF8D8F6007D6727 /* CNLiveShopGoodsListCell.swift */,
375 1965FA3D2AFB176E00F0F435 /* CNLiveShopAddGoodsSingleView.swift */, 379 1965FA3D2AFB176E00F0F435 /* CNLiveShopAddGoodsSingleView.swift */,
376 1965FA3F2AFB38AA00F0F435 /* CNLiveAddGoodsSelectUploadImageView.swift */, 380 1965FA3F2AFB38AA00F0F435 /* CNLiveAddGoodsSelectUploadImageView.swift */,
  381 + 1917328D2B032583007BCC04 /* CNLiveRoundedRectView.swift */,
  382 + 1917328F2B0348F6007BCC04 /* CNLiveSwitchView.swift */,
377 ); 383 );
378 path = GoodsManager; 384 path = GoodsManager;
379 sourceTree = "<group>"; 385 sourceTree = "<group>";
@@ -1137,12 +1143,14 @@ @@ -1137,12 +1143,14 @@
1137 19BB1FE82AECAD060094D962 /* CNLiveShopConsoleModel.swift in Sources */, 1143 19BB1FE82AECAD060094D962 /* CNLiveShopConsoleModel.swift in Sources */,
1138 19BB1FEE2AF0E1EC0094D962 /* CNLiveShopDetailViewModel.swift in Sources */, 1144 19BB1FEE2AF0E1EC0094D962 /* CNLiveShopDetailViewModel.swift in Sources */,
1139 19F1C2332AB5728B0083D06C /* CNIDCardView.swift in Sources */, 1145 19F1C2332AB5728B0083D06C /* CNIDCardView.swift in Sources */,
  1146 + 1917328E2B032583007BCC04 /* CNLiveRoundedRectView.swift in Sources */,
1140 7CD675292A270F6A008354C1 /* WJColorChange.m in Sources */, 1147 7CD675292A270F6A008354C1 /* WJColorChange.m in Sources */,
1141 79F4B11C2A33036E00993C03 /* CNLiveMineInfoAlertView.swift in Sources */, 1148 79F4B11C2A33036E00993C03 /* CNLiveMineInfoAlertView.swift in Sources */,
1142 79BB96A82AF223FB00AEA4AC /* CNLiveConfigAlertManager.swift in Sources */, 1149 79BB96A82AF223FB00AEA4AC /* CNLiveConfigAlertManager.swift in Sources */,
1143 19BB1FF02AF0E5B30094D962 /* CNLiveShopDetailModel.swift in Sources */, 1150 19BB1FF02AF0E5B30094D962 /* CNLiveShopDetailModel.swift in Sources */,
1144 796398942A260C0100D045EB /* AppDelegate.swift in Sources */, 1151 796398942A260C0100D045EB /* AppDelegate.swift in Sources */,
1145 7989B5C72A4BDC7200A19B10 /* CNLiveMineEarnListViewController.swift in Sources */, 1152 7989B5C72A4BDC7200A19B10 /* CNLiveMineEarnListViewController.swift in Sources */,
  1153 + 191732902B0348F6007BCC04 /* CNLiveSwitchView.swift in Sources */,
1146 792B53282AFCD7640009AB49 /* CNLiveShopOrderExpressDetailViewController.swift in Sources */, 1154 792B53282AFCD7640009AB49 /* CNLiveShopOrderExpressDetailViewController.swift in Sources */,
1147 79396EF12A31C21B0053E1AF /* CNLiveInfoShowViewController.swift in Sources */, 1155 79396EF12A31C21B0053E1AF /* CNLiveInfoShowViewController.swift in Sources */,
1148 192336EB2AD9224300D47CD4 /* CNUpSlideViewController.swift in Sources */, 1156 192336EB2AD9224300D47CD4 /* CNUpSlideViewController.swift in Sources */,
metaCode/Classes/Config/CNLiveConfigManager.swift
@@ -73,4 +73,12 @@ extension Notification.Name { @@ -73,4 +73,12 @@ extension Notification.Name {
73 //发货成功通知 73 //发货成功通知
74 public static let CNLiveShopOrderSendExpressNotification = Notification.Name("CNLiveShopOrderSendExpressNotification") 74 public static let CNLiveShopOrderSendExpressNotification = Notification.Name("CNLiveShopOrderSendExpressNotification")
75 } 75 }
  76 + struct ShopGoodsManage {
  77 + //新增商品通知
  78 + public static let kDSGoodsManageAddNotification = Notification.Name("kDSGoodsManageAddNotification")
  79 + //编辑商品通知
  80 + public static let kDSGoodsManageEditNotification = Notification.Name("kDSGoodsManageEditNotification")
  81 + //删除商品通知
  82 + public static let kDSGoodsManageDeleteNotification = Notification.Name("kDSGoodsManageDeleteNotification")
  83 + }
76 } 84 }
metaCode/Classes/Main/HomePage/Controller/GoodsManager/CNLiveShopNewProductController.swift
@@ -19,6 +19,7 @@ enum CNLiveShopGoodsAddEditType{ @@ -19,6 +19,7 @@ enum CNLiveShopGoodsAddEditType{
19 class CNLiveShopNewProductController:CNLiveBaseViewController{ 19 class CNLiveShopNewProductController:CNLiveBaseViewController{
20 20
21 var type:CNLiveShopGoodsAddEditType = .add 21 var type:CNLiveShopGoodsAddEditType = .add
  22 + var goodsId = ""
22 lazy var bgScrollView :UIScrollView = { 23 lazy var bgScrollView :UIScrollView = {
23 let bgScrollView = UIScrollView(frame: CGRect(x: 0, y: KNavigationHeight, width: KSreenWidth, height: KSreenHeight-KNavigationHeight-KTabBarHeight)) 24 let bgScrollView = UIScrollView(frame: CGRect(x: 0, y: KNavigationHeight, width: KSreenWidth, height: KSreenHeight-KNavigationHeight-KTabBarHeight))
24 bgScrollView.showsVerticalScrollIndicator = false 25 bgScrollView.showsVerticalScrollIndicator = false
metaCode/Classes/Main/HomePage/Controller/GoodsManager/CNLiveShopProductManagerController.swift
@@ -6,12 +6,22 @@ @@ -6,12 +6,22 @@
6 // 商品管理 6 // 商品管理
7 7
8 import Foundation 8 import Foundation
  9 +import MJRefresh
  10 +import EmptyDataSet_Swift
9 11
10 -class CNLiveShopProductManagerController:CNLiveBaseViewController, UITableViewDataSource, UITableViewDelegate{ 12 +///商品管理通知
  13 +let kDSGoodsManageAddNotification = "kDSGoodsManageAddNotification"
  14 +let kDSGoodsManageEditNotification = "kDSGoodsManageEditNotification"
  15 +let kDSGoodsManageDeleteNotification = "kDSGoodsManageDeleteNotification"
  16 +
  17 +class CNLiveShopProductManagerController:CNLiveBaseViewController, UITableViewDataSource, UITableViewDelegate, CNLiveGoodsManagerClassifyViewDelegate, EmptyDataSetSource, EmptyDataSetDelegate, UITextFieldDelegate{
11 18
12 let kCNLiveShopGoodsListCellIdentifier = "kCNLiveShopGoodsListCellIdentifier" 19 let kCNLiveShopGoodsListCellIdentifier = "kCNLiveShopGoodsListCellIdentifier"
13 20
14 - 21 + ///排序类型 1新品 2价格从底到高 3 价格从高到底
  22 + var sortType = "1"
  23 + var network_type: CNLiveMineResponseType!
  24 + var pageNum: NSInteger = 0
15 // MARK: - 懒加载 25 // MARK: - 懒加载
16 ///数据源 26 ///数据源
17 lazy var dataArray: NSMutableArray = { 27 lazy var dataArray: NSMutableArray = {
@@ -20,8 +30,12 @@ class CNLiveShopProductManagerController:CNLiveBaseViewController, UITableViewDa @@ -20,8 +30,12 @@ class CNLiveShopProductManagerController:CNLiveBaseViewController, UITableViewDa
20 }() 30 }()
21 31
22 lazy var classifyView: CNLiveShopGoodsListClassifyView = { 32 lazy var classifyView: CNLiveShopGoodsListClassifyView = {
23 - let classifyView = CNLiveShopGoodsListClassifyView(frame: CGRect(x: 0, y: KNavigationHeight, width: KSreenWidth, height: 44)) 33 + let itemA = CNLiveClassifyItem.init(itemTitle: "最新", itemImage: nil)
  34 + let itemB = CNLiveClassifyItem.init(itemTitle: "价格", itemImage: UIImage(named: "DS_goods_manager_pirce_default"))
  35 +
  36 + let classifyView = CNLiveShopGoodsListClassifyView(frame: CGRect(x: 0, y: KNavigationHeight, width: KSreenWidth, height: 44), itemArray: [itemA,itemB])
24 classifyView.backgroundColor = .white 37 classifyView.backgroundColor = .white
  38 + classifyView.delegate = self
25 return classifyView 39 return classifyView
26 }() 40 }()
27 lazy var addBtn: UIButton = { 41 lazy var addBtn: UIButton = {
@@ -36,7 +50,10 @@ class CNLiveShopProductManagerController:CNLiveBaseViewController, UITableViewDa @@ -36,7 +50,10 @@ class CNLiveShopProductManagerController:CNLiveBaseViewController, UITableViewDa
36 let tableView = UITableView(frame: .zero, style: .plain) 50 let tableView = UITableView(frame: .zero, style: .plain)
37 tableView.dataSource = self 51 tableView.dataSource = self
38 tableView.delegate = self 52 tableView.delegate = self
  53 + tableView.emptyDataSetSource = self
  54 + tableView.emptyDataSetDelegate = self
39 tableView.separatorStyle = .none 55 tableView.separatorStyle = .none
  56 + tableView.tableFooterView = UIView.init()
40 tableView.rowHeight = 167 57 tableView.rowHeight = 167
41 tableView.register(CNLiveShopGoodsListCell.self, forCellReuseIdentifier: kCNLiveShopGoodsListCellIdentifier) 58 tableView.register(CNLiveShopGoodsListCell.self, forCellReuseIdentifier: kCNLiveShopGoodsListCellIdentifier)
42 return tableView 59 return tableView
@@ -52,16 +69,27 @@ class CNLiveShopProductManagerController:CNLiveBaseViewController, UITableViewDa @@ -52,16 +69,27 @@ class CNLiveShopProductManagerController:CNLiveBaseViewController, UITableViewDa
52 emptyLabel.adjustsFontSizeToFitWidth=true 69 emptyLabel.adjustsFontSizeToFitWidth=true
53 return emptyLabel 70 return emptyLabel
54 }() 71 }()
55 - 72 +
56 override func viewDidLoad() { 73 override func viewDidLoad() {
57 super.viewDidLoad() 74 super.viewDidLoad()
58 self.setUI() 75 self.setUI()
59 - self.getGoodsListApi(page: "1") 76 + self.getGoodsListApi(page: 1)
  77 +
  78 + NotificationCenter.default.addObserver(self, selector: #selector(goodsManageAddNotification), name: Notification.Name.ShopGoodsManage.kDSGoodsManageAddNotification, object: nil)
  79 + NotificationCenter.default.addObserver(self, selector: #selector(goodsManageEditNotification), name: Notification.Name.ShopGoodsManage.kDSGoodsManageEditNotification, object: nil)
  80 + NotificationCenter.default.addObserver(self, selector: #selector(goodsManageDeleteNotification), name: Notification.Name.ShopGoodsManage.kDSGoodsManageDeleteNotification, object: nil)
  81 + }
  82 + deinit {
  83 + NotificationCenter.default.removeObserver(self, name: Notification.Name.ShopGoodsManage.kDSGoodsManageAddNotification, object: nil)
  84 + NotificationCenter.default.removeObserver(self, name: Notification.Name.ShopGoodsManage.kDSGoodsManageEditNotification, object: nil)
  85 + NotificationCenter.default.removeObserver(self, name: Notification.Name.ShopGoodsManage.kDSGoodsManageDeleteNotification, object: nil)
60 } 86 }
  87 +
61 func setUI(){ 88 func setUI(){
62 navigationBarHidden = false 89 navigationBarHidden = false
63 titleName = "商品管理" 90 titleName = "商品管理"
64 -// rightNavBtns = [self.addBtn] 91 + rightNavBtns = [self.addBtn]
  92 + self.pageNum = 1
65 self.view.addSubview(self.classifyView) 93 self.view.addSubview(self.classifyView)
66 self.view.addSubview(tableView) 94 self.view.addSubview(tableView)
67 self.view.addSubview(self.emptyLabel) 95 self.view.addSubview(self.emptyLabel)
@@ -69,6 +97,18 @@ class CNLiveShopProductManagerController:CNLiveBaseViewController, UITableViewDa @@ -69,6 +97,18 @@ class CNLiveShopProductManagerController:CNLiveBaseViewController, UITableViewDa
69 tableView.frame = CGRect(x: 0, y:self.classifyView.bottom , width: KSreenWidth, height: KSreenHeight - self.classifyView.bottom) 97 tableView.frame = CGRect(x: 0, y:self.classifyView.bottom , width: KSreenWidth, height: KSreenHeight - self.classifyView.bottom)
70 } 98 }
71 99
  100 + func addRefreshView() {
  101 + tableView.mj_header = MJRefreshNormalHeader.init(refreshingBlock: {[weak self] in
  102 + self!.pageNum = 1
  103 + self?.getGoodsListApi(page: 1)
  104 + })
  105 +
  106 + tableView.mj_footer = MJRefreshAutoNormalFooter.init(refreshingBlock: {[weak self] in
  107 + self!.pageNum = self!.pageNum + 1
  108 + self?.getGoodsListApi(page: self!.pageNum)
  109 + })
  110 + }
  111 +
72 // MARK: - UITableViewDelegate 112 // MARK: - UITableViewDelegate
73 func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 113 func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
74 return self.dataArray.count 114 return self.dataArray.count
@@ -84,6 +124,17 @@ class CNLiveShopProductManagerController:CNLiveBaseViewController, UITableViewDa @@ -84,6 +124,17 @@ class CNLiveShopProductManagerController:CNLiveBaseViewController, UITableViewDa
84 } 124 }
85 125
86 cell.goodsModel = goodsModel 126 cell.goodsModel = goodsModel
  127 + cell.editBlock = { mdl in
  128 + let model = mdl
  129 + self.editGoodsModel(goodsModel: model)
  130 + }
  131 + cell.editCountBlock = { mdl in
  132 + let model = mdl
  133 + self.editGoodsCountModel(goodsModel: model)
  134 + }
  135 + cell.operStateBlock = { model,state in
  136 + self.operStateWithGoodsModel(goodsModel: model, state: state)
  137 + }
87 return cell 138 return cell
88 } 139 }
89 func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { 140 func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
@@ -95,47 +146,233 @@ class CNLiveShopProductManagerController:CNLiveBaseViewController, UITableViewDa @@ -95,47 +146,233 @@ class CNLiveShopProductManagerController:CNLiveBaseViewController, UITableViewDa
95 return 167 146 return 167
96 } 147 }
97 148
  149 + func title(forEmptyDataSet scrollView: UIScrollView) -> NSAttributedString? {
  150 + var defult_string = ""
  151 + if network_type == .failed || network_type == .unkonw {
  152 + defult_string = "接口请求错误,刷新试试~"
  153 + }
  154 + if network_type == .noNetwork {
  155 + defult_string = "网络开小差了,刷新试试~"
  156 + }
  157 + if dataArray.count == 0 {
  158 + defult_string = "暂时没有数据~"
  159 + }
  160 + return NSAttributedString(string: defult_string, attributes: [.font: Font_17,.foregroundColor: HexColor("#666666")!])
  161 + }
  162 +
  163 + func buttonTitle(forEmptyDataSet scrollView: UIScrollView, for state: UIControl.State) -> NSAttributedString? {
  164 + if network_type == .failed || network_type == .noNetwork {
  165 + let attributes = [NSAttributedString.Key.font:Font_16_Fit,
  166 + NSAttributedString.Key.foregroundColor: HexColor("#609BFF")]
  167 + return NSAttributedString(string: "刷一刷", attributes: attributes as [NSAttributedString.Key : Any])
  168 + }
  169 + return nil
  170 + }
  171 +
  172 + func emptyDataSet(_ scrollView: UIScrollView, didTapView view: UIView) {
  173 + if network_type == .failed || network_type == .noNetwork {
  174 + getGoodsListApi(page: 1)
  175 + }
  176 + }
  177 +
  178 + // MARK: - 编辑商品
  179 + func editGoodsModel(goodsModel:CNLiveShopGoodsListModel){
  180 + let vc = CNLiveShopNewProductController.init()
  181 + vc.type = .edit
  182 + vc.goodsId = goodsModel.id!
  183 + self.navigationController?.pushViewController(vc, animated: false)
  184 + }
  185 +
  186 + // MARK: - 编辑商品库存
  187 + func editGoodsCountModel(goodsModel:CNLiveShopGoodsListModel){
  188 + let alertController = UIAlertController(title: "编辑商品库存", message: "请输入库存数量", preferredStyle: .alert)
  189 + alertController.addTextField { textField in
  190 + textField.delegate = self
  191 + textField.keyboardType = .numberPad
  192 + textField.returnKeyType = .done
  193 + textField.tag = 666
  194 + }
  195 + let cancel = UIAlertAction(title: "取消", style: .cancel) { action in
  196 + }
  197 + alertController.addAction(cancel)
  198 + let confirm = UIAlertAction(title: "修改", style: .default) { action in
  199 + self.view.endEditing(true)
  200 + let textField = alertController.textFields?.first
  201 + if (textField!.text?.count ?? 0 > 0 && (textField!.text?.isPurnInt() == false)) {
  202 + showMessage(message: "只能输入数字")
  203 + return
  204 + }
  205 + if (textField!.text?.count == 0 || textField!.text?.count ?? 0 >= 6){
  206 + showMessage(message: "请输入1~99999范围内的数量")
  207 + return
  208 + }
  209 + self.requsetEditGoodsCount(count: textField!.text ?? "", goodsModel: goodsModel)
  210 + }
  211 + alertController.addAction(confirm)
  212 + self.present(alertController, animated: true)
  213 +
  214 + }
  215 +
  216 + func requsetEditGoodsCount(count:String,goodsModel:CNLiveShopGoodsListModel){
  217 + showLoading(message: "")
  218 + CNLiveShopGoodListViewModel.postGoodsEditAttrWithShopId(shopId: DSUserInfoManager.shared.dsUserInfo.id!, goodsId: goodsModel.id!, type: 1, value: count) { result, status in
  219 + if status == .success{
  220 + showMessage(message: "操作成功")
  221 + let dataArr = Array(self.dataArray)
  222 + for (idx,mdl) in dataArr.enumerated() {
  223 + let model = mdl as! CNLiveShopGoodsListModel
  224 + if model.id == goodsModel.id {
  225 + model.count = count
  226 + self.dataArray.replaceObject(at: idx, with: model)
  227 + self.tableView.reloadData()
  228 + break
  229 + }
  230 + }
  231 + }else{
  232 + showMessage(message: "操作失败")
  233 + }
  234 + }
  235 + }
  236 +
  237 + // MARK: - 编辑商品上下架状态
  238 + func operStateWithGoodsModel(goodsModel:CNLiveShopGoodsListModel,state:Int){
  239 + var message = ""
  240 + if state == 2{
  241 + message = "确认下架?"
  242 + }else{
  243 + message = "确认上架?"
  244 + }
  245 + AlertTool.showSystemAlert(title: message, message: nil, actionTitles: ["取消","确定"], style: .alert, actionStyles:[.cancel,.default] ) { index in
  246 + if (index == 2) {
  247 + showLoading(message: "")
  248 + CNLiveShopGoodListViewModel.postChangeGoodsStateWithGoodsId(goodsId: goodsModel.id!, state: "") { result, status in
  249 + if status == .success{
  250 + showMessage(message: "操作成功")
  251 + let dataArr = Array(self.dataArray)
  252 + for (idx,mdl) in dataArr.enumerated() {
  253 + let model = mdl as! CNLiveShopGoodsListModel
  254 + if model.id == goodsModel.id {
  255 + if (model.state == 2) {
  256 + model.state = 1
  257 + }else {
  258 + model.state = 2
  259 + }
  260 + self.dataArray.replaceObject(at: idx, with: model)
  261 +
  262 + self.tableView.reloadData()
  263 + break
  264 + }
  265 + }
  266 + }else if (status == .failed){
  267 + self.network_type = .failed
  268 + showMessage(message: "操作失败")
  269 + }else if (status == .noNetwork){
  270 + self.network_type = .noNetwork
  271 + showMessage(message: "操作失败")
  272 + }
  273 + }
  274 + }
  275 + }
  276 + }
  277 +
  278 +
  279 + // MARK: -CNLiveGoodsManagerClassifyViewDelegate
  280 + func shopGoodsManagerClassifyViewDidSeleted(type: CNLiveGoodsManagerClassifyType) {
  281 + switch (type) {
  282 + case .newest:
  283 + self.sortType = "1"
  284 + case .priceMin:
  285 + self.sortType = "2"
  286 + case .priceMax:
  287 + self.sortType = "3"
  288 + }
  289 + self.tableView.mj_header?.beginRefreshing()
  290 + }
  291 +
  292 +
98 // MARK: - BtnAction 293 // MARK: - BtnAction
99 @objc func addBtnAction(){ 294 @objc func addBtnAction(){
100 295
101 currentViewController()?.navigationController?.pushViewController(CNLiveShopNewProductController(), animated: true) 296 currentViewController()?.navigationController?.pushViewController(CNLiveShopNewProductController(), animated: true)
102 } 297 }
103 298
  299 + // MARK: - 商品编辑通知
  300 + @objc func goodsManageAddNotification(notification:Notification) {
  301 + self.getGoodsListApi(page: 1)
  302 + }
  303 + @objc func goodsManageEditNotification(notification:Notification){
  304 + let dict = (notification.userInfo ?? ["":""]) as! [String :Any]
  305 + let nModel = newDictionaryToModel(dict, CNLiveShopGoodsListModel.self) as! CNLiveShopGoodsListModel
  306 + var dataArr = Array(self.dataArray)
  307 +
  308 + for (idx,mdl) in dataArr.enumerated() {
  309 + let model = mdl as! CNLiveShopGoodsListModel
  310 + if model.id == nModel.id {
  311 + model.title = nModel.title
  312 + model.simg = nModel.simg
  313 + model.price = nModel.price
  314 + model.ads = nModel.ads
  315 + model.groupid = nModel.groupid
  316 + model.shopid = nModel.shopid
  317 + model.category_id = nModel.category_id
  318 + model.state = nModel.state
  319 + model.count = nModel.count
  320 + model.ord = nModel.ord
  321 + self.dataArray.replaceObject(at: idx, with: nModel)
  322 + self.tableView.reloadData()
  323 + break
  324 + }
  325 + }
  326 +
  327 + }
  328 +
  329 + @objc func goodsManageDeleteNotification(notification:Notification){
  330 + let dict = (notification.userInfo ?? ["":""]) as! [String :Any]
  331 + let dataArr = Array(self.dataArray)
  332 +
  333 + for (_,mdl) in dataArr.enumerated() {
  334 + let model = mdl as! CNLiveShopGoodsListModel
  335 + if model.id == (dict["goodsId"] as! String){
  336 + self.dataArray.remove(model)
  337 + self.tableView.reloadData()
  338 + break
  339 + }
  340 + }
  341 + }
  342 +
104 //MARK: - 网络请求获取商品列表 343 //MARK: - 网络请求获取商品列表
105 - func getGoodsListApi(page:String) 344 + func getGoodsListApi(page:NSInteger)
106 { 345 {
107 showLoading(message: "") 346 showLoading(message: "")
108 CNLiveShopGoodListViewModel.requestGoodsList(shopId: DSUserInfoManager.shared.dsUserInfo.id, sortType: "1", page: page) { result, status in 347 CNLiveShopGoodListViewModel.requestGoodsList(shopId: DSUserInfoManager.shared.dsUserInfo.id, sortType: "1", page: page) { result, status in
109 hiddenLoading() 348 hiddenLoading()
110 if status == .success{ 349 if status == .success{
111 let arr = result as! [CNLiveShopGoodsListModel] 350 let arr = result as! [CNLiveShopGoodsListModel]
112 - if arr.count > 0  
113 - { 351 +
  352 + if self.pageNum == 1 {
  353 + self.dataArray.removeAllObjects()
114 self.dataArray.addObjects(from: result as! [CNLiveShopGoodsListModel]) 354 self.dataArray.addObjects(from: result as! [CNLiveShopGoodsListModel])
115 - let newDataArray = NSMutableArray()  
116 - for goodsModel in self.dataArray {  
117 - if let model = goodsModel as? CNLiveShopGoodsListModel{  
118 - newDataArray.add(model)  
119 - } 355 + if (self.dataArray.count > 0 && self.tableView.mj_header == nil && self.tableView.mj_footer == nil) {
  356 + self.addRefreshView()
120 } 357 }
121 - self.dataArray.removeAllObjects()  
122 - self.dataArray.addObjects(from: newDataArray as! [Any])  
123 - 358 + }else if self.pageNum > 1 {
  359 + self.dataArray.addObjects(from: result as! [CNLiveShopGoodsListModel])
  360 + }
  361 + self.tableView.reloadData()
  362 + self.tableView.mj_header?.endRefreshing()
  363 + self.tableView.mj_footer?.endRefreshing()
  364 + if (result as! Array<Any>).count == 0 {
  365 + self.tableView.mj_footer?.endRefreshingWithNoMoreData()
124 self.tableView.reloadData() 366 self.tableView.reloadData()
125 - self.emptyLabel.isHidden = true  
126 - self.classifyView.emptyView(isEmpty: false)  
127 - }else if arr.count == 0{  
128 - //展示emptyView  
129 - self.classifyView.emptyView(isEmpty: true)  
130 - self.emptyLabel.isHidden = false  
131 } 367 }
132 }else if (status == .failed){ 368 }else if (status == .failed){
133 -// self.NetApiStatus = .apiError 369 + self.network_type = .failed
  370 + self.tableView.reloadEmptyDataSet()
134 }else if (status == .noNetwork){ 371 }else if (status == .noNetwork){
135 -  
136 -// self.NetApiStatus = .notNetwork 372 + self.network_type = .noNetwork
  373 + self.tableView.reloadEmptyDataSet()
137 } 374 }
  375 +
138 } 376 }
139 -//  
140 } 377 }
141 } 378 }
metaCode/Classes/Main/HomePage/View/GoodsManager/CNLiveRoundedRectView.swift 0 → 100644
  1 +//
  2 +// CNLiveRoundedRectView.swift
  3 +// metaCode
  4 +//
  5 +// Created by zx on 2023/11/14.
  6 +//
  7 +
  8 +import Foundation
  9 +import CoreGraphics
  10 +
  11 +let DS_RRV_ONE_PIXEL = 1.0 / UIScreen.main.scale
  12 +
  13 +class CNLiveRoundedRectView: UIView {
  14 +
  15 + //填充色
  16 + var _fillColor:UIColor?
  17 + var fillColor:UIColor?{
  18 + get{
  19 + _fillColor
  20 + }
  21 + set{
  22 + _fillColor = newValue
  23 + self.setNeedsDisplay()
  24 + }
  25 + }
  26 + //边框色
  27 + var _strokeColor:UIColor?
  28 + var strokeColor:UIColor?{
  29 + get{
  30 + _strokeColor
  31 + }
  32 + set{
  33 + _strokeColor = newValue
  34 + self.setNeedsDisplay()
  35 + }
  36 + }
  37 + //边框宽度
  38 + var _strokeWidth:CGFloat = 0.0
  39 + var strokeWidth:CGFloat{
  40 + get{
  41 + _strokeWidth
  42 + }
  43 + set{
  44 + _strokeWidth = newValue
  45 + self.setNeedsDisplay()
  46 + }
  47 + }
  48 +
  49 + //圆角度数 默认0
  50 + var _radius:CGFloat = 0.0
  51 + var radius:CGFloat{
  52 + get{
  53 + _radius
  54 + }
  55 + set{
  56 + _radius = newValue
  57 + self.setNeedsDisplay()
  58 + }
  59 + }
  60 + override init(frame: CGRect) {
  61 + super.init(frame: frame)
  62 + self.backgroundColor = .clear
  63 + }
  64 +
  65 + override var frame:CGRect{
  66 + didSet {
  67 + let newFrame = frame
  68 + super.frame = newFrame
  69 + self.setNeedsDisplay()
  70 + }
  71 + }
  72 +
  73 + required init?(coder: NSCoder) {
  74 + fatalError("init(coder:) has not been implemented")
  75 + }
  76 +
  77 +
  78 + override func draw(_ rect: CGRect) {
  79 + super.draw(rect)
  80 + if ((self.strokeColor != nil && self.strokeColor?.cgColor != UIColor.clear.cgColor) && ( self.fillColor != nil && self.fillColor?.cgColor != UIColor.clear.cgColor))
  81 + {
  82 + let fpath = UIBezierPath(roundedRect: self.bounds, cornerRadius: self.radius)
  83 + self.fillColor?.setFill()
  84 + fpath.fill()
  85 + let lineWidth = self.strokeWidth == 0 ? DS_RRV_ONE_PIXEL : self.strokeWidth
  86 + let fx = lineWidth
  87 + let fy = lineWidth
  88 + let fwidth = self.width - fx*2
  89 + let fheight = self.height - fy*2
  90 + let spath = UIBezierPath(roundedRect: CGRect(x: fx, y: fy, width: fwidth, height: fheight), cornerRadius: self.radius-lineWidth)
  91 + spath.lineWidth = lineWidth
  92 + self.strokeColor?.setStroke()
  93 + spath.stroke()
  94 + }else if ((self.strokeColor != nil && self.strokeColor?.cgColor != UIColor.clear.cgColor) && (self.fillColor == nil || self.fillColor?.cgColor == UIColor.clear.cgColor)) {
  95 + UIColor.clear.setFill()
  96 + let lineWidth = self.strokeWidth == 0 ? DS_RRV_ONE_PIXEL : self.strokeWidth
  97 + let x = lineWidth
  98 + let y = lineWidth
  99 + let width = self.width - x*2
  100 + let height = self.height - y*2
  101 + let path = UIBezierPath(roundedRect: CGRect(x: x, y: y, width: width, height: height), cornerRadius: self.radius-lineWidth)
  102 + path.lineWidth = lineWidth
  103 + self.strokeColor?.setStroke()
  104 + path.stroke()
  105 + }else if ((self.strokeColor == nil || self.strokeColor?.cgColor == UIColor.clear.cgColor) && (self.fillColor != nil && self.fillColor?.cgColor != UIColor.clear.cgColor)){
  106 + UIColor.clear.setStroke()
  107 + let path = UIBezierPath(roundedRect: self.bounds, cornerRadius: self.radius)
  108 + self.fillColor?.setFill()
  109 + path.fill()
  110 + }else{
  111 + UIColor.clear.setStroke()
  112 + UIColor.clear.setFill()
  113 + }
  114 + }
  115 +}
metaCode/Classes/Main/HomePage/View/GoodsManager/CNLiveShopAddGoodsSingleView.swift
@@ -321,7 +321,7 @@ class CNLiveShopAddGoodsSingleView: UIView, UITextFieldDelegate { @@ -321,7 +321,7 @@ class CNLiveShopAddGoodsSingleView: UIView, UITextFieldDelegate {
321 321
322 @objc func textDidChange(sender:UITextField) { 322 @objc func textDidChange(sender:UITextField) {
323 if (sender == self.countTF) { 323 if (sender == self.countTF) {
324 - if (self.countTF.text?.count ?? 0 > 0 && self.countTF.text?.isPurnInt() ?? false) { 324 + if (self.countTF.text?.count ?? 0 > 0 && (self.countTF.text?.isPurnInt() == false)) {
325 let count:Int = (self.countTF.text! as NSString).integerValue 325 let count:Int = (self.countTF.text! as NSString).integerValue
326 if (count <= 1) { 326 if (count <= 1) {
327 self.subtractBtn.setImage(UIImage(named: "DS_main_unadd_count_n"), for: .normal) 327 self.subtractBtn.setImage(UIImage(named: "DS_main_unadd_count_n"), for: .normal)
metaCode/Classes/Main/HomePage/View/GoodsManager/CNLiveShopGoodsListCell.swift
@@ -7,8 +7,16 @@ @@ -7,8 +7,16 @@
7 7
8 import Foundation 8 import Foundation
9 9
  10 +typealias editClickBlock = (_ goodsModel:CNLiveShopGoodsListModel)->Void
  11 +typealias operStateClickBlock = (_ goodsModel:CNLiveShopGoodsListModel , _ state:Int)->Void
10 class CNLiveShopGoodsListCell: UITableViewCell { 12 class CNLiveShopGoodsListCell: UITableViewCell {
11 13
  14 + // 操作上下架回调 state:1上架 2下架
  15 + var operStateBlock:operStateClickBlock?
  16 + //编辑按钮回调
  17 + var editBlock:editClickBlock?
  18 + //编辑库存按钮回调
  19 + var editCountBlock:editClickBlock?
12 //goodsModel 20 //goodsModel
13 var _goodsModel : CNLiveShopGoodsListModel? 21 var _goodsModel : CNLiveShopGoodsListModel?
14 var goodsModel : CNLiveShopGoodsListModel? { 22 var goodsModel : CNLiveShopGoodsListModel? {
@@ -29,8 +37,7 @@ class CNLiveShopGoodsListCell: UITableViewCell { @@ -29,8 +37,7 @@ class CNLiveShopGoodsListCell: UITableViewCell {
29 lazy var editBtn: UIButton = { 37 lazy var editBtn: UIButton = {
30 let editBtn = UIButton(type: .custom) 38 let editBtn = UIButton(type: .custom)
31 editBtn.frame = CGRect(x: KSreenWidth-15*2-28, y: 0, width: 15*2+28, height: 15*2+20) 39 editBtn.frame = CGRect(x: KSreenWidth-15*2-28, y: 0, width: 15*2+28, height: 15*2+20)
32 - editBtn.setTitle(" ", for: .normal)  
33 -// editBtn.setTitle("编辑", for: .normal) 40 + editBtn.setTitle("编辑", for: .normal)
34 editBtn.setTitleColor(HexColor("#333333"), for: .normal) 41 editBtn.setTitleColor(HexColor("#333333"), for: .normal)
35 editBtn.titleLabel?.font = Font_15 42 editBtn.titleLabel?.font = Font_15
36 editBtn.addTarget(self, action: #selector(editBtnAction), for: .touchUpInside) 43 editBtn.addTarget(self, action: #selector(editBtnAction), for: .touchUpInside)
@@ -92,6 +99,29 @@ class CNLiveShopGoodsListCell: UITableViewCell { @@ -92,6 +99,29 @@ class CNLiveShopGoodsListCell: UITableViewCell {
92 editCountBtn.addTarget(self, action: #selector(editCountBtnAction), for: .touchUpInside) 99 editCountBtn.addTarget(self, action: #selector(editCountBtnAction), for: .touchUpInside)
93 return editCountBtn 100 return editCountBtn
94 }() 101 }()
  102 + lazy var stateView :CNLiveSwitchView = {
  103 + let stateView = CNLiveSwitchView(frame: CGRect(x: KSreenWidth-80-17, y: 0, width: 80, height: 20))
  104 + stateView.radius = stateView.height/2
  105 + stateView.centerY = self.priceLabel.centerY
  106 + stateView.selectedBgColor = HexColor("#61C464")
  107 + stateView.selectedTitleColor = HexColor("#FFFFFF")
  108 + stateView.unselectedBgColor = HexColor("#F0F0F0")
  109 + stateView.unselectedTitleColor = HexColor("#999999")
  110 + stateView.titleFont = Font_11
  111 + stateView.titles = ["下架","上架"]
  112 + stateView.switchBlock = {index in
  113 + var state = 2
  114 + if index == 0{
  115 + state = 2
  116 + }else{
  117 + state = 1
  118 + }
  119 + if ((self.operStateBlock) != nil) {
  120 + self.operStateBlock!(self.goodsModel!,state)
  121 + }
  122 + }
  123 + return stateView
  124 + }()
95 125
96 override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { 126 override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
97 super.init(style: style, reuseIdentifier: reuseIdentifier) 127 super.init(style: style, reuseIdentifier: reuseIdentifier)
@@ -104,7 +134,8 @@ class CNLiveShopGoodsListCell: UITableViewCell { @@ -104,7 +134,8 @@ class CNLiveShopGoodsListCell: UITableViewCell {
104 contentView.addSubview(self.priceLabel) 134 contentView.addSubview(self.priceLabel)
105 contentView.addSubview(self.bottomLineView) 135 contentView.addSubview(self.bottomLineView)
106 contentView.addSubview(self.countLabel) 136 contentView.addSubview(self.countLabel)
107 -// contentView.addSubview(self.editCountBtn) 137 + contentView.addSubview(self.editCountBtn)
  138 + contentView.addSubview(self.stateView)
108 139
109 } 140 }
110 141
@@ -119,18 +150,26 @@ class CNLiveShopGoodsListCell: UITableViewCell { @@ -119,18 +150,26 @@ class CNLiveShopGoodsListCell: UITableViewCell {
119 self.priceLabel.text = "¥"+(model.price ?? "0.00") 150 self.priceLabel.text = "¥"+(model.price ?? "0.00")
120 if model.state == 2{ 151 if model.state == 2{
121 //设置 上架 152 //设置 上架
  153 + self.stateView.selectIndex = 1
122 }else{ 154 }else{
123 //设置 下架 155 //设置 下架
  156 + self.stateView.selectIndex = 0
124 } 157 }
125 self.countLabel.text = "库存: "+(model.count ?? "0") 158 self.countLabel.text = "库存: "+(model.count ?? "0")
126 } 159 }
127 160
128 // MARK: - BtnAction 161 // MARK: - BtnAction
129 @objc func editBtnAction(){ 162 @objc func editBtnAction(){
130 - 163 + if ((self.editBlock) != nil) {
  164 + self.editBlock!(self.goodsModel!)
  165 + }
131 } 166 }
132 @objc func editCountBtnAction(){ 167 @objc func editCountBtnAction(){
133 - 168 + if ((self.editCountBlock) != nil) {
  169 + self.editCountBlock!(self.goodsModel!)
  170 + }
134 } 171 }
135 172
  173 +// operStateBlock
  174 +
136 } 175 }
metaCode/Classes/Main/HomePage/View/GoodsManager/CNLiveShopGoodsListClassifyView.swift
@@ -3,67 +3,146 @@ @@ -3,67 +3,146 @@
3 // metaCode 3 // metaCode
4 // 4 //
5 // Created by zx on 2023/11/6. 5 // Created by zx on 2023/11/6.
6 -// 6 +// 商品管理 - 顶部分类筛选
7 7
8 import Foundation 8 import Foundation
9 9
10 -class CNLiveShopGoodsListClassifyView: UIView { 10 +//分类的每个小块
  11 +class CNLiveClassifyItem: NSObject {
  12 + var title:String?
  13 + var image:UIImage?
11 14
12 - //最新  
13 - lazy var lastestBtn: UIButton = {  
14 - let lastestBtn = UIButton(type: .custom)  
15 - lastestBtn.frame = CGRect(x: 0, y: 0, width: KSreenWidth*0.5, height: self.height)  
16 - lastestBtn.setTitle("最新", for: .normal)  
17 - lastestBtn.setTitle("最新", for: .selected)  
18 - lastestBtn.titleLabel?.font = Font_14  
19 - lastestBtn.setTitleColor(HexColor("#999999"), for: .normal)  
20 - lastestBtn.setTitleColor(HexColor("#FC1541"), for: .selected)  
21 - lastestBtn.addTarget(self, action: #selector(lastestBtnAction), for: .touchUpInside)  
22 - return lastestBtn  
23 - }() 15 + init(itemTitle:String?,itemImage:UIImage?){
  16 + super.init()
  17 + self.title = itemTitle
  18 + self.image = itemImage
  19 + }
  20 +}
  21 +
  22 +///排序类型
  23 +enum CNLiveGoodsManagerClassifyType:Int {
  24 + ///按最新上架排序
  25 + case newest,
  26 + ///按价格从底到高排序
  27 + priceMin,
  28 + ///按价格从高到底排序
  29 + priceMax
  30 +}
  31 +
  32 +typealias classifyClickBlock = (_ classifyType:CNLiveGoodsManagerClassifyType)->Void
  33 +
  34 +protocol CNLiveGoodsManagerClassifyViewDelegate:NSObjectProtocol{
  35 + /// 已经选中某个item
  36 + /// @param type 类型
  37 + func shopGoodsManagerClassifyViewDidSeleted(type:CNLiveGoodsManagerClassifyType)
  38 +}
  39 +
  40 +class CNLiveShopGoodsListClassifyView: UIView {
24 41
25 - //价格 后面再完善  
26 - lazy var priceBtn: UIButton = {  
27 - let priceBtn = UIButton(type: .custom)  
28 - priceBtn.frame = CGRect(x: KSreenWidth*0.5, y: 0, width: KSreenWidth*0.5, height: self.height)  
29 - priceBtn.setTitle("价格", for: .normal)  
30 - priceBtn.setTitle("价格", for: .selected)  
31 - priceBtn.titleLabel?.font = Font_14  
32 - priceBtn.setTitleColor(HexColor("#999999"), for: .normal)  
33 - priceBtn.setTitleColor(HexColor("#FC1541"), for: .selected)  
34 - priceBtn.addTarget(self, action: #selector(priceBtnAction), for: .touchUpInside)  
35 - return priceBtn  
36 - }() 42 + weak var delegate:CNLiveGoodsManagerClassifyViewDelegate?
  43 + ///当前选择的按钮
  44 + var seletedBtn = UIButton()
  45 + var itemArray:Array<CNLiveClassifyItem> = []
  46 + var type:CNLiveGoodsManagerClassifyType = .newest
37 47
  48 + lazy var scrollView :UIScrollView = {
  49 + let scrollView = UIScrollView(frame: CGRect(x: 0, y: 0, width: KSreenWidth, height: 40))
  50 + scrollView.showsVerticalScrollIndicator = false
  51 + scrollView.showsHorizontalScrollIndicator = false
  52 + return scrollView
  53 + }()
38 54
39 - override init(frame: CGRect) { 55 + required init(frame: CGRect ,itemArray:Array<CNLiveClassifyItem>) {
40 super.init(frame: frame) 56 super.init(frame: frame)
  57 + self.backgroundColor = .white
  58 + self.itemArray = itemArray
41 self.setUI() 59 self.setUI()
42 } 60 }
43 61
44 func setUI(){ 62 func setUI(){
45 - self.addSubview(self.lastestBtn)  
46 -// self.addSubview(self.priceBtn)  
47 - self.lastestBtn.isSelected = true 63 + self.addSubview(self.scrollView)
  64 + //底部灰色线条
  65 + let bottomLine = UILabel.init(frame: CGRectMake(0, 43, KSreenWidth, 1))
  66 + bottomLine.backgroundColor = HexColor("#e4e4e4")
  67 + self.addSubview(bottomLine)
  68 +
  69 + var itemW:CGFloat = 0.0
  70 + let itemH:CGFloat = self.scrollView.height
  71 + //根据最多itemArray的个数计算item显示的宽度,最多显示4个
  72 + if (self.itemArray.count > 4) {
  73 + itemW = KSreenWidth / 4
  74 + }else{
  75 + itemW = KSreenWidth / CGFloat(self.itemArray.count)
  76 + }
  77 + for i in 0..<self.itemArray.count {
  78 + let item = self.itemArray[i]
  79 +
  80 + let btn = UIButton(type: .custom)
  81 + btn.tag = i
  82 + btn.frame = CGRect(x: itemW * CGFloat(i), y: 0, width: itemW, height: itemH)
  83 + btn.setupButtonImageAndTitlePossitionWith(padding: 4, style: .left)
  84 + btn.setTitle(item.title, for: .normal)
  85 + btn.setTitleColor(HexColor("#999999"), for: .normal)
  86 + btn.setTitleColor(HexColor("#FC1541"), for: .selected)
  87 + btn.titleLabel?.font = Font_14
  88 + btn.imageEdgeInsets = UIEdgeInsets(top: 0, left: 4, bottom: 0, right: 0)
  89 + if (item.image != nil){
  90 + btn.setImage(item.image, for: .normal)
  91 + }
  92 + btn.addTarget(self, action: #selector(btnAction(_:)), for: .touchUpInside)
  93 + self.scrollView.addSubview(btn)
  94 + //默认第一个选中
  95 + if (i == 0) {
  96 + btn.isSelected = true
  97 + self.seletedBtn = btn
  98 + }
  99 + /**添加 btn 之间分割线*/
  100 + if (i < self.itemArray.count-1) {
  101 + let line = UIView(frame: CGRect(x: btn.right-1, y: 12, width: 1, height: 20))
  102 + line.backgroundColor = HexColor("#e6e6e6")
  103 + self.scrollView.addSubview(line)
  104 + }
  105 +
  106 + //更新scrollView 的 contentSize
  107 + if (i == self.itemArray.count-1) {
  108 + self.scrollView.contentSize = CGSize(width: btn.right, height: 40)
  109 + }
  110 + }
48 } 111 }
49 112
50 required init?(coder: NSCoder) { 113 required init?(coder: NSCoder) {
51 fatalError("init(coder:) has not been implemented") 114 fatalError("init(coder:) has not been implemented")
52 } 115 }
53 116
54 - public func emptyView(isEmpty:Bool){  
55 - //后面替换成其他  
56 - self.lastestBtn.isHidden = isEmpty 117 + @objc func btnAction(_ btn: UIButton){
  118 + self.seletedBtn.isSelected = false
  119 + btn.isSelected = true
  120 + let item = self.itemArray[btn.tag]
  121 + if (item.title == "价格" && self.seletedBtn.titleLabel?.text == "价格"){
  122 + //切换价格排序规则
  123 + if self.type == .priceMin{
  124 + self.type = .priceMax
  125 + btn.setImage(UIImage(named: "DS_goods_manager_pirce_max"), for: .selected)
  126 + }else{
  127 + self.type = .priceMin
  128 + btn.setImage(UIImage(named: "DS_goods_manager_pirce_min"), for: .selected)
  129 + }
  130 + self.delegate?.shopGoodsManagerClassifyViewDidSeleted(type: self.type)
  131 + }else if (item.title == "价格" && self.seletedBtn.titleLabel?.text != "价格"){
  132 + self.type = .priceMin
  133 + btn.setImage(UIImage(named: "DS_goods_manager_pirce_min"), for: .selected)
  134 + self.delegate?.shopGoodsManagerClassifyViewDidSeleted(type: self.type)
  135 +
  136 +
  137 + }else if (btn.tag == 0 && self.seletedBtn.tag != 0){
  138 + self.type = .newest
  139 + self.delegate?.shopGoodsManagerClassifyViewDidSeleted(type: self.type)
  140 + }else if(btn.tag == 0 && self.seletedBtn.tag == 0)
  141 + {
  142 + //再次选中了最新按钮不做处理
  143 + }
57 144
58 - }  
59 -  
60 - @objc func priceBtnAction(){  
61 - self.priceBtn.isSelected = true  
62 - self.lastestBtn.isSelected = false  
63 - }  
64 - @objc func lastestBtnAction(){  
65 - self.lastestBtn.isSelected = true  
66 - self.priceBtn.isSelected = false 145 + self.seletedBtn = btn
67 } 146 }
68 } 147 }
69 148
metaCode/Classes/Main/HomePage/View/GoodsManager/CNLiveSwitchView.swift 0 → 100644
  1 +//
  2 +// CNLiveSwitchView.swift
  3 +// metaCode
  4 +//
  5 +// Created by zx on 2023/11/14.
  6 +// 商品列表 - 上架,下架Switch
  7 +
  8 +import Foundation
  9 +
  10 +typealias switchClickBlock = (_ index:Int)->Void
  11 +
  12 +class CNLiveSwitchView: UIView {
  13 + //开关点击回调
  14 + var switchBlock:switchClickBlock?
  15 +
  16 + /// 未选中背景颜色 无默认
  17 + var _unselectedBgColor:UIColor?
  18 + var unselectedBgColor:UIColor?{
  19 + get{
  20 + _unselectedBgColor
  21 + }
  22 + set{
  23 + _unselectedBgColor = newValue
  24 + self.resetUI()
  25 + }
  26 + }
  27 + /// 选中背景颜色 无默认
  28 + var _selectedBgColor:UIColor?
  29 + var selectedBgColor:UIColor?{
  30 + get{
  31 + _selectedBgColor
  32 + }
  33 + set{
  34 + _selectedBgColor = newValue
  35 + self.resetUI()
  36 + }
  37 + }
  38 + /// 未选中颜色 无默认
  39 + var _unselectedTitleColor:UIColor?
  40 + var unselectedTitleColor:UIColor?{
  41 + get{
  42 + _unselectedTitleColor
  43 + }
  44 + set{
  45 + _unselectedTitleColor = newValue
  46 + self.resetUI()
  47 + }
  48 + }
  49 + /// 选中颜色 无默认
  50 + var _selectedTitleColor:UIColor?
  51 + var selectedTitleColor:UIColor?{
  52 + get{
  53 + _selectedTitleColor
  54 + }
  55 + set{
  56 + _selectedTitleColor = newValue
  57 + self.resetUI()
  58 + }
  59 + }
  60 + /// 标题 无默认
  61 + var _titleFont:UIFont?
  62 + var titleFont:UIFont?{
  63 + get{
  64 + _titleFont
  65 + }
  66 + set{
  67 + _titleFont = newValue
  68 + self.resetUI()
  69 + }
  70 + }
  71 + /// 选中的索引 默认0
  72 + var _selectIndex:Int = 0
  73 + var selectIndex:Int{
  74 + get{
  75 + _selectIndex
  76 + }
  77 + set{
  78 + _selectIndex = newValue
  79 + self.resetUI()
  80 + }
  81 + }
  82 + /// 标题数组 无默认
  83 + var _titles:NSArray = []
  84 + var titles:NSArray{
  85 + get{
  86 + _titles
  87 + }
  88 + set{
  89 + _titles = newValue
  90 + self.resetUI()
  91 + }
  92 + }
  93 + /// 角度 无默认
  94 + var _radius:CGFloat = 0.0
  95 + var radius:CGFloat{
  96 + get{
  97 + _radius
  98 + }
  99 + set{
  100 + _radius = newValue
  101 + self.resetUI()
  102 + }
  103 + }
  104 + lazy var bgView :CNLiveRoundedRectView = {
  105 + let bgView = CNLiveRoundedRectView()
  106 + return bgView
  107 + }()
  108 +
  109 + override init(frame: CGRect) {
  110 + super.init(frame: frame)
  111 + self.backgroundColor = .clear
  112 + self.setUI()
  113 + }
  114 +
  115 + required init?(coder: NSCoder) {
  116 + fatalError("init(coder:) has not been implemented")
  117 + }
  118 +
  119 + override func layoutSubviews() {
  120 + super.layoutSubviews()
  121 + self.bgView.frame = CGRect(x: 0, y: 0, width: self.width, height: self.height)
  122 + self.bgView.layer.cornerRadius = self.height/2
  123 + self.bgView.clipsToBounds = true
  124 + let titlesCount = CGFloat(self.titles.count)
  125 + let width = self.width/titlesCount
  126 + for i in 0..<self.titles.count {
  127 + let titleBgView = self.bgView.viewWithTag((i+1)*100+1) as! CNLiveRoundedRectView
  128 + let titleBtn = self.bgView.viewWithTag((i+1)*100+2) as! UIButton
  129 + titleBgView.frame = CGRect(x: CGFloat(i)*width, y: 0, width: width, height: self.height)
  130 + titleBtn.frame = CGRect(x: CGFloat(i)*width, y: 0, width: width, height: self.height)
  131 + }
  132 + }
  133 +
  134 + func setUI(){
  135 + self.bgView = CNLiveRoundedRectView(frame: CGRectZero)
  136 + self.bgView.backgroundColor = UIColor(hue:0.00, saturation:0.00, brightness:0.94, alpha:1.00)
  137 + self.addSubview(self.bgView)
  138 + }
  139 +
  140 + func resetUI(){
  141 + self.bgView.subviews.forEach {$0.removeFromSuperview()}
  142 + for i in 0..<self.titles.count {
  143 + let titleBgView = CNLiveRoundedRectView.init()
  144 + titleBgView.tag = (i+1)*100+1
  145 + titleBgView.radius = self.radius
  146 + self.bgView.addSubview(titleBgView)
  147 +
  148 + let titleBtn = UIButton(type: .custom)
  149 + titleBtn.setTitle((self.titles[i] as! String), for: .normal)
  150 + titleBtn.titleLabel?.font = self.titleFont
  151 + titleBtn.addTarget(self, action: #selector(titleBtnClick), for: .touchUpInside)
  152 + titleBtn.tag = (i+1)*100+2
  153 + self.bgView.addSubview(titleBtn)
  154 +
  155 + if self.selectIndex == i{
  156 + titleBgView.fillColor = self.selectedBgColor
  157 + titleBtn.setTitleColor(self.selectedTitleColor, for: .normal)
  158 + }else{
  159 + titleBgView.fillColor = self.unselectedBgColor
  160 + titleBtn.setTitleColor(self.unselectedTitleColor, for: .normal)
  161 + }
  162 + }
  163 + self.layoutSubviews()
  164 + }
  165 +
  166 + @objc func titleBtnClick(sender:UIButton){
  167 + let selectIndex = (sender.tag-2)/100-1
  168 + if self.selectIndex == selectIndex {
  169 + return
  170 + }
  171 + if ((self.switchBlock) != nil) {
  172 + self.switchBlock!(selectIndex)
  173 + }
  174 + }
  175 +}
metaCode/Classes/Main/HomePage/ViewModel/GoodsManager/CNLiveShopGoodListViewModel.swift
@@ -9,20 +9,19 @@ import Foundation @@ -9,20 +9,19 @@ import Foundation
9 import CNLiveRequestBastKit 9 import CNLiveRequestBastKit
10 10
11 class CNLiveShopGoodListViewModel:NSObject{ 11 class CNLiveShopGoodListViewModel:NSObject{
12 - /// 商品列表获取 12 + /// 请求店铺商品列表
13 /// - Parameters: 13 /// - Parameters:
14 /// - shopId:id 14 /// - shopId:id
15 /// - sortType:排序类型 1新品 2价格从底到高 3 价格从高到底 15 /// - sortType:排序类型 1新品 2价格从底到高 3 价格从高到底
16 /// - page:页数 1 16 /// - page:页数 1
17 - static func requestGoodsList(shopId:String?,sortType:String?,page:String?,resultBlock: @escaping downSlideResultBlock) { 17 + static func requestGoodsList(shopId:String?,sortType:String?,page:NSInteger?,resultBlock: @escaping downSlideResultBlock) {
18 let param = NSMutableDictionary() 18 let param = NSMutableDictionary()
19 param.setValue(shopId, forKey: "shop_id") 19 param.setValue(shopId, forKey: "shop_id")
20 param.setValue(sortType ?? "1", forKey: "type") 20 param.setValue(sortType ?? "1", forKey: "type")
21 param.setValue("0", forKey: "state") 21 param.setValue("0", forKey: "state")
22 param.setValue("", forKey: "category_id") 22 param.setValue("", forKey: "category_id")
23 param.setValue("", forKey: "keyword") 23 param.setValue("", forKey: "keyword")
24 - param.setValue(page ?? "1", forKey: "page")  
25 - 24 + param.setValue("\(page ?? 1)", forKey: "page")
26 25
27 CNLiveNetworking.setAllowRequestDefaultArgument(true) 26 CNLiveNetworking.setAllowRequestDefaultArgument(true)
28 CNLiveNetworking.setupShowDataResult(false) 27 CNLiveNetworking.setupShowDataResult(false)
@@ -44,4 +43,54 @@ class CNLiveShopGoodListViewModel:NSObject{ @@ -44,4 +43,54 @@ class CNLiveShopGoodListViewModel:NSObject{
44 } 43 }
45 } 44 }
46 } 45 }
  46 +
  47 + /// 商品单个属性修改
  48 + /// @param shopId 商家id
  49 + /// @param goodsId 商品id
  50 + /// @param type 1修改库存 2修改排序
  51 + /// @param value 修改的值
  52 + /// @param result 结果
  53 + static func postGoodsEditAttrWithShopId(shopId:String,goodsId:String,type:Int,value:String,resultBlock: @escaping downSlideResultBlock){
  54 +
  55 + let param = NSMutableDictionary()
  56 + param.setValue(shopId, forKey: "shop_id")
  57 + param.setValue(goodsId, forKey: "id")
  58 + param.setValue("\(type)", forKey: "type")
  59 + param.setValue(value, forKey: "value")
  60 +
  61 + CNLiveNetworking.setAllowRequestDefaultArgument(true)
  62 + CNLiveNetworking.setupShowDataResult(false)
  63 + CNLiveNetworking.setupDSRequest(true)
  64 + CNLiveNetworking.requestNetwork(with: .POST, urlString: APPBaseWjjBUrl+"/api/v1/goodsEditAttr", param: param as! [String : String], cacheType: .networkOnly) { task, result, error in
  65 + hiddenLoading()
  66 + if (error == nil) {
  67 + resultBlock(result as Any,.success)
  68 + }else{
  69 + resultBlock(NSNull(),.failed)
  70 + }
  71 + }
  72 + }
  73 +
  74 + /// 商品上下架删除
  75 + /// @param goodsId 商品id
  76 + /// @param state 传3为删除 不传为上下架
  77 + /// @param result 结果
  78 + static func postChangeGoodsStateWithGoodsId(goodsId:String,state:String,resultBlock: @escaping downSlideResultBlock){
  79 + let param = NSMutableDictionary()
  80 + param.setValue(state, forKey: "state")
  81 + param.setValue(goodsId, forKey: "id")
  82 +
  83 + CNLiveNetworking.setAllowRequestDefaultArgument(true)
  84 + CNLiveNetworking.setupShowDataResult(false)
  85 + CNLiveNetworking.setupDSRequest(true)
  86 + CNLiveNetworking.requestNetwork(with: .POST, urlString: APPBaseWjjBUrl+"/api/v1/changeGoodsState", param: param as! [String : String], cacheType: .networkOnly) { task, result, error in
  87 + hiddenLoading()
  88 + if (error == nil) {
  89 + resultBlock(result as Any,.success)
  90 + }else{
  91 + resultBlock(NSNull(),.failed)
  92 + }
  93 + }
  94 + }
  95 +
47 } 96 }
metaCode/Supporting Files/Assets.xcassets/Shop/DS_goods_manager_pirce_default.imageset/Contents.json 0 → 100644
  1 +{
  2 + "images" : [
  3 + {
  4 + "idiom" : "universal",
  5 + "scale" : "1x"
  6 + },
  7 + {
  8 + "filename" : "DS_goods_manager_pirce_default@2x.png",
  9 + "idiom" : "universal",
  10 + "scale" : "2x"
  11 + },
  12 + {
  13 + "filename" : "DS_goods_manager_pirce_default@3x.png",
  14 + "idiom" : "universal",
  15 + "scale" : "3x"
  16 + }
  17 + ],
  18 + "info" : {
  19 + "author" : "xcode",
  20 + "version" : 1
  21 + }
  22 +}
metaCode/Supporting Files/Assets.xcassets/Shop/DS_goods_manager_pirce_default.imageset/DS_goods_manager_pirce_default@2x.png 0 → 100644

197 Bytes

metaCode/Supporting Files/Assets.xcassets/Shop/DS_goods_manager_pirce_default.imageset/DS_goods_manager_pirce_default@3x.png 0 → 100644

371 Bytes

metaCode/Supporting Files/Assets.xcassets/Shop/DS_goods_manager_pirce_max.imageset/Contents.json 0 → 100644
  1 +{
  2 + "images" : [
  3 + {
  4 + "idiom" : "universal",
  5 + "scale" : "1x"
  6 + },
  7 + {
  8 + "filename" : "DS_goods_manager_pirce_max@2x.png",
  9 + "idiom" : "universal",
  10 + "scale" : "2x"
  11 + },
  12 + {
  13 + "filename" : "DS_goods_manager_pirce_max@3x.png",
  14 + "idiom" : "universal",
  15 + "scale" : "3x"
  16 + }
  17 + ],
  18 + "info" : {
  19 + "author" : "xcode",
  20 + "version" : 1
  21 + }
  22 +}
metaCode/Supporting Files/Assets.xcassets/Shop/DS_goods_manager_pirce_max.imageset/DS_goods_manager_pirce_max@2x.png 0 → 100644

254 Bytes

metaCode/Supporting Files/Assets.xcassets/Shop/DS_goods_manager_pirce_max.imageset/DS_goods_manager_pirce_max@3x.png 0 → 100644

521 Bytes

metaCode/Supporting Files/Assets.xcassets/Shop/DS_goods_manager_pirce_min.imageset/Contents.json 0 → 100644
  1 +{
  2 + "images" : [
  3 + {
  4 + "idiom" : "universal",
  5 + "scale" : "1x"
  6 + },
  7 + {
  8 + "filename" : "DS_goods_manager_pirce_min@2x.png",
  9 + "idiom" : "universal",
  10 + "scale" : "2x"
  11 + },
  12 + {
  13 + "filename" : "DS_goods_manager_pirce_min@3x.png",
  14 + "idiom" : "universal",
  15 + "scale" : "3x"
  16 + }
  17 + ],
  18 + "info" : {
  19 + "author" : "xcode",
  20 + "version" : 1
  21 + }
  22 +}
metaCode/Supporting Files/Assets.xcassets/Shop/DS_goods_manager_pirce_min.imageset/DS_goods_manager_pirce_min@2x.png 0 → 100644

256 Bytes

metaCode/Supporting Files/Assets.xcassets/Shop/DS_goods_manager_pirce_min.imageset/DS_goods_manager_pirce_min@3x.png 0 → 100644

520 Bytes