// // PLJobsView+.swift,主要放置筛选、排序 // IOS_study // // Created by CC-star on 2025/7/10. // import SwiftUI extension PLJobsView { //筛选 var filterBtn: some View { Button { showOrderView = false showFilterView.toggle()//反转 } label: { HStack(spacing: 3) { Text("筛选") if vm.filter.totalCount > 0 { Text("\(vm.filter.totalCount)").badgeStyle() } arrowIcon(showFilterView) }.tc2().size15() }.disabled(vm.isFcJobs) } var plFilterView: some View { VStack(spacing: 14) { VStack(alignment: .leading) { Text("行业").labelStyleOF() LazyVGrid(columns: [GridItem(.adaptive(minimum: 80))]) { ForEach(kBusinessArr,id: \.self) { business in Button { if vm.filter.business == business { vm.filter.business = nil } else { vm.filter.business = business } } label: { Text(business).frame(maxWidth: .infinity) }.selectBtnStyle(vm.filter.business == business) } } } VStack(alignment: .leading) { Text("城市").labelStyleOF() LazyVGrid(columns: [GridItem(.adaptive(minimum: 70))]) { ForEach(kCityArr,id: \.self) { city in Button { if vm.filter.city == city { vm.filter.city = nil } else { vm.filter.city = city } } label: { Text(city).frame(maxWidth: .infinity) }.selectBtnStyle(vm.filter.city == city) } } } HStack { Button { vm.filter = PLFilter() } label: { Text("清空").appleStyleS() }.buttonStyle(.bordered) Button { showFilterView = false getJobsByOF() } label: { Text("筛选").appleStyleS() }.tint(.aTC).buttonStyle(.borderedProminent) }.padding(.top, 9) }.size14().padding().bg() } //排序 var orderBtn: some View { Button { showFilterView = false showOrderView.toggle()//反转 } label: { HStack(spacing: 3) { Text(vm.order.rawValue) arrowIcon(showOrderView) }.tc2().size15() }.disabled(vm.isFcJobs) } //排序视图 var plOrderView: some View { VStack(spacing: 14) { ForEach(PLOrder.allCases.indices, id: \.self) { index in let order = PLOrder.allCases[index] HStack { Text(order.rawValue).foregroundStyle(vm.order == order ? .accent : .aTC) Spacer() if vm.order == order { Image(systemName: "checkmark.circle.fill").accent() } }.contentShape(Rectangle())//指定点击区域为整个矩形 .onTapGesture { vm.order = order showOrderView = false getJobsByOF() } if order != PLOrder.allCases.last { exDivider() } } }.size15().padding().bg() } func getJobsByOF() {//筛选功能 vm.isOF.toggle() if vm.filter == lastPLFilter && vm.order == lastPLOrder { return }//如果与上次筛选\排序的选择一样,则不请求 lastPLFilter = vm.filter lastPLOrder = vm.order Task { await vm.getJobs(isResFresh: true)//刷新 } } }