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

master
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;
}
}
}

View File

@ -50,7 +50,6 @@ export default {
},
created () {
this.getGoodsDetail();
},
data () {
return {

View File

@ -108,7 +108,7 @@ export default {
this.pageNumber = 1;
this.params.pageSize = val;
this.getList()
},
}
}
}
</script>
@ -132,10 +132,10 @@ export default {
color: $theme_color;
}
}
.selected-cate{
color: $theme_color;
}
}
.page-size {
width: 1200px;

View File

@ -4,15 +4,23 @@
<!-- LOGO 步骤条 -->
<div class="width_1200 logo">
<div>
<router-link to="/"><img :src="logoImg" alt="lili shop" title="lilishop"></router-link>
<router-link to="/"
><img :src="logoImg" alt="lili shop" title="lilishop"
/></router-link>
<div>结算页</div>
</div>
<div class="cart-steps">
<span :class="stepIndex==1?'active':''">1.我的购物车</span>
<Icon :class="stepIndex==1?'active-arrow':''" custom="icomoon icon-next"></Icon>
<span :class="stepIndex==1?'active':''">2.填写订单信息</span>
<Icon :class="stepIndex==1?'active-arrow':''" custom="icomoon icon-next"></Icon>
<span :class="stepIndex==2?'active':''">3.成功提交订单</span>
<span :class="stepIndex == 1 ? 'active' : ''">1.我的购物车</span>
<Icon
:class="stepIndex == 1 ? 'active-arrow' : ''"
custom="icomoon icon-next"
></Icon>
<span :class="stepIndex == 1 ? 'active' : ''">2.填写订单信息</span>
<Icon
:class="stepIndex == 1 ? 'active-arrow' : ''"
custom="icomoon icon-next"
></Icon>
<span :class="stepIndex == 2 ? 'active' : ''">3.成功提交订单</span>
</div>
</div>
<Divider />
@ -24,18 +32,35 @@
<span @click="goAddressManage"></span>
</div>
<div class="address-manage">
<div class="address-item" v-show="moreAddr ? true : index < 3" :class="selectedAddress.id === item.id?'border-red':''" @mouseenter="showEditBtn = index" @mouseleave="showEditBtn = ''"
@click="selectAddress(item)" v-for="(item,index) in addressList" :key="index">
<div
class="address-item"
v-show="moreAddr ? true : index < 3"
:class="selectedAddress.id === item.id ? 'border-red' : ''"
@mouseenter="showEditBtn = index"
@mouseleave="showEditBtn = ''"
@click="selectAddress(item)"
v-for="(item, index) in addressList"
:key="index"
>
<div>
<span>{{item.name}}</span>
<span>{{ item.name }}</span>
<Tag class="ml_10" v-if="item.isDefault" color="red"></Tag>
<Tag class="ml_10" v-if="item.alias" color="warning">{{item.alias}}</Tag>
<Tag class="ml_10" v-if="item.alias" color="warning">{{
item.alias
}}</Tag>
</div>
<div>{{ item.mobile }}</div>
<div>
{{ item.consigneeAddressPath | unitAddress }} {{ item.detail }}
</div>
<div>{{item.mobile}}</div>
<div>{{ item.consigneeAddressPath | unitAddress }} {{item.detail}}</div>
<div class="edit-btn" v-show="showEditBtn === index">
<span @click.stop="editAddress(item.id)">修改</span>
<span class="ml_10" v-if="!item.isDefault" @click.stop="delAddress(item)"></span>
<span
class="ml_10"
v-if="!item.isDefault"
@click.stop="delAddress(item)"
>删除</span
>
</div>
<div class="corner-icon" v-show="selectedAddress.id === item.id">
<div></div>
@ -48,8 +73,12 @@
</div>
</div>
<div class="more-addr" @click="moreAddr = !moreAddr" v-if="addressList.length>3">
{{moreAddr ? '收起地址' : '更多地址'}}
<div
class="more-addr"
@click="moreAddr = !moreAddr"
v-if="addressList.length > 3"
>
{{ moreAddr ? "收起地址" : "更多地址" }}
<Icon v-show="!moreAddr" type="md-arrow-dropdown" />
<Icon v-show="moreAddr" type="md-arrow-dropup" />
</div>
@ -60,10 +89,17 @@
<span>商品信息</span>
<span @click="$router.push('/cart')"></span>
</div>
<div class="goods-msg" v-for="(shop,shopIndex) in goodsList" :key="shopIndex">
<div
class="goods-msg"
v-for="(shop, shopIndex) in goodsList"
:key="shopIndex"
>
<div class="shop-name">
<span>
<span class="hover-color" @click="goShopPage(shop.storeId)">{{shop.storeName}}</span>&nbsp;&nbsp;
<span class="hover-color" @click="goShopPage(shop.storeId)">{{
shop.storeName
}}</span
>&nbsp;&nbsp;
</span>
<!-- <span>
<p style="width:120px">配送方式</p>
@ -73,33 +109,60 @@
</span> -->
</div>
<div class="goods-list">
<div class="goods-item" v-for="(goods,goodsIndex) in shop.skuList" :key="goodsIndex">
<span class="hover-color" @click="goGoodsDetail(goods.goodsSku.id, goods.goodsSku.goodsId)">
<img :src="goods.goodsSku.thumbnail" alt="">
<span style="vertical-align:top;">{{goods.goodsSku.goodsName}}</span>
<div
class="goods-item"
v-for="(goods, goodsIndex) in shop.skuList"
:key="goodsIndex"
>
<span
class="hover-color"
@click="
goGoodsDetail(goods.goodsSku.id, goods.goodsSku.goodsId)
"
>
<img :src="goods.goodsSku.thumbnail" alt="" />
<span style="vertical-align: top">{{
goods.goodsSku.goodsName
}}</span>
</span>
<span class="goods-price">{{goods.goodsSku.price | unitPrice('¥')}}</span>
<span>x{{goods.num}}</span>
<span>{{goods.goodsSku.quantity > 0 ? '有货' : '无货'}}</span>
<span class="goods-price">{{goods.goodsSku.price * goods.num | unitPrice('¥')}}</span>
<span class="goods-price">{{
goods.goodsSku.price | unitPrice("¥")
}}</span>
<span>x{{ goods.num }}</span>
<span>{{ goods.goodsSku.quantity > 0 ? "有货" : "无货" }}</span>
<span class="goods-price">{{
(goods.goodsSku.price * goods.num) | unitPrice("¥")
}}</span>
</div>
</div>
<div class="order-mark">
<Input type="textarea" maxlength="60" v-model="shop.remark" show-word-limit placeholder="订单备注" />
<span style="font-size:12px;color:#999;">提示请勿填写有关支付收货发票方面的信息</span>
<Input
type="textarea"
maxlength="60"
v-model="shop.remark"
show-word-limit
placeholder="订单备注"
/>
<span style="font-size: 12px; color: #999"
>提示请勿填写有关支付收货发票方面的信息</span
>
</div>
</div>
</div>
<!-- 发票信息 -->
<div class="invoice">
<div class="card-head mt_20 mb_20">
<span class="relative">发票信息<span class="inv-tips">
<Icon type="ios-alert-outline" />开企业抬头发票须填写纳税人识别号以免影响报销
</span></span>
<span class="relative"
>发票信息<span class="inv-tips">
<Icon
type="ios-alert-outline"
/>
</span></span
>
</div>
<div class="inovice-content">
<span>{{invoiceData.receiptTitle}}</span>
<span>{{invoiceData.receiptContent}}</span>
<span>{{ invoiceData.receiptTitle }}</span>
<span>{{ invoiceData.receiptContent }}</span>
<span @click="editInvoice"></span>
</div>
</div>
@ -108,24 +171,49 @@
<div class="card-head mt_20 mb_20">
<span class="relative">优惠券</span>
</div>
<div v-if="couponList.length === 0">
无可用优惠券
</div>
<div v-if="couponList.length === 0"></div>
<ul v-else class="coupon-list">
<li v-for="(item, index) in couponList" class="coupon-item" :key="index">
<li
v-for="(item, index) in couponList"
class="coupon-item"
:key="index"
>
<div class="c-left">
<div>
<span v-if="item.couponType === 'PRICE'" class="fontsize_12 global_color">¥<span class="price">{{item.price | unitPrice}}</span></span>
<span v-if="item.couponType === 'DISCOUNT'" class="fontsize_12 global_color"><span class="price">{{item.couponDiscount}}</span></span>
<span class="describe">{{item.consumeThreshold}}元可用</span>
<span
v-if="item.couponType === 'PRICE'"
class="fontsize_12 global_color"
><span class="price">{{
item.price | unitPrice
}}</span></span
>
<span
v-if="item.couponType === 'DISCOUNT'"
class="fontsize_12 global_color"
><span class="price">{{ item.couponDiscount }}</span
></span
>
<span class="describe"
>{{ item.consumeThreshold }}元可用</span
>
</div>
<p>使用范围{{useScope(item.scopeType)}}</p>
<p>有效期{{item.endTime}}</p>
<p>使用范围{{ useScope(item.scopeType) }}</p>
<p>有效期{{ item.endTime }}</p>
</div>
<img class="used" v-if="usedCouponId.includes(item.id)" src="../../assets/images/geted.png" alt="">
<img
class="used"
v-if="usedCouponId.includes(item.id)"
src="../../assets/images/geted.png"
alt=""
/>
<b></b>
<a class="c-right" @click="useCoupon(item.id, true)">立即使用</a>
<a class="c-right" v-if="usedCouponId.includes(item.id)" @click="useCoupon(item.id, false)"></a>
<a
class="c-right"
v-if="usedCouponId.includes(item.id)"
@click="useCoupon(item.id, false)"
>放弃优惠</a
>
<i class="circle-top"></i>
<i class="circle-bottom"></i>
</li>
@ -138,81 +226,116 @@
</div>
<div>
<div>
<span>使用积分</span><Input type="text" style="width:100px;" v-model.number="otherMsgForm.point" placeholder="请输入使用积分" /> <span style="color:#999;">您当前的可用积分为 {{otherMsgForm.totalPoint}}
本订单最多可以使用{{otherMsgForm.availablePoint}}</span>
<span>使用积分</span
><Input
type="text"
style="width: 100px"
v-model.number="otherMsgForm.point"
placeholder="请输入使用积分"
/>
<span style="color: #999"
>您当前的可用积分为
{{ otherMsgForm.totalPoint }} 本订单最多可以使用{{
otherMsgForm.availablePoint
}}</span
>
</div>
</div>
</div>
<!-- 订单价格 -->
<div class="order-price">
<div>
<span>{{totalNum}}件商品总商品金额</span><span>{{priceDetailDTO.goodsPrice | unitPrice('¥')}}</span>
<span>{{ totalNum }}件商品总商品金额</span
><span>{{ priceDetailDTO.goodsPrice | unitPrice("¥") }}</span>
</div>
<div>
<span>运费</span><span>{{ priceDetailDTO.freightPrice | unitPrice('¥')}}</span>
<span>运费</span
><span>{{ priceDetailDTO.freightPrice | unitPrice("¥") }}</span>
</div>
<div>
<span>优惠金额</span><span>-{{ priceDetailDTO.discountPrice + priceDetailDTO.couponPrice + priceDetailDTO.updatePrice | unitPrice('¥')}}</span>
<span>优惠金额</span
><span
>-{{
(priceDetailDTO.discountPrice +
priceDetailDTO.couponPrice +
priceDetailDTO.updatePrice)
| unitPrice("¥")
}}</span
>
</div>
<div>
<span>应付金额</span><span class='actrual-price'>{{priceDetailDTO.billPrice | unitPrice('¥')}}</span>
<span>应付金额</span
><span class="actrual-price">{{
priceDetailDTO.billPrice | unitPrice("¥")
}}</span>
</div>
</div>
</div>
<!-- 底部支付栏 -->
<div class="order-footer width_1200">
<div class="pay ml_20" @click="pay"></div>
<div class="pay-address" v-if="addressList.length">{{ selectedAddress.consigneeAddressPath | unitAddress }}
{{selectedAddress.detail}}&nbsp;&nbsp;收货人{{selectedAddress.name}}&nbsp;&nbsp;{{selectedAddress.mobile}}</div>
<div class="pay-address" v-if="addressList.length">
配送至{{ selectedAddress.consigneeAddressPath | unitAddress }}
{{ selectedAddress.detail }}&nbsp;&nbsp;收货人{{
selectedAddress.name
}}&nbsp;&nbsp;{{ selectedAddress.mobile }}
</div>
</div>
<BaseFooter></BaseFooter>
<!-- 添加发票模态框 -->
<invoice-modal ref="invModal" :invoiceData="invoiceData" @change="getInvMsg" />
<invoice-modal
ref="invModal"
:invoiceData="invoiceData"
@change="getInvMsg"
/>
<!-- 选择地址模态框 -->
<address-manage ref="address" :id="addrId" @change="addrChange"></address-manage>
<address-manage
ref="address"
:id="addrId"
@change="addrChange"
></address-manage>
</div>
</template>
<script>
import invoiceModal from "@/components/invoiceModal";
import addressManage from "@/components/addressManage";
import { memberAddress, delMemberAddress } from "@/api/address";
import invoiceModal from '@/components/invoiceModal';
import addressManage from '@/components/addressManage';
import { memberAddress, delMemberAddress } from '@/api/address';
import {
cartGoodsPay,
createTrade,
selectAddr,
shippingMethod,
selectCoupon,
couponNum,
} from "@/api/cart";
import { canUseCouponList } from "@/api/member.js";
import { getLogo } from "@/api/common.js";
couponNum
} from '@/api/cart';
import { canUseCouponList } from '@/api/member.js';
import { getLogo } from '@/api/common.js';
export default {
name: "Pay",
name: 'Pay',
components: { invoiceModal, addressManage },
data() {
data () {
return {
stepIndex: 1, //
invoiceAvailable: false, //
showEditBtn: "", //
orderMark: "", //
showEditBtn: '', //
orderMark: '', //
invoiceData: {
//
receiptTitle: "个人",
receiptContent: "不开发票",
receiptTitle: '个人',
receiptContent: '不开发票'
},
otherMsgForm: {
//
point: 0,
availablePoint: 10,
totalPoint: 100,
noGoods: 0,
noGoods: 0
},
deliveryList: [
//
// {value: 'SELF_PICK_UP', label: ''},
{ value: "LOGISTICS", label: "物流" },
{ value: 'LOGISTICS', label: '物流' }
// {value: 'LOCAL_TOWN_DELIVERY', label: ''}
],
addressList: [], //
@ -220,37 +343,37 @@ export default {
goodsList: [], //
priceDetailDTO: {}, //
totalNum: 0, //
addrId: "", // id
addrId: '', // id
moreAddr: false, //
canUseCouponNum: 0, //
couponList: [], //
logoImg: "", // logo
logoImg: '', // logo
usedCouponId: [], // 使id
selectedCoupon: {}, //
selectedCoupon: {} //
};
},
mounted() {
mounted () {
this.init();
if (!this.Cookies.getItem("logo")) {
if (!this.Cookies.getItem('logo')) {
getLogo().then((res) => {
if (res.success) {
let logoObj = JSON.parse(res.result.settingValue);
this.Cookies.setItem("logo", logoObj.buyerSideLogo);
this.Cookies.setItem('logo', logoObj.buyerSideLogo);
}
});
} else {
this.logoImg = this.Cookies.getItem("logo");
this.logoImg = this.Cookies.getItem('logo');
}
},
methods: {
init() {
init () {
this.getGoodsDetail();
},
goAddressManage() {
goAddressManage () {
//
this.$router.push("/home/MyAddress");
this.$router.push('/home/MyAddress');
},
getAddress() {
getAddress () {
//
memberAddress().then((res) => {
if (res.success) {
@ -263,7 +386,7 @@ export default {
}
});
},
getGoodsDetail() {
getGoodsDetail () {
//
this.$Spin.show();
cartGoodsPay({ way: this.$route.query.way })
@ -274,24 +397,21 @@ export default {
this.priceDetailDTO = res.result.priceDetailDTO;
this.skuList = res.result.skuList;
res.result.receiptVO
? (this.invoiceData = res.result.receiptVO)
: "";
res.result.receiptVO ? (this.invoiceData = res.result.receiptVO) : '';
let notSupArea = res.result.notSupportFreight;
this.selectedCoupon = {};
if (res.result.platformCoupon)
this.selectedCoupon.platformCoupon = res.result.platformCoupon;
if (res.result.platformCoupon) this.selectedCoupon.platformCoupon = res.result.platformCoupon;
Object.assign(this.selectedCoupon, res.result.storeCoupons);
if (notSupArea) {
let content = [];
let title = "";
let title = '';
notSupArea.forEach((e) => {
title = e.errorMessage;
content.push(e.goodsSku.goodsName);
});
this.$Modal.warning({
title: "以下商品超出配送区域" || title,
title: '以下商品超出配送区域' || title,
content: content.toString(),
});
}
@ -310,7 +430,7 @@ export default {
this.$Spin.hide();
});
},
getCouponNum() {
getCouponNum () {
//
couponNum({ way: this.$route.query.way }).then((res) => {
this.canUseCouponNum = res.result;
@ -326,10 +446,10 @@ export default {
let params = {
pageNumber: 1,
pageSize: 100,
memberCouponStatus: "NEW",
memberCouponStatus: 'NEW',
scopeId: skuArr.toString(),
storeId: storeArr.toString(),
totalPrice: this.priceDetailDTO.goodsPrice,
totalPrice: this.priceDetailDTO.goodsPrice
};
canUseCouponList(params).then((res) => {
//
@ -350,86 +470,85 @@ export default {
}
});
},
selectAddress(item) {
selectAddress (item) {
//
let params = {
way: this.$route.query.way,
shippingAddressId: item.id,
shippingAddressId: item.id
};
selectAddr(params).then((res) => {
if (res.success) {
this.$Message.success("选择收货地址成功");
this.$Message.success('选择收货地址成功');
this.selectedAddress = item;
this.getGoodsDetail();
}
});
},
editAddress(id) {
editAddress (id) {
//
this.addrId = id;
this.$refs.address.show();
},
addrChange(item) {
addrChange () {
//
this.getAddress();
},
delAddress(item) {
delAddress (item) {
//
this.$Modal.confirm({
title: "提示",
content: "你确定删除这个收货地址",
title: '提示',
content: '你确定删除这个收货地址',
onOk: () => {
delMemberAddress(item.id).then((res) => {
if (res.success) {
this.$Message.success("删除成功");
this.$Message.success('删除成功');
this.getAddress();
}
});
},
onCancel: () => {},
onCancel: () => {}
});
},
goGoodsDetail(skuId, goodsId) {
goGoodsDetail (skuId, goodsId) {
//
let routeUrl = this.$router.resolve({
path: "/goodsDetail",
query: { skuId, goodsId },
path: '/goodsDetail',
query: { skuId, goodsId }
});
window.open(routeUrl.href, "_blank");
window.open(routeUrl.href, '_blank');
},
//
goShopPage(id) {
goShopPage (id) {
let routeUrl = this.$router.resolve({
path: "/Merchant",
query: { id: id },
path: '/Merchant',
query: { id: id }
});
window.open(routeUrl.href, "_blank");
window.open(routeUrl.href, '_blank');
},
selectDelivery(delivery) {
selectDelivery (delivery) {
//
let params = {
way: this.$route.query.way,
shippingMethod: delivery.value,
shippingMethod: delivery.value
};
shippingMethod(params).then((res) => {});
},
useCoupon(id, used) {
useCoupon (id, used) {
// 使
let params = {
way: this.$route.query.way,
memberCouponId: id,
used: used, // true 使 false
used: used // true 使 false
};
selectCoupon(params).then((res) => {
if (res.success) this.init();
});
},
editInvoice() {
editInvoice () {
//
this.$refs.invModal.invoiceAvailable = true;
},
getInvMsg(item) {
getInvMsg (item) {
//
if (item) {
this.init();
@ -437,18 +556,18 @@ export default {
}
},
pay() {
pay () {
//
const params = {
client: "PC",
client: 'PC',
remark: [],
way: this.$route.query.way,
way: this.$route.query.way
};
this.goodsList.forEach((e) => {
if (e.remark) {
params.remark.push({
remark: e.remark,
storeId: e.storeId,
storeId: e.storeId
});
}
});
@ -461,8 +580,8 @@ export default {
this.$Spin.hide();
if (res.success) {
this.$router.push({
path: "/payment",
query: { orderType: "TRADE", sn: res.result.sn },
path: '/payment',
query: { orderType: 'TRADE', sn: res.result.sn }
});
}
})
@ -470,22 +589,22 @@ export default {
this.$Spin.hide();
});
},
useScope(type) {
let goods = "全部商品";
useScope (type) {
let goods = '全部商品';
switch (type) {
case "ALL":
goods = "全部商品";
case 'ALL':
goods = '全部商品';
break;
case "PORTION_GOODS":
goods = "部分商品";
case 'PORTION_GOODS':
goods = '部分商品';
break;
case "PORTION_GOODS_CATEGORY":
goods = "部分分类商品";
case 'PORTION_GOODS_CATEGORY':
goods = '部分分类商品';
break;
}
return `${goods}可用`;
},
},
}
}
};
</script>

View File

@ -1,27 +1,27 @@
// import Vue from 'vue';
import axios from "axios";
import https from "https";
import { Message, Spin, Modal } from "view-design";
import Storage from "./storage";
import config from "@/config";
import router from "../router/index.js";
import store from "../vuex/store";
import { handleRefreshToken } from "@/api/index";
const qs = require("qs");
import axios from 'axios';
import https from 'https';
import { Message, Spin, Modal } from 'view-design';
import Storage from './storage';
import config from '@/config';
import router from '../router/index.js';
import store from '../vuex/store';
import { handleRefreshToken } from '@/api/index';
const qs = require('qs');
export const buyerUrl =
process.env.NODE_ENV === "development"
process.env.NODE_ENV === 'development'
? config.api_dev.buyer
: config.api_prod.buyer;
export const commonUrl =
process.env.NODE_ENV === "development"
process.env.NODE_ENV === 'development'
? config.api_dev.common
: config.api_prod.common;
export const managerUrl =
process.env.NODE_ENV === "development"
process.env.NODE_ENV === 'development'
? config.api_dev.manager
: config.api_prod.manager;
export const sellerUrl =
process.env.NODE_ENV === "development"
process.env.NODE_ENV === 'development'
? config.api_dev.seller
: config.api_prod.seller;
// 创建axios实例
@ -35,7 +35,7 @@ const service = axios.create({
}),
paramsSerializer: params =>
qs.stringify(params, {
arrayFormat: "repeat"
arrayFormat: 'repeat'
})
});
@ -44,15 +44,15 @@ service.interceptors.request.use(
config => {
const { loading } = config;
// 如果是put/post请求用qs.stringify序列化参数
const isPutPost = config.method === "put" || config.method === "post";
const isJson = config.headers["Content-Type"] === "application/json";
const isFile = config.headers["Content-Type"] === "multipart/form-data";
const isPutPost = config.method === 'put' || config.method === 'post';
const isJson = config.headers['Content-Type'] === 'application/json';
const isFile = config.headers['Content-Type'] === 'multipart/form-data';
if (isPutPost && isJson) {
config.data = JSON.stringify(config.data);
}
if (isPutPost && !isFile && !isJson) {
config.data = qs.stringify(config.data, {
arrayFormat: "repeat"
arrayFormat: 'repeat'
});
}
/** 配置全屏加载 */
@ -60,16 +60,16 @@ service.interceptors.request.use(
config.loading = Spin.show();
}
const uuid = Storage.getItem("uuid");
config.headers["uuid"] = uuid;
const uuid = Storage.getItem('uuid');
config.headers['uuid'] = uuid;
// 获取访问Token
let accessToken = Storage.getItem("accessToken");
let accessToken = Storage.getItem('accessToken');
if (accessToken && config.needToken) {
config.headers["accessToken"] = accessToken;
config.headers['accessToken'] = accessToken;
// 解析当前token时间
let jwtData = JSON.parse(
decodeURIComponent(escape(window.atob(accessToken.split(".")[1])))
decodeURIComponent(escape(window.atob(accessToken.split('.')[1])))
);
if (jwtData.exp < Math.round(new Date() / 1000)) {
refresh()
@ -83,33 +83,32 @@ service.interceptors.request.use(
}
);
async function refresh() {
async function refresh (error) {
const getTokenRes = await refreshToken();
if (getTokenRes === "success") {
if (getTokenRes === 'success') {
// 刷新token
if (isRefreshToken === 1) {
error.response.config.headers.accessToken = Storage.getItem(
"accessToken"
'accessToken'
);
return service(error.response.config);
} else {
router.go(0);
}
} else {
Storage.removeItem("accessToken");
Storage.removeItem("refreshToken");
Storage.removeItem("userInfo");
Storage.setItem("cartNum", 0);
store.commit("SET_CARTNUM", 0);
console.log("1111");
Storage.removeItem('accessToken');
Storage.removeItem('refreshToken');
Storage.removeItem('userInfo');
Storage.setItem('cartNum', 0);
store.commit('SET_CARTNUM', 0);
Modal.confirm({
title: "请登录",
content: "<p>请登录后执行此操作</p>",
okText: "立即登录",
cancelText: "继续浏览",
title: '请登录',
content: '<p>请登录后执行此操作</p>',
okText: '立即登录',
cancelText: '继续浏览',
onOk: () => {
router.push({
path: "/login",
path: '/login',
query: {
rePath: router.history.current.path,
query: JSON.stringify(router.history.current.query)
@ -140,15 +139,15 @@ service.interceptors.response.use(
isRefreshToken++;
if (isRefreshToken === 1) {
refresh()
refresh(error)
isRefreshToken = 0;
}
} else {
if (error.message) {
let _message =
error.code === "ECONNABORTED"
? "连接超时,请稍候再试!"
: "网络错误,请稍后再试!";
error.code === 'ECONNABORTED'
? '连接超时,请稍候再试!'
: '网络错误,请稍后再试!';
Message.error(errorData.message || _message);
}
}
@ -171,13 +170,13 @@ const closeLoading = target => {
};
export const Method = {
GET: "get",
POST: "post",
PUT: "put",
DELETE: "delete"
GET: 'get',
POST: 'post',
PUT: 'put',
DELETE: 'delete'
};
export default function request(options) {
export default function request (options) {
// 如果是服务端或者是请求的刷新token不需要检查token直接请求。
// if (process.server || options.url.indexOf('passport/token') !== -1) {
return service(options);
@ -186,19 +185,19 @@ export default function request(options) {
}
// 防抖闭包来一波
function getTokenDebounce() {
function getTokenDebounce () {
let lock = false;
let success = false;
return function() {
return function () {
if (!lock) {
lock = true;
let oldRefreshToken = Storage.getItem("refreshToken");
let oldRefreshToken = Storage.getItem('refreshToken');
handleRefreshToken(oldRefreshToken)
.then(res => {
if (res.success) {
let { accessToken, refreshToken } = res.result;
Storage.setItem("accessToken", accessToken);
Storage.setItem("refreshToken", refreshToken);
Storage.setItem('accessToken', accessToken);
Storage.setItem('refreshToken', refreshToken);
success = true;
lock = false;
@ -220,9 +219,9 @@ function getTokenDebounce() {
if (!lock) {
clearInterval(timer);
if (success) {
resolve("success");
resolve('success');
} else {
resolve("fail");
resolve('fail');
}
}
}, 500); // 轮询时间间隔

View File

@ -5,7 +5,7 @@ import ViewUI from "view-design";
import "./styles/theme.less";
import "core-js/stable";
import "regenerator-runtime/runtime";
// import "regenerator-runtime/runtime";
import vueQr from 'vue-qr'
import App from "./App";