tmp: 部分代码与UnishopV5结合,但是代码有严重缺陷
This commit is contained in:
@@ -31,9 +31,11 @@
|
||||
@click="change(item_value.sku_id, item_value.spec_id)">
|
||||
<image v-if="item_value.image" :src="$util.img(item_value.image, { size: 'small' })" @error="valueImageError(index, index_value)" />
|
||||
<text>{{ item_value.spec_value_name }}</text>
|
||||
<view class="empty-stock" v-if="item_value.stock == 0">缺货</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<ns-form :data="goodsForm" v-if="goodsForm" ref="form"></ns-form>
|
||||
</scroll-view>
|
||||
</view>
|
||||
<view class="footer">
|
||||
@@ -50,12 +52,12 @@
|
||||
</view>
|
||||
</view>
|
||||
<view class="footer-right">
|
||||
<view class="change_num" v-if="number > 0">
|
||||
<view class="change_num" v-if="cartInputLock">
|
||||
<view class="num-action" @click="changeNum('-')">
|
||||
<text class="desc iconfont icon-jianshao color-base-text"></text>
|
||||
<view class="click-event"></view>
|
||||
</view>
|
||||
<input type="number" class="uni-input" @blur="blur" v-model="number" placeholder="0" @input="keyInput(false)" />
|
||||
<input type="number" class="uni-input" @blur="blur" v-model.lazy="number" placeholder="0" @input="keyInput(false,null,true)" />
|
||||
<view class="num-action" :id="'select-sku-num-' + goodsDetail.goods_id" @click="changeNum('+', $event)">
|
||||
<text class="add iconfont icon-add-fill color-base-text change_hover"></text>
|
||||
<view class="click-event"></view>
|
||||
@@ -115,7 +117,9 @@
|
||||
maxBuy: 0,
|
||||
minBuy: 0,
|
||||
isLoad: false,
|
||||
timeout: null
|
||||
timeout: null,
|
||||
goodsForm: null,
|
||||
skuList: []
|
||||
};
|
||||
},
|
||||
created() {
|
||||
@@ -124,21 +128,44 @@
|
||||
watch: {
|
||||
pointLimit(newNum, oldNum) {
|
||||
this.limitNumber = Number(newNum);
|
||||
},
|
||||
minBuy(newData, oldData) {
|
||||
if (this.minBuy > 1) {
|
||||
this.number = Number(this.minBuy);
|
||||
}
|
||||
},
|
||||
computed:{
|
||||
cartInputLock:function() {
|
||||
if(!this.isLoad){
|
||||
return true
|
||||
}else if(this.number>0){
|
||||
return true
|
||||
}else{
|
||||
return false
|
||||
}
|
||||
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
calcSkuStock() {
|
||||
if(this.goodsDetail.goods_spec_format && this.goodsDetail.goods_spec_format.length){
|
||||
this.goodsDetail.goods_spec_format.forEach(spec => {
|
||||
spec.value.forEach(val => {
|
||||
this.skuList.forEach(sku => {
|
||||
if (val.sku_id == sku.sku_id) {
|
||||
this.$set(val,'stock',sku.stock);
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
},
|
||||
show(data) {
|
||||
this.number = 0 ; // 每次打开要初始化
|
||||
this.isLoad = true;
|
||||
this.goodsDetail = data;
|
||||
this.goodsId = this.goodsDetail.goods_id;
|
||||
this.skuId = this.goodsDetail.sku_id;
|
||||
this.maxBuy = this.goodsDetail.max_buy;
|
||||
this.minBuy = this.goodsDetail.min_buy;
|
||||
this.goodsForm = null
|
||||
this.getGoodsForm()
|
||||
this.getGoodsSkuList(this.goodsId);
|
||||
this.keyInput(false);
|
||||
if (this.getCurrentCart()) {
|
||||
@@ -146,6 +173,19 @@
|
||||
}
|
||||
this.$refs.skuPopup.open();
|
||||
},
|
||||
getGoodsForm(){
|
||||
this.$api.sendRequest({
|
||||
url: "/form/api/form/goodsform",
|
||||
data: {
|
||||
goods_id: this.goodsDetail.goods_id
|
||||
},
|
||||
success: res => {
|
||||
if (res.code == 0 && res.data) {
|
||||
this.goodsForm = res.data
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
hide() {
|
||||
if(this.$refs.skuPopup) this.$refs.skuPopup.close();
|
||||
},
|
||||
@@ -175,6 +215,7 @@
|
||||
} else {
|
||||
this.number = 0;
|
||||
}
|
||||
this.calcSkuStock()
|
||||
},
|
||||
//查看规格图片
|
||||
previewMedia() {
|
||||
@@ -200,7 +241,7 @@
|
||||
if (res.code >= 0) {
|
||||
let data = res.data,
|
||||
obj = {};
|
||||
|
||||
|
||||
res.data.forEach((item, index) => {
|
||||
// 当前商品SKU规格
|
||||
if (item.sku_spec_format) item.sku_spec_format = JSON.parse(item.sku_spec_format);
|
||||
@@ -228,6 +269,8 @@
|
||||
obj['sku_' + item.sku_id] = item;
|
||||
});
|
||||
this.goodsSkuList = obj;
|
||||
this.skuList = res.data;
|
||||
this.calcSkuStock();
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -281,12 +324,11 @@
|
||||
}
|
||||
|
||||
const query = uni.createSelectorQuery().in(this);
|
||||
query.select('#' + event.currentTarget.id + ' .click-event')
|
||||
.boundingClientRect(data => {
|
||||
if (data) {
|
||||
this.$emit('addCart', data.left, data.top);
|
||||
}
|
||||
}).exec();
|
||||
query.select('#' + event.currentTarget.id + ' .click-event').boundingClientRect(data => {
|
||||
if (data) {
|
||||
this.$emit('addCart', data.left, data.top);
|
||||
}
|
||||
}).exec();
|
||||
} else if (tag == '-') {
|
||||
// 减
|
||||
if (this.number > min) {
|
||||
@@ -325,14 +367,16 @@
|
||||
|
||||
let newNumber = parseInt(this.number);
|
||||
|
||||
this.isLoad = false;
|
||||
this.isLoad = true;
|
||||
|
||||
setTimeout(() => {
|
||||
this.number = newNumber;
|
||||
this.cartNumChange(this.number);
|
||||
}, 0);
|
||||
},
|
||||
//输入数量
|
||||
keyInput(flag, callback) {
|
||||
keyInput(flag, callback,isInput) {
|
||||
if(isInput) this.isLoad = false
|
||||
setTimeout(() => {
|
||||
var stock = this.goodsDetail.stock;
|
||||
|
||||
@@ -352,7 +396,7 @@
|
||||
this.number = stock;
|
||||
}
|
||||
// 商品起售数
|
||||
if (this.minBuy > 1 && this.number < this.minBuy) {
|
||||
if (flag && this.minBuy > 1 && this.number < this.minBuy) {
|
||||
this.number = this.minBuy;
|
||||
}
|
||||
|
||||
@@ -374,7 +418,13 @@
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.$refs.form) {
|
||||
if (!this.$refs.form.verify()) return;
|
||||
uni.setStorageSync('goodFormData', {
|
||||
goods_id: this.goodsDetail.goods_id,
|
||||
form_data: this.$refs.form.formData
|
||||
});
|
||||
}
|
||||
this.number = 1;
|
||||
//纠正数量
|
||||
this.keyInput(true, () => {
|
||||
@@ -676,7 +726,20 @@
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
|
||||
.body-item .sku-list-wrap .empty-stock{
|
||||
font-size: 18rpx;
|
||||
line-height: 22rpx;
|
||||
position: absolute;
|
||||
right: 0;
|
||||
top: 0;
|
||||
border-radius: 4rpx;
|
||||
transform: translateY(-50%);
|
||||
padding: 0 2rpx;
|
||||
color: #989898;
|
||||
background-color: #f0f1f2;
|
||||
}
|
||||
|
||||
.sku-layer .body-item .sku-list-wrap .items {
|
||||
text-align: center;
|
||||
position: relative;
|
||||
|
||||
@@ -51,12 +51,7 @@
|
||||
* @param {Object} data 商品项
|
||||
*/
|
||||
singleSpecificationGoods(data, event) {
|
||||
let cart =
|
||||
this.cartList['goods_' + data.goods_id] && this.cartList['goods_' + data.goods_id]['sku_' + data
|
||||
.sku_id
|
||||
] ?
|
||||
this.cartList['goods_' + data.goods_id]['sku_' + data.sku_id] :
|
||||
null;
|
||||
let cart = this.cartList['goods_' + data.goods_id] && this.cartList['goods_' + data.goods_id]['sku_' + data.sku_id] ? this.cartList['goods_' + data.goods_id]['sku_' + data.sku_id] : null;
|
||||
|
||||
let cartNum = cart ? cart.num : 0;
|
||||
let api = cart && cart.cart_id ? '/api/cart/edit' : '/api/cart/add';
|
||||
@@ -66,6 +61,7 @@
|
||||
if(cart && cart.cart_id){
|
||||
_num = _num + (data.min_buy > 0 ? data.min_buy : 1)
|
||||
}
|
||||
|
||||
let cart_id = cart ? cart.cart_id : 0;
|
||||
if (_num > parseInt(data.stock)) {
|
||||
this.$util.showToast({
|
||||
@@ -119,8 +115,7 @@
|
||||
this.isRepeat = false;
|
||||
if (res.code == 0) {
|
||||
if (cart_id == 0) {
|
||||
this.cartList['goods_' + data.goods_id]['sku_' + data.sku_id].cart_id =
|
||||
res.data;
|
||||
this.cartList['goods_' + data.goods_id]['sku_' + data.sku_id].cart_id = res.data;
|
||||
}
|
||||
this.$util.showToast({
|
||||
title: "商品添加购物车成功"
|
||||
|
||||
@@ -153,6 +153,7 @@
|
||||
}" class="items" @click="change(item_value.sku_id, item_value.spec_id)">
|
||||
<image v-if="item_value.image" :src="$util.img(item_value.image, { size: 'small' })" @error="valueImageError(index, index_value)" />
|
||||
<text>{{ item_value.spec_value_name }}</text>
|
||||
<view class="empty-stock" v-if="item_value.stock == 0">缺货</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
@@ -173,8 +174,8 @@
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<ns-form :data="goodsForm" v-if="goodsForm" ref="form"></ns-form>
|
||||
|
||||
<ns-form :data="goodsForm" v-if="goodsForm" ref="form" @changeFormVal="changeFormVal"></ns-form>
|
||||
</scroll-view>
|
||||
</view>
|
||||
<view class="footer" @click="confirm()">
|
||||
@@ -182,7 +183,8 @@
|
||||
<block v-if="type == 'point'">
|
||||
<block v-if="goodsDetail.type == 1">
|
||||
<!-- 兑换商品 -->
|
||||
<button v-if="goodsDetail.stock && goodsDetail.stock != 0" type="primary">兑换</button>
|
||||
<button v-if="goodsDetail.point * number > memberPoint" disabled="true" type="primary">积分不足</button>
|
||||
<button v-else-if="goodsDetail.stock && goodsDetail.stock != 0" type="primary">兑换</button>
|
||||
<button type="primary" v-else disabled="true">库存不足</button>
|
||||
</block>
|
||||
<block v-else-if="goodsDetail.type == 2 || goodsDetail.type == 3">
|
||||
@@ -195,7 +197,8 @@
|
||||
<button type="primary" v-else-if="goodsDetail.stock && goodsDetail.stock != 0 && type == 'buy_now'">立即购买</button>
|
||||
<button type="primary" v-else-if="goodsDetail.stock && goodsDetail.stock != 0 && type == 'confirm'">确认</button>
|
||||
<template v-else-if="goodsDetail.stock && goodsDetail.stock != 0">
|
||||
<template v-if="goodsDetail.buy_num">
|
||||
<!-- 拼团和拼返的buy_num代表最大购买数量,不是最小购买数量 -->
|
||||
<template v-if="type != 'pintuan' && type != 'pinfan' && goodsDetail.buy_num">
|
||||
<button type="primary" v-if="goodsDetail.buy_num <= goodsDetail.stock">立即抢购</button>
|
||||
<button type="primary" v-else disabled="true">库存不足</button>
|
||||
</template>
|
||||
@@ -226,6 +229,10 @@
|
||||
type: [Number, String],
|
||||
default: 0
|
||||
},
|
||||
memberPoint: {
|
||||
type: [Number, String],
|
||||
default: 0
|
||||
},
|
||||
goodsDetail: {
|
||||
type: Object,
|
||||
default: null
|
||||
@@ -244,6 +251,12 @@
|
||||
minBuy: {
|
||||
type: Number,
|
||||
default: 0
|
||||
},
|
||||
goodsFormVal: {
|
||||
type: Array,
|
||||
default () {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
},
|
||||
data() {
|
||||
@@ -265,7 +278,8 @@
|
||||
pintuan_num_field: 'pintuan_num',
|
||||
goodsSkuInfo: null, //所有的商品规格信息
|
||||
goodsForm: null,
|
||||
isLoad: false // 是否首次加载
|
||||
isLoad: false ,// 是否首次加载
|
||||
skuList: [],//所有规格数据
|
||||
};
|
||||
},
|
||||
created() {
|
||||
@@ -310,8 +324,8 @@
|
||||
this.pintuan_num_field = newData.pintuan_num_field;
|
||||
}
|
||||
if (this.goodsDetail.goods_form && !this.goodsForm) this.goodsForm = this.goodsDetail.goods_form;
|
||||
|
||||
// 切换商品,重新赋值
|
||||
this.calcSkuStock()
|
||||
if (newData.goods_id != oldData.goods_id) {
|
||||
if (this.goodsDetail.pintuan_id) {
|
||||
this.getPintuanGoodsSkuList();
|
||||
@@ -378,6 +392,34 @@
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
calcSkuStock() {
|
||||
if(this.goodsDetail.goods_spec_format && this.goodsDetail.goods_spec_format.length){
|
||||
this.goodsDetail.goods_spec_format.forEach(spec => {
|
||||
spec.value.forEach(val => {
|
||||
this.skuList.forEach(sku => {
|
||||
if (val.sku_id == sku.sku_id) {
|
||||
this.$set(val,'stock',sku.stock);
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
},
|
||||
changeFormVal(e) {
|
||||
this.$emit('detailChangeVal',e)
|
||||
},
|
||||
getGoodsForm(){
|
||||
this.$api.sendRequest({
|
||||
url: "/form/api/form/goodsform",
|
||||
data: {
|
||||
goods_id: this.goodsDetail.goods_id
|
||||
},
|
||||
success: res => {
|
||||
if (res.code == 0 && res.data) this.$set(this.goodsDetail, 'goods_form', res.data);
|
||||
if(this.goodsFormVal.length) Object.assign(this.goodsDetail.goods_form,this.goodsFormVal)
|
||||
}
|
||||
});
|
||||
},
|
||||
//【普通商品】获取所有规格信息
|
||||
getGeneralGoodsSkuList(callback) {
|
||||
this.$api.sendRequest({
|
||||
@@ -387,9 +429,7 @@
|
||||
},
|
||||
success: res => {
|
||||
if (res.code >= 0) {
|
||||
let data = res.data,
|
||||
obj = {};
|
||||
|
||||
let obj = {};
|
||||
res.data.forEach((item, index) => {
|
||||
item = this.handleData(item);
|
||||
|
||||
@@ -415,6 +455,8 @@
|
||||
if (this.skuId == 0) this.skuId = res.data[0].sku_id;
|
||||
this.goodsSkuInfo = obj;
|
||||
this.isLoad = false;
|
||||
this.skuList = res.data;
|
||||
this.calcSkuStock();
|
||||
if (callback) callback();
|
||||
} else {
|
||||
this.$util.redirectTo('/pages/index/index');
|
||||
@@ -493,7 +535,7 @@
|
||||
item = this.handleData(item);
|
||||
item.show_price = this.goodsDetail.groupbuy_price;
|
||||
item.save_price = item.price - item.show_price > 0 ? (item.price - item.show_price).toFixed(2) : 0;
|
||||
|
||||
//团购buy_num指最少购买数量
|
||||
if (data.stock > data.buy_num) {
|
||||
this.number = this.goodsDetail.buy_num;
|
||||
this.minNumber = this.goodsDetail.buy_num;
|
||||
@@ -730,6 +772,9 @@
|
||||
popclose() {
|
||||
if (this.$refs.skuPopup.showPopup) {
|
||||
this.$emit('hideSkuPop');
|
||||
}else{
|
||||
this.goodsForm = null
|
||||
this.getGoodsForm()
|
||||
}
|
||||
},
|
||||
//查看规格图片
|
||||
@@ -766,7 +811,6 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.goodsSkuDetail = this.goodsSkuInfo['sku_' + this.skuId];
|
||||
this.$emit('refresh', this.goodsSkuDetail);
|
||||
this.$emit('getSkuId', this.skuId);
|
||||
@@ -781,6 +825,7 @@
|
||||
this.confirmDisabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
this.keyInput(true);
|
||||
},
|
||||
showPrice(price) {
|
||||
@@ -1013,7 +1058,7 @@
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.goodsDetail.buy_num > this.goodsDetail.stock) {
|
||||
if (this.type != 'pintuan' && this.type != 'pinfan' && this.goodsDetail.buy_num > this.goodsDetail.stock) {
|
||||
this.$util.showToast({
|
||||
title: '库存小于最低购买数量'
|
||||
});
|
||||
@@ -1077,7 +1122,7 @@
|
||||
title: '加入购物车成功'
|
||||
});
|
||||
this.cartNum += this.number;
|
||||
|
||||
this.$store.dispatch('getCartNumber');
|
||||
let discount_price = this.goodsDetail.discount_price;
|
||||
if (this.goodsDetail.member_price > 0 && Number(this.goodsDetail.member_price) <= Number(this.goodsDetail.discount_price)) {
|
||||
discount_price = this.goodsDetail.member_price;
|
||||
@@ -1213,28 +1258,29 @@
|
||||
});
|
||||
} else if (this.type == 'bargain') {
|
||||
// 砍价
|
||||
this.$api.sendRequest({
|
||||
url: '/bargain/api/bargain/launch',
|
||||
data: {
|
||||
id: this.goodsDetail.id
|
||||
},
|
||||
success: res => {
|
||||
this.btnSwitch = false;
|
||||
if (res.code == 0) {
|
||||
this.$util.redirectTo(
|
||||
'/pages_promotion/bargain/detail', {
|
||||
if (this.callback) {
|
||||
this.callback();
|
||||
}else {
|
||||
this.$api.sendRequest({
|
||||
url: '/bargain/api/bargain/launch',
|
||||
data: {
|
||||
id: this.goodsDetail.id
|
||||
},
|
||||
success: res => {
|
||||
this.btnSwitch = false;
|
||||
if (res.code == 0) {
|
||||
this.$util.redirectTo('/pages_promotion/bargain/detail', {
|
||||
b_id: this.goodsDetail.bargain_id,
|
||||
l_id: res.data
|
||||
},
|
||||
'redirectTo'
|
||||
);
|
||||
} else {
|
||||
this.$util.showToast({
|
||||
title: res.message
|
||||
});
|
||||
}, 'redirectTo');
|
||||
} else {
|
||||
this.$util.showToast({
|
||||
title: res.message
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
} else if (this.type == 'point') {
|
||||
// 积分兑换
|
||||
var data = {
|
||||
@@ -1399,13 +1445,27 @@
|
||||
|
||||
.body-item .sku-list-wrap {
|
||||
padding-bottom: 0rpx;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.body-item .sku-list-wrap .title {
|
||||
padding: 20rpx 0;
|
||||
display: block;
|
||||
}
|
||||
|
||||
|
||||
.body-item .sku-list-wrap .empty-stock{
|
||||
font-size: 18rpx;
|
||||
line-height: 22rpx;
|
||||
position: absolute;
|
||||
right: 0;
|
||||
top: 0;
|
||||
border-radius: 4rpx;
|
||||
transform: translateY(-50%);
|
||||
padding: 0 2rpx;
|
||||
color: #989898;
|
||||
background-color: #f0f1f2;
|
||||
}
|
||||
|
||||
.body-item .sku-list-wrap .items {
|
||||
position: relative;
|
||||
display: inline-block;
|
||||
|
||||
Reference in New Issue
Block a user