feat(订单页面): 开票
This commit is contained in:
14
pages.json
14
pages.json
@@ -353,6 +353,20 @@
|
||||
"navigationBarTitleText": "订单详情",
|
||||
"enablePullDownRefresh": false
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "my/my-drug/invoice-apply",
|
||||
"style": {
|
||||
"navigationBarTitleText": "申请开票",
|
||||
"enablePullDownRefresh": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "my/my-drug/invoice-detail",
|
||||
"style": {
|
||||
"navigationBarTitleText": "开票详情",
|
||||
"enablePullDownRefresh": false
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
@@ -339,9 +339,9 @@ export async function getUseWayPay(params) {
|
||||
return data
|
||||
}
|
||||
|
||||
// 更新配送方式 http://xiaokang.com/member/v1/product-order/update-delivery
|
||||
// 更新配送方式(Laravel:单品包邮重算)
|
||||
export async function getDelivery(params) {
|
||||
let data = await http('/oldApi/v1/product-order/update-delivery', params)
|
||||
let data = await http('/xkApi/product-order/update-delivery', params)
|
||||
return data
|
||||
}
|
||||
|
||||
|
||||
33
request/api/invoice.js
Normal file
33
request/api/invoice.js
Normal file
@@ -0,0 +1,33 @@
|
||||
import { get, post } from './http'
|
||||
|
||||
/**
|
||||
* 将 xk-api 的 code/result 规范为 errcode/data,便于页面统一判断
|
||||
*/
|
||||
function normalizeXkApiResponse(res) {
|
||||
if (res && res.data && (res.data.code === 0 || res.data.code === '0')) {
|
||||
res.data.errcode = 0
|
||||
res.data.data = res.data.result
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
/**
|
||||
* 申请开票
|
||||
* @param {object} params order_id, title_type, title_name, tax_no, receive_type, email
|
||||
*/
|
||||
export async function applyInvoiceApi(params) {
|
||||
const data = await post('/invoice/apply', params, 3)
|
||||
return normalizeXkApiResponse(data)
|
||||
}
|
||||
|
||||
/**
|
||||
* 开票详情
|
||||
* @param {object} params id 或 order_id
|
||||
*/
|
||||
export async function getInvoiceDetailApi(params) {
|
||||
const data = await get('/invoice/detail', params, 3)
|
||||
return normalizeXkApiResponse(data)
|
||||
}
|
||||
|
||||
/** 与 config/xk.php invoice_notice 保持一致的订阅消息模板 ID */
|
||||
export const INVOICE_NOTICE_TMPL_ID = '2FuQhhO74mABSqGx2cF7vRR2wGekrIMM9kZMvVI6h-Q'
|
||||
@@ -432,51 +432,62 @@ export default {
|
||||
return
|
||||
}
|
||||
|
||||
// 先调用接口更新,成功后再更新页面状态
|
||||
if (index == 1) {
|
||||
// 到店自取:先调用接口,成功后再更新页面
|
||||
this.toUpdata(index)
|
||||
this.toUpdata(1)
|
||||
return
|
||||
}
|
||||
|
||||
// 快递到家:已有地址则直接切配送;否则去地址页(地址页会带 delivery_method=0 提交)
|
||||
// 禁止在此处只改本地状态而不调接口,否则 onShow 可能用旧 delivery_method=1 覆盖
|
||||
const hasAddress = !!(this.orderInfo.ProductOrder && this.orderInfo.ProductOrder.address_id)
|
||||
|| !!uni.getStorageSync('address_id')
|
||||
if (hasAddress) {
|
||||
this.toUpdata(0)
|
||||
} else {
|
||||
// 快递到家:跳转到地址选择页面
|
||||
this.isshowed = false
|
||||
this.isshow = true
|
||||
this.toChoose()
|
||||
}
|
||||
},
|
||||
// 更新配送方式
|
||||
// 更新配送方式(仅用户明确操作时调用,禁止 onShow 盲调)
|
||||
toUpdata(deliveryMethodIndex) {
|
||||
if (!this.order_id) return
|
||||
if (deliveryMethodIndex === undefined || deliveryMethodIndex === null) {
|
||||
return
|
||||
}
|
||||
|
||||
// 如果传入了参数,使用传入的值,否则使用当前的 delivery_method
|
||||
const targetDeliveryMethod = deliveryMethodIndex !== undefined ? deliveryMethodIndex : this.delivery_method
|
||||
const targetDeliveryMethod = deliveryMethodIndex
|
||||
const addressId = uni.getStorageSync('address_id')
|
||||
|| (this.orderInfo.ProductOrder && this.orderInfo.ProductOrder.address_id)
|
||||
|| 0
|
||||
|
||||
getDelivery({
|
||||
method: "post",
|
||||
data: {
|
||||
address_id: uni.getStorageSync('address_id'),
|
||||
address_id: addressId,
|
||||
delivery_method: targetDeliveryMethod,
|
||||
order_id: this.order_id,
|
||||
store_id: uni.getStorageSync('store_id') || '11001'
|
||||
}
|
||||
}).then((res) => {
|
||||
if (res.data.errcode === 0) {
|
||||
// 接口成功后再更新页面状态
|
||||
if (deliveryMethodIndex !== undefined) {
|
||||
this.delivery_method = deliveryMethodIndex
|
||||
if (deliveryMethodIndex == 1) {
|
||||
this.isshowed = true
|
||||
this.isshow = false
|
||||
} else {
|
||||
this.isshowed = false
|
||||
this.isshow = true
|
||||
}
|
||||
const ok = res.data && (res.data.code === 0 || res.data.errcode === 0)
|
||||
if (ok) {
|
||||
this.delivery_method = targetDeliveryMethod
|
||||
uni.setStorageSync('delivery_method', targetDeliveryMethod)
|
||||
if (targetDeliveryMethod == 1) {
|
||||
this.isshowed = true
|
||||
this.isshow = false
|
||||
} else {
|
||||
this.isshowed = false
|
||||
this.isshow = true
|
||||
}
|
||||
// 刷新订单信息
|
||||
this.getInfo()
|
||||
} else {
|
||||
// 错误处理:拒绝更新并显示错误信息,不更新页面状态
|
||||
this.$refs.uToast.show({
|
||||
title: res.data.msg || '更新失败',
|
||||
title: (res.data && (res.data.message || res.data.msg)) || '更新失败',
|
||||
type: 'default',
|
||||
icon: false
|
||||
})
|
||||
@@ -597,7 +608,7 @@ export default {
|
||||
}
|
||||
})
|
||||
},
|
||||
// 地址列表
|
||||
// 地址列表(仅拉取列表,禁止自动 toUpdata,避免用旧 delivery_method=1 覆盖刚改好的快递)
|
||||
getList() {
|
||||
getaddressList({
|
||||
method: "post",
|
||||
@@ -609,8 +620,6 @@ export default {
|
||||
this.actionList = res.data.data
|
||||
}
|
||||
})
|
||||
|
||||
this.toUpdata()
|
||||
},
|
||||
// 地址
|
||||
toChoose() {
|
||||
|
||||
@@ -130,8 +130,16 @@
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 按钮区完全保留你原有的判断逻辑 -->
|
||||
<!-- 按钮区:查看发票为左下角 link,其余操作靠右 -->
|
||||
<view class="choose_btn">
|
||||
<view
|
||||
class="invoice_link"
|
||||
v-if="item.invoice_id && item.invoice_status==2"
|
||||
@tap.stop="toInvoiceDetail(item.invoice_id)"
|
||||
>
|
||||
查看发票
|
||||
</view>
|
||||
<view class="btn_right">
|
||||
<view class="order_info active" v-if="item.is_pay==0 && item.status==0 && item.cancel_status==0"
|
||||
@tap.stop="goCancel(item.id)">
|
||||
取消
|
||||
@@ -167,7 +175,21 @@
|
||||
<view class="order_info active" v-if="(item.status===2||item.status===6||item.status===7) && item.is_pay==1 && item.cancel_status==0 && item.delivery_method === 0" @tap.stop="toDevilty(item.id)">
|
||||
查看物流
|
||||
</view>
|
||||
|
||||
<view
|
||||
class="order_info active"
|
||||
v-if="item.can_invoice==1"
|
||||
@tap.stop="toInvoiceApply(item)"
|
||||
>
|
||||
申请开票
|
||||
</view>
|
||||
<view
|
||||
class="order_info active"
|
||||
v-else-if="item.invoice_id && (item.invoice_status==0 || item.invoice_status==1)"
|
||||
@tap.stop="toInvoiceDetail(item.invoice_id)"
|
||||
>
|
||||
开票详情
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<u-loadmore :status="loadMoreStatus" v-if="orderList.length!=0" margin-top="30" margin-bottom="30" />
|
||||
@@ -304,6 +326,24 @@ export default {
|
||||
url: '/subPackages/shop/logistics?id=' + e
|
||||
})
|
||||
},
|
||||
/**
|
||||
* 跳转申请开票页
|
||||
*/
|
||||
toInvoiceApply(item) {
|
||||
uni.navigateTo({
|
||||
url: '/subPackages/my/my-drug/invoice-apply?order_id=' + item.id
|
||||
+ '&order_no=' + encodeURIComponent(item.order_no || '')
|
||||
+ '&amount=' + encodeURIComponent(item.total_pay_price || '')
|
||||
})
|
||||
},
|
||||
/**
|
||||
* 跳转开票详情/下载页
|
||||
*/
|
||||
toInvoiceDetail(invoiceId) {
|
||||
uni.navigateTo({
|
||||
url: '/subPackages/my/my-drug/invoice-detail?id=' + invoiceId
|
||||
})
|
||||
},
|
||||
|
||||
next(id) {
|
||||
this.id = id
|
||||
@@ -850,10 +890,26 @@ export default {
|
||||
|
||||
.choose_btn {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-top: 32rpx;
|
||||
flex-wrap: wrap;
|
||||
|
||||
.invoice_link {
|
||||
font-size: 26rpx;
|
||||
font-weight: 500;
|
||||
color: #5f71fe;
|
||||
padding: 12rpx 0;
|
||||
margin-right: auto;
|
||||
}
|
||||
|
||||
.btn_right {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
justify-content: flex-end;
|
||||
margin-left: auto;
|
||||
}
|
||||
|
||||
.order_info {
|
||||
font-size: 26rpx;
|
||||
font-weight: 400;
|
||||
|
||||
326
subPackages/my/my-drug/invoice-apply.vue
Normal file
326
subPackages/my/my-drug/invoice-apply.vue
Normal file
@@ -0,0 +1,326 @@
|
||||
<template>
|
||||
<view class="page safe-area-inset-bottom">
|
||||
<!-- 订单摘要 -->
|
||||
<view class="card">
|
||||
<view class="card_title">订单信息</view>
|
||||
<view class="card_row">
|
||||
<text class="label">订单号</text>
|
||||
<text class="value">{{ orderNo }}</text>
|
||||
</view>
|
||||
<view class="card_row last">
|
||||
<text class="label">开票金额</text>
|
||||
<text class="value price">¥{{ amount }}</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 抬头信息 -->
|
||||
<view class="card">
|
||||
<view class="card_title">抬头信息</view>
|
||||
<view class="card_row">
|
||||
<text class="label">抬头类型</text>
|
||||
<view class="seg">
|
||||
<view
|
||||
class="seg_item"
|
||||
:class="{ active: titleType == 1 }"
|
||||
@tap="titleType = 1"
|
||||
>个人</view>
|
||||
<view
|
||||
class="seg_item"
|
||||
:class="{ active: titleType == 2 }"
|
||||
@tap="titleType = 2"
|
||||
>企业</view>
|
||||
</view>
|
||||
</view>
|
||||
<view class="card_row">
|
||||
<text class="label"><text class="req">*</text>抬头名称</text>
|
||||
<input
|
||||
class="input"
|
||||
v-model="titleName"
|
||||
:placeholder="titleType == 2 ? '请输入企业名称' : '请输入个人姓名'"
|
||||
placeholder-class="ph"
|
||||
/>
|
||||
</view>
|
||||
<view class="card_row last" v-if="titleType == 2">
|
||||
<text class="label"><text class="req">*</text>企业税号</text>
|
||||
<input
|
||||
class="input"
|
||||
v-model="taxNo"
|
||||
placeholder="请输入纳税人识别号"
|
||||
placeholder-class="ph"
|
||||
/>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 接收方式(暂时隐藏,保留代码;默认小程序可查 + 邮箱选填) -->
|
||||
<view class="card" v-if="false">
|
||||
<view class="card_title">接收方式</view>
|
||||
<view class="seg full">
|
||||
<view
|
||||
class="seg_item"
|
||||
:class="{ active: receiveType == 1 }"
|
||||
@tap="receiveType = 1"
|
||||
>小程序下载</view>
|
||||
<view
|
||||
class="seg_item"
|
||||
:class="{ active: receiveType == 2 }"
|
||||
@tap="receiveType = 2"
|
||||
>邮箱接收</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 邮箱选填 + 说明 -->
|
||||
<view class="card">
|
||||
<view class="card_title">接收邮箱</view>
|
||||
<view class="card_row last">
|
||||
<text class="label">邮箱</text>
|
||||
<input
|
||||
class="input"
|
||||
v-model="email"
|
||||
placeholder="选填,便于邮件查收"
|
||||
placeholder-class="ph"
|
||||
/>
|
||||
</view>
|
||||
<view class="tip">开具发票后可到小程序或邮箱中查收</view>
|
||||
</view>
|
||||
|
||||
<view class="footer">
|
||||
<button class="submit" :loading="submitting" @tap="onSubmit">提交申请</button>
|
||||
</view>
|
||||
<u-toast ref="uToast" />
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { applyInvoiceApi, INVOICE_NOTICE_TMPL_ID } from '@/request/api/invoice.js'
|
||||
|
||||
/**
|
||||
* 申请开票页:抬头必填、邮箱选填;接收方式隐藏,固定小程序通道
|
||||
* 提交前申请一次订阅授权(留给开票完成推送)
|
||||
*/
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
orderId: 0,
|
||||
orderNo: '',
|
||||
amount: '',
|
||||
titleType: 1,
|
||||
titleName: '',
|
||||
taxNo: '',
|
||||
// 固定小程序可查;接收方式选择 UI 已隐藏
|
||||
receiveType: 1,
|
||||
email: '',
|
||||
submitting: false
|
||||
}
|
||||
},
|
||||
onLoad(query) {
|
||||
this.orderId = Number(query.order_id || 0)
|
||||
this.orderNo = decodeURIComponent(query.order_no || '')
|
||||
this.amount = query.amount || ''
|
||||
},
|
||||
/**
|
||||
* 下拉刷新:重置表单字段,保留路由带来的订单信息
|
||||
*/
|
||||
onPullDownRefresh() {
|
||||
this.resetForm()
|
||||
uni.stopPullDownRefresh()
|
||||
},
|
||||
methods: {
|
||||
/** 重置抬头与邮箱,订单号/金额不动 */
|
||||
resetForm() {
|
||||
this.titleType = 1
|
||||
this.titleName = ''
|
||||
this.taxNo = ''
|
||||
this.receiveType = 1
|
||||
this.email = ''
|
||||
},
|
||||
/**
|
||||
* 校验表单后请求订阅授权,再提交申请
|
||||
*/
|
||||
onSubmit() {
|
||||
if (!this.orderId) {
|
||||
this.$refs.uToast.show({ title: '订单无效', type: 'error' })
|
||||
return
|
||||
}
|
||||
const titleName = (this.titleName || '').trim()
|
||||
if (!titleName) {
|
||||
this.$refs.uToast.show({ title: '请填写抬头名称', type: 'warning' })
|
||||
return
|
||||
}
|
||||
if (this.titleType == 2 && !(this.taxNo || '').trim()) {
|
||||
this.$refs.uToast.show({ title: '请填写企业税号', type: 'warning' })
|
||||
return
|
||||
}
|
||||
let email = (this.email || '').trim()
|
||||
// 邮箱选填:有值才校验格式
|
||||
if (email && !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email)) {
|
||||
this.$refs.uToast.show({ title: '请填写正确邮箱', type: 'warning' })
|
||||
return
|
||||
}
|
||||
if (!email) {
|
||||
email = ''
|
||||
}
|
||||
// 订阅消息同模板一次手势只给 1 次额度,留给「开票完成」推送
|
||||
uni.requestSubscribeMessage({
|
||||
tmplIds: [INVOICE_NOTICE_TMPL_ID],
|
||||
complete: () => {
|
||||
this.doApply(titleName, email)
|
||||
}
|
||||
})
|
||||
},
|
||||
/**
|
||||
* 调用后端提交开票申请(固定 receive_type=1,邮箱可带)
|
||||
*/
|
||||
doApply(titleName, email) {
|
||||
if (this.submitting) return
|
||||
this.submitting = true
|
||||
applyInvoiceApi({
|
||||
order_id: this.orderId,
|
||||
title_type: this.titleType,
|
||||
title_name: titleName,
|
||||
tax_no: this.titleType == 2 ? (this.taxNo || '').trim() : '',
|
||||
receive_type: 1,
|
||||
email: email
|
||||
}).then((res) => {
|
||||
if (res.data && res.data.errcode == 0) {
|
||||
const id = res.data.data && res.data.data.id
|
||||
uni.showToast({ title: '提交成功', icon: 'success' })
|
||||
setTimeout(() => {
|
||||
if (id) {
|
||||
uni.redirectTo({
|
||||
url: '/subPackages/my/my-drug/invoice-detail?id=' + id
|
||||
})
|
||||
} else {
|
||||
uni.navigateBack()
|
||||
}
|
||||
}, 500)
|
||||
} else {
|
||||
uni.showToast({
|
||||
title: (res.data && (res.data.errmsg || res.data.message)) || '提交失败',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
}).catch(() => {
|
||||
uni.showToast({ title: '提交失败', icon: 'none' })
|
||||
}).finally(() => {
|
||||
this.submitting = false
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.page {
|
||||
min-height: 100vh;
|
||||
background: #f8fafc;
|
||||
padding: 20rpx 0 180rpx;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
.card {
|
||||
width: 720rpx;
|
||||
margin: 0 auto 20rpx;
|
||||
background: #fff;
|
||||
border-radius: 16rpx;
|
||||
padding: 0 28rpx 8rpx;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
.card_title {
|
||||
height: 96rpx;
|
||||
line-height: 96rpx;
|
||||
font-size: 32rpx;
|
||||
font-weight: 500;
|
||||
color: #232323;
|
||||
border-bottom: 1rpx solid #e2e8f0;
|
||||
}
|
||||
.card_row {
|
||||
min-height: 100rpx;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
border-bottom: 1rpx solid #e2e8f0;
|
||||
padding: 12rpx 0;
|
||||
}
|
||||
.card_row.last {
|
||||
border-bottom: none;
|
||||
}
|
||||
.label {
|
||||
color: #1e293b;
|
||||
font-size: 28rpx;
|
||||
flex-shrink: 0;
|
||||
margin-right: 24rpx;
|
||||
}
|
||||
.req {
|
||||
color: #ff5050;
|
||||
margin-right: 4rpx;
|
||||
}
|
||||
.value {
|
||||
color: #334155;
|
||||
font-size: 28rpx;
|
||||
text-align: right;
|
||||
flex: 1;
|
||||
word-break: break-all;
|
||||
}
|
||||
.price {
|
||||
color: #ff5050;
|
||||
font-weight: 600;
|
||||
}
|
||||
.input {
|
||||
flex: 1;
|
||||
font-size: 28rpx;
|
||||
color: #1e293b;
|
||||
text-align: right;
|
||||
}
|
||||
.ph {
|
||||
color: #94a3b8;
|
||||
}
|
||||
.seg {
|
||||
display: flex;
|
||||
gap: 16rpx;
|
||||
}
|
||||
.seg.full {
|
||||
width: 100%;
|
||||
margin: 24rpx 0;
|
||||
}
|
||||
.seg_item {
|
||||
min-width: 140rpx;
|
||||
padding: 12rpx 28rpx;
|
||||
text-align: center;
|
||||
border-radius: 32rpx;
|
||||
border: 2rpx solid #e5e5e5;
|
||||
color: #64748b;
|
||||
font-size: 26rpx;
|
||||
background: #fff;
|
||||
}
|
||||
.seg_item.active {
|
||||
border-color: #5f71fe;
|
||||
color: #5f71fe;
|
||||
background: #f4f5ff;
|
||||
font-weight: 500;
|
||||
}
|
||||
.tip {
|
||||
font-size: 24rpx;
|
||||
color: #94a3b8;
|
||||
line-height: 1.5;
|
||||
padding: 8rpx 0 24rpx;
|
||||
}
|
||||
.footer {
|
||||
position: fixed;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
padding: 20rpx 32rpx calc(20rpx + env(safe-area-inset-bottom));
|
||||
background: #fff;
|
||||
box-shadow: 0 -4rpx 16rpx rgba(0, 0, 0, 0.04);
|
||||
}
|
||||
.submit {
|
||||
background: #5f71fe;
|
||||
color: #fff;
|
||||
border-radius: 44rpx;
|
||||
font-size: 30rpx;
|
||||
height: 88rpx;
|
||||
line-height: 88rpx;
|
||||
}
|
||||
.submit::after {
|
||||
border: none;
|
||||
}
|
||||
</style>
|
||||
250
subPackages/my/my-drug/invoice-detail.vue
Normal file
250
subPackages/my/my-drug/invoice-detail.vue
Normal file
@@ -0,0 +1,250 @@
|
||||
<template>
|
||||
<view class="page safe-area-inset-bottom">
|
||||
<view class="card" v-if="info">
|
||||
<view class="status-row">
|
||||
<text class="status">{{ info.status_text || '' }}</text>
|
||||
<text class="amount">¥{{ info.amount || '' }}</text>
|
||||
</view>
|
||||
<view class="row"><text class="label">订单号</text><text class="value">{{ info.order_no }}</text></view>
|
||||
<view class="row"><text class="label">抬头类型</text><text class="value">{{ info.title_type_text }}</text></view>
|
||||
<view class="row"><text class="label">抬头名称</text><text class="value">{{ info.title_name }}</text></view>
|
||||
<view class="row" v-if="info.title_type == 2">
|
||||
<text class="label">税号</text><text class="value">{{ info.tax_no }}</text>
|
||||
</view>
|
||||
<view class="row"><text class="label">接收方式</text><text class="value">{{ info.receive_type_text }}</text></view>
|
||||
<view class="row" v-if="info.receive_type == 2">
|
||||
<text class="label">邮箱</text><text class="value">{{ info.email }}</text>
|
||||
</view>
|
||||
<view class="row" v-if="info.invoice_code">
|
||||
<text class="label">票据代码</text><text class="value">{{ info.invoice_code }}</text>
|
||||
</view>
|
||||
<view class="row" v-if="info.reject_reason">
|
||||
<text class="label">拒绝原因</text><text class="value warn">{{ info.reject_reason }}</text>
|
||||
</view>
|
||||
<view class="tip" v-if="info.status == 2 && info.receive_type == 2">
|
||||
发票已发送至邮箱{{ info.email_sent == 1 ? '' : '(如未收到可联系客服)' }}
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="card" v-if="info && info.status == 2 && fileList.length">
|
||||
<view class="section-title">发票文件</view>
|
||||
<view
|
||||
class="file-item"
|
||||
v-for="(url, index) in fileList"
|
||||
:key="index"
|
||||
@tap="openFile(url)"
|
||||
>
|
||||
<image
|
||||
v-if="isImage(url)"
|
||||
class="thumb"
|
||||
:src="url"
|
||||
mode="aspectFill"
|
||||
/>
|
||||
<view v-else class="file-icon">PDF</view>
|
||||
<text class="file-name">{{ fileName(url, index) }}</text>
|
||||
<text class="link">{{ isImage(url) ? '预览' : '打开文档预览' }}</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="empty" v-if="!loading && !info">暂无开票信息</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { getInvoiceDetailApi } from '@/request/api/invoice.js'
|
||||
|
||||
/**
|
||||
* 开票详情/下载页:订阅消息落地页,支持预览图片与打开 PDF
|
||||
*/
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
id: 0,
|
||||
orderId: 0,
|
||||
info: null,
|
||||
loading: false
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
fileList() {
|
||||
if (!this.info || !this.info.invoice_files) return []
|
||||
return this.info.invoice_files
|
||||
}
|
||||
},
|
||||
onLoad(query) {
|
||||
this.id = Number(query.id || 0)
|
||||
this.orderId = Number(query.order_id || 0)
|
||||
this.loadDetail()
|
||||
},
|
||||
methods: {
|
||||
/**
|
||||
* 拉取开票详情
|
||||
*/
|
||||
loadDetail() {
|
||||
if (!this.id && !this.orderId) return
|
||||
this.loading = true
|
||||
const params = this.id ? { id: this.id } : { order_id: this.orderId }
|
||||
getInvoiceDetailApi(params).then((res) => {
|
||||
if (res.data && res.data.errcode == 0) {
|
||||
this.info = res.data.data || null
|
||||
} else {
|
||||
uni.showToast({
|
||||
title: (res.data && (res.data.errmsg || res.data.message)) || '加载失败',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
}).finally(() => {
|
||||
this.loading = false
|
||||
})
|
||||
},
|
||||
isImage(url) {
|
||||
return /\.(jpg|jpeg|png|gif|webp)(\?|$)/i.test(url || '')
|
||||
},
|
||||
fileName(url, index) {
|
||||
const name = (url || '').split('/').pop() || ''
|
||||
return name || ('发票文件' + (index + 1))
|
||||
},
|
||||
/**
|
||||
* 预览图片;PDF 通过微信文档能力打开(小程序无法页内嵌 PDF)
|
||||
*/
|
||||
openFile(url) {
|
||||
if (!url) return
|
||||
if (this.isImage(url)) {
|
||||
uni.previewImage({
|
||||
urls: this.fileList.filter((u) => this.isImage(u)),
|
||||
current: url
|
||||
})
|
||||
return
|
||||
}
|
||||
uni.showLoading({ title: '打开文档预览' })
|
||||
uni.downloadFile({
|
||||
url: url,
|
||||
success: (res) => {
|
||||
if (res.statusCode === 200) {
|
||||
uni.openDocument({
|
||||
filePath: res.tempFilePath,
|
||||
fileType: 'pdf',
|
||||
showMenu: true,
|
||||
fail: () => {
|
||||
uni.showToast({ title: '无法打开文档,请稍后重试或联系客服', icon: 'none' })
|
||||
}
|
||||
})
|
||||
} else {
|
||||
uni.showToast({ title: '下载失败', icon: 'none' })
|
||||
}
|
||||
},
|
||||
fail: () => {
|
||||
uni.showToast({ title: '下载失败,请稍后重试', icon: 'none' })
|
||||
},
|
||||
complete: () => {
|
||||
uni.hideLoading()
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.page {
|
||||
min-height: 100vh;
|
||||
background: #f5f6f8;
|
||||
padding: 24rpx;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
.card {
|
||||
background: #fff;
|
||||
border-radius: 16rpx;
|
||||
padding: 24rpx;
|
||||
margin-bottom: 24rpx;
|
||||
}
|
||||
.status-row {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 16rpx;
|
||||
padding-bottom: 16rpx;
|
||||
border-bottom: 1rpx solid #f0f0f0;
|
||||
}
|
||||
.status {
|
||||
font-size: 32rpx;
|
||||
font-weight: 600;
|
||||
color: #1777ff;
|
||||
}
|
||||
.amount {
|
||||
color: #e54d42;
|
||||
font-size: 32rpx;
|
||||
font-weight: 600;
|
||||
}
|
||||
.row {
|
||||
display: flex;
|
||||
padding: 12rpx 0;
|
||||
font-size: 28rpx;
|
||||
}
|
||||
.label {
|
||||
width: 160rpx;
|
||||
color: #999;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.value {
|
||||
flex: 1;
|
||||
color: #333;
|
||||
word-break: break-all;
|
||||
}
|
||||
.warn {
|
||||
color: #e54d42;
|
||||
}
|
||||
.tip {
|
||||
margin-top: 16rpx;
|
||||
font-size: 24rpx;
|
||||
color: #999;
|
||||
}
|
||||
.section-title {
|
||||
font-size: 30rpx;
|
||||
font-weight: 600;
|
||||
margin-bottom: 16rpx;
|
||||
}
|
||||
.file-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 16rpx 0;
|
||||
border-top: 1rpx solid #f0f0f0;
|
||||
}
|
||||
.thumb {
|
||||
width: 80rpx;
|
||||
height: 80rpx;
|
||||
border-radius: 8rpx;
|
||||
margin-right: 16rpx;
|
||||
background: #f5f5f5;
|
||||
}
|
||||
.file-icon {
|
||||
width: 80rpx;
|
||||
height: 80rpx;
|
||||
border-radius: 8rpx;
|
||||
margin-right: 16rpx;
|
||||
background: #fff1f0;
|
||||
color: #e54d42;
|
||||
font-size: 24rpx;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
.file-name {
|
||||
flex: 1;
|
||||
font-size: 26rpx;
|
||||
color: #333;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.link {
|
||||
color: #1777ff;
|
||||
font-size: 26rpx;
|
||||
margin-left: 12rpx;
|
||||
}
|
||||
.empty {
|
||||
text-align: center;
|
||||
color: #999;
|
||||
padding: 80rpx 0;
|
||||
}
|
||||
</style>
|
||||
@@ -394,55 +394,64 @@
|
||||
return
|
||||
}
|
||||
|
||||
// 先调用接口更新,成功后再更新页面状态
|
||||
if (index == 1) {
|
||||
// 到店自取:先调用接口,成功后再更新页面
|
||||
this.toUpdata(index)
|
||||
this.toUpdata(1)
|
||||
return
|
||||
}
|
||||
|
||||
// 快递到家:已有地址则直接切配送;否则去地址页
|
||||
const hasAddress = !!(this.orderInfo.ProductOrder && this.orderInfo.ProductOrder.address_id)
|
||||
|| !!uni.getStorageSync('address_id')
|
||||
if (hasAddress) {
|
||||
this.toUpdata(0)
|
||||
} else {
|
||||
// 快递到家:跳转到地址选择页面
|
||||
this.isshowed = false
|
||||
this.isshow = true
|
||||
this.toChoose()
|
||||
}
|
||||
// console.log(`点击了第${index + 1}项,内容为:${this.list[index].text}`)
|
||||
},
|
||||
// 更新配送方式
|
||||
// 更新配送方式(仅用户明确操作时调用,禁止 onShow 盲调)
|
||||
toUpdata(deliveryMethodIndex) {
|
||||
// 如果传入了参数,使用传入的值,否则使用当前的 delivery_method
|
||||
const targetDeliveryMethod = deliveryMethodIndex !== undefined ? deliveryMethodIndex : this.delivery_method
|
||||
if (this.order_id == '') {
|
||||
return
|
||||
}
|
||||
if (deliveryMethodIndex === undefined || deliveryMethodIndex === null) {
|
||||
return
|
||||
}
|
||||
|
||||
const targetDeliveryMethod = deliveryMethodIndex
|
||||
const addressId = uni.getStorageSync('address_id')
|
||||
|| (this.orderInfo.ProductOrder && this.orderInfo.ProductOrder.address_id)
|
||||
|| 0
|
||||
|
||||
if (this.order_id == '') {
|
||||
return ;
|
||||
}
|
||||
getDelivery({
|
||||
method: "post",
|
||||
data: {
|
||||
address_id: uni.getStorageSync('address_id'),
|
||||
address_id: addressId,
|
||||
delivery_method: targetDeliveryMethod,
|
||||
order_id: this.order_id,
|
||||
store_id: uni.getStorageSync('store_id') || '11001'
|
||||
}
|
||||
}).then((res) => {
|
||||
if (res.data.errcode === 0) {
|
||||
// 接口成功后再更新页面状态
|
||||
if (deliveryMethodIndex !== undefined) {
|
||||
this.wayText = this.list[deliveryMethodIndex].text
|
||||
this.delivery_method = deliveryMethodIndex
|
||||
if (deliveryMethodIndex == 1) {
|
||||
this.isshowed = true
|
||||
this.isshow = false
|
||||
} else {
|
||||
this.isshowed = false
|
||||
this.isshow = true
|
||||
}
|
||||
const ok = res.data && (res.data.code === 0 || res.data.errcode === 0)
|
||||
if (ok) {
|
||||
this.wayText = this.list[targetDeliveryMethod] && this.list[targetDeliveryMethod].text
|
||||
this.delivery_method = targetDeliveryMethod
|
||||
uni.setStorageSync('delivery_method', targetDeliveryMethod)
|
||||
if (targetDeliveryMethod == 1) {
|
||||
this.isshowed = true
|
||||
this.isshow = false
|
||||
} else {
|
||||
this.isshowed = false
|
||||
this.isshow = true
|
||||
}
|
||||
// 刷新订单信息
|
||||
this.getInfo()
|
||||
// console.log(res, '确定代煎');
|
||||
} else {
|
||||
// 错误处理:拒绝更新并显示错误信息,不更新页面状态
|
||||
this.$refs.uToast.show({
|
||||
title: res.data.msg || '更新失败',
|
||||
title: (res.data && (res.data.message || res.data.msg)) || '更新失败',
|
||||
type: 'default',
|
||||
icon: false
|
||||
})
|
||||
@@ -591,7 +600,7 @@
|
||||
}
|
||||
})
|
||||
},
|
||||
// 地址列表
|
||||
// 地址列表(仅拉取列表,禁止自动 toUpdata,避免用旧 delivery_method=1 覆盖刚改好的快递)
|
||||
getList() {
|
||||
getaddressList({
|
||||
method: "post",
|
||||
@@ -604,7 +613,6 @@
|
||||
this.actionList = res.data.data
|
||||
}
|
||||
})
|
||||
this.toUpdata()
|
||||
},
|
||||
// 地址
|
||||
toChoose() {
|
||||
|
||||
@@ -136,7 +136,9 @@
|
||||
store_id: uni.getStorageSync('store_id') || '11001',
|
||||
}
|
||||
}).then((res) => {
|
||||
if (res.data.errcode == 0) {
|
||||
const ok = res.data && (res.data.code === 0 || res.data.errcode === 0)
|
||||
if (ok) {
|
||||
uni.setStorageSync('delivery_method', 0)
|
||||
uni.showLoading({
|
||||
title: "加载中"
|
||||
});
|
||||
@@ -150,6 +152,12 @@
|
||||
});
|
||||
|
||||
}, 1300)
|
||||
} else {
|
||||
uni.showToast({
|
||||
title: (res.data && (res.data.message || res.data.msg)) || '更新失败',
|
||||
icon: 'none',
|
||||
duration: 1500
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user