package com.lukouguoji.gjc.activity

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.databinding.DataBindingUtil
import androidx.lifecycle.ViewModelProvider
import com.alibaba.android.arouter.facade.annotation.Route
import com.lukouguoji.gjc.R
import com.lukouguoji.gjc.databinding.ActivityGjcGoodsListBinding
import com.lukouguoji.gjc.holder.GjcGoodsViewHolder
import com.lukouguoji.gjc.viewModel.GjcGoodsListViewModel
import com.lukouguoji.module_base.BaseActivity
import com.lukouguoji.module_base.base.BaseBindingActivity
import com.lukouguoji.module_base.base.CommonAdapter
import com.lukouguoji.module_base.common.Constant
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
import kotlin.properties.Delegates

@Route(path = ARouterConstants.ACTIVITY_URL_GJC_GOODS_LIST)
class GjcGoodsListActivity :
    BaseBindingActivity<ActivityGjcGoodsListBinding, GjcGoodsListViewModel>() {

    override fun layoutId() = R.layout.activity_gjc_goods_list

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

    override fun initOnCreate(savedInstanceState: Bundle?) {
        setBackArrow("国际出港货物交接")
        binding.viewModel = viewModel

        binding.rv.adapter =
            CommonAdapter(this, R.layout.item_gjc_goods, GjcGoodsViewHolder::class.java)
        viewModel.pageModel.bindSmartRefreshLayout(binding.srl, binding.rv, viewModel, this)
        binding.rv.addOnItemClickListener(viewModel)

        viewModel.getData()

        // 新增成功
        FlowBus.with<Any>(ConstantEvent.GJC_HANDOVER_ADD_SUCCESS)
            .observe(this) {
                viewModel.refresh()
            }
        // 签名成功
        FlowBus.with<Any>(ConstantEvent.GJC_HANDOVER_SIGNATURE_SUCCESS)
            .observe(this) {
                viewModel.refresh()
            }
    }

}