"use strict";

Object.defineProperty(exports, "__esModule", {
    value: true
});
exports.CampaignItem = undefined;

var _toConsumableArray2 = require("babel-runtime/helpers/toConsumableArray");

var _toConsumableArray3 = _interopRequireDefault(_toConsumableArray2);

var _extends2 = require("babel-runtime/helpers/extends");

var _extends3 = _interopRequireDefault(_extends2);

var _classCallCheck2 = require("babel-runtime/helpers/classCallCheck");

var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);

var _createClass2 = require("babel-runtime/helpers/createClass");

var _createClass3 = _interopRequireDefault(_createClass2);

var _possibleConstructorReturn2 = require("babel-runtime/helpers/possibleConstructorReturn");

var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);

var _inherits2 = require("babel-runtime/helpers/inherits");

var _inherits3 = _interopRequireDefault(_inherits2);

var _fdx = require("@whalecloud/fdx");

var _react = require("react");

var _react2 = _interopRequireDefault(_react);

var _skuInputNumber = require("../sku-input-number");

var _skuInputNumber2 = _interopRequireDefault(_skuInputNumber);

var _coupon = require("./imgs/coupon.svg");

var _coupon2 = _interopRequireDefault(_coupon);

require("./index.less");

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

/**
 * @class CampaignItem
 * 一个满系活动，包含其中的商品
 */
