70 lines
1.8 KiB
Swift
70 lines
1.8 KiB
Swift
//
|
|
// PostPLJobIView+.swift
|
|
// IOS_study
|
|
//
|
|
// Created by CC-star on 2025/6/29.
|
|
//
|
|
|
|
import SwiftUI
|
|
|
|
extension PostPLJobIView {
|
|
|
|
var postBtn: some View {
|
|
Button {
|
|
// hud.show("提交成功")
|
|
Task {//开启异步任务
|
|
await postJob()
|
|
}
|
|
} label: {
|
|
if vm.isPosting {
|
|
ProgressView().appleStyleP()//提交加载
|
|
}else {
|
|
Text("提交").appleStyle()
|
|
}
|
|
}.disabled(vm.isPosting).padding().bg()
|
|
}
|
|
|
|
func postJob() async {
|
|
if let invalidMsg = invalidMsg {//也可以写成if let invalidMsg
|
|
hud.show(invalidMsg)
|
|
return
|
|
}
|
|
// print("输入ok")
|
|
vm.isPosting = true
|
|
defer {
|
|
vm.isPosting = false
|
|
}
|
|
|
|
UIApplication.shared.hideKeyboard()//收起键盘
|
|
|
|
workPlaceName = draftJob.placeName
|
|
workProvince = draftJob.province
|
|
workCity = draftJob.city
|
|
workContact = draftJob.contact
|
|
|
|
vm.draftJob.companyName = profileVM.user.cName
|
|
|
|
do {
|
|
try await vm.postJob(isEditing: isEditing)
|
|
if !profileVM.user.hasPLJobs {
|
|
profileVM.user.hasPLJobs = true
|
|
try await UserManager.shared.setTo(filed: DBUser.CodingKeys.hasPLJobs.rawValue, true)
|
|
}
|
|
profileVM.shouldRefreshMyPLJobs = true
|
|
if isEditing {
|
|
hud.show("修改成功")
|
|
if !naviPath.isEmpty { naviPath.removeLast() }
|
|
} else {
|
|
hud.show("发布成功")
|
|
tabbarVM.goJobsAndRefresh("兼职")
|
|
}
|
|
scrollView?.scrollTo("title",anchor: .top)
|
|
vm.draftJob = PLJob()
|
|
} catch {
|
|
hud.show("\(error)")
|
|
print("用户上传或修改兼职失败:\(error)")
|
|
}
|
|
// vm.isPosting = false
|
|
}
|
|
}
|