采购列表和入库列表页支持修改数量和价格;识别弹窗关闭及延迟识别;入库页面逻辑优化;提交未选择仓库时提示优化;
This commit is contained in:
@@ -113,7 +113,9 @@ class FoodCollectionActivity : ComponentActivity() {
|
||||
binding = ActivityFoodCollectionBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
cameraUtils.initCamera()
|
||||
binding.root.hideKeyboard()
|
||||
binding.root.setOnClickListener {
|
||||
it.hideKeyboard()
|
||||
}
|
||||
val previewBinding =
|
||||
LayoutCameraPreviewBinding.inflate(layoutInflater, binding.flCameraPreview)
|
||||
previewView = previewBinding.previewView.also {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.sw.inbound.activity
|
||||
|
||||
import android.graphics.Color
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.text.SpannableStringBuilder
|
||||
@@ -21,7 +22,6 @@ import com.sw.inbound.dialog.DropdownPopup
|
||||
import com.sw.inbound.dialog.GoodsRecognizeDialog
|
||||
import com.sw.inbound.dialog.GoodsSearchDialog
|
||||
import com.sw.inbound.dialog.NotReceiptWarnDialog
|
||||
import com.sw.inbound.ext.toSafeDouble
|
||||
import com.sw.inbound.model.request.GoodsAddParam
|
||||
import com.sw.inbound.model.request.PurchaseWarehouseParam
|
||||
import com.sw.inbound.model.request.UploadInfo
|
||||
@@ -36,6 +36,8 @@ import com.sw.inbound.utils.CameraUtils
|
||||
import com.sw.inbound.utils.ImageUtil
|
||||
import com.sw.inbound.utils.ext.dp
|
||||
import com.sw.inbound.utils.ext.gone
|
||||
import com.sw.inbound.utils.ext.hideKeyboard
|
||||
import com.sw.inbound.utils.ext.roundedDecimalPlace
|
||||
import com.sw.inbound.utils.ext.toJsonString
|
||||
import com.sw.inbound.utils.ext.toast
|
||||
import com.sw.inbound.viewmodel.ReceiptViewModel
|
||||
@@ -43,12 +45,14 @@ import dagger.hilt.android.AndroidEntryPoint
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import timber.log.Timber
|
||||
import java.io.File
|
||||
import kotlin.math.abs
|
||||
import kotlin.math.min
|
||||
|
||||
@AndroidEntryPoint
|
||||
abstract class GoodsListActivity : ComponentActivity() {
|
||||
|
||||
companion object {
|
||||
private const val TAG = "GoodsListActivity"
|
||||
public const val ID = "id"
|
||||
public const val SUPPLIER_ID = "supplierId"
|
||||
|
||||
@@ -56,6 +60,7 @@ abstract class GoodsListActivity : ComponentActivity() {
|
||||
public const val IS_NEW_RECEIPT = "isNewReceipt"
|
||||
|
||||
const val PAGE_SIZE = 10
|
||||
private const val DELAY_TIME = 30 * 1000
|
||||
}
|
||||
|
||||
var isReceiptPage: Boolean = false
|
||||
@@ -89,7 +94,9 @@ abstract class GoodsListActivity : ComponentActivity() {
|
||||
replaceIncludeContent()
|
||||
initRecyclerView()
|
||||
initView()
|
||||
|
||||
binding.root.setOnClickListener {
|
||||
it.hideKeyboard()
|
||||
}
|
||||
binding.btnBack.setOnClickListener { handleBackEvent() }
|
||||
|
||||
binding.flWarehouseDropdown.setOnClickListener { v ->
|
||||
@@ -105,6 +112,7 @@ abstract class GoodsListActivity : ComponentActivity() {
|
||||
list = dropdownList,
|
||||
popHeight = min(355.dp, dropdownList.size * 71.dp)
|
||||
) {
|
||||
binding.cvDropdownBg.setCardBackgroundColor(Color.TRANSPARENT)
|
||||
binding.tvWareHouse.run {
|
||||
text = it.value
|
||||
tag = it.id
|
||||
@@ -114,23 +122,11 @@ abstract class GoodsListActivity : ComponentActivity() {
|
||||
dropdownPopup?.showAsDropDown(v)
|
||||
}
|
||||
binding.tvPurchaseNo.setOnClickListener {
|
||||
isShowRecognizeDialog = false
|
||||
GoodsRecognizeDialog(
|
||||
context = this,
|
||||
list = mutableListOf()
|
||||
) {
|
||||
GoodsSearchDialog(this).show()
|
||||
}.apply {
|
||||
setOnDismissListener {
|
||||
isShowRecognizeDialog = true
|
||||
}
|
||||
setOnShowListener {
|
||||
isShowRecognizeDialog = false
|
||||
}
|
||||
if (isFinishing.not() && isDestroyed.not()) {
|
||||
show()
|
||||
}
|
||||
}
|
||||
handleGoodsResult(
|
||||
goodsList = mutableListOf(),
|
||||
file = null,
|
||||
name = null
|
||||
)
|
||||
}
|
||||
binding.tvUserName.text = GlobalData.deviceId
|
||||
binding.tvUserName.gone()
|
||||
@@ -144,8 +140,7 @@ abstract class GoodsListActivity : ComponentActivity() {
|
||||
}
|
||||
}
|
||||
cameraUtils.setPreviewController(previewView)
|
||||
|
||||
//viewModel.startSensorScale()
|
||||
startTime = System.currentTimeMillis()
|
||||
binding.root.postDelayed({
|
||||
SensorScaleUtils.addWeightListener {
|
||||
weightCallback?.invoke(it)
|
||||
@@ -159,15 +154,38 @@ abstract class GoodsListActivity : ComponentActivity() {
|
||||
weightCallback = callback
|
||||
}
|
||||
|
||||
private var lastWeight = 0
|
||||
private fun recognizeWeight(weight: Int) {
|
||||
Timber.tag(TAG).d("recognizeWeight,lastWeight=$lastWeight,weight=$weight")
|
||||
//if (this.lastWeight - weight >= 0) {
|
||||
// this.lastWeight = weight
|
||||
// //从秤上取物品中
|
||||
// return
|
||||
//}
|
||||
if (weight < 200) {
|
||||
if (abs(weight) < 10) {
|
||||
if (goodsRecognizeDialog?.isShowing == true) {
|
||||
goodsRecognizeDialog?.dismiss()
|
||||
isShowRecognizeDialog = true
|
||||
goodsRecognizeDialog = null
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
runOnUiThread {
|
||||
recognizeFood()
|
||||
this.lastWeight = weight
|
||||
val checkResult = isFirstRecognize.not() && System.currentTimeMillis() - startTime <= DELAY_TIME
|
||||
Timber.tag(TAG).d("recognizeWeight,checkResult=$checkResult")
|
||||
if (checkResult) {
|
||||
Timber.tag(TAG).d("recognizeWeight,等待中:${(System.currentTimeMillis() - startTime)/1000}")
|
||||
return
|
||||
}
|
||||
Timber.tag(TAG).d("recognizeWeight,recognizeFood:isShowRecognizeDialog=$isShowRecognizeDialog")
|
||||
recognizeFood()
|
||||
}
|
||||
|
||||
var startTime = 0L
|
||||
var isFirstRecognize = true
|
||||
|
||||
private val takePhotoSuccessCallback: (Uri) -> Unit = { uri ->
|
||||
Thread {
|
||||
searchFood(uri)
|
||||
@@ -178,9 +196,11 @@ abstract class GoodsListActivity : ComponentActivity() {
|
||||
if (isShowRecognizeDialog.not()) {
|
||||
return
|
||||
}
|
||||
Timber.tag(TAG).d("recognizeFood,takePhoto")
|
||||
isShowRecognizeDialog = false
|
||||
bindCamera()
|
||||
//bindCamera()
|
||||
cameraUtils.takePhoto(takePhotoSuccessCallback)
|
||||
isFirstRecognize = false
|
||||
}
|
||||
|
||||
private var dropdownPopup: DropdownPopup? = null
|
||||
@@ -230,7 +250,7 @@ abstract class GoodsListActivity : ComponentActivity() {
|
||||
private fun handleGoodsResult(
|
||||
goodsList: List<SearchGoodsInfo.Record>,
|
||||
file: File?,
|
||||
name: String
|
||||
name: String?
|
||||
) {
|
||||
runOnUiThread {
|
||||
if (goodsRecognizeDialog?.isShowing == true) {
|
||||
@@ -241,7 +261,7 @@ abstract class GoodsListActivity : ComponentActivity() {
|
||||
context = this,
|
||||
list = goodsList.toMutableList(),
|
||||
goodsFile = file,
|
||||
goodsName = name
|
||||
goodsName = name,
|
||||
) {
|
||||
GoodsSearchDialog(this).show()
|
||||
}.apply {
|
||||
@@ -249,17 +269,15 @@ abstract class GoodsListActivity : ComponentActivity() {
|
||||
goodsRecognizeDialog = null
|
||||
isShowRecognizeDialog = true
|
||||
}
|
||||
setOnShowListener {
|
||||
isShowRecognizeDialog = false
|
||||
}
|
||||
if (isFinishing.not() && isDestroyed.not()) {
|
||||
isShowRecognizeDialog = false
|
||||
show()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private var goodsRecognizeDialog: GoodsRecognizeDialog? = null
|
||||
var goodsRecognizeDialog: GoodsRecognizeDialog? = null
|
||||
|
||||
private fun replaceIncludeContent() {
|
||||
binding.flContainer.removeAllViews()
|
||||
@@ -305,22 +323,23 @@ abstract class GoodsListActivity : ComponentActivity() {
|
||||
return
|
||||
}
|
||||
val item = goodsList.firstOrNull { it.goodId == goods.goodId }
|
||||
if (item == null) {
|
||||
if (item == null || item.unitName != goods.unitName) {
|
||||
//不存在物品或者物品单位不同
|
||||
goods.isSelected = true
|
||||
goodsList.add(goods)
|
||||
binding.rvGoodsList.adapter?.notifyItemInserted(goodsList.size - 1)
|
||||
return
|
||||
}
|
||||
item.isSelected = true
|
||||
val finalWeight = item.goodsWeight?.toDouble().plus2(goods.goodsWeight?.toDouble())
|
||||
val finalNum = item.receivedNum.plus2(goods.receivedNum)
|
||||
val finalAmount = item.recUnitPriceTaxIn.plus2(goods.recUnitPriceTaxIn)
|
||||
val finalPrice =
|
||||
if (finalAmount == 0.toDouble() || finalNum == 0.toDouble()) 0.toDouble() else finalAmount / finalNum
|
||||
val finalAmount = item.recPriceInItem.plus2(goods.recPriceInItem)
|
||||
val finalPrice = if (finalAmount == 0.toDouble() || finalNum == 0.toDouble()) 0.toDouble() else finalAmount / finalNum
|
||||
item.run {
|
||||
receivedNum = finalNum
|
||||
recUnitPriceTaxIn = goods.recUnitPriceTaxIn
|
||||
recPriceInItem = finalPrice.toSafeDouble()
|
||||
goodsWeight = goods.goodsWeight
|
||||
recUnitPriceTaxIn = finalPrice.roundedDecimalPlace(2)
|
||||
recPriceInItem = finalAmount.roundedDecimalPlace(2)
|
||||
goodsWeight = finalWeight.toBigDecimal()
|
||||
}
|
||||
binding.rvGoodsList.adapter?.notifyItemChanged(goodsList.indexOf(item))
|
||||
if (this is ReceiptActivity) {
|
||||
@@ -430,6 +449,11 @@ abstract class GoodsListActivity : ComponentActivity() {
|
||||
fun selfProcurementSubmit() {
|
||||
if (binding.tvWareHouse.tag == null) {
|
||||
toast("请选择仓库")
|
||||
binding.cvDropdownBg.setCardBackgroundColor(Color.RED)
|
||||
return
|
||||
}
|
||||
if (goodsList.isEmpty()) {
|
||||
toast("暂无入库物品,请采集后操作")
|
||||
return
|
||||
}
|
||||
val submitData = goodsList.map {
|
||||
@@ -442,7 +466,7 @@ abstract class GoodsListActivity : ComponentActivity() {
|
||||
goodsPrice = it.goodsPrice ?: 0.0,
|
||||
//goodPurId = it.goodsPurId,
|
||||
warehouseId = binding.tvWareHouse.tag.toString(),
|
||||
buyToInventoryValue = it.consumeValue ?: ""
|
||||
buyToInventoryValue = it.buyToInventoryValue ?: ""
|
||||
)
|
||||
}
|
||||
Timber.tag("SelfProcurementActivity")
|
||||
|
||||
@@ -51,7 +51,9 @@ class ReceiptActivity : GoodsListActivity() {
|
||||
binding.tvPurchaseNo.text = "采购单号:${detail.purCode}"
|
||||
val list = detail.receiveGoodsInfoList
|
||||
list.forEach { goodsInfo ->
|
||||
goodsInfo.recUnitPriceTaxIn2 = goodsInfo.recUnitPriceTaxIn
|
||||
goodsInfo.recUnitPriceTaxInBak = goodsInfo.recUnitPriceTaxIn
|
||||
goodsInfo.unitNameBak = goodsInfo.unitName
|
||||
goodsInfo.receivedNumBak = goodsInfo.receivedNum
|
||||
}
|
||||
goodsList.addAll(list)
|
||||
adapter.notifyDataSetChanged()
|
||||
|
||||
@@ -1,24 +1,33 @@
|
||||
package com.sw.inbound.adapter
|
||||
|
||||
import android.content.Context
|
||||
import android.text.InputType
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import android.widget.EditText
|
||||
import android.widget.LinearLayout
|
||||
import android.widget.TextView
|
||||
import androidx.core.graphics.toColorInt
|
||||
import androidx.core.view.updateLayoutParams
|
||||
import androidx.core.widget.addTextChangedListener
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.chad.library.adapter4.BaseQuickAdapter
|
||||
import com.chad.library.adapter4.viewholder.QuickViewHolder
|
||||
import com.sw.inbound.R
|
||||
import com.sw.inbound.databinding.ListItemReceiptGoodsBinding
|
||||
import com.sw.inbound.dialog.WarnDialog
|
||||
import com.sw.inbound.ext.toSafeDouble
|
||||
import com.sw.inbound.model.response.GoodsInfo
|
||||
import com.sw.inbound.utils.ext.dp
|
||||
import com.sw.inbound.utils.ext.gone
|
||||
import com.sw.inbound.utils.ext.hideKeyboard
|
||||
import com.sw.inbound.utils.ext.ifNullOrBlank
|
||||
import com.sw.inbound.utils.ext.ifNullOrZero
|
||||
import com.sw.inbound.utils.ext.roundedDecimalPlace
|
||||
import com.sw.inbound.utils.ext.setShapeDrawable
|
||||
import com.sw.inbound.utils.ext.toast
|
||||
import com.sw.inbound.utils.ext.visible
|
||||
import com.sw.inbound.utils.removeTrailingZeros
|
||||
|
||||
class ReceiptGoodsAdapter(var list: MutableList<GoodsInfo>) :
|
||||
BaseQuickAdapter<GoodsInfo, ReceiptGoodsAdapter.VH>(list) {
|
||||
@@ -42,18 +51,32 @@ class ReceiptGoodsAdapter(var list: MutableList<GoodsInfo>) :
|
||||
solidColor = if (item!!.isSelected) "#FFD5E1FF" else "#FFFFFFFF",
|
||||
radius = 6.dp
|
||||
)
|
||||
root.setOnClickListener {
|
||||
it.hideKeyboard()
|
||||
}
|
||||
updateTextView(
|
||||
tvGoodsName, tvProcurementUnit,
|
||||
tvProcurementCount, tvProcurementPrice,
|
||||
tvProcurementAmount, tvReceiptCount, tvGoodsWeight,
|
||||
tvProcurementCount, tvGoodsWeight,
|
||||
etReceiptCount, etReceiptAmount
|
||||
//tvReceiptCount, tvProcurementPrice, tvProcurementAmount,
|
||||
)
|
||||
tvGoodsName.text = item.goodName.ifNullOrBlank("-")
|
||||
tvProcurementUnit.text = item.unitName.ifNullOrBlank("-")
|
||||
tvProcurementCount.text = item.receiveCount.ifNullOrZero("-")
|
||||
tvProcurementPrice.text = item.recUnitPriceTaxIn2.toSafeDouble(2).ifNullOrZero("-")
|
||||
tvProcurementAmount.text = item.recPriceExItem.toSafeDouble(2).ifNullOrZero("-")
|
||||
tvReceiptCount.text = item.receivedNum.toSafeDouble(2).ifNullOrZero("-")
|
||||
tvGoodsWeight.text = item.goodsWeight?.toDouble().toSafeDouble(2).ifNullOrZero("-")
|
||||
tvProcurementCount.text = if (item.receiveCount == null || item.receiveCount == 0.toDouble()) "-"
|
||||
else item.receiveCount.removeTrailingZeros()
|
||||
//tvProcurementPrice.text = item.recUnitPriceTaxInBak.toSafeDouble(2).ifNullOrZero("-")
|
||||
//tvProcurementAmount.text = item.recPriceExItem.toSafeDouble(2).ifNullOrZero("-")
|
||||
//tvReceiptCount.text = item.receivedNum.toSafeDouble(2).ifNullOrZero("-")
|
||||
tvGoodsWeight.text = if (item.goodsWeight == null || item.goodsWeight == 0.toBigDecimal()) "-"
|
||||
else item.goodsWeight?.toDouble().removeTrailingZeros()
|
||||
|
||||
if (item.unitHint.isNullOrBlank().not()) {
|
||||
unitDivider.visible()
|
||||
tvUnitHint.run {
|
||||
visible()
|
||||
text = item.unitHint?.replace(",", "\n")
|
||||
}
|
||||
}
|
||||
|
||||
tvState.gone()
|
||||
ivState.run {
|
||||
@@ -65,10 +88,94 @@ class ReceiptGoodsAdapter(var list: MutableList<GoodsInfo>) :
|
||||
else R.mipmap.ic_receipt_all
|
||||
)
|
||||
}
|
||||
|
||||
etReceiptCount.run {
|
||||
isEnabled = item.receivedNum != null && item.receivedNum != 0.toDouble()
|
||||
updateLayoutParams<LinearLayout.LayoutParams> {
|
||||
topMargin = if (isEnabled) 20.dp else 0
|
||||
bottomMargin = if (isEnabled) 20.dp else 0
|
||||
leftMargin = if (isEnabled) 20.dp else 0
|
||||
rightMargin = if (isEnabled) 20.dp else 0
|
||||
}
|
||||
if (isEnabled) {
|
||||
setShapeDrawable(strokeColor = "#FFDCDCF0", strokeWidth = 2.dp, radius = 8.dp)
|
||||
val unit = item.unitName
|
||||
inputType = if (unit == "千克" || unit == "公斤" || unit == "斤") {
|
||||
InputType.TYPE_CLASS_NUMBER or InputType.TYPE_NUMBER_FLAG_DECIMAL
|
||||
} else {
|
||||
InputType.TYPE_CLASS_NUMBER
|
||||
}
|
||||
setText(item.receivedNum?.removeTrailingZeros())
|
||||
setSelection(length())
|
||||
} else {
|
||||
setText("-")
|
||||
}
|
||||
}
|
||||
etReceiptAmount.run {
|
||||
isEnabled = item.recPriceInItem != null && item.recPriceInItem != 0.toDouble()
|
||||
updateLayoutParams<LinearLayout.LayoutParams> {
|
||||
topMargin = if (isEnabled) 20.dp else 0
|
||||
bottomMargin = if (isEnabled) 20.dp else 0
|
||||
leftMargin = if (isEnabled) 20.dp else 0
|
||||
rightMargin = if (isEnabled) 20.dp else 0
|
||||
}
|
||||
if (isEnabled) {
|
||||
setShapeDrawable(strokeColor = "#FFDCDCF0", strokeWidth = 2.dp, radius = 6.dp)
|
||||
setText(item.recPriceInItem?.removeTrailingZeros())
|
||||
setSelection(length())
|
||||
} else {
|
||||
setText("-")
|
||||
val colorString = if (item.isSelected) "#FFD5E1FF" else "#FFFFFFFF"
|
||||
setBackgroundColor(colorString.toColorInt())
|
||||
}
|
||||
}
|
||||
addEditListener(etReceiptCount) {
|
||||
if (it == 0.toDouble()) {
|
||||
context.toast("数量不能为0")
|
||||
etReceiptCount.setText(item.receivedNum?.removeTrailingZeros())
|
||||
return@addEditListener
|
||||
}
|
||||
item.receivedNum = it
|
||||
item.recUnitPriceTaxIn = item.recPriceInItem!! / it
|
||||
//tvGoodsPrice.text = "${item.goodsUnitPrice?.roundedDecimalPlace(2)}"
|
||||
}
|
||||
addEditListener(etReceiptAmount) {
|
||||
if (it == 0.toDouble()) {
|
||||
context.toast("金额不能为0")
|
||||
etReceiptAmount.setText(item.recPriceInItem?.removeTrailingZeros())
|
||||
return@addEditListener
|
||||
}
|
||||
item.recPriceInItem = it
|
||||
item.recUnitPriceTaxIn = it / item.receivedNum!!
|
||||
//tvGoodsPrice.text = "${item.goodsUnitPrice?.roundedDecimalPlace(2)}"
|
||||
}
|
||||
ivClear.run {
|
||||
visible()
|
||||
setOnClickListener {
|
||||
if (item.isLocalGoods) {
|
||||
//删除行数据弹窗
|
||||
showWarnDialog(content = "请确认是否删除该条采购数据,删除后不可恢复?") {
|
||||
list.removeAt(position)
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
return@setOnClickListener
|
||||
}
|
||||
//清除数据,恢复默认
|
||||
showWarnDialog(content = "请确认是否清除添加的收货信息,清除后不可恢复?") {
|
||||
item.receivedNum = item.receivedNumBak
|
||||
item.recPriceInItem = 0.0
|
||||
item.recUnitPriceTaxIn = 0.0
|
||||
item.unitName = item.unitNameBak
|
||||
notifyItemChanged(position)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun showWarnDialog(content:String, callback:()-> Unit) {
|
||||
WarnDialog(context = context, content = content, confirmBlock = callback).show()
|
||||
}
|
||||
|
||||
private fun updateTextView(vararg views: TextView) {
|
||||
views.forEach {
|
||||
it.setTextColor("#FF1E2832".toColorInt())
|
||||
@@ -76,4 +183,31 @@ class ReceiptGoodsAdapter(var list: MutableList<GoodsInfo>) :
|
||||
}
|
||||
}
|
||||
|
||||
private fun addEditListener(editText: EditText, action: (Double) -> Unit) {
|
||||
editText.run {
|
||||
addTextChangedListener(onTextChanged = { it, _, _, _ ->
|
||||
try {
|
||||
if (editText.isFocused.not()) {
|
||||
return@addTextChangedListener
|
||||
}
|
||||
val input = it.toString()
|
||||
if (input.startsWith(".")) {
|
||||
setText("0.")
|
||||
setSelection(length())
|
||||
} else if (input.contains(".")) {
|
||||
val index = input.indexOf(".")
|
||||
if (input.length - index > 3) {
|
||||
setText(input.substring(0, index + 3))
|
||||
setSelection(length())
|
||||
}
|
||||
}
|
||||
val value = if (input == "0.") 0.0 else input.toDouble()
|
||||
action(value)
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,23 +1,29 @@
|
||||
package com.sw.inbound.adapter
|
||||
|
||||
import android.content.Context
|
||||
import android.text.InputType
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import android.view.inputmethod.EditorInfo
|
||||
import android.widget.EditText
|
||||
import android.widget.LinearLayout
|
||||
import android.widget.TextView
|
||||
import androidx.core.graphics.toColorInt
|
||||
import androidx.core.view.updateLayoutParams
|
||||
import androidx.core.widget.addTextChangedListener
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.chad.library.adapter4.BaseQuickAdapter
|
||||
import com.chad.library.adapter4.viewholder.QuickViewHolder
|
||||
import com.sw.inbound.databinding.ListItemSelfProcurementBinding
|
||||
import com.sw.inbound.ext.toSafeDouble
|
||||
import com.sw.inbound.model.response.GoodsInfo
|
||||
import com.sw.inbound.utils.ext.dp
|
||||
import com.sw.inbound.utils.ext.gone
|
||||
import com.sw.inbound.utils.ext.ifNullOrBlank
|
||||
import com.sw.inbound.utils.ext.ifNullOrZero
|
||||
import com.sw.inbound.utils.ext.hideKeyboard
|
||||
import com.sw.inbound.utils.ext.roundedDecimalPlace
|
||||
import com.sw.inbound.utils.ext.setShapeDrawable
|
||||
import com.sw.inbound.utils.ext.toast
|
||||
import com.sw.inbound.utils.ext.visible
|
||||
import com.sw.inbound.utils.removeTrailingZeros
|
||||
|
||||
class SelfProcurementAdapter(var list: MutableList<GoodsInfo>) :
|
||||
BaseQuickAdapter<GoodsInfo, SelfProcurementAdapter.VH>(list) {
|
||||
@@ -41,19 +47,79 @@ class SelfProcurementAdapter(var list: MutableList<GoodsInfo>) :
|
||||
solidColor = if (item!!.isSelected) "#FFD5E1FF" else "#FFFFFFFF",
|
||||
radius = 6.dp
|
||||
)
|
||||
root.setOnClickListener {
|
||||
it.hideKeyboard()
|
||||
}
|
||||
updateTextView(
|
||||
tvGoodsName, tvProcurementUnit,
|
||||
tvProcurementCount, tvProcurementPrice,
|
||||
tvProcurementAmount
|
||||
tvGoodsName, tvGoodsUnit,
|
||||
etGoodsCount, tvGoodsWeight, tvGoodsPrice,
|
||||
etGoodsAmount
|
||||
)
|
||||
tvGoodsName.text = item.goodName.ifNullOrBlank("-")
|
||||
tvProcurementUnit.text = item.unitName.ifNullOrBlank("-")
|
||||
tvProcurementCount.text = item.goodsCount.ifNullOrZero("-")
|
||||
tvProcurementPrice.text = item.goodsUnitPrice.toSafeDouble(2).ifNullOrZero("-")
|
||||
tvProcurementAmount.text = item.goodsPrice.toSafeDouble(2).ifNullOrZero("-")
|
||||
tvGoodsName.text = item.goodName
|
||||
tvGoodsUnit.text = item.unitName
|
||||
if (item.unitHint.isNullOrBlank().not()) {
|
||||
unitDivider.visible()
|
||||
tvUnitHint.run {
|
||||
visible()
|
||||
text = item.unitHint?.replace(",", "\n")
|
||||
}
|
||||
}
|
||||
etGoodsCount.run {
|
||||
updateLayoutParams<LinearLayout.LayoutParams> {
|
||||
topMargin = 20.dp
|
||||
bottomMargin = 20.dp
|
||||
}
|
||||
setShapeDrawable(strokeColor = "#FFDCDCF0", strokeWidth = 2.dp, radius = 8.dp)
|
||||
isEnabled = true
|
||||
setText(item.goodsCount?.removeTrailingZeros())
|
||||
val unit = item.unitName
|
||||
inputType = if (unit == "千克" || unit == "公斤" || unit == "斤") {
|
||||
InputType.TYPE_CLASS_NUMBER or InputType.TYPE_NUMBER_FLAG_DECIMAL
|
||||
} else {
|
||||
InputType.TYPE_CLASS_NUMBER
|
||||
}
|
||||
if (isEnabled) {
|
||||
setSelection(length())
|
||||
}
|
||||
}
|
||||
tvGoodsWeight.text = item.goodsWeight?.toDouble()?.removeTrailingZeros()
|
||||
tvGoodsPrice.text = "${item.goodsUnitPrice?.roundedDecimalPlace(2)}"
|
||||
etGoodsAmount.run {
|
||||
updateLayoutParams<LinearLayout.LayoutParams> {
|
||||
topMargin = 20.dp
|
||||
bottomMargin = 20.dp
|
||||
}
|
||||
setShapeDrawable(strokeColor = "#FFDCDCF0", strokeWidth = 2.dp, radius = 6.dp)
|
||||
isEnabled = true
|
||||
setText(item.goodsPrice?.removeTrailingZeros())
|
||||
if (isEnabled) {
|
||||
setSelection(length())
|
||||
}
|
||||
}
|
||||
|
||||
tvState.gone()
|
||||
ivState.visible()
|
||||
|
||||
addEditListener(etGoodsCount) {
|
||||
if (it == 0.toDouble()) {
|
||||
context.toast("数量不能为0")
|
||||
etGoodsCount.setText(item.goodsCount?.removeTrailingZeros())
|
||||
return@addEditListener
|
||||
}
|
||||
item.goodsCount = it
|
||||
item.goodsUnitPrice = item.goodsPrice!! / it
|
||||
tvGoodsPrice.text = "${item.goodsUnitPrice?.roundedDecimalPlace(2)}"
|
||||
}
|
||||
addEditListener(etGoodsAmount) {
|
||||
if (it == 0.toDouble()) {
|
||||
context.toast("金额不能为0")
|
||||
etGoodsAmount.setText(item.goodsPrice?.removeTrailingZeros())
|
||||
return@addEditListener
|
||||
}
|
||||
item.goodsPrice = it
|
||||
item.goodsUnitPrice = it / item.goodsCount!!
|
||||
tvGoodsPrice.text = "${item.goodsUnitPrice?.roundedDecimalPlace(2)}"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,4 +130,31 @@ class SelfProcurementAdapter(var list: MutableList<GoodsInfo>) :
|
||||
}
|
||||
}
|
||||
|
||||
private fun addEditListener(editText: EditText, action: (Double) -> Unit) {
|
||||
editText.run {
|
||||
addTextChangedListener(onTextChanged = { it, _, _, _ ->
|
||||
try {
|
||||
if (editText.isFocused.not()) {
|
||||
return@addTextChangedListener
|
||||
}
|
||||
val input = it.toString()
|
||||
if (input.startsWith(".")) {
|
||||
setText("0.")
|
||||
setSelection(length())
|
||||
} else if (input.contains(".")) {
|
||||
val index = input.indexOf(".")
|
||||
if (input.length - index > 3) {
|
||||
setText(input.substring(0, index + 3))
|
||||
setSelection(length())
|
||||
}
|
||||
}
|
||||
val value = if (input == "0.") 0.0 else input.toDouble()
|
||||
action(value)
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,7 +5,6 @@ import android.content.Context
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import coil.load
|
||||
import com.sw.inbound.activity.GoodsListActivity
|
||||
import com.sw.inbound.adapter.RecognizeAdapter
|
||||
import com.sw.inbound.databinding.DialogGoodsRecognizeBinding
|
||||
@@ -19,6 +18,7 @@ class GoodsRecognizeDialog(
|
||||
var goodsFile: File?=null,
|
||||
var goodsName: String?=null,
|
||||
var list: MutableList<SearchGoodsInfo.Record>,
|
||||
//var closeCallback:()->Unit,
|
||||
var findGoods: () -> Unit
|
||||
) : BaseDialog(context) {
|
||||
|
||||
@@ -41,9 +41,7 @@ class GoodsRecognizeDialog(
|
||||
isStateViewEnable = true
|
||||
setOnItemClickListener { adapter, view, position ->
|
||||
if (list[position].isSelected) {
|
||||
GoodsStoreDialog(context, list[position]) {
|
||||
activity?.addGoods(it)
|
||||
}.show()
|
||||
showGoodsStoreDialog(position)
|
||||
return@setOnItemClickListener
|
||||
}
|
||||
list.forEach { item ->
|
||||
@@ -51,13 +49,19 @@ class GoodsRecognizeDialog(
|
||||
}
|
||||
list[position].isSelected = true
|
||||
notifyDataSetChanged()
|
||||
GoodsStoreDialog(context, list[position]) {
|
||||
activity?.addGoods(it)
|
||||
}.show()
|
||||
showGoodsStoreDialog(position)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun showGoodsStoreDialog(position: Int) {
|
||||
GoodsStoreDialog(context, list[position]) {
|
||||
activity?.addGoods(it)
|
||||
activity?.startTime = System.currentTimeMillis()
|
||||
dismiss()
|
||||
}.show()
|
||||
}
|
||||
|
||||
private var activity: GoodsListActivity? = null
|
||||
override fun initView() {
|
||||
activity = getReceiptActivity()
|
||||
@@ -68,7 +72,12 @@ class GoodsRecognizeDialog(
|
||||
if (recognizeAdapter.list.isEmpty()) {
|
||||
loadEmptyView()
|
||||
}
|
||||
binding.ivClose.setOnClickListener { dismiss() }
|
||||
binding.ivClose.setOnClickListener {
|
||||
dismiss()
|
||||
activity?.isShowRecognizeDialog = true
|
||||
activity?.goodsRecognizeDialog = null
|
||||
activity?.startTime = System.currentTimeMillis()
|
||||
}
|
||||
binding.btnManuallyFind.setOnClickListener {
|
||||
findGoods()
|
||||
//dismiss()
|
||||
|
||||
@@ -65,6 +65,9 @@ class GoodsSearchDialog(
|
||||
}
|
||||
GoodsStoreDialog(context, list[clickIndex]) {
|
||||
activity?.addGoods(it)
|
||||
activity?.startTime = System.currentTimeMillis()
|
||||
activity?.goodsRecognizeDialog?.dismiss()
|
||||
dismiss()
|
||||
}.show()
|
||||
}
|
||||
binding.rvSearch.let {
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.sw.inbound.dialog
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Typeface
|
||||
import android.text.InputType
|
||||
import android.text.SpannableStringBuilder
|
||||
import android.text.style.ForegroundColorSpan
|
||||
import android.text.style.StyleSpan
|
||||
@@ -21,8 +22,11 @@ import com.sw.inbound.model.response.GoodsInfo
|
||||
import com.sw.inbound.model.response.SearchGoodsInfo
|
||||
import com.sw.inbound.sdk.SensorScaleUtils
|
||||
import com.sw.inbound.utils.ext.dp
|
||||
import com.sw.inbound.utils.ext.roundedDecimalPlace
|
||||
import com.sw.inbound.utils.ext.toast
|
||||
import com.sw.inbound.utils.removeTrailingZeros
|
||||
import kotlin.Int
|
||||
import kotlin.math.abs
|
||||
import kotlin.math.min
|
||||
|
||||
class GoodsStoreDialog(
|
||||
@@ -47,23 +51,6 @@ class GoodsStoreDialog(
|
||||
private var activity: GoodsListActivity? = null
|
||||
override fun initView() {
|
||||
activity = getReceiptActivity()
|
||||
activity?.readWeightInfo { weight ->
|
||||
this.realWeight = weight
|
||||
binding.tvTotalWeight.text = getSpannable(weight)
|
||||
val id = binding.tvProcurementUnit.tag.toString()
|
||||
val count = getUnitVo(id)
|
||||
if (count == 0.toDouble()) {
|
||||
return@readWeightInfo
|
||||
}
|
||||
val currentCount = binding.etProcurementCount.text.toString().trim()
|
||||
if (currentCount == "$count") {
|
||||
return@readWeightInfo
|
||||
}
|
||||
binding.etProcurementCount.let {
|
||||
it.setText("$count")
|
||||
it.setSelection(it.length())
|
||||
}
|
||||
}
|
||||
if (goods.unitVoList.isNullOrEmpty()) {
|
||||
activity?.toast("未匹配到合适的入库单位")
|
||||
dismiss()
|
||||
@@ -73,6 +60,7 @@ class GoodsStoreDialog(
|
||||
goods.unitVoList!!.forEach {
|
||||
dropdownList.add(DictType(id = it.businessUnitId, value = it.purchaseUnitName))
|
||||
}
|
||||
//binding.etProcurementCount.isEnabled = false
|
||||
binding.etGoodsName.run {
|
||||
setText(goods.goodsName)
|
||||
isEnabled = false
|
||||
@@ -96,25 +84,38 @@ class GoodsStoreDialog(
|
||||
popWidth = 428.dp,
|
||||
popHeight = min(dropdownList.size, 4) * 71.dp
|
||||
) { dictType ->
|
||||
binding.tvProcurementUnit.run {
|
||||
text = dictType.value
|
||||
tag = dictType.id
|
||||
}
|
||||
binding.tvCountUnit.text = dictType.value
|
||||
val first = goods.unitVoList!!.first { it.businessUnitId == dictType.id }
|
||||
val stringBuilder = StringBuilder()
|
||||
.append("1").append(dictType.value).append("=").append(first.purchaseValue!!.toInt().toString()).append(goods.kcUnitName)
|
||||
.append(",")
|
||||
.append("1").append(goods.kcUnitName).append("=").append(first.consumeValue).append("克")
|
||||
binding.tvUnitCalculate.text = stringBuilder.toString()
|
||||
val count = getUnitVo(dictType.id!!)
|
||||
if (count == 0.toDouble()) {
|
||||
//context.toast("入库数量不能为0")
|
||||
return@DropdownPopup
|
||||
}
|
||||
binding.etProcurementCount.let {
|
||||
it.setText("$count")
|
||||
it.setSelection(it.length())
|
||||
try {
|
||||
binding.tvProcurementUnit.run {
|
||||
text = dictType.value
|
||||
tag = dictType.id
|
||||
}
|
||||
val unit = dictType.value
|
||||
binding.tvCountUnit.text = unit
|
||||
binding.etProcurementCount.let {
|
||||
//it.isEnabled = true
|
||||
it.inputType = if (unit == "千克" || unit == "公斤" || unit == "斤") {
|
||||
InputType.TYPE_CLASS_NUMBER or InputType.TYPE_NUMBER_FLAG_DECIMAL
|
||||
} else {
|
||||
InputType.TYPE_CLASS_NUMBER
|
||||
}
|
||||
}
|
||||
val first = goods.unitVoList!!.first { it.businessUnitId == dictType.id }
|
||||
val stringBuilder = StringBuilder()
|
||||
.append("1").append(dictType.value).append("=").append(first.purchaseValue!!.toInt().toString()).append(goods.kcUnitName)
|
||||
.append(",")
|
||||
.append("1").append(goods.kcUnitName).append("=").append(first.consumeValue).append("克")
|
||||
binding.tvUnitCalculate.text = stringBuilder.toString()
|
||||
//val count = getUnitCount(dictType.id!!)
|
||||
//if (count.isBlank() || "0" == count) {
|
||||
// //context.toast("入库数量不能为0")
|
||||
// return@DropdownPopup
|
||||
//}
|
||||
//binding.etProcurementCount.let {
|
||||
// it.setText(count)
|
||||
// it.setSelection(it.length())
|
||||
//}
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -136,43 +137,76 @@ class GoodsStoreDialog(
|
||||
//context.toast("入库数量不能为0")
|
||||
return@addPriceInputListener
|
||||
}
|
||||
val price = (it / count).toFormattedString(2)
|
||||
binding.tvProcurementPrice.text = price
|
||||
val price = (it / count).roundedDecimalPlace(2)
|
||||
binding.tvProcurementPrice.text = price.removeTrailingZeros()
|
||||
}
|
||||
binding.etProcurementCount.run {
|
||||
addTextChangedListener(onTextChanged = { it, _, _, _ ->
|
||||
try {
|
||||
if (isFocused.not()) {
|
||||
if (it.isNullOrBlank()) {
|
||||
if (it.isNullOrBlank()) {
|
||||
binding.tvProcurementPrice.text = ""
|
||||
}
|
||||
return@addTextChangedListener
|
||||
}
|
||||
val amountText = binding.etProcurementAmount.text.toString().trim()
|
||||
if (amountText.isEmpty()) {
|
||||
if (amountText.isBlank()) {
|
||||
return@addTextChangedListener
|
||||
}
|
||||
val input = it?.toString() ?: ""
|
||||
val count = if (input.isNotBlank()) input.toDouble() else 0.toDouble()
|
||||
val input = it.toString()
|
||||
val count = input.toDouble()
|
||||
if (count == 0.toDouble()) {
|
||||
//context.toast("入库数量不能为0")
|
||||
return@addTextChangedListener
|
||||
}
|
||||
val amount = amountText.toDouble()
|
||||
val price = amount / count
|
||||
binding.tvProcurementPrice.text = price.toFormattedString(2)
|
||||
val price = (amount / count).roundedDecimalPlace(2)
|
||||
binding.tvProcurementPrice.text = price.removeTrailingZeros()
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
})
|
||||
}
|
||||
addWeightListener()
|
||||
}
|
||||
|
||||
private fun addWeightListener() {
|
||||
activity?.readWeightInfo { weight ->
|
||||
if (abs(this.realWeight - weight) < 10 && binding.etProcurementCount.text.isNotBlank()) {
|
||||
//两次数据差在10克内,认为无变化,不进行操作
|
||||
return@readWeightInfo
|
||||
}
|
||||
this.realWeight = weight
|
||||
binding.tvTotalWeight.text = getSpannable(weight)
|
||||
if (binding.etProcurementCount.isFocused) {
|
||||
return@readWeightInfo
|
||||
}
|
||||
val unitTag = binding.tvProcurementUnit.tag
|
||||
if (unitTag == null) {
|
||||
return@readWeightInfo
|
||||
}
|
||||
val id = unitTag.toString()
|
||||
val count = getUnitCount(id)
|
||||
val currentCount = binding.etProcurementCount.text.toString().trim()
|
||||
if (currentCount == count || count.isBlank() || "0" == count) {
|
||||
return@readWeightInfo
|
||||
}
|
||||
binding.etProcurementCount.let {
|
||||
it.setText(count)
|
||||
it.setSelection(it.length())
|
||||
//it.isEnabled = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun addPriceInputListener(editText: EditText, action: (Double) -> Unit) {
|
||||
editText.run {
|
||||
addTextChangedListener(onTextChanged = { it, _, _, _ ->
|
||||
try {
|
||||
if (editText.isFocused.not()) {
|
||||
if (it.isNullOrBlank()) {
|
||||
return@addTextChangedListener
|
||||
}
|
||||
val input = it ?: ""
|
||||
val input = it.toString()
|
||||
if (input.startsWith(".")) {
|
||||
setText("0.")
|
||||
setSelection(length())
|
||||
@@ -183,7 +217,7 @@ class GoodsStoreDialog(
|
||||
setSelection(length())
|
||||
}
|
||||
}
|
||||
val value = if (input.toString() == "0.") 0.0 else input.toString().toDouble()
|
||||
val value = if (input == "0.") 0.0 else input.toDouble()
|
||||
action(value)
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
@@ -214,7 +248,7 @@ class GoodsStoreDialog(
|
||||
return
|
||||
}
|
||||
val countText = binding.etProcurementCount.text.trim().toString()
|
||||
if (countText.isBlank()) {
|
||||
if (countText.isBlank() || "0" == countText) {
|
||||
context.toast("请录入入库数量")
|
||||
return
|
||||
}
|
||||
@@ -247,6 +281,8 @@ class GoodsStoreDialog(
|
||||
context.toast("入库金额不能为0")
|
||||
return
|
||||
}
|
||||
val id = binding.tvProcurementUnit.tag.toString()
|
||||
val unitVo = goods.unitVoList!!.first { it.businessUnitId == id }
|
||||
confirmBlock(
|
||||
GoodsInfo(
|
||||
goodId = goods.id,
|
||||
@@ -255,8 +291,11 @@ class GoodsStoreDialog(
|
||||
//goodsPurId = binding.tvProcurementUnit.tag.toString(),
|
||||
kcUnitId = binding.tvProcurementUnit.tag.toString(),
|
||||
unitName = unit,
|
||||
//收货接口-数量
|
||||
receivedNum = count,
|
||||
//收货接口-单价(含税)
|
||||
recUnitPriceTaxIn = price,
|
||||
//收货接口-金额(含税)
|
||||
recPriceInItem = totalPrice,
|
||||
goodsWeight = realWeight.toBigDecimal(),
|
||||
isLocalGoods = true,
|
||||
@@ -264,14 +303,17 @@ class GoodsStoreDialog(
|
||||
goodsCount = count,
|
||||
goodsUnitPrice = price,
|
||||
goodsPrice = totalPrice,
|
||||
buyToInventoryValue = unitVo.buyToInventoryValue,
|
||||
|
||||
unitHint = binding.tvUnitCalculate.text.toString()
|
||||
)
|
||||
)
|
||||
dismiss()
|
||||
}
|
||||
|
||||
private fun getUnitVo(id: String): Double {
|
||||
private fun getUnitCount(id: String): String {
|
||||
val first = goods.unitVoList!!.first { it.businessUnitId == id }
|
||||
val count = first.getPurchaseUnitValue(this.realWeight)
|
||||
val count = first.getPurchaseUnitValue( this.realWeight)
|
||||
return count
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.sw.inbound.dialog
|
||||
|
||||
import android.content.Context
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import com.sw.inbound.databinding.DialogNotReceiptWarnBinding
|
||||
import com.sw.inbound.databinding.DialogWarnBinding
|
||||
import com.sw.inbound.utils.ext.dp
|
||||
|
||||
class WarnDialog(
|
||||
context: Context,
|
||||
var content:String,
|
||||
var cancelBlock: () -> Unit = {},
|
||||
var confirmBlock: () -> Unit = {},
|
||||
) : BaseDialog(context = context, defWidth = 960.dp, defHeight = 540.dp) {
|
||||
|
||||
private lateinit var binding: DialogWarnBinding
|
||||
override fun getRootView(): View {
|
||||
val inflater = LayoutInflater.from(context)
|
||||
binding = DialogWarnBinding.inflate(inflater)
|
||||
return binding.root
|
||||
}
|
||||
|
||||
override fun initView() {
|
||||
binding.tvWarnContent.text = content
|
||||
binding.btnCancel.setOnClickListener {
|
||||
cancelBlock()
|
||||
dismiss()
|
||||
}
|
||||
binding.btnConfirm.setOnClickListener {
|
||||
confirmBlock()
|
||||
dismiss()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -29,7 +29,7 @@ data class GoodsInfo(
|
||||
* 单价
|
||||
*/
|
||||
var recUnitPriceTaxIn: Double? = null,
|
||||
var recUnitPriceTaxIn2: Double? = null,
|
||||
var recUnitPriceTaxInBak: Double? = null,
|
||||
|
||||
// 单价 界面显示
|
||||
var recUnitPriceTaxInTemp: String = "",
|
||||
@@ -44,6 +44,7 @@ data class GoodsInfo(
|
||||
* 单位名称
|
||||
*/
|
||||
var unitName: String? = null,
|
||||
var unitNameBak: String? = null,
|
||||
|
||||
/**
|
||||
* 采购单位id
|
||||
@@ -88,6 +89,7 @@ data class GoodsInfo(
|
||||
|
||||
// 收货数量 收货入参
|
||||
var receivedNum: Double? = null,
|
||||
var receivedNumBak: Double? = null,
|
||||
var receiveCountAll: Double? = null,
|
||||
// 收货数量显示
|
||||
var receivedNumTemp: String = "",
|
||||
@@ -107,7 +109,11 @@ data class GoodsInfo(
|
||||
var recPriceInItem:Double?=null,
|
||||
var goodsCount:Double?=null,
|
||||
var goodsUnitPrice:Double?=null,
|
||||
var goodsPrice:Double?=null
|
||||
var goodsPrice:Double?=null,
|
||||
|
||||
var unitHint:String?="",
|
||||
var buyToInventoryValue:String?="",
|
||||
|
||||
//--------------------------------------------------------
|
||||
) : Parcelable, BaseBean() {
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ package com.sw.inbound.model.response
|
||||
import android.os.Parcelable
|
||||
import com.google.gson.annotations.SerializedName
|
||||
import com.sw.inbound.utils.ext.roundedDecimalPlace
|
||||
import com.sw.inbound.utils.removeTrailingZeros
|
||||
import kotlinx.parcelize.IgnoredOnParcel
|
||||
import kotlinx.parcelize.Parcelize
|
||||
|
||||
@@ -122,7 +123,7 @@ data class SearchGoodsInfo(
|
||||
/**
|
||||
* 购买单位数值
|
||||
*/
|
||||
fun getPurchaseUnitValue(value: Int): Double {
|
||||
fun getPurchaseUnitValue(value: Int): String {
|
||||
val defZero = 0.toDouble()
|
||||
val num = when (purchaseUnitName) {
|
||||
"千克", "公斤" -> 2
|
||||
@@ -130,16 +131,17 @@ data class SearchGoodsInfo(
|
||||
else -> 0
|
||||
}
|
||||
if (purchaseValue == null || purchaseValue == defZero || consumeValue.isNullOrBlank()) {
|
||||
return defZero.roundedDecimalPlace(num)
|
||||
return ""
|
||||
}
|
||||
var consumeValueDouble: Double
|
||||
try {
|
||||
consumeValueDouble = consumeValue.toDouble()
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
return defZero.roundedDecimalPlace(num)
|
||||
return ""
|
||||
}
|
||||
return (value / purchaseValue / consumeValueDouble).roundedDecimalPlace(num)
|
||||
val count = (value / purchaseValue / consumeValueDouble).roundedDecimalPlace(num)
|
||||
return count.removeTrailingZeros()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,8 +17,8 @@ class RequestInterceptor : Interceptor {
|
||||
.header("Content-Type", "application/json")
|
||||
.header("Accept", "application/json")
|
||||
.header("deviceId", GlobalData.deviceId)
|
||||
.header("X-DEVICE-CODE", GlobalData.deviceId)
|
||||
// .header("X-DEVICE-CODE", "bcf396ed-78f6-3864-9837-7c37c5b2ec41")
|
||||
// .header("X-DEVICE-CODE", GlobalData.deviceId)
|
||||
.header("X-DEVICE-CODE", "bcf396ed-78f6-3864-9837-7c37c5b2ec41")
|
||||
.header("x-access-token", GlobalData.appToken)
|
||||
.header("authorization", "57ee87183f2a4fa59683ec9ef41c8f5d")
|
||||
// .header("Authorization", "Bearer ${getToken()}")
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.sw.inbound.sdk
|
||||
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import com.sw.inbound.utils.ThreadUtils
|
||||
import com.sw.inbound.utils.ToastUtils
|
||||
import com.wabon.wbintelligenthardwaresdk.api.SensorScale
|
||||
@@ -26,14 +28,18 @@ object SensorScaleUtils {
|
||||
* 读取重量
|
||||
*/
|
||||
override fun readWeight(state: Int, value: Double) {
|
||||
val stateStr = when (state) {
|
||||
SensorScale.STATE_STABLE -> "稳定"
|
||||
SensorScale.STATE_UNSTABLE -> "不稳定"
|
||||
SensorScale.STATE_OVER_WEIGHT -> "量程溢出"
|
||||
else -> "未知"
|
||||
//val stateStr = when (state) {
|
||||
// SensorScale.STATE_STABLE -> "稳定"
|
||||
// SensorScale.STATE_UNSTABLE -> "不稳定"
|
||||
// SensorScale.STATE_OVER_WEIGHT -> "量程溢出"
|
||||
// else -> "未知"
|
||||
//}
|
||||
if (state != SensorScale.STATE_STABLE) {
|
||||
return
|
||||
}
|
||||
Handler(Looper.getMainLooper()).post {
|
||||
weightCallback?.invoke((value * 1000).toInt())
|
||||
}
|
||||
|
||||
weightCallback?.invoke((value * 1000).toInt())
|
||||
//Timber.d("readWeight state = ${stateStr}, weight = $value")
|
||||
// 只使用稳定值
|
||||
// if (state == SensorScale.STATE_STABLE) {
|
||||
|
||||
@@ -107,8 +107,6 @@ fun HomeScreen(
|
||||
// .build()
|
||||
// )
|
||||
navController.context.startActivity<SelfProcurementActivity> {
|
||||
putExtra(GoodsListActivity.ID, "2342342343")
|
||||
putExtra(GoodsListActivity.SUPPLIER_ID, "23423423424234")
|
||||
putExtra(GoodsListActivity.IS_RECEIPT_PAGE, false)
|
||||
}
|
||||
},
|
||||
|
||||
@@ -190,7 +190,8 @@ fun PurchaseOrderScreen(
|
||||
navController.popBackStack()
|
||||
}, onRight2ButtonClick = {
|
||||
//navController.navigate(Screen.SelfProcurement.route)
|
||||
navController.context.startActivity<SelfProcurementActivity> {}
|
||||
navController.context.startActivity<SelfProcurementActivity> {
|
||||
putExtra(GoodsListActivity.IS_RECEIPT_PAGE, false)}
|
||||
//navController.context.startActivity<ReceiptActivity> {
|
||||
// //xtra(GoodsListActivity.ID,it!!.id)
|
||||
// //xtra(GoodsListActivity.SUPPLIER_ID,it.supplierId)
|
||||
|
||||
@@ -21,6 +21,9 @@ class CameraUtils(private var activity: ComponentActivity) {
|
||||
}
|
||||
photoCaptureHelper?.let {
|
||||
it.addSuccessCallback(callback)
|
||||
it.bindCameraCallback {
|
||||
bind()
|
||||
}
|
||||
it.takePhoto()
|
||||
}
|
||||
}
|
||||
@@ -52,7 +55,7 @@ class CameraUtils(private var activity: ComponentActivity) {
|
||||
)
|
||||
cameraSelector = CameraSelector.DEFAULT_BACK_CAMERA
|
||||
}
|
||||
//cameraController?.bindToLifecycle(activity)
|
||||
bind()
|
||||
}
|
||||
|
||||
// if (isCameraReady.not()) {
|
||||
|
||||
@@ -0,0 +1,105 @@
|
||||
package com.sw.inbound.utils;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.sw.inbound.MyApp;
|
||||
import com.sw.inbound.R;
|
||||
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
|
||||
/**
|
||||
* The type Toast utils.
|
||||
*/
|
||||
public class CustomToastUtils {
|
||||
|
||||
private static Toast toast;
|
||||
@SuppressLint("StaticFieldLeak")
|
||||
private static TextView textCenterView;
|
||||
|
||||
/**
|
||||
* Show center toast.
|
||||
*
|
||||
* @param text the text
|
||||
*/
|
||||
public static void showToast(String text) {
|
||||
Context context = MyApp.Companion.getInstance();
|
||||
if (toast == null) {
|
||||
View view = LayoutInflater.from(context).inflate(R.layout.layout_custom_toast, null);
|
||||
textCenterView = view.findViewById(R.id.toast_tv);
|
||||
toast = new Toast(context);
|
||||
toast.setGravity(Gravity.CENTER, 0, 20);
|
||||
toast.setDuration(Toast.LENGTH_SHORT);
|
||||
toast.setView(view);
|
||||
}
|
||||
|
||||
textCenterView.setText(text);
|
||||
toast.show();
|
||||
}
|
||||
|
||||
/**
|
||||
* Show center toast.
|
||||
*
|
||||
* @param text the text
|
||||
*/
|
||||
public static void showToast(String text, int duration) {
|
||||
Context context = MyApp.Companion.getInstance();
|
||||
if (toast == null) {
|
||||
View view = LayoutInflater.from(context).inflate(R.layout.layout_custom_toast, null);
|
||||
textCenterView = view.findViewById(R.id.toast_tv);
|
||||
toast = new Toast(context);
|
||||
toast.setGravity(Gravity.CENTER, 0, 20);
|
||||
toast.setView(view);
|
||||
}
|
||||
|
||||
textCenterView.setText(text);
|
||||
toast.setDuration(duration);
|
||||
toast.show();
|
||||
}
|
||||
|
||||
public static void showLongToast(String text) {
|
||||
Context context = MyApp.Companion.getInstance();
|
||||
if (toast == null) {
|
||||
View view = LayoutInflater.from(context).inflate(R.layout.layout_custom_toast, null);
|
||||
textCenterView = view.findViewById(R.id.toast_tv);
|
||||
toast = new Toast(context);
|
||||
toast.setGravity(Gravity.TOP, 0, 20);
|
||||
toast.setDuration(Toast.LENGTH_LONG);
|
||||
toast.setView(view);
|
||||
}
|
||||
textCenterView.setText(text);
|
||||
showMyToast(toast, 1000000 * 30);
|
||||
}
|
||||
|
||||
|
||||
//自定义Toast控件
|
||||
private static void showMyToast(final Toast toast, final int cnt) {
|
||||
final Timer timer = new Timer();
|
||||
timer.schedule(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
toast.show();
|
||||
}
|
||||
}, 0, Toast.LENGTH_LONG);
|
||||
new Timer().schedule(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
toast.cancel();
|
||||
timer.cancel();
|
||||
}
|
||||
}, cnt);
|
||||
}
|
||||
|
||||
public static void showSystemToast(String text) {
|
||||
Context context = MyApp.Companion.getInstance();
|
||||
Toast.makeText(context, text, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -32,6 +32,11 @@ class PhotoCaptureHelper(
|
||||
}
|
||||
}
|
||||
|
||||
private var bindCamera:(()->Unit)?=null
|
||||
fun bindCameraCallback(callback:()->Unit) {
|
||||
this.bindCamera = callback
|
||||
}
|
||||
|
||||
/**
|
||||
* 拍照方法
|
||||
* @param fileNamePrefix 文件名前缀,默认为"IMG_"
|
||||
@@ -69,6 +74,13 @@ class PhotoCaptureHelper(
|
||||
|
||||
override fun onError(exception: ImageCaptureException) {
|
||||
val errorMsg = "拍照失败: ${exception.message}"
|
||||
if (errorMsg.contains("Not bound to a valid Camera")) {
|
||||
if (bindCamera != null) {
|
||||
bindCamera?.invoke()
|
||||
takePhoto()
|
||||
}
|
||||
|
||||
}
|
||||
Timber.e(exception, errorMsg)
|
||||
onError(errorMsg)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
package com.sw.inbound.utils
|
||||
/**
|
||||
* 去除小数点后无效零的工具类
|
||||
* 功能示例:
|
||||
* 1230.00 => 1230
|
||||
* 1230.10 => 1230.1
|
||||
* 3.40 => 3.4
|
||||
* 3.0 => 3
|
||||
*/
|
||||
class RemoveZeroUtils {
|
||||
|
||||
companion object {
|
||||
|
||||
/**
|
||||
* 方法1:使用字符串格式化(最简单)
|
||||
* @param number 输入的double数值
|
||||
* @return 去除无效零后的字符串
|
||||
*/
|
||||
fun removeZeroByFormat(number: Double): String {
|
||||
return "%.10f".format(number) // 先格式化为固定小数位
|
||||
.replace(Regex("0*$"), "") // 移除末尾的零
|
||||
.replace(Regex("\\.$"), "") // 如果小数点后全为零,移除小数点
|
||||
}
|
||||
|
||||
/**
|
||||
* 方法2:使用DecimalFormat(推荐)
|
||||
* @param number 输入的double数值
|
||||
* @return 去除无效零后的字符串
|
||||
*/
|
||||
fun removeZeroByDecimalFormat(number: Double): String {
|
||||
val format = java.text.DecimalFormat("0.##########")
|
||||
format.roundingMode = java.math.RoundingMode.FLOOR
|
||||
return format.format(number)
|
||||
}
|
||||
|
||||
/**
|
||||
* 方法3:使用正则表达式处理字符串
|
||||
* @param number 输入的double数值
|
||||
* @return 去除无效零后的字符串
|
||||
*/
|
||||
fun removeZeroByRegex(number: Double): String {
|
||||
var str = number.toString()
|
||||
|
||||
// 如果包含小数点,处理末尾的零
|
||||
if (str.contains(".")) {
|
||||
str = str.replace(Regex("0+?$"), "") // 移除末尾的零
|
||||
.replace(Regex("[.]$"), "") // 如果小数点后全为零,移除小数点
|
||||
}
|
||||
|
||||
return str
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 扩展函数方式,更符合Kotlin风格
|
||||
fun Double?.removeTrailingZeros(): String {
|
||||
if (this == null) return ""
|
||||
return RemoveZeroUtils.removeZeroByDecimalFormat(this)
|
||||
}
|
||||
@@ -22,6 +22,7 @@ import androidx.core.graphics.toColorInt
|
||||
import androidx.fragment.app.Fragment
|
||||
import com.google.gson.Gson
|
||||
import com.google.gson.reflect.TypeToken
|
||||
import com.sw.inbound.utils.CustomToastUtils
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.Job
|
||||
@@ -38,7 +39,8 @@ fun Context.toast(
|
||||
return
|
||||
}
|
||||
Handler(Looper.getMainLooper()).post {
|
||||
Toast.makeText(this, message, duration).show()
|
||||
//Toast.makeText(this, message, duration).show()
|
||||
CustomToastUtils.showToast(message, duration)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user