var CampaignItem = exports.CampaignItem = function (_Component) {
    (0, _inherits3["default"])(CampaignItem, _Component);

    function CampaignItem(props) {
        (0, _classCallCheck3["default"])(this, CampaignItem);

        var _this = (0, _possibleConstructorReturn3["default"])(this, (CampaignItem.__proto__ || Object.getPrototypeOf(CampaignItem)).call(this, props));

        _this.giftElement = function (gift) {
            var _a;
            return _react2["default"].createElement(
                _fdx.Row,
                { key: gift.giftObjId, className: function () {
                        return _this.determinGiftStyle(gift);
                    }() },
                _react2["default"].createElement(_fdx.Col, { className: "checkbox-col", span: 1 }),
                _react2["default"].createElement(
                    _fdx.Col,
                    { span: 9 },
                    _react2["default"].createElement(
                        "div",
                        { className: "item-info" },
                        _react2["default"].createElement(
                            "div",
                            { className: "item-img" },
                            gift.giftType === 'CP' ? _react2["default"].createElement("img", { src: _coupon2["default"] }) : _react2["default"].createElement("img", { className: "item-pic", src: gift.imgUrl })
                        ),
                        _react2["default"].createElement(
                            "div",
                            { className: "item-detail" },
                            _react2["default"].createElement(
                                "p",
                                { className: "item-name" },
                                gift.giftName
                            ),
                            _react2["default"].createElement(
                                "div",
                                { className: "certified-icons" },
                                _react2["default"].createElement("img", { src: "data:image/svg+xml;base64, " })
                            )
                        )
                    )
                ),
                _react2["default"].createElement(
                    _fdx.Col,
                    { span: 5 },
                    _react2["default"].createElement(
                        "div",
                        { className: "spec-container" },
                        (_a = gift.selectedAttributes) === null || _a === void 0 ? void 0 : _a.map(function (attr) {
                            return _react2["default"].createElement(
                                "p",
                                { key: attr.value.value },
                                attr.name,
                                ": ",
                                attr.value.title
                            );
                        })
                    )
                ),
                _react2["default"].createElement(
                    _fdx.Col,
                    { className: "price-container", span: 3 },
                    _react2["default"].createElement(
                        "p",
                        { className: "current-price" },
                        "$ 00.00"
                    )
                ),
                _react2["default"].createElement(
                    _fdx.Col,
                    { className: "total-price", span: 4 },
                    _react2["default"].createElement(
                        "p",
                        { className: "total-amount" },
                        "$ 00.00"
                    ),
                    _react2["default"].createElement(
                        "p",
                        { className: "disabled-text" },
                        gift.num
                    )
                )
            );
        };
        _this.state = {
            campaignInfo: (0, _extends3["default"])({}, props.campaignItem.campaignInfo),
            itemList: [].concat((0, _toConsumableArray3["default"])(props.campaignItem.itemList))
        };
        return _this;
    }

    (0, _createClass3["default"])(CampaignItem, [{
        key: "componentWillReceiveProps",
        value: function componentWillReceiveProps(nextProps) {
            this.setState({
                campaignInfo: (0, _extends3["default"])({}, nextProps.campaignItem.campaignInfo),
                itemList: [].concat((0, _toConsumableArray3["default"])(nextProps.campaignItem.itemList))
            });
        }
        /**
        * @method composeItemCampaignList
        * @param campaignList {Array} 商品的营销活动数组
        * 组装商品的营销活动选择列表
        */

    }, {
        key: "composeItemCampaignList",
        value: function composeItemCampaignList(campaignList, item) {
            var _this2 = this;

            return _react2["default"].createElement(
                "div",
                { className: "item-campaign-list" },
                campaignList === null || campaignList === void 0 ? void 0 : campaignList.map(function (campaign) {
                    return _react2["default"].createElement(
                        "div",
                        { key: campaign.id, className: campaign.selected ? "campaign-item selected" : "campaign-item", onClick: function onClick() {
                                _this2.changeItemCampaign(campaign, item);
                            } },
                        campaign.desc
                    );
                })
            );
        }
    }, {
        key: "changeItemCampaign",
        value: function changeItemCampaign(campaign, item) {
            var _a;
            (_a = item.itemCampaignList) === null || _a === void 0 ? void 0 : _a.map(function (campaign) {
                campaign.selected = false;
            });
            campaign.selected = true;
            item.selectedCampaign = campaign;
            this.triggerCartItemChange([item]);
            this.setState({
                itemList: [].concat((0, _toConsumableArray3["default"])(this.state.itemList))
            });
        }
        /**
        * @method itemSpecPopoverChange
        * 把商品上已经选中的参数同步到备选参数数组中去。
        * @param visible 弹出框当前的可见状态
        * @param item 商品条目
        */

    }, {
        key: "itemSpecPopoverChange",
        value: function itemSpecPopoverChange(visible, item) {
            var _a;
            if (visible) {
                if (!item.attrOptions) return;
                (_a = item.selectedAttributes) === null || _a === void 0 ? void 0 : _a.map(function (selectedAttr) {
                    for (var i = 0; i < item.attrOptions.length; i++) {
                        var option = item.attrOptions[i];
                        if (selectedAttr.name === option.name) {
                            var title = selectedAttr.value.title;
                            for (var j = 0; j < option.values.length; j++) {
                                var value = option.values[j];
                                if (value.title === title) {
                                    value.selected = selectedAttr.value.selected;
                                } else {
                                    value.selected = false;
                                }
                            }
                            break;
                        }
                    }
                });
                this.setState({
                    itemList: [].concat((0, _toConsumableArray3["default"])(this.state.itemList))
                });
            }
        }
        /**
         * @method chooseItemSpec
         * 修改商品参数
         * @param val
         * @param attr
         */

    }, {
        key: "chooseItemSpec",
        value: function chooseItemSpec(val, attr) {
            attr.values.map(function (temp) {
                temp.selected = false;
            });
            val.selected = true;
            this.setState({
                itemList: [].concat((0, _toConsumableArray3["default"])(this.state.itemList))
            });
        }
        /**
         * @method commitItemSpecChange
         * 点OK正式修改商品属性
         * @param item
         */

    }, {
        key: "commitItemSpecChange",
        value: function commitItemSpecChange(item) {
            if (!item.attrOptions) return;
            item.selectedAttributes = [];
            item.attrOptions.map(function (spec) {
                spec.values.map(function (specItem) {
                    if (specItem.selected) {
                        item.selectedAttributes.push({
                            name: spec.name,
                            value: JSON.parse(JSON.stringify(specItem))
                        });
                    }
                });
            });
            this.props.onCartItemChange && this.props.onCartItemChange([item]);
            this.setState({
                itemList: [].concat((0, _toConsumableArray3["default"])(this.state.itemList))
            });
        }
        /***
         * @method composeAttrOptions
         * 组装编辑商品属性的弹出框
         * @param item 商品
         */

    }, {
        key: "composeAttrOptions",
        value: function composeAttrOptions(item) {
            var _this3 = this;

            var _a;
            if (!item.attrOptions) return "";
            return _react2["default"].createElement(
                "div",
                { className: "edit-item-attr-container" },
                _react2["default"].createElement(
                    "div",
                    { className: "param-list-container" },
                    (_a = item.attrOptions) === null || _a === void 0 ? void 0 : _a.map(function (attr) {
                        return _react2["default"].createElement(
                            "div",
                            { key: attr.name, className: "param" },
                            _react2["default"].createElement(
                                "div",
                                { className: "param-key" },
                                attr.name,
                                ":"
                            ),
                            _react2["default"].createElement(
                                "div",
                                { className: "param-value" },
                                attr.values.map(function (val) {
                                    return _react2["default"].createElement(
                                        "div",
                                        { key: val.value, className: val.selected ? "param-tag selected" : "param-tag", onClick: function onClick() {
                                                _this3.chooseItemSpec(val, attr);
                                            } },
                                        val.title
                                    );
                                })
                            )
                        );
                    }),
                    _react2["default"].createElement(
                        "div",
                        { className: "param" },
                        _react2["default"].createElement("div", { className: "param-key" }),
                        _react2["default"].createElement(
                            "div",
                            { className: "param-value" },
                            _react2["default"].createElement(
                                "div",
                                { className: "ok-btn", onClick: function onClick() {
                                        _this3.commitItemSpecChange(item);
                                    } },
                                "OK"
                            ),
                            _react2["default"].createElement(
                                "div",
                                { className: "cancel-btn" },
                                "Cancel"
                            )
                        )
                    )
                ),
                _react2["default"].createElement(
                    "div",
                    { className: "img-container" },
                    _react2["default"].createElement("img", { src: item.imgURL })
                )
            );
        }
    }, {
        key: "updateTotalAmount",
        value: function updateTotalAmount(item, num) {
            item.count = num;
            this.setState({
                itemList: [].concat((0, _toConsumableArray3["default"])(this.state.itemList))
            });
            this.triggerCartItemChange([item]);
        }
    }, {
        key: "deleteItem",
        value: function deleteItem(item) {
            this.props.onDelItem && this.props.onDelItem(item);
        }
    }, {
        key: "likeItem",
        value: function likeItem(item) {
            this.props.onLikeItem && this.props.onLikeItem(item);
        }
        // 通知外面修改购物车信息，包括数量，是否选中等

    }, {
        key: "triggerCartItemChange",
        value: function triggerCartItemChange(items) {
            this.props.onCartItemChange && this.props.onCartItemChange([].concat((0, _toConsumableArray3["default"])(items)));
        }
    }, {
        key: "choseAll",
        value: function choseAll(status) {
            this.state.itemList.map(function (item) {
                item.selected = status;
            });
            var itemList = [].concat((0, _toConsumableArray3["default"])(this.state.itemList));
            this.setState({
                itemList: itemList
            });
            this.triggerCartItemChange(itemList);
        }
        /**
         * @method setItemCheckStates 设置单个商品的选中和反选状态
         * @param item
         */

    }, {
        key: "setItemCheckStates",
        value: function setItemCheckStates(item) {
            var status = !item.selected;
            item.selected = status;
            this.setState({
                campaignInfo: (0, _extends3["default"])({}, this.state.campaignInfo),
                itemList: [].concat((0, _toConsumableArray3["default"])(this.state.itemList))
            });
            this.triggerCartItemChange([item]);
        }
        /**
         * @method getItemStateAll
         * 获取所有商品的状态，暴露给外部调用方。
         */

    }, {
        key: "getItemStateAll",
        value: function getItemStateAll() {
            return JSON.stringify(this.state.itemList);
        }
        /**
         * @determinItemStyle
         * 根据商品的属性决定背景样式
         * @param item
         */

    }, {
        key: "determinItemStyle",
        value: function determinItemStyle(item) {
            var styleClass = "cart-item-info";
            if (item.disabled) {
                styleClass += " disabled";
            }
            if (item.selected) {
                styleClass += " selected";
            }
            return styleClass;
        }
        /**
         * @determinGiftStyle
         * 根据赠品的属性决定背景样式
         * @param item
         */

    }, {
        key: "determinGiftStyle",
        value: function determinGiftStyle(item) {
            var _a;
            var styleClass = "gift-item-info";
            if (item.selected) {
                styleClass += " selected";
            }
            if (((_a = this.state.campaignInfo) === null || _a === void 0 ? void 0 : _a.offerGetMethod) === 'O') {
                styleClass += " chose-gift";
            }
            return styleClass;
        }
    }, {
        key: "chooseGift",
        value: function chooseGift(e) {
            var _a, _b;
            this.props.onChooseGift({
                "campaignId": (_a = this.state.campaignInfo) === null || _a === void 0 ? void 0 : _a.id,
                "buygetnRuleId": (_b = this.state.campaignInfo) === null || _b === void 0 ? void 0 : _b.buygetnRuleId,
                "giftObjId": e.target.value
            });
        }
    }, {
        key: "renderGift",
        value: function renderGift() {
            var _this4 = this;

            var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
            // 多个赠品，需要选择
            var needChoose = ((_a = this.state.campaignInfo) === null || _a === void 0 ? void 0 : _a.offerGetMethod) === 'O';
            if (needChoose) {
                var defaultVal = (_b = this.state.campaignInfo.giftOffers) === null || _b === void 0 ? void 0 : _b.filter(function (item) {
                    return item.isSelected === 'Y';
                })[0];
                return _react2["default"].createElement(
                    _react2["default"].Fragment,
                    null,
                    _react2["default"].createElement(
                        _fdx.Radio.Group,
                        { defaultValue: defaultVal === null || defaultVal === void 0 ? void 0 : defaultVal.giftObjId, onChange: function onChange(e) {
                                return _this4.chooseGift(e);
                            } },
                        (_d = (_c = this.state.campaignInfo) === null || _c === void 0 ? void 0 : _c.giftOffers) === null || _d === void 0 ? void 0 : _d.map(function (gift) {
                            return _react2["default"].createElement(
                                _fdx.Radio,
                                { value: gift.giftObjId },
                                _this4.giftElement(gift)
                            );
                        })
                    ),
                    (_f = (_e = this.state.campaignInfo) === null || _e === void 0 ? void 0 : _e.giftCoupons) === null || _f === void 0 ? void 0 : _f.map(function (gift) {
                        return _this4.giftElement(gift);
                    })
                );
            } else {
                return _react2["default"].createElement(
                    _react2["default"].Fragment,
                    null,
                    (_h = (_g = this.state.campaignInfo) === null || _g === void 0 ? void 0 : _g.giftOffers) === null || _h === void 0 ? void 0 : _h.map(function (gift) {
                        return _this4.giftElement(gift);
                    }),
                    (_k = (_j = this.state.campaignInfo) === null || _j === void 0 ? void 0 : _j.giftCoupons) === null || _k === void 0 ? void 0 : _k.map(function (gift) {
                        return _this4.giftElement(gift);
                    })
                );
            }
        }
    }, {
        key: "render",
        value: function render() {
            var _this5 = this;

            var _a, _b;
            return _react2["default"].createElement(
                _react2["default"].Fragment,
                null,
                ((_a = this.state.campaignInfo) === null || _a === void 0 ? void 0 : _a.name) ? _react2["default"].createElement(
                    "div",
                    { className: "campaignInfo" },
                    _react2["default"].createElement(
                        "span",
                        { className: "dis" },
                        "Money Off"
                    ),
                    _react2["default"].createElement(
                        "span",
                        null,
                        this.state.campaignInfo.name
                    )
                ) : null,
                _react2["default"].createElement("span", { className: "checkAll" + this.props.shopId, onClick: function onClick() {
                        return _this5.choseAll(true);
                    } }),
                _react2["default"].createElement("span", { className: "uncheck" + this.props.shopId, onClick: function onClick() {
                        return _this5.choseAll(false);
                    } }),
                (_b = this.state.itemList) === null || _b === void 0 ? void 0 : _b.map(function (item) {
                    var _a, _b, _c;
                    return _react2["default"].createElement(
                        "div",
                        { key: item.id },
                        _react2["default"].createElement(
                            _fdx.Row,
                            { className: function () {
                                    return _this5.determinItemStyle(item);
                                }() },
                            item.disabled ? _react2["default"].createElement(
                                _fdx.Col,
                                { className: "item-disabled-icon", span: 1 },
                                _react2["default"].createElement(_fdx.Icon, { type: "exclamation-circle", theme: "filled" })
                            ) : _react2["default"].createElement(
                                _fdx.Col,
                                { className: "checkbox-col", span: 1 },
                                _react2["default"].createElement(_fdx.Checkbox, { onChange: function onChange() {
                                        _this5.setItemCheckStates(item);
                                    }, checked: item.selected })
                            ),
                            _react2["default"].createElement(
                                _fdx.Col,
                                { span: 9 },
                                _react2["default"].createElement(
                                    "div",
                                    { className: "item-info" },
                                    _react2["default"].createElement(
                                        "div",
                                        null,
                                        _react2["default"].createElement("img", { className: "item-pic", src: item.imgURL })
                                    ),
                                    _react2["default"].createElement(
                                        "div",
                                        { className: "item-detail" },
                                        _react2["default"].createElement(
                                            "p",
                                            { className: "item-name" },
                                            item.name
                                        ),
                                        item.disabled ? "" : ((_a = item.itemCampaignList) === null || _a === void 0 ? void 0 : _a.length) > 0 ? _react2["default"].createElement(
                                            _fdx.Popover,
                                            { placement: "bottom", content: function () {
                                                    return _this5.composeItemCampaignList(item.itemCampaignList, item);
                                                }(), trigger: "click" },
                                            _react2["default"].createElement(
                                                "div",
                                                { className: "campaign-container" },
                                                _react2["default"].createElement(
                                                    "span",
                                                    { className: "campaign-desc" },
                                                    item.selectedCampaign && item.selectedCampaign.desc
                                                ),
                                                _react2["default"].createElement(_fdx.Icon, { type: "down" })
                                            )
                                        ) : "",
                                        item.disabled ? "" : _react2["default"].createElement(
                                            "div",
                                            { className: "certified-icons" },
                                            item.refund7 ? _react2["default"].createElement("img", { src: "data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz4KPHN2ZyB3aWR0aD0iMThweCIgaGVpZ2h0PSIxOHB4IiB2aWV3Qm94PSIwIDAgMTggMTgiIHZlcnNpb249IjEuMSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayI+CiAgICA8dGl0bGU+N+WkqTwvdGl0bGU+CiAgICA8ZyBpZD0i6K6i5Y2VJmFtcDvotK3nianovaYiIHN0cm9rZT0ibm9uZSIgc3Ryb2tlLXdpZHRoPSIxIiBmaWxsPSJub25lIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiPgogICAgICAgIDxnIGlkPSLmiJHnmoTorqLljZUiIHRyYW5zZm9ybT0idHJhbnNsYXRlKC00MDguMDAwMDAwLCAtNTA2LjAwMDAwMCkiPgogICAgICAgICAgICA8ZyBpZD0ibGlzdC0jMSIgdHJhbnNmb3JtPSJ0cmFuc2xhdGUoMzIwLjAwMDAwMCwgNDAwLjAwMDAwMCkiPgogICAgICAgICAgICAgICAgPGcgaWQ9IuiuouWNleS6p+WTgTEiIHRyYW5zZm9ybT0idHJhbnNsYXRlKDAuMDAwMDAwLCAzOC4wMDAwMDApIj4KICAgICAgICAgICAgICAgICAgICA8ZyBpZD0iN+WkqSIgdHJhbnNmb3JtPSJ0cmFuc2xhdGUoODguMDAwMDAwLCA2OC4wMDAwMDApIj4KICAgICAgICAgICAgICAgICAgICAgICAgPHJlY3QgaWQ9IlJlY3RhbmdsZSIgZmlsbD0iIzE0Qzk3RSIgeD0iMCIgeT0iMCIgd2lkdGg9IjE4IiBoZWlnaHQ9IjE4Ij48L3JlY3Q+CiAgICAgICAgICAgICAgICAgICAgICAgIDx0ZXh0IGlkPSI3IiBmb250LWZhbWlseT0iTnVuaXRvU2Fucy1CbGFjaywgTnVuaXRvIFNhbnMiIGZvbnQtc2l6ZT0iMTIiIGZvbnQtd2VpZ2h0PSI3MDAiIGZpbGw9IiNGRkZGRkYiPgogICAgICAgICAgICAgICAgICAgICAgICAgICAgPHRzcGFuIHg9IjUuNCIgeT0iMTMiPjc8L3RzcGFuPgogICAgICAgICAgICAgICAgICAgICAgICA8L3RleHQ+CiAgICAgICAgICAgICAgICAgICAgPC9nPgogICAgICAgICAgICAgICAgPC9nPgogICAgICAgICAgICA8L2c+CiAgICAgICAgPC9nPgogICAgPC9nPgo8L3N2Zz4=" }) : "",
                                            item.certified ? _react2["default"].createElement("img", { src: "data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz4KPHN2ZyB3aWR0aD0iMThweCIgaGVpZ2h0PSIxOHB4IiB2aWV3Qm94PSIwIDAgMTggMTgiIHZlcnNpb249IjEuMSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayI+CiAgICA8dGl0bGU+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5vbnplcm8iPgogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIDxwYXRoIGQ9Ik01LjQ0LDAgQzUuNjE2NzMxMTIsMCA1Ljc2LDAuMTQzMjY4ODggNS43NiwwLjMyIEM1Ljc2LDEuOTEwNTgwMDggNC40NzA1ODAwOCwzLjIgMi44OCwzLjIgQzEuMjg5NDE5OTIsMy4yIDAsMS45MTA1ODAwOCAwLDAuMzIgQzAsMC4xNDMyNjg4OCAwLjE0MzI2ODg4LDAgMC4zMiwwIEMwLjQ5NjczMTEyLDAgMC42NCwwLjE0MzI2ODg4IDAuNjQsMC4zMiBDMC42NCwxLjU1NzExNzg0IDEuNjQyODgyMTYsMi41NiAyLjg4LDIuNTYgQzQuMTE3MTE3ODQsMi41NiA1LjEyLDEuNTU3MTE3ODQgNS4xMiwwLjMyIEM1LjEyLDAuMTQzMjY4ODggNS4yNjMyNjg4OCwwIDUuNDQsMCBaIiBpZD0iUGF0aCI+PC9wYXRoPgogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgPC9nPgogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICA8L2c+CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgPC9nPgogICAgICAgICAgICAgICAgICAgICAgICAgICAgPC9nPgogICAgICAgICAgICAgICAgICAgICAgICA8L2c+CiAgICAgICAgICAgICAgICAgICAgPC9nPgogICAgICAgICAgICAgICAgPC9nPgogICAgICAgICAgICA8L2c+CiAgICAgICAgPC9nPgogICAgPC9nPgo8L3N2Zz4=" }) : ""
                                        )
                                    )
                                )
                            ),
                            _react2["default"].createElement(
                                _fdx.Col,
                                { span: 5 },
                                item.disabled ? _react2["default"].createElement(
                                    "div",
                                    { className: "spec-container-disabled" },
                                    item.selectedAttributes && ((_b = item.selectedAttributes) === null || _b === void 0 ? void 0 : _b.map(function (attr) {
                                        return _react2["default"].createElement(
                                            "p",
                                            { key: attr.value.value },
                                            attr.name,
                                            ": ",
                                            attr.value.title
                                        );
                                    }))
                                ) : item.selectedAttributes ? _react2["default"].createElement(
                                    _fdx.Popover,
                                    { ref: "itemSpecPopover", onVisibleChange: function onVisibleChange(visible) {
                                            _this5.itemSpecPopoverChange(visible, item);
                                        }, placement: "bottomLeft", content: function () {
                                            return item.attrOptions.length > 0 ? _this5.composeAttrOptions(item) : '';
                                        }(), trigger: "click" },
                                    _react2["default"].createElement(
                                        "div",
                                        { className: "spec-container" },
                                        item.selectedAttributes && ((_c = item.selectedAttributes) === null || _c === void 0 ? void 0 : _c.map(function (attr) {
                                            return _react2["default"].createElement(
                                                "p",
                                                { key: attr.value.value },
                                                attr.name,
                                                ": ",
                                                attr.value.title
                                            );
                                        }))
                                    )
                                ) : ""
                            ),
                            _react2["default"].createElement(
                                _fdx.Col,
                                { className: "price-container", span: 3 },
                                _react2["default"].createElement(
                                    "p",
                                    { className: "current-price" },
                                    item.currentPrice
                                ),
                                item.disabled ? "" : _react2["default"].createElement(
                                    "div",
                                    null,
                                    _react2["default"].createElement(
                                        "p",
                                        { className: "origin-price" },
                                        item.originPrice
                                    ),
                                    _react2["default"].createElement(
                                        "p",
                                        { className: "cut-off" },
                                        item.cutOff
                                    )
                                )
                            ),
                            _react2["default"].createElement(
                                _fdx.Col,
                                { className: "total-price", span: 4 },
                                _react2["default"].createElement(
                                    "p",
                                    { className: "total-amount" },
                                    item.totalAmount
                                ),
                                item.disabled ? _react2["default"].createElement(
                                    "p",
                                    { className: "disabled-text" },
                                    item.count
                                ) : _react2["default"].createElement(_skuInputNumber2["default"], { min: item.minNumber, max: item.maxNumber, disabled: !(item.hasStock == null || item.hasStock), value: item.count, onChange: function onChange(num) {
                                        _this5.updateTotalAmount(item, num);
                                    } })
                            ),
                            _react2["default"].createElement(
                                _fdx.Col,
                                { className: "btns", span: 2 },
                                _react2["default"].createElement(_fdx.Icon, { className: "ope-icon", type: "delete", onClick: function onClick() {
                                        _this5.deleteItem(item);
                                    } }),
                                item.disabled ? "" : item.isCollection ? _react2["default"].createElement(_fdx.Icon, { className: "ope-icon", style: { color: '#ed2121' }, theme: "filled", type: "heart", onClick: function onClick() {
                                        _this5.likeItem(item);
                                    } }) : _react2["default"].createElement(_fdx.Icon, { className: "ope-icon", type: "heart", onClick: function onClick() {
                                        _this5.likeItem(item);
                                    } })
                            )
                        )
                    );
                }),
                this.renderGift()
            );
        }
    }]);
    return CampaignItem;
}(_react.Component);
/**
 * @class CartItem
 * 购物车中的一个店铺，包含满系活动和产品条目，此组件界面和数据结构都比较复杂，状态全部由组件自己管理。
 */


