CNLiveShopAddGoodsSingleView.swift
14.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
//
// CNLiveShopAddGoodsSingleView.swift
// metaCode
//
// Created by zx on 2023/11/8.
//
import Foundation
///回调
typealias updateBlock = ()->Void
typealias tapClickBlock = (_ singleView:CNLiveShopAddGoodsSingleView)->Void
class CNLiveShopAddGoodsSingleView: UIView, UITextFieldDelegate {
///
var updateFrameBlock:updateBlock?
//
var tapBlock:tapClickBlock?
//model
var _addEditGoodsListModel : CNLiveShopAddEditGoodsListModel?
var addEditGoodsListModel : CNLiveShopAddEditGoodsListModel? {
get{
_addEditGoodsListModel
}
set{
_addEditGoodsListModel = newValue!
self.setupNewUI(model: _addEditGoodsListModel!)
}
}
///标题
lazy var titleLabel: UILabel = {
let titleLabel = UILabel.init(frame: CGRectMake(15 , 15, 145, 20))
// titleLabel.textColor = HexColor("#333333")
// titleLabel.textAlignment = .left
// titleLabel.font = Font_15
// titleLabel.adjustsFontSizeToFitWidth=true
// titleLabel.text = "啊啊啊啊啊"
return titleLabel
}()
//副标题
var subButton = UIButton()
var contentTextField = UITextField()
var delectButton = UIButton()
var rightImageView = UIImageView()
var contentSwitch = UISwitch()
var uploadImageView = CNLiveAddGoodsSelectUploadImageView(frame: CGRectZero)
var contentTextBgView = UIView()
var contentTextView = UITextView()//
var addBtn = UIButton()
var subtractBtn = UIButton()
var countTF = UITextField()
var descLab = UILabel()
var line = UIImageView()
var starImageView = UIImageView()
override init(frame: CGRect) {
super.init(frame: frame)
self.setUI()
}
func setUI(){
}
func setupNewUI(model:CNLiveShopAddEditGoodsListModel){
self.backgroundColor = model.style == "2" ? HexColor("#F6F6F6") : HexColor("#FFFFFF")
if (model.isHaveTo ?? false) {
self.starImageView = UIImageView()
self.starImageView.image = UIImage(named: "DS_shop_manageGoodsDetails_star")
self.starImageView.clipsToBounds = true
self.starImageView.contentMode = .scaleAspectFit
self.addSubview(self.starImageView)
}
self.titleLabel = UILabel()
if (self.addEditGoodsListModel?.style == "2") {
self.titleLabel.textColor = HexColor("#9D9D9D")
self.titleLabel.text = self.addEditGoodsListModel?.title
if (self.addEditGoodsListModel!.touchSubtitle?.count ?? 0 > 0) {
let subBtn = UIButton(type: .custom)
subBtn.frame = CGRect(x: self.width - 50, y: 0, width: 50, height: 50)
subBtn.setTitle("添加通用参数", for: .normal)
subBtn.setTitleColor(HexColor("#0091FF"), for: .normal)
subBtn.titleLabel?.font = Font_14
subBtn.titleLabel?.textAlignment = .right
subBtn.addTarget(self, action: #selector(subBtnAction), for: .touchUpInside)
self.subButton = subBtn
self.addSubview(self.subButton)
}
}else
{
self.titleLabel.textColor = HexColor("#333333")
if (self.addEditGoodsListModel?.subtitle?.count ?? 0 > 0) {
self.titleLabel.text = "\(self.addEditGoodsListModel?.title ?? "")+\(self.addEditGoodsListModel?.subtitle ?? "")"
}else{
self.titleLabel.text = self.addEditGoodsListModel?.title ?? ""
}
}
self.titleLabel.font = Font_14
self.addSubview(self.titleLabel)
if (self.addEditGoodsListModel?.style == "1") {
let contentTextField = UITextField()
contentTextField.returnKeyType = .done
contentTextField.placeholder = "请输入"
contentTextField.font = Font_14
contentTextField.textColor = HexColor(model.contentTextColor ?? "#787878")
contentTextField.delegate = self
if (model.content?.count ?? 0 > 0){ contentTextField.text = model.content
}
if (model.contentTextFieldkeyboardType == "2") {
contentTextField.keyboardType = .decimalPad
}else {
contentTextField.keyboardType = .default
}
self.contentTextField = contentTextField
if (model.contentType == "1") {
self.contentTextField.isUserInteractionEnabled = true
if (model.isDelect ?? false) {
self.delectButton = UIButton(type: .custom)
self.delectButton.setTitle("删除", for: .normal)
self.delectButton.setTitleColor(HexColor("#0091FF"), for: .normal)
self.delectButton.titleLabel?.font = Font_14
self.delectButton.titleLabel?.textAlignment = .right
self.delectButton.addTarget(self, action: #selector(selectDelectParamAction), for: .touchUpInside)
self.addSubview(self.delectButton)
}
}else if (model.contentType == "2") {
self.contentTextField.isUserInteractionEnabled = false
self.rightImageView = UIImageView()
self.rightImageView.image = UIImage(named: "DS_shop_manageGoodsDetails_rightArrow")
self.rightImageView.contentMode = .scaleAspectFit
self.rightImageView.clipsToBounds = true
self.addSubview(self.rightImageView)
self.addGestureRecognizer(UITapGestureRecognizer.init(target: self, action: #selector(selfTap)))
}else {
self.contentTextField.isUserInteractionEnabled = false
self.contentTextField.isHidden = true
self.contentSwitch = UISwitch()
self.contentSwitch.transform = CGAffineTransformMakeScale(0.7, 0.7)
//不写到layoutSubviews中是因为 会变位置
self.contentSwitch.top = (50-self.contentSwitch.height)*0.5
self.contentSwitch.onTintColor = HexColor("#61C464")
self.contentSwitch.tintColor = HexColor("#DBDEDB")
self.contentSwitch.isOn = true
self.contentSwitch.addTarget(self, action: #selector(switchValueChanged), for: .valueChanged)
self.addSubview(self.contentSwitch)
}
self.addSubview(self.contentTextField)
self.height = 50
}else if (model.style == "2") {
self.height = 50
}else if (model.style == "3") {
self.uploadImageView = CNLiveAddGoodsSelectUploadImageView(frame: CGRectZero)
// self.uploadImageView.column = 3
// self.uploadImageView.maxSelectImageCount = model.maxSelectImageCount
// self.uploadImageView.isAbleSelectVideo = model.isAbleSelectVideo
// self.uploadImageView.isDisplySelectCover = model.isAbleSelectCover
// if model.id?.isEmpty {
// self.uploadImageView.deleteImage = UIImage(named: "DS_shop_manageGoodsDetails_delete")
// }
// [self.uploadImageView setChangeFrameCallBack:^{
// weakSelf.height = CGRectGetMaxY(weakSelf.uploadImageView.frame) + DS_adapt_length(15);
// if (weakSelf.changeFrameCallBack) {
// weakSelf.changeFrameCallBack();
// }
// }];
self.addSubview(self.uploadImageView)
}else if (model.style == "4") {
self.contentTextBgView = UIView()
// self.contentTextBgView.fillColor = HexColor("F9F9F9")
// self.contentTextBgView.radius = 8
self.addSubview(self.contentTextBgView)
// self.contentTextView = UITextView()
// self.contentTextView.placeholder = model.placeholder
// self.contentTextView.placeholderColor = HexColor("c6c6c6")
// self.contentTextView.font = Font_14
// self.contentTextView.textColor = HexColor("787878")
// self.contentTextView.delegate = self
// if (model.content?.count ?? 0 > 0){ self.contentTextView.text = model.content
// }
// self.contentTextBgView.addSubview(self.contentTextView)
self.height = 120
}else if (model.style == "5") {
//添加输入框
self.addBtn = UIButton(type: .custom)
self.addBtn.setImage(UIImage(named: "DS_main_add_count"), for: .normal)
self.addBtn.imageView?.contentMode = .scaleAspectFit
self.addBtn.addTarget(self, action: #selector(addBtnClick), for: .touchUpInside)
self.addSubview(self.addBtn)
self.subtractBtn = UIButton(type: .custom)
self.subtractBtn.setImage(UIImage(named: "DS_main_unadd_count_n"), for: .normal)
self.subtractBtn.imageView?.contentMode = .scaleAspectFit
self.subtractBtn.addTarget(self, action: #selector(subtractBtnClick), for: .touchUpInside)
self.addSubview(self.subtractBtn)
self.countTF = UITextField()
self.countTF.text = "1"
self.countTF.textAlignment = .center
self.countTF.font = Font_15
self.countTF.borderStyle = .none
self.countTF.delegate = self
self.countTF.layer.masksToBounds = true
self.countTF.layer.cornerRadius = 5
self.countTF.keyboardType = .numberPad
self.countTF.backgroundColor = HexColor("#F1F1F1")
self.countTF.addTarget(self, action: #selector(textDidChange(sender:)), for: .editingChanged)
self.addSubview(self.countTF)
self.descLab = UILabel()
self.descLab.textColor = HexColor("#C4C4C6)")
self.descLab.font = Font_10
self.descLab.text = model.desc
self.addSubview(self.descLab)
self.height = 60
}
if (model.isDisplayLine ?? false) {
self.line = UIImageView()
self.line.backgroundColor = HexColor("#e6e6e6)")
self.addSubview(self.line)
}
}
override func layoutSubviews() {
super.layoutSubviews()
self.titleLabel.frame = CGRect(x: 15, y: 15, width: 145, height: 20)
if (self.addEditGoodsListModel!.desc?.count ?? 0 > 0 && self.addEditGoodsListModel!.style == "5") {
self.descLab.frame = CGRect(x: 15, y: 35, width: 145, height: 20)
}
self.starImageView.frame = CGRect(x: self.titleLabel.left-3-5, y: 0, width: 5, height: 5)
self.starImageView.centerY = self.titleLabel.centerY
if (self.addEditGoodsListModel?.style == "2"){
self.subButton.frame = CGRect(x: KSreenWidth-130, y: 15, width: 120, height: 20)
}
if (self.addEditGoodsListModel!.style == "1") {
if (self.addEditGoodsListModel!.contentType == "1") {
if (self.addEditGoodsListModel!.isDelect ?? false) {
self.delectButton.frame = CGRect(x: KSreenWidth-50, y: 0, width: 40, height: 50)
self.contentTextField.frame = CGRect(x: self.titleLabel.right+15, y: 0, width: self.width-self.titleLabel.right+15*2-40, height: 50)
}else{
self.contentTextField.frame = CGRect(x: self.titleLabel.right+15, y: 0, width: self.width-self.titleLabel.right-15*2, height: 50)
}
}else if (self.addEditGoodsListModel!.contentType == "2") {
let contentTextFieldMaxW = self.width - self.titleLabel.right-15*3-2
self.contentTextField.sizeToFit()
if (self.contentTextField.width > contentTextFieldMaxW) {
self.contentTextField.width = contentTextFieldMaxW
}
self.contentTextField.left = self.titleLabel.right + 15
self.contentTextField.centerY = self.titleLabel.centerY
self.rightImageView.frame = CGRect(x: self.contentTextField.right+2, y: 0, width: 15, height: 15)
self.rightImageView.centerY = self.titleLabel.centerY
}else {
self.contentSwitch.left = self.titleLabel.right+15
}
self.addSubview(self.contentTextField)
}else if (self.addEditGoodsListModel!.style == "3") {
self.uploadImageView.frame = CGRect(x: 0, y: self.titleLabel.bottom+2, width: self.width, height: 0)
if (self.height == 0) {
self.height = self.uploadImageView.bottom+15
if ((self.updateFrameBlock) != nil) {
self.updateFrameBlock!()
}
}
}else if (self.addEditGoodsListModel!.style == "4") {
self.contentTextBgView.frame = CGRect(x: 15, y: self.titleLabel.bottom+10, width: self.width - 15*2, height: 60)
self.contentTextView.frame = CGRect(x: 10, y: 10, width: self.contentTextBgView.width-10*2, height: self.contentTextBgView.height-10*2)
}else if (self.addEditGoodsListModel!.style == "5") {
self.subtractBtn.frame = CGRect(x: 15+self.titleLabel.right, y: 15, width: 30, height: 30)
self.countTF.frame = CGRect(x: self.subtractBtn.right+2, y: self.subtractBtn.top+5, width: 55, height: 20)
self.addBtn.frame = CGRect(x: self.countTF.right+2, y: self.subtractBtn.top, width: 30, height: 30)
}
self.line.frame = CGRect(x: 15, y: self.height-1, width: self.width-15*2, height: 1)
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
// MARK: - BtnAction
@objc func subBtnAction(){
if ((self.updateFrameBlock) != nil) {
self.updateFrameBlock!()
}
}
@objc func selectDelectParamAction(){
AlertTool.showSystemAlert(title: "确认删除?", message: nil, actionTitles: ["取消","确定"], style: .alert, actionStyles:[.cancel,.default] ) { index in
if (index == 1) {
if ((self.updateFrameBlock) != nil) {
self.updateFrameBlock!()
}
}
}
}
@objc func selfTap(){
if ((self.tapBlock) != nil) {
self.tapBlock!(self)
}
}
@objc func switchValueChanged(){
}
@objc func addBtnClick(){
}
@objc func subtractBtnClick(){
}
@objc func textDidChange(sender:UITextField) {
if (sender == self.countTF) {
if (self.countTF.text?.count ?? 0 > 0 && (self.countTF.text?.isPurnInt() == false)) {
let count:Int = (self.countTF.text! as NSString).integerValue
if (count <= 1) {
self.subtractBtn.setImage(UIImage(named: "DS_main_unadd_count_n"), for: .normal)
}else{
self.subtractBtn.setImage(UIImage(named: "DS_main_unadd_count"), for: .normal)
}
}
}
}
}