Commit c9286519 authored by zhaopengxiang's avatar zhaopengxiang

匡威新需求Ui验收完成

parent 8110e192
package com.miya.fastcashier.config
interface IntentExtra {
companion object {
const val KEY_EXTRA_DATA = "extra_data"
const val KEY_EXTRA_TYPE = "extra_type"
}
}
\ No newline at end of file
......@@ -48,9 +48,7 @@ class MainActivity : BaseActivity() {
tvSlog.text = AccountService.getUserName()
llPay.clickWithTrigger {
val intent = Intent()
intent.setClass(this@MainActivity, PriceInputActivity::class.java)
startActivity(intent)
PriceInputActivity.start(this@MainActivity)
}
llRefund.clickWithTrigger {
val intent = Intent()
......@@ -101,7 +99,6 @@ class MainActivity : BaseActivity() {
}
}
initData()
}
......
......@@ -8,21 +8,17 @@ import com.miya.fastcashier.databinding.ActivityRefundBinding
import com.miya.fastcashier.ui.dialog.MessageDialog
import com.miya.fastcashier.ui.dialog.NumberManualDialog
import com.miya.fastcashier.ui.dialog.NumberManualDialog.NumberInputListener
import com.miya.fastcashier.ui.dialog.RefundInfoDialog
import com.miya.fastcashier.utils.CenterToasty
import com.miya.fastcashier.utils.ScanGunKeyEventHelper
import com.miya.fastcashier.utils.clickWithTrigger
import com.miya.fastcashier.viewmodel.PayViewModel
import com.sdy.miya.moblie.component.pay.platform.bean.PayServiceResponse
class RefundActivity : BaseActivity() {
private var alertDialog: MessageDialog? = null
private lateinit var viewModel: PayViewModel
private lateinit var binding: ActivityRefundBinding
private var refundInfoDialog: RefundInfoDialog? = null
private var numberManualDialog: NumberManualDialog? = null
private var numberManualDialog: NumberManualDialog? = null
private var scanGunKeyEventHelper: ScanGunKeyEventHelper = ScanGunKeyEventHelper()
......@@ -32,33 +28,29 @@ class RefundActivity : BaseActivity() {
binding = ActivityRefundBinding.inflate(layoutInflater)
setContentView(binding.root)
viewModel = ViewModelProvider(this).get(PayViewModel::class.java)
viewModel.payResultLiveData.observe(this, { payResult ->
viewModel.payResultLiveData.observe(this, { payResult ->
payResult.onFailure {
dismissProgressDialog()
it.message?.let { it1 -> CenterToasty.error(this, it1,Toast.LENGTH_LONG).show() }
it.message?.let { it1 -> CenterToasty.error(this, it1, Toast.LENGTH_LONG).show() }
}
payResult.onSuccess { payServiceResponse ->
dismissProgressDialog()
//金额确认弹窗
if(null == refundInfoDialog){
refundInfoDialog = RefundInfoDialog(this)
}
refundInfoDialog?.setData(payServiceResponse) {
doubleRefundConfirm(it)
};
refundInfoDialog?.show()
PriceInputActivity.start(
this@RefundActivity,
PriceInputActivity.Companion.PRICEINPUT_TYPE_CREFUND,
payServiceResponse
)
}
})
viewModel.refundLiveData.observe(this, { payResult ->
viewModel.refundLiveData.observe(this, { payResult ->
payResult.onFailure {
dismissProgressDialog()
it.message?.let { it1 -> CenterToasty.error(this, it1,Toast.LENGTH_LONG).show() }
it.message?.let { it1 -> CenterToasty.error(this, it1, Toast.LENGTH_LONG).show() }
}
payResult.onSuccess {
dismissProgressDialog()
CenterToasty.success(this,"退款成功!!",Toast.LENGTH_LONG).show()
CenterToasty.success(this, "退款成功!!", Toast.LENGTH_LONG).show()
finish()
}
})
......@@ -87,33 +79,8 @@ class RefundActivity : BaseActivity() {
}
}
/**
* 二次退款确认
*/
private fun doubleRefundConfirm(payServiceResponse: PayServiceResponse) {
if (null == alertDialog) {
alertDialog = MessageDialog(this)
.setCustomMessage("是否确认退款")
.setPositiveButton("确认退款"
) { _, _ ->
run {
showProgressDialog("退款中")
viewModel.refund(payServiceResponse)
}
}
}
alertDialog?.show()
}
override fun dispatchKeyEvent(event: KeyEvent?): Boolean {
scanGunKeyEventHelper.analysisKeyEvent(event)
return super.dispatchKeyEvent(event)
}
override fun onStop() {
super.onStop()
refundInfoDialog?.dismiss()
}
}
\ No newline at end of file
......@@ -133,6 +133,11 @@ class CommonDialog : Dialog {
return this
}
fun setCustomMessage(contentStr: SpannableString): CommonDialog {
mContentSpanStr = contentStr
return this
}
fun setMessageGravity(gravity: Int): CommonDialog {
mMessageGravity = gravity
return this
......
package com.miya.fastcashier.utils
import android.content.Context
import android.text.SpannableString
import com.miya.fastcashier.utils.WordUtil
import android.text.TextUtils
import android.text.style.ForegroundColorSpan
import androidx.core.content.ContextCompat
import android.text.Spanned
import android.text.style.StyleSpan
import android.graphics.Typeface
import android.content.Intent
import android.graphics.Color
import android.os.Build
import android.text.style.ClickableSpan
import android.text.TextPaint
import android.text.Html
import android.util.Log
import android.view.View
import java.lang.Exception
import java.util.regex.Pattern
object WordUtil {
/**
* 关键字变色
*
* @param context 上下文
* @param color 变化的色值
* @param text 文字
* @param keyword 文字中的关键字
* @return 结果SpannableString
*/
fun matcherDiscolor(
context: Context?,
color: Int,
text: String,
keyword: String
): SpannableString {
var text = text
var keyword = keyword
val s = SpannableString(text)
keyword = escapeExprSpecialWord(keyword)
text = escapeExprSpecialWord(text)
if (!TextUtils.isEmpty(keyword) && text.contains(keyword)) {
try {
val p = Pattern.compile(keyword)
val m = p.matcher(s)
while (m.find()) {
val start = m.start()
val end = m.end()
//注意:请使用ContextCompat.getColor获取颜色值。
s.setSpan(
ForegroundColorSpan(ContextCompat.getColor(context!!, color)),
start,
end,
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
)
}
} catch (e: Exception) {
e.printStackTrace()
}
}
return s
}
fun matcherBold(context: Context?, text: String, keyword: String): SpannableString {
var text = text
var keyword = keyword
val s = SpannableString(text)
keyword = escapeExprSpecialWord(keyword)
text = escapeExprSpecialWord(text)
if (!TextUtils.isEmpty(keyword) && text.contains(keyword)) {
try {
val p = Pattern.compile(keyword)
val m = p.matcher(s)
while (m.find()) {
val start = m.start()
val end = m.end()
s.setSpan(
StyleSpan(Typeface.BOLD),
start,
end,
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
)
break
}
} catch (e: Exception) {
e.printStackTrace()
}
}
return s
}
/**
* 关键字高亮变色 添加点击链接并跳转
*
* @param context 上下文
* @param color 变化的色值
* @param text 文字
* @param keyword 文字中的关键字
*/
fun setClickableSpanAndLighted(
context: Context,
color: Int,
text: String,
keyword: String,
intent: Intent?
): SpannableString {
var text = text
var keyword = keyword
val s = SpannableString(text)
keyword = escapeExprSpecialWord(keyword)
text = escapeExprSpecialWord(text)
if (!TextUtils.isEmpty(keyword) && text.contains(keyword)) {
try {
val p = Pattern.compile(keyword)
val m = p.matcher(s)
while (m.find()) {
val start = m.start()
val end = m.end()
val clickableSpan: ClickableSpan = object : ClickableSpan() {
override fun onClick(view: View) {
Log.e("setClickableSpan", "点击")
context.startActivity(intent)
}
//设置文字样式
override fun updateDrawState(ds: TextPaint) {
super.updateDrawState(ds)
ds.isUnderlineText = false
ds.bgColor = Color.WHITE
ds.color = ContextCompat.getColor(context, color)
}
}
s.setSpan(clickableSpan, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
}
} catch (e: Exception) {
e.printStackTrace()
}
}
return s
}
/**
* 关键字高亮变色 添加点击链接并跳转
*
* @param context 上下文
* @param color 变化的色值
* @param keyword 文字中的关键字
*/
fun setClickableSpanAndLighted(
context: Context,
color: Int,
s: SpannableString?,
keyword: String,
intent: Intent?
): SpannableString? {
var keyword = keyword
if (s == null) {
return null
}
keyword = escapeExprSpecialWord(keyword)
if (!TextUtils.isEmpty(keyword) && s.toString().contains(keyword)) {
try {
val p = Pattern.compile(keyword)
val m = p.matcher(s)
while (m.find()) {
val start = m.start()
val end = m.end()
val clickableSpan: ClickableSpan = object : ClickableSpan() {
override fun onClick(view: View) {
Log.e("setClickableSpan", "点击")
context.startActivity(intent)
}
//设置文字样式
override fun updateDrawState(ds: TextPaint) {
super.updateDrawState(ds)
ds.isUnderlineText = false
ds.bgColor = Color.WHITE
ds.color = ContextCompat.getColor(context, color)
}
}
s.setSpan(clickableSpan, start, end, 0)
}
} catch (e: Exception) {
e.printStackTrace()
}
}
return s
}
/**
* 转义正则特殊字符 ($()*+.[]?\^{},|)
*
* @param keyword
* @return keyword
*/
fun escapeExprSpecialWord(keyword: String): String {
var keyword = keyword
if (!TextUtils.isEmpty(keyword)) {
val fbsArr =
arrayOf("\\", "$", "(", ")", "*", "+", ".", "[", "]", "?", "^", "{", "}", "|")
for (key in fbsArr) {
if (keyword.contains(key)) {
keyword = keyword.replace(key, "\\" + key)
}
}
}
return keyword
}
/**
* 通过Html.fromHtml方式修改颜色(解决SDK版本问题)
*
* @param html
* @return
*/
fun fromHtml(html: String?): Spanned {
val result: Spanned
result = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
Html.fromHtml(html, Html.FROM_HTML_MODE_LEGACY)
} else {
Html.fromHtml(html)
}
return result
}
/**
* 字体颜色修改
*
* @param content
* @param color
* @return
*/
fun color(content: String, color: Int): String {
return "<font color=\"#" + Integer.toHexString(color) + "\" >" + content + "</font>"
}
/**
* 加粗字体
*
* @param content
* @return
*/
fun bold(content: String): String {
return "<b>$content</b>"
}
}
\ No newline at end of file
......@@ -34,6 +34,9 @@ class PayViewModel : ViewModel() {
val payServiceResponseLiveData: MutableLiveData<Result<PayServiceResponse>> = MutableLiveData()
val payResultLiveData: MutableLiveData<Result<PayServiceResponse>> = MutableLiveData()
/**
* 退款全额
*/
fun refund(payServiceResponse: PayServiceResponse) {
XLog.d("开始退款:${JSON.toJSONString(payServiceResponse)}")
viewModelScope.launch(Dispatchers.IO) {
......@@ -79,8 +82,57 @@ class PayViewModel : ViewModel() {
}
}
/**
* 退款固定数额
*/
fun refund(payServiceResponse: PayServiceResponse, refundPrice: String) {
XLog.d("开始退款:${JSON.toJSONString(payServiceResponse)}")
viewModelScope.launch(Dispatchers.IO) {
//退款
var refundPayServiceResponse: PayServiceResponse? = null
try {
val refundParams = HashMap<String, String>()
refundParams["oriOrderNo"] = payServiceResponse.shopTradeNo;
val refundOrderNo =
AccountService.getAccountInfo()?.shopInfo?.saasid + System.currentTimeMillis()
refundParams["refundOrderNo"] = refundOrderNo
refundParams["refundPrice"] = refundPrice
refundPayServiceResponse = PayRepository.refundByOrderNo(refundParams)
XLog.d("退款成功:${JSON.toJSONString(refundPayServiceResponse)}")
//保存到数据库
ViewPayOrderData.insert(refundPayServiceResponse)
refundLiveData.postValue(Result.success(refundPayServiceResponse))
} catch (e: Exception) {
e.printStackTrace()
XLog.d("退款异常:${e.message}")
refundLiveData.postValue(Result.failure(e))
}
//退款打印
try {
XLog.d("开始退款打印")
AccountService.getAccountInfo()
?.let {
refundPayServiceResponse?.let { it1 ->
PrintService.refundPrint(
it,
it1
)
}
}
} catch (e: Exception) {
e.printStackTrace()
XLog.d("退款打印异常${e.message}")
refundLiveData.postValue(Result.failure(e))
}
}
}
/**
* 生成付款码支付
* payType 只支持微信或者支付宝
* 2是微信 1是支付宝
* price 传进来要是分,整数
......@@ -165,7 +217,7 @@ class PayViewModel : ViewModel() {
/**
* 金额是元,首先要转成分
* 被扫支付,金额是元,首先要转成分
*/
fun pay(price: String, payCode: String) {
XLog.d("被扫开始")
......
......@@ -12,7 +12,7 @@
<androidx.appcompat.widget.LinearLayoutCompat
android:id="@+id/llBack"
android:layout_width="200dp"
android:layout_height="87dp"
android:layout_height="88dp"
android:orientation="horizontal"
android:gravity="center_vertical"
app:layout_constraintStart_toStartOf="parent"
......@@ -44,28 +44,45 @@
</androidx.appcompat.widget.LinearLayoutCompat>
<TextView
android:id="@+id/tvTitle"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
android:layout_height="88dp"
android:gravity="center"
android:textColor="@color/white"
android:text="收款"
android:textSize="36sp"/>
<TextView
android:id="@+id/tvPriceText"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/llBack"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="32dp"
android:layout_marginLeft="32dp"
android:layout_marginTop="48dp"
android:layout_marginTop="54dp"
android:textColor="@color/white"
android:text="收款金额"
android:textSize="24sp"/>
android:textSize="32sp"/>
<TextView
android:id="@+id/tvRefundPriceTotal"
app:layout_constraintStart_toEndOf="@+id/tvPriceText"
app:layout_constraintTop_toBottomOf="@+id/llBack"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="54dp"
android:textColor="@color/white"
android:textStyle="bold"
android:visibility="gone"
tools:text="¥319.00"
tools:visibility="visible"
android:textSize="32sp"/>
<ImageView
android:id="@+id/ivRmb"
......@@ -107,13 +124,28 @@
android:layout_marginRight="32dp"
android:gravity="end" />
<TextView
android:id="@+id/tvInvalidRefundPrice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="32dp"
app:layout_constraintTop_toBottomOf="@+id/vBaseLine"
app:layout_constraintEnd_toEndOf="parent"
android:layout_marginTop="16dp"
android:textColor="@color/color_FF4E33"
android:visibility="gone"
android:text="退款金额无效"
tools:visibility="visible"
android:textSize="26sp"/>
<com.miya.fastcashier.widget.DecimalKeyboard
android:id="@+id/numKeyboard"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:layout_width="match_parent"
app:layout_constraintBottom_toTopOf="@+id/tvScanPayCode"
android:layout_height="637dp"/>
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginBottom="130dp"
android:layout_height="637dp" />
<TextView
android:id="@+id/tvScanPayCode"
......@@ -141,6 +173,20 @@
android:background="@drawable/app_paycode_generate"
android:layout_width="0dp"/>
<TextView
android:id="@+id/tvRefund"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_height="130dp"
android:textColor="@color/white"
android:textSize="36sp"
android:text="确认退款"
android:gravity="center"
android:visibility="gone"
android:background="@drawable/app_paycode_generate"
android:layout_width="0dp"/>
<!-- &lt;!&ndash;封装成一个View&ndash;&gt;-->
<!-- <androidx.constraintlayout.widget.ConstraintLayout-->
<!-- android:visibility="gone"-->
......
......@@ -16,4 +16,5 @@
<color name="color_ECECEC">#ECECEC</color>
<color name="color_F8F8F8">#F8F8F8</color>
<color name="color_E5E5E5">#E5E5E5</color>
<color name="color_D83773">#D83773</color>
</resources>
\ No newline at end of file
......@@ -23,5 +23,6 @@
<string name="search_order_prompt_text">还没有明细哦~</string>
<string name="app_text_login_out">是否确认退出登录账号</string>
<string name="text_login_out_sure">确认退出</string>
<string name="text_refund_amount">退款金额¥%s,是否确认退款</string>
</resources>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment