import * as React from 'react'
import CoverImg from "./coverImg";
import ProductName from "./productName";
import ShopProductDescption from "./productDesc";
import ShopOriginalPrice from "./productOriginalPrice";
import ShopProductBtn from "./productBtn";
import LinkWrapper from "../goodslinkWrapper";
import MUtil from "../../util/utils";
import ShopMarkingNum from "./markingNum";
import ShopPriceWrapper from "./productPrice/wrapper";
import ShopPrice from "./productPrice";

const marketType = MUtil.marketType();

class ShopProduct extends React.Component<any, any> {
    constructor(props) {
        super(props);
        this.goDetail = this.goDetail.bind(this);
    }

    componentDidMount(): void {

    }

    goDetail(data) {
        if (this.props.env == 'isMp') {
            this.props.goMpPath(data.goodsLink);
        } else {
            window.location.href = data.goodsLink;
        }
    }

    render() {
        let data = this.props.data;
        return (
            <LinkWrapper {...data}
                         className={'shop-pro-item shop-distri-item'
                         + (data.mItemType == 'big' ? ' shop-pro-item-big' : '')
                         + (data.mItemType == 'small' ? ' shop-pro-item-small' : '')
                         + (data.className ? ' ' + data.className : '')
                         + (data.fillType == 2 ? ' shop-pro-item-cover' : '')
                         }
                         onClick={this.goDetail.bind(this, data.goodsLink)}
            >
                <div className={'shop-pro-content'}>
                    <div className={'shop-relative shop-pro-img-wrapper'}>
                        {/*图片*/}
                        <CoverImg data={data}></CoverImg>
                    </div>

                    {/*商品名称*/}
                    <ProductName data={data}></ProductName>


                    {/*商品描述*/}
                    <ShopProductDescption data={data}></ShopProductDescption>

                    {/*价格和购买按钮*/}
                    {
                        data.cptType == 9401 ?
                            <div className={'shop-product-card  shop-product-card-points'}>
                                {
                                    data.showPrice || data.markPrice == 1 ?
                                        <div className={'shop-product-price-container'}>
                                            {/*价格*/}
                                            {
                                                data.showPrice ?
                                                    <span>
                                                        <ShopPriceWrapper
                                                            data={data}>{data.pointsPrice ? data.pointsPrice : 0}{data.pointsName ? data.pointsName : '积分'}</ShopPriceWrapper>
                                                        {
                                                            data.moneyPrice && data.moneyPrice > 0 ?
                                                                <span>
                                                                    <span className={'shop-pro-pointsAdd'}>+</span>
                                                                    <ShopPriceWrapper
                                                                        data={data}>￥{MUtil.centTransformOut(data.moneyPrice)}</ShopPriceWrapper>
                                                                </span> : ''
                                                        }
                                                    </span> : ''
                                            }

                                            <ShopOriginalPrice data={data}></ShopOriginalPrice>
                                        </div> : ''
                                }


                                {
                                    data.showPurBtn ?
                                        <div className={'shop-product-btn-container'}>
                                            {/*购买按钮*/}
                                            <ShopProductBtn data={data}></ShopProductBtn>
                                        </div> : ''
                                }

                            </div> :
                            data.cptType == 9402 || data.cptType == 9404 ?
                                <div className={'shop-product-card  shop-product-card-points'}>
                                    {
                                        data.showPrice ?
                                            <div className={'shop-product-price-container'}>
                                                {/*价格*/}
                                                <ShopPriceWrapper
                                                    data={data}>{data.pointsPrice ? data.pointsPrice : 0}积分</ShopPriceWrapper>
                                                {
                                                    data.moneyPrice && data.moneyPrice > 0 ?
                                                        <span>
                                                            <span className={'shop-pro-pointsAdd'}>+</span>
                                                            <ShopPriceWrapper
                                                                data={data}>￥{MUtil.centTransformOut(data.moneyPrice)}</ShopPriceWrapper>
                                                        </span> : ''
                                                }

                                            </div> : ''
                                    }

                                    <div className={'clearfix shop-product-btn-container-points'}>
                                        <ShopOriginalPrice data={data}></ShopOriginalPrice>

                                        {/*购买按钮*/}
                                        {
                                            data.showPurBtn ?
                                                <div className={'shop-product-btn-container'}>
                                                    {/*购买按钮*/}
                                                    <ShopProductBtn data={data}></ShopProductBtn>
                                                </div> : ''
                                        }
                                    </div>

                                </div> :
                                data.cptType == 9403 || data.cptType == 9406 ?
                                    <div className={'shop-product-card  shop-product-card-points'}>
                                        {
                                            data.showPrice && data.moneyPrice > 0 ?
                                                <div className={'shop-product-price-container'}>
                                                    {/*价格*/}
                                                    <ShopPriceWrapper
                                                        data={data}>￥{MUtil.centTransformOut(data.moneyPrice)}</ShopPriceWrapper>
                                                </div> : ''
                                        }

                                        {
                                            data.showPrice || data.showPurBtn ?
                                                <div className={'clearfix shop-product-btn-container-points'}>
                                                    {
                                                        data.showPrice ?
                                                            <ShopPriceWrapper
                                                                data={data}>{data.pointsPrice ? data.pointsPrice : 0}积分</ShopPriceWrapper> : ''
                                                    }
                                                    {/*购买按钮*/}
                                                    {
                                                        data.showPurBtn ?
                                                            <div className={'shop-product-btn-container'}>
                                                                {/*购买按钮*/}
                                                                <ShopProductBtn data={data}></ShopProductBtn>
                                                            </div> : ''
                                                    }
                                                </div> : ''
                                        }


                                    </div> :
                                    data.cptType == 9405 ?
                                        <div className={'shop-product-card  shop-product-card-points'}>
                                            {
                                                data.showPrice || (data.markPrice && data.mItemType == 'big') ?
                                                    <div className={'shop-product-price-container'}>
                                                        {/*价格*/}
                                                        <ShopPriceWrapper
                                                            data={data}>{data.pointsPrice ? data.pointsPrice : 0}积分</ShopPriceWrapper>
                                                        {
                                                            data.moneyPrice && data.moneyPrice > 0 ?
                                                                <span>
                                                                     <span className={'shop-pro-pointsAdd'}>+</span>
                                                                        <ShopPriceWrapper
                                                                            data={data}>￥{MUtil.centTransformOut(data.moneyPrice)}</ShopPriceWrapper>
                                                                </span> : ''
                                                        }


                                                        {
                                                            data.mItemType == 'big' ?
                                                                <ShopOriginalPrice data={data}></ShopOriginalPrice> : ''
                                                        }

                                                    </div> : ''
                                            }


                                            {/*购买按钮*/}
                                            {
                                                data.markPrice || data.showPurBtn ?
                                                    <div className={'shop-product-btn-container'}>
                                                        {
                                                            data.mItemType == 'small' ?
                                                                <ShopOriginalPrice data={data}></ShopOriginalPrice> : ''
                                                        }
                                                        {/*购买按钮*/}
                                                        <ShopProductBtn data={data}></ShopProductBtn>
                                                    </div> : ''
                                            }

                                        </div> : ""

                    }

                </div>
            </LinkWrapper>
        );
    }
}

export default ShopProduct;