package com.yidian.shenghuoquan.border.ui

import androidx.activity.viewModels
import com.yidian.bcommon.constant.IntentConstants
import com.yidian.bcommon.constant.XRouterPathConstants
import com.yidian.bcommon.mvvm.BaseMvvmActivity
import com.yidian.shenghuoquan.border.R
import com.yidian.shenghuoquan.border.databinding.BorderActivityOrderDetailBinding
import com.yidian.shenghuoquan.border.manager.OrderStatusManager
import com.yidian.shenghuoquan.border.viewmodel.OrderDetailViewModel
import com.yidian.xpage.XPageViewProtocol

/**
 * author: yinjiacheng
 * date: 2021/8/21 09:29
 * description: 订单详情页
 */
class OrderDetailActivity : BaseMvvmActivity<BorderActivityOrderDetailBinding, OrderDetailViewModel>(), XPageViewProtocol {

  override val layoutId: Int = R.layout.border_activity_order_detail
  override val vm: OrderDetailViewModel by viewModels()

  /**
   * 订单id
   */
  private val orderId by lazy {
    intent.getSerializableExtra(XRouterPathConstants.ParamsKey)?.let { params ->
      (params as HashMap<*, *>)[IntentConstants.KEY_EXTRA_ORDER_ID]?.let {
        it as String
      }
    }
  }

  override fun getXPageName(): String {
    return XRouterPathConstants.ORDER_DETAIL_ACTIVITY
  }

  override fun initView() {
    vm.orderDetailData.observe(this, {
      // 获取当前订单状态
      val status = OrderStatusManager.getOrderStatus(it.orderStatus)
      binding.svOrderStatus.setOrderStatus(status, it)
      binding.pvPickupPointInfo.setPickupPoint(it.placeList)
      binding.ivConsigneeInfo.setConsigneeInfo(status, it.orderShippingInfo)
      binding.ivCommodityInfo.setCommodityInfo(status, it)
      binding.ivOrderInfo.setOrderInfo(status, it)
    })
    // 请求订单详情
    orderId?.let { vm.requestOrderDetail(it) }
  }
}
