main
fanfan 12 months ago
parent 46eb254312
commit d114542654
  1. 72
      components/goods-sku-popup/index.vue
  2. 13
      pages/goods/components/SkuPopup.vue

@ -19,7 +19,8 @@
<text class="sign">¥</text> <text class="sign">¥</text>
<text class="price" :class="priceCom.length > 16 ? 'price2' : ''">{{ priceCom }}</text> <text class="price" :class="priceCom.length > 16 ? 'price2' : ''">{{ priceCom }}</text>
</view> </view>
<view class="inventory" v-if="!hideStock">{{ stockText }}{{ stockCom }}</view> <view class="inventory" v-if="stockValue">{{ stockText }}{{stockValue?stockValue:'-' }}
</view>
<view class="inventory"></view> <view class="inventory"></view>
<view class="choose" v-show="isManyCom"> <view class="choose" v-show="isManyCom">
<text v-if="!selectArr.every(val => val == '')">已选{{ selectArr.join(' ') }}</text> <text v-if="!selectArr.every(val => val == '')">已选{{ selectArr.join(' ') }}</text>
@ -33,8 +34,7 @@
<view class="item-wrapper"> <view class="item-wrapper">
<view class="item-content" v-for="(item_value, index2) in item.list" :key="index2" <view class="item-content" v-for="(item_value, index2) in item.list" :key="index2"
:class="[item_value.ishow ? '' : 'noactived', subIndex[index1] == index2 ? 'actived' : '']" :class="[item_value.ishow ? '' : 'noactived', subIndex[index1] == index2 ? 'actived' : '']"
:style="[ :style="[item_value.ishow ? '' : themeColorFn('disableStyle'),
item_value.ishow ? '' : themeColorFn('disableStyle'),
item_value.ishow ? themeColorFn('btnStyle') : '', item_value.ishow ? themeColorFn('btnStyle') : '',
subIndex[index1] == index2 ? themeColorFn('activedStyle') : '' subIndex[index1] == index2 ? themeColorFn('activedStyle') : ''
]" @click="skuClick(item_value, index1, index2,item)"> ]" @click="skuClick(item_value, index1, index2,item)">
@ -61,16 +61,16 @@
<view class="sure" style="color:#ffffff;background-color:#cccccc">{{ noStockText }}</view> <view class="sure" style="color:#ffffff;background-color:#cccccc">{{ noStockText }}</view>
</view> </view>
<view class="btn-wrapper" v-else-if="mode == 1"> <view class="btn-wrapper" v-else-if="mode == 1">
<view class="sure add-cart" style="border-radius:38rpx 0rpx 0rpx 38rpx;" :style="{ <view class="sure add-cart" v-if="stockValue=='有货'" style="border-radius:38rpx 0rpx 0rpx 38rpx;" :style="{
color: themeColorFn('addCartColor'), color: themeColorFn('addCartColor'),
backgroundColor: themeColorFn('addCartBackgroundColor') backgroundColor:stockValue=='有货'? themeColorFn('addCartBackgroundColor'):'#cecece'
}" @click="addCart"> }" @click="addCart">
{{ addCartText }} {{ addCartText }}
</view> </view>
<view class="sure" style="border-radius:0rpx 38rpx 38rpx 0rpx;" :style="{ <view class="sure" style="border-radius:0rpx 38rpx 38rpx 0rpx;" :style="{
color: themeColorFn('buyNowColor'), color: themeColorFn('buyNowColor'),
backgroundColor: themeColorFn('buyNowBackgroundColor') backgroundColor:stockValue=='有货'? themeColorFn('buyNowBackgroundColor'):'#cecece'
}" @click="buyNow"> }" @click="buyNow">
{{ userInfo.user_type == 40?'修改价格':buyNowText }} {{ userInfo.user_type == 40?'修改价格':buyNowText }}
</view> </view>
@ -78,7 +78,7 @@
<view class="btn-wrapper" v-else-if="mode == 2"> <view class="btn-wrapper" v-else-if="mode == 2">
<view class="sure add-cart" :style="{ <view class="sure add-cart" :style="{
color: themeColorFn('addCartColor'), color: themeColorFn('addCartColor'),
backgroundColor: themeColorFn('addCartBackgroundColor') backgroundColor: stockValue=='有货'?themeColorFn('addCartBackgroundColor'):'#cecece'
}" @click="addCart"> }" @click="addCart">
{{ addCartText }} {{ addCartText }}
</view> </view>
@ -86,7 +86,7 @@
<view class="btn-wrapper" v-else-if="mode == 3"> <view class="btn-wrapper" v-else-if="mode == 3">
<view class="sure" :style="{ <view class="sure" :style="{
color: themeColorFn('buyNowColor'), color: themeColorFn('buyNowColor'),
backgroundColor: themeColorFn('buyNowBackgroundColor') backgroundColor: stockValue=='有货'? themeColorFn('buyNowBackgroundColor'):'#cecece'
}" @click="buyNow"> }" @click="buyNow">
{{ userInfo.user_type == 40?'修改价格':buyNowText }} {{ userInfo.user_type == 40?'修改价格':buyNowText }}
</view> </view>
@ -98,6 +98,7 @@
<script> <script>
import NumberBox from './number-box' import NumberBox from './number-box'
import * as GoodsApi from '@/api/goods'
var vk; // vk var vk; // vk
var goodsCache = {}; // var goodsCache = {}; //
export default { export default {
@ -334,9 +335,18 @@
Type: Boolean, Type: Boolean,
default: true default: true
}, },
addressResult: {
type: Object,
default: {
province: '江苏省',
city: '南京市',
district: '玄武区'
}
},
}, },
data() { data() {
return { return {
stockValue: '有货',
skuItem: '', skuItem: '',
userInfo: {}, userInfo: {},
complete: false, // complete: false, //
@ -446,6 +456,29 @@
}, },
mounted() {}, mounted() {},
methods: { methods: {
async getGoodsStockInfor(list) {
let that = this;
let params = {
list: list,
province: that.addressResult ? that.addressResult.province : '江苏省',
city: that.addressResult ? that.addressResult.city : '南京市',
district: that.addressResult ? that.addressResult.district : '玄武区'
}
let {
status,
message,
data
} = await GoodsApi.getGoodsStock(params);
if (status == 200) {
that.stockValue = data[0].state
if (that.stockValue == '无货') {
uni.showToast({
icon: "none",
title: "该商品暂时无货"
})
}
}
},
// //
init(notAutoClick) { init(notAutoClick) {
let that = this; let that = this;
@ -461,8 +494,6 @@
that.selectArr.push(''); that.selectArr.push('');
that.subIndex.push(-1); that.subIndex.push(-1);
}); });
console.log(notAutoClick, that.specListName)
console.log(that.goodsInfo)
that.checkItem(); // sku that.checkItem(); // sku
that.checkInpath(-1); // -1 that.checkInpath(-1); // -1
if (!notAutoClick) that.autoClickSku(); // sku if (!notAutoClick) that.autoClickSku(); // sku
@ -645,6 +676,7 @@
}, },
// sku // sku
skuClick(value, index1, index2, item) { skuClick(value, index1, index2, item) {
console.log(value, index1, index2, item, )
let that = this; let that = this;
if (value.ishow) { if (value.ishow) {
if (that.selectArr[index1] != value.name) { if (that.selectArr[index1] != value.name) {
@ -663,8 +695,21 @@
that.checkInpath(index1); that.checkInpath(index1);
// //
that.checkSelectShop(); that.checkSelectShop();
let {
selectShop,
selectNum
} = that;
if (!that.isObjectEmpty(selectShop)) {
that.getGoodsStockInfor([{
goods_id: selectShop.goods_id,
num: selectNum
}])
}
} }
}, },
isObjectEmpty(obj) {
return Object.keys(obj).length === 0;
},
// sku // sku
checkSelectShop() { checkSelectShop() {
let that = this; let that = this;
@ -770,7 +815,6 @@
[] []
] ]
); );
// console.timeEnd('');
}, },
getArrayToSting(arr) { getArrayToSting(arr) {
let str = ''; let str = '';
@ -941,7 +985,7 @@
let skuName = skuArr[index]; let skuName = skuArr[index];
let specList = specListArr[index].list; let specList = specListArr[index].list;
let index1 = index; let index1 = index;
let index2 = that.getListIndex(specList, 'name', skuName); let index2 = that.getListIndex(specList, 'name', skuName, );
if (index2 == -1) { if (index2 == -1) {
clickKey = false; clickKey = false;
break; break;
@ -1015,7 +1059,7 @@
maxStock = max; maxStock = max;
} }
} }
console.log("getMaxStock",maxStock) console.log("getMaxStock", maxStock)
return maxStock; return maxStock;
}, },
numChange(e) { numChange(e) {
@ -1042,7 +1086,7 @@
if (max > maxStock) { if (max > maxStock) {
max = maxStock; max = maxStock;
} }
console.log("maxBuyNumCom",maxStock,that.maxBuyNum) console.log("maxBuyNumCom", maxStock, that.maxBuyNum)
return max; return max;
}, },
// //

