# PressConvertExchangeTemplate Exchange Template Component

# πŸ“¦ Component Introduction

PressConvertExchangeTemplate is a template component that encapsulates exchange list and point consumption functionality, integrating press-convert-exchange-list and press-convert-point-cost sub-components to provide complete point exchange features.

✨ Architecture Advantages:

  • Mixin Shared Logic - Avoid code duplication
  • Independent Template Files - Support different DOM structures
  • Auto Props Pass-through - Using v-bind="{ ...$props, ...$attrs }" and explicit event forwarding
  • Easy to Maintain and Extend - Modify logic only in mixin, modify structure only in corresponding template

# πŸ—οΈ Architecture Design

# File Structure

press-convert-exchange-template/
β”œβ”€β”€ press-convert-exchange-template.vue  # Main component (routing dispatcher)
β”œβ”€β”€ template-mixin.js                    # Common logic Mixin
β”œβ”€β”€ pwd/
β”‚   └── index.vue                       # PWD template (independent DOM structure)
β”œβ”€β”€ party/
β”‚   └── index.vue                       # Party template (independent DOM structure)
β”œβ”€β”€ demo.vue                             # Example code
└── README.md                            # Documentation

# Architecture Principle

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  press-convert-exchange-template.vue        β”‚
β”‚  (Main component - dispatcher)              β”‚
β”‚                                             β”‚
β”‚  <TemplatePwd v-if="type === 'pwd'" ... />  β”‚
β”‚  <TemplateParty v-else ... />               β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
           β”‚
           β”œβ”€β”€β”€ type="pwd" ──→ pwd/index.vue (PWD template)
           β”‚                    β”œβ”€ mixins: [templateMixin]
           β”‚                    β”œβ”€ Independent DOM structure
           β”‚                    └─ Exclusive prop: pwdWrapBg
           β”‚
           └─── type="party" ──→ party/index.vue (Party template)
                                  β”œβ”€ mixins: [templateMixin]
                                  └─ Independent DOM structure

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  template-mixin.js                  β”‚
β”‚  (Common logic - shared by all)     β”‚
β”‚                                     β”‚
β”‚  - props definition                 β”‚
β”‚  - emits definition                 β”‚
β”‚  - methods (event handlers)         β”‚
β”‚  - components (sub-components)      β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

# Template Layout Structure

Both templates share the same DOM layout:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   point-cost        β”‚  ← Point info + refresh button
β”‚     <slot />        β”‚  ← Default slot (inside point-cost)
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚   exchange-list     β”‚  ← Exchange item list
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

# 🎯 Features

  • βœ… Support 2 preset templates (PWD/Party), each with independent DOM structure
  • βœ… Exchange list display
  • βœ… Point information display
  • βœ… Slot extension support
  • βœ… Event callback handling
  • βœ… Mixin shared logic, avoid code duplication

# πŸ“– Usage

# Basic Usage - Using PWD Template

<template>
  <PressConvertExchangeTemplate
    type="pwd"
    :exchange-list="exchangeList"
    :point-icon="pointIcon"
    :point-info="pointInfo"
    @exchangeClick="handleExchangeClick"
    @showRewardExplain="handleShowRewardExplain"
    @refresh="handleRefresh"
  />
</template>

<script>
import PressConvertExchangeTemplate from 'press-plus/press-convert-exchange-template/press-convert-exchange-template';

export default {
  components: {
    PressConvertExchangeTemplate,
  },
  data() {
    return {
      pointIcon: 'https://example.com/point-icon.png',
      exchangeList: [
        {
          pic: 'https://example.com/reward.png',
          name: '$100 Coupon',
          need_money: 1000,
          num: 50,
          showMoney: true,
          btnTxt: 'Exchange Now',
          disabled: false,
        },
      ],
      pointInfo: {
        pointIcon: 'https://example.com/point-icon.png',
        pointCount: 5000,
        expireTime: '30 days',
      },
    };
  },
  methods: {
    handleExchangeClick(item) {
      console.log('Exchange item:', item);
    },
    handleShowRewardExplain(index) {
      console.log('Show reward explanation:', index);
    },
    handleRefresh() {
      console.log('Refresh points');
    },
  },
};
</script>

# Switch Between Templates

<!-- PWD Template - PWD exclusive layout -->
<PressConvertExchangeTemplate type="pwd" ... />

<!-- Party Template - Party carnival layout -->
<PressConvertExchangeTemplate type="party" ... />

# Using Slots

