package com.lukouguoji.gjj.activity

import android.content.Context
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import com.lukouguoji.gjj.R
import com.lukouguoji.gjj.databinding.ActivityGjjTallyAddBinding
import com.lukouguoji.gjj.viewModel.GjjTallyAddViewModel
import com.lukouguoji.module_base.base.BaseBindingActivity
import com.lukouguoji.module_base.bean.GjjTallyBean
import com.lukouguoji.module_base.common.Constant
import com.lukouguoji.module_base.http.net.NetApply
import com.lukouguoji.module_base.ktx.addOnItemClickListener
import com.lukouguoji.module_base.ktx.toJson

class GjjTallyAddActivity :
    BaseBindingActivity<ActivityGjjTallyAddBinding, GjjTallyAddViewModel>() {

    override fun layoutId() = R.layout.activity_gjj_tally_add

    override fun viewModelClass() = GjjTallyAddViewModel::class.java

    override fun initOnCreate(savedInstanceState: Bundle?) {
        setBackArrow("国际进港开始理货")
        intent.getStringExtra(Constant.Key.DATA)?.let {
            viewModel.tallyBean = NetApply.gson.fromJson(it, GjjTallyBean::class.java)
            viewModel.getData()
        }

        binding.viewModel = viewModel
        viewModel.pageModel.bindSmartRefreshLayout(binding.srl, binding.rv, viewModel, this)
        binding.rv.addOnItemClickListener(viewModel)
    }

    companion object {
        @JvmStatic
        fun start(context: Context, bean: GjjTallyBean? = null) {
            val starter = Intent(context, GjjTallyAddActivity::class.java)
            bean?.let {
                starter.putExtra(Constant.Key.DATA, it.toJson(false))
            }
            context.startActivity(starter)
        }
    }
}