|
|
@@ -0,0 +1,322 @@
|
|
|
+package cn.muchinfo.rma.view.base.warehousereceipt
|
|
|
+
|
|
|
+import android.os.Bundle
|
|
|
+import android.view.*
|
|
|
+import androidx.fragment.app.Fragment
|
|
|
+import androidx.recyclerview.widget.LinearLayoutManager
|
|
|
+import androidx.recyclerview.widget.RecyclerView
|
|
|
+import androidx.viewpager.widget.PagerAdapter
|
|
|
+import androidx.viewpager.widget.ViewPager
|
|
|
+import cn.muchinfo.rma.R
|
|
|
+import cn.muchinfo.rma.global.GlobalDataCollection
|
|
|
+import cn.muchinfo.rma.lifecycle.bindOptional
|
|
|
+import cn.muchinfo.rma.view.autoWidget.*
|
|
|
+import cn.muchinfo.rma.view.base.BaseFragment
|
|
|
+import cn.muchinfo.rma.view.base.platinumtreasure.adapter.PlatnumTreasureAdapter
|
|
|
+import cn.muchinfo.rma.view.base.procurement.TopTabAdpater
|
|
|
+import cn.muchinfo.rma.view.base.warehousereceipt.one.OnePriceAdapter
|
|
|
+import com.blankj.utilcode.util.ConvertUtils
|
|
|
+import com.blankj.utilcode.util.SizeUtils
|
|
|
+import com.qmuiteam.qmui.util.QMUIDisplayHelper
|
|
|
+import com.qmuiteam.qmui.widget.tab.QMUITabIndicator
|
|
|
+import com.qmuiteam.qmui.widget.tab.QMUITabSegment
|
|
|
+import org.jetbrains.anko.*
|
|
|
+import org.jetbrains.anko.support.v4.UI
|
|
|
+import org.jetbrains.anko.support.v4.viewPager
|
|
|
+
|
|
|
+/**
|
|
|
+ * 仓单贸易报价牌
|
|
|
+ */
|
|
|
+class WarehouseReceiptFragment : BaseFragment<WarehouseReceiptViewModel>(){
|
|
|
+
|
|
|
+ lateinit var segment: QMUITabSegment
|
|
|
+ var selectedTabIndex: Int = 0
|
|
|
+ private lateinit var viewPager: ViewPager
|
|
|
+
|
|
|
+ //一口价报价牌
|
|
|
+ private val onePriceUI by lazy { OnePriceUI(this,viewModel) }
|
|
|
+
|
|
|
+ //浮动价报价牌
|
|
|
+ private val floatingPriceUI by lazy { FloatingPriceUI(this,viewModel) }
|
|
|
+
|
|
|
+ //viewpager的适配器
|
|
|
+ private var newPagerAdapter : PagerAdapter? = null
|
|
|
+
|
|
|
+ //tabSegment标题
|
|
|
+ private val newTabsArray : ArrayList<String> = arrayListOf()
|
|
|
+
|
|
|
+ //暂存的页面组
|
|
|
+ private val uiList : ArrayList<_FrameLayout> = arrayListOf()
|
|
|
+
|
|
|
+ fun initMenuData(){
|
|
|
+
|
|
|
+ newTabsArray.add("一口价")
|
|
|
+ uiList.add(onePriceUI.root)
|
|
|
+
|
|
|
+ newTabsArray.add("浮动价")
|
|
|
+ uiList.add(floatingPriceUI.root)
|
|
|
+
|
|
|
+ newPagerAdapter = object : PagerAdapter() {
|
|
|
+
|
|
|
+ override fun getPageTitle(position: Int): CharSequence? = newTabsArray[position]
|
|
|
+
|
|
|
+ override fun instantiateItem(container: ViewGroup, position: Int): Any {
|
|
|
+ return uiList.get(position).apply {
|
|
|
+ container.addView(
|
|
|
+ this,
|
|
|
+ ViewGroup.LayoutParams(matchParent, matchParent)
|
|
|
+ )
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun destroyItem(container: ViewGroup, position: Int, `object`: Any) {
|
|
|
+ (`object` as? View)?.let { container.removeView(it) }
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun isViewFromObject(view: View, `object`: Any): Boolean = view == `object`
|
|
|
+
|
|
|
+ override fun getCount(): Int = newTabsArray.size
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ override fun onCreateView(
|
|
|
+ inflater: LayoutInflater,
|
|
|
+ container: ViewGroup?,
|
|
|
+ savedInstanceState: Bundle?
|
|
|
+ ): View? {
|
|
|
+
|
|
|
+ return UI {
|
|
|
+ verticalLayout {
|
|
|
+ linearLayout {
|
|
|
+ background = resources.getDrawable(R.color.main_title_bg_color)
|
|
|
+
|
|
|
+ view {
|
|
|
+
|
|
|
+ }.lparams(autoSize(200), autoSize(100))
|
|
|
+
|
|
|
+ tabSegment {
|
|
|
+ segment = this
|
|
|
+ background = resources.getDrawable(R.color.segtabment_bg_color)
|
|
|
+ addOnTabSelectedListener(object :
|
|
|
+ QMUITabSegment.OnTabSelectedListener {
|
|
|
+ override fun onDoubleTap(index: Int) {}
|
|
|
+ override fun onTabReselected(index: Int) {}
|
|
|
+ override fun onTabUnselected(index: Int) {}
|
|
|
+ override fun onTabSelected(index: Int) {
|
|
|
+ selectedTabIndex = index
|
|
|
+ }
|
|
|
+ })
|
|
|
+ setIndicator(
|
|
|
+ QMUITabIndicator(
|
|
|
+ QMUIDisplayHelper.dp2px(context, 2),
|
|
|
+ false,
|
|
|
+ true
|
|
|
+ )
|
|
|
+ )
|
|
|
+ setDefaultTextSize(ConvertUtils.sp2px(16f), ConvertUtils.sp2px(16f))
|
|
|
+ }.lparams(matchParent, autoSize(100))
|
|
|
+
|
|
|
+ view {
|
|
|
+
|
|
|
+ }.lparams(autoSize(200), autoSize(100))
|
|
|
+ }.lparams(matchParent, autoSize(100))
|
|
|
+
|
|
|
+ view {
|
|
|
+ background = resources.getDrawable(R.color.main_hit_bg_color)
|
|
|
+ }.lparams(matchParent, autoSize(1)) {
|
|
|
+ marginStart = autoSize(32)
|
|
|
+ marginEnd = autoSize(32)
|
|
|
+ }
|
|
|
+ viewPager {
|
|
|
+ background = resources.getDrawable(R.color.white)
|
|
|
+ viewPager = this
|
|
|
+ adapter = newPagerAdapter
|
|
|
+ }.lparams(matchParent, matchParent)
|
|
|
+
|
|
|
+ segment.setupWithViewPager(viewPager)
|
|
|
+ segment.selectTab(1)
|
|
|
+ }
|
|
|
+ }.view
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * 一口价报价牌
|
|
|
+ * @property fragment Fragment
|
|
|
+ * @property viewModel WarehouseReceiptViewModel
|
|
|
+ * @constructor
|
|
|
+ */
|
|
|
+class OnePriceUI(private val fragment : Fragment,private val viewModel: WarehouseReceiptViewModel) : OnePriceAdapter.OnContentScrollListener{
|
|
|
+
|
|
|
+ private lateinit var swipeToLayout: SwipeToLoadLayout
|
|
|
+ private lateinit var statusLayout: StatusLayout
|
|
|
+ lateinit var horScrollview: CustomHorizontalScrollView
|
|
|
+ lateinit var recyclerView: RecyclerView
|
|
|
+
|
|
|
+ lateinit var dataRecyclerview : RecyclerView
|
|
|
+
|
|
|
+
|
|
|
+ //标题头部
|
|
|
+ val topAdapter by lazy {
|
|
|
+ TopTabAdpater(fragment.context)
|
|
|
+ }
|
|
|
+
|
|
|
+ val onePriceAdapter by lazy {
|
|
|
+ OnePriceAdapter(fragment.context)
|
|
|
+ }
|
|
|
+
|
|
|
+ val root = _FrameLayout(fragment.context!!).apply {
|
|
|
+ verticalLayout {
|
|
|
+ linearLayout {
|
|
|
+ linearLayout {
|
|
|
+ gravity = Gravity.LEFT or Gravity.CENTER_VERTICAL
|
|
|
+ textView {//待点价头部左侧数据
|
|
|
+// viewModel.titleList.bindOptional(context) {
|
|
|
+// text = it?.get(0)?.columntitle?.replace("\\n", "\n") ?: ""
|
|
|
+// }
|
|
|
+ text = "商品"
|
|
|
+ textColorStr = "#AAAAAA"
|
|
|
+ textSizeAuto = 31
|
|
|
+ }.lparams(wrapContent, wrapContent){
|
|
|
+ marginStart = autoSize(30)
|
|
|
+ }
|
|
|
+ }.lparams(autoSize(SizeUtils.dp2px(100f)), autoSize(100))
|
|
|
+ onePriceAdapter.setOnContentScrollListener(this@OnePriceUI)
|
|
|
+ inflateLayout<CustomHorizontalScrollView>(R.layout.scrollview) {
|
|
|
+ horScrollview = this
|
|
|
+ setOnCustomScrollChangeListener { listener, scrollX, scrollY, oldScrollX, oldScrollY -> //代码重复,可以抽取/////
|
|
|
+ onePriceAdapter.offestX = scrollX
|
|
|
+ val viewHolderCacheList: List<OnePriceAdapter.ItemViewHolder> =
|
|
|
+ onePriceAdapter.viewHolderCacheList
|
|
|
+ if (null != viewHolderCacheList) {
|
|
|
+ val size = viewHolderCacheList.size
|
|
|
+ for (i in 0 until size) {
|
|
|
+ viewHolderCacheList[i].horItemScrollview.scrollTo(
|
|
|
+ scrollX,
|
|
|
+ 0
|
|
|
+ )
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ relativeLayout {
|
|
|
+ recyclerView {//待点价头部右侧数据
|
|
|
+ val linearLayoutManager = LinearLayoutManager(context)
|
|
|
+ linearLayoutManager.orientation = LinearLayoutManager.HORIZONTAL
|
|
|
+ layoutManager = linearLayoutManager
|
|
|
+ background = resources.getDrawable(R.color.white)
|
|
|
+ adapter = topAdapter
|
|
|
+ }
|
|
|
+// viewModel.titleList.bindOptional(context) {
|
|
|
+// val titleStringList = arrayListOf<String>()
|
|
|
+// it?.subList(1, it.size)?.forEach { data ->
|
|
|
+// titleStringList.add(data.columntitle?.replace("\\n", "\n") ?: "")
|
|
|
+// }
|
|
|
+// topAdapter.setDatas(titleStringList)
|
|
|
+// }
|
|
|
+ topAdapter.setDatas(arrayListOf("卖价","卖量","买价","买量","仓库"))
|
|
|
+ }
|
|
|
+ }.lparams(matchParent, matchParent)
|
|
|
+ }.lparams(matchParent, autoSize(100))
|
|
|
+
|
|
|
+ statusLayout(contentBlock = {
|
|
|
+ statusLayout = this
|
|
|
+ setRetryAction {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ swipeToLoadLayout {
|
|
|
+ swipeToLayout = this
|
|
|
+ setEnableRefresh(true)
|
|
|
+ setEnableLoadMore(false)
|
|
|
+ setOnRefreshListener {
|
|
|
+
|
|
|
+ }
|
|
|
+ setEnableScrollContentWhenLoaded(false)
|
|
|
+ setEnableLoadMoreWhenContentNotFull(false)
|
|
|
+
|
|
|
+ recyclerView {//待点价列表
|
|
|
+ dataRecyclerview = this
|
|
|
+ background = resources.getDrawable(R.color.white)
|
|
|
+ adapter = onePriceAdapter
|
|
|
+ addOnScrollListener(object : RecyclerView.OnScrollListener() {
|
|
|
+ override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
|
|
|
+ super.onScrolled(recyclerView, dx, dy)
|
|
|
+ val viewHolderCacheList: List<OnePriceAdapter.ItemViewHolder> =
|
|
|
+ onePriceAdapter.viewHolderCacheList
|
|
|
+ if (null != viewHolderCacheList) {
|
|
|
+ val size = viewHolderCacheList.size
|
|
|
+ for (i in 0 until size) {
|
|
|
+ viewHolderCacheList[i].horItemScrollview.scrollTo(
|
|
|
+ onePriceAdapter.getOffestX(),
|
|
|
+ 0
|
|
|
+ )
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ addOnScrollListener(object : RecyclerView.OnScrollListener() {
|
|
|
+ override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) {
|
|
|
+ super.onScrollStateChanged(recyclerView, newState)
|
|
|
+ // DES: 找出当前可视Item位置
|
|
|
+ val linearLayoutManager = dataRecyclerview!!.layoutManager as LinearLayoutManager
|
|
|
+ if (newState == RecyclerView.SCROLL_STATE_IDLE) {// 这个判断是当recyclerview不滚动时
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ }, emptyBlock = {
|
|
|
+ emptyView(hint = resources.getString(R.string.now_no_data))
|
|
|
+ }).lparams(matchParent, matchParent)
|
|
|
+
|
|
|
+ viewModel.floatProceDataList.bindOptional(context) {
|
|
|
+// if (it?.size ?: 0 > 10){
|
|
|
+// lastShow = 10
|
|
|
+// }else{
|
|
|
+// lastShow = it?.size ?: 0
|
|
|
+// }
|
|
|
+ if (it?.isEmpty() == true || it?.size == 0) {
|
|
|
+ statusLayout.showEmpty()
|
|
|
+ } else {
|
|
|
+ if (swipeToLayout.getIsRefreshing()) {
|
|
|
+ swipeToLayout.finishRefresh()
|
|
|
+// mHeadHeaderHSView.scrollTo(scrollXView,scrollYView)
|
|
|
+ }
|
|
|
+ statusLayout.showSuccess()
|
|
|
+ onePriceAdapter.setDatas(it)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun onScroll(event: MotionEvent?) {
|
|
|
+ //处理单个item滚动时,顶部tab需要联动
|
|
|
+ if (null != horScrollview) horScrollview.onTouchEvent(event)
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * 浮动价报价牌
|
|
|
+ * @property fragment Fragment
|
|
|
+ * @property viewModel WarehouseReceiptViewModel
|
|
|
+ * @property root _FrameLayout
|
|
|
+ * @constructor
|
|
|
+ */
|
|
|
+class FloatingPriceUI(private val fragment : Fragment,private val viewModel: WarehouseReceiptViewModel){
|
|
|
+ val root = _FrameLayout(fragment.context!!).apply {
|
|
|
+ verticalLayout {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|