PurchaseView.swift 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. //
  2. // PurchaseView.swift
  3. // AIEmoji
  4. //
  5. // Created by 100Years on 2025/6/30.
  6. //
  7. import SwiftUI
  8. import SwiftUIX
  9. struct PurchaseView :View {
  10. @ObservedObject var viewModel: PurchaseViewModel
  11. var body: some View {
  12. let vipType = PurchaseManager.default.vipType
  13. VStack {
  14. Spacer()
  15. VStack(alignment: .leading, spacing: 12, content: {
  16. TSFeatureItemView(image: .purchaseIconPhoto, text: "Unlimited Photo Filters & Styles".localized)
  17. TSFeatureItemView(image: .purchaseIconUnlimited, text: "Unlimited AI Image Generation".localized)
  18. TSFeatureItemView(image: .purchaseIconVideo, text: String(format: "%d Video Effects & Video Generations".localized,viewModel.selectedType.creatVideoMaxNum))
  19. TSFeatureItemView(image: .purchaseIconAd, text: "No Ads or Watermarks".localized)
  20. }).multilineTextAlignment(.center).font(.font(size: 16,weight:.regular)).foregroundColor(.white)
  21. // VStack {
  22. // let text = vipType == .none ? "Get PRO Access".localized : "Super Offer for Yearly Pro".localized
  23. // Text(text)
  24. // .multilineTextAlignment(.center)
  25. // .font(.font(name: .PoppinsBoldItalic,size: 26))
  26. // .foregroundColor(UIColor.white.color)
  27. // .frame(width: k_ScreenWidth - 32, alignment: .center)
  28. //
  29. // if vipType == .none {
  30. // Spacer().frame(height: 12)
  31. // HStack {
  32. // Text("Unlimited")
  33. // .foregroundColor("#FECB34".uiColor.color)
  34. //
  35. // Text("Generation")
  36. // .foregroundColor(UIColor.white.color)
  37. //
  38. // }
  39. // .multilineTextAlignment(.center)
  40. // .font(.font(name: .PoppinsBoldItalic,size: 26))
  41. // .frame(height: 26*kDesignScale)
  42. // }
  43. // }
  44. Spacer().frame(height: 32)
  45. VStack(spacing: 12) {
  46. if vipType == .none {
  47. ZStack(alignment: .topTrailing) {
  48. // //增加月付费
  49. // PurchaseItemView(title: "One Month".localized, type: .month, selectedType: $viewModel.selectedType).onTapGesture {
  50. // viewModel.selectedType = .month
  51. PurchaseItemView(title: "One Year".localized, type: .year, selectedType: $viewModel.selectedType).onTapGesture {
  52. viewModel.selectedType = .year
  53. viewModel.buyPublisher.send(true)
  54. }
  55. TSVipRecView(save: vipType.saveString)
  56. .offset(x:-30,y:-14)
  57. }
  58. PurchaseItemView(title: "One Week".localized, type: .week(.week), selectedType: $viewModel.selectedType).onTapGesture {
  59. viewModel.selectedType = .week(.week)
  60. viewModel.buyPublisher.send(true)
  61. }
  62. }else{
  63. PurchaseItemTypeOneView(title: "One Year".localized, type: .year, selectedType: $viewModel.selectedType).onTapGesture {
  64. viewModel.selectedType = .year
  65. viewModel.buyPublisher.send(true)
  66. }
  67. }
  68. Spacer().frame(height: 4)
  69. Button {
  70. viewModel.buyPublisher.send(true)
  71. } label: {
  72. ZStack {
  73. UIColor.themeColor.color
  74. Text("Unlock All Features".localized)
  75. .font(.font(size: 16,weight: .medium))
  76. .foregroundColor(.hex("#111111"))
  77. }.frame(maxWidth: .infinity ,minHeight: 48.0,maxHeight: 48.0)
  78. .cornerRadius(24.0)
  79. }
  80. HStack {
  81. Text("Recurring billing, cancel anytime".localized)
  82. .foregroundColor(Color.hex("#FFBD59")) +
  83. Text(",Payment will be charged to your iTunes account at confirmation of purchase. Subscriptions automatically renew for the same applicable term and price, unless auto-renew is turned off at least 24 hours before the end of the current period.".localized)
  84. .foregroundColor(UIColor.lesserText.color)
  85. }
  86. .multilineTextAlignment(.center).font(.font(size: 8))
  87. .onTapGesture {
  88. viewModel.privacyPublisher.send(true)
  89. }
  90. Spacer().frame(height: 6.0)
  91. HStack(spacing: 8) {
  92. Text("Terms of Service".localized)
  93. .onTapGesture {
  94. viewModel.termPublisher.send(true)
  95. }
  96. Text("|")
  97. Text("Privacy Policy".localized)
  98. .onTapGesture {
  99. viewModel.privacyPublisher.send(true)
  100. }
  101. if vipType == .none {
  102. Text("|")
  103. Text("Restore".localized)
  104. .onTapGesture {
  105. viewModel.restorePublisher.send(true)
  106. }
  107. }
  108. }.font(.system(size: 12)).foregroundColor(.hex("#999999"))
  109. }.padding(.horizontal)
  110. Spacer().frame(height:9+k_Height_safeAreaInsetsBottom())
  111. }
  112. }
  113. // 定义一个返回 View 的方法
  114. func customText(text:String,fontName:FontName,color:Color) -> some View {
  115. let gorgeousColor = color //UIColor.themeColor.color
  116. return Text(text)
  117. .font(.font(name: fontName,size: 48))
  118. .gradientForeground(
  119. colors: [.hex("#FA794F"),.hex("#F8C32A"),.hex("#FEFBF4")],
  120. startPoint: UnitPoint.leading,
  121. endPoint: UnitPoint.trailing
  122. )
  123. .foregroundColor(gorgeousColor)
  124. .frame(height: 20)
  125. }
  126. }
  127. struct PurchaseItemView: View {
  128. var title: String
  129. var type: PremiumPeriod
  130. @Binding var selectedType: PremiumPeriod
  131. var body: some View {
  132. ZStack {
  133. Color.white.opacity(0.1)
  134. HStack {
  135. //左边加个
  136. VStack(alignment: .leading, spacing: 14) {
  137. Text(title).font(.font(size: 14)).foregroundColor(UIColor.white.color)
  138. HStack {
  139. Text(PurchaseManager.default.price(for: type) ?? "--").font(.font(size: 18,weight: .medium)).foregroundColor(UIColor.mainText.color)
  140. if type == .year { //.month {//增加月付费
  141. Text(" (≈\(PurchaseManager.default.averageWeekly(for:type) ?? "--")/\("Per week".localized))").font(.font(size: 12,weight: .medium)).foregroundColor(UIColor.mainText.withAlphaComponent(0.6).color)
  142. }
  143. }
  144. }
  145. Spacer()
  146. //
  147. // //右边每周的💰
  148. // VStack(alignment: .trailing, spacing: 2) {
  149. // Text("\(PurchaseManager.default.averageWeekly(for:type) ?? "--")")
  150. // Text("Per week".localized)
  151. //
  152. // }.font(.font(size: 16,weight: .regular)).foregroundColor(Color.white.opacity(0.6))
  153. }.padding(.horizontal)
  154. }
  155. .frame(height: 74) // 设置高度
  156. .cornerRadius(16.0) // 圆角
  157. .overlay(
  158. RoundedRectangle(cornerRadius: 16)
  159. .stroke(Color.hex("#FECB34"), lineWidth: type == selectedType ? 1 : 0) // 边框
  160. )
  161. }
  162. }
  163. struct PurchaseItemTypeOneView: View {
  164. var title: String
  165. var type: PremiumPeriod
  166. @Binding var selectedType: PremiumPeriod
  167. var body: some View {
  168. ZStack {
  169. Color.white.opacity(0.1)
  170. HStack {
  171. //左边加个
  172. VStack(alignment: .leading, spacing: 8) {
  173. Text(title).font(.font(size: 14,weight: .medium)).foregroundColor(UIColor.white.color)
  174. Text(String(format:"Only %@ per day".localized,"\(PurchaseManager.default.averageDay(for:type) ?? "--")"))
  175. .font(.font(size: 12,weight: .medium))
  176. . foregroundColor(UIColor.white.color).opacity(0.7)
  177. }
  178. Spacer()
  179. Text(PurchaseManager.default.price(for: type) ?? "--").font(.font(size: 18,weight: .medium)).foregroundColor(UIColor.mainText.color)
  180. }.padding(.horizontal)
  181. }
  182. .frame(height: 74) // 设置高度
  183. .cornerRadius(16.0) // 圆角
  184. .overlay(
  185. RoundedRectangle(cornerRadius: 16)
  186. .stroke(Color.hex("#FECB34"), lineWidth: type == selectedType ? 1 : 0) // 边框
  187. )
  188. }
  189. }
  190. //推荐选择view
  191. struct TSVipRecView: View {
  192. var save:String //年 80%,月 30%
  193. var body: some View {
  194. HStack(spacing: 4) {
  195. Image("upvote_black").resizable().frame(width: 16, height: 16)
  196. Text("Save-Vip".localized + " " + save).font(.font(size: 12,weight: .medium)).foregroundColor(.hex("#111111"))
  197. }
  198. .padding(EdgeInsets(top: 6, leading: 6, bottom: 6, trailing: 6))
  199. .background(Color.hex("#FECB34"))
  200. .frame(height: 28) // 设置高度
  201. .cornerRadius([.topLeading, .topTrailing, .bottomLeading, .bottomTrailing], 16.0)
  202. }
  203. }
  204. //推荐选择view
  205. struct TSFeatureItemView: View {
  206. var image:ImageResource
  207. var text:String
  208. var body: some View {
  209. let backgroundColor = Color.clear
  210. ZStack {
  211. HStack(alignment: .center, spacing: 12) {
  212. Image(image).resizable().frame(width: 24, height: 24)
  213. Text(text)
  214. }
  215. }
  216. }
  217. }