Browse Source

修改秒杀详情无法更改数量的问题

master
Gao xiaosong 4 years ago
parent
commit
3233ff782f
  1. 2
      pages/activity/GoodsSeckill/index.vue
  2. 654
      pages/activity/SeckillDetails/index.vue

2
pages/activity/GoodsSeckill/index.vue

@ -50,7 +50,7 @@
<view class="grab" v-if="item.status === 1 && itemSeckill.stock <= 0">已售磬</view> <view class="grab" v-if="item.status === 1 && itemSeckill.stock <= 0">已售磬</view>
<view class="grab bg-color-red" @click="goDetail(itemSeckill.id,item.status)" v-if="item.status === 2">即将开始 <view class="grab bg-color-red" @click="goDetail(itemSeckill.id,item.status)" v-if="item.status === 2">即将开始
</view> </view>
<view class="grab bg-color-red" v-if="item.status === 0">已结束</view> <view class="grab bg-color-red" @click="goDetail(itemSeckill.id,item.status)" v-if="item.status === 0">已结束</view>
</view> </view>
</view> </view>
<view class="noCommodity" style="background-color: #f5f5f5;" v-if="seckillList.length === 0 && page > 1"> <view class="noCommodity" style="background-color: #f5f5f5;" v-if="seckillList.length === 0 && page > 1">

654
pages/activity/SeckillDetails/index.vue

