package com.zj365.health.act

import android.content.ClipData
import android.content.ClipboardManager
import com.alibaba.android.arouter.facade.annotation.Route
import com.xty.base.act.BaseVmAct
import com.xty.common.arouter.ARouterUrl
import com.xty.common.setImage
import com.xty.network.model.ShopOrderDetailBean
import com.zj365.health.databinding.ActShopOrderDetailBinding
import com.zj365.health.vm.ShopOrderVm

@Route(path = ARouterUrl.SHOP_ORDER_DETAIL_ACT)
class ShopOrderDetailAct: BaseVmAct<ShopOrderVm>() {
    val binding by lazy { ActShopOrderDetailBinding.inflate(layoutInflater) }
    var orderDetailBean:ShopOrderDetailBean? = null
    override fun liveObserver() {
        mViewModel.orderDetailLiveData.observe(this){
            it.data?.let {
                orderDetailBean = it
                binding.imgGoods.setImage(this@ShopOrderDetailAct,it.goods_pic)
                binding.tvPrice.text = "¥ ${it.pay_price}"
                binding.tvGoodsName.text = it.goods_name
                binding.tvStatus.text = it.status_name
                binding.tvTotalPrice.text = "商品总价：¥ ${it.pay_price}"
                binding.tvOrderNo.text = "订单编号：${it.order_no}"
                binding.tvPayTime.text = "支付时间：${it.pay_time}"
                binding.tvCompleteTime.text = "成交时间：${it.create_time}"
                binding.tvPayType.text ="支付类型：${it.pay_type_name}"

            }

        }
    }

    override fun initView() {
        super.initView()
        statusBar(binding.title.mView)
        binding.title.mTvTitle.text = "订单详情"
        binding.title.mIvBack.setOnClickListener {
            finish()
        }
        var id = intent.getLongExtra("id",0)
        mViewModel.getOrderDetail(id)
        binding.tvCopy.setOnClickListener {
            orderDetailBean?.let {
                val clipboard: ClipboardManager =
                    getSystemService(CLIPBOARD_SERVICE) as ClipboardManager
                val clipData = ClipData.newPlainText("date", it.order_no)
                clipboard.setPrimaryClip(clipData);
            }

        }
    }

    override fun setLayout() = binding.root
}