<!--components/couponWrap/index.wxml-->
<block wx:if= "{{list.length>0}}">
    <view class="coupon-list">
        <view wx:for="{{list}}" wx:key="coupon" class="coupon-item coupon-item-ex-class">
           <!-- 礼包 -->
           <view class="coupon-card">
                <view class="coupon-card-left">
                      <view class="coupon-prices {{nums.priceClass(item)}}">
                        <block wx:if="{{item.type.value == 'C'}}">
                            <text>{{nums.formatReduceCost(item)}}</text>
                            <text class="_unit">元</text>
                        </block>
                        <block wx:elif="{{item.type.value == 'D'}}">
                            <text>{{nums.formatDiscount(item)}}</text>
                            <text class="_unit">折</text>
                        </block>
                      </view>
                      <view class="coupon-condition">{{nums.formatLeastCost(item)}}</view>
                </view>
                <view class="coupon-card-right">
                    <view class="_title">{{item.title}}</view>
                    <view class="_time_des">{{item.validTimesStr}}</view>
                </view>
                <block wx:if="{{item.isSn}}">
                    <view wx:if="{{item.couponState == 0}}" class="coupon-card-btn">
                      <jumpmallapp>立即使用</jumpmallapp>
                    </view>
                    <view class="coupon-card-btn gray" wx:else>
                        {{item.stateStr}}
                    </view>
                </block>
                <view class="coupon-card-num" wx:else>
                    {{item.num}}张
                </view>
           </view>
           <view class="coupon-split">
                 <view class="coupon-circule _left coupon-circule-ex-class" ></view>
                 <view class="coupon-circule _right coupon-circule-ex-class"></view>
           </view>

           <view class="coupon-detail">
                <view class="fold-title" data-index= "{{index}}" catchtap="exFoldPanel">使用规则 
                    <image wx:if="{{!flodMap[index]}}" class="fold-btn" src="../../images/welfareMall/down-ico.png" />
                    <image wx:else class="fold-btn" src="../../images/welfareMall/up-ico.png" />
                </view>
                <block wx:if="{{flodMap[index]}}">
                   <view class="coupon-detail-line" style="margin-top: 22rpx;">
                        <text class="_key">适用门店：</text>
                        <block wx:if="{{item.bindShopType == 1}}">
                          <text>全国所有门店</text>
                        </block>
                        <block wx:elif="{{item.bindShopType == 2 || item.bindShopType == 4}}">
                           <text>适用部分门店</text>
                           <text class="look_more_txt" data-index="{{index}}" catchtap="toFixStorePage">点击查看>></text>
                        </block>
                        <block wx:elif="{{item.bindShopType == 3 }}">
                           <text>随领取门店可用</text>
                        </block>
                   </view>
                   <view class="coupon-detail-line">
                        <text class="_key">适用商品：</text>
                        <block wx:if="{{item.bindGoodsType == 1}}">
                          <text>特价商品除外</text>
                        </block>
                        <block wx:elif="{{item.bindGoodsType == 2 || item.bindGoodsType == 4}}">
                           <text>适用部分商品</text>
                           <text class="look_more_txt" data-index="{{index}}" catchtap="toFixFoodPage">点击查看>></text>
                        </block>
                   </view>
                   <view class="coupon-detail-line">
                        <text class="_key">适用场景：</text>
                        <text>门店</text>
                   </view>

                   <view class="coupon-detail-line">
                        <text class="_key">使用规则：</text>
                   </view>

                   <view class="coupon-detail-des">
                       {{item.description}}
                   </view>

                </block>

           </view>

        </view>
    </view>

    <!-- 弹窗 -->

</block>


<wxs module="nums">
        module.exports.formatReduceCost = function (item) {
            if (item.formatReduceCost) {
                return item.formatReduceCost;
            } else if (item.reduceCost) {
                return parseFloat(parseInt(item.reduceCost * 100) / 10000)
            }
            return 0
        }
        module.exports.formatLeastCost = function (item) {
            if (!item.formatLeastCost) {
                item.formatLeastCost = parseFloat(parseInt((item.leastCost || 0) * 100) / 10000)
            }
            if (item.formatLeastCost == 0) {
                return "无限制"
            }
            return "满" + item.formatLeastCost + "元"
        }
        module.exports.formatDiscount = function(item) {
            if (item.formatDiscount) {
                return item.formatDiscount
            } else if (item.discount) {
                return parseFloat(parseInt((item.discount || 0) * 10) / 100)
            }
            return 0
        }
        module.exports.priceClass = function(item) {
            if (item.type.value == "C") {
                if (item.reduceCost >= 100) {
                    return "_small"
                }
                return 100
            }
            if (item.type.value == "D" ) {
                if (item.discount >= 10) {
                    return "_small"
                }
                return ""
            }
            return ""
        }
</wxs>