@ -1,5 +1,8 @@
<template> <template>
<view :class="[posterImageStatus ? 'noscroll product-con' : 'product-con']" v-show="domStatus"> <view
:class="[posterImageStatus ? 'noscroll product-con' : 'product-con']"
v-show="domStatus"
>
<product-con-swiper :imgUrls="imgUrls"></product-con-swiper> <product-con-swiper :imgUrls="imgUrls"></product-con-swiper>
<view class="nav acea-row row-between-wrapper"> <view class="nav acea-row row-between-wrapper">
<view class="money"> <view class="money">
@ -10,8 +13,15 @@
<view class="acea-row row-middle"> <view class="acea-row row-middle">
<view class="times"> <view class="times">
<view>距秒杀结束仅剩</view> <view>距秒杀结束仅剩</view>
<count-down :isDay="false" :tipText="' '" :dayText="' '" :hourText="' : '" :minuteText="' : '" <count-down
:secondText="' '" :datatime="datatime/1000"></count-down> :isDay="false"
:tipText="' '"
:dayText="' '"
:hourText="' : '"
:minuteText="' : '"
:secondText="' '"
:datatime="datatime / 1000"
></count-down>
</view> </view>
<view class="iconfont icon-jiantou"></view> <view class="iconfont icon-jiantou"></view>
</view> </view>
@ -40,12 +50,12 @@
</view> </view>
<!-- 操作栏 --> <!-- 操作栏 -->
<view style="height:100rpx;"></view> <view style="height: 100rpx"></view>
<view class="footer acea-row row-between-wrapper"> <view class="footer acea-row row-between-wrapper">
<!-- #ifdef MP-WEIXIN --> <!-- #ifdef MP-WEIXIN -->
<view class="item"> <view class="item">
<button open-type="contact" class='contacButton'> <button open-type="contact" class="contacButton">
<view style="padding-bottom: 8rpx;" class="item"> <view style="padding-bottom: 8rpx" class="item">
<view class="iconfont icon-kefu"></view> <view class="iconfont icon-kefu"></view>
<text>客服</text> <text>客服</text>
</view> </view>
@ -60,11 +70,10 @@
<view class="iconfont icon-shoucang"></view> <view class="iconfont icon-shoucang"></view>
<text>收藏</text> <text>收藏</text>
</view> </view>
<view class="bnt acea-row" v-if=" <view
seckillStatus == 1 && class="bnt acea-row"
storeInfo.num > 0 && v-if="seckillStatus == 1 && storeInfo.num > 0 && storeInfo.stock > 0"
storeInfo.stock > 0 >
">
<view class="joinCart" @click="openAlone"> <view class="joinCart" @click="openAlone">
<text>单独购买</text> <text>单独购买</text>
</view> </view>
@ -73,11 +82,10 @@
</view> </view>
</view> </view>
<div class="bnt acea-row" v-if=" <div
seckillStatus == 1 && class="bnt acea-row"
storeInfo.num <= 0 && v-if="seckillStatus == 1 && storeInfo.num <= 0 && storeInfo.stock <= 0"
storeInfo.stock <= 0 >
">
<div class="joinCart" @click="openAlone">原价购买</div> <div class="joinCart" @click="openAlone">原价购买</div>
<div class="buy bg-color-hui">已售罄</div> <div class="buy bg-color-hui">已售罄</div>
</div> </div>
@ -89,319 +97,359 @@
<div class="joinCart" @click="openAlone">原价购买</div> <div class="joinCart" @click="openAlone">原价购买</div>
<div class="buy bg-color-hui">已结束</div> <div class="buy bg-color-hui">已结束</div>
</div> </div>
</view> </view>
<ProductWindow v-on:changeFun="changeFun" :attr="attr" :cartNum="cartNum"></ProductWindow> <ProductWindow
<StorePoster v-on:setPosterImageStatus="setPosterImageStatus" :posterImageStatus="posterImageStatus" v-on:changeFun="changeFun"
:posterData="posterData"></StorePoster> :attr="attr"
:cartNum="cartNum"
></ProductWindow>
<StorePoster
v-on:setPosterImageStatus="setPosterImageStatus"
:posterImageStatus="posterImageStatus"
:posterData="posterData"
></StorePoster>
</view> </view>
</template> </template>
<style scoped lang="less"> <style scoped lang="less">
.noscroll { .noscroll {
height: 100%; height: 100%;
overflow: hidden; overflow: hidden;
} }
</style> </style>
<script> <script>
import ProductConSwiper from "@/components/ProductConSwiper"; import ProductConSwiper from "@/components/ProductConSwiper";
import CountDown from "@/components/CountDown"; import CountDown from "@/components/CountDown";
import ProductWindow from "@/components/ProductWindow"; import ProductWindow from "@/components/ProductWindow";
import StorePoster from "@/components/StorePoster"; import StorePoster from "@/components/StorePoster";
import { import { getSeckillDetail } from "@/api/activity";
getSeckillDetail import { postCartAdd } from "@/api/store";
} from "@/api/activity"; import { imageBase64 } from "@/api/public";
import { import {
postCartAdd getCoupon,
} from "@/api/store"; getCollectAdd,
import { getCollectDel,
imageBase64 getUserInfo,
} from "@/api/public"; } from "@/api/user";
import { const NAME = "SeckillDetails";
getCoupon,
getCollectAdd,
getCollectDel,
getUserInfo
} from "@/api/user";
const NAME = "SeckillDetails";
export default { export default {
name: "SeckillDetails", name: "SeckillDetails",
components: { components: {
ProductConSwiper, ProductConSwiper,
CountDown, CountDown,
ProductWindow, ProductWindow,
StorePoster StorePoster,
}, },
props: {}, props: {},
data: function () { data: function () {
return {
seckillStatus: "",
domStatus: false,
posterData: {
image: "",
title: "",
price: "",
code: "",
},
posterImageStatus: false,
action: "",
imgUrls: [],
storeInfo: [],
replyCount: 0,
reply: [],
cartNum: 1,
attrTxt: "请选择",
productValue: [],
attrValue: "",
attr: {
cartAttr: false,
productAttr: [],
productSelect: {},
},
datatime: 0,
userCollect: false,
};
},
onShow: function () {
this.mountedStart();
},
methods: {
onShareAppMessage: function () {
return { return {
seckillStatus: '', title: this.storeInfo.title,
domStatus: false, imageUrl: this.storeInfo.image,
posterData: { path:
image: "", "pages/activity/GoodsSeckill/index?id=" +
title: "", this.storeInfo.id +
price: "", "&spread=" +
code: "" uni.getStorageSync("uid") +
"&pageType=good&codeType=routine",
success(res) {
uni.showToast({
title: "分享成功",
});
}, },
posterImageStatus: false, fail(res) {
action: "", uni.showToast({
imgUrls: [], title: "分享失败",
storeInfo: [], icon: "none",
replyCount: 0, });
reply: [],
cartNum: 1,
attrTxt: "请选择",
productValue: [],
attrValue: "",
attr: {
cartAttr: false,
productAttr: [],
productSelect: {},
}, },
datatime: 0,
userCollect: false
}; };
}, },
onShow: function () { openAlone: function () {
this.mountedStart(); this.$yrouter.push({
path: "/pages/shop/GoodsCon/index",
query: {
id: this.storeInfo.productId,
},
});
// this.$yrouter.replace({ path: "/detail/" + this.storeInfo.productId });
},
routerGo(item) {
this.$yrouter.push({
path: "/pages/user/CustomerList/index",
});
}, },
methods: { //
onShareAppMessage: function () { setCollect: function () {
return { let that = this,
title: this.storeInfo.title, id = that.storeInfo.id,
imageUrl: this.storeInfo.image, category = "product";
path: "pages/activity/GoodsSeckill/index?id=" + this.storeInfo.id + "&spread=" + uni.getStorageSync("uid") + if (that.userCollect) {
"&pageType=good&codeType=routine", getCollectDel(id, category).then(function () {
success(res) { that.userCollect = !that.userCollect;
uni.showToast({
title: '分享成功'
})
},
fail(res) {
uni.showToast({
title: '分享失败',
icon: 'none'
})
}
}
},
openAlone: function () {
this.$yrouter.push({
path: "/pages/shop/GoodsCon/index",
query: {
id: this.storeInfo.productId
}
}); });
// this.$yrouter.replace({ path: "/detail/" + this.storeInfo.productId }); } else {
}, getCollectAdd(id, category).then(function () {
routerGo(item) { that.userCollect = !that.userCollect;
this.$yrouter.push({
path: '/pages/user/CustomerList/index'
})
},
//
setCollect: function () {
let that = this,
id = that.storeInfo.id,
category = "product";
if (that.userCollect) {
getCollectDel(id, category).then(function () {
that.userCollect = !that.userCollect;
});
} else {
getCollectAdd(id, category).then(function () {
that.userCollect = !that.userCollect;
});
}
},
mountedStart: function () {
var that = this;
console.log(this)
let id = that.$yroute.query.id;
this.seckillStatus = that.$yroute.query.status;
that.datatime = parseInt(that.$yroute.query.time);
getSeckillDetail(id).then(res => {
that.userCollect = res.data.userCollect;
res.data.storeInfo.description = res.data.storeInfo.description.replace(
/\<img/gi,
'<img style="max-width:100%;height:auto;"'
);
that.$set(that.attr, "productAttr", res.data.productAttr);
that.$set(that, "productValue", res.data.productValue);
that.$set(that, "storeInfo", res.data.storeInfo);
that.$set(that, "imgUrls", res.data.storeInfo.sliderImageArr);
that.$set(that, "replyCount", res.data.replyCount);
that.$set(that, "reply", res.data.reply);
that.posterData.image = that.storeInfo.image_base;
that.updateTitle();
if (that.storeInfo.title.length > 30) {
that.posterData.title = that.storeInfo.title.substring(0, 30) + "...";
} else {
that.posterData.title = that.storeInfo.title;
}
that.posterData.price = that.storeInfo.price;
that.posterData.code = that.storeInfo.code_base;
// that.setProductSelect();
that.domStatus = true;
that.DefaultSelect();
}); });
}, }
updateTitle() { },
// document.title = this.storeInfo.title || this.$yroute.meta.title; mountedStart: function () {
}, var that = this;
setPosterImageStatus: function () { console.log(this);
// var sTop = document.body || document.documentElement; let id = that.$yroute.query.id;
// sTop.scrollTop = 0; this.seckillStatus = that.$yroute.query.status;
this.posterImageStatus = !this.posterImageStatus; that.datatime = parseInt(that.$yroute.query.time);
}, getSeckillDetail(id).then((res) => {
DefaultSelect: function () { that.userCollect = res.data.userCollect;
let productAttr = this.attr.productAttr; res.data.storeInfo.description = res.data.storeInfo.description.replace(
let value = []; /\<img/gi,
for (let i = 0; i < productAttr.length; i++) { '<img style="max-width:100%;height:auto;"'
this.$set(productAttr[i], "index", 0); );
value.push(productAttr[i].attrValueArr[0]); that.$set(that.attr, "productAttr", res.data.productAttr);
that.$set(that, "productValue", res.data.productValue);
that.$set(that, "storeInfo", res.data.storeInfo);
that.$set(that, "imgUrls", res.data.storeInfo.sliderImageArr);
that.$set(that, "replyCount", res.data.replyCount);
that.$set(that, "reply", res.data.reply);
that.posterData.image = that.storeInfo.image_base;
that.updateTitle();
if (that.storeInfo.title.length > 30) {
that.posterData.title = that.storeInfo.title.substring(0, 30) + "...";
} else {
that.posterData.title = that.storeInfo.title;
} }
//sort();:-- that.posterData.price = that.storeInfo.price;
let productSelect = this.productValue[value.sort().join(",")]; that.posterData.code = that.storeInfo.code_base;
console.log(productSelect) // that.setProductSelect();
if (productSelect && productAttr.length) { that.domStatus = true;
this.$set( that.DefaultSelect();
this.attr.productSelect, });
"store_name", },
this.storeInfo.title updateTitle() {
); // document.title = this.storeInfo.title || this.$yroute.meta.title;
this.$set(this.attr.productSelect, "image", productSelect.image); },
this.$set(this.attr.productSelect, "price", productSelect.seckillPrice); setPosterImageStatus: function () {
this.$set(this.attr.productSelect, "stock", productSelect.seckillStock); // var sTop = document.body || document.documentElement;
this.$set(this.attr.productSelect, "unique", productSelect.unique); // sTop.scrollTop = 0;
this.$set(this.attr.productSelect, "cart_num", 1); this.posterImageStatus = !this.posterImageStatus;
this.$set(this, "attrValue", value.sort().join(",")); },
this.$set(this, "attrTxt", "已选择"); DefaultSelect: function () {
} else if (!productSelect && productAttr.length) { let productAttr = this.attr.productAttr;
this.$set( let value = [];
this.attr.productSelect, for (let i = 0; i < productAttr.length; i++) {
"store_name", this.$set(productAttr[i], "index", 0);
this.storeInfo.title value.push(productAttr[i].attrValueArr[0]);
); }
this.$set(this.attr.productSelect, "image", this.storeInfo.image); //sort();:--
this.$set(this.attr.productSelect, "price", this.storeInfo.seckillPrice); let productSelect = this.productValue[value.sort().join(",")];
this.$set(this.attr.productSelect, "stock", 0); console.log(productSelect);
this.$set(this.attr.productSelect, "unique", ""); if (productSelect && productAttr.length) {
this.$set(this.attr.productSelect, "cart_num", 0); this.$set(this.attr.productSelect, "store_name", this.storeInfo.title);
this.$set(this, "attrValue", ""); this.$set(this.attr.productSelect, "image", productSelect.image);
this.$set(this, "attrTxt", "请选择"); this.$set(this.attr.productSelect, "price", productSelect.seckillPrice);
} else if (!productSelect && !productAttr.length) { this.$set(this.attr.productSelect, "stock", productSelect.seckillStock);
this.$set( this.$set(this.attr.productSelect, "unique", productSelect.unique);
this.attr.productSelect, this.$set(this.attr.productSelect, "cart_num", 1);
"store_name", this.$set(this, "attrValue", value.sort().join(","));
this.storeInfo.title this.$set(this, "attrTxt", "已选择");
); } else if (!productSelect && productAttr.length) {
this.$set(this.attr.productSelect, "image", this.storeInfo.image); this.$set(this.attr.productSelect, "store_name", this.storeInfo.title);
this.$set(this.attr.productSelect, "price", this.storeInfo.seckillPrice); this.$set(this.attr.productSelect, "image", this.storeInfo.image);
this.$set(this.attr.productSelect, "stock", this.storeInfo.seckillStock); this.$set(
this.$set( this.attr.productSelect,
this.attr.productSelect, "price",
"unique", this.storeInfo.seckillPrice
this.storeInfo.unique || "" );
); this.$set(this.attr.productSelect, "stock", 0);
this.$set(this.attr.productSelect, "cart_num", 1); this.$set(this.attr.productSelect, "unique", "");
this.$set(this, "attrValue", ""); this.$set(this.attr.productSelect, "cart_num", 0);
this.$set(this, "attrTxt", "请选择"); this.$set(this, "attrValue", "");
this.$set(this, "attrTxt", "请选择");
} else if (!productSelect && !productAttr.length) {
this.$set(this.attr.productSelect, "store_name", this.storeInfo.title);
this.$set(this.attr.productSelect, "image", this.storeInfo.image);
this.$set(
this.attr.productSelect,
"price",
this.storeInfo.seckillPrice
);
this.$set(
this.attr.productSelect,
"stock",
this.storeInfo.seckillStock
);
this.$set(
this.attr.productSelect,
"unique",
this.storeInfo.unique || ""
);
this.$set(this.attr.productSelect, "cart_num", 1);
this.$set(this, "attrValue", "");
this.$set(this, "attrTxt", "请选择");
}
},
//
changeFun: function (opt) {
if (typeof opt !== "object") opt = {};
let action = opt.action || "";
let value = opt.value === undefined ? "" : opt.value;
this[action] && this[action](value);
},
changeattr: function (res) {
var that = this;
that.attr.cartAttr = res;
},
// ChangeCartNum: function (res) {
// var that = this;
// if (res) {
// if (that.attr.productSelect.cart_num < that.storeInfo.seckillStock) {
// that.attr.productSelect.cart_num += 1;
// this.cartNum += 1;
// console.log(this.cartNum)
// }
// } else {
// if (that.attr.productSelect.cart_num > 1) {
// that.attr.productSelect.cart_num -= 1;
// this.cartNum -= 1;
// }
// }
// },
ChangeCartNum: function (changeValue) {
//changeValue: |
//
let productSelect = this.productValue[this.attrValue];
//,
if (productSelect === undefined && !this.attr.productAttr.length) {
productSelect = this.attr.productSelect;
} }
}, //0
// if (productSelect === undefined) return;
changeFun: function (opt) { let stock = productSelect.stock || 0;
if (typeof opt !== "object") opt = {}; let num = this.attr.productSelect;
let action = opt.action || ""; if (changeValue) {
let value = opt.value === undefined ? "" : opt.value; num.cart_num++;
this[action] && this[action](value); if (num.cart_num > stock) {
}, this.$set(this.attr.productSelect, "cart_num", stock);
changeattr: function (res) { this.$set(this, "cartNum", stock);
var that = this; } else {
that.attr.cartAttr = res; this.$set(this.attr.productSelect, "cart_num", num.cart_num);
}, this.$set(this, "cartNum", num.cart_num);
ChangeCartNum: function (res) {
var that = this;
if (res) {
if (that.attr.productSelect.cart_num < that.storeInfo.seckillStock) {
that.attr.productSelect.cart_num++;
this.cartNum++;
} }
} else { } else {
if (that.attr.productSelect.cart_num > 1) { num.cart_num--;
that.attr.productSelect.cart_num--; if (num.cart_num < 1) {
this.cartNum--; this.$set(this.attr.productSelect, "cart_num", 1);
this.$set(this, "cartNum", 1);
} else {
this.$set(this.attr.productSelect, "cart_num", num.cart_num);
this.$set(this, "cartNum", num.cart_num);
} }
} }
}, },
// //
ChangeAttr: function (res) { ChangeAttr: function (res) {
// //
let productSelect = this.productValue[res.value]; let productSelect = this.productValue[res.value];
if (productSelect) { if (productSelect) {
this.attr.productAttr[res.indexw].index = res.indexn; this.attr.productAttr[res.indexw].index = res.indexn;
this.$set(this.attr.productSelect, "image", productSelect.image); this.$set(this.attr.productSelect, "image", productSelect.image);
this.$set(this.attr.productSelect, "price", productSelect.seckillPrice); this.$set(this.attr.productSelect, "price", productSelect.seckillPrice);
this.$set(this.attr.productSelect, "stock", productSelect.seckillStock); this.$set(this.attr.productSelect, "stock", productSelect.seckillStock);
this.$set(this.attr.productSelect, "unique", productSelect.unique); this.$set(this.attr.productSelect, "unique", productSelect.unique);
this.$set(this.attr.productSelect, "cart_num", 1); this.$set(this.attr.productSelect, "cart_num", 1);
this.$set(this, "attrValue", res.value); this.$set(this, "attrValue", res.value);
this.$set(this, "attrTxt", "已选择"); this.$set(this, "attrTxt", "已选择");
} else { } else {
this.$set(this.attr.productSelect, "image", this.storeInfo.image); this.$set(this.attr.productSelect, "image", this.storeInfo.image);
this.$set(this.attr.productSelect, "price", this.storeInfo.seckillPrice); this.$set(
this.$set(this.attr.productSelect, "stock", 0); this.attr.productSelect,
this.$set(this.attr.productSelect, "unique", ""); "price",
this.$set(this.attr.productSelect, "cart_num", 0); this.storeInfo.seckillPrice
this.$set(this, "attrValue", ""); );
this.$set(this, "attrTxt", "请选择"); this.$set(this.attr.productSelect, "stock", 0);
} this.$set(this.attr.productSelect, "unique", "");
}, this.$set(this.attr.productSelect, "cart_num", 0);
selecAttrTap: function () { this.$set(this, "attrValue", "");
this.attr.cartAttr = true; this.$set(this, "attrTxt", "请选择");
this.isOpen = true; }
}, },
tapBuy: function () { selecAttrTap: function () {
var that = this; this.attr.cartAttr = true;
if (that.attr.cartAttr == false) { this.isOpen = true;
that.attr.cartAttr = !this.attr.attrcartAttr; },
} else { tapBuy: function () {
var data = {}; var that = this;
data.productId = that.storeInfo.productId; if (that.attr.cartAttr == false) {
data.cartNum = that.attr.productSelect.cart_num; that.attr.cartAttr = !this.attr.attrcartAttr;
data.uniqueId = that.attr.productSelect.unique; } else {
data.secKillId = that.storeInfo.id; var data = {};
data.new = 1; data.productId = that.storeInfo.productId;
postCartAdd(data) data.cartNum = that.attr.productSelect.cart_num;
.then(res => { data.uniqueId = that.attr.productSelect.unique;
that.$yrouter.push({ data.secKillId = that.storeInfo.id;
path: "/pages/order/OrderSubmission/index", data.new = 1;
query: { postCartAdd(data)
id: res.data.cartId .then((res) => {
} that.$yrouter.push({
}); path: "/pages/order/OrderSubmission/index",
}) query: {
.catch(err => { id: res.data.cartId,
uni.showToast({ },
title: err.msg || err.response.data.msg || err.response.data.message,
icon: 'none',
duration: 2000
});
}); });
} })
.catch((err) => {
uni.showToast({
title:
err.msg || err.response.data.msg || err.response.data.message,
icon: "none",
duration: 2000,
});
});
} }
} },
}; },
};
</script> </script>
<style scoped lang="less"> <style scoped lang="less">
.product-con .nav { .product-con .nav {
padding: 0 0.2*100rpx; padding: 0 0.2 * 100rpx;
} }
.product-con .footer .bnt .buy.bg-color-hui { .product-con .footer .bnt .buy.bg-color-hui {
background: #ccc; background: #ccc;
}
}
</style> </style>

Loading…
Cancel
Save