package cn.muchinfo.rma.view.base.future.holds

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import cn.muchinfo.rma.R
import cn.muchinfo.rma.view.base.BaseFragment

/**
 * 持仓列表界面
 */
class HoldFragment : BaseFragment<HoldViewModel>() {

    companion object {
        fun getInstance() = HoldFragment()
    }
//region views
    private var _view: View? = null
    private var idHoldList: RecyclerView? = null // 持仓列表
//endregion
    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        _view = inflater.inflate(R.layout.hold_fragment, container, false)
        initViews()
        return _view
    }

    private fun initViews() {
        idHoldList = _view?.findViewById(R.id.id_hold_list)
        val list: ArrayList<HoldData>? = ArrayList()
        for (a in 1..5) {
            val m = HoldData()
            m.goodsName = "铁矿石" + (2105 + a)
            m.goodsCode = "I" + (2105 + a)
            m.lastPrice = 998.0 + a
            m.available = 1.0 + a
            m.totals = 5.0 + a
            m.cost = 500.0 + a
            m.pl = 100.0 + a
            m.plp = (100 + a) * 0.003
            m.holdPrice = 899.0 + a
            m.direction = a
            list?.add(m)
        }
        val layoutManager = LinearLayoutManager(context)
        idHoldList?.layoutManager = layoutManager
        viewModel.list = list
        idHoldList?.adapter = viewModel.getAdapter()
    }
}