Эх сурвалжийг харах

手动物资更换页:修复显示异常、添加tab页数据同步;SelectableInput添加启用/禁用功能;添加手动更换物资接口

Frankensteinly 8 сар өмнө
parent
commit
754f18cc02

+ 21 - 0
app/src/main/java/com/grkj/iscs_mc/model/vo/material/MaterialManualReplacementReqVO.kt

@@ -0,0 +1,21 @@
+package com.grkj.iscs_mc.model.vo.material
+
+data class MaterialManualReplacementReqVO(
+    val oldMaterialsId: Long?,
+
+    val materialsName: String?,
+
+    val materialsTypeId: Long?,
+
+    val propertiesValueId: String?,
+
+    val propertiesValue: String?,
+
+    val propertiesPropertyId: String?,
+
+    val propertiesProperty: String?,
+
+    val materialsRfid: String?,
+
+    val expirationDate: String?
+)

+ 6 - 1
app/src/main/java/com/grkj/iscs_mc/model/vo/replacement/ManualReplacementListRespVO.kt

@@ -78,6 +78,11 @@ data class ManualReplacementListRespVO(
         /**
          * 选择的型号
          */
-        var selectedModelId: Long?
+        var selectedModelId: Long?,
+
+        /**
+         * 是否完成填写
+         */
+        var isDone: Boolean = false
     )
 }

+ 21 - 0
app/src/main/java/com/grkj/iscs_mc/util/NetApi.kt

@@ -16,6 +16,7 @@ import com.grkj.iscs_mc.model.vo.material.MaterialBorrowReturnReqVO
 import com.grkj.iscs_mc.model.vo.material.MaterialDetailRespVO
 import com.grkj.iscs_mc.model.vo.material.MaterialInstructionListRespVO
 import com.grkj.iscs_mc.model.vo.material.MaterialListRespVO
+import com.grkj.iscs_mc.model.vo.material.MaterialManualReplacementReqVO
 import com.grkj.iscs_mc.model.vo.material.MaterialPropertyPageRespVO
 import com.grkj.iscs_mc.model.vo.material.MaterialPropertyValuePageRespVO
 import com.grkj.iscs_mc.model.vo.material.MaterialTypePageRespVO
@@ -1004,4 +1005,24 @@ object NetApi {
             }, isGet = false, isAuth = true
         )
     }
+
+    /**
+     * 手动更换物资
+     */
+    fun manualReplacement(list: MutableList<MaterialManualReplacementReqVO>, callBack: (Boolean) -> Unit) {
+        NetHttpManager.getInstance().doRequestNet(
+            UrlConsts.MANUAL_REPLACEMENT,
+            false,
+            mapOf(
+                "list" to list
+            ),
+            { res, _, _ ->
+                res?.let {
+                    callBack.invoke(true)
+                } ?: run {
+                    callBack.invoke(false)
+                }
+            }, isGet = false, isAuth = true
+        )
+    }
 }

+ 26 - 10
app/src/main/java/com/grkj/iscs_mc/view/fragment/MaterialManualReplacementFragment.kt

@@ -56,15 +56,18 @@ class MaterialManualReplacementFragment :
 
                     // 新
                     val ciName = holder.getView<SelectableInput>(R.id.ci_name_new)
+                    ciName.setEnableStatus(!vo.isDone)
                     ciName.setText(vo.newName)
                     ciName.setOnTextChangeListener(object : SelectableInput.OnTextChangeListener {
                         override fun onTextChange(str: String?) {
                             vo.newName = str
+                            presenter?.syncData(mMaterialList, vo)
                         }
                     })
 
                     // 类型
                     val ciType = holder.getView<SelectableInput>(R.id.ci_type_new)
