Ver Fonte

feat: 新增订单校验接口

YuJing há 1 mês atrás
pai
commit
afc1da8b39

+ 2 - 2
commons/basic/src/main/ets/utils/arkts/utils/YTRouter.ets

@@ -173,8 +173,8 @@ class YTRouter extends NavPathStack {
   }
 
   // 进入订单详情确认页
-  router2OrderDetailPage(){
-    this.pushPathByName('OrderDetailPage', null)
+  router2OrderDetailPage(params: Array<BookItem>){
+    this.pushPathByName('OrderDetailPage', params)
   }
 
   // 进入搜索结果页

+ 1 - 0
commons/basic/src/main/resources/base/media/icon_selectSvg.svg

@@ -0,0 +1 @@
+<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1762765563482" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="4564" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="200"><path d="M512 10.180608C235.034624 10.180608 10.508288 235.266048 10.508288 512.9216S235.034624 1015.66464 512 1015.66464s501.491712-225.08544 501.491712-502.74304S788.965376 10.180608 512 10.180608z m263.69024 359.264256L442.761216 736.657408a40.96 40.96 0 0 1-59.342848 1.417216l-158.398464-158.79168c-15.976448-16.01536-15.94368-41.951232 0.07168-57.92768 16.01536-15.970304 41.949184-15.94368 57.925632 0.07168l127.981568 128.301056 304.003072-335.306752c15.19616-16.758784 41.099264-18.026496 57.856-2.832384 16.758784 15.194112 18.028544 41.097216 2.832384 57.856z" fill="#2E333A" p-id="4565"></path></svg>

BIN
commons/basic/src/main/resources/base/media/icon_wx.png


+ 6 - 0
features/feature/src/main/ets/apis/ApiUrl.ets

@@ -54,4 +54,10 @@ export class ApiUrl {
    * @method POST
    */
   static removeBookFromBag = '/api/book/bookSchoolbag/removeBook';
+
+  /**
+   * @description 校验订单信息
+   * @method POST
+   */
+  static checkOrder = '/api/book/order/checkOrder';
 }

+ 9 - 0
features/feature/src/main/ets/apis/OrderApi.ets

@@ -1,4 +1,5 @@
 import { BookItem, YTRequest } from "basic";
+import { OrderValidationData } from "../model/OrderModelIndex";
 import { PageResponse } from "../model/PageResponse";
 import { bookPackageQuery } from "../model/Query";
 import { ApiUrl } from "./ApiUrl";
@@ -29,4 +30,12 @@ export class OrderApi {
     return YTRequest.post<ESObject>(ApiUrl.removeBookFromBag, {bookIds})
   }
 
+  /**
+   * @description 订单验证
+   * @param orderValidation
+   * @returns
+   */
+  static checkOrder(orderValidation: OrderValidationData): Promise<ESObject> {
+    return YTRequest.post<ESObject>(ApiUrl.checkOrder, orderValidation)
+  }
 }

+ 11 - 3
features/feature/src/main/ets/components/AddressItemComp.ets

@@ -1,3 +1,4 @@
+import { Address } from "../model/Address"
 import { CustomTextStyle } from "../style/CustomTextStyle"
 
 @ComponentV2
