|
@@ -7,10 +7,15 @@
|
|
|
//
|
|
|
|
|
|
import UIKit
|
|
|
+import RxSwift
|
|
|
|
|
|
class ShopViewShopInfoTableViewCell: UITableViewCell {
|
|
|
|
|
|
- class func cellWith(tableView:UITableView,indexPath:IndexPath) -> UITableViewCell {
|
|
|
+ let disposeBag = DisposeBag()
|
|
|
+
|
|
|
+ typealias LookButtonClosure = (_ isSelected: Bool) -> Void
|
|
|
+ var lookButtonClosure : LookButtonClosure?
|
|
|
+ class func cellWith(tableView:UITableView,indexPath:IndexPath) -> ShopViewShopInfoTableViewCell {
|
|
|
let ID = "ShopViewShopInfoTableViewCell"
|
|
|
tableView.register(ShopViewShopInfoTableViewCell.self, forCellReuseIdentifier: ID)
|
|
|
let cell : ShopViewShopInfoTableViewCell = tableView.dequeueReusableCell(withIdentifier: ID, for: indexPath) as! ShopViewShopInfoTableViewCell
|
|
@@ -41,6 +46,7 @@ class ShopViewShopInfoTableViewCell: UITableViewCell {
|
|
|
addSubview(shopNameLabel)
|
|
|
addSubview(productNumberLabel)
|
|
|
addSubview(descriptionLabel)
|
|
|
+ addSubview(lookButton)
|
|
|
}
|
|
|
|
|
|
func setupLayouts() {
|
|
@@ -61,11 +67,16 @@ class ShopViewShopInfoTableViewCell: UITableViewCell {
|
|
|
make.height.equalTo(14)
|
|
|
make.bottom.equalTo(shopIconImageView).offset(-11)
|
|
|
}
|
|
|
- descriptionLabel.snp.makeConstraints { (make) in
|
|
|
+ descriptionLabel.snp.remakeConstraints { (make) in
|
|
|
make.top.equalTo(shopIconImageView.snp.bottom).offset(10)
|
|
|
make.left.equalTo(14)
|
|
|
make.right.equalTo(-14)
|
|
|
- make.bottom.equalTo(-20)
|
|
|
+ make.bottom.equalTo(-35)
|
|
|
+ }
|
|
|
+ lookButton.snp.makeConstraints { (make) in
|
|
|
+ make.top.equalTo(descriptionLabel.snp.bottom).offset(10)
|
|
|
+ make.right.equalTo(-18)
|
|
|
+ make.bottom.equalTo(-10)
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -96,6 +107,7 @@ class ShopViewShopInfoTableViewCell: UITableViewCell {
|
|
|
descriptionLabel.textColor = UIColor.white
|
|
|
descriptionLabel.font = kRegularFont14
|
|
|
descriptionLabel.numberOfLines = 0
|
|
|
+ descriptionLabel.sizeToFit()
|
|
|
let str = "彩虹星球专营店主营生鲜蔬菜肉类生禽彩虹星球专营店主营生鲜蔬菜、肉类生禽彩虹彩虹星球专营店主营生鲜蔬菜肉类生禽彩虹星球专营店主营生鲜蔬菜、肉类生禽彩虹彩虹星球专营店主营生鲜蔬菜肉类生禽彩虹星球专营店主营生鲜蔬菜、肉类生禽彩虹…"
|
|
|
let attributeString = NSMutableAttributedString(string:str)
|
|
|
attributeString.changeAllLineSpacing(2)
|
|
@@ -103,15 +115,83 @@ class ShopViewShopInfoTableViewCell: UITableViewCell {
|
|
|
return descriptionLabel
|
|
|
}()
|
|
|
|
|
|
+ lazy var lookButton: UIButton = {
|
|
|
+ let lookButton = UIButton(type: UIButton.ButtonType.custom)
|
|
|
+ lookButton.setTitleColor(UIColor.white, for: UIControl.State.normal)
|
|
|
+ lookButton.titleLabel?.font = kRegularFont14
|
|
|
+ lookButton.isHidden = true
|
|
|
+ lookButton.rx.tap.subscribe(onNext: { [weak self] (data) in
|
|
|
+ lookButton.isSelected = !lookButton.isSelected
|
|
|
+ if let lookButtonClosure = self?.lookButtonClosure {
|
|
|
+ lookButtonClosure(lookButton.isSelected)
|
|
|
+ }
|
|
|
+ }).disposed(by: disposeBag)
|
|
|
+ return lookButton
|
|
|
+ }()
|
|
|
+
|
|
|
var shopModel : ShopModel? {
|
|
|
didSet {
|
|
|
- shopIconImageView.kf.setImage(with: kURLImage(name: shopModel?.logoImg ?? "pic_preload"), placeholder: kImage(name: "pic_preload"))
|
|
|
- shopNameLabel.text = shopModel?.shopName
|
|
|
+
|
|
|
let str = shopModel?.shopDesc
|
|
|
let attributeString = NSMutableAttributedString(string:str ?? "")
|
|
|
attributeString.changeAllLineSpacing(2)
|
|
|
descriptionLabel.attributedText = attributeString
|
|
|
- productNumberLabel.text = "全部商品:200"
|
|
|
+
|
|
|
+
|
|
|
+ let dict = [
|
|
|
+ NSAttributedString.Key.font: UIFont.systemFont(ofSize: 14),
|
|
|
+ ]
|
|
|
+ let height: CGFloat = str?.boundingRect(with: CGSize(width: kScreenWidth-60-28-10, height:CGFloat(MAXFLOAT)), options: .usesLineFragmentOrigin, attributes: dict, context: nil).size.height ?? 0
|
|
|
+ let labelHeight = height
|
|
|
+
|
|
|
+ let count = Int((labelHeight) / descriptionLabel.font.lineHeight)
|
|
|
+
|
|
|
+
|
|
|
+ if (shopModel?.isOpen ?? false) {
|
|
|
+ descriptionLabel.numberOfLines = 0
|
|
|
+ descriptionLabel.lineBreakMode = .byCharWrapping
|
|
|
+ lookButton.isSelected = true
|
|
|
+ lookButton.setImage(UIImage.init(named: "common_word_packup"), for: UIControl.State.selected)
|
|
|
+ lookButton.setTitle("收起", for: UIControl.State.normal)
|
|
|
+ } else {
|
|
|
+ descriptionLabel.numberOfLines = 2
|
|
|
+ descriptionLabel.lineBreakMode = .byTruncatingTail
|
|
|
+ lookButton.isSelected = false
|
|
|
+ lookButton.setImage(kImage(name: "common_word_unfold"), for: UIControl.State.normal)
|
|
|
+ lookButton.setTitle("查看更多", for: UIControl.State.normal)
|
|
|
+ }
|
|
|
+ lookButton.layoutButton(edgeInsetsStyle: ButtonEdgeInsetsStyle.right, imageTitleSpace: 4)
|
|
|
+
|
|
|
+
|
|
|
+ shopIconImageView.kf.setImage(with: kURLImage(name: shopModel?.logoImg ?? "pic_preload"), placeholder: kImage(name: "pic_preload"))
|
|
|
+ shopNameLabel.text = shopModel?.shopName
|
|
|
+
|
|
|
+
|
|
|
+ if count > 2 {
|
|
|
+ descriptionLabel.snp.remakeConstraints { (make) in
|
|
|
+ make.top.equalTo(shopIconImageView.snp.bottom).offset(10)
|
|
|
+ make.left.equalTo(14)
|
|
|
+ make.right.equalTo(-14)
|
|
|
+ make.bottom.equalTo(-35)
|
|
|
+ }
|
|
|
+ lookButton.isHidden = false
|
|
|
+ }else {
|
|
|
+ descriptionLabel.snp.remakeConstraints { (make) in
|
|
|
+ make.top.equalTo(shopIconImageView.snp.bottom).offset(10)
|
|
|
+ make.left.equalTo(14)
|
|
|
+ make.right.equalTo(-14)
|
|
|
+ make.bottom.equalTo(-10)
|
|
|
+ }
|
|
|
+ lookButton.isHidden = true
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ var paginationModel: PaginationModel? {
|
|
|
+ didSet{
|
|
|
+ productNumberLabel.text = "全部商品:\(paginationModel?.total ?? 0)"
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
}
|