Merge remote-tracking branch 'origin/master-vue3' into master-vue3

# Conflicts:
#	sheep/components/s-wallet-card/s-wallet-card.vue
pull/25/head
owen 2023-12-09 23:00:11 +08:00
commit 4e3b8eccff
3 changed files with 77 additions and 30 deletions

View File

@ -4,7 +4,7 @@
<view class="ss-modal-box bg-white ss-flex-col">
<view class="modal-header ss-flex ss-col-center">
<view class="header-left ss-m-r-30">
<image class="sku-image" :src="sheep.$url.cdn(state.selectedSkuPrice.image || goodsInfo.image)"
<image class="sku-image" :src="state.selectedSkuPrice.image || goodsInfo.image"
mode="aspectFill"></image>
</view>
<view class="header-right ss-flex-col ss-row-between ss-flex-1">
@ -38,17 +38,17 @@
</view>
<view class="modal-content ss-flex-1">
<scroll-view scroll-y="true" class="modal-content-scroll" @touchmove.stop>
<view class="sku-item ss-m-b-20" v-for="sku1 in goodsInfo.skus" :key="sku1.id">
<view class="sku-item ss-m-b-20" v-for="sku1 in skuList" :key="sku1.id">
<view class="label-text ss-m-b-20">{{ sku1.name }}</view>
<view class="ss-flex ss-col-center ss-flex-wrap">
<button class="ss-reset-button spec-btn" v-for="sku2 in sku1.children" :class="[
<button class="ss-reset-button spec-btn" v-for="sku2 in sku1.values" :class="[
{
'ui-BG-Main-Gradient': state.currentSkuArray[sku2.parent_id] == sku2.id,
'ui-BG-Main-Gradient': state.currentSkuArray[sku1.id] == sku2.id,
},
{
'disabled-btn': sku2.disabled == true,
'disabled-btn': sku2.disabled === true,
},
]" :key="sku2.id" :disabled="sku2.disabled == true" @tap="onSelectSku(sku2.parent_id, sku2.id)">
]" :key="sku2.id" :disabled="sku2.disabled === true" @tap="onSelectSku(sku1.id, sku2.id)">
{{ sku2.name }}
</button>
</view>
@ -56,7 +56,7 @@
<view class="buy-num-box ss-flex ss-col-center ss-row-between ss-m-b-40">
<view class="label-text">购买数量</view>
<su-number-box :min="1" :max="state.selectedSkuPrice.stock" :step="1"
v-model="state.selectedSkuPrice.goods_num" @change="onNumberChange($event)"></su-number-box>
v-model="state.selectedSkuPrice.goods_num" @change="onNumberChange($event)" />
</view>
</scroll-view>
</view>
@ -82,7 +82,8 @@
import sheep from '@/sheep';
import {
formatStock,
formatPrice
formatPrice,
convertProductPropertyList
} from '@/sheep/hooks/useGoods';
import {
isEmpty
@ -108,27 +109,32 @@
selectedSkuPrice: {},
currentSkuArray: [],
});
//
//
function onNumberChange(e) {
if (e === 0) return;
if (state.selectedSkuPrice.goods_num === e) return;
state.selectedSkuPrice.goods_num = e;
}
// TODO
//
if (!props.goodsInfo.is_sku) {
state.selectedSkuPrice = props.goodsInfo.sku_prices[0];
}
// if (!props.goodsInfo.is_sku) {
// state.selectedSkuPrice = props.goodsInfo.sku_prices[0];
// }
const skuList = props.goodsInfo.skus;
const skuList = convertProductPropertyList(props.goodsInfo.skus);
//
const skuPrices = computed(() => {
let skuPrices = props.goodsInfo.sku_prices;
if (props.goodsInfo.is_sku) {
skuPrices.forEach((item) => {
item.goods_sku_id_arr = item.goods_sku_ids.split(',');
});
}
let skuPrices = props.goodsInfo.skus;
// TODO
// if (props.goodsInfo.is_sku) {
// skuPrices.forEach((item) => {
// item.goods_sku_id_arr = item.goods_sku_ids.split(',');
// });
// }
for (let price of skuPrices) {
price.goods_sku_id_arr = price.properties.map((item) => item.valueId).join(',')
}
return skuPrices;
});
@ -143,7 +149,7 @@
);
const goodsPrice = computed(() => {
let price, score;
let price, score;
if (isEmpty(state.selectedSkuPrice)) {
price = props.goodsInfo.price[0];
score = props.goodsInfo.score || 0;
@ -182,7 +188,7 @@
}
//
function changeDisabled(isChecked = false, pid = 0, skuId = 0) {
let newPrice = []; // skuPrice
let newPrice = []; // skuPrice
if (isChecked) {
//
@ -192,6 +198,7 @@
// this.goodsNum uni-number-box stock goods_num
continue;
}
console.log(price.goods_sku_id_arr, '=======')
if (price.goods_sku_id_arr.indexOf(skuId.toString()) >= 0) {
newPrice.push(price);
}
@ -262,6 +269,7 @@
}
// skuPrice
function getCanUseSkuPrice() {
// debugger
let newPrice = [];
for (let price of skuPrices.value) {
@ -287,6 +295,7 @@
}
//
function onSelectSku(pid, skuId) {
// debugger
//
let isChecked = true; // or
if (state.currentSkuArray[pid] != undefined && state.currentSkuArray[pid] == skuId) {
@ -306,7 +315,7 @@
}
});
// skuPric
// skuPrice
let newPrice = getCanUseSkuPrice();
//

View File

@ -1,4 +1,5 @@
<template>
<!-- TODO @惠智造代码合并有问题可以看看 -->
<view class="ss-wallet-menu-wrap ss-flex ss-col-center">
<view class="menu-item ss-flex-1 ss-flex-col ss-row-center ss-col-center"
@tap="sheep.$router.go('/pages/user/wallet/money')">
@ -8,14 +9,6 @@
</view>
<view class="menu-title ss-m-t-28">账户余额</view>
</view>
<!-- <view class="menu-item ss-flex-1 ss-flex-col ss-row-center ss-col-center"
@tap="sheep.$router.go('/pages/user/wallet/commission')">
<view class="value-box ss-flex ss-col-bottom">
<view class="value-text">{{ userInfo?.commission || '0.00' }}</view>
<view class="unit-text ss-m-l-6"></view>
</view>
<view class="menu-title ss-m-t-28">佣金</view>
</view> -->
<view class="menu-item ss-flex-1 ss-flex-col ss-row-center ss-col-center"
@tap="sheep.$router.go('/pages/user/wallet/score')">
<view class="value-box ss-flex ss-col-bottom">
@ -99,3 +92,4 @@
}
}
</style>

View File

@ -156,3 +156,47 @@ function getDayjsTime(time) {
return dayjs.unix(parseInt(time));
}
}
/**
* 从商品 SKU 数组中转换出商品属性的数组
*
* 类似结构[{
* id: // 属性的编号
* name: // 属性的名字
* values: [{
* id: // 属性值的编号
* name: // 属性值的名字
* }]
* }]
*
* @param skus 商品 SKU 数组
*/
export function convertProductPropertyList(skus) {
let result = [];
for (const sku of skus) {
if (!sku.properties) {
continue
}
for (const property of sku.properties) {
// ① 先处理属性
let resultProperty = result.find(item => item.id === property.propertyId)
if (!resultProperty) {
resultProperty = {
id: property.propertyId,
name: property.propertyName,
values: []
}
result.push(resultProperty)
}
// ② 再处理属性值
let resultValue = resultProperty.values.find(item => item.id === property.valueId)
if (!resultValue) {
resultProperty.values.push({
id: property.valueId,
name: property.valueName
})
}
}
}
return result;
}