Commit 22f558e3 authored by 刘俊宏's avatar 刘俊宏

完善商品列表请求对接

parent 389a3174
......@@ -11,9 +11,14 @@ import SwiftyJSON
import ObjectMapper
import Alamofire
import IQKeyboardManagerSwift
import Kingfisher
class BaseViewController: UIViewController ,NavBarViewDelegate{
// 顶部刷新
let headerMJ = MJRefreshNormalHeader()
// 底部加载
let footerMJ = MJRefreshAutoNormalFooter()
override func viewWillAppear(_ animated: Bool) {
self.navigationController?.navigationBar.isHidden = true
IQKeyboardManager.shared.shouldPlayInputClicks = true
......
......@@ -33,6 +33,8 @@ class GoodsListDataModel: Mappable {
}
func mapping(map: Map) {
count <- map["count"]
goods_res <- map["goods_res"]
}
}
......
......@@ -80,7 +80,7 @@ func getGelipayMobile(_ params:[String:Any],success:@escaping (_ res:Any)->(),fa
}
}
//MARK:--获取商店管理员验证手机号
//params-key(user_token)
//params-key( )
func getShopMobile(_ params:[String:Any],success:@escaping (_ res:Any)->(),failture:@escaping(_ error:Error)->()) {
NetworkRequest.sharedInstance.postRequest("获取商店管理员验证手机号", params, { (rep:DataResponse<GetMobileModel>) in
}, success: { (data) in
......
......@@ -11,6 +11,7 @@ import LGButton
class GoodsCollectionViewCell: UICollectionViewCell {
@IBOutlet weak var goodsImgV: UIImageView!
@IBOutlet weak var codeBtn: UIButton!
@IBOutlet weak var rightBtn: UIButton!
@IBOutlet weak var leftBtn: UIButton!
......
......@@ -201,6 +201,7 @@
<size key="customSize" width="136" height="281"/>
<connections>
<outlet property="codeBtn" destination="4Xi-Jf-NQw" id="ORF-0T-7hL"/>
<outlet property="goodsImgV" destination="T8c-YA-14K" id="jQ2-Zp-Pnu"/>
<outlet property="goodsName" destination="tHK-Kt-m55" id="P8Y-sF-MbY"/>
<outlet property="leftBtn" destination="w99-DC-tI2" id="3Vh-3A-Wlg"/>
<outlet property="lgBtn" destination="MEL-J8-S3c" id="Ja4-8M-q7d"/>
......@@ -222,7 +223,7 @@
<color red="0.92941176470588238" green="0.92941176470588238" blue="0.92941176470588238" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</namedColor>
<namedColor name="灰色字体颜色">
<color red="0.40000000000000002" green="0.40000000000000002" blue="0.40000000000000002" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<color red="0.40000000596046448" green="0.40000000596046448" blue="0.40000000596046448" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</namedColor>
<namedColor name="白色背景色">
<color red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
......
......@@ -13,6 +13,8 @@ class WarehoseMangementListVC: BaseViewController, UISearchBarDelegate, UITableV
weak var searchV: SearchBarView? = nil
@IBOutlet weak var contentView: UIView!
@IBOutlet weak var searchView: UIView!
override func viewDidLoad() {
super.viewDidLoad()
self.view.backgroundColor = UIColor.white
......@@ -46,7 +48,9 @@ class WarehoseMangementListVC: BaseViewController, UISearchBarDelegate, UITableV
tableSearchV.dataSource = self
tableSearchV.separatorStyle = .none
tableSearchV?.register(UINib(nibName: "WarehoseMangementCell", bundle: nil), forCellReuseIdentifier: "WarehoseMangementCell")
if blackBtnView != nil {
blackBtnView.removeFromSuperview()
}
}
//MAKR:--调起搜索后添加个蒙版本
var blackBtnView:UIButton! = nil
......@@ -84,6 +88,8 @@ class WarehoseMangementListVC: BaseViewController, UISearchBarDelegate, UITableV
blackBtnView.removeFromSuperview()
searchV!.resignFirstResponder()
}
let vc = CheckWareHourseViewController()
self.navigationController?.pushViewController(vc, animated: false)
}
var tableV :UITableView!
......
......@@ -13,17 +13,27 @@ class GoodsManageListVC: BaseViewController, UICollectionViewDelegate, UICollect
var collection : UICollectionView? = nil
var layout = UICollectionViewFlowLayout()
private let animations = [AnimationType.from(direction: .bottom, offset: 100.0*glscale)]
private var items = [Any?]()
private let animations = [AnimationType.from(direction: .bottom, offset: 150*glscale)]
weak var showSelectV: SelectContentView! = nil
weak var selectV: HeaderSelectView! = nil
var selectIndexArr = [0,0,0]
var showSelectvIndex = 0
@IBOutlet weak var collectionBgView: UIView!
@IBOutlet weak var changeBgView: UIView!
@IBOutlet weak var searchBgView: UIView!
@IBOutlet weak var contentView: UIView!
weak var searchV: SearchBarView? = nil
//MARK:--请求字段
var pageNum = 1
var pageSearchNum = 1
var keyword = ""
var sort = 1
var isShow = 2
var goodsType = 0
//MARK:--数据处理字段
var items = Array<GoodsResModel>()
var itemsSearch = Array<GoodsResModel>()
var selectIndexArr = [0,0,0]
var showSelectvIndex = 0
var isSearch = false
//MARK:--添加初始化
override func viewDidLoad() {
super.viewDidLoad()
......@@ -36,7 +46,7 @@ class GoodsManageListVC: BaseViewController, UICollectionViewDelegate, UICollect
make.centerY.equalToSuperview()
make.height.equalTo(35)
}
searchV = searchBr
searchBr.placeholderStr = "请输入商品名称"
searchBr.cornerRadius = 35/2.0
searchBr.delegate = self
......@@ -65,36 +75,188 @@ class GoodsManageListVC: BaseViewController, UICollectionViewDelegate, UICollect
self.collection?.register(UICollectionReusableView.self, forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: "headerIdentifier")
//下拉刷新相关设置
headerMJ.setRefreshingTarget(self, refreshingAction: #selector(loadData))
self.collection!.mj_header = headerMJ
//上拉加载相关设置
footerMJ.setRefreshingTarget(self, refreshingAction: #selector(loadMoreData))
self.collection!.mj_footer = footerMJ
self.collection?.mj_header?.beginRefreshing()
DispatchQueue.main.asyncAfter(deadline: .now() + 0.33) {
self.items = Array(repeating: nil, count: 11)
self.collection?.reloadData()
self.collection?.performBatchUpdates({
UIView.animate(views: self.collection!.orderedVisibleCells,
animations: self.animations, completion: {
}
//MARK:--整理排序数据
func getSortData (){
for i in 0..<selectIndexArr.count{
let index = selectIndexArr[i]
if i == 0 {
goodsType = 0
if index == 1{
goodsType = 1
}else if index == 2{
goodsType = 5
}
}else if i == 1{
isShow = 2
if index == 1{
isShow = 0
}else if index == 2{
isShow = 1
}
}else if i == 2{
sort = index + 1
}
}
}
//MARK:--加载数据
@objc func loadData(){
var page = 1
if isSearch{
pageSearchNum = 1
page = pageSearchNum
}else{
pageNum = 1
page = pageNum
}
getSortData ()
goodsList(["user_token":UserToken as Any,"keyword":keyword,"goods_type":goodsType,"sort":sort,"is_show":isShow,"page":page], success: { (data) in
let dataM = data as! GoodsListModel
if self.isSearch {
self.pageSearchNum = 2
self.itemsSearch.removeAll()
dataM.data?.goods_res?.forEach({ (model) in
self.itemsSearch.append(model)
})
}else{
self.pageNum = 2
self.items.removeAll()
dataM.data?.goods_res?.forEach({ (model) in
self.items.append(model)
})
}, completion: nil)
}
//collection动画效果
DispatchQueue.main.asyncAfter(deadline: .now() + 0.33) {
self.collection?.reloadData()
self.collection?.mj_header?.endRefreshing()
self.collection?.mj_footer?.resetNoMoreData()
self.collection?.performBatchUpdates({
UIView.animate(views: self.collection!.orderedVisibleCells,
animations: self.animations, completion: {
})
}, completion: nil)
}
}) { (error) in
self.collection?.mj_header?.endRefreshing()
}
}
//MARK:--加载更多数据
@objc func loadMoreData(){
var page = 2
if isSearch{
page = pageSearchNum
}else{
page = pageNum
}
getSortData ()
goodsList(["user_token":UserToken as Any,"keyword":keyword,"goods_type":goodsType,"sort":sort,"is_show":isShow,"page":page], success: { (data) in
let dataM = data as! GoodsListModel
if (dataM.data?.goods_res!.count)! > 0 {
if self.isSearch {
self.pageSearchNum += 1
dataM.data?.goods_res?.forEach({ (model) in
self.itemsSearch.append(model)
})
}else{
self.pageNum += 1
dataM.data?.goods_res?.forEach({ (model) in
self.items.append(model)
})
}
self.collection?.reloadData()
self.collection?.mj_footer?.endRefreshing()
}else{
self.collection?.mj_footer?.endRefreshingWithNoMoreData()
}
}) { (error) in
self.collection?.mj_footer?.endRefreshing()
}
}
//MARK:--搜索模块
//MAKR:--调起搜索后添加个蒙版本
var blackBtnView:UIButton! = nil
func searchBarShouldBeginEditing(_ searchBar: UISearchBar) -> Bool {
print("调起搜索后添加个蒙版本")
if showSelectV != nil {
showSelectV.removeFromSuperview()
selectV.colseBytitleArr(arr: [], index:showSelectvIndex)
}
blackBtnView = UIButton ()
blackBtnView.backgroundColor = UIColor.init(named: "提示视图背景色")
view.addSubview(blackBtnView)
blackBtnView.snp.makeConstraints { (make) in
make.left.right.bottom.equalToSuperview()
make.top.equalTo(changeBgView.snp_top)
}
blackBtnView.addTarget(self, action: #selector(removeBlackBtnView), for: .touchUpInside)
return true
}
@objc func removeBlackBtnView(){
if blackBtnView != nil {
blackBtnView.removeFromSuperview()
searchV!.resignFirstResponder()
}
}
//MARK:--搜索按钮代理
func searchBarSearchButtonClicked(_ searchBar: UISearchBar) {
print("点击搜索进行--")
print("点击搜索关键字进行--\(searchBar.text)")
searchBar.resignFirstResponder()
if blackBtnView != nil {
blackBtnView.removeFromSuperview()
}
isSearch = true
keyword = searchBar.text!
self.collection?.mj_header?.beginRefreshing()
}
//MARK:--取消搜索代理
//MARK:--清空搜索代理
func clearSearchAction() {
}
//MARK:--编辑即将结束
func searchBarTextDidEndEditing(_ searchBar: UISearchBar) {
print("编辑即将结束了--")
removeBlackBtnView()
if keyword.count > 0 {
keyword = searchBar.text!
if keyword.count == 0 {
isSearch = false
loadData()
}
}
}
//MARK:--新增触发
@IBAction func addNewGoodsAction(_ sender: UIButton) {
print("新增触发-")
if blackBtnView != nil {
blackBtnView.removeFromSuperview()
searchV!.resignFirstResponder()
}
if showSelectV != nil {
showSelectV.removeFromSuperview()
selectV.colseBytitleArr(arr: [], index:showSelectvIndex)
}
let vc = ProductDetailViewController()
self.navigationController?.pushViewController(vc, animated: true)
}
//MARK:--下拉视图各种代理
//MARK:--下拉视图模块
func showAction(sender: Int) {
showSelectvIndex = sender
let showSelectView = SelectContentView()
......@@ -149,17 +311,36 @@ class GoodsManageListVC: BaseViewController, UICollectionViewDelegate, UICollect
}
selectV.colseBytitleArr(arr: arr, index:showSelectvIndex)
loadData()
}
func selectContentvRemoveForSup() {
selectV.colseBytitleArr(arr: [], index:showSelectvIndex)
}
//MARK:--collectionView所有代理
func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
let headerV = collectionView.dequeueReusableSupplementaryView(ofKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: "headerIdentifier", for: indexPath)
headerV.subviews.forEach { (view) in
view.removeFromSuperview()
}
let headerLbl = UILabel(frame: CGRect(x: 15*glscale, y: 10*glscale, width: 100*glscale, height: 20*glscale))
headerLbl.text = "共x件商品"
if isSearch {
if itemsSearch.count > 0 {
headerLbl.text = "共" + StringByInt(number: itemsSearch.count) + "件商品"
}else{
headerLbl.text = ""
}
}else{
if items.count > 0 {
headerLbl.text = "共" + StringByInt(number: items.count) + "件商品"
}else{
headerLbl.text = ""
}
}
headerLbl.textColor = UIColor.init(named: "标题字颜色")
headerLbl.font = UIFont.systemFont(ofSize: 13)
headerV.addSubview(headerLbl)
......@@ -173,17 +354,32 @@ class GoodsManageListVC: BaseViewController, UICollectionViewDelegate, UICollect
return 1
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
if isSearch {
return itemsSearch.count
}
return items.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "GoodsCollectionViewCell", for: indexPath) as! GoodsCollectionViewCell
cell.goodsName.showSkeleton(transition: .crossDissolve(0.25))
cell.priceLbl.showSkeleton(transition: .crossDissolve(0.25))
let rowModel = self.items[indexPath.row]
cell.goodsName.text = rowModel.goods_name
cell.priceLbl.text = "¥" + rowModel.price!
cell.goodsImgV.kf.setImage(with: URL.init(string:SERVERCE_HOST + rowModel.goods_thumb!)!, placeholder: nil, options: nil, progressBlock: nil, completionHandler: nil)
if rowModel.is_show == 0 {
cell.leftBtn.setTitle("下架", for: .normal)
cell.rightBtn.setTitle("入库", for: .normal)
}else if rowModel.is_show == 1{
cell.leftBtn.setTitle("入库", for: .normal)
cell.rightBtn.setTitle("上架", for: .normal)
}
cell.lgBtn.tag = indexPath.row
cell.leftBtn.tag = indexPath.row
cell.rightBtn.tag = indexPath.row
cell.codeBtn.tag = indexPath.row
cell.goodsName.showSkeleton(transition: .crossDissolve(0.25))
cell.priceLbl.showSkeleton(transition: .crossDissolve(0.25))
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
cell.goodsName.hideSkeleton(reloadDataAfter: true, transition: .crossDissolve(0.25))
......@@ -202,4 +398,5 @@ class GoodsManageListVC: BaseViewController, UICollectionViewDelegate, UICollect
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
print("选中===\(indexPath)")
}
}
......@@ -254,7 +254,7 @@ class ProductDetailViewController: BaseViewController,UITableViewDelegate,UITabl
func btnClick(content: String, cell: TitleAndBtnCell) { if cell.nameLbl.text == "商品类型" {
if glSelectView == nil {
let view = GLAlertSelectView(frame: self.view.bounds)
view.isMultipleSelect = false
view.isMultipleSelect = true
view.titleLbl.text = "请选择仓库类型"
view.delegate = self
view.dataArr = ["预售","普通","期货","团购"]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment