package com.zswc.creativity.fragment

import android.app.Activity
import android.content.Intent
import android.os.Bundle
import android.view.LayoutInflater
import android.view.ViewGroup
import com.ysnows.base.utils.UiUtils
import com.zswc.creativity.adapter.SaleListFragmentAdapter
import com.zswc.creativity.adapter.ShopListFragmentAdapter
import com.zswc.creativity.base.MBRFragment
import com.zswc.creativity.config.MIntentAction
import com.zswc.creativity.databinding.FragmentSaleListBinding
import com.zswc.creativity.databinding.FragmentShopGoodsBinding
import com.zswc.creativity.utils.GridSpaceItemToDecoration
import com.zswc.creativity.vmodel.SaleListFragmentVModel
import com.zswc.creativity.vmodel.ShopListFragmentVModel

/**
 *
 *on 2021/3/15
 */
class ShopListFragment: MBRFragment<ShopListFragmentVModel, ShopListFragmentAdapter, FragmentShopGoodsBinding>() {


    override fun __before(savedInstanceState: Bundle?) {
        super.__before(savedInstanceState)
        vm.state=arguments?.getString("state")

        binding.recyclerView.addItemDecoration(GridSpaceItemToDecoration(2,
                UiUtils.dp2Px(context(), 12f),
                UiUtils.dp2Px(context(), 15f)))

    }

    override fun init(savedInstanceState: Bundle?) {
        super.init(savedInstanceState)
        vm.fragment=this
    }

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)

        if (resultCode != Activity.RESULT_OK) {
            return
        }
        if (requestCode == MIntentAction.REQUEST_CODE_ONE) {//刷新
            onRefresh()
        }
    }
    override fun vmClass(): Class<ShopListFragmentVModel> {
        return ShopListFragmentVModel::class.java
    }

    override fun binding(inflater: LayoutInflater, container: ViewGroup?): FragmentShopGoodsBinding {
        return FragmentShopGoodsBinding.inflate(layoutInflater)
    }

    override fun initAdapter(): ShopListFragmentAdapter {
        return ShopListFragmentAdapter(vm)
    }

    override fun title(): String? {
        return null
    }

    override val isRxbus: Boolean
        get() = true


//    @Subscribe(tags = [Tag(ConfigRx.ORDER_SEARCH)])
//    fun setOrderSearch(k: String) {
//        vm.k=k
//        onRefresh()
//
//    }
//
//
//    @Subscribe(tags = [Tag(ConfigRx.ORDER_REFRESH)])
//    fun setOrderRefresh(type: String) {
//
//        onRefresh()
//
//    }
}