+                    ciType.setEnableStatus(!vo.isDone)
                     ciType.setOptionList(mTypeList.map { it.materialsTypeName!! }.toMutableList())
                     ciType.setText(mTypeList.find { it.materialsTypeId == vo.selectedTypeId }?.materialsTypeName)
                     ciType.setOnSpinnerSelectListener(object :
@@ -75,11 +78,13 @@ class MaterialManualReplacementFragment :
                             }
                             vo.selectedTypeId = mTypeList[index].materialsTypeId
                             mBinding?.rvReplacement?.adapter?.notifyItemChanged(position)
+                            presenter?.syncData(mMaterialList, vo)
                         }
                     })
 
                     // 型号
                     val ciModel = holder.getView<SelectableInput>(R.id.ci_model_new)
+                    ciModel.setEnableStatus(!vo.isDone)
                     ciModel.setOptionList(mPropertyList
                         .filter {
                             it.propertyId.toString() ==
@@ -92,22 +97,27 @@ class MaterialManualReplacementFragment :
                         SelectableInput.OnSpinnerSelectListener {
                         override fun onSelect(str: String?, index: Int) {
                             vo.selectedModelId = mPropertyList[index].recordId
+                            presenter?.syncData(mMaterialList, vo)
                         }
                     })
 
                     val ciRfid = holder.getView<SelectableInput>(R.id.ci_rfid_new)
+                    ciRfid.setEnableStatus(!vo.isDone)
                     ciRfid.setText(vo.newRfid)
                     ciRfid.setOnTextChangeListener(object : SelectableInput.OnTextChangeListener {
                         override fun onTextChange(str: String?) {
                             vo.newRfid = str
+                            presenter?.syncData(mMaterialList, vo)
                         }
                     })
 
                     val ciDate = holder.getView<SelectableInput>(R.id.ci_date_new)
+                    ciDate.setEnableStatus(!vo.isDone)
                     ciDate.setText(vo.newDate)
                     ciDate.setOnTextChangeListener(object : SelectableInput.OnTextChangeListener {
                         override fun onTextChange(str: String?) {
                             vo.newDate = str
+                            presenter?.syncData(mMaterialList, vo)
                         }
                     })
 
@@ -116,14 +126,18 @@ class MaterialManualReplacementFragment :
                         .into(holder.getView(R.id.iv_new))
 
                     // 按钮
+                    holder.setVisible(R.id.tv_reset, vo.isDone)
                     holder.setOnClickListener(R.id.tv_reset) {
-                        vo.selectedTypeId = vo.materialsTypeId
-                        vo.selectedModelId = vo.propertiesValueId?.toLong()
+                        vo.isDone = false
                         mBinding?.rvReplacement?.adapter?.notifyItemChanged(position)
+                        presenter?.syncData(mMaterialList, vo)
                     }
 
+                    holder.setVisible(R.id.tv_confirm, !vo.isDone)
                     holder.setOnClickListener(R.id.tv_confirm) {
-                        // TODO 确定更换
+                        vo.isDone = true
+                        mBinding?.rvReplacement?.adapter?.notifyItemChanged(position)
+                        presenter?.syncData(mMaterialList, vo)
                     }
                 }
             }
@@ -141,6 +155,15 @@ class MaterialManualReplacementFragment :
         presenter?.getManualReplacementList {
             it?.let {
                 mMaterialList.addAll(it)
+                mMaterialList.forEach {
+                    it.materials?.forEach { itDetail ->
+                        itDetail.newName = itDetail.materialsName
+                        itDetail.newRfid = itDetail.materialsRfid
+                        itDetail.newDate = itDetail.expirationDate
+                        itDetail.selectedTypeId = itDetail.materialsTypeId
+                        itDetail.selectedModelId = itDetail.propertiesValueId?.toLong()
+                    }
+                }
             }
             val list = mutableListOf<ExpandableTabLayout.ItemData>()
             it?.forEach { itData ->
@@ -158,13 +181,6 @@ class MaterialManualReplacementFragment :
                 mMaterialList[0].materials?.let {
                     mDetailList.addAll(it)
                 }
-                mDetailList.forEach {
-                    it.newName = it.materialsName
-                    it.newRfid = it.materialsRfid
-                    it.newDate = it.expirationDate
-                    it.selectedTypeId = it.materialsTypeId
-                    it.selectedModelId = it.propertiesValueId?.toLong()
-                }
             }
             mBinding?.rvReplacement?.adapter?.notifyDataSetChanged()
         }

