|
@@ -7,11 +7,13 @@ import {
|
|
Radio,
|
|
Radio,
|
|
RadioGroup,
|
|
RadioGroup,
|
|
Stepper,
|
|
Stepper,
|
|
- Tag
|
|
|
|
|
|
+ Tag,
|
|
|
|
+ Toast
|
|
} from 'vant'
|
|
} from 'vant'
|
|
import { defineComponent } from 'vue'
|
|
import { defineComponent } from 'vue'
|
|
import styles from './index.module.less'
|
|
import styles from './index.module.less'
|
|
import iconSellOut from '../../images/icon-sell-out.png'
|
|
import iconSellOut from '../../images/icon-sell-out.png'
|
|
|
|
+import request from '@/helpers/request'
|
|
|
|
|
|
export default defineComponent({
|
|
export default defineComponent({
|
|
name: 'add-goods-cart',
|
|
name: 'add-goods-cart',
|
|
@@ -29,8 +31,10 @@ export default defineComponent({
|
|
pic: '',
|
|
pic: '',
|
|
stock: 0,
|
|
stock: 0,
|
|
price: 0,
|
|
price: 0,
|
|
- spDataJson: ''
|
|
|
|
- }
|
|
|
|
|
|
+ spDataJson: '',
|
|
|
|
+ skuCode: ''
|
|
|
|
+ },
|
|
|
|
+ total: 1
|
|
}
|
|
}
|
|
},
|
|
},
|
|
computed: {
|
|
computed: {
|
|
@@ -58,19 +62,47 @@ export default defineComponent({
|
|
}
|
|
}
|
|
})
|
|
})
|
|
// 处理默认显示
|
|
// 处理默认显示
|
|
- const { id, price, pic, stock, spDataJson } = skuStockList[0]
|
|
|
|
|
|
+ const { id, price, pic, stock, spDataJson, skuCode } = skuStockList[0]
|
|
this.radio = id
|
|
this.radio = id
|
|
this.selectItem = {
|
|
this.selectItem = {
|
|
id,
|
|
id,
|
|
price,
|
|
price,
|
|
pic: pic || this.item.pic,
|
|
pic: pic || this.item.pic,
|
|
stock,
|
|
stock,
|
|
- spDataJson
|
|
|
|
|
|
+ spDataJson,
|
|
|
|
+ skuCode
|
|
}
|
|
}
|
|
return skuStockList
|
|
return skuStockList
|
|
}
|
|
}
|
|
},
|
|
},
|
|
mounted() {},
|
|
mounted() {},
|
|
|
|
+ methods: {
|
|
|
|
+ async onAddCart() {
|
|
|
|
+ // console.log(this.total, this.selectItem, this.item)
|
|
|
|
+ const selectItem = this.selectItem
|
|
|
|
+ const item = this.item
|
|
|
|
+ const body = {
|
|
|
|
+ price: selectItem.price, //添加到购物车的价格
|
|
|
|
+ productCategoryId: item.productCategoryId, //商品分类
|
|
|
|
+ productName: item.name, // 商品名称
|
|
|
|
+ productPic: selectItem.pic, // 商品主图
|
|
|
|
+ productSkuCode: selectItem.skuCode, //商品sku条码
|
|
|
|
+ productSkuId: selectItem.id,
|
|
|
|
+ productSn: item.productSn,
|
|
|
|
+ productSubTitle: item.subTitle, // 副标题
|
|
|
|
+ quantity: this.total, // 数量
|
|
|
|
+ productId: item.id,
|
|
|
|
+ productAttr: selectItem.spDataJson
|
|
|
|
+ }
|
|
|
|
+ console.log(body)
|
|
|
|
+ try {
|
|
|
|
+ let { code, data } = await request.post('/api-mall-portal/cart/add', {
|
|
|
|
+ data: body
|
|
|
|
+ })
|
|
|
|
+ code === 200 && Toast('加入购物车成功')
|
|
|
|
+ } catch (error) {}
|
|
|
|
+ }
|
|
|
|
+ },
|
|
render() {
|
|
render() {
|
|
const item = this.item
|
|
const item = this.item
|
|
return (
|
|
return (
|
|
@@ -126,14 +158,16 @@ export default defineComponent({
|
|
onClick={() => {
|
|
onClick={() => {
|
|
this.radio = item.id
|
|
this.radio = item.id
|
|
// 处理默认显示
|
|
// 处理默认显示
|
|
- const { id, price, pic, stock, spDataJson } = item
|
|
|
|
|
|
+ const { id, price, pic, stock, spDataJson, skuCode } =
|
|
|
|
+ item
|
|
this.radio = id
|
|
this.radio = id
|
|
this.selectItem = {
|
|
this.selectItem = {
|
|
id,
|
|
id,
|
|
price,
|
|
price,
|
|
pic: pic || this.item.pic,
|
|
pic: pic || this.item.pic,
|
|
stock,
|
|
stock,
|
|
- spDataJson
|
|
|
|
|
|
+ spDataJson,
|
|
|
|
+ skuCode
|
|
}
|
|
}
|
|
}}
|
|
}}
|
|
>
|
|
>
|
|
@@ -155,6 +189,7 @@ export default defineComponent({
|
|
center
|
|
center
|
|
>
|
|
>
|
|
<Stepper
|
|
<Stepper
|
|
|
|
+ v-model={this.total}
|
|
inputWidth="50px"
|
|
inputWidth="50px"
|
|
theme="round"
|
|
theme="round"
|
|
buttonSize="24px"
|
|
buttonSize="24px"
|
|
@@ -170,6 +205,7 @@ export default defineComponent({
|
|
type="primary"
|
|
type="primary"
|
|
text="确定"
|
|
text="确定"
|
|
disabled={this.selectItem.stock <= 0}
|
|
disabled={this.selectItem.stock <= 0}
|
|
|
|
+ onClick={() => this.onAddCart()}
|
|
/>
|
|
/>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|