杨锴
2024-11-06 63f7ed967433acee3ae8764c7a077e15c29c41f2
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
//
//  ContactCustomerVC.swift
//  XQMuse
//
//  Created by 无故事王国 on 2024/8/22.
//
 
import UIKit
import RxSwift
import JQTools
 
class ContactCustomerViewModel:RefreshInnerModel<CommonQuestionModel>{
                override func api() -> (Observable<BaseResponse<BaseResponseList<CommonQuestionModel>>>)? {
                                return Services.commonQuestion(page: page, pageSize: 20)
                }
}
 
class ContactCustomerVC: BaseVC {
 
                @IBOutlet weak var tableView: UITableView!
    private var customerImageView:UIImageView?
 
    private var headView:UIView = {
        let v = UIView()
        return v
    }()
 
                private var viewModel = ContactCustomerViewModel()
                private var customerImage:UIImage?
 
    override func viewDidLoad() {
        super.viewDidLoad()
                                title = "联系客服"
 
        headView.bounds = CGRect(x: 0, y: 0, width: JQ_ScreenW, height: 248)
        customerImageView = UIImageView()
        headView.addSubview(customerImageView!)
        customerImageView!.snp.makeConstraints { make in
            make.top.equalTo(50.5)
            make.centerX.equalToSuperview()
            make.width.height.equalTo(130.8)
        }
 
        let hintL = UILabel()
        hintL.text = "扫码添加客服微信"
        hintL.textColor = UIColor(hexString: "#333333")
        hintL.font = .systemFont(ofSize: 13, weight: .medium)
        headView.addSubview(hintL)
        hintL.snp.makeConstraints { make in
            make.top.equalTo(customerImageView!.snp.bottom).offset(13)
            make.centerX.equalToSuperview()
        }
 
        tableView.tableHeaderView = headView
        tableView.separatorStyle = .none
        tableView.backgroundColor = .clear
                                tableView.delegate = self
                                tableView.dataSource = self
                                tableView.showsVerticalScrollIndicator = false
                                tableView.register(UINib(nibName: "ContactCustomerTCell", bundle: nil), forCellReuseIdentifier: "_ContactCustomerTCell")
 
                                viewModel.configure(tableView)
                                viewModel.beginRefresh()
 
                                Services.getCustomerCode().subscribe(onNext: {data in
                                                if let m = data.data{
                self.customerImageView?.sd_setImage(with: URL(string: m))
                                                }
                                }).disposed(by: disposeBag)
 
//        let longPress = UILongPressGestureRecognizer(target: self, action: #selector(longPressCopyAction(_:)))
//        longPress.minimumPressDuration = 0.8
//        image_qrCode.isUserInteractionEnabled = true
//        image_qrCode.addGestureRecognizer(longPress)
    }
 
    @objc private  func longPressCopyAction(_ gesture:UILongPressGestureRecognizer){
//        if gesture.state == .began{
//            if let img = image_qrCode.image{
//                image_qrCode.isUserInteractionEnabled = false
//                UIImageWriteToSavedPhotosAlbum(img, nil,nil, nil)
//                alertSuccess(msg: "保存成功")
//            }
//        }
    }
}
 
extension ContactCustomerVC:UITableViewDelegate & UITableViewDataSource{
                func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
                                let model = viewModel.dataSource.value!.list[indexPath.row]
                                let vc = ContactCustomerDetailVC(model,customerImage: customerImage)
                                push(vc: vc)
                }
 
                func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
                                let model = viewModel.dataSource.value!.list[indexPath.row]
                                let cell = tableView.dequeueReusableCell(withIdentifier: "_ContactCustomerTCell", for: indexPath) as!
                                ContactCustomerTCell
                                cell.setCommonQuestionModel(model)
                                return cell
                }
 
    func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        return 51
    }
 
    func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
 
        var headView  = tableView.dequeueReusableHeaderFooterView(withIdentifier: "headerView")
        if headView == nil{
            headView = UITableViewHeaderFooterView(reuseIdentifier: "headerView")
            headView?.contentView.backgroundColor = .white
            let label = UILabel()
            label.text = "问题类型"
            label.font = .systemFont(ofSize: 15, weight: .bold)
            headView?.contentView.addSubview(label)
            label.snp.makeConstraints { make in
                make.left.equalTo(18)
                make.bottom.equalToSuperview().offset(-4.5)
            }
        }
        headView?.backgroundColor = .white
        return headView
    }
 
                func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
                                return viewModel.dataSource.value?.list.count ?? 0
                }
 
 
}