修改立即购买按钮一直加载bug

This commit is contained in:
mabo
2021-06-23 10:45:05 +08:00
parent 9586eedb56
commit a1fd5be5c4
7 changed files with 397 additions and 264 deletions

View File

@@ -126,7 +126,7 @@
<Button type="error" :loading="loading" :disabled="skuDetail.quantity === 0" @click="addShoppingCartBtn">加入购物车</Button>
<Button type="warning" :loading="loading1" :disabled="skuDetail.quantity === 0" @click="buyNow">立即购买</Button>
</div>
</div>
</div>
</div>
@@ -199,13 +199,18 @@ export default {
skuId: this.skuDetail.id
};
this.loading = true;
console.log(11111111);
addCartGoods(params).then(res => {
debugger;
this.loading = false;
if (res.success) {
this.$router.push({path: '/shoppingCart', query: {detail: this.skuDetail, count: this.count}});
} else {
this.$Message.warning(res.message);
}
}).catch(() => {
console.log('catch');
this.loading = false;
});
},
buyNow () { // 立即购买
@@ -222,6 +227,8 @@ export default {
} else {
this.$Message.warning(res.message);
}
}).catch(() => {
this.loading1 = false;
});
},
pointPay () { // 积分购买
@@ -339,7 +346,7 @@ export default {
}
})
}
this.formatSku(this.goodsSpecList);
this.promotion()
document.title = this.skuDetail.goodsName

View File

@@ -11,42 +11,37 @@
</div> -->
<!-- 普通发票 -->
<div class="nav-content">
<Form
:model="invoiceForm"
ref="form"
label-position="left"
:rules="ruleInline"
:label-width="110"
>
<Form :model="invoiceForm" ref="form" label-position="left" :rules="ruleInline" :label-width="110">
<FormItem label="发票类型">
<RadioGroup v-model="invoiceForm.type" type="button" button-style="solid">
<RadioGroup v-model="invoice" type="button" button-style="solid">
<Radio @on-change="changeInvoice" :label="1">电子普通发票</Radio>
<Radio :label="2" :disabled="true">增值税专用发票</Radio>
</RadioGroup>
</FormItem>
<FormItem label="发票抬头">
<RadioGroup v-model="type" @on-change="changeInvoice" type="button" button-style="solid">
<Radio :label="1">个人</Radio>
<Radio :label="2">单位</Radio>
</RadioGroup>
</FormItem>
<FormItem
label="发票抬头"
v-if="invoiceForm.type == 2"
prop="receiptTitle"
>
<FormItem label="个人名称" v-if="type === 1" prop="receiptTitle">
<i-input v-model="invoiceForm.receiptTitle"></i-input>
</FormItem>
<FormItem
label="纳税人识别号"
v-if="invoiceForm.type == 2"
prop="taxpayerId"
>
<FormItem label="单位名称" v-if="type === 2" prop="receiptTitle">
<i-input v-model="invoiceForm.receiptTitle"></i-input>
</FormItem>
<FormItem label="纳税人识别号" v-if="type === 2" prop="taxpayerId">
<i-input v-model="invoiceForm.taxpayerId"></i-input>
</FormItem>
<FormItem label="发票内容">
<RadioGroup v-model="invoiceForm.receiptContent" type="button" button-style="solid">
<Radio label="不开发票">不开发票</Radio>
<Radio label="商品明细">商品明细</Radio>
<Radio label="商品类别">商品类别</Radio>
</RadioGroup>
</FormItem>
</Form>
<div style="text-align: center">
<Button type="primary" :loading="loading" @click="save">保存发票信息</Button>
<Button type="primary" :loading="loading" @click="submit">保存发票信息</Button>
<Button type="default" @click="invoiceAvailable = false">取消</Button>
</div>
</div>
@@ -54,20 +49,21 @@
</div>
</template>
<script>
import { saveReceipt } from '@/api/member.js';
import { receiptSelect } from '@/api/cart.js';
import { TINumber } from '@/plugins/RegExp.js';
export default {
name: 'invoiceModal',
data () {
return {
invoice: 1,
invoiceAvailable: false, // 模态框显隐
loading: false, // 提交状态
invoiceForm: { // 发票表单
invoiceForm: {
// 发票表单
// 普票表单
receiptTitle: '', // 发票抬头
taxpayerId: '', // 纳税人识别号
receiptContent: '不开发票', // 发票内容
type: 1 // 1 个人 2 单位
receiptContent: '商品明细', // 发票内容
},
type: 1, // 1 个人 2 单位
ruleInline: {
@@ -78,63 +74,76 @@ export default {
}
};
},
props: ["invoiceData"],
props: ['invoiceData'],
watch: {
invoiceData: {
handler(val) {
handler (val) {
this.invoiceForm = { ...val };
if (flag) {
let params = {
receiptTitle: '个人',
receiptContent: this.invoiceForm.receiptContent
};
this.loading = true;
saveReceipt(params)
.then((res) => {
this.loading = false;
if (res.success) {
this.$emit('change', res.result);
this.invoiceAvailable = false;
}
})
.catch(() => {
this.loading = false;
});
if (val.taxpayerId) {
this.type = 2;
} else {
this.type = 1;
}
} else {
// 单位
},
deep: true,
immeadite: true
}
},
methods: {
/**
* 选择发票抬头
*/
changeInvoice (val) {
this.$nextTick(() => {
this.type = val;
});
},
/**
* 保存判断
*/
save () {
let flage = true;
// 保存分为两种类型,个人以及企业
const { type, receiptTitle, receiptContent } = JSON.parse(
JSON.stringify(this.invoiceForm)
);
// 判断是否填写发票抬头
if (!receiptTitle) {
this.$Message.error('请填写发票抬头!');
flage = false;
return false;
}
if (type === 2) {
this.$refs.form.validate((valid) => {
if (valid) {
this.loading = true;
let params = {
receiptTitle: this.invoiceForm.receiptTitle,
taxpayerId: this.invoiceForm.taxpayerId,
receiptContent: this.invoiceForm.receiptContent
};
let flag = true;
this.receiptItems.forEach((e) => {
if (e.taxpayerId === params.taxpayerId) {
flag = false;
}
});
if (!flag) {
this.$Message.error('已有当前税号的发票信息,请直接选择已有发票');
} else {
saveReceipt(params)
.then((res) => {
this.loading = false;
if (res.success) {
this.$emit('change', res.result);
this.invoiceAvailable = false;
}
})
.catch(() => {
this.loading = false;
});
}
if (!valid) {
flage = false;
}
});
} else {
delete this.invoiceForm.taxpayerId;
}
return flage;
},
async submit () {
if (this.save()) {
this.loading = true;
let submit = {
way: this.$route.query.way,
...this.invoiceForm
};
let receipt = await receiptSelect(submit);
if (receipt.success) {
this.$emit('change', true);
}
this.loading = false;
}
}
}