@ -4,7 +4,7 @@
:addCartColor="appTheme.viceText" :addCartBackgroundColor="appTheme.viceBg" :addCartColor="appTheme.viceText" :addCartBackgroundColor="appTheme.viceBg"
:activedStyle="{ color: appTheme.mainBg, borderColor: appTheme.mainBg, backgroundColor: activedBtnBackgroundColor }" :activedStyle="{ color: appTheme.mainBg, borderColor: appTheme.mainBg, backgroundColor: activedBtnBackgroundColor }"
@open="openSkuPopup" @close="closeSkuPopup" @add-cart="addCart" @buy-now="buyNow" @num-change='numChange' @open="openSkuPopup" @close="closeSkuPopup" @add-cart="addCart" @buy-now="buyNow" @num-change='numChange'
@selected-old='selectedOld' buyNowText="立即购买" :maxBuyNum="maxBuyNum" /> @selected-old='selectedOld' buyNowText="立即购买" :maxBuyNum="maxBuyNum" :addressResult='addressResult' />
</template> </template>
<script> <script>
@ -40,12 +40,7 @@
default: {} default: {}
}, },
addressResult: { addressResult: {
type: Object, type: Object
default: {
province: '江苏省',
city: '南京市',
district: '玄武区'
}
}, },
}, },
data() { data() {
@ -218,8 +213,8 @@
let that = this; let that = this;
let params = { let params = {
list: [{ list: [{
goods_id: that.goods.goods_id, goods_id:selectShop.goods_id,
num: that.selectNum num: selectShop.buy_num
}], }],
province: that.addressResult ? that.addressResult.province : '江苏省', province: that.addressResult ? that.addressResult.province : '江苏省',
city: that.addressResult ? that.addressResult.city : '南京市', city: that.addressResult ? that.addressResult.city : '南京市',

Loading…
Cancel
Save