123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- //
- // PQStuckPointMusicSearchController.swift
- // PQSpeed
- //
- // Created by SanW on 2021/5/6.
- // Copyright © 2021 BytesFlow. All rights reserved.
- //
- import UIKit
- import BFCommonKit
- class PQStuckPointMusicSearchController: PQStuckPointMusicContentController {
- // 选中的总时长
- var selectedTotalDuration: Float64 = 0
- // 选择的总数
- var selectedDataCount: Int = 0
- // 选择的图片总数
- var selectedImageDataCount: Int = 0
- // 当前搜索页数
- var pageNum: Int = 1
- // 当前搜索关键字
- var searchWord: String?
- // 当前选中的index
- var lastSelectedIndex: IndexPath?
- // 热搜数据
- var hotList: [Any] = Array<Any>.init()
- override func viewDidLoad() {
- super.viewDidLoad()
- emptyData?.title = "没有搜索到相关音乐"
- emptyData?.emptyImage = "pic_search_empty"
- emptyRemindView.remindLab.font = UIFont.systemFont(ofSize: 14)
- emptyRemindView.remindLab.textColor = UIColor.hexColor(hexadecimal: "#999999")
- emptyRemindView.frame = CGRect(x: 0, y: 0, width: view.frame.width, height: 200)
- emptyRemindView.emptyData = emptyData
- refreshHandle = { [weak self] _, _ in
- self?.loadRequestData(isRefresh: false)
- }
- }
- /// 开始搜索
- /// - Parameter keyword: 搜索文字
- /// - Returns: <#description#>
- func loadSearchData(keyword: String?) {
- if keyword == nil || (keyword?.count ?? 0) <= 0 {
- cShowHUB(superView: nil, msg: "请先输入搜索内容")
- return
- }
- BFLog(message: "背景音乐--开始搜索背景音乐")
- if keyword != searchWord || (keyword == searchWord && itemList.count <= 0) {
- showEmptyView()
- itemList.removeAll()
- collectionView.reloadData()
- pageNum = 0
- searchWord = keyword
- // SWNetRequest.cancelTask(url: PQENVUtil.shared.materialSearchApi + searchBGMMaterialUrl)
- loadRequestData()
- }
- }
- // 发起搜索请求
- @objc func loadRequestData(isRefresh: Bool = true) {
- pageNum = pageNum + 1
- PQBaseViewModel.searchBGMListData(searchWord, pageNum, 20, videoCount: selectedDataCount - selectedImageDataCount, imageCount: selectedImageDataCount, totalDuration: selectedTotalDuration) { [weak self] bgmList, msg in
- // 处理请求数据
- BFLog(message: "背景音乐--搜索背景音乐成功")
- if bgmList.count <= 0 {
- self?.pageNum = (self?.pageNum ?? 0) - 1
- }
-
- if bgmList.count <= 0, (self?.itemList.count ?? 0) <= 0, (self?.hotList.count ?? 0) > 0 {
- if !(self?.hotList.first is PQEmptyModel){
- self?.hotList.insert(PQEmptyModel(), at: 0)
- }
-
- self?.configMusicListData(isRefresh: true, musicListData: self?.hotList ?? [])
- } else {
- self?.configMusicListData(isRefresh: isRefresh, musicListData: bgmList)
- }
- // 点击上报:用户在搜索框输入文字然后按回车-返回结果后上报
- PQEventTrackViewModel.baseReportUpload(businessType: .bt_buttonClick, objectType: .ot_click_searchSyncedUpMusic, pageSource: .sp_stuck_searchSyncedUpMusic, extParams: ["searchText": self?.searchWord ?? "", "searchResultNumber": bgmList.count, "isSuccess": msg == nil], remindmsg: "卡点视频数据上报-(点击上报:用户在搜索框输入文字然后按回车)")
- }
- }
- /// 清空搜索数据
- /// - Returns: <#description#>
- func clearData() {
- BFLog(message: "背景音乐--清空背景音乐搜索数据")
- hotList.forEach { item in
- if item is PQVoiceModel {
- (item as? PQVoiceModel)?.isSelected = false
- (item as? PQVoiceModel)?.isPlaying = false
- }
- }
- itemList.removeAll()
- searchWord = nil
- pageNum = 0
- lastSelectedIndex = nil
- collectionView.reloadData()
- }
- }
|