var CartItem = function (_Component2) {
    (0, _inherits3["default"])(CartItem, _Component2);

    function CartItem(props) {
        (0, _classCallCheck3["default"])(this, CartItem);

        var _this6 = (0, _possibleConstructorReturn3["default"])(this, (CartItem.__proto__ || Object.getPrototypeOf(CartItem)).call(this, props));

        _this6.state = {
            shopInfo: (0, _extends3["default"])({}, props.cartItem.shopInfo),
            campaigns: [].concat((0, _toConsumableArray3["default"])(props.cartItem.campaigns))
        };
        return _this6;
    }

    (0, _createClass3["default"])(CartItem, [{
        key: "componentWillReceiveProps",
        value: function componentWillReceiveProps(nextProps) {
            this.setState({
                shopInfo: (0, _extends3["default"])({}, nextProps.cartItem.shopInfo),
                campaigns: [].concat((0, _toConsumableArray3["default"])(nextProps.cartItem.campaigns))
            });
        }
    }, {
        key: "choseShop",
        value: function choseShop(val) {
            var info = (0, _extends3["default"])({}, this.state.shopInfo);
            info.selected = val;
            this.setState({
                shopInfo: info
            });
        }
        /**
         * @method composeShopCoupons
         * 组装店铺级的优惠券结构
         */

    }, {
        key: "composeShopCoupons",
        value: function composeShopCoupons() {
            var _a, _b;
            var onCollectCoupon = this.props.onCollectCoupon;

            return this.state.shopInfo.shopCouponList.length > 0 ? (_b = (_a = this.state.shopInfo) === null || _a === void 0 ? void 0 : _a.shopCouponList) === null || _b === void 0 ? void 0 : _b.map(function (coupon) {
                return _react2["default"].createElement(
                    "div",
                    { key: coupon.id, className: "shop-coupon-list" },
                    _react2["default"].createElement(
                        "div",
                        { className: "coupon-item" },
                        _react2["default"].createElement(
                            "div",
                            { className: "coupon-left" },
                            _react2["default"].createElement(
                                "div",
                                { className: "coupon-num" },
                                coupon.amount
                            ),
                            _react2["default"].createElement(
                                "div",
                                { className: "coupon-title" },
                                coupon.desc
                            ),
                            _react2["default"].createElement(
                                "div",
                                { className: "coupon-time" },
                                coupon.activeTime
                            )
                        ),
                        _react2["default"].createElement(
                            "div",
                            { className: "coupon-right" },
                            coupon.collected ? _react2["default"].createElement("div", { className: "collected-icon" }) : _react2["default"].createElement(
                                "div",
                                { className: "collect-btn", onClick: function onClick() {
                                        onCollectCoupon && onCollectCoupon(coupon);
                                    } },
                                "Collect"
                            )
                        )
                    )
                );
            }) : _react2["default"].createElement(
                "div",
                null,
                "No Coupon"
            );
        }
        /**
         * @determinShopStyle
         * 根据店铺的属性决定背景样式
         * @param item
         */

    }, {
        key: "determinShopStyle",
        value: function determinShopStyle(shopInfo) {
            var styleClass = "cart-shop-info";
            if (shopInfo.disabled) {
                styleClass += " disabled";
            }
            if (shopInfo.selected) {
                styleClass += " selected";
            }
            return styleClass;
        }
        /**
         * @method setCheckStatusAll 设置全部商品的选中状态
         */

    }, {
        key: "setCheckStatusAll",
        value: function setCheckStatusAll() {
            var info = (0, _extends3["default"])({}, this.state.shopInfo);
            info.selected = !this.state.shopInfo.selected;
            this.setState({
                shopInfo: info
            });
            if (info.selected) {
                var elements = document.getElementsByClassName("checkAll" + info.shopId);
                if ((elements === null || elements === void 0 ? void 0 : elements.length) > 0) {
                    for (var index = 0; index < elements.length; index++) {
                        var element = elements[index];
                        element.click();
                    }
                }
            } else {
                var _elements = document.getElementsByClassName("uncheck" + info.shopId);
                if ((_elements === null || _elements === void 0 ? void 0 : _elements.length) > 0) {
                    for (var _index = 0; _index < _elements.length; _index++) {
                        var _element = _elements[_index];
                        _element.click();
                    }
                }
            }
        }
        // 任一商品被选中或取消选中

    }, {
        key: "cartItemChange",
        value: function cartItemChange(val) {
            var _a;
            var itemList = [];
            var selectedIndex = 0;
            (_a = this.state.campaigns) === null || _a === void 0 ? void 0 : _a.forEach(function (campaign) {
                campaign.itemList.forEach(function (item) {
                    var _a;
                    if (item.id === ((_a = val[0]) === null || _a === void 0 ? void 0 : _a.id)) {
                        itemList.push(val[0]);
                    } else {
                        itemList.push(item);
                    }
                });
            });
            this.props.onCartItemChange(val);
            itemList.map(function (item) {
                if (item.selected) {
                    selectedIndex++;
                }
            });
            this.choseShop(selectedIndex === itemList.length);
        }
    }, {
        key: "render",
        value: function render() {
            var _this7 = this;

            var _a;
            return _react2["default"].createElement(
                "div",
                { className: "cart-item-container" },
                _react2["default"].createElement(
                    _fdx.Row,
                    { className: function () {
                            return _this7.determinShopStyle(_this7.state.shopInfo);
                        }() },
                    _react2["default"].createElement(
                        _fdx.Col,
                        { className: "checkbox-col", span: 1 },
                        this.state.shopInfo.disabled ? "" : _react2["default"].createElement(_fdx.Checkbox, { checked: this.state.shopInfo.selected, onChange: function onChange() {
                                _this7.setCheckStatusAll();
                            } })
                    ),
                    _react2["default"].createElement(
                        _fdx.Col,
                        { className: "shop-info", span: 20 },
                        _react2["default"].createElement("span", { className: "shop-icon" }),
                        _react2["default"].createElement(
                            "span",
                            { className: "shop-name" },
                            this.state.shopInfo.shopName
                        ),
                        _react2["default"].createElement(_fdx.Icon, { className: "msg-icon", type: "message", theme: "filled" }),
                        this.state.shopInfo.disabled ? "" : _react2["default"].createElement(
                            "span",
                            { className: "tip" },
                            this.state.shopInfo.tip
                        )
                    ),
                    this.state.shopInfo.disabled ? "" : this.state.shopInfo.shopCouponList ? _react2["default"].createElement(
                        _fdx.Col,
                        { className: "coupon", span: 3 },
                        _react2["default"].createElement(
                            _fdx.Popover,
                            { placement: "bottomRight", content: function () {
                                    return _this7.composeShopCoupons();
                                }(), trigger: "click" },
                            _react2["default"].createElement(
                                "div",
                                { className: "shop-coupon-icon", onClick: function onClick() {
                                        _this7.props.dropDownCoupon && _this7.props.dropDownCoupon(_this7.props.cartItem);
                                    } },
                                "Coupons"
                            )
                        )
                    ) : ""
                ),
                ((_a = this.state.campaigns) === null || _a === void 0 ? void 0 : _a.length) > 0 ? this.state.campaigns.map(function (campaignItem) {
                    return _react2["default"].createElement(CampaignItem, { campaignItem: campaignItem, choseShop: function choseShop(val) {
                            return _this7.choseShop(val);
                        }, onDelItem: _this7.props.onDelItem, onLikeItem: _this7.props.onLikeItem, onCartItemChange: function onCartItemChange(val) {
                            return _this7.cartItemChange(val);
                        }, onChooseGift: function onChooseGift(val) {
                            return _this7.props.onChooseGift(val);
                        }, shopId: _this7.state.shopInfo.shopId });
                }) : null
            );
        }
    }]);
    return CartItem;
}(_react.Component);

exports["default"] = CartItem;