PrintViewModel.kt 1.02 KB
Newer Older
jiangjiantao's avatar
jiangjiantao committed
1 2 3 4 5
package com.miya.fastcashier.viewmodel

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
6
import com.fastcashier.lib_common.function.account.AccountService
7
import com.fastcashier.lib_common.function.print.PrintService
jiangjiantao's avatar
jiangjiantao committed
8
import com.sdy.miya.moblie.component.pay.platform.bean.PayServiceResponse
zhaopengxiang's avatar
zhaopengxiang committed
9 10
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
jiangjiantao's avatar
jiangjiantao committed
11 12 13 14 15 16 17 18 19

class PrintViewModel : ViewModel() {

    val printResultLiveData: MutableLiveData<Result<Any>> = MutableLiveData()

    fun printOrder(payServiceResponse: PayServiceResponse){
        //todo 检查参数
        viewModelScope.launch(Dispatchers.IO){
            try {
jiangjiantao's avatar
jiangjiantao committed
20
                AccountService.getAccountInfo()?.let {
21
                    PrintService.payPrint(payServiceResponse, it)
jiangjiantao's avatar
jiangjiantao committed
22 23 24 25 26 27 28 29 30 31
                }
                printResultLiveData.postValue(Result.success(Any()))
            }catch (e:Exception){
                printResultLiveData.postValue(Result.failure(e))
            }
        }
    }


}