package com.zxhl.main.page.activity

import android.graphics.Paint
import android.content.Intent
import android.util.Log
import android.view.View
import android.widget.ImageView
import com.bumptech.glide.Glide
import com.bumptech.glide.load.resource.bitmap.CircleCrop
import com.bumptech.glide.request.RequestOptions
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import com.zxhl.cms.AppContext
import com.zxhl.cms.common.base.BaseActivity
import com.zxhl.cms.net.model.shop.ShopListEntity
import com.zxhl.cms.utils.NoDoubleClickListener
import com.zxhl.main.R
import kotlinx.android.synthetic.main.activity_layout_shop_goods_detail.*

/**
 * @author (wangXuewei)
 * @detail :商店详情
 */
class ShopGoodsDetailActivity : BaseActivity() {
    private var goodsDetail: ShopListEntity? = null;
    var mChoosList: MutableList<String> = ArrayList()
    override fun onClick(v: View?) {

    }

    override fun layoutID(): Int {
        return R.layout.activity_layout_shop_goods_detail
    }
    override fun before() {
        super.before()
        setStatusBarBackground(AppContext.get().resources.getColor(R.color.transparent))
    }
    override fun init() {
        goodsDetail = intent.getSerializableExtra("goods") as ShopListEntity?

        id_shop_detail_goods_img.setLoadImageUrl(goodsDetail?.mainImage, false)
        id_shop_detail_goods_price.text = goodsDetail?.salePriceStr
        id_shop_detail_goods_oldPrice.text = "¥${goodsDetail?.originalPrice}"
        id_shop_detail_goods_oldPrice.paint?.flags = Paint.STRIKE_THRU_TEXT_FLAG //中划线
        id_shop_detail_goods_sell_num.text = "售出: ${goodsDetail?.salesVolume}"
        id_shop_detail_goods_name.text = goodsDetail?.productName
        //解析商品详情图
        var goodsImgList: List<String> =
            Gson().fromJson(goodsDetail?.descImg, object : TypeToken<List<String>>() {}.type)

        for (goodsImg in goodsImgList) {
            var detailImageView = ImageView(this)
            Glide.with(this).load(goodsImg).into(detailImageView)
            id_shop_goods_detail_img_list.addView(detailImageView)
        }






        id_img_back.setOnClickListener {
            finish()
        }
        id_bug_goods_btn.setOnClickListener(object : NoDoubleClickListener() {
            override fun onNoDoubleClick(v: View?) {
                gotoBuy()
            }
        })
    }


    fun gotoBuy() {
        mChoosList.clear()
        mChoosList.add(goodsDetail?.id.toString())
        val intent = Intent(mActivity, ShopOrderActivity::class.java)
        intent.putStringArrayListExtra(
            "stringList",
            mChoosList as java.util.ArrayList<String>?
        )
        startActivity(intent)
    }
}