<template>
	<view class="content">
		<text class="success-icon yticon icon-xuanzhong2"></text>
		<text class="tit">支付成功</text>
    <!-- #ifdef MP -->
    <view class="subscribe-box" style="padding-top: 50px;">
      <view class="subscribe-title" style="float: left">获取实时发货信息与订单状态</view>
      <view class="subscribe-start" style="float: left;padding-left: 10px;color: red" @tap="subscribeMessage">立即订阅</view>
    </view>
    <!-- #endif -->
		<view class="btn-group">
			<navigator url="/pages/order/list?state=0" open-type="redirect" class="mix-btn">查看订单</navigator>
			<navigator url="/pages/index/index" open-type="switchTab" class="mix-btn hollow">返回首页</navigator>
		</view>
	</view>
</template>

<script>
import { WxaSubscribeTemplate } from '@/util/const';
import { subscribeMessage,getSubscribeTemplate } from '@/util/miniProgram';
	export default {
		data() {
			return {
        SUBSCRIBE_BTN_STATUS_STORAGE_KEY: 'subscribeBtnStatus' // 存储键
			}
		},
		methods: {
      subscribeMessage() {
        const that = this;
        that.$api.request('get', 'social/app/get-subscribe-template-list', {}, failres => {
          that.$api.msg(failres.msg);
        }).then(res => {
          getSubscribeTemplate(res.data); // 确保传递了数据
          const event = [WxaSubscribeTemplate.ORDER_SUCCESSFUL,WxaSubscribeTemplate.ORDER_FULFILLMENT];
          subscribeMessage(event, () => {
            // 订阅后记录一下订阅状态
            uni.removeStorageSync(this.SUBSCRIBE_BTN_STATUS_STORAGE_KEY);
            uni.setStorageSync(this.SUBSCRIBE_BTN_STATUS_STORAGE_KEY, '已订阅');
            // 隐藏订阅按钮
            this.showSubscribeBtn = false;
          });
        });
      }
		}
	}
</script>

<style lang='scss'>
	.content{
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
	}
	.success-icon{
		font-size: 160upx;
		color: #2AAC34;
		margin-top: 100upx;
	}
	.tit{
		font-size: 38upx;
		color: #303133;
	}
	.btn-group{
		padding-top: 100upx;
	}
	.mix-btn {
		margin-top: 30upx;
		display: flex;
		align-items: center;
		justify-content: center;
		width: 600upx;
		height: 80upx;
		font-size: $font-lg;
		color: #fff;
		background-color: #2AAC34;
		border-radius: 10upx;
		&.hollow{
			background: #fff;
			color: #303133;
			border: 1px solid #ccc;
		}
	}



  .subscribe-box {
    .subscribe-img {
      width: 44rpx;
      height: 44rpx;
    }

    .subscribe-title {
      font-weight: 500;
      font-size: 32rpx;
      line-height: 36rpx;
      color: #434343;
    }

    .subscribe-start {
      color: var(--ui-BG-Main);
      font-weight: 700;
      font-size: 32rpx;
      line-height: 36rpx;
    }
  }
</style>
