|
@@ -60,6 +60,9 @@
|
|
import {
|
|
import {
|
|
getGoodsDetail
|
|
getGoodsDetail
|
|
} from '@/api/goods.js'
|
|
} from '@/api/goods.js'
|
|
|
|
+ import {
|
|
|
|
+ addGoodsToCart
|
|
|
|
+ } from '@/api/shoppingCart.js'
|
|
import jyfParser from "@/components/jyf-parser/jyf-parser";
|
|
import jyfParser from "@/components/jyf-parser/jyf-parser";
|
|
export default {
|
|
export default {
|
|
components: {
|
|
components: {
|
|
@@ -85,12 +88,8 @@
|
|
onLoad(opts) {
|
|
onLoad(opts) {
|
|
console.log(opts)
|
|
console.log(opts)
|
|
this.id = opts.id
|
|
this.id = opts.id
|
|
- this.goldLimit = opts.goldLimit
|
|
|
|
this.getDetail()
|
|
this.getDetail()
|
|
},
|
|
},
|
|
- onUnload() {
|
|
|
|
- uni.$off('addCart')
|
|
|
|
- },
|
|
|
|
methods: {
|
|
methods: {
|
|
// 查详情
|
|
// 查详情
|
|
getDetail(){
|
|
getDetail(){
|
|
@@ -98,6 +97,7 @@
|
|
console.log(res)
|
|
console.log(res)
|
|
if(res.status == 200){
|
|
if(res.status == 200){
|
|
this.goodContent = res.data
|
|
this.goodContent = res.data
|
|
|
|
+ this.goldLimit = res.data.goodsType.goldLimit
|
|
let arr=res.data.images.split(',')
|
|
let arr=res.data.images.split(',')
|
|
arr.map(item => {
|
|
arr.map(item => {
|
|
this.imageList.push({image:item})
|
|
this.imageList.push({image:item})
|
|
@@ -105,11 +105,44 @@
|
|
}
|
|
}
|
|
})
|
|
})
|
|
},
|
|
},
|
|
|
|
+ // 添加购物车
|
|
|
|
+ addGoodToCart(item){
|
|
|
|
+ uni.showLoading({
|
|
|
|
+ mask: true,
|
|
|
|
+ title: "加入购物车中..."
|
|
|
|
+ })
|
|
|
|
+ addGoodsToCart(item).then(res => {
|
|
|
|
+ if(res.status == 200){
|
|
|
|
+ // 刷新购物车
|
|
|
|
+ if(!item.hasCunzai){
|
|
|
|
+ this.$store.state.vuex_cartNums = this.$store.state.vuex_cartNums + 1
|
|
|
|
+ }
|
|
|
|
+ uni.showToast({
|
|
|
|
+ icon: 'none',
|
|
|
|
+ title:'加入购物车成功'
|
|
|
|
+ })
|
|
|
|
+ }else{
|
|
|
|
+ uni.hideLoading()
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ },
|
|
|
|
+ // 判断当前商品是否已存在购物车中
|
|
|
|
+ hasCunzai(data){
|
|
|
|
+ let list = this.$store.state.vuex_cartList
|
|
|
|
+ let row = list.find(item=> item.goodsTypeNo == data.goodsTypeNo)
|
|
|
|
+ return row
|
|
|
|
+ },
|
|
// 加入购物车
|
|
// 加入购物车
|
|
- addCart(){
|
|
|
|
- let _this = this
|
|
|
|
|
|
+ addCart() {
|
|
let item = this.goodContent
|
|
let item = this.goodContent
|
|
- uni.$emit("addCart",{goodsNo:item.goodsNo,buyQty:_this.nums})
|
|
|
|
|
|
+ if(this.nums * item.sellGold >= this.goldLimit){
|
|
|
|
+ this.addGoodToCart({goodsNo:item.goodsNo,buyQty:this.nums,hasCunzai:this.hasCunzai(item)})
|
|
|
|
+ }else{
|
|
|
|
+ uni.showToast({
|
|
|
|
+ icon: 'none',
|
|
|
|
+ title: `此商品需满${this.goldLimit}乐豆才能购买`
|
|
|
|
+ })
|
|
|
|
+ }
|
|
},
|
|
},
|
|
// 立即下单
|
|
// 立即下单
|
|
toOrder(){
|
|
toOrder(){
|
|
@@ -117,7 +150,7 @@
|
|
if(this.goodContent.sellGold * this.nums >= this.goldLimit){
|
|
if(this.goodContent.sellGold * this.nums >= this.goldLimit){
|
|
this.$u.vuex("vuex_toOrderList",[{id:this.id,buyQty:this.nums,goodsNo:this.goodContent.goodsNo,goods:this.goodContent}])
|
|
this.$u.vuex("vuex_toOrderList",[{id:this.id,buyQty:this.nums,goodsNo:this.goodContent.goodsNo,goods:this.goodContent}])
|
|
uni.redirectTo({
|
|
uni.redirectTo({
|
|
- url:"/pages/toOrder/index"
|
|
|
|
|
|
+ url:"/pages/toOrder/index?orderForm=ORDER_NOW"
|
|
})
|
|
})
|
|
}else{
|
|
}else{
|
|
uni.showToast({
|
|
uni.showToast({
|