+ 25 - 0
app/src/main/java/com/grkj/iscs_mc/view/presenter/MaterialManualReplacementPresenter.kt

@@ -1,6 +1,7 @@
 package com.grkj.iscs_mc.view.presenter
 
 import com.grkj.iscs_mc.extentions.serialNo
+import com.grkj.iscs_mc.model.vo.material.MaterialManualReplacementReqVO
 import com.grkj.iscs_mc.model.vo.material.MaterialPropertyValuePageRespVO
 import com.grkj.iscs_mc.model.vo.material.MaterialTypePageRespVO
 import com.grkj.iscs_mc.model.vo.replacement.ManualReplacementListRespVO
@@ -34,4 +35,28 @@ class MaterialManualReplacementPresenter : BasePresenter<IMaterialManualReplacem
             }
         }
     }
+
+    fun manualReplacement(list: MutableList<MaterialManualReplacementReqVO>, callBack: (Boolean) -> Unit) {
+        NetApi.manualReplacement(list) {
+            Executor.runOnMain {
+                callBack(it)
+            }
+        }
+    }
+
+    /**
+     * 同步不同tab标签的数据
+     */
+    fun syncData(list: MutableList<ManualReplacementListRespVO>, material: ManualReplacementListRespVO.MaterialsPageVO) {
+        list.forEach {
+            it.materials?.find { it.materialsId == material.materialsId }?.let { itVO ->
+                itVO.newName = material.newName
+                itVO.newRfid = material.newRfid
+                itVO.newDate = material.newDate
+                itVO.selectedTypeId = material.selectedTypeId
+                itVO.selectedModelId = material.selectedModelId
+                itVO.isDone = material.isDone
+            }
+        }
+    }
 }

+ 30 - 1
app/src/main/java/com/grkj/iscs_mc/view/widget/SelectableInput.kt

@@ -37,6 +37,7 @@ class SelectableInput(private val ctx: Context, attrs: AttributeSet) : LinearLay
     private var mSelectListener: OnSpinnerSelectListener? = null
     private var mTextChangeListener: OnTextChangeListener? = null
     var mSelectIdx: Int? = null
+    private var mMode: Int = MODE_INPUT
 
     init {
         val root = View.inflate(ctx, R.layout.layout_selectable_input, this)
@@ -50,7 +51,7 @@ class SelectableInput(private val ctx: Context, attrs: AttributeSet) : LinearLay
         val isEnabled = attrSet.getBoolean(R.styleable.SelectableInput_enabled, true)
         mBinding.et.isEnabled = isEnabled
 
-        val mode = attrSet.getInt(R.styleable.SelectableInput_mode, 0)
+        val mode = attrSet.getInt(R.styleable.SelectableInput_mode, MODE_INPUT)
         setMode(mode)
 
         mBinding.tvName.text = attrSet.getString(R.styleable.SelectableInput_name)
@@ -64,10 +65,34 @@ class SelectableInput(private val ctx: Context, attrs: AttributeSet) : LinearLay
         attrSet.recycle()
     }
 
