package com.yidian.shenghuoquan.buserorder.viewmodel

import android.view.View
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.databinding.BindingAdapter
import com.yidian.bcommon.constant.XEventConfig
import com.yidian.bcommon.mvvm.BaseViewModel
import com.yidian.shenghuoquan.buserorder.dto.PickupPoint
import com.yidian.utils.DensityUtil
import com.yidian.xarc.xevent.XBaseEvent
import com.yidian.xarc.xevent.XEventManager
import com.yidian.xpage.XPageManager

/**
 * author: yinjiacheng
 * date: 2021/8/24 17:19
 * description: 自提点列表
 */
class PickupPointListItemViewModel : BaseViewModel() {

  companion object {
    /**
     * 设置左外边距
     * @param margin 外边距 单位dp
     */
    @JvmStatic
    @BindingAdapter("layout_marginStart")
    fun setMarginStart(view: View, margin: Int) {
      val lp = view.layoutParams as ConstraintLayout.LayoutParams
      lp.marginStart = DensityUtil.dp2px(margin.toFloat())
      view.layoutParams = lp
    }
  }

  /**
   * 回传选择的自提点
   */
  fun selectPickupPoint(data: PickupPoint) {
    XEventManager.post(XBaseEvent(XEventConfig.CONFIRM_ORDER_CHOOSE_POINT_SUCCESS, data))
    XPageManager.pop(null)
  }
}
