package com.lukouguoji.gjc.activity

import android.os.Bundle
import com.alibaba.android.arouter.facade.annotation.Route
import com.lukouguoji.gjc.R
import com.lukouguoji.gjc.databinding.ActivityBoxAssembleBinding
import com.lukouguoji.gjc.holder.BoxAssembleViewHolder
import com.lukouguoji.gjc.viewModel.BoxAssembleViewModel
import com.lukouguoji.module_base.base.BaseBindingActivity
import com.lukouguoji.module_base.base.CommonAdapter
import com.lukouguoji.module_base.common.ConstantEvent
import com.lukouguoji.module_base.impl.FlowBus
import com.lukouguoji.module_base.impl.observe
import com.lukouguoji.module_base.ktx.addOnItemClickListener
import com.lukouguoji.module_base.router.ARouterConstants

/**
 * 板箱组装
 */
@Route(path = ARouterConstants.ACTIVITY_URL_GJC_BOX_ASSEMBLE)
class BoxAssembleActivity :
    BaseBindingActivity<ActivityBoxAssembleBinding, BoxAssembleViewModel>() {

    override fun layoutId() = R.layout.activity_box_assemble

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

    override fun initOnCreate(savedInstanceState: Bundle?) {
        setBackArrow("国际出港板箱组装")
        binding.viewModel = viewModel

        binding.rv.adapter =
            CommonAdapter(this, R.layout.item_box_assemble, BoxAssembleViewHolder::class.java)
        binding.rv.addOnItemClickListener(viewModel)
        // 绑定刷新事件
        viewModel.pageModel.bindSmartRefreshLayout(binding.srl, binding.rv, viewModel, this)

        // 刷新数据
        viewModel.getData()

        FlowBus.with<Any>(ConstantEvent.GJC_BOX_ADD_SUCCESS)
            .observe(this) {
                viewModel.getData()
            }
    }

}