@@ -10,6 +11,13 @@ export struct AddressItemComp {
   @Param isLocation: boolean = true
   @Param align_: VerticalAlign = VerticalAlign.Center
 
+  @Param address: Address = {
+    userName: '占三峰',
+    phone: '13598728343',
+    address: '高新区火炬园路321号韩菲诗.诚享大厦304室内',
+    region: '福建-厦门-火炬园',
+  }
+
   @Event click: () => void
 
   build() {
@@ -22,12 +30,12 @@ export struct AddressItemComp {
 
 
       Column({space: 5}){
-        Text('福建省厦门市火炬园高新区火炬园路321号韩菲诗.诚享大厦304室内')
+        Text(`${this.address.region?.split('-').join('')}${this.address.address}`)
           .attributeModifier(new CustomTextStyle({ size: 14, weight: 400, color: '#FF000000' }))
 
         Row({space: 8}){
-          Text('占三峰').attributeModifier(new CustomTextStyle({ size: 14, weight: 500, color: '#FF000000' }))
-          Text('13598728343').attributeModifier(new CustomTextStyle({ size: 14, weight: 500, color: '#FF000000' }))
+          Text(this.address.userName).attributeModifier(new CustomTextStyle({ size: 14, weight: 500, color: '#FF000000' }))
+          Text(this.address.phone).attributeModifier(new CustomTextStyle({ size: 14, weight: 500, color: '#FF000000' }))
         }
       }
       .layoutWeight(1)

+ 21 - 0
features/feature/src/main/ets/model/Address.ets

@@ -0,0 +1,21 @@
+export interface Address {
+  /**
+   * 手机
+   */
+  phone?: string;
+
+  /**
+   * 详细地址
+   */
+  address?: string;
+
+  /**
+   * 详细地区(格式如:XXX-XXX-XXX)
+   */
+  region?: string;
+
+  /**
+   * 收件人名称
+   */
+  userName?: string;
+}

+ 61 - 0
features/feature/src/main/ets/model/OrderModelIndex.ets

@@ -0,0 +1,61 @@
+export interface OrderValidationData {
+  /**
+   * 详细地址
+   */
+  address?: string;
+
+  /**
+   * 书本id集合
+   */
+  bookIds?: Array<string>;
+
+  /**
+   * 书本价格
+   */
+  bookPrice?: number;
+
+  /**
+   * 邮寄方式: 1.顺丰 2.京东
+   */
+  deliveryMethod?: number;
+
+  /**
+   * 押金(由于没有交押金不会到下单页面,所以前端默认传递 0)
+   */
+  deposit?: number;
+
+  /**
+   * 订单总价格
+   */
+  orderPrice?: number;
+
+  /**
+   * 支付方式;微信0/支付宝1/抖音2
+   */
+  payWay?: number;
+
+  /**
+   * 手机
+   */
+  phone?: string;
+
+  /**
+   * 往返邮费
+   */
+  postFee?: number;
+
+  /**
+   * 详细地区(格式如:XXX-XXX-XXX)
+   */
+  region?: string;
+
+  /**
+   * 用户订单备注
+   */
+  remark?: string;
+
+  /**
+   * 收件人名称
+   */
+  userName?: string;
+}

+ 4 - 0
features/feature/src/main/ets/model/Storage.ets

@@ -88,3 +88,7 @@ export class CartStorage{
     }
   }
 }
+
+// 用户地址
+@ObservedV2
+export class UserAddressStorage{}

+ 136 - 16
features/feature/src/main/ets/pages/Order/OrderDetailPage.ets

@@ -1,16 +1,44 @@
-import { DiaLogSheetControl, RouterPage, YTAvoid, YTHeader, yTRouter } from 'basic'
+import { BasicType, BookItem, DiaLogSheetControl, IBestToast, YTAvoid, YTHeader, yTRouter } from 'basic'
+import { OrderApi } from '../../apis/OrderApi'
 import { AddressComp } from '../../components/AddressComp'
 import { AddressItemComp } from '../../components/AddressItemComp'
 import { buttonComp } from '../../components/BuilderIndex'
+import { Address } from '../../model/Address'
+import { OrderValidationData } from '../../model/OrderModelIndex'
 import { CustomTextStyle } from '../../style/CustomTextStyle'
 
 @ComponentV2
-@RouterPage
 struct OrderDetailPage {
-  safeBottom: number = AppStorage.get(YTAvoid.SAFE_BOTTOM_KEY) as number
+  @Local safeBottom: number = AppStorage.get(YTAvoid.SAFE_BOTTOM_KEY) as number
+  // 租借的图书 URL
+  @Param bookList: BookItem[] = []
+
+  @Local forEach: Array<BasicType> = []
+  // 总价
+  // todo 默认为邮费
+  @Local totalPrice: number = 9.99
+  // 地址信息
+  @Local address: Address = {}
+
+  // 用户订单备注
+  remark: string = ''
+
+  // 提交订单校验
+  orderValidation: OrderValidationData = {
+    bookIds: [],
+    deliveryMethod: 2,
+    deposit: 0,
+    payWay: 0,
+    postFee: 9.99,
+    userName: '占三峰',
+    phone: '13598728343',
+    address: '高新区火炬园路321号韩菲诗.诚享大厦304室内',
+    region: '福建-厦门-火炬园',
+  }
 
   // 打开选择地址弹窗
   openAddressDialog() {
+    // todo 有 地址数据 打开弹窗, 没有进入地址管理页面添加页面添加地址
     let control: DiaLogSheetControl = new DiaLogSheetControl(this.getUIContext())
     yTRouter.router2BottomDialog({
       control: control,
@@ -18,6 +46,48 @@ struct OrderDetailPage {
     })
   }
 
+  // 提交订单
+  submitOrder() {
+    if(!this.orderValidation?.phone) {
+      IBestToast.show('请填写收件人信息')
+      return
+    }
+    // yTRouter.router2BorrowAnsPage()
+
+    this.orderValidation.orderPrice = this.totalPrice
+    this.orderValidation.remark = this.remark
+    OrderApi.checkOrder(this.orderValidation)
+  }
+
+
+  aboutToAppear(): void {
+    // 书本价格计算
+    let total: number = 0.00
+    this.bookList.forEach((item: BookItem, index) => {
+      if(item.rentPerDay) {
+        total += Number.parseFloat(item.rentPerDay)
+      }
+      this.orderValidation.bookIds?.push(item.id!)
+    })
+
+    // 生成明细
+    this.forEach = [
+      { text: '租借期限', message: '30天' },
+      { text: '租借时间', message: '快递签收日起30天' },
+      { text: '租借价格', message: `¥${total.toFixed(2)}` },
+      { text: '往返运费', message: `¥9.99` },
+      { text: '租借期限', message: '30天' },
+    ]
+
+    // todo 在有地址列表 或 默认地址的情况下添加地址信息
+
+
+
+    // todo 订单校验数据结构整合
+    this.totalPrice += total
+    this.orderValidation.bookPrice = total
+  }
+
   build() {
     NavDestination() {
       Column() {
@@ -29,7 +99,19 @@ struct OrderDetailPage {
 
             // 地址栏
             ListItem(){
-              AddressItemComp({type: 0})
+              // todo 订单地址校验
+              if(this.address?.phone) {
+                AddressItemComp({type: 0})
+              } else {
+                Row(){
+                  Text('+ 添加收件人信息')
+                    .attributeModifier(new CustomTextStyle({ size: 16, weight: 500 }))
+                }.width('100%')
+                .borderRadius(8)
+                .border({width: 2})
+                .padding({top: 30, bottom: 30})
+                .justifyContent(FlexAlign.Center)
+              }
             }
             .backgroundColor(Color.White)
             .onClick(() => { this.openAddressDialog() })
@@ -41,18 +123,19 @@ struct OrderDetailPage {
                   Text('租借图书')
                     .attributeModifier(new CustomTextStyle({ size: 16, weight: 500, color: '#FF000000' }))
 
-                  Text('共10件')
+                  Text(`共${this.bookList.length}件`)
                     .attributeModifier(new CustomTextStyle({ size: 12, weight: 500, color: '#80000000' }))
                 }
 
                 List({space: 15}){
-                  ForEach(new Array(8).fill(''), (item: string, index) => {
+                  ForEach(this.bookList, (item: BookItem, index) => {
                     ListItem(){
-                      Image($r('[basic].media.png_defaultBook'))
+                      Image(item.coverUrl)
                         .width(63)
                         .height(81)
                         .borderRadius(6)
                         .backgroundColor('#FFFECF2F')
+                        .alt($r('[basic].media.png_defaultBook'))
                     }
                   })
                 }.width("100%").height(81)
@@ -70,23 +153,24 @@ struct OrderDetailPage {
             // 订单信息
             ListItem(){
               Column({space: 16}){
-                ForEach(new Array(5).fill(''), (item: string, index) => {
+                ForEach(this.forEach, (item: BasicType, index) => {
                   Row(){
-                    Text('租借期限')
+                    Text(item.text)
                       .attributeModifier(new CustomTextStyle({ size: 14, weight: 500, color: '#FF666666' }))
 
-                    Text('30天')
+                    Text(item.message)
                       .attributeModifier(new CustomTextStyle({ size: 14, weight: 400, color: '#FF333333' }))
                   }.width('100%').justifyContent(FlexAlign.SpaceBetween)
                 })
 
+
                 Divider().height(1).width('100%').backgroundColor('#FF666666')
 
                 Row(){
                   Text('小计')
                     .attributeModifier(new CustomTextStyle({ size: 14, weight: 500, color: '#FF666666' }))
 
-                  Text('¥219.80')
+                  Text(`¥${this.totalPrice.toFixed(2)}`)
                     .attributeModifier(new CustomTextStyle({ size: 14, weight: 400, color: '#FF333333' }))
                 }.width('100%').justifyContent(FlexAlign.SpaceBetween)
               }
@@ -96,13 +180,47 @@ struct OrderDetailPage {
             .border({width: 2})
             .backgroundColor(Color.White)
 
+            // 支付方式
+            ListItem(){
+              Column({space: 16}){
+                Text('支付方式')
+                  .attributeModifier(new CustomTextStyle({ size: 16, weight: 500, color: '#000000' }))
+
+                Divider().height(1).width('100%').backgroundColor('#FF666666')
+
+                Row(){
+                  Row({space: 5}){
+                    Image($r('[basic].media.icon_wx'))
+                      .width(20)
+                      .aspectRatio(1)
+
+                    Text('微信支付')
+                      .attributeModifier(new CustomTextStyle({ size: 14, weight: 500, color: '#666666' }))
+                  }
+
+                  Image($r('[basic].media.icon_selectSvg'))
+                    .width(14)
+                    .aspectRatio(1)
+                    .fillColor('#20BB06')
+                }
+                .width('100%')
+                .justifyContent(FlexAlign.SpaceBetween)
+              }
+              .justifyContent(FlexAlign.Start)
+              .alignItems(HorizontalAlign.Start)
+              .padding({left: 16, right: 16, top: 9, bottom: 9})
+            }
+            .borderRadius(8)
+            .border({width: 2})
+            .backgroundColor(Color.White)
+
             // 备注
             ListItem(){
               Row({space: 20}){
                 Text('备注')
                   .attributeModifier(new CustomTextStyle({ size: 14, weight: 500, color: '#FF666666' }))
 
-                TextInput({placeholder: '请输入您的留言'})
+                TextInput({placeholder: '请输入您的留言', text: $$this.remark})
                   .padding(0)
                   .borderRadius(0)
                   .layoutWeight(1)
@@ -115,6 +233,8 @@ struct OrderDetailPage {
             .borderRadius(8)
             .border({width: 2})
             .backgroundColor(Color.White)
+
+            ListItem()
           }.width('100%').height('100%')
           .scrollBar(BarState.Off)
           .padding({left: 15, right: 15})
@@ -123,12 +243,12 @@ struct OrderDetailPage {
         Row(){
           Text(){
             Span('应付:')
-            Span(`¥218.8`).fontColor('#FFFF0000').fontSize(20)
+            Span(`¥${this.totalPrice.toFixed(2)}`).fontColor('#FFFF0000').fontSize(20)
           }
           .attributeModifier(new CustomTextStyle({ size: 14, weight: 400, color: '#FF000000' }))
 
           buttonComp('提交订单', 143, 10, new CustomTextStyle({size: 18}), () => {
-            yTRouter.router2BorrowAnsPage()
+            this.submitOrder()
           })
         }
         .width('100%')
@@ -153,6 +273,6 @@ struct OrderDetailPage {
 }
 
 @Builder
-function OrderDetailBuilder() {
-  OrderDetailPage()
+function OrderDetailBuilder(_: string, param: Array<BookItem>) {
+  OrderDetailPage({bookList: param})
 }

+ 3 - 3
features/feature/src/main/ets/view/ThirdView.ets

@@ -36,10 +36,10 @@ export struct ThirdView {
       // 底部按钮
       Row(){
         Row(){
-          if(this.vm.selectList.length != 10 || (this.vm.bookList.length != 0 && this.vm.selectList.length == this.vm.bookList.length)) {
-            Row().width(15).aspectRatio(1).borderRadius(15).border({width: 1})
-          } else {
+          if(this.vm.selectList.length == 10 || (this.vm.bookList.length != 0 && this.vm.selectList.length == this.vm.bookList.length)) {
             Image($r('[basic].media.icon_select')).width(15).aspectRatio(1)
+          } else {
+            Row().width(15).aspectRatio(1).borderRadius(15).border({width: 1})
           }
 
           Text('全选')

+ 14 - 4
features/feature/src/main/ets/view/viewModel/ThirdViewModel.ets

@@ -1,4 +1,4 @@
-import { BookItem, YTAvoid, yTRouter } from "basic";
+import { BookItem, IBestToast, YTAvoid, yTRouter } from "basic";
 import { OrderApi } from "../../apis/OrderApi";
 import { PageResponse } from "../../model/PageResponse";
 import { bookPackageQuery } from "../../model/Query";
@@ -21,7 +21,6 @@ export class ThirdViewModel{
 
   query: bookPackageQuery = new bookPackageQuery()
 
-
   // 分类
   categoryList = ['全部', '可借', '已借光'] // , '已预订'
 
@@ -60,7 +59,18 @@ export class ThirdViewModel{
     if(this.editMode) {
       this.removeBook()
     } else {
-      yTRouter.router2OrderDetailPage()
+      if(this.selectList.length == 0) {
+        IBestToast.show('请选择需要借阅的书本')
+        return
+      }
+
+      let param: BookItem[] = []
+      this.bookList.forEach((item) => {
+        if(this.selectList.indexOf(item.id!) != -1) {
+          param.push(item)
+        }
+      })
+      yTRouter.router2OrderDetailPage(param)
     }
   }
 
@@ -69,7 +79,7 @@ export class ThirdViewModel{
     if(this.bookList.length == 0) return
 
     let count = this.selectList.length
-    if(count == 10) {
+    if(count == 10 || count == this.bookList.length) {
       this.selectList = []
     } else {
       this.bookList.forEach((item) => {