Commit 8c1183ce authored by Alex朱枝文's avatar Alex朱枝文

优化UI

parent 7339b650
......@@ -91,6 +91,7 @@ class YHCustomerInformationQuestionnaireVC: YHBaseViewController {
private var displayedQuestions: [YHSurveyQuestionItem] = []
/// key: 问题Id, value: 答案
private var answerDic: [String: [YHSurveyConditionOptionExtra]] = [:]
private var needShowFail: Bool = false
override func viewDidLoad() {
super.viewDidLoad()
......@@ -153,6 +154,15 @@ class YHCustomerInformationQuestionnaireVC: YHBaseViewController {
guard let surveyContent = viewModel.surveyContainerModel?.surveyContent else {
return
}
if let lastQuestion = displayedQuestions.last, lastQuestion.isRequired == 1, answerDic[lastQuestion.id] == nil {
needShowFail = true
let sections = tableView.numberOfSections
if sections > 0 {
tableView.reloadSections(IndexSet(integer: sections - 1), with: .automatic)
}
needShowFail = false
return
}
YHHUD.show(.progress(message: "加载中..."))
var answers: [YHSurveyArticleAnswerItem] = []
displayedQuestions.forEach { [weak self] question in
......@@ -307,7 +317,11 @@ extension YHCustomerInformationQuestionnaireVC: UITableViewDelegate, UITableView
}
}
}
cell.configure(with: "\(indexPath.section + 1). " + model.title, isRequired: model.isRequired == 1, options: model.options.compactMap { $0.title }, selectedIndices: selectedIndices)
var needShowFailButton = false
if needShowFail, model.isRequired == 1, answerDic[model.id] == nil {
needShowFailButton = true
}
cell.configure(with: "\(indexPath.section + 1). " + model.title, isRequired: model.isRequired == 1, options: model.options.compactMap { $0.title }, selectedIndices: selectedIndices, needShowFailButton: needShowFailButton)
cell.optionSelected = { [weak self] index in
guard let self = self else {
return
......@@ -344,6 +358,7 @@ extension YHCustomerInformationQuestionnaireVC: UITableViewDelegate, UITableView
self.displayedQuestions.append(nextQuestion)
self.tableView.insertSections(IndexSet(integer: currentIndex + 1), with: .bottom)
} completion: { [weak self] _ in
self?.tableView.reloadSections(IndexSet(integer: currentIndex), with: .automatic)
self?.scrollToBottom()
}
}
......
......@@ -36,6 +36,15 @@ class YHSurveyTableViewCell: YHResignDocumentCell {
stack.distribution = .fillProportionally
return stack
}()
private lazy var infoFailLabel: UILabel = {
let label = UILabel()
label.font = .PFSC_R(ofSize: 12)
label.textColor = .failColor
label.text = "请选择"
label.isHidden = true
return label
}()
// MARK: - Properties
......@@ -59,6 +68,7 @@ class YHSurveyTableViewCell: YHResignDocumentCell {
updateCellCorner(.single)
subContainerView.addSubview(questionLabel)
subContainerView.addSubview(optionsStackView)
subContainerView.addSubview(infoFailLabel)
questionLabel.snp.makeConstraints { make in
make.top.equalToSuperview().offset(24)
......@@ -72,11 +82,18 @@ class YHSurveyTableViewCell: YHResignDocumentCell {
make.right.equalToSuperview().offset(-18)
make.bottom.equalToSuperview().offset(-24).priority(.high)
}
infoFailLabel.snp.makeConstraints { make in
make.left.equalTo(questionLabel)
make.right.lessThanOrEqualToSuperview().offset(-18)
make.bottom.equalToSuperview().offset(-24).priority(.high)
}
infoFailLabel.isHidden = true
}
// MARK: - Configuration
func configure(with question: String, isRequired: Bool = true, options: [String], selectedIndices: [Int], type: QuestionType = .singleChoice) {
func configure(with question: String, isRequired: Bool = true, options: [String], selectedIndices: [Int], type: QuestionType = .singleChoice, needShowFailButton: Bool = false) {
let questionAttr: ASAttributedString = .init("\(question)", .font(UIFont.PFSC_M(ofSize: 15)), .foreground(UIColor.mainTextColor))
if isRequired {
let starAttr: ASAttributedString = .init("*", .font(UIFont.PFSC_M(ofSize: 15)), .foreground(UIColor.failColor))
......@@ -94,6 +111,37 @@ class YHSurveyTableViewCell: YHResignDocumentCell {
let optionView = createOptionView(text: option, isSelected: selectedIndices.contains(index), index: index)
optionsStackView.addArrangedSubview(optionView)
}
updateFailState(needShowFailButton)
}
private func updateFailState(_ needShowFailButton: Bool = false) {
if needShowFailButton {
optionsStackView.snp.remakeConstraints { make in
make.top.equalTo(questionLabel.snp.bottom).offset(16)
make.left.equalToSuperview().offset(28)
make.right.equalToSuperview().offset(-18)
}
infoFailLabel.snp.remakeConstraints { make in
make.top.equalTo(optionsStackView.snp.bottom).offset(8)
make.left.equalTo(questionLabel)
make.right.lessThanOrEqualToSuperview().offset(-18)
make.bottom.equalToSuperview().offset(-24).priority(.high)
}
infoFailLabel.isHidden = false
} else {
optionsStackView.snp.remakeConstraints { make in
make.top.equalTo(questionLabel.snp.bottom).offset(16)
make.left.equalToSuperview().offset(28)
make.right.equalToSuperview().offset(-18)
make.bottom.equalToSuperview().offset(-24).priority(.high)
}
infoFailLabel.snp.remakeConstraints { make in
make.left.equalTo(questionLabel)
make.right.lessThanOrEqualToSuperview().offset(-18)
make.bottom.equalToSuperview().offset(-24).priority(.high)
}
infoFailLabel.isHidden = true
}
}
private func createOptionView(text: String, isSelected: Bool, index: Int) -> UIView {
......
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