+    fun setEnableStatus(isEnabled: Boolean) {
+        mBinding.et.isEnabled = isEnabled
+        when (mMode) {
+            // 选择模式、日期模式
+            MODE_SELECT, MODE_DATE -> {
+                mBinding.et.background = if (mBinding.et.isEnabled) {
+                    AppCompatResources.getDrawable(ctx, R.drawable.selectable_input_spinner_bg)
+                } else {
+                    AppCompatResources.getDrawable(ctx, R.drawable.selectable_input_spinner_disabled_bg)
+                }
+            }
+            // 输入模式
+            MODE_INPUT -> {
+                mBinding.et.background = if (mBinding.et.isEnabled) {
+                    AppCompatResources.getDrawable(ctx, R.drawable.selectable_input_text_bg)
+                } else {
+                    AppCompatResources.getDrawable(ctx, R.drawable.selectable_input_text_disabled_bg)
+                }
+            }
+        }
+    }
+
     private fun setMode(mode: Int) {
         when (mode) {
             // 选择模式
             MODE_SELECT -> {
+                mMode = MODE_SELECT
+
                 mBinding.et.background = if (mBinding.et.isEnabled) {
                     AppCompatResources.getDrawable(ctx, R.drawable.selectable_input_spinner_bg)
                 } else {
@@ -89,6 +114,8 @@ class SelectableInput(private val ctx: Context, attrs: AttributeSet) : LinearLay
             }
             // 输入模式
             MODE_INPUT -> {
+                mMode = MODE_INPUT
+
                 mBinding.et.background = if (mBinding.et.isEnabled) {
                     AppCompatResources.getDrawable(ctx, R.drawable.selectable_input_text_bg)
                 } else {
@@ -119,6 +146,8 @@ class SelectableInput(private val ctx: Context, attrs: AttributeSet) : LinearLay
             }
             // 日期模式
             else -> {
+                mMode = MODE_DATE
+
                 mBinding.et.background = if (mBinding.et.isEnabled) {
                     AppCompatResources.getDrawable(ctx, R.drawable.selectable_input_spinner_bg)
                 } else {

+ 30 - 26
app/src/main/res/layout/item_rv_manual_replacement.xml

@@ -32,38 +32,42 @@
             android:text="@string/new_material" />
     </LinearLayout>
 
-    <TextView
-        android:id="@+id/tv_confirm"
-        style="@style/CommonBtnRed"
-        android:layout_width="56dp"
-        android:layout_height="17dp"
+    <LinearLayout
+        android:id="@+id/ll_btn"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:orientation="horizontal"
         android:layout_alignParentRight="true"
-        android:layout_alignParentBottom="true"
-        android:layout_marginVertical="3dp"
-        android:layout_marginRight="3dp"
-        android:padding="0dp"
-        android:text="@string/confirm_replacement"
-        android:textSize="@dimen/common_text_size_small" />
-
-    <TextView
-        android:id="@+id/tv_reset"
-        style="@style/CommonBtnRed"
-        android:layout_width="56dp"
-        android:layout_height="17dp"
-        android:layout_alignParentBottom="true"
-        android:layout_marginVertical="3dp"
-        android:layout_marginRight="3dp"
-        android:layout_toLeftOf="@id/tv_confirm"
-        android:backgroundTint="@color/common_light_gray"
-        android:padding="0dp"
-        android:text="@string/reset_modification"
-        android:textSize="@dimen/common_text_size_small" />
+        android:layout_alignParentBottom="true">
+        <TextView
+            android:id="@+id/tv_confirm"
+            style="@style/CommonBtnRed"
+            android:layout_width="56dp"
+            android:layout_height="17dp"
+            android:layout_marginVertical="3dp"
+            android:layout_marginRight="3dp"
+            android:padding="0dp"
+            android:text="@string/confirm_replacement"
+            android:textSize="@dimen/common_text_size_small" />
+
+        <TextView
+            android:id="@+id/tv_reset"
+            style="@style/CommonBtnRed"
+            android:layout_width="56dp"
+            android:layout_height="17dp"
+            android:layout_marginVertical="3dp"
+            android:layout_marginRight="3dp"
+            android:backgroundTint="@color/common_light_gray"
+            android:padding="0dp"
+            android:text="@string/reset_modification"
+            android:textSize="@dimen/common_text_size_small" />
+    </LinearLayout>
 
     <View
         android:id="@+id/v_bottom_divider"
         android:layout_width="match_parent"
         android:layout_height="@dimen/divider_line_width"
-        android:layout_above="@id/tv_confirm"
+        android:layout_above="@id/ll_btn"
         android:background="@color/main_color" />
 
     <LinearLayout