|
|
@@ -106,6 +106,7 @@ export default {
|
|
|
currentProduct: {},
|
|
|
qualityOptions: [],
|
|
|
sourceFrom: 0,
|
|
|
+ searchWord: '',
|
|
|
isSubmitting: false, // 防重复提交标志
|
|
|
};
|
|
|
},
|
|
|
@@ -140,14 +141,25 @@ export default {
|
|
|
}
|
|
|
},
|
|
|
methods: {
|
|
|
- open(product, sourceFrom) {
|
|
|
+ open(product, sourceFrom, searchWord) {
|
|
|
this.visible = true;
|
|
|
this.quantity = 1;
|
|
|
this.sourceFrom = sourceFrom || 0;
|
|
|
+ this.searchWord = searchWord || '';
|
|
|
if (product.isbn) {
|
|
|
this.getGoodQualityInfo(product.isbn);
|
|
|
}
|
|
|
},
|
|
|
+ buildAddCartParams(conditionType) {
|
|
|
+ const params = {
|
|
|
+ isbn: this.currentProduct.isbn,
|
|
|
+ quantity: this.quantity,
|
|
|
+ conditionType: conditionType,
|
|
|
+ sourceFrom: this.sourceFrom
|
|
|
+ };
|
|
|
+ if (this.searchWord) params.searchWord = this.searchWord;
|
|
|
+ return params;
|
|
|
+ },
|
|
|
//根据 isbn 获取商品品相信息
|
|
|
getGoodQualityInfo(isbn) {
|
|
|
uni.$u.http.get('/token/shop/bookDetail', { isbn }).then(res => {
|
|
|
@@ -234,12 +246,7 @@ export default {
|
|
|
|
|
|
this.isSubmitting = true; // 设置提交中状态
|
|
|
|
|
|
- this.$u.api.addShopCartAjax({
|
|
|
- isbn: this.currentProduct.isbn,
|
|
|
- quantity: this.quantity,
|
|
|
- conditionType: conditionType,
|
|
|
- sourceFrom: this.sourceFrom
|
|
|
- }).then(async res => {
|
|
|
+ this.$u.api.addShopCartAjax(this.buildAddCartParams(conditionType)).then(async res => {
|
|
|
if (res.code === 200) {
|
|
|
await this.$updateCartBadge();
|
|
|
this.$u.toast('加入购物车成功');
|
|
|
@@ -274,12 +281,7 @@ export default {
|
|
|
|
|
|
this.isSubmitting = true; // 设置提交中状态
|
|
|
|
|
|
- this.$u.api.addShopCartAjax({
|
|
|
- isbn: this.currentProduct.isbn,
|
|
|
- quantity: this.quantity,
|
|
|
- conditionType: conditionType,
|
|
|
- sourceFrom: this.sourceFrom
|
|
|
- }).then(async res => {
|
|
|
+ this.$u.api.addShopCartAjax(this.buildAddCartParams(conditionType)).then(async res => {
|
|
|
if (res.code === 200) {
|
|
|
await this.$updateCartBadge();
|
|
|
this.$u.toast('加入购物车成功');
|