|
@@ -76,6 +76,38 @@
|
|
|
@change="onNumberChange($event)"
|
|
|
/>
|
|
|
</view>
|
|
|
+ <!-- 我要房券 -->
|
|
|
+ <view v-else class="ss-m-b-20">
|
|
|
+ <checkbox-group class="ss-m-b-10" @change="isGetPrizeChange">
|
|
|
+ <label>
|
|
|
+ <checkbox value="getPrize" :checked="isGetPrize" />
|
|
|
+ 我要房券
|
|
|
+ </label>
|
|
|
+ </checkbox-group>
|
|
|
+ <div v-if="noCity" style="color: gray;" class="ss-m-20">房券已被抢完啦</div>
|
|
|
+ <div v-show="isGetPrize" class="ss-m-20">
|
|
|
+ <div class="getPrizeTip ss-m-20">请勾选一到三个地点作为期望获赠房券的所在地,系统将随机抽取一张</div>
|
|
|
+ <view v-if="prizeAreaList?.length" class="ss-flex ss-col-center ss-flex-wrap">
|
|
|
+ <button
|
|
|
+ class="ss-reset-button spec-btn"
|
|
|
+ v-for="(item, index) of prizeAreaList"
|
|
|
+ :key="item+index"
|
|
|
+ :class="[
|
|
|
+ {
|
|
|
+ 'ui-BG-Main-Gradient': item.active,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ 'disabled-btn': item.total <= 0,
|
|
|
+ },
|
|
|
+ ]"
|
|
|
+ :disabled="item.total <= 0"
|
|
|
+ @tap="cityChange(index, item.active)"
|
|
|
+ >
|
|
|
+ {{ item.label }}
|
|
|
+ </button>
|
|
|
+ </view>
|
|
|
+ </div>
|
|
|
+ </view>
|
|
|
</scroll-view>
|
|
|
</view>
|
|
|
|
|
@@ -93,9 +125,10 @@
|
|
|
</template>
|
|
|
|
|
|
<script setup>
|
|
|
- import { computed, reactive, watch } from 'vue';
|
|
|
+ import { computed, reactive, watch, ref } from 'vue';
|
|
|
import sheep from '@/sheep';
|
|
|
import { formatStock, convertProductPropertyList, fen2yuan } from '@/sheep/hooks/useGoods';
|
|
|
+ import PrizeApi from '@/sheep/api/prizeDraw'
|
|
|
|
|
|
const emits = defineEmits(['change', 'addCart', 'buy', 'close']);
|
|
|
const props = defineProps({
|
|
@@ -171,7 +204,15 @@
|
|
|
sheep.$helper.toast('库存不足');
|
|
|
return;
|
|
|
}
|
|
|
- emits('buy', state.selectedSku);
|
|
|
+ if (isGetPrize.value && !checkList?.length) {
|
|
|
+ sheep.$helper.toast('请勾选期望获赠房券的所在地!');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ let city = []
|
|
|
+ if (isGetPrize.value && checkList?.length) {
|
|
|
+ checkList.forEach(index => city.push(prizeAreaList.value[index].label))
|
|
|
+ }
|
|
|
+ emits('buy', { ...state.selectedSku, city })
|
|
|
}
|
|
|
|
|
|
// 改变禁用状态:计算每个 property 属性值的按钮,是否禁用
|
|
@@ -317,10 +358,72 @@
|
|
|
if (e.values && e.values.length) onSelectSku(e.id, e.values[0].id)
|
|
|
})
|
|
|
}
|
|
|
+
|
|
|
+ function checkAllTotalsAreZero(obj) {
|
|
|
+ for (let city in obj) {
|
|
|
+ if (obj.hasOwnProperty(city) && obj[city].total !== 0) {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return true
|
|
|
+ }
|
|
|
+
|
|
|
+ const isGetPrize = ref(false)
|
|
|
+ const noCity = ref(false)
|
|
|
+ const prizeAreaList = ref([])
|
|
|
+ // 根据商品id活动对应的奖品区域信息
|
|
|
+ const getAreaData = async () => {
|
|
|
+ const id = props.goodsInfo?.id
|
|
|
+ if (!id) return
|
|
|
+ const params = {
|
|
|
+ spuId: id,
|
|
|
+ type: 'city',
|
|
|
+ }
|
|
|
+ const res = await PrizeApi.getPrizeAreaByGoodsId(params)
|
|
|
+ const data = res?.data
|
|
|
+ if (!data || !Object.keys(data).length || checkAllTotalsAreZero(data)) {
|
|
|
+ noCity.value = true
|
|
|
+ isGetPrize.value = false
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ let list = [] // 只显示还有库存的城市
|
|
|
+ Object.keys(data).forEach(cityName => {
|
|
|
+ list.push({ label: cityName, total: data[cityName].total, active: false })
|
|
|
+ })
|
|
|
+ prizeAreaList.value = [...new Set(list)]
|
|
|
+ // getPrizeLoading.value = false
|
|
|
+ }
|
|
|
+
|
|
|
+ let checkList = []
|
|
|
+ const cityChange = (index, active) => {
|
|
|
+ if (active) { // 取消
|
|
|
+ checkList = checkList.filter(item => item !== index)
|
|
|
+ } else { // 选中
|
|
|
+ if (checkList.length > 2) return sheep.$helper.toast('最多只可选择三个')
|
|
|
+
|
|
|
+ checkList.push(index)
|
|
|
+ }
|
|
|
+ prizeAreaList.value[index].active = !active
|
|
|
+ }
|
|
|
+
|
|
|
+ const isGetPrizeChange = (e) => {
|
|
|
+ isGetPrize.value = Boolean(e?.detail?.value?.length)
|
|
|
+ if (!isGetPrize.value) {
|
|
|
+ // checkList = []
|
|
|
+ // prizeAreaList.value.forEach(e => e.active = false)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ getAreaData()
|
|
|
+ }
|
|
|
</script>
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
// 购买
|
|
|
+ .getPrizeTip {
|
|
|
+ font-weight: bold;
|
|
|
+ text-decoration: underline;
|
|
|
+ }
|
|
|
.buy-box {
|
|
|
padding: 10rpx 0;
|
|
|
|