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

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 EntrustChildFragment(type: String) : BaseFragment<EntrustChildViewModel>() {
    private var type: String? = type

    companion object {
        fun getInstance(type: String) = EntrustChildFragment(type)
    }

    private var _view: View? = null
    private var idEntrustList: RecyclerView? = null // 委托单列表

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        _view = inflater.inflate(R.layout.entrust_child, container, false)
        initViews()
        return _view
    }

    private fun initViews() {
        idEntrustList = _view?.findViewById(R.id.id_entrust_list)
        val list: ArrayList<EntrustData>? = ArrayList()
        for (a in 1..5) {
            val m = EntrustData()
            m.goodsName = "铁矿石" + (2105 + a)
            m.goodsCode = "I" + (2105 + a)
            m.lastPrice = 998.0 + a
            m.entrustPrice = 1000.0 + a
            m.entrustType = "买多"
            m.entrustNum = 50.0 + a
            m.time = "10:10:10"
            m.goodsId = a
            m.pl = 1001.0
            m.status = "已报"
            m.direction = a
            list?.add(m)
        }

        val layoutManager = LinearLayoutManager(context)
        idEntrustList?.layoutManager = layoutManager
        viewModel.list = list
        idEntrustList?.adapter = viewModel.getAdapter()
    }
}