✨ 商品详情:优惠劵信息的接入
							parent
							
								
									b422c7414f
								
							
						
					
					
						commit
						275e8a278f
					
				| 
						 | 
					@ -209,18 +209,21 @@
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // 领取优惠劵
 | 
				
			||||||
  async function getCoupon() {
 | 
					  async function getCoupon() {
 | 
				
			||||||
    const { error, msg } = await sheep.$api.coupon.get(state.id);
 | 
					    const { code } = await CouponApi.takeCoupon(state.id);
 | 
				
			||||||
    if (error === 0) {
 | 
					    if (code !== 0) {
 | 
				
			||||||
      uni.showToast({
 | 
					      return;
 | 
				
			||||||
        title: msg,
 | 
					 | 
				
			||||||
      });
 | 
					 | 
				
			||||||
      setTimeout(() => {
 | 
					 | 
				
			||||||
        getCouponContent(state.id, state.couponId);
 | 
					 | 
				
			||||||
      }, 1000);
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					    uni.showToast({
 | 
				
			||||||
 | 
					      title: '领取成功',
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					    setTimeout(() => {
 | 
				
			||||||
 | 
					      getCouponContent();
 | 
				
			||||||
 | 
					    }, 1000);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // 加载优惠劵信息
 | 
				
			||||||
  async function getCouponContent() {
 | 
					  async function getCouponContent() {
 | 
				
			||||||
    const { code, data } = state.id > 0 ? await CouponApi.getCouponTemplate(state.id)
 | 
					    const { code, data } = state.id > 0 ? await CouponApi.getCouponTemplate(state.id)
 | 
				
			||||||
      : await CouponApi.getCoupon(state.couponId);
 | 
					      : await CouponApi.getCoupon(state.couponId);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -111,7 +111,7 @@
 | 
				
			||||||
    state.currentTab = e.index;
 | 
					    state.currentTab = e.index;
 | 
				
			||||||
    state.type = e.value;
 | 
					    state.type = e.value;
 | 
				
			||||||
    resetPagination(state.pagination)
 | 
					    resetPagination(state.pagination)
 | 
				
			||||||
    if (state.currentTab == 0) {
 | 
					    if (state.currentTab === 0) {
 | 
				
			||||||
    	getData();
 | 
					    	getData();
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
      getCoupon();
 | 
					      getCoupon();
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -186,18 +186,16 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// 立即领取  TODO 芋艿:待测试
 | 
						// 立即领取  TODO 芋艿:待测试
 | 
				
			||||||
	async function onGet(id) {
 | 
						async function onGet(id) {
 | 
				
			||||||
		const {
 | 
					    const { code } = await CouponApi.takeCoupon(id);
 | 
				
			||||||
			error,
 | 
					    if (code !== 0) {
 | 
				
			||||||
			msg
 | 
					      return;
 | 
				
			||||||
		} = await sheep.$api.coupon.get(id);
 | 
					    }
 | 
				
			||||||
		if (error === 0) {
 | 
					    uni.showToast({
 | 
				
			||||||
			uni.showToast({
 | 
					      title: '领取成功',
 | 
				
			||||||
				title: msg,
 | 
					    });
 | 
				
			||||||
			});
 | 
					    setTimeout(() => {
 | 
				
			||||||
			setTimeout(() => {
 | 
					      getCoupon();
 | 
				
			||||||
				getCoupon();
 | 
					    }, 1000);
 | 
				
			||||||
			}, 1000);
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	//  TODO 芋艿:待测试
 | 
						//  TODO 芋艿:待测试
 | 
				
			||||||
| 
						 | 
					@ -221,7 +219,14 @@
 | 
				
			||||||
		}, );
 | 
							}, );
 | 
				
			||||||
	});
 | 
						});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	onLoad(async (options) => {
 | 
					  async function getCoupon() {
 | 
				
			||||||
 | 
					    const { code, data } = await CouponApi.getCouponTemplateList(state.goodsId, 2, 10);
 | 
				
			||||||
 | 
					    if (code === 0) {
 | 
				
			||||||
 | 
					      state.couponInfo = data;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						onLoad((options) => {
 | 
				
			||||||
		// 非法参数
 | 
							// 非法参数
 | 
				
			||||||
		if (!options.id) {
 | 
							if (!options.id) {
 | 
				
			||||||
			state.goodsInfo = null;
 | 
								state.goodsInfo = null;
 | 
				
			||||||
| 
						 | 
					@ -249,12 +254,7 @@
 | 
				
			||||||
		});
 | 
							});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// 2. 加载优惠劵信息
 | 
							// 2. 加载优惠劵信息
 | 
				
			||||||
		CouponApi.getCouponTemplateList(state.goodsId, 2, 10).then((res) => {
 | 
					    getCoupon();
 | 
				
			||||||
			if (res.code !== 0) {
 | 
					 | 
				
			||||||
				return;
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
			state.couponInfo = res.data;
 | 
					 | 
				
			||||||
		});
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// 3. 加载营销活动信息
 | 
							// 3. 加载营销活动信息
 | 
				
			||||||
		ActivityApi.getActivityListBySpuId(state.goodsId).then((res) => {
 | 
							ActivityApi.getActivityListBySpuId(state.goodsId).then((res) => {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,3 +1,4 @@
 | 
				
			||||||
 | 
					<!-- 商品详情 - 优惠劵领取 -->
 | 
				
			||||||
<template>
 | 
					<template>
 | 
				
			||||||
  <su-popup
 | 
					  <su-popup
 | 
				
			||||||
    :show="show"
 | 
					    :show="show"
 | 
				
			||||||
| 
						 | 
					@ -21,13 +22,11 @@
 | 
				
			||||||
            <template #default>
 | 
					            <template #default>
 | 
				
			||||||
              <button
 | 
					              <button
 | 
				
			||||||
                class="ss-reset-button card-btn ss-flex ss-row-center ss-col-center"
 | 
					                class="ss-reset-button card-btn ss-flex ss-row-center ss-col-center"
 | 
				
			||||||
                :class="
 | 
					                :class="!item.canTake ? 'boder-btn' : ''"
 | 
				
			||||||
                  item.get_status != 'can_get' && item.get_status != 'can_use' ? 'boder-btn' : ''
 | 
					 | 
				
			||||||
                "
 | 
					 | 
				
			||||||
                @click.stop="getBuy(item.id)"
 | 
					                @click.stop="getBuy(item.id)"
 | 
				
			||||||
                :disabled="item.get_status != 'can_get' && item.get_status != 'can_use'"
 | 
					                :disabled="!item.canTake"
 | 
				
			||||||
              >
 | 
					              >
 | 
				
			||||||
                {{ item.get_status_text }}
 | 
					                {{ item.canTake ? '立即领取' : '已领取' }}
 | 
				
			||||||
              </button>
 | 
					              </button>
 | 
				
			||||||
            </template>
 | 
					            </template>
 | 
				
			||||||
          </s-coupon-list>
 | 
					          </s-coupon-list>
 | 
				
			||||||
| 
						 | 
					@ -38,6 +37,7 @@
 | 
				
			||||||
</template>
 | 
					</template>
 | 
				
			||||||
<script setup>
 | 
					<script setup>
 | 
				
			||||||
  import { computed, reactive } from 'vue';
 | 
					  import { computed, reactive } from 'vue';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const props = defineProps({
 | 
					  const props = defineProps({
 | 
				
			||||||
    modelValue: {
 | 
					    modelValue: {
 | 
				
			||||||
      type: Object,
 | 
					      type: Object,
 | 
				
			||||||
| 
						 | 
					@ -48,16 +48,17 @@
 | 
				
			||||||
      default: false,
 | 
					      default: false,
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
  });
 | 
					  });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const emits = defineEmits(['get', 'close']);
 | 
					  const emits = defineEmits(['get', 'close']);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const state = reactive({
 | 
					  const state = reactive({
 | 
				
			||||||
    couponInfo: computed(() => props.modelValue),
 | 
					    couponInfo: computed(() => props.modelValue)
 | 
				
			||||||
    currentValue: -1,
 | 
					 | 
				
			||||||
    couponId: '',
 | 
					 | 
				
			||||||
  });
 | 
					  });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // 领取优惠劵
 | 
				
			||||||
  const getBuy = (id) => {
 | 
					  const getBuy = (id) => {
 | 
				
			||||||
    emits('get', id);
 | 
					    emits('get', id);
 | 
				
			||||||
  };
 | 
					  };
 | 
				
			||||||
  //立即领取
 | 
					 | 
				
			||||||
</script>
 | 
					</script>
 | 
				
			||||||
<style lang="scss" scoped>
 | 
					<style lang="scss" scoped>
 | 
				
			||||||
  .model-box {
 | 
					  .model-box {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue