uniapp【新增】:发票页面新增从微信获取发票数据

This commit is contained in:
花城
2024-11-25 14:41:54 +08:00
parent 39b57ab895
commit b8436adf56
2 changed files with 247 additions and 229 deletions

View File

@@ -60,32 +60,29 @@
justify-content: space-between;
.btn-box {
padding:20rpx;
width: calc(100% - 40rpx);
width: 100%;
display: flex;
align-items: center;
justify-content: space-between;
.no {
width: 48%;
background-color: #333;
color: #fff;
.btn {
flex: 1;
margin: 20rpx;
font-size: 27rpx;
height: 90prx;
line-height: 90rpx;
border-radius: 15rpx;
text-align: center;
color: #fff;
}
.no {
background-color: #333;
}
.ok {
width: 48%;
background-color: #d33123;
color: #fff;
font-size: 27rpx;
height: 90prx;
line-height: 90rpx;
border-radius: 15rpx;
text-align: center;
}
.choose {
background-color: #54bd63;
}
}
}

View File

@@ -45,8 +45,11 @@
<!-- 底部按钮 -->
<view class="goods-detail-bottom-tabbar">
<view class="btn-box">
<view class="no" @click="handleNotUseInvoices"> 本次不开具发票 </view>
<view class="ok" @click="handleSaveInvoice"> 保存发票 </view>
<view class="btn no" @click="handleNotUseInvoices"> 本次不开具发票 </view>
<view class="btn ok" @click="handleSaveInvoice"> 保存发票 </view>
<!-- #ifdef MP-WEIXIN -->
<view class="btn choose" @click="handleChooseInvoice"> 获取用户发票 </view>
<!-- #endif -->
</view>
</view>
</view>
@@ -140,6 +143,24 @@
})
}
/**
* https://developers.weixin.qq.com/miniprogram/dev/api/open-api/invoice/wx.chooseInvoiceTitle.html
* 在微信小程序中,当前小程序必须关联一个公众号,且这个公众号是完成了微信认证的,才能调用 chooseInvoiceTitle。
*/
const handleChooseInvoice = () => {
uni.chooseInvoiceTitle({
success(res : any) {
if (res.errMsg == "chooseInvoiceTitle:ok") {
state.model.name = res.title;
state.model.code = res.taxNumber;
state.model.type = res.type == "0" ? InvoiceEnum.company : InvoiceEnum.personal;
state.model.typeName = res.type == "0" ? state.radioItems[1].name : state.radioItems[0].name;
} else {
handleShowToast(res.errMsg)
}
}
})
}
/** 保存发票 */
const handleSaveInvoice = () => {
if (state.model.type === InvoiceEnum.no) {