The default slot is located inside the point-cost component (within the point info area).

<PressConvertExchangeTemplate
  type="pwd"
  :exchange-list="exchangeList"
  :point-icon="pointIcon"
  :point-info="pointInfo"
>
  <div class="custom-content">
    <button @click="handleCustomAction">
      View More Rewards
    </button>
  </div>
</PressConvertExchangeTemplate>

# πŸ“‹ Props

# Template Configuration

Prop Type Default Description
type String 'pwd' Template type: 'pwd' / 'party'
Prop Type Default Description
exchangeList Array [] Exchange list data
pointIcon String '' Point icon URL
exchangeListBg String '' Exchange list background image
tagBg String '' Exchange list tag background image
redeemRewardBg String '' Reward box background image
rewardTextColor String '' Reward text color
rewardBtnBg String '' Reward button background image
rewardBtnTextColor String '' Reward button text color
Prop Type Default Description
pointInfo Object {} Point information object
pointTextColor String '' Point text color

# PWD Template Exclusive

Prop Type Default Description
pwdWrapBg String '' Background image for PWD template outer container

# exchangeList Data Structure

[
  {
    pic: 'https://example.com/reward.png',  // Reward image
    name: '$100 Coupon',                     // Reward name
    need_money: 1000,                        // Required points
    num: 50,                                 // Remaining quantity
    showMoney: true,                         // Show points or not
    btnTxt: 'Exchange Now',                  // Button text
    disabled: false,                         // Disabled or not
  }
]

# pointInfo Data Structure

{
  pointIcon: 'https://example.com/point-icon.png',  // Point icon
  pointCount: 5000,                                  // Point count
  expireTime: '30 days',                             // Expiration hint, displays as "XεŽε€±ζ•ˆ"; 0 = no expiry
}

# πŸŽͺ Events

Event Parameters Description
exchangeClick item: Object Triggered when exchange button is clicked, returns exchange item data
showRewardExplain index: Number Triggered when reward image is clicked, returns index
refresh - Triggered when refresh button is clicked

# 🎨 Slots

Slot Description
default Default slot, located inside the point-cost component

# πŸ’‘ Template Differences

# PWD Template (pwd/index.vue)

Layout:

point-cost (point info + refresh)
  └─ <slot />
exchange-list

Features:

  • Supports pwdWrapBg outer container background image
  • Suitable for PWD activity scenarios

# Party Template (party/index.vue)

Layout:

point-cost (point info + refresh)
  └─ <slot />
exchange-list

Features:

  • Suitable for party activity scenarios

# πŸ”§ Extend New Template

# Step 1: Create New Template Directory and File festival/index.vue

<template>
  <div class="press-exchange-festival">
    <point-cost
      :point-info="pointInfo"
      :text-color="pointTextColor"
      @refresh="handleRefresh"
    >
      <slot />
    </point-cost>
    <exchange-list
      :exchange-list="exchangeList"
      :point-icon="pointIcon"
      :exchange-list-bg="exchangeListBg"
      :tag-bg="tagBg"
      :redeem-reward-bg="redeemRewardBg"
      :reward-text-color="rewardTextColor"
      :reward-btn-bg="rewardBtnBg"
      :reward-btn-text-color="rewardBtnTextColor"
      @exchangeClick="handleExchangeClick"
      @showRewardExplain="handleShowRewardExplain"
    />
  </div>
</template>

<script>
import templateMixin from '../template-mixin';

export default {
  name: 'PressExchangeTemplateFestival',
  mixins: [templateMixin],
};
</script>

# Step 2: Register in Main Component

// press-convert-exchange-template.vue
import TemplateFestival from './festival/index.vue';

export default {
  components: {
    TemplatePwd,
    TemplateParty,
    TemplateFestival,
  },
  props: {
    type: {
      validator: value => ['pwd', 'party', 'festival'].includes(value),
    },
  },
};

# πŸ“ Notes

  1. Modify Common Logic - Modifying template-mixin.js affects all templates
  2. Modify Template Structure - Modifying pwd/index.vue or party/index.vue only affects corresponding template
  3. Props Auto Pass-through - Main component props are automatically passed to sub-templates
  4. Event Auto Pass-through - Sub-template events automatically bubble to main component
  5. Image URLs need to be valid network addresses or local paths
  6. Recommend validating point balance and stock before exchange

# πŸ“¦ Dependencies

  • press-convert-exchange-list - Exchange list component
  • press-convert-point-cost - Point cost component