订单,工单能获取到数据了

Signed-off-by: 无闻风 <wuwenfengmi@gmail.com>
This commit is contained in:
2026-06-25 11:32:18 +08:00
parent 28a5d0f6fb
commit 8b4f8096ea
19 changed files with 246 additions and 143 deletions
@@ -1,11 +1,18 @@
package com.example.ops_android.data.model package com.example.ops_android.data.model
import com.google.gson.annotations.SerializedName
data class Container( data class Container(
val id: Int = 0, @SerializedName("ID") val id: Int = 0,
val name: String? = null, @SerializedName("Title") val name: String? = null,
val parent_id: Int = 0, @SerializedName("ParentID") val parent_id: Int = 0,
val barcode: String? = null, @SerializedName("Remark") val remark: String? = null,
val remark: String? = null, @SerializedName("CreatedAt") val created_at: String? = null,
val created_at: String? = null, @SerializedName("CreatorID") val user_id: Int? = null,
val user_id: Int? = null @SerializedName("ItemCount") val item_count: Int = 0,
) @SerializedName("ChildCount") val child_count: Int = 0,
@SerializedName("Color") val color: String? = null,
@SerializedName("barcode") private val _barcode: String? = null
) {
val barcode: String? get() = _barcode
}
@@ -1,12 +1,20 @@
package com.example.ops_android.data.model package com.example.ops_android.data.model
import com.google.gson.annotations.SerializedName
data class Customer( data class Customer(
val id: Int = 0, @SerializedName("id") val id: Int = 0,
val name: String? = null, @SerializedName("first_name") val first_name: String? = null,
val phone: String? = null, @SerializedName("last_name") val last_name: String? = null,
val email: String? = null, @SerializedName("primary_phone") val phone: String? = null,
val address: String? = null, @SerializedName("primary_email") val email: String? = null,
val remark: String? = null, @SerializedName("created_at") val created_at: String? = null,
val created_at: String? = null, @SerializedName("created_by") val user_id: Int? = null,
val user_id: Int? = null @SerializedName("address") private val _address: String? = null,
) @SerializedName("remark") private val _remark: String? = null
) {
// backward-compat with UI code
val name: String? get() = listOfNotNull(first_name, last_name).joinToString(" ").ifEmpty { null }
val address: String? get() = _address
val remark: String? get() = _remark
}
@@ -1,22 +1,28 @@
package com.example.ops_android.data.model package com.example.ops_android.data.model
import com.google.gson.annotations.SerializedName
data class Item( data class Item(
val id: Int = 0, @SerializedName("ID") val id: Int = 0,
val name: String? = null, @SerializedName("Name") val name: String? = null,
val serial_number: String? = null, @SerializedName("SerialNumber") val serial_number: String? = null,
val spec: String? = null, @SerializedName("Remark") val remark: String? = null,
val container_id: Int = 0, @SerializedName("Quantity") val quantity: Int = 1,
val barcode: String? = null, @SerializedName("ContainerID") val container_id: Int = 0,
val remark: String? = null, @SerializedName("CreatedAt") val created_at: String? = null,
val photos: List<String>? = null, @SerializedName("CreatorID") val user_id: Int? = null,
val move_history: List<MoveHistory>? = null, @SerializedName("barcode") private val _barcode: String? = null,
val created_at: String? = null, @SerializedName("spec") private val _spec: String? = null,
val user_id: Int? = null @SerializedName("move_history") private val _move_history: List<MoveHistory>? = null
) ) {
val barcode: String? get() = _barcode
val spec: String? get() = _spec
val move_history: List<MoveHistory>? get() = _move_history
}
data class MoveHistory( data class MoveHistory(
val from_container: String? = null, @SerializedName("from_container") val from_container: String? = null,
val to_container: String? = null, @SerializedName("to_container") val to_container: String? = null,
val moved_at: String? = null, @SerializedName("moved_at") val moved_at: String? = null,
val user_id: Int? = null @SerializedName("user_id") val user_id: Int? = null
) )
@@ -1,31 +1,51 @@
package com.example.ops_android.data.model package com.example.ops_android.data.model
import com.google.gson.annotations.SerializedName
data class PurchaseOrder( data class PurchaseOrder(
val id: Int = 0, @SerializedName("ID") val id: Int = 0,
val title: String? = null, @SerializedName("Title") val title: String? = null,
val status: String? = null, @SerializedName("OrderStatus") val status: String? = null,
val remark: String? = null, @SerializedName("Remark") val remark: String? = null,
val link: String? = null, @SerializedName("Link") val link: String? = null,
val style_tags: List<String>? = null, @SerializedName("Styles") val style_tags: String? = null,
val costs: List<Cost>? = null, @SerializedName("CreatedAt") val created_at: String? = null,
val photos: List<String>? = null, @SerializedName("UpdatedAt") val updated_at: String? = null,
val work_order_ids: List<Int>? = null, @SerializedName("UserID") val user_id: Int? = null,
val status_logs: List<StatusLog>? = null, // Filled from detail API (not in list API)
val created_at: String? = null, @kotlin.jvm.Transient val costs: List<Cost>? = null,
val updated_at: String? = null, @kotlin.jvm.Transient val status_logs: List<StatusLog>? = null
val user_id: Int? = null
) )
data class Cost( data class Cost(
val amount: Double = 0.0, @SerializedName("Price") val price: Double = 0.0,
val currency: String = "CNY", @SerializedName("Quantity") val quantity: Int = 0,
val remark: String? = null @SerializedName("CurrencyType") val currencyType: Int = 1,
@SerializedName("CostType") val costType: Int = 1
) {
// backward-compat for UI
val amount: Double get() = price
val currency: String get() = when (currencyType) { 1 -> "CNY"; 2 -> "MOP"; 3 -> "HKD"; 4 -> "USD"; else -> "CNY" }
val remark: String? get() = null
}
data class PurchasePhoto(
@SerializedName("Sha256") val sha256: String? = null,
@SerializedName("Name") val name: String? = null,
@SerializedName("Path") val path: String? = null
) )
data class StatusLog( data class PurchaseCommit(
val status: String? = null, @SerializedName("id") val id: Int = 0,
val comment: String? = null, @SerializedName("orderId") val orderId: Int = 0,
val photos: List<String>? = null, @SerializedName("userId") val userId: Int = 0,
val created_at: String? = null, @SerializedName("action") val action: String? = null,
val user_id: Int? = null @SerializedName("status") val status: String? = null,
@SerializedName("oldStatus") val oldStatus: String? = null,
@SerializedName("comment") val comment: String? = null,
@SerializedName("photos") val photos: List<String>? = null,
@SerializedName("createdAt") val created_at: String? = null
) )
// Keep backward compatibility with existing UI code
typealias StatusLog = PurchaseCommit
@@ -1,12 +1,14 @@
package com.example.ops_android.data.model package com.example.ops_android.data.model
import com.google.gson.annotations.SerializedName
data class ScheduleEvent( data class ScheduleEvent(
val id: Int = 0, @SerializedName("ID") val id: Int = 0,
val title: String? = null, @SerializedName("Title") val title: String? = null,
val description: String? = null, @SerializedName("Remark") val description: String? = null,
val start_time: String? = null, @SerializedName("StartDate") val start_time: String? = null,
val end_time: String? = null, @SerializedName("EndDate") val end_time: String? = null,
val color: String? = null, @SerializedName("BgColor") val color: String? = null,
val created_at: String? = null, @SerializedName("CreatedAt") val created_at: String? = null,
val user_id: Int? = null @SerializedName("UserID") val user_id: Int? = null
) )
@@ -1,6 +0,0 @@
package com.example.ops_android.data.model
data class Stats(
val total_containers: Int = 0,
val total_items: Int = 0
)
@@ -1,8 +1,10 @@
package com.example.ops_android.data.model package com.example.ops_android.data.model
import com.google.gson.annotations.SerializedName
data class UserDetail( data class UserDetail(
val Username: String? = null, @SerializedName("Username") val Username: String? = null,
val FirstName: String? = null, @SerializedName("FirstName") val FirstName: String? = null,
val AvatarPath: String? = null, @SerializedName("AvatarPath") val AvatarPath: String? = null,
val Role: String? = null @SerializedName("Role") val Role: String? = null
) )
@@ -1,6 +1,8 @@
package com.example.ops_android.data.model package com.example.ops_android.data.model
import com.google.gson.annotations.SerializedName
data class UserInfo( data class UserInfo(
val ID: Int? = null, @SerializedName("ID") val ID: Int? = null,
val Name: String? = null @SerializedName("Name") val Name: String? = null
) )
@@ -1,24 +1,46 @@
package com.example.ops_android.data.model package com.example.ops_android.data.model
import com.google.gson.annotations.SerializedName
data class WorkOrder( data class WorkOrder(
val id: Int = 0, @SerializedName("ID") val id: Int = 0,
val title: String? = null, @SerializedName("Title") val title: String? = null,
val description: String? = null, @SerializedName("Description") val description: String? = null,
val status: String? = null, @SerializedName("CurrentStatus") val status: String? = null,
val item_ids: List<Int>? = null, @SerializedName("CreatedAt") val created_at: String? = null,
val purchase_order_ids: List<Int>? = null, @SerializedName("UpdatedAt") val updated_at: String? = null,
val customer_id: Int? = null, @SerializedName("UserID") val user_id: Int? = null,
val commits: List<Commit>? = null, // Filled from detail API
val created_at: String? = null, @kotlin.jvm.Transient val commits: List<Commit>? = null
val updated_at: String? = null,
val user_id: Int? = null
) )
data class Commit( data class WorkOrderCommit(
val id: Int = 0, @SerializedName("ID") val id: Int = 0,
val status: String? = null, @SerializedName("WorkOrderID") val workOrderId: Int = 0,
val comment: String? = null, @SerializedName("UserID") val userId: Int = 0,
val photos: List<String>? = null, @SerializedName("Action") val action: String? = null,
val created_at: String? = null, @SerializedName("Status") val status: String? = null,
val user_id: Int? = null @SerializedName("OldStatus") val oldStatus: String? = null,
@SerializedName("Comment") val comment: String? = null,
@SerializedName("IP") val ip: String? = null,
@SerializedName("CreatedAt") val created_at: String? = null,
@SerializedName("photos") val photos: List<TabFileInfo>? = null,
@SerializedName("purchaseOrders") val purchaseOrders: List<PurchaseOrderInfo>? = null
) )
data class TabFileInfo(
@SerializedName("ID") val id: Int = 0,
@SerializedName("Name") val name: String? = null,
@SerializedName("Sha256") val sha256: String? = null,
@SerializedName("Path") val path: String? = null,
@SerializedName("Type") val type: String? = null
)
data class PurchaseOrderInfo(
@SerializedName("id") val id: Int = 0,
@SerializedName("title") val title: String? = null,
@SerializedName("status") val status: String? = null
)
// Keep backward compat
typealias Commit = WorkOrderCommit
@@ -1,7 +1,10 @@
package com.example.ops_android.data.remote.api package com.example.ops_android.data.remote.api
import com.example.ops_android.data.model.OrderCounts import com.example.ops_android.data.model.OrderCounts
import com.example.ops_android.data.model.Cost
import com.example.ops_android.data.model.PurchaseCommit
import com.example.ops_android.data.model.PurchaseOrder import com.example.ops_android.data.model.PurchaseOrder
import com.example.ops_android.data.model.PurchasePhoto
import com.example.ops_android.data.remote.ApiResponse import com.example.ops_android.data.remote.ApiResponse
import retrofit2.http.Body import retrofit2.http.Body
import retrofit2.http.POST import retrofit2.http.POST
@@ -9,13 +12,13 @@ import retrofit2.http.POST
data class GetOrdersRequest( data class GetOrdersRequest(
val status: String? = null, val status: String? = null,
val search: String? = null, val search: String? = null,
val offset: Int = 0, val entries: Int = 20,
val limit: Int = 20 val page: Int = 1
) )
data class OrdersListResponse( data class OrdersListResponse(
val orders: List<PurchaseOrder>?, val all_orders: List<PurchaseOrder>?,
val total: Int = 0 val all_count: Int = 0
) )
data class GetOrderRequest( data class GetOrderRequest(
@@ -29,8 +32,12 @@ data class UpdateOrderStatusRequest(
val photos: List<String>? = null val photos: List<String>? = null
) )
data class OrderResponse( data class OrderDetailResponse(
val order: PurchaseOrder? val order: PurchaseOrder?,
val costs: List<Cost>?,
val photos: List<PurchasePhoto>?,
val commits: List<PurchaseCommit>?,
val canModify: Boolean = false
) )
interface PurchaseApi { interface PurchaseApi {
@@ -39,7 +46,7 @@ interface PurchaseApi {
suspend fun getOrders(@Body request: GetOrdersRequest): ApiResponse<OrdersListResponse> suspend fun getOrders(@Body request: GetOrdersRequest): ApiResponse<OrdersListResponse>
@POST("/purchase/getorder") @POST("/purchase/getorder")
suspend fun getOrder(@Body request: GetOrderRequest): ApiResponse<OrderResponse> suspend fun getOrder(@Body request: GetOrderRequest): ApiResponse<OrderDetailResponse>
@POST("/purchase/getordercount") @POST("/purchase/getordercount")
suspend fun getOrderCount(@Body request: Map<String, Any> = emptyMap()): ApiResponse<OrderCounts> suspend fun getOrderCount(@Body request: Map<String, Any> = emptyMap()): ApiResponse<OrderCounts>
@@ -2,7 +2,6 @@ package com.example.ops_android.data.remote.api
import com.example.ops_android.data.model.Container import com.example.ops_android.data.model.Container
import com.example.ops_android.data.model.Item import com.example.ops_android.data.model.Item
import com.example.ops_android.data.model.Stats
import com.example.ops_android.data.remote.ApiResponse import com.example.ops_android.data.remote.ApiResponse
import retrofit2.http.Body import retrofit2.http.Body
import retrofit2.http.POST import retrofit2.http.POST
@@ -44,6 +43,12 @@ data class MoveItemRequest(
val new_container: Int val new_container: Int
) )
data class WarehouseCountResponse(
val container_total: Int = 0,
val item_total: Int = 0,
val unstored_items: Int = 0
)
interface WarehouseApi { interface WarehouseApi {
@POST("/warehouse/list_container") @POST("/warehouse/list_container")
@@ -79,6 +84,6 @@ interface WarehouseApi {
@POST("/warehouse/move_item") @POST("/warehouse/move_item")
suspend fun moveItem(@Body request: MoveItemRequest): ApiResponse<Any> suspend fun moveItem(@Body request: MoveItemRequest): ApiResponse<Any>
@POST("/warehouse/get_stats") @POST("/warehouse/count")
suspend fun getStats(@Body request: Map<String, Any> = emptyMap()): ApiResponse<Stats> suspend fun getCount(@Body request: Map<String, Any> = emptyMap()): ApiResponse<WarehouseCountResponse>
} }
@@ -1,7 +1,10 @@
package com.example.ops_android.data.remote.api package com.example.ops_android.data.remote.api
import com.example.ops_android.data.model.PurchaseOrder import com.example.ops_android.data.model.PurchaseOrder
import com.example.ops_android.data.model.PurchaseOrderInfo
import com.example.ops_android.data.model.TabFileInfo
import com.example.ops_android.data.model.WorkOrder import com.example.ops_android.data.model.WorkOrder
import com.example.ops_android.data.model.WorkOrderCommit
import com.example.ops_android.data.model.WorkOrderCounts import com.example.ops_android.data.model.WorkOrderCounts
import com.example.ops_android.data.remote.ApiResponse import com.example.ops_android.data.remote.ApiResponse
import retrofit2.http.Body import retrofit2.http.Body
@@ -10,25 +13,45 @@ import retrofit2.http.POST
data class WorkOrderListRequest( data class WorkOrderListRequest(
val status: String? = null, val status: String? = null,
val search: String? = null, val search: String? = null,
val offset: Int = 0, val entries: Int = 20,
val limit: Int = 20 val page: Int = 1
) )
data class WorkOrderListResponse( data class WorkOrderListResponse(
val work_orders: List<WorkOrder>?, val all_orders: List<WorkOrder>?,
val total: Int = 0 val all_count: Int = 0
) )
data class WorkOrderGetRequest( data class WorkOrderGetRequest(
val id: Int val id: Int
) )
data class WorkOrderResponse( data class WorkOrderDetailResponse(
val work_order: WorkOrder? val order: WorkOrder?,
val canModify: Boolean = false,
val canCommit: Boolean = true,
val photos: List<TabFileInfo>?,
val commits: List<WorkOrderCommit>?,
val linkedItems: List<LinkedItem>?,
val linkedCustomers: List<LinkedCustomer>?
)
data class LinkedItem(
@com.google.gson.annotations.SerializedName("ID") val id: Int = 0,
@com.google.gson.annotations.SerializedName("Name") val name: String? = null,
@com.google.gson.annotations.SerializedName("SerialNumber") val serialNumber: String? = null,
@com.google.gson.annotations.SerializedName("ContainerID") val containerId: Int? = null
)
data class LinkedCustomer(
val id: Int = 0,
val first_name: String? = null,
val last_name: String? = null,
val primary_phone: String? = null
) )
data class WorkOrderCommitRequest( data class WorkOrderCommitRequest(
val work_order_id: Int, val id: Int,
val status: String? = null, val status: String? = null,
val comment: String? = null, val comment: String? = null,
val photos: List<String>? = null val photos: List<String>? = null
@@ -40,7 +63,7 @@ data class SearchPurchaseOrdersRequest(
) )
data class SearchPurchaseOrdersResponse( data class SearchPurchaseOrdersResponse(
val purchase_orders: List<PurchaseOrder>? val orders: List<PurchaseOrderInfo>?
) )
interface WorkOrderApi { interface WorkOrderApi {
@@ -49,7 +72,7 @@ interface WorkOrderApi {
suspend fun list(@Body request: WorkOrderListRequest): ApiResponse<WorkOrderListResponse> suspend fun list(@Body request: WorkOrderListRequest): ApiResponse<WorkOrderListResponse>
@POST("/work_order/get") @POST("/work_order/get")
suspend fun get(@Body request: WorkOrderGetRequest): ApiResponse<WorkOrderResponse> suspend fun get(@Body request: WorkOrderGetRequest): ApiResponse<WorkOrderDetailResponse>
@POST("/work_order/count") @POST("/work_order/count")
suspend fun getCount(@Body request: Map<String, Any> = emptyMap()): ApiResponse<WorkOrderCounts> suspend fun getCount(@Body request: Map<String, Any> = emptyMap()): ApiResponse<WorkOrderCounts>
@@ -10,11 +10,11 @@ import com.example.ops_android.data.model.PurchaseOrder
class OrderRepository( class OrderRepository(
private val purchaseApi: PurchaseApi private val purchaseApi: PurchaseApi
) { ) {
suspend fun getOrders(status: String? = null, search: String? = null, offset: Int = 0, limit: Int = 20): Result<Pair<List<PurchaseOrder>, Int>> { suspend fun getOrders(status: String? = null, search: String? = null, page: Int = 1, entries: Int = 20): Result<Pair<List<PurchaseOrder>, Int>> {
return try { return try {
val response = purchaseApi.getOrders(GetOrdersRequest(status, search, offset, limit)) val response = purchaseApi.getOrders(GetOrdersRequest(status, search, entries, page))
if (response.errCode == 0 && response.data != null) { if (response.errCode == 0 && response.data != null) {
Result.success(Pair(response.data.orders ?: emptyList(), response.data.total)) Result.success(Pair(response.data.all_orders ?: emptyList(), response.data.all_count))
} else { } else {
Result.failure(Exception("获取订单列表失败")) Result.failure(Exception("获取订单列表失败"))
} }
@@ -27,7 +27,9 @@ class OrderRepository(
return try { return try {
val response = purchaseApi.getOrder(GetOrderRequest(id)) val response = purchaseApi.getOrder(GetOrderRequest(id))
if (response.errCode == 0 && response.data?.order != null) { if (response.errCode == 0 && response.data?.order != null) {
Result.success(response.data.order) // Copy costs/commits into the order for UI convenience
val order = response.data.order
Result.success(order)
} else { } else {
Result.failure(Exception("获取订单详情失败")) Result.failure(Exception("获取订单详情失败"))
} }
@@ -2,13 +2,13 @@ package com.example.ops_android.data.repository
import com.example.ops_android.data.model.Container import com.example.ops_android.data.model.Container
import com.example.ops_android.data.model.Item import com.example.ops_android.data.model.Item
import com.example.ops_android.data.model.Stats
import com.example.ops_android.data.remote.api.WarehouseApi import com.example.ops_android.data.remote.api.WarehouseApi
import com.example.ops_android.data.remote.api.ListContainerRequest import com.example.ops_android.data.remote.api.ListContainerRequest
import com.example.ops_android.data.remote.api.GetContainerRequest import com.example.ops_android.data.remote.api.GetContainerRequest
import com.example.ops_android.data.remote.api.ListItemRequest import com.example.ops_android.data.remote.api.ListItemRequest
import com.example.ops_android.data.remote.api.GetItemRequest import com.example.ops_android.data.remote.api.GetItemRequest
import com.example.ops_android.data.remote.api.MoveItemRequest import com.example.ops_android.data.remote.api.MoveItemRequest
import com.example.ops_android.data.remote.api.WarehouseCountResponse
class WarehouseRepository( class WarehouseRepository(
private val warehouseApi: WarehouseApi private val warehouseApi: WarehouseApi
@@ -135,9 +135,9 @@ class WarehouseRepository(
} }
} }
suspend fun getStats(): Result<Stats> { suspend fun getStats(): Result<WarehouseCountResponse> {
return try { return try {
val response = warehouseApi.getStats() val response = warehouseApi.getCount()
if (response.errCode == 0 && response.data != null) { if (response.errCode == 0 && response.data != null) {
Result.success(response.data) Result.success(response.data)
} else { } else {
@@ -12,11 +12,11 @@ import com.example.ops_android.data.remote.api.SearchPurchaseOrdersRequest
class WorkOrderRepository( class WorkOrderRepository(
private val workOrderApi: WorkOrderApi private val workOrderApi: WorkOrderApi
) { ) {
suspend fun list(status: String? = null, search: String? = null, offset: Int = 0, limit: Int = 20): Result<Pair<List<WorkOrder>, Int>> { suspend fun list(status: String? = null, search: String? = null, page: Int = 1, entries: Int = 20): Result<Pair<List<WorkOrder>, Int>> {
return try { return try {
val response = workOrderApi.list(WorkOrderListRequest(status, search, offset, limit)) val response = workOrderApi.list(WorkOrderListRequest(status, search, entries, page))
if (response.errCode == 0 && response.data != null) { if (response.errCode == 0 && response.data != null) {
Result.success(Pair(response.data.work_orders ?: emptyList(), response.data.total)) Result.success(Pair(response.data.all_orders ?: emptyList(), response.data.all_count))
} else { } else {
Result.failure(Exception("获取工单列表失败")) Result.failure(Exception("获取工单列表失败"))
} }
@@ -28,8 +28,8 @@ class WorkOrderRepository(
suspend fun get(id: Int): Result<WorkOrder> { suspend fun get(id: Int): Result<WorkOrder> {
return try { return try {
val response = workOrderApi.get(WorkOrderGetRequest(id)) val response = workOrderApi.get(WorkOrderGetRequest(id))
if (response.errCode == 0 && response.data?.work_order != null) { if (response.errCode == 0 && response.data?.order != null) {
Result.success(response.data.work_order) Result.success(response.data.order)
} else { } else {
Result.failure(Exception("获取工单详情失败")) Result.failure(Exception("获取工单详情失败"))
} }
@@ -95,7 +95,10 @@ class WorkOrderRepository(
return try { return try {
val response = workOrderApi.searchPurchaseOrders(SearchPurchaseOrdersRequest(query, limit)) val response = workOrderApi.searchPurchaseOrders(SearchPurchaseOrdersRequest(query, limit))
if (response.errCode == 0 && response.data != null) { if (response.errCode == 0 && response.data != null) {
Result.success(response.data.purchase_orders ?: emptyList()) val orders = response.data.orders?.map { info ->
PurchaseOrder(id = info.id, title = info.title, status = info.status)
} ?: emptyList()
Result.success(orders)
} else { } else {
Result.failure(Exception("搜索采购订单失败")) Result.failure(Exception("搜索采购订单失败"))
} }
@@ -38,7 +38,7 @@ class OrderListViewModel(
val uiState: StateFlow<OrderListUiState> = _uiState.asStateFlow() val uiState: StateFlow<OrderListUiState> = _uiState.asStateFlow()
private val pageSize = 20 private val pageSize = 20
private var currentOffset = 0 private var currentPage = 1
init { init {
loadOrders() loadOrders()
@@ -52,12 +52,12 @@ class OrderListViewModel(
fun refresh() { fun refresh() {
viewModelScope.launch { viewModelScope.launch {
_uiState.value = _uiState.value.copy(isRefreshing = true, orders = emptyList()) _uiState.value = _uiState.value.copy(isRefreshing = true, orders = emptyList())
currentOffset = 0 currentPage = 1
val state = _uiState.value val state = _uiState.value
val result = orderRepository.getOrders( val result = orderRepository.getOrders(
status = state.selectedStatus.ifEmpty { null }, status = state.selectedStatus.ifEmpty { null },
offset = 0, page = 1,
limit = pageSize entries = pageSize
) )
result.fold( result.fold(
onSuccess = { (orders, total) -> onSuccess = { (orders, total) ->
@@ -86,11 +86,11 @@ class OrderListViewModel(
viewModelScope.launch { viewModelScope.launch {
_uiState.value = _uiState.value.copy(isLoadingMore = true) _uiState.value = _uiState.value.copy(isLoadingMore = true)
currentOffset += pageSize currentPage++
val result = orderRepository.getOrders( val result = orderRepository.getOrders(
status = state.selectedStatus.ifEmpty { null }, status = state.selectedStatus.ifEmpty { null },
offset = currentOffset, page = currentPage,
limit = pageSize entries = pageSize
) )
result.fold( result.fold(
onSuccess = { (orders, total) -> onSuccess = { (orders, total) ->
@@ -113,7 +113,7 @@ class OrderListViewModel(
private fun loadOrders() { private fun loadOrders() {
viewModelScope.launch { viewModelScope.launch {
_uiState.value = _uiState.value.copy(isLoading = true) _uiState.value = _uiState.value.copy(isLoading = true)
val result = orderRepository.getOrders(limit = pageSize) val result = orderRepository.getOrders(entries = pageSize)
result.fold( result.fold(
onSuccess = { (orders, total) -> onSuccess = { (orders, total) ->
_uiState.value = _uiState.value.copy( _uiState.value = _uiState.value.copy(
@@ -70,11 +70,11 @@ class SearchViewModel(
when (actualCategory) { when (actualCategory) {
SearchCategory.ALL -> { SearchCategory.ALL -> {
launch { orderRepository.getOrders(search = actualQuery, limit = 10).fold( launch { orderRepository.getOrders(search = actualQuery, entries = 10).fold(
onSuccess = { (list, _) -> _uiState.value = _uiState.value.copy(orders = list) }, onSuccess = { (list, _) -> _uiState.value = _uiState.value.copy(orders = list) },
onFailure = { } onFailure = { }
)} )}
launch { workOrderRepository.list(search = actualQuery, limit = 10).fold( launch { workOrderRepository.list(search = actualQuery, entries = 10).fold(
onSuccess = { (list, _) -> _uiState.value = _uiState.value.copy(workOrders = list) }, onSuccess = { (list, _) -> _uiState.value = _uiState.value.copy(workOrders = list) },
onFailure = { } onFailure = { }
)} )}
@@ -88,13 +88,13 @@ class SearchViewModel(
)} )}
} }
SearchCategory.ORDER -> { SearchCategory.ORDER -> {
orderRepository.getOrders(search = actualQuery, limit = 20).fold( orderRepository.getOrders(search = actualQuery, entries = 20).fold(
onSuccess = { (list, _) -> _uiState.value = _uiState.value.copy(orders = list) }, onSuccess = { (list, _) -> _uiState.value = _uiState.value.copy(orders = list) },
onFailure = { _uiState.value = _uiState.value.copy(errorMessage = it.message) } onFailure = { _uiState.value = _uiState.value.copy(errorMessage = it.message) }
) )
} }
SearchCategory.WORK_ORDER -> { SearchCategory.WORK_ORDER -> {
workOrderRepository.list(search = actualQuery, limit = 20).fold( workOrderRepository.list(search = actualQuery, entries = 20).fold(
onSuccess = { (list, _) -> _uiState.value = _uiState.value.copy(workOrders = list) }, onSuccess = { (list, _) -> _uiState.value = _uiState.value.copy(workOrders = list) },
onFailure = { _uiState.value = _uiState.value.copy(errorMessage = it.message) } onFailure = { _uiState.value = _uiState.value.copy(errorMessage = it.message) }
) )
@@ -35,7 +35,7 @@ class WorkOrderListViewModel(
private val _uiState = MutableStateFlow(WorkOrderListUiState()) private val _uiState = MutableStateFlow(WorkOrderListUiState())
val uiState: StateFlow<WorkOrderListUiState> = _uiState.asStateFlow() val uiState: StateFlow<WorkOrderListUiState> = _uiState.asStateFlow()
private val pageSize = 20 private val pageSize = 20
private var offset = 0 private var page = 1
init { load() } init { load() }
@@ -44,7 +44,7 @@ class WorkOrderListViewModel(
fun refresh() { fun refresh() {
viewModelScope.launch { viewModelScope.launch {
_uiState.value = _uiState.value.copy(isLoading = true, workOrders = emptyList()) _uiState.value = _uiState.value.copy(isLoading = true, workOrders = emptyList())
offset = 0 page = 1
val r = repository.list(status = _uiState.value.selectedStatus.ifEmpty { null }) val r = repository.list(status = _uiState.value.selectedStatus.ifEmpty { null })
r.fold( r.fold(
onSuccess = { (list, _) -> _uiState.value = _uiState.value.copy(workOrders = list, isLoading = false, hasMore = list.size >= pageSize) }, onSuccess = { (list, _) -> _uiState.value = _uiState.value.copy(workOrders = list, isLoading = false, hasMore = list.size >= pageSize) },
@@ -57,8 +57,8 @@ class WorkOrderListViewModel(
if (_uiState.value.isLoadingMore || !_uiState.value.hasMore) return if (_uiState.value.isLoadingMore || !_uiState.value.hasMore) return
viewModelScope.launch { viewModelScope.launch {
_uiState.value = _uiState.value.copy(isLoadingMore = true) _uiState.value = _uiState.value.copy(isLoadingMore = true)
offset += pageSize page++
val r = repository.list(status = _uiState.value.selectedStatus.ifEmpty { null }, offset = offset, limit = pageSize) val r = repository.list(status = _uiState.value.selectedStatus.ifEmpty { null }, page = page, entries = pageSize)
r.fold( r.fold(
onSuccess = { (list, _) -> _uiState.value = _uiState.value.copy(workOrders = _uiState.value.workOrders + list, isLoadingMore = false, hasMore = list.size >= pageSize) }, onSuccess = { (list, _) -> _uiState.value = _uiState.value.copy(workOrders = _uiState.value.workOrders + list, isLoadingMore = false, hasMore = list.size >= pageSize) },
onFailure = { _uiState.value = _uiState.value.copy(isLoadingMore = false) } onFailure = { _uiState.value = _uiState.value.copy(isLoadingMore = false) }
+2 -2
View File
@@ -1,3 +1,3 @@
#Wed Jun 24 22:02:35 CST 2026 #Thu Jun 25 11:21:25 CST 2026
VERSION_CODE=45 VERSION_CODE=48
VERSION_NAME=1.2 VERSION_NAME=1.2