Untitled
unknown
swift
3 years ago
34 kB
11
Indexable
//
// CartView.swift
// Garageworks-iOS-Revamp
//
// Created by mac on 15/12/22.
//
import SwiftUI
//import Razorpay
struct CartView: View {
let rsUnicode = "\u{20B9}"
@State var paymentButton: Bool
@State var instructionNumber: String
@State var isComplaintsOpen: Bool = true
@State var isSparesOpen: Bool = true
@State var isRepairsOpen: Bool = true
@State var isShowAppliedCoupon: Bool = false
@Binding var isShowCommonAlertView: Bool
@Binding var nextButtonText : String
@State var isComplaintsShow: Bool = false
@State var isSparesShow: Bool = false
@State var isLabourShow: Bool = false
@State var isQuestionShow: Bool = false
@Binding var tooltipText : String
@State var serviceId = UserDefaultsManager.fetchSelectedServicePackage()?.service_id ?? ""
// @Binding var isShowAppliedCoupon: Bool
@StateObject var calculateCart = CalculateCartObserver()
@StateObject var allCoupon = AllCouponObservable(
vehicle_category: UserDefaultsManager.fetchSelectedModel()?.vehicle_category ?? "",
model: UserDefaultsManager.fetchSelectedModel()?.model_code ?? "",
make: UserDefaultsManager.fetchSelectedMake()?.make_id ?? "",
city: UserDefaultsManager.fetchSelectedArea()?.city ?? "",
mobile: UserDefaultsManager.fetchCustomer()?.mobile ?? "",
package_name: UserDefaultsManager.fetchSelectedServicePackage()?.package_name ?? "")
var body: some View {
GeometryReader{geometry in
if calculateCart.isStatusTrue{
VStack{
ScrollView{
// VStack{
VStack(alignment: .leading ,spacing: 10){
Text("Final Confirmation")
.font(Font.custom(Fonts.product_regular, size: 15))
.foregroundColor(Color.init(hex: Colors.color_gr2))
.multilineTextAlignment(.leading)
.onAppear{
print("first element")
}
// .padding([.top], 10)
VStack(spacing: 5){
HStack{
AsyncImage(url: URL(string: UserDefaultsManager.fetchSelectedCustomerVehicle()?.vehicle_category_icon ?? ""),
content: { image in
image
.resizable()
.aspectRatio(contentMode: .fit)
}, placeholder: {})
.frame(width: geometry.size.width * 0.16, height: 50)
//.padding()
Text("\(UserDefaultsManager.fetchSelectedCustomerVehicle()?.make_name ?? "") \(UserDefaultsManager.fetchSelectedCustomerVehicle()?.model_name ?? "") ")
.font(Font.custom(Fonts.product_medium, size: 16))
.foregroundColor(Color.init(hex:"#0F1C21"))
Spacer()
VStack(spacing: 5){
var convertedDate1 = dateConverterInDDMM(dateString: UserDefaultsManager.fetchSelectedDate() ?? "")
Text("Date & Time")
.font(Font.custom(Fonts.product_regular, size: 12))
.foregroundColor(Color.init(hex: Colors.color_light_gr))
VStack{
// Text(("\(UserDefaultsManager.fetchSelectedTime()?.text ?? "") \(UserDefaultsManager.fetchSelectedDate() ?? "")"))
Text(("\(convertedDate1) \(UserDefaultsManager.fetchSelectedTime()?.text ?? "")"))
.font(Font.custom(Fonts.product_medium, size: 14))
.foregroundColor(Color.init(hex: Colors.color_gr2))
}
}
}
.padding()
Divider()
.frame(height: 0.5)
.padding(.horizontal, 0)
.background(Color.init(hex: Colors.color_e7))
.cornerRadius(5)
.padding(.top, 0)
.cornerRadius(10)
VStack(alignment: .leading,spacing: 10){
HStack{
Text(UserDefaultsManager.fetchSelectedServicePackage()?.package_name ?? "")
.font(Font.custom(Fonts.product_regular, size: 14))
.foregroundColor(Color.init(hex: Colors.color_f1))
Spacer()
Text("\u{20B9}"+"\(UserDefaultsManager.fetchSelectedServicePackage()?.rates ?? "")")
.font(Font.custom(Fonts.product_regular, size: 14))
.foregroundColor(Color.init(hex: Colors.color_f1))
}
.padding([.leading,.trailing])
.padding(.top,15)
// complaints,Spares,laboue *******
VStack(spacing: 10){
//Standard Service VStack
let complaints = UserDefaultsManager.fetchSelectedComplaints().joined(separator: ", ")
if isComplaintsShow {
VStack(alignment: .leading){
HStack{
Text("Specific Complaints")
.font(Font.custom(Fonts.product_regular, size: 14))
.foregroundColor(Color.init(hex: Colors.color_f1))
Spacer()
// if complaints == "" {
if !UserDefaultsManager.fetchSelectedComplaints().isEmpty {
Button(){
self.isComplaintsOpen.toggle()
// self.isSparesOpen = false
// self.isRepairsOpen = false
}label:{
if isComplaintsOpen == false{
Image("Vector 2")
.resizable()
.frame(width: 10, height: 7)
.padding(.trailing,5)
.foregroundColor(Color.init(hex: Colors.color_29))
}
else{
Image("expandArrow")
.resizable()
.foregroundColor(Color.init(hex: Colors.color_29))
.frame(width: 10, height: 7)
.padding(.trailing,5)
}
}
}
// }
}
.padding([.leading,.trailing])
}
//Collapsible and expandable list
if !UserDefaultsManager.fetchSelectedComplaints().isEmpty && isComplaintsOpen{
Text(complaints)
.frame(width: geometry.size.width * 0.8,alignment: .leading)
.multilineTextAlignment(.leading)
.font(Font.custom(Fonts.product_regular, size: 14))
.foregroundColor(Color.init(hex: Colors.color_F6))
.lineLimit(nil)
.fixedSize(horizontal: false, vertical: true) //** It keeps 'width size' and expands 'height size'
// .padding(.leading,14)
}
}
//Specific Complaints VStack--End
//Specific Spares
if isSparesShow{
VStack(alignment: .leading){
HStack{
Text("Specific Spares")
.font(Font.custom(Fonts.product_regular, size: 14))
.foregroundColor(Color.init(hex: Colors.color_f1))
Spacer()
if !UserDefaultsManager.fetchSelectedSpares().isEmpty {
Button(){
self.isSparesOpen.toggle()
// self.isComplaintsOpen = false
// self.isRepairsOpen = false
}label:{
if isSparesOpen == false{
Image("Vector 2")
.resizable()
.frame(width: 10, height: 7)
.padding(.trailing,5)
.foregroundColor(Color.init(hex: Colors.color_29))
}
else{
Image("expandArrow")
.resizable()
.foregroundColor(Color.init(hex: Colors.color_29))
.frame(width: 10, height: 7)
.padding(.trailing,5)
}
}
}
}
.padding([.leading,.trailing])
//Appended array
if !UserDefaultsManager.fetchSelectedSpares().isEmpty && isSparesOpen{
let spares = UserDefaultsManager.fetchSelectedSpares().joined(separator: ", ")
Text(spares)
.frame(width: geometry.size.width * 0.8,alignment: .leading)
.multilineTextAlignment(.leading)
.font(Font.custom(Fonts.product_regular, size: 14))
.foregroundColor(Color.init(hex: Colors.color_F6))
.lineLimit(nil)
.fixedSize(horizontal: false, vertical: true) //** It keeps 'width size' and expands 'height size'
.padding(.leading,14)
}
}
}
//Specific Spares end----
//Specific repairs
if isLabourShow{
VStack(alignment: .leading){
HStack{
Text("Specific Repairs")
.font(Font.custom(Fonts.product_regular, size: 14))
.foregroundColor(Color.init(hex: Colors.color_f1))
Spacer()
if !UserDefaultsManager.fetchSelectedLabour().isEmpty {
Button(){
self.isRepairsOpen.toggle()
// self.isComplaintsOpen = false
// self.isSparesOpen = false
}label:{
if isRepairsOpen == false{
Image("Vector 2")
.resizable()
.frame(width: 10, height: 7)
.padding(.trailing,5)
.foregroundColor(Color.init(hex: Colors.color_29))
}
else{
Image("expandArrow")
.resizable()
.foregroundColor(Color.init(hex: Colors.color_29))
.frame(width: 10, height: 7)
.padding(.trailing,5)
}
}
}
}.padding([.leading,.trailing])
//Appended array
if !UserDefaultsManager.fetchSelectedLabour().isEmpty && isRepairsOpen{
let repairs = UserDefaultsManager.fetchSelectedLabour().joined(separator: ", ")
Text(repairs)
.frame(width: geometry.size.width * 0.8,alignment: .leading)
.multilineTextAlignment(.leading)
.font(Font.custom(Fonts.product_regular, size: 14))
.foregroundColor(Color.init(hex: Colors.color_F6))
.lineLimit(nil)
.fixedSize(horizontal: false, vertical: true) //** It keeps 'width size' and expands 'height size'
.padding(.leading,14)
}
}
}
// battery question
if isQuestionShow{
VStack(alignment: .leading){
Text("\u{2022}"+" \(UserDefaultsManager.fetchBattryQuestion() ?? "")")
// Text(UserDefaultsManager.fetchBattryQuestion() ?? "yes")
.frame(width: geometry.size.width * 0.8,alignment: .leading)
.font(Font.custom(Fonts.product_regular, size: 14))
.foregroundColor(Color.init(hex: Colors.color_bk))
.padding(.leading,14)
Text(UserDefaultsManager.fetchBattryAnswer() ?? "")
.frame(width: geometry.size.width * 0.8,alignment: .leading)
.font(Font.custom(Fonts.product_regular, size: 14))
.foregroundColor(Color.init(hex: Colors.color_bk))
.padding(.leading,16)
}
}
}
// complaints,Spares,laboue end *******
// .onDisappear(){
// UserDefaults.standard.removePersistentDomain(forName: complaints)
// }
} .frame(width: geometry.size.width * 0.9)
.background()
.padding([.leading,.trailing,.bottom])
}
.frame(width: geometry.size.width * 0.9)
.background()
.cornerRadius(10)
}
Text("*Estimate amount will be updated at time of jobcard creation")
.font(Font.custom(Fonts.product_regular, size: 12))
.foregroundColor(Color.init(hex: Colors.color_light_gr))
VStack(alignment: .leading){
Text("Special Instructions/ Comments")
.font(Font.custom(Fonts.product_medium, size: 15))
.foregroundColor(Color.init(hex: Colors.color_gr2))
TextField("Enter your instruction number", text: $instructionNumber)
.font(Font.custom(Fonts.product_medium, size: 14))
.foregroundColor(Color.init(hex: Colors.color_b7))
.frame(width: geometry.size.width * 0.8, height: 35)
.padding()
.background()
.cornerRadius(10)
}
.padding()
// if calculateCart.showProgress {
// ProgressView()
// .padding()
// }
Button(action: {
debugPrint("Apply coupon pressed")
}, label: {
NavigationLink(destination: ApplyCouponView(allCoupons: allCoupon.allCouponObservable?.all_coupons ?? [], isShowAppliedCoupon: $isShowAppliedCoupon).navigationBarHidden(true)){
HStack{
Image("ticket-discount")
.resizable()
.frame(width: 25, height: 25)
Text("Apply Coupon (\(allCoupon.allCouponObservable?.all_coupons.count ?? 0) Offers)")
.font(Font.custom(Fonts.product_medium, size: 14))
.foregroundColor(Color.init(hex: Colors.color_F0))
Spacer()
Image("Forward")
.resizable()
.frame(width: 8, height: 14)
.padding(.trailing,5)
}
.padding()
}
})
.foregroundColor(Color.init(hex: Colors.color_F0))
.frame(width: geometry.size.width * 0.9, height: 56).overlay(
RoundedRectangle(cornerRadius: 10)
.stroke(style: StrokeStyle(lineWidth: 1, dash: [10.0]))
.foregroundColor(Color.init(hex: Colors.color_F0)))
.background()
.cornerRadius(10)
.background()
.cornerRadius(10)
if isShowAppliedCoupon{
VStack(alignment: .leading){
VStack(alignment: .leading){
HStack{
Text("Coupon Applied")
.foregroundColor(Color.white)
.font(.system(size: 13))
Text(UserDefaultsManager.fetchSelectedCoupons()?.coupon_code ?? "")
.foregroundColor(Color.white)
.font(.system(size: 13, weight: .bold))
Spacer()
Button(action: {
debugPrint("Remove button pressed")
}, label: {
Text("Remove")
.font(.system(size: 11))
.padding(.all, 5)
.onTapGesture {
isShowAppliedCoupon = false
}
}).background()
.foregroundColor(Color.black)
.cornerRadius(10)
}
Text(UserDefaultsManager.fetchSelectedCoupons()?.coupon_details ?? "")
.font(.system(size: 13))
.foregroundColor(Color.white)
}
.padding()
}.frame(width: geometry.size.width * 0.9, height: 72)
.background(.green)
.cornerRadius(10)
.padding()
.onAppear{
nextButtonText = "Pay Now"
}
}
VStack(alignment: .leading){
HStack{
Text("Payment Details")
.font(Font.custom(Fonts.product_regular, size: 15))
.foregroundColor(Color.init(hex: Colors.color_gr2))
Image("info-circle")
.resizable()
.frame(width:15,height:15)
.onTapGesture {
isShowCommonAlertView = true
// print(isShowCommonAlertView)
}
.onAppear{
tooltipText = calculateCart.calculateCartObserver?.cart_tooltip_text ?? ""
}
}
.padding(.top)
VStack(spacing: 10){
HStack{
Text("Booking Fee: ")
.font(Font.custom(Fonts.product_regular, size: 14))
.foregroundColor(Color.init(hex: Colors.color_light_gr))
Spacer()
Text("\u{20B9}"+"\(calculateCart.calculateCartObserver?.booking_fee ?? 0)").bold()
.font(Font.custom(Fonts.product_regular, size: 14))
.foregroundColor(Color.init(hex: Colors.color_bk))
}
.padding([.leading,.trailing])
HStack{
Text("Discounts: ")
.font(Font.custom(Fonts.product_regular, size: 14))
.foregroundColor(Color.init(hex: Colors.color_light_gr))
Spacer()
Text(isShowAppliedCoupon ? UserDefaultsManager.fetchSelectedCoupons()?.coupon_code ?? "" : "\u{20B9} \(calculateCart.calculateCartObserver?.discount ?? 0)")
.bold()
.font(Font.custom(Fonts.product_regular, size: 14))
.foregroundColor(Color.init(hex: Colors.color_bk))
}
.padding([.leading,.trailing])
}
.frame(width: geometry.size.width * 0.9, height: 76)
.background()
.cornerRadius(10)
}
let pay_now = calculateCart.calculateCartObserver?.pay_now
let pay_later = calculateCart.calculateCartObserver?.pay_later
if pay_now == "1" && pay_later == "1"{
if isShowAppliedCoupon {
Text("")
.onAppear{
self.nextButtonText = "Pay Now"
}
}else{
HStack(spacing: 20){
RadioButtonGroupsGeneral(selectedId: "Pay Now", items: ["Pay Now", "Pay Later"]){ selection in
if(selection == "Pay Later" ){
nextButtonText = "Pay Later"
}else{
nextButtonText = "Pay Now"
}
}
}
.padding()
}
}else if pay_later == "1" {
Text("")
.onAppear{
self.nextButtonText = "Pay Later"
}
}
// else if calculateCart.calculateCartObserver?.pay_now == "1" {
// nextButtonText = "Pay Now"
// }
}.frame(width:geometry.size.width, height:geometry.size.height * 0.91,alignment: .top)
.padding()
}
.frame(width:geometry.size.width, height:geometry.size.height * 0.99,alignment: .bottom)
.background(Color.init(hex: Colors.color_gr))
.cornerRadius(30, corners: [.topLeft, .topRight])
.edgesIgnoringSafeArea(.bottom)
.onAppear{
if(serviceId == "11"){
isSparesShow = true
}else if(serviceId == "2"){
isComplaintsShow = true
isLabourShow = true
}else if(serviceId == "5" || serviceId == "6"){
isQuestionShow = true
}else{
isSparesShow = true
isComplaintsShow = true
isLabourShow = true
}
}
}else{
ProgressView()
.frame(width:geometry.size.width, height:geometry.size.height * 0.91,alignment: .center)
}
// if(isShowCommonAlertView){
// VStack{
//
// }
// .frame(width:UIScreen.main.bounds.width ,height:UIScreen.main.bounds.height,alignment: .top)
// .background(Color.black.opacity(0.5))
// .disabled(true)
// // CommonAlertView(isShowCommonAlertView: $isShowCommonAlertView)
// // Text(splitFeatures(feature:servicePackages?.benefits ?? ""))
//
// GenericAlertView(title: "Disclaimer", description: splitFeaturesForNewLine(feature:(calculateCart.calculateCartObserver?.cart_tooltip_text ?? "")), isShowCommonAlertView : $isShowCommonAlertView)
// }
}
// .environmentObject(calculateCart)
}
}
struct CartView_Previews: PreviewProvider {
static var previews: some View {
CartView(paymentButton: false, instructionNumber: "", isShowCommonAlertView: .constant(false), nextButtonText: .constant("Pay Now"), tooltipText: .constant(""))
}
}
Editor is loading...