|
|
@@ -3,11 +3,13 @@ package cn.muchinfo.rma.view.base.main.castsurely
|
|
|
import android.graphics.Color
|
|
|
import android.os.Bundle
|
|
|
import android.view.Gravity
|
|
|
+import android.view.View
|
|
|
import android.view.inputmethod.EditorInfo
|
|
|
import android.widget.EditText
|
|
|
import androidx.lifecycle.MutableLiveData
|
|
|
import cn.muchinfo.rma.R
|
|
|
import cn.muchinfo.rma.global.GlobalDataCollection
|
|
|
+import cn.muchinfo.rma.global.data.RStrategyData
|
|
|
import cn.muchinfo.rma.global.data.account.loginQeruy.GoodsInfo
|
|
|
import cn.muchinfo.rma.global.database.DataBase
|
|
|
import cn.muchinfo.rma.lifecycle.bindOptional
|
|
|
@@ -55,6 +57,9 @@ class AddCastSurelyActivity : BaseActivity<MyCastSurelyViewModel>() {
|
|
|
intent.getStringExtra("outGoodsCode")
|
|
|
}
|
|
|
|
|
|
+ //用于修改定投
|
|
|
+ val data by lazy { intent.getParcelableExtra<RStrategyData>("data") as RStrategyData }
|
|
|
+
|
|
|
//选择的交易类型 金额或者数量
|
|
|
val selectPayType: MutableLiveData<SelectData> = MutableLiveData()
|
|
|
|
|
|
@@ -69,7 +74,7 @@ class AddCastSurelyActivity : BaseActivity<MyCastSurelyViewModel>() {
|
|
|
*/
|
|
|
val selectTime: MutableLiveData<SelectData> = MutableLiveData()
|
|
|
|
|
|
- // 1是新增 2是修改
|
|
|
+ // 1定投列表进入是新增 2是修改 3 是从其他地方进入的定投(这里需要再次请求定投列表用于判断此商品是否存在正在进行的定投策略)
|
|
|
val type by lazy { intent.getStringExtra("type") }
|
|
|
|
|
|
//行情推送通知
|
|
|
@@ -94,7 +99,14 @@ class AddCastSurelyActivity : BaseActivity<MyCastSurelyViewModel>() {
|
|
|
viewModel.goodsInfoData.postValue(
|
|
|
DataBase.getInstance().goodsInfoDao().getGoodsInfo(goodsId?.toInt() ?: 0)
|
|
|
)//获取商品详情
|
|
|
- selectPayType.postValue(SelectData(id = "1", value = "按克数定投"))
|
|
|
+ if (type == "1"){
|
|
|
+ selectPayType.postValue(SelectData(id = "1", value = "按重量定投"))
|
|
|
+ }else if (type == "2"){
|
|
|
+ selectPayType.postValue(SelectData(id = data.regularlymode ?: "1", value = if (data.regularlymode == "1"){"按重量定投"}else{"按金额定投"}))
|
|
|
+ selectTime.postValue(SelectData(id = data.regularlycycle ?: "1",value = data.regularlycyclevalue ?: "1"))
|
|
|
+ }else if (type == "3"){
|
|
|
+ viewModel.queryMyRStrategy(goodsid = goodsId ?: "0")
|
|
|
+ }
|
|
|
viewModel.queryGoodsEx(goodsId ?: "")
|
|
|
viewModel.queryQuoteDay(
|
|
|
tag = thisTag,
|
|
|
@@ -114,6 +126,10 @@ class AddCastSurelyActivity : BaseActivity<MyCastSurelyViewModel>() {
|
|
|
EventBus.getDefault().register(this)
|
|
|
verticalLayout {
|
|
|
initData()
|
|
|
+ viewModel.isCastSureData.bindOptional(context){//从交易页面进入的定投页,若是针对此商品已进行了定投策略,则该页面为修改定投,并在此进行赋值
|
|
|
+ selectPayType.postValue(SelectData(id = it?.regularlymode ?: "1", value = if (it?.regularlymode == "1"){"按重量定投"}else{"按金额定投"}))
|
|
|
+ selectTime.postValue(SelectData(id = it?.regularlycycle ?: "1",value = it?.regularlycyclevalue ?: "1"))
|
|
|
+ }
|
|
|
createLoadingDialog(hintStr = "请求中...").bindTaskStatus(
|
|
|
context,
|
|
|
viewModel.loadingDialogStatus
|
|
|
@@ -122,12 +138,26 @@ class AddCastSurelyActivity : BaseActivity<MyCastSurelyViewModel>() {
|
|
|
topBar {
|
|
|
commonLeftButton()
|
|
|
commonTitle {
|
|
|
- text = "新增定投"
|
|
|
+ if (type == "1"){
|
|
|
+ text = "新增定投"
|
|
|
+ }else if (type == "2"){
|
|
|
+ text = "修改定投"
|
|
|
+ }else {
|
|
|
+ text = "新增定投"
|
|
|
+ }
|
|
|
+ viewModel.isCastSureData.bindOptional(context){
|
|
|
+ if (it?.goodsid.isNullOrEmpty().not()){
|
|
|
+ text = "修改定投"
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
linearLayout {
|
|
|
onThrottleFirstClick {
|
|
|
+ if (type == "2" || viewModel.isCastSureData.value?.goodsid.isNullOrEmpty().not()){
|
|
|
+ return@onThrottleFirstClick
|
|
|
+ }
|
|
|
val selectGoodsInfoList = arrayListOf<GoodsInfo>()
|
|
|
val goodsInfoList = DataBase.getInstance().goodsInfoDao().all
|
|
|
goodsInfoList.forEach {
|
|
|
@@ -135,7 +165,7 @@ class AddCastSurelyActivity : BaseActivity<MyCastSurelyViewModel>() {
|
|
|
selectGoodsInfoList.add(it)
|
|
|
}
|
|
|
}
|
|
|
- creatGoodsInfoBottomSheetDialog("请选择的商品", selectGoodsInfoList) {
|
|
|
+ creatGoodsInfoBottomSheetDialog("请选择的商品", viewModel.getCanAddCastSureList()) {
|
|
|
viewModel.goodsInfoData.postValue(this)
|
|
|
viewModel.queryGoodsEx(this.goodsid.toString())
|
|
|
viewModel.queryQuoteDay(
|
|
|
@@ -152,6 +182,7 @@ class AddCastSurelyActivity : BaseActivity<MyCastSurelyViewModel>() {
|
|
|
if (it?.goodsname.isNullOrEmpty()){
|
|
|
text = "请选择商品"
|
|
|
}else{
|
|
|
+ visibility = View.VISIBLE
|
|
|
text = it?.goodsname
|
|
|
}
|
|
|
}
|
|
|
@@ -215,6 +246,14 @@ class AddCastSurelyActivity : BaseActivity<MyCastSurelyViewModel>() {
|
|
|
editText {
|
|
|
gravity = Gravity.CENTER_VERTICAL
|
|
|
amount_input = this
|
|
|
+ if (type == "2"){
|
|
|
+ setText(data.regularlymodevalue)
|
|
|
+ }
|
|
|
+ viewModel.isCastSureData.bindOptional(context){
|
|
|
+ if (it?.goodsid.isNullOrEmpty().not()){
|
|
|
+ setText(it?.regularlymodevalue)
|
|
|
+ }
|
|
|
+ }
|
|
|
selectPayType.bindOptional(context) {
|
|
|
if (it?.id == "1") {//按克数定投
|
|
|
hint = "请输入定投克数"
|
|
|
@@ -343,10 +382,40 @@ class AddCastSurelyActivity : BaseActivity<MyCastSurelyViewModel>() {
|
|
|
if (check().not()){
|
|
|
return@onThrottleFirstClick
|
|
|
}
|
|
|
- viewModel.requestQhjRegularlyStrategyReq(goodsID = viewModel.goodsInfoData.value?.goodsid?.toLong() ?: 0,regularlyCycle = selectTime.value?.id?.toInt() ?: 1,regularlyCycleValue = selectTime.value?.value?.toInt() ?: 1,regularlyMode = selectPayType.value?.id?.toInt() ?: 0,
|
|
|
- regularlyModeValue = amount_input.text.toString().toDouble().times(Math.pow(10.0,viewModel.goodsInfoData.value?.qtydecimalplace?.toDouble() ?: 2.0)),operateType = 1){
|
|
|
- viewModel.loadingDialogStatus.postValue(TaskUiModel.success(msg = "新增定投成功"))
|
|
|
- finish()
|
|
|
+ var regularlyModeValue = 0.0
|
|
|
+ var operateType = 0
|
|
|
+ if (selectPayType.value?.id == "1"){//重量
|
|
|
+ regularlyModeValue = amount_input.text.toString().toDouble().times(Math.pow(10.0,viewModel.goodsInfoData.value?.qtydecimalplace?.toDouble() ?: 2.0))
|
|
|
+ }else{//金额
|
|
|
+ regularlyModeValue = amount_input.text.toString().toDouble()
|
|
|
+ }
|
|
|
+
|
|
|
+ if (type == "1"){//新增
|
|
|
+ viewModel.requestQhjRegularlyStrategyReq(goodsID = viewModel.goodsInfoData.value?.goodsid?.toLong() ?: 0,regularlyCycle = selectTime.value?.id?.toInt() ?: 1,regularlyCycleValue = selectTime.value?.value?.toInt() ?: 1,regularlyMode = selectPayType.value?.id?.toInt() ?: 0,
|
|
|
+ regularlyModeValue = regularlyModeValue,operateType = 1){
|
|
|
+ viewModel.loadingDialogStatus.postValue(TaskUiModel.success(msg = "新增定投成功"))
|
|
|
+ finish()
|
|
|
+ }
|
|
|
+ }else if (type == "2"){//修改
|
|
|
+ viewModel.requestQhjRegularlyStrategyReq(regularlyStrategyID = data.regularlystrategyid?.toLong() ?: 0,goodsID = viewModel.goodsInfoData.value?.goodsid?.toLong() ?: 0,regularlyCycle = selectTime.value?.id?.toInt() ?: 1,regularlyCycleValue = selectTime.value?.value?.toInt() ?: 1,regularlyMode = selectPayType.value?.id?.toInt() ?: 0,
|
|
|
+ regularlyModeValue = regularlyModeValue,operateType = 2){
|
|
|
+ viewModel.loadingDialogStatus.postValue(TaskUiModel.success(msg = "修改定投成功"))
|
|
|
+ finish()
|
|
|
+ }
|
|
|
+ }else if (type == "3"){
|
|
|
+ if (viewModel.isCastSureData.value?.goodsid.isNullOrEmpty().not()){//修改
|
|
|
+ viewModel.requestQhjRegularlyStrategyReq(regularlyStrategyID = viewModel.isCastSureData.value?.regularlystrategyid?.toLong() ?: 0,goodsID = viewModel.goodsInfoData.value?.goodsid?.toLong() ?: 0,regularlyCycle = selectTime.value?.id?.toInt() ?: 1,regularlyCycleValue = selectTime.value?.value?.toInt() ?: 1,regularlyMode = selectPayType.value?.id?.toInt() ?: 0,
|
|
|
+ regularlyModeValue = regularlyModeValue,operateType = 2){
|
|
|
+ viewModel.loadingDialogStatus.postValue(TaskUiModel.success(msg = "修改定投成功"))
|
|
|
+ finish()
|
|
|
+ }
|
|
|
+ }else{//新增
|
|
|
+ viewModel.requestQhjRegularlyStrategyReq(goodsID = viewModel.goodsInfoData.value?.goodsid?.toLong() ?: 0,regularlyCycle = selectTime.value?.id?.toInt() ?: 1,regularlyCycleValue = selectTime.value?.value?.toInt() ?: 1,regularlyMode = selectPayType.value?.id?.toInt() ?: 0,
|
|
|
+ regularlyModeValue = regularlyModeValue,operateType = 1){
|
|
|
+ viewModel.loadingDialogStatus.postValue(TaskUiModel.success(msg = "新增定投成功"))
|
|
|
+ finish()
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
gravity = Gravity.CENTER
|