فهرست منبع

feat: 新增我的借阅页面相关请求接口

YuJing 1 ماه پیش
والد
کامیت
9ab7e1b417

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

@@ -72,4 +72,7 @@ export class ApiUrl {
    * @method POST
    */
   static getUnifiedPayInfo = '/api/book/order/pay';
+
+  // 获取订单分页
+  static getOrderPage = '/api/book/order/page';
 }

+ 13 - 2
features/feature/src/main/ets/apis/OrderApi.ets

@@ -1,7 +1,9 @@
 import { BookItem, YTRequest } from "basic";
-import { DepositData, GetUnifiedPayInfoRequestData, OrderValidationData } from "../model/OrderModelIndex";
+import { DepositData, GetUnifiedPayInfoRequestData,
+  OrderDetailData,
+  OrderValidationData } from "../model/OrderModelIndex";
 import { PageResponse } from "../model/PageResponse";
-import { bookPackageQuery } from "../model/Query";
+import { bookPackageQuery, userOrderQuery } from "../model/Query";
 import { ApiUrl } from "./ApiUrl";
 
 export class OrderApi {
@@ -55,4 +57,13 @@ export class OrderApi {
   static getPayInfo(orderInfo: GetUnifiedPayInfoRequestData): Promise<string> {
     return YTRequest.post<string>(ApiUrl.getUnifiedPayInfo, orderInfo)
   }
+
+  /**
+   * 获取用户订单列表
+   * @param param
+   * @returns
+   */
+  static getUserOrderList(param: userOrderQuery): Promise<PageResponse<OrderDetailData>> {
+    return YTRequest.post<PageResponse<OrderDetailData>, userOrderQuery>(ApiUrl.getOrderPage, param)
+  }
 }

+ 19 - 5
features/feature/src/main/ets/components/ytComp/ytEmptyComp.ets

@@ -5,21 +5,35 @@ export struct ytEmptyComp {
   @BuilderParam container: () => void
 
   @Param @Require dataSource: Array<ESObject>
-  @Param keyStr: string = '书籍'
+  @Param keyStr: string = '暂无数据'
+  // 按钮关键字, 为空不显示按钮
+  @Param buttonKey: string = ''
+  // 按钮的点击事件,未传按钮关键字则不响应
+  @Event clickButton: () => void
+  // 图标, 不传显示默认的
+  @Param icon: PixelMap | ResourceStr | DrawableDescriptor = $r('[basic].media.png_empty_0')
 
   build() {
     Column() {
       if(this.dataSource.length == 0) {
-        Image($r('[basic].media.png_empty_0'))
+        Image(this.icon)
           .width(139)
           .height(148)
-          .margin({top: 100})
+          .margin({top: 100, right: 15})
 
-        Text(`未搜索到相关书籍${this.keyStr},${'\n'}` +
-          '换个关键词试试吧!')
+        Text(this.keyStr)
           .margin({top: 10})
           .textAlign(TextAlign.Center)
           .attributeModifier(new CustomTextStyle({size: 14, weight: 400, color: '#80000000'}))
+
+        if(this.buttonKey) {
+          Text(this.buttonKey)
+            .border({width: 2}).borderRadius(24.5)
+            .backgroundColor('#FECF2F').margin({top: 8})
+            .attributeModifier(new CustomTextStyle({size: 18}))
+            .padding({left: 45, top: 10, right: 45, bottom: 10})
+            .onClick(() => { this.clickButton() })
+        }
       } else {
         if(this.container){
           this.container()

+ 16 - 30
features/feature/src/main/ets/model/EnumState.ets

@@ -2,40 +2,26 @@
  * 订单状态枚举
  */
 export enum OrderStatus {
-  /** 未确认订单 */
-  UNCONFIRMED,
-  /**
-   * @description 待支付
-   */
+  /** @description 待支付 */
   PENDING_PAYMENT,
-  /**
-   * @description 借阅中
-   */
-  BORROWING,
-  /**
-   * @description 待出库
-   */
+  /** @description 待出库 */
   PENDING_OUTBOUND,
-  /**
-   * @description 待取书
-   */
+  /** @description 待收书 */
+  PENDING_RECEIPT,
+  /** @description 借阅中 */
+  BORROWING,
+  /** 已超期 */
+  OVERDUE,
+  /** @description 待取书 */
   PENDING_PICKUP,
-  /**
-   * @description 已关闭
-   */
-  CLOSED,
-  /**
-   * @description 借阅完成
-   */
-  BORROWING_COMPLETED,
-  /**
-   * @description 待验收
-   */
+  /** @description 待验收 */
   PENDING_ACCEPTANCE,
-  /**
-   * @description 待收书
-   */
-  PENDING_RECEIPT,
+  /** @description 借阅完成/已完成 */
+  BORROWING_COMPLETED,
+  /** @description 已关闭 */
+  CLOSED,
+  /** 未确认订单 */
+  UNCONFIRMED,
 }
 
 

+ 142 - 4
features/feature/src/main/ets/model/OrderModelIndex.ets

@@ -1,4 +1,8 @@
-/** 订单 校验 数据 */
+import { BookItem } from "basic";
+
+/**
+ * 订单 校验 数据
+ * */
 export interface OrderValidationData {
   /**
    * 详细地址
@@ -66,16 +70,150 @@ export interface OrderValidationData {
 }
 
 
-/** 押金数据结构 */
+/**
+ * 押金数据结构
+ * */
 export interface DepositData {
   deposit: string;
 }
 
 
-/** 获取统一支付信息 请求数据类型 */
+/**
+ * 获取统一支付信息 请求数据类型
+ * */
 export interface GetUnifiedPayInfoRequestData {
   /** 订单id */
   orderId?: string,
   /** 支付方式 */
   payWay?: string,
-}
+}
+
+/**
+ * 订单列表详情数据结构
+ */
+export interface OrderDetailData {
+  /**
+   * 订单ID
+   */
+  id?: string;
+
+  /**
+   * 用户ID
+   */
+  userId?: string;
+
+  /**
+   * 收件人名称
+   */
+  userName?: string;
+
+  /**
+   * 手机
+   */
+  phone?: string;
+
+  /**
+   * 订单状态码
+   */
+  statusCode?: string;
+
+  /**
+   * 订单类型
+   */
+  orderType?: string;
+
+  /**
+   * 详细地区(格式如:XXX-XXX-XXX)
+   */
+  region?: string;
+
+  /**
+   * 详细地址
+   */
+  address?: string;
+
+  /**
+   * 书本id集合
+   */
+  bookIds?: Array<string> | null;
+
+  /**
+   * 归还日期
+   */
+  returnDate?: string | null;
+
+  /**
+   * 订单总价格
+   */
+  orderPrice?: string;
+
+  /**
+   * 往返邮费
+   */
+  postFee?: string;
+
+  /**
+   * 押金
+   */
+  deposit?: string;
+
+  /**
+   * 数量
+   */
+  amount?: string;
+
+  /**
+   * 支付方式;微信0/支付宝1/抖音2
+   */
+  payWay?: string;
+
+  /**
+   * 用户订单备注
+   */
+  remark?: string | null;
+
+  /**
+   * 支付成功时间
+   */
+  successTime?: string | null;
+
+  /**
+   * 邮寄信息
+   */
+  postInfo?: string | null;
+
+  /**
+   * 退款金额
+   */
+  refund?: string;
+
+  /**
+   * 创建人
+   */
+  createBy?: string;
+
+  /**
+   * 创建时间
+   */
+  createTime?: string;
+
+  /**
+   * 更新人
+   */
+  updateBy?: string;
+
+  /**
+   * 更新时间
+   */
+  updateTime?: string;
+
+  /**
+   * 书籍列表
+   */
+  bookList?: Array<BookItem>;
+
+  /**
+   * 书本价格
+   */
+  bookPrice?: string;
+}

+ 2 - 1
features/feature/src/main/ets/model/PageResponse.ets

@@ -6,8 +6,9 @@ import { BookListItem } from "./BookModelIndex";
 export class PageResponse<T> {
   /** 总记录数 */
   total?: string;
-  /** 数据列表 */
+  /** 数据列表  看后端返回的结果选择 */
   list?: Array<T>;
+  records?: Array<T>
   /** 当前页码 */
   pageNum?: string;
   /** 每页显示数量 */

+ 13 - 3
features/feature/src/main/ets/model/Query.ets

@@ -9,12 +9,16 @@ abstract class Query{
 
   reload() {
     this.pageNum = 1
-    this.pageSize = 15
+    this.pageSize = 16
     this.total = 1
   }
 
-  reachEnd() {
-    this.pageNum++
+  reachEnd(sourceLength: number): boolean {
+    if(sourceLength < this.pageSize) {
+      this.pageNum++
+      return true
+    }
+    return false
   }
 }
 
@@ -63,4 +67,10 @@ export class searchBookQuery extends Query {
 export class bookPackageQuery extends Query{
   //  0代表全部 1代表可借 2代表已借光
   flag: number = 0;
+}
+
+// 用户订单数据
+export class userOrderQuery extends Query{
+  /** 订单状态 订单状态;待支付0/待出库1/待收书2/借阅中3/已超期4/待取书5/待验收6/已完成7/已关闭8 */
+  statusCode?: number;
 }

+ 2 - 2
features/feature/src/main/ets/pages/BookList/BookSearchResultPage.ets

@@ -71,7 +71,7 @@ struct BookSearchResultPage {
   // 书籍列表
   @Builder
   BookItemList() {
-    ytEmptyComp({ dataSource: this.vm.book, keyStr: '书籍' }){
+    ytEmptyComp({ dataSource: this.vm.book, keyStr: `未搜索到相关书籍,${'\n'}换个关键词试试吧!`}){
       List({space: 16}){
         ListItem()
 
@@ -93,7 +93,7 @@ struct BookSearchResultPage {
   // 书单列表
   @Builder
   BookList() {
-    ytEmptyComp({ dataSource: this.vm.bookList, keyStr: '书单' }){
+    ytEmptyComp({ dataSource: this.vm.bookList, keyStr: `未搜索到相关书籍,${'\n'}换个关键词试试吧!` }){
       List({space: 16}){
         ListItem()
 

+ 68 - 21
features/feature/src/main/ets/pages/Order/OrderManagementPage.ets

@@ -1,6 +1,8 @@
-import { RouterPage, YTHeader, yTRouter } from 'basic';
+import { BookItem, RouterPage, YTHeader, yTRouter } from 'basic';
 import { buttonComp } from '../../components/BuilderIndex';
+import { ytEmptyComp } from '../../components/ytComp/ytEmptyComp';
 import { OrderStatus } from '../../model/EnumState';
+import { OrderDetailData } from '../../model/OrderModelIndex';
 import { CustomTextStyle } from '../../style/CustomTextStyle';
 import { OrderManagementViewModel } from '../viewModel/OrderManagementViewModel';
 
@@ -10,7 +12,16 @@ import { OrderManagementViewModel } from '../viewModel/OrderManagementViewModel'
 @ComponentV2
 @RouterPage
 struct OrderManagementPage {
-  @Param @Require vm: OrderManagementViewModel;
+  @Param @Require targetIndex: number;
+
+  vm: OrderManagementViewModel = new OrderManagementViewModel();
+  aboutToAppear(): void {
+    if(this.targetIndex != undefined) {
+      this.vm.changeCategory(this.targetIndex)
+    } else {
+      this.vm.changeCategory(0)
+    }
+  }
 
   build() {
     NavDestination() {
@@ -20,6 +31,9 @@ struct OrderManagementPage {
           bgc: Color.White,
         })
 
+        /**
+         * 分类列表
+         * */
         List({space: 22}){
           ForEach(this.vm.categoryList, (item: string, index) => {
             ListItem(){
@@ -28,7 +42,9 @@ struct OrderManagementPage {
                   .zIndex(99)
                   .width(50)
                   .textAlign(TextAlign.Center)
-                  .onClick(() => { this.vm.changeCategory(index) })
+                  .onClick(() => {
+                    this.vm.tabControl.changeIndex(index)
+                  })
                   .fontSize(16)
                   .fontWeight(600)
                   .fontColor(this.vm.categoryIndex == index ? '#FF111111' : '#FF777777')
@@ -53,12 +69,18 @@ struct OrderManagementPage {
         .borderRadius({bottomLeft: 16, bottomRight: 16})
         .padding({top: 10, left: 16, right: 16, bottom: 10})
 
+        /**
+         * 数据源
+         * */
         Column(){
-          Tabs({controller: this.vm.tabControl, index: this.vm.categoryIndex}){
+          Tabs({controller: this.vm.tabControl}){
             ForEach(this.vm.categoryList, (item: string, index) => {
               TabContent(){
                 Refresh({refreshing: this.vm.isRefresh}){
                   if((this.vm.isRefresh && this.vm.isFirst) || this.vm.categoryIndex != index) {
+                    /**
+                     * 骨架列表
+                     */
                     Column({space: 16}){
                       ForEach(['', '', ''], (item: string, index) => {
                         ListItem(){
@@ -69,20 +91,31 @@ struct OrderManagementPage {
                     .justifyContent(FlexAlign.Start)
                     .padding({left: 15, right: 15, top: 14})
                   } else {
-                    List({space: 16}){
-                      ListItem()
+                    /**
+                     * 订单组件列表
+                     */
+                    ytEmptyComp({
+                      dataSource: this.vm.dataSource,
+                      keyStr: '暂无借阅信息~',
+                      buttonKey: "去借阅",
+                      clickButton: () => { yTRouter.changeIndex(1) }
+                    }){
+                      List({space: 16}){
+                        ListItem()
 
-                      ForEach(this.vm.dataSource, (item: string, index) => {
-                        ListItem(){
-                          OrderItemComp({orderStatus: index+1})
-                        }
-                      })
+                        ForEach(this.vm.dataSource, (item: OrderDetailData, index) => {
+                          ListItem(){
+                            OrderItemComp({orderData: item})
+                          }
+                        })
+                      }
+                      .width("100%")
+                      .height('100%')
+                      .scrollBar(BarState.Off)
+                      .edgeEffect(EdgeEffect.None)
+                      .padding({left: 15, right: 15, bottom: this.vm.safeBottom})
+                      .onReachEnd(() => { this.vm.onReachEnd() })
                     }
-                    .width("100%")
-                    .height('100%')
-                    .scrollBar(BarState.Off)
-                    .padding({left: 15, right: 15, bottom: this.vm.safeBottom})
-                    .onReachEnd(() => { this.vm.onReachEnd() })
                   }
                 }
                 .padding(0)
@@ -96,6 +129,13 @@ struct OrderManagementPage {
           .onChange((index: number) => {
             this.vm.changeCategory(index)
           })
+          .onAnimationStart((index: number, target: number) => {
+            if(index == target) return
+            this.vm.changeCategory(target)
+          })
+          .onAppear(() => {
+            this.vm.tabControl.changeIndex(this.vm.categoryIndex)
+          })
         }
         .width('100%')
         .layoutWeight(1)
@@ -110,14 +150,20 @@ struct OrderManagementPage {
 
 @Builder
 function OrderManagementBuilder(_: string, targetIndex?: number) {
-  OrderManagementPage({vm: new OrderManagementViewModel(targetIndex)})
+  OrderManagementPage({ targetIndex })
 }
 
 
-
+// 订单结构
 @ComponentV2
 struct OrderItemComp{
-  @Param orderStatus: OrderStatus = OrderStatus.PENDING_PAYMENT;
+  @Param @Require orderData: OrderDetailData
+  @Local orderStatus: OrderStatus = OrderStatus.PENDING_PAYMENT;
+
+  aboutToAppear(): void {
+    this.orderStatus = Number.parseInt(this.orderData.statusCode!)
+  }
+
 
   getOrderStatusDes(status: OrderStatus): string {
     switch (status) {
@@ -186,13 +232,14 @@ struct OrderItemComp{
         .margin({top: 14, bottom: 16})
 
       List({space: 15}){
-        ForEach(new Array(8).fill(''), (item: string, index) => {
+        ForEach(this.orderData.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)

+ 4 - 5
features/feature/src/main/ets/pages/PrivacyPolicyPage.ets

@@ -3,6 +3,7 @@ import { webview } from '@kit.ArkWeb'
 import { bundleManager, common } from '@kit.AbilityKit'
 import { BusinessError } from '@kit.BasicServicesKit'
 import { WebViewJavascriptBridge, WVJBResponseCallback } from '@yue/webview_javascript_bridge'
+import util from '@kit.ArkTS';
 
 
 @Component
@@ -144,9 +145,11 @@ struct PrivacyPolicyPage {
           } else {
             Scroll() {
               Web({
-                src: '',
+                src: this.fromText,
                 controller: this.controller
               })
+                .width('100%')
+                .height('100%')
                 .geolocationAccess(false)
                 .domStorageAccess(true)
                 .mixedMode(MixedMode.Compatible)
@@ -154,10 +157,6 @@ struct PrivacyPolicyPage {
                 .multiWindowAccess(true)
                 .onControllerAttached(() => {
                   this.setupWebViewJavascriptBridge();
-                  const url = `<!DOCTYPE html> <html></body> ${this.fromText} </body></html>`
-                  console.log('url',url)
-                  this.controller.loadData(this.fromText, '', '');
-
                 })
                 .onProgressChange((date) => {
                   if (date) {

+ 2 - 1
features/feature/src/main/ets/pages/viewModel/BookListViewModel.ets

@@ -58,13 +58,14 @@ export class BookListViewModel{
   }
 
   // 获取书单列表
+  // todo 列表加载待完善
   async getBookList(isReload: boolean = true) {
     if(isReload) {
       this.query.reload()
     } else {
       // if()
 
-      this.query.reachEnd()
+      // this.query.reachEnd()
     }
 
     try {

+ 2 - 1
features/feature/src/main/ets/pages/viewModel/BookSearchResultViewModel.ets

@@ -36,11 +36,12 @@ export class BookSearchResultViewModel{
 
 
   // 获取书单列表
+  // todo 列表加载待完善
   async getBookList(isReload: boolean = true) {
     if(isReload) {
       this.bookListQuery.reload()
     } else {
-      this.bookListQuery.reachEnd()
+      // this.bookListQuery.reachEnd()
     }
 
     try {

+ 8 - 5
features/feature/src/main/ets/pages/viewModel/OrderDetailViewModel.ets

@@ -90,15 +90,18 @@ export class OrderDetailViewModel{
       IBestToast.show('请填写收件人信息')
       return
     }
+    /**
+     * 前往借阅成功页面
+     */
     // yTRouter.router2BorrowAnsPage()
 
-    // this.orderValidation.orderPrice = Number.parseFloat(this.totalPrice.toFixed(2))
-    // this.orderValidation.remark = this.remark
-    // let ans: OrderValidationData = await OrderApi.checkOrder(this.orderValidation)
-    // console.log(`借阅结果数据结构 ans = ${JSON.stringify(ans)}`)
+    this.orderValidation.orderPrice = Number.parseFloat(this.totalPrice.toFixed(2))
+    this.orderValidation.remark = this.remark
+    let ans: OrderValidationData = await OrderApi.checkOrder(this.orderValidation)
+    console.log(`借阅结果数据结构 ans = ${JSON.stringify(ans)}`)
 
     let payInfo: GetUnifiedPayInfoRequestData = {
-      orderId: '16',//ans.id,
+      orderId: ans.id,
       payWay: '2',
     }
 

+ 45 - 24
features/feature/src/main/ets/pages/viewModel/OrderManagementViewModel.ets

@@ -1,54 +1,75 @@
 import { YTAvoid } from "basic"
+import { OrderApi } from "../../apis/OrderApi"
+import { OrderDetailData } from "../../model/OrderModelIndex"
+import { userOrderQuery } from "../../model/Query"
 
 @ObservedV2
 export class OrderManagementViewModel{
   @Trace safeTop: number = AppStorage.get(YTAvoid.SAFE_TOP_KEY) as number
   @Trace safeBottom: number = AppStorage.get(YTAvoid.SAFE_BOTTOM_KEY) as number
 
-  @Trace categoryIndex: number = 0
+  @Trace categoryIndex: number = -1
   @Trace isRefresh: boolean = false
-  @Trace dataSource: string[] = new Array(8).fill('')
+  // 订单列表
+  @Trace dataSource: OrderDetailData[] = []
   @Trace isFirst: boolean = false
 
+  // 0 2 3 7
   categoryList: string[] = ['全部', '待支付', '待收书', '待还书', '已完成']
   tabControl: TabsController = new TabsController()
+  query: userOrderQuery = new userOrderQuery()
+  // 订单状态对照
+  orderStatus: number[] = [0, 2, 3, 7]
+
+
+  tag = "OrderPage"
 
   private debounceTimer: number | null = null
-  private readonly DEBOUNCE_DELAY: number = 500
+  private readonly DEBOUNCE_DELAY: number = 0
 
   constructor(index?: number) {
-    if(index != undefined) {
-      this.changeCategory(index)
-    } else {
-      this.changeCategory(0)
-    }
+    // todo 列表初次请求有问题 - 会被第一个if 拦截掉
+    // if(index != undefined) {
+    //   this.changeCategory(index)
+    // } else {
+    //   this.changeCategory(0)
+    // }
   }
 
-  changeCategory(index: number) {
-    // 清除之前的定时器
-    if (this.debounceTimer !== null) {
-      clearTimeout(this.debounceTimer)
+  // 修改分类
+  changeCategory(index: number, isAppear: boolean = false) {
+    if(this.categoryIndex == index) return
+
+    this.categoryIndex = index
+    this.isRefresh = true
+    this.isFirst = true
+
+    if(index == 0) {
+      this.query.statusCode = undefined
+    } else {
+      this.query.statusCode = this.orderStatus[index-1]
     }
 
-    // 设置新的防抖定时器
-    this.debounceTimer = setTimeout(() => {
-      this.categoryIndex = index
-      this.isRefresh = true
-      this.isFirst = true
-      this.onRefreshing()
-      this.debounceTimer = null
-    }, this.DEBOUNCE_DELAY)
+    this.onRefreshing()
   }
 
   onRefreshing(){
-    // this.isRefresh = true
-    setTimeout(() => {
+    console.log(`刷新了 = ${JSON.stringify('刷新了')}`)
+    this.query.reload()
+    this.getOrderList().finally(()=>{
       this.isRefresh = false
-      this.isFirst = false
-    }, 500)
+      this.isFirst =false
+    })
   }
 
   onReachEnd(){
+    console.log(`触底了 = ${JSON.stringify('触底了')}`)
+  }
 
+  // 获取订单列表
+  async getOrderList(){
+    let ans = await OrderApi.getUserOrderList(this.query)
+    console.log(`订单信息 ans = ${JSON.stringify(ans)}`)
+    this.dataSource = ans.records ?? []
   }
 }