OrderDetailPage.ets 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. import { BasicType, BookItem, DiaLogSheetControl, IBestToast, YTAvoid, YTHeader, yTRouter } from 'basic'
  2. import { OrderApi } from '../../apis/OrderApi'
  3. import { AddressComp } from '../../components/AddressComp'
  4. import { AddressItemComp } from '../../components/AddressItemComp'
  5. import { buttonComp } from '../../components/BuilderIndex'
  6. import { Address } from '../../model/Address'
  7. import { AddressAddPageState } from '../../model/EnumState'
  8. import { OrderValidationData } from '../../model/OrderModelIndex'
  9. import { CustomTextStyle } from '../../style/CustomTextStyle'
  10. @ComponentV2
  11. struct OrderDetailPage {
  12. @Local safeBottom: number = AppStorage.get(YTAvoid.SAFE_BOTTOM_KEY) as number
  13. // 租借的图书 URL
  14. @Param bookList: BookItem[] = []
  15. @Local forEach: Array<BasicType> = []
  16. // 总价
  17. // todo 默认为邮费
  18. @Local totalPrice: number = 9.99
  19. // 地址信息
  20. @Local address: Address = {}
  21. // 用户订单备注
  22. remark: string = ''
  23. // 提交订单校验
  24. orderValidation: OrderValidationData = {
  25. bookIds: [],
  26. deliveryMethod: 2,
  27. deposit: 0,
  28. payWay: 0,
  29. postFee: 9.99,
  30. userName: '占三峰',
  31. phone: '13598728343',
  32. address: '高新区火炬园路321号韩菲诗.诚享大厦304室内',
  33. region: '福建-厦门-火炬园',
  34. }
  35. // 打开选择地址弹窗
  36. openAddressDialog() {
  37. if(true){
  38. yTRouter.router2IncreaseAddressPage(AddressAddPageState.ADD_AND_USE, (info) => {
  39. let ans = info.result
  40. console.log(`ans = ${JSON.stringify(ans)}`)
  41. })
  42. return
  43. }
  44. // todo 有 地址数据 打开弹窗, 没有进入地址管理页面添加页面添加地址
  45. let control: DiaLogSheetControl = new DiaLogSheetControl(this.getUIContext())
  46. yTRouter.router2BottomDialog({
  47. control: control,
  48. builder: () => { this.AddressSelection(control) },
  49. })
  50. }
  51. // 提交订单
  52. submitOrder() {
  53. if(!this.orderValidation?.phone) {
  54. IBestToast.show('请填写收件人信息')
  55. return
  56. }
  57. // yTRouter.router2BorrowAnsPage()
  58. this.orderValidation.orderPrice = Number.parseFloat(this.totalPrice.toFixed(2))
  59. this.orderValidation.remark = this.remark
  60. OrderApi.checkOrder(this.orderValidation)
  61. }
  62. aboutToAppear(): void {
  63. // 书本价格计算
  64. let total: number = 0.00
  65. this.bookList.forEach((item: BookItem, index) => {
  66. if(item.rentPerDay) {
  67. total += Number.parseFloat(item.rentPerDay)
  68. }
  69. this.orderValidation.bookIds?.push(item.id!)
  70. })
  71. // 生成明细
  72. this.forEach = [
  73. { text: '租借期限', message: '30天' },
  74. { text: '租借时间', message: '快递签收日起30天' },
  75. { text: '租借价格', message: `¥${total.toFixed(2)}` },
  76. { text: '往返运费', message: `¥9.99` },
  77. { text: '租借期限', message: '30天' },
  78. ]
  79. // todo 在有地址列表 或 默认地址的情况下添加地址信息
  80. // todo 订单校验数据结构整合
  81. this.totalPrice += total
  82. this.orderValidation.bookPrice = total
  83. }
  84. build() {
  85. NavDestination() {
  86. Column() {
  87. YTHeader({ defaultStyle: {title:'订单详情'}, bgc: Color.White })
  88. Column(){
  89. List({space: 16}){
  90. ListItem()
  91. // 地址栏
  92. ListItem(){
  93. // todo 订单地址校验
  94. if(this.address?.phone) {
  95. AddressItemComp({type: 0})
  96. } else {
  97. Row(){
  98. Text('+ 添加收件人信息')
  99. .attributeModifier(new CustomTextStyle({ size: 16, weight: 500 }))
  100. }.width('100%')
  101. .borderRadius(8)
  102. .border({width: 2})
  103. .padding({top: 30, bottom: 30})
  104. .justifyContent(FlexAlign.Center)
  105. }
  106. }
  107. .backgroundColor(Color.White)
  108. .onClick(() => { this.openAddressDialog() })
  109. // 租借的图书
  110. ListItem(){
  111. Column({space: 10}){
  112. Row({space: 10}){
  113. Text('租借图书')
  114. .attributeModifier(new CustomTextStyle({ size: 16, weight: 500, color: '#FF000000' }))
  115. Text(`共${this.bookList.length}件`)
  116. .attributeModifier(new CustomTextStyle({ size: 12, weight: 500, color: '#80000000' }))
  117. }
  118. List({space: 15}){
  119. ForEach(this.bookList, (item: BookItem, index) => {
  120. ListItem(){
  121. Image(item.coverUrl)
  122. .width(63)
  123. .height(81)
  124. .borderRadius(6)
  125. .backgroundColor('#FFFECF2F')
  126. .alt($r('[basic].media.png_defaultBook'))
  127. }
  128. })
  129. }.width("100%").height(81)
  130. .scrollBar(BarState.Off)
  131. .listDirection(Axis.Horizontal)
  132. }
  133. .width('100%')
  134. .alignItems(HorizontalAlign.Start)
  135. .padding({left: 16, right: 16, top: 9, bottom: 9})
  136. }
  137. .borderRadius(8)
  138. .border({width: 2})
  139. .backgroundColor(Color.White)
  140. // 订单信息
  141. ListItem(){
  142. Column({space: 16}){
  143. ForEach(this.forEach, (item: BasicType, index) => {
  144. Row(){
  145. Text(item.text)
  146. .attributeModifier(new CustomTextStyle({ size: 14, weight: 500, color: '#FF666666' }))
  147. Text(item.message)
  148. .attributeModifier(new CustomTextStyle({ size: 14, weight: 400, color: '#FF333333' }))
  149. }.width('100%').justifyContent(FlexAlign.SpaceBetween)
  150. })
  151. Divider().height(1).width('100%').backgroundColor('#FF666666')
  152. Row(){
  153. Text('小计')
  154. .attributeModifier(new CustomTextStyle({ size: 14, weight: 500, color: '#FF666666' }))
  155. Text(`¥${this.totalPrice.toFixed(2)}`)
  156. .attributeModifier(new CustomTextStyle({ size: 14, weight: 400, color: '#FF333333' }))
  157. }.width('100%').justifyContent(FlexAlign.SpaceBetween)
  158. }
  159. .padding({left: 16, right: 16, top: 13, bottom: 13})
  160. }
  161. .borderRadius(8)
  162. .border({width: 2})
  163. .backgroundColor(Color.White)
  164. // 支付方式
  165. ListItem(){
  166. Column({space: 16}){
  167. Text('支付方式')
  168. .attributeModifier(new CustomTextStyle({ size: 16, weight: 500, color: '#000000' }))
  169. Divider().height(1).width('100%').backgroundColor('#FF666666')
  170. Row(){
  171. Row({space: 5}){
  172. Image($r('[basic].media.icon_wx'))
  173. .width(20)
  174. .aspectRatio(1)
  175. Text('微信支付')
  176. .attributeModifier(new CustomTextStyle({ size: 14, weight: 500, color: '#666666' }))
  177. }
  178. Image($r('[basic].media.icon_selectSvg'))
  179. .width(14)
  180. .aspectRatio(1)
  181. .fillColor('#20BB06')
  182. }
  183. .width('100%')
  184. .justifyContent(FlexAlign.SpaceBetween)
  185. }
  186. .justifyContent(FlexAlign.Start)
  187. .alignItems(HorizontalAlign.Start)
  188. .padding({left: 16, right: 16, top: 9, bottom: 9})
  189. }
  190. .borderRadius(8)
  191. .border({width: 2})
  192. .backgroundColor(Color.White)
  193. // 备注
  194. ListItem(){
  195. Row({space: 20}){
  196. Text('备注')
  197. .attributeModifier(new CustomTextStyle({ size: 14, weight: 500, color: '#FF666666' }))
  198. TextInput({placeholder: '请输入您的留言', text: $$this.remark})
  199. .padding(0)
  200. .borderRadius(0)
  201. .layoutWeight(1)
  202. .border({width: 0})
  203. .textAlign(TextAlign.End)
  204. .backgroundColor(Color.Transparent)
  205. }.width('100%').justifyContent(FlexAlign.SpaceBetween)
  206. .padding(16)
  207. }
  208. .borderRadius(8)
  209. .border({width: 2})
  210. .backgroundColor(Color.White)
  211. ListItem()
  212. }.width('100%').height('100%')
  213. .scrollBar(BarState.Off)
  214. .padding({left: 15, right: 15})
  215. }.width('100%').layoutWeight(1)
  216. Row(){
  217. Text(){
  218. Span('应付:')
  219. Span(`¥${this.totalPrice.toFixed(2)}`).fontColor('#FFFF0000').fontSize(20)
  220. }
  221. .attributeModifier(new CustomTextStyle({ size: 14, weight: 400, color: '#FF000000' }))
  222. buttonComp('提交订单', 143, 10, new CustomTextStyle({size: 18}), () => {
  223. this.submitOrder()
  224. })
  225. }
  226. .width('100%')
  227. .backgroundColor(Color.White)
  228. .alignItems(VerticalAlign.Center)
  229. .justifyContent(FlexAlign.SpaceBetween)
  230. .shadow({radius: 5, offsetY: 5})
  231. .padding({bottom: this.safeBottom, top: 10, left: 15, right: 15})
  232. }
  233. .width('100%')
  234. .height('100%')
  235. .backgroundColor('#F7F9FA')
  236. }
  237. .hideTitleBar(true)
  238. }
  239. @Builder
  240. AddressSelection(control: DiaLogSheetControl) {
  241. AddressComp({control: control})
  242. }
  243. }
  244. @Builder
  245. function OrderDetailBuilder(_: string, param: Array<BookItem>) {
  246. OrderDetailPage({bookList: param})
  247. }