123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536 |
- <template>
- <app-layout>
- <view class="code-info" :style="{backgroundImage: 'url('+ background + ')'}">
- <view class="code">{{code}}</view>
- <view v-if="exchange == 0">该兑换码包含{{list.length}}种礼品,您可以{{mode == 0 ? '全部':'任选一件'}}兑换:</view>
- <view v-if="exchange == 1">于{{r_raffled_at}}兑换以下礼品</view>
- </view>
- <view>
- <view class="rewards" v-for="(item,index) in list" :key="index">
- <view class="rewards-top dir-left-nowrap cross-center" :class="mode == 1 ? 'active-item':''">
- <app-radio width="88" :height="item.type == 'integral' || item.type == 'balance' || item.type == 'svip' ? '36':'140'" @click="toggle" :value="item.active" :item="item" :theme="getTheme" type="round" v-if="mode == 1">
- </app-radio>
- <view v-if="item.type == 'goods'" class="dir-left-nowrap card goods">
- <image class="card-img" mode="aspectFill" :src="item.goods_info.cover_pic"></image>
- <view class="card-info">
- <view class="t-omit-two card-name">{{item.goods_info.name}}</view>
- <view class="attr">{{item.goods_info.attr_str}}</view>
- <view class="dir-right-nowrap">
- <div class="goods-num" :class="getTheme + '-m-text ' + getTheme">x{{item.goods_num}}</div>
- </view>
- </view>
- </view>
- <view v-if="item.type == 'card'" class="dir-left-nowrap card">
- <image class="card-img" mode="aspectFill" v-if="item.card_info.pic_url" :src="item.card_info.pic_url"></image>
- <view class="card-info">
- <view class="dir-left-nowrap">
- <image src="./../image/card.png"></image>
- <view class="t-omit-two card-name">{{item.card_info.name}}</view>
- </view>
- <view class="main-between cross-center">
- <div class="card-number" :class="getTheme + '-m-text ' + getTheme + '-m-back-o ' + getTheme">剩余{{item.card_info.number}}次</div>
- <div class="card-num" :class="getTheme + '-m-text ' + getTheme">x{{item.card_num}}</div>
- </view>
- </view>
- </view>
- <view v-if="item.type == 'coupon'" class="dir-left-nowrap card">
- <view class="card-info">
- <view class="dir-left-nowrap">
- <image src="./../image/coupon.png"></image>
- <view class="t-omit-two card-name">{{item.coupon_info.name}}</view>
- </view>
- <view class="main-between cross-center">
- <div v-if="item.coupon_info.type == 1" class="card-number" :class="getTheme + '-m-text ' + getTheme + '-m-back-o ' + getTheme">{{item.coupon_info.discount}}折 满{{item.coupon_info.min_price == 0 ? '任意金额': '¥'+item.coupon_info.min_price}}可用 <text style="margin-left: 10rpx" v-if="item.coupon_info.discount_limit">优惠上限¥{{item.coupon_info.discount_limit}}</text></div>
- <div v-if="item.coupon_info.type == 2" class="card-number" :class="getTheme + '-m-text ' + getTheme + '-m-back-o ' + getTheme">¥{{item.coupon_info.sub_price}} 满{{item.coupon_info.min_price == 0 ? '任意金额': '¥'+item.coupon_info.min_price}}可用</div>
- <div class="card-num" :class="getTheme + '-m-text ' + getTheme">x{{item.coupon_num}}</div>
- </view>
- </view>
- </view>
- <view v-if="item.type == 'integral' || item.type == 'balance' || item.type == 'svip'" class="dir-left-nowrap balance">
- <view class="balance-info cross-center main-between">
- <view class="dir-left-nowrap cross-center">
- <image v-if="item.type == 'integral'" src="./../image/point.png"></image>
- <image v-if="item.type == 'balance'" src="./../image/balance.png"></image>
- <image v-if="item.type == 'svip'" src="./../image/svip.png"></image>
- <view class="balance-name">{{item.name}}</view>
- </view>
- <view v-if="item.type == 'integral'" :class="getTheme + '-m-text ' + getTheme">{{item.integral_num}}</view>
- <view v-if="item.type == 'balance'" :class="getTheme + '-m-text ' + getTheme">¥{{item.balance}}</view>
- <view v-if="item.type == 'svip'" :class="getTheme + '-m-text ' + getTheme">{{item.svip_info.discount}}折</view>
- </view>
- </view>
- </view>
- <view v-if="exchange == 1" class="rewards-bottom dir-right-nowrap cross-center">
- <view v-if="item.is_send == 0" @click="apply(item)" :class="getTheme + '-m-back ' + getTheme" class="rewards-submit">立即领取</view>
- <view v-if="item.is_send == 1" class="rewards-submit over">已领取</view>
- <view v-if="item.goods_id > 0 || item.user_coupon_id.length > 0 || item.user_card_id.length > 0" @click="toDetail(item)" :class="getTheme + '-m-text ' + getTheme + '-m-border ' + getTheme" class="rewards-detail">查看详情</view>
- </view>
- </view>
- </view>
- <view v-if="exchange == 0" class="placeholder"></view>
- <view v-if="exchange == 0 && list.length > 0" class="apply safe-area-inset-bottom">
- <view class="apply-btn" @click="submit" :class="getTheme + '-m-back ' + getTheme">立即兑换</view>
- </view>
- <u-mask :show="dialog" :maskClickAble="false" :zoom="false">
- <view class="dialog">
- <image class="dialog-img" src="./../image/error.png"></image>
- <view class="dialog-msg">
- <text>{{msg}}</text>
- </view>
- <view class="dialog-other">{{other}}</view>
- <view @click="goback" :class="getTheme + '-m-back ' + getTheme" class="dialog-button">我知道了</view>
- </view>
- </u-mask>
- </app-layout>
- </template>
- <script>
- import {mapGetters, mapState} from 'vuex';
- import uMask from '../../../components/basic-component/u-mask/u-mask.vue';
- import appIphoneX from '../../../components/basic-component/app-iphone-x/app-iphone-x.vue';
- import appRadio from '../../../components/basic-component/app-radio/app-radio.vue';
- export default {
- name: "index",
- data() {
- return {
- first: true,
- loading: false,
- code: '',
- dialog: false,
- msg: '',
- other: '',
- background: '',
- r_raffled_at: '',
- list: [],
- mode: 0,
- exchange: 0,
- token: ''
- };
- },
- components:{
- 'app-radio': appRadio,
- uMask,
- 'app-iphone-x': appIphoneX,
- },
- onLoad(options) {
- let that = this;
- that.code = options.code;
- that.exchange = options.exchange == 1 ? 1 : 0;
- that.background = that.exchangeImg.a;
- switch(that.getTheme) {
- case 'b':
- that.background = that.exchangeImg.b;
- break;
- case 'c':
- that.background = that.exchangeImg.c;
- break;
- case 'd':
- that.background = that.exchangeImg.d;
- break;
- case 'e':
- that.background = that.exchangeImg.e;
- break;
- case 'g':
- that.background = that.exchangeImg.g;
- break;
- case 'h':
- that.background = that.exchangeImg.h;
- break;
- case 'i':
- that.background = that.exchangeImg.i;
- break;
- }
- that.$showLoading({
- type: 'global',
- text: '加载中...'
- });
- that.getList();
- },
- onShow() {
- if(this.exchange == 1 && !this.first) {
- this.getList()
- }
- },
- computed: {
- ...mapGetters('mallConfig', {
- getTheme: 'getTheme',
- }),
- ...mapState({
- exchangeImg: state => state.mallConfig.__wxapp_img.exchange
- })
- },
- methods: {
- toDetail(item) {
- if(item.type == 'goods') {
- uni.navigateTo({
- url: `/pages/goods/goods?id=${item.goods_id}&code=${this.code}&token=${item.token}&attr=${item.goods_info.attr_str}&attr_id=${item.attr_id}&goods_num=${item.goods_num}&exchange=${item.is_send}`
- });
- }else if(item.type == 'coupon') {
- uni.navigateTo({
- url: `/pages/coupon/details/details-no-share?person=1&id=${item.user_coupon_id[0]}`
- });
- }else if(item.type == 'card') {
- uni.navigateTo({
- url: `/pages/card/details/details?id=${item.user_card_id[0]}`
- });
- }
- },
- goback() {
- this.dialog = false;
- uni.navigateBack();
- },
- apply(item) {
- let that = this;
- uni.showLoading({
- title: '领取中...'
- });
- if(item.type != 'goods') {
- that.$request({
- url: that.$api.exchange.covert,
- data: {
- code: this.code,
- token: item.token
- },
- method: 'post'
- }).then(response=>{
- uni.hideLoading();
- if(response.code == 0) {
- uni.showToast({
- title: response.msg,
- duration: 1000
- });
- this.getList();
- }else {
- uni.showToast({
- title: response.msg,
- icon: 'none',
- duration: 1000
- });
- }
- }).catch(response => {
- uni.hideLoading();
- });
- }else {
- let mch_list = [{
- mch_id: 0,
- goods_list: [{
- id: item.goods_id,
- attr: item.goods_info.attr_str,
- num: item.goods_num,
- cat_id: 0,
- goods_attr_id: item.attr_id
- }],
- code: this.code,
- token: item.token,
- }];
- let url = `/pages/order-submit/order-submit?mch_list=${JSON.stringify(mch_list)}`;
- url += `&preview_url=${encodeURIComponent(this.$api.exchange.exchange_preview)}&submit_url=${encodeURIComponent(this.$api.exchange.exchange_submit)}&plugin=exchange`;
- uni.navigateTo({
- url: url
- })
- }
- },
- toggle(boolean,row) {
- for(let item of this.list) {
- if(item.token == row.token) {
- item.active = boolean;
- this.token = row.token
- }else {
- item.active = false;
- }
- }
- this.$forceUpdate();
- },
- submit() {
- let that = this;
- if(that.mode == 1 && !that.token) {
- uni.showToast({
- title: '请选择想要兑换的礼品',
- icon: 'none',
- duration: 1000
- });
- return false
- }
- if(this.loading) {
- return false
- }
- this.loading = true;
- uni.showLoading({
- title: '领取中...'
- });
- that.$request({
- url: that.$api.exchange.unite,
- data: {
- code: this.code,
- token: this.token
- },
- method: 'post'
- }).then(response=>{
- this.loading = false;
- uni.hideLoading();
- if(response.code == 0) {
- this.exchange = 1;
- this.mode = 0;
- this.getList();
- }else {
- uni.showToast({
- title: response.msg,
- icon: 'none',
- duration: 1000
- });
- }
- }).catch(response => {
- uni.hideLoading();
- });
- },
- getList() {
- let that = this;
- that.$request({
- url: that.exchange == 1 ? that.$api.exchange.log_detail : that.$api.exchange.info,
- data: {
- code: that.code
- }
- }).then(response=>{
- that.$hideLoading();
- uni.hideLoading();
- that.first = false;
- if(response.code == 0) {
- if(that.exchange == 0) {
- that.list = response.list.rewards;
- that.mode = response.list.mode;
- if(that.mode == 1) {
- for(let item of that.list) {
- item.active = false;
- }
- }
- }else {
- that.r_raffled_at = response.data.codeModel.r_raffled_at
- that.list = response.data.rewards;
- }
- }else {
- if(that.exchange == 0) {
- that.msg = response.msg;
- that.other = '';
- if(response.msg == '该兑换码未到使用时间!') {
- that.other = response.data.valid_start_time + '-' + response.data.valid_end_time + ' 可用'
- }
- that.dialog = true;
- }else {
- uni.showToast({
- title: response.msg,
- icon: 'none',
- duration: 1000
- });
- }
- }
- }).catch(response => {
- that.$hideLoading();
- uni.hideLoading();
- });
- }
- }
- }
- </script>
- <style scoped lang="scss">
- .dialog {
- margin: 270rpx auto;
- background-color: #fff;
- border-radius: 16rpx;
- width: 600rpx;
- padding: 60rpx 0;
- text-align: center;
- .dialog-img {
- width: 200rpx;
- height: 200rpx;
- margin: 0 auto 20rpx;
- }
- .dialog-msg {
- font-size: 32rpx;
- color: #353535;
- }
- .dialog-other {
- font-size: 24rpx;
- color: #999999;
- }
- .dialog-button {
- font-size: 26rpx;
- width: 520rpx;
- height: 90rpx;
- border-radius: 45rpx;
- line-height: 90rpx;
- text-align: center;
- color: #fff;
- margin: 50rpx auto 0;
- }
- }
- .code-info {
- width: 702rpx;
- height: 240rpx;
- border-radius: 16rpx;
- background-size: 100% 100%;
- margin: 24rpx;
- text-align: center;
- color: #fff;
- font-size: 24rpx;
- .code {
- margin-top: 50rpx;
- display: inline-block;
- font-size: 38rpx;
- text-align: center;
- padding: 24rpx 95rpx;
- border-radius: 60rpx;
- color: #fff;
- background-color: rgba(255,255,255,.2);
- margin-bottom: 20rpx;
- }
- }
- .rewards {
- background-color: #fff;
- border-radius: 16rpx;
- width: 702rpx;
- margin: 24rpx auto 0;
- .rewards-top {
- padding: 34rpx 40rpx;
- &.active-item {
- padding-left: 0;
- }
- .active {
- width: 88rpx;
- height: 140rpx;
- text-align: center;
- flex-shrink: 0;
- image {
- width: 32rpx;
- height: 32rpx;
- margin-top: 54rpx;
- border-radius: 16rpx;
- }
- &.small {
- height: 36rpx;
- image {
- margin-top: 2rpx;
- }
- }
- }
- .goods-num {
- font-size: 28rpx;
- }
- .balance {
- width: 100%;
- .balance-info {
- width: 100%;
- image {
- width: 30rpx;
- height: 30rpx;
- margin-right: 14rpx;
- }
- .balance-name {
- font-size: 28rpx;
- color: #353535;
- }
- }
- }
- .card {
- width: 100%;
- &.goods {
- .card-info {
- .card-name {
- margin-top: 0;
- margin-bottom: 10rpx;
- }
- }
- }
- .card-img {
- height: 140rpx;
- width: 140rpx;
- border-radius: 8rpx;
- margin-right: 20rpx;
- flex-shrink: 0;
- }
- .card-info {
- width: 100%;
- image {
- width: 30rpx;
- height: 30rpx;
- margin-right: 14rpx;
- }
- .attr {
- font-size: 24rpx;
- color: #999;
- }
- .card-name {
- margin-top: -5rpx;
- font-size: 28rpx;
- color: #353535;
- margin-bottom: 30rpx;
- }
- .card-number {
- padding: 12rpx 20rpx;
- font-size: 24rpx;
- border-radius: 30rpx;
- }
- .card-num {
- font-size: 28rpx;
- }
- }
- }
- }
- .rewards-bottom {
- border-top: #{2rpx} solid #e2e2e2;
- height: #{118rpx};
- width: 100%;
- padding: 0 #{30rpx};
- .rewards-submit {
- height: #{68rpx};
- line-height: #{68rpx};
- text-align: center;
- padding: 0 #{30rpx};
- border-radius: #{40rpx};
- color: #fff;
- font-size: #{28rpx};
- &.over {
- background-color: #f7f7f7;
- color: #999999;
- }
- }
- .rewards-detail {
- height: #{68rpx};
- line-height: #{68rpx};
- text-align: center;
- padding: 0 #{30rpx};
- border-radius: #{40rpx};
- background-color: #fff;
- font-size: #{28rpx};
- border: #{2rpx} solid;
- margin-right: #{18rpx};
- }
- }
- }
- .placeholder {
- height: #{178rpx};
- width: 100%;
- }
- .apply {
- position: fixed;
- bottom: 0;
- left: 0;
- z-index: 2;
- height: #{154rpx};
- width: 100%;
- background-color: #fff;
- padding-top: #{26rpx};
- padding-left: #{24rpx};
- .apply-btn {
- width: #{702rpx};
- height: #{88rpx};
- line-height: #{88rpx};
- border-radius: #{44rpx};
- text-align: center;
- color: #fff;
- font-size: #{32rpx};
- }
- }
- </style>
|