mirror of
https://gitee.com/beijing_hongye_huicheng/lilishop-uniapp.git
synced 2026-11-13 04:18:53 +08:00
refactor(after-sales): 删除独立售后页面并整合至订单列表
- 删除 afterSales.vue 独立页面,将售后入口统一至 myOrder 页面 - 修改售后相关页面跳转路径为 /pages/order/myOrder?status=5 - 重构 applySuccess 页面,增加微信订阅消息授权与视觉优化 - 重构预存款明细页面,增加收支筛选与日志解析功能 - 新增 store 端 API 基础地址配置
This commit is contained in:
26
pages-sub/merchant/api/evaluation.js
Normal file
26
pages-sub/merchant/api/evaluation.js
Normal file
@@ -0,0 +1,26 @@
|
||||
import { storeHttp } from "../utils/storeRequest.js";
|
||||
|
||||
/**
|
||||
* 分页获取客户评价列表
|
||||
* @param {Object} params { grade, goodsName, replyStatus, pageNumber, pageSize }
|
||||
*/
|
||||
export function getStoreEvaluationList(params) {
|
||||
return storeHttp.request({
|
||||
url: "/member/evaluation",
|
||||
method: "GET",
|
||||
params,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 回复客户评价
|
||||
* @param {String} id 评价ID
|
||||
* @param {String} reply 回复文字
|
||||
* @param {String} replyImage 可选回复图片
|
||||
*/
|
||||
export function replyStoreEvaluation(id, reply, replyImage = "") {
|
||||
return storeHttp.request({
|
||||
url: `/member/evaluation/reply/${id}?reply=${encodeURIComponent(reply)}&replyImage=${encodeURIComponent(replyImage)}`,
|
||||
method: "PUT",
|
||||
});
|
||||
}
|
||||
70
pages-sub/merchant/api/goods.js
Normal file
70
pages-sub/merchant/api/goods.js
Normal file
@@ -0,0 +1,70 @@
|
||||
import { storeHttp } from "../utils/storeRequest.js";
|
||||
|
||||
/**
|
||||
* 获取商家商品列表
|
||||
* @param {Object} params { goodsName, marketEnable, authFlag, pageNumber, pageSize }
|
||||
*/
|
||||
export function getStoreGoodsList(params) {
|
||||
return storeHttp.request({
|
||||
url: "/goods/goods/list",
|
||||
method: "GET",
|
||||
params,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取商家商品详情
|
||||
* @param {String} id 商品ID
|
||||
*/
|
||||
export function getStoreGoodsDetail(id) {
|
||||
return storeHttp.request({
|
||||
url: `/goods/goods/get/${id}`,
|
||||
method: "GET",
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取商品关联的 SKU 列表
|
||||
* @param {String} goodsId 商品ID
|
||||
*/
|
||||
export function getStoreGoodsSkuList(goodsId) {
|
||||
return storeHttp.request({
|
||||
url: `/goods/goods/sku/${goodsId}/list`,
|
||||
method: "GET",
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 上架商品
|
||||
* @param {String|Array} goodsId
|
||||
*/
|
||||
export function upGoods(goodsId) {
|
||||
const ids = Array.isArray(goodsId) ? goodsId.join(",") : goodsId;
|
||||
return storeHttp.request({
|
||||
url: `/goods/goods/up?goodsId=${ids}`,
|
||||
method: "PUT",
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 下架商品
|
||||
* @param {String|Array} goodsId
|
||||
*/
|
||||
export function downGoods(goodsId) {
|
||||
const ids = Array.isArray(goodsId) ? goodsId.join(",") : goodsId;
|
||||
return storeHttp.request({
|
||||
url: `/goods/goods/under?goodsId=${ids}`,
|
||||
method: "PUT",
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取商品统计数量(出售中、已下架等)
|
||||
*/
|
||||
export function getStoreGoodsNumber(params) {
|
||||
return storeHttp.request({
|
||||
url: "/goods/goods/goodsNumber",
|
||||
method: "GET",
|
||||
params,
|
||||
});
|
||||
}
|
||||
104
pages-sub/merchant/api/order.js
Normal file
104
pages-sub/merchant/api/order.js
Normal file
@@ -0,0 +1,104 @@
|
||||
import { storeHttp } from "../utils/storeRequest.js";
|
||||
|
||||
/**
|
||||
* 商家订单列表
|
||||
* @param {Object} params { orderStatus, orderType, keywords, pageNumber, pageSize }
|
||||
*/
|
||||
export function getStoreOrderList(params) {
|
||||
return storeHttp.request({
|
||||
url: "/order/order",
|
||||
method: "GET",
|
||||
params,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 商家订单详情
|
||||
* @param {String} sn
|
||||
*/
|
||||
export function getStoreOrderDetail(sn) {
|
||||
return storeHttp.request({
|
||||
url: `/order/order/${sn}`,
|
||||
method: "GET",
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 自提 / 虚拟商品单码核销
|
||||
* @param {String} sn
|
||||
* @param {String} verificationCode
|
||||
*/
|
||||
export function storeOrderTake(sn, verificationCode) {
|
||||
return storeHttp.request({
|
||||
url: `/order/order/take/${sn}/${verificationCode}`,
|
||||
method: "PUT",
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 通用核销预检(按核销码查询)
|
||||
* @param {String} code
|
||||
*/
|
||||
export function previewStoreVerification(code) {
|
||||
return storeHttp.request({
|
||||
url: "/order/order/verification/preview",
|
||||
method: "GET",
|
||||
params: { code },
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 通用确认核销
|
||||
* @param {String} code
|
||||
*/
|
||||
export function confirmStoreVerification(code) {
|
||||
return storeHttp.request({
|
||||
url: "/order/order/verification/confirm",
|
||||
method: "POST",
|
||||
data: { code },
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 预约服务 — 根据核销码查询预约订单详情
|
||||
* @param {String} code
|
||||
*/
|
||||
export function getAppointmentOrderByCode(code) {
|
||||
return storeHttp.request({
|
||||
url: `/appointment/verification/order/${code}`,
|
||||
method: "GET",
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 预约服务 — 执行核销
|
||||
* @param {Object} params { orderSn, code, serviceStaffId }
|
||||
*/
|
||||
export function verifyAppointmentCode(params) {
|
||||
return storeHttp.request({
|
||||
url: "/appointment/verification/verify",
|
||||
method: "POST",
|
||||
data: params,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 预约服务 — 获取已启用的服务人员列表(供核销时指派/确认)
|
||||
*/
|
||||
export function getEnabledServiceStaff() {
|
||||
return storeHttp.request({
|
||||
url: "/appointment/service-staff/enabled",
|
||||
method: "GET",
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 预约服务 — 根据订单号获取预约单核销状态
|
||||
* @param {String} orderSn
|
||||
*/
|
||||
export function getAppointmentVerificationByOrderSn(orderSn) {
|
||||
return storeHttp.request({
|
||||
url: `/appointment/verification/order-by-sn/${orderSn}`,
|
||||
method: "GET",
|
||||
});
|
||||
}
|
||||
94
pages-sub/merchant/api/passport.js
Normal file
94
pages-sub/merchant/api/passport.js
Normal file
@@ -0,0 +1,94 @@
|
||||
import { storeHttp } from "../utils/storeRequest.js";
|
||||
|
||||
/**
|
||||
* 账号密码登录(支持店主与店员账号)
|
||||
* @param {Object} params { username, password }
|
||||
*/
|
||||
export function userLogin(params) {
|
||||
return storeHttp.request({
|
||||
url: "/passport/login/userLogin",
|
||||
method: "POST",
|
||||
params,
|
||||
header: {
|
||||
"content-type": "application/x-www-form-urlencoded",
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 短信验证码登录(支持店主与店员手机号)
|
||||
* @param {Object} params { mobile, code }
|
||||
*/
|
||||
export function smsLogin(params) {
|
||||
return storeHttp.request({
|
||||
url: "/passport/login/smsLogin",
|
||||
method: "POST",
|
||||
params,
|
||||
header: {
|
||||
"content-type": "application/x-www-form-urlencoded",
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送登录短信
|
||||
* @param {String} mobile
|
||||
* @param {String} verificationEnums (LOGIN)
|
||||
*/
|
||||
export function sendStoreSms(mobile, verificationEnums = "LOGIN") {
|
||||
return storeHttp.request({
|
||||
url: `/common/sms/${verificationEnums}/${mobile}`,
|
||||
method: "GET",
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取滑块验证码
|
||||
* @param {String} verificationEnums (LOGIN)
|
||||
*/
|
||||
export function getStoreSlider(verificationEnums = "LOGIN") {
|
||||
return storeHttp.request({
|
||||
url: `/common/slider/${verificationEnums}`,
|
||||
method: "GET",
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 登出
|
||||
*/
|
||||
export function storeLogout() {
|
||||
return storeHttp.request({
|
||||
url: "/passport/login/logout",
|
||||
method: "POST",
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取店铺基本配置与信息
|
||||
*/
|
||||
export function getStoreSettings() {
|
||||
return storeHttp.request({
|
||||
url: "/settings/storeSettings",
|
||||
method: "GET",
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前登录人员(店主 / 店员)个人信息
|
||||
*/
|
||||
export function getStoreUserInfo() {
|
||||
return storeHttp.request({
|
||||
url: "/member/user/info",
|
||||
method: "GET",
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前登录所属店铺详情
|
||||
*/
|
||||
export function getStoreDetail() {
|
||||
return storeHttp.request({
|
||||
url: "/member/user",
|
||||
method: "GET",
|
||||
});
|
||||
}
|
||||
650
pages-sub/merchant/pages/evaluation/list.vue
Normal file
650
pages-sub/merchant/pages/evaluation/list.vue
Normal file
@@ -0,0 +1,650 @@
|
||||
<template>
|
||||
<view class="merchant-evaluation-page">
|
||||
<!-- 顶部 Tab 过滤 -->
|
||||
<view class="sticky-header">
|
||||
<view class="tab-scroll-wrap">
|
||||
<view
|
||||
class="tab-item"
|
||||
v-for="item in tabList"
|
||||
:key="item.key"
|
||||
:class="{ active: currentTab === item.key }"
|
||||
@click="switchTab(item.key)"
|
||||
>
|
||||
<text class="tab-label">{{ item.label }}</text>
|
||||
<view class="indicator" v-if="currentTab === item.key"></view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 评价列表主体 -->
|
||||
<view class="eval-list-body">
|
||||
<view
|
||||
class="eval-card"
|
||||
v-for="item in evalList"
|
||||
:key="item.id"
|
||||
>
|
||||
<!-- 头部:买家信息与星级 -->
|
||||
<view class="eval-header">
|
||||
<view class="user-box">
|
||||
<image
|
||||
class="user-avatar"
|
||||
:src="item.memberProfile || '/static/tabbar/home.png'"
|
||||
mode="aspectFill"
|
||||
></image>
|
||||
<view class="user-meta">
|
||||
<text class="user-name">{{ maskName(item.memberName) }}</text>
|
||||
<text class="eval-time">{{ item.createTime || '--' }}</text>
|
||||
</view>
|
||||
</view>
|
||||
<!-- 评分 -->
|
||||
<view class="rating-stars">
|
||||
<u-icon
|
||||
v-for="star in 5"
|
||||
:key="star"
|
||||
name="star-fill"
|
||||
size="14"
|
||||
:color="star <= (item.descriptionScore || 5) ? '#f59e0b' : '#e5e7eb'"
|
||||
></u-icon>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 评价文字内容 -->
|
||||
<view class="eval-content">
|
||||
<text class="content-text">{{ item.content || '用户未填写文字评价' }}</text>
|
||||
</view>
|
||||
|
||||
<!-- 买家晒图 -->
|
||||
<view class="eval-images" v-if="getImages(item.images).length > 0">
|
||||
<image
|
||||
class="eval-pic"
|
||||
v-for="(img, idx) in getImages(item.images)"
|
||||
:key="idx"
|
||||
:src="img"
|
||||
mode="aspectFill"
|
||||
@click="previewImages(getImages(item.images), idx)"
|
||||
></image>
|
||||
</view>
|
||||
|
||||
<!-- 关联商品简要信息 -->
|
||||
<view class="goods-snippet" v-if="item.goodsName">
|
||||
<image
|
||||
class="goods-snippet-img"
|
||||
:src="item.goodsImage || '/static/tabbar/home.png'"
|
||||
mode="aspectFill"
|
||||
></image>
|
||||
<text class="goods-snippet-title">{{ item.goodsName }}</text>
|
||||
</view>
|
||||
|
||||
<!-- 商家已回复内容 -->
|
||||
<view class="seller-reply-box" v-if="item.reply">
|
||||
<view class="reply-title-row">
|
||||
<text class="reply-tag">掌柜回复:</text>
|
||||
<text class="reply-time" v-if="item.replyTime">{{ item.replyTime }}</text>
|
||||
</view>
|
||||
<text class="reply-text">{{ item.reply }}</text>
|
||||
</view>
|
||||
|
||||
<!-- 回复动作条 -->
|
||||
<view class="eval-footer">
|
||||
<view
|
||||
class="reply-trigger-btn"
|
||||
@click="openReplyModal(item)"
|
||||
>
|
||||
<u-icon name="chat" size="14" :color="item.reply ? '#6b7280' : '#ffffff'"></u-icon>
|
||||
<text :class="{ 'is-replied': item.reply }">
|
||||
{{ item.reply ? '修改回复' : '立即回复' }}
|
||||
</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 空状态 -->
|
||||
<view class="empty-state" v-if="!loading && evalList.length === 0">
|
||||
<u-icon name="chat" size="56" color="#d1d5db"></u-icon>
|
||||
<text class="empty-text">暂无相关评价数据</text>
|
||||
</view>
|
||||
|
||||
<!-- 加载提示 -->
|
||||
<view class="loading-more" v-if="loading">
|
||||
<text>正在加载评价数据...</text>
|
||||
</view>
|
||||
<view class="no-more" v-else-if="finished && evalList.length > 0">
|
||||
<text>没有更多了</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 回复弹窗 -->
|
||||
<view class="reply-modal-mask" v-if="showReplyModal" @click.self="closeReplyModal">
|
||||
<view class="reply-modal-card">
|
||||
<view class="modal-header">
|
||||
<text class="modal-title">回复买家评价</text>
|
||||
<view class="close-btn" @click="closeReplyModal">
|
||||
<u-icon name="close" size="18" color="#9ca3af"></u-icon>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="modal-body">
|
||||
<textarea
|
||||
class="reply-textarea"
|
||||
v-model="replyText"
|
||||
placeholder="请输入真诚的掌柜回复内容,让买家感受到热情与专业..."
|
||||
placeholder-class="placeholder"
|
||||
maxlength="300"
|
||||
></textarea>
|
||||
<view class="char-count">
|
||||
<text>{{ replyText.length }}/300</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="modal-footer">
|
||||
<view class="modal-btn cancel" @click="closeReplyModal">取消</view>
|
||||
<view
|
||||
class="modal-btn confirm"
|
||||
:class="{ loading: submittingReply }"
|
||||
@click="submitReply"
|
||||
>
|
||||
{{ submittingReply ? '提交中...' : '提交回复' }}
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref } from 'vue'
|
||||
import { onLoad, onPullDownRefresh, onReachBottom } from '@dcloudio/uni-app'
|
||||
import { getStoreEvaluationList, replyStoreEvaluation } from '../../api/evaluation.js'
|
||||
|
||||
const currentTab = ref('ALL')
|
||||
const loading = ref(false)
|
||||
const finished = ref(false)
|
||||
const pageNumber = ref(1)
|
||||
const pageSize = ref(10)
|
||||
const evalList = ref([])
|
||||
|
||||
const showReplyModal = ref(false)
|
||||
const currentEval = ref(null)
|
||||
const replyText = ref('')
|
||||
const submittingReply = ref(false)
|
||||
|
||||
const tabList = [
|
||||
{ key: 'ALL', label: '全部' },
|
||||
{ key: 'GOOD', label: '好评' },
|
||||
{ key: 'POOR', label: '中差评' },
|
||||
{ key: 'UNREPLIED', label: '待回复' },
|
||||
]
|
||||
|
||||
onLoad(() => {
|
||||
fetchEvaluations(true)
|
||||
})
|
||||
|
||||
onPullDownRefresh(async () => {
|
||||
await fetchEvaluations(true)
|
||||
uni.stopPullDownRefresh()
|
||||
})
|
||||
|
||||
onReachBottom(() => {
|
||||
if (!finished.value && !loading.value) {
|
||||
pageNumber.value++
|
||||
fetchEvaluations(false)
|
||||
}
|
||||
})
|
||||
|
||||
const fetchEvaluations = async (reset = false) => {
|
||||
if (reset) {
|
||||
pageNumber.value = 1
|
||||
evalList.value = []
|
||||
finished.value = false
|
||||
}
|
||||
|
||||
loading.value = true
|
||||
const params = {
|
||||
pageNumber: pageNumber.value,
|
||||
pageSize: pageSize.value,
|
||||
}
|
||||
|
||||
if (currentTab.value === 'GOOD') {
|
||||
params.grade = 'GOOD'
|
||||
} else if (currentTab.value === 'POOR') {
|
||||
params.grade = 'POOR'
|
||||
} else if (currentTab.value === 'UNREPLIED') {
|
||||
params.replyStatus = false
|
||||
}
|
||||
|
||||
try {
|
||||
const res = await getStoreEvaluationList(params)
|
||||
loading.value = false
|
||||
if (res.data && res.data.success && res.data.result) {
|
||||
const records = res.data.result.records || []
|
||||
if (reset) {
|
||||
evalList.value = records
|
||||
} else {
|
||||
evalList.value = [...evalList.value, ...records]
|
||||
}
|
||||
if (records.length < pageSize.value) {
|
||||
finished.value = true
|
||||
}
|
||||
} else {
|
||||
finished.value = true
|
||||
}
|
||||
} catch (e) {
|
||||
loading.value = false
|
||||
finished.value = true
|
||||
}
|
||||
}
|
||||
|
||||
const switchTab = (tabKey) => {
|
||||
if (currentTab.value === tabKey) return
|
||||
currentTab.value = tabKey
|
||||
fetchEvaluations(true)
|
||||
}
|
||||
|
||||
const maskName = (name) => {
|
||||
if (!name) return '匿名买家'
|
||||
if (name.length <= 2) return name[0] + '*'
|
||||
return name[0] + '***' + name[name.length - 1]
|
||||
}
|
||||
|
||||
const getImages = (imgs) => {
|
||||
if (!imgs) return []
|
||||
if (Array.isArray(imgs)) return imgs
|
||||
if (typeof imgs === 'string') {
|
||||
try {
|
||||
const parsed = JSON.parse(imgs)
|
||||
if (Array.isArray(parsed)) return parsed
|
||||
} catch (e) {
|
||||
return imgs.split(',').filter(Boolean)
|
||||
}
|
||||
}
|
||||
return []
|
||||
}
|
||||
|
||||
const previewImages = (urls, current) => {
|
||||
uni.previewImage({
|
||||
urls,
|
||||
current,
|
||||
})
|
||||
}
|
||||
|
||||
// 打开回复弹窗
|
||||
const openReplyModal = (item) => {
|
||||
currentEval.value = item
|
||||
replyText.value = item.reply || ''
|
||||
showReplyModal.value = true
|
||||
}
|
||||
|
||||
const closeReplyModal = () => {
|
||||
showReplyModal.value = false
|
||||
currentEval.value = null
|
||||
replyText.value = ''
|
||||
}
|
||||
|
||||
// 提交回复
|
||||
const submitReply = async () => {
|
||||
if (!replyText.value.trim()) {
|
||||
uni.showToast({ title: '请输入回复内容', icon: 'none' })
|
||||
return
|
||||
}
|
||||
if (submittingReply.value) return
|
||||
|
||||
submittingReply.value = true
|
||||
uni.showLoading({ title: '提交中...' })
|
||||
|
||||
try {
|
||||
const res = await replyStoreEvaluation(currentEval.value.id, replyText.value.trim())
|
||||
uni.hideLoading()
|
||||
submittingReply.value = false
|
||||
|
||||
if (res.data && res.data.success) {
|
||||
uni.showToast({ title: '回复成功', icon: 'success' })
|
||||
closeReplyModal()
|
||||
fetchEvaluations(true)
|
||||
} else {
|
||||
uni.showToast({
|
||||
title: res.data?.message || '回复失败',
|
||||
icon: 'none',
|
||||
})
|
||||
}
|
||||
} catch (e) {
|
||||
uni.hideLoading()
|
||||
submittingReply.value = false
|
||||
uni.showToast({ title: '网络异常,请重试', icon: 'none' })
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.merchant-evaluation-page {
|
||||
min-height: 100vh;
|
||||
background-color: #f3f4f6;
|
||||
padding-bottom: 40rpx;
|
||||
}
|
||||
|
||||
.sticky-header {
|
||||
position: sticky;
|
||||
top: 0;
|
||||
z-index: 100;
|
||||
background: #ffffff;
|
||||
box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.04);
|
||||
|
||||
.tab-scroll-wrap {
|
||||
display: flex;
|
||||
border-bottom: 1rpx solid #f0f0f0;
|
||||
padding: 0 16rpx;
|
||||
|
||||
.tab-item {
|
||||
flex: 1;
|
||||
text-align: center;
|
||||
padding: 24rpx 0;
|
||||
position: relative;
|
||||
|
||||
.tab-label {
|
||||
font-size: 28rpx;
|
||||
color: #6b7280;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
&.active {
|
||||
.tab-label {
|
||||
color: #111827;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.indicator {
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
width: 40rpx;
|
||||
height: 6rpx;
|
||||
background: #111827;
|
||||
border-radius: 3rpx;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.eval-list-body {
|
||||
padding: 24rpx 28rpx;
|
||||
|
||||
.eval-card {
|
||||
background: #ffffff;
|
||||
border-radius: 20rpx;
|
||||
padding: 28rpx;
|
||||
margin-bottom: 24rpx;
|
||||
box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.03);
|
||||
|
||||
.eval-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
|
||||
.user-box {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
|
||||
.user-avatar {
|
||||
width: 72rpx;
|
||||
height: 72rpx;
|
||||
border-radius: 36rpx;
|
||||
background: #f3f4f6;
|
||||
}
|
||||
|
||||
.user-meta {
|
||||
margin-left: 16rpx;
|
||||
|
||||
.user-name {
|
||||
font-size: 26rpx;
|
||||
font-weight: 600;
|
||||
color: #111827;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.eval-time {
|
||||
font-size: 20rpx;
|
||||
color: #9ca3af;
|
||||
margin-top: 4rpx;
|
||||
display: block;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.rating-stars {
|
||||
display: flex;
|
||||
gap: 4rpx;
|
||||
}
|
||||
}
|
||||
|
||||
.eval-content {
|
||||
margin-top: 20rpx;
|
||||
|
||||
.content-text {
|
||||
font-size: 28rpx;
|
||||
color: #1f2937;
|
||||
line-height: 1.5;
|
||||
word-break: break-all;
|
||||
}
|
||||
}
|
||||
|
||||
.eval-images {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 16rpx;
|
||||
margin-top: 16rpx;
|
||||
|
||||
.eval-pic {
|
||||
width: 150rpx;
|
||||
height: 150rpx;
|
||||
border-radius: 12rpx;
|
||||
background: #f3f4f6;
|
||||
}
|
||||
}
|
||||
|
||||
.goods-snippet {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
background: #f9fafb;
|
||||
border-radius: 12rpx;
|
||||
padding: 14rpx;
|
||||
margin-top: 20rpx;
|
||||
|
||||
.goods-snippet-img {
|
||||
width: 64rpx;
|
||||
height: 64rpx;
|
||||
border-radius: 8rpx;
|
||||
background: #e5e7eb;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.goods-snippet-title {
|
||||
font-size: 22rpx;
|
||||
color: #4b5563;
|
||||
margin-left: 14rpx;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
}
|
||||
|
||||
.seller-reply-box {
|
||||
margin-top: 20rpx;
|
||||
background: #f3f4f6;
|
||||
border-left: 6rpx solid #111827;
|
||||
border-radius: 8rpx;
|
||||
padding: 16rpx 20rpx;
|
||||
|
||||
.reply-title-row {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 8rpx;
|
||||
|
||||
.reply-tag {
|
||||
font-size: 24rpx;
|
||||
font-weight: 700;
|
||||
color: #111827;
|
||||
}
|
||||
|
||||
.reply-time {
|
||||
font-size: 20rpx;
|
||||
color: #9ca3af;
|
||||
}
|
||||
}
|
||||
|
||||
.reply-text {
|
||||
font-size: 26rpx;
|
||||
color: #4b5563;
|
||||
line-height: 1.4;
|
||||
}
|
||||
}
|
||||
|
||||
.eval-footer {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
margin-top: 24rpx;
|
||||
padding-top: 20rpx;
|
||||
border-top: 1rpx solid #f9fafb;
|
||||
|
||||
.reply-trigger-btn {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8rpx;
|
||||
padding: 10rpx 28rpx;
|
||||
border-radius: 12rpx;
|
||||
background: #111827;
|
||||
color: #ffffff;
|
||||
font-size: 24rpx;
|
||||
font-weight: 600;
|
||||
|
||||
.is-replied {
|
||||
color: #4b5563;
|
||||
}
|
||||
|
||||
&:has(.is-replied) {
|
||||
background: #f3f4f6;
|
||||
border: 1rpx solid #e5e7eb;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.empty-state {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
padding: 120rpx 0;
|
||||
|
||||
.empty-text {
|
||||
font-size: 26rpx;
|
||||
color: #9ca3af;
|
||||
margin-top: 20rpx;
|
||||
}
|
||||
}
|
||||
|
||||
.loading-more,
|
||||
.no-more {
|
||||
text-align: center;
|
||||
padding: 24rpx 0;
|
||||
font-size: 22rpx;
|
||||
color: #9ca3af;
|
||||
}
|
||||
}
|
||||
|
||||
/* 回复弹窗 */
|
||||
.reply-modal-mask {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background: rgba(0, 0, 0, 0.6);
|
||||
z-index: 999;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 40rpx;
|
||||
|
||||
.reply-modal-card {
|
||||
background: #ffffff;
|
||||
width: 100%;
|
||||
max-width: 640rpx;
|
||||
border-radius: 28rpx;
|
||||
padding: 36rpx;
|
||||
|
||||
.modal-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 24rpx;
|
||||
|
||||
.modal-title {
|
||||
font-size: 32rpx;
|
||||
font-weight: 700;
|
||||
color: #111827;
|
||||
}
|
||||
}
|
||||
|
||||
.modal-body {
|
||||
position: relative;
|
||||
|
||||
.reply-textarea {
|
||||
width: 100%;
|
||||
height: 240rpx;
|
||||
background: #f9fafb;
|
||||
border: 1rpx solid #e5e7eb;
|
||||
border-radius: 16rpx;
|
||||
padding: 20rpx;
|
||||
font-size: 28rpx;
|
||||
color: #111827;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.placeholder {
|
||||
color: #9ca3af;
|
||||
font-size: 26rpx;
|
||||
}
|
||||
|
||||
.char-count {
|
||||
position: absolute;
|
||||
right: 16rpx;
|
||||
bottom: 16rpx;
|
||||
font-size: 20rpx;
|
||||
color: #9ca3af;
|
||||
}
|
||||
}
|
||||
|
||||
.modal-footer {
|
||||
display: flex;
|
||||
gap: 20rpx;
|
||||
margin-top: 28rpx;
|
||||
|
||||
.modal-btn {
|
||||
flex: 1;
|
||||
height: 84rpx;
|
||||
border-radius: 16rpx;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: 30rpx;
|
||||
font-weight: 600;
|
||||
|
||||
&.cancel {
|
||||
background: #f3f4f6;
|
||||
color: #4b5563;
|
||||
}
|
||||
|
||||
&.confirm {
|
||||
background: #111827;
|
||||
color: #ffffff;
|
||||
|
||||
&.loading {
|
||||
opacity: 0.7;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
737
pages-sub/merchant/pages/goods/detail.vue
Normal file
737
pages-sub/merchant/pages/goods/detail.vue
Normal file
@@ -0,0 +1,737 @@
|
||||
<template>
|
||||
<view class="merchant-goods-detail" v-if="goodsDetail">
|
||||
<!-- 顶部主图轮播 -->
|
||||
<view class="gallery-wrapper">
|
||||
<swiper
|
||||
class="gallery-swiper"
|
||||
:indicator-dots="false"
|
||||
:autoplay="false"
|
||||
@change="onSwiperChange"
|
||||
>
|
||||
<swiper-item
|
||||
v-for="(img, idx) in galleryImages"
|
||||
:key="idx"
|
||||
@click="previewGallery(idx)"
|
||||
>
|
||||
<image class="swiper-img" :src="img" mode="aspectFill"></image>
|
||||
</swiper-item>
|
||||
</swiper>
|
||||
<view class="swiper-indicator" v-if="galleryImages.length > 1">
|
||||
<text>{{ currentSwiperIndex + 1 }} / {{ galleryImages.length }}</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 核心信息卡片 -->
|
||||
<view class="info-card core-card">
|
||||
<view class="price-row">
|
||||
<view class="main-price">
|
||||
<text class="symbol">¥</text>
|
||||
<text class="num">{{ goodsDetail.price || '0.00' }}</text>
|
||||
</view>
|
||||
<view class="sub-price" v-if="goodsDetail.cost">
|
||||
<text>成本价 ¥{{ goodsDetail.cost }}</text>
|
||||
</view>
|
||||
<view class="status-tags">
|
||||
<view
|
||||
class="badge market"
|
||||
:class="goodsDetail.marketEnable === 'UPPER' ? 'on-sale' : 'off-sale'"
|
||||
>
|
||||
{{ goodsDetail.marketEnable === 'UPPER' ? '出售中' : '已下架' }}
|
||||
</view>
|
||||
<view
|
||||
class="badge auth"
|
||||
:class="goodsDetail.authFlag === 'PASS' ? 'auth-pass' : 'auth-pending'"
|
||||
>
|
||||
{{ getAuthText(goodsDetail.authFlag) }}
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="title-row">
|
||||
<text class="goods-title">{{ goodsDetail.goodsName }}</text>
|
||||
</view>
|
||||
|
||||
<view class="meta-stats-grid">
|
||||
<view class="stat-col">
|
||||
<text class="stat-num">{{ goodsDetail.quantity ?? 0 }}</text>
|
||||
<text class="stat-label">总库存</text>
|
||||
</view>
|
||||
<view class="stat-sep"></view>
|
||||
<view class="stat-col">
|
||||
<text class="stat-num">{{ goodsDetail.buyCount ?? 0 }}</text>
|
||||
<text class="stat-label">累计销量</text>
|
||||
</view>
|
||||
<view class="stat-sep"></view>
|
||||
<view class="stat-col">
|
||||
<text class="stat-num">{{ goodsDetail.sn || '--' }}</text>
|
||||
<text class="stat-label">商品货号</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 规格与多 SKU 列表 -->
|
||||
<view class="info-card" v-if="skuList && skuList.length > 0">
|
||||
<view class="card-head">
|
||||
<view class="head-left">
|
||||
<text class="card-title">规格与 SKU 明细</text>
|
||||
<text class="sku-count-pill">共 {{ skuList.length }} 种规格</text>
|
||||
</view>
|
||||
</view>
|
||||
<view class="sku-list">
|
||||
<view
|
||||
class="sku-item"
|
||||
v-for="(sku, index) in skuList"
|
||||
:key="sku.id || sku.sn || index"
|
||||
>
|
||||
<image
|
||||
class="sku-thumb"
|
||||
:src="getSkuThumb(sku)"
|
||||
mode="aspectFill"
|
||||
></image>
|
||||
<view class="sku-info">
|
||||
<text class="sku-spec">{{ formatSpecs(sku, index) }}</text>
|
||||
<text class="sku-sn" v-if="sku.sn">SKU编码:{{ sku.sn }}</text>
|
||||
<view class="sku-nums">
|
||||
<text class="sku-price">售价:<text class="val">¥{{ sku.price || '0.00' }}</text></text>
|
||||
<text class="sku-stock">库存:<text class="val">{{ sku.quantity ?? sku.stock ?? sku.enableQuantity ?? 0 }}</text></text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 基本属性卡片(优化分类展示) -->
|
||||
<view class="info-card">
|
||||
<view class="card-head">
|
||||
<text class="card-title">基本属性</text>
|
||||
</view>
|
||||
<view class="prop-row" v-if="goodsDetail.categoryName">
|
||||
<text class="prop-label">所属分类</text>
|
||||
<text class="prop-val cat-val">{{ formatCategoryName(goodsDetail.categoryName) }}</text>
|
||||
</view>
|
||||
<view class="prop-row" v-if="goodsDetail.brandName">
|
||||
<text class="prop-label">商品品牌</text>
|
||||
<text class="prop-val">{{ goodsDetail.brandName }}</text>
|
||||
</view>
|
||||
<view class="prop-row" v-if="goodsDetail.goodsUnit">
|
||||
<text class="prop-label">计量单位</text>
|
||||
<text class="prop-val">{{ goodsDetail.goodsUnit }}</text>
|
||||
</view>
|
||||
<view class="prop-row" v-if="goodsDetail.releaseTime">
|
||||
<text class="prop-label">发布时间</text>
|
||||
<text class="prop-val">{{ goodsDetail.releaseTime }}</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 图文详情 -->
|
||||
<view class="info-card intro-card" v-if="goodsDetail.intro || goodsDetail.mobileIntro">
|
||||
<view class="card-head">
|
||||
<text class="card-title">商品图文详情</text>
|
||||
</view>
|
||||
<view class="intro-html">
|
||||
<rich-text :nodes="formatRichText(goodsDetail.mobileIntro || goodsDetail.intro)"></rich-text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 底部固定悬浮操作栏(带安全底间距,防止遮挡内容) -->
|
||||
<view class="bottom-action-bar">
|
||||
<view class="preview-btn" @click="previewInMall">
|
||||
<u-icon name="eye" size="20" color="#4b5563"></u-icon>
|
||||
<text>买家预览</text>
|
||||
</view>
|
||||
<view
|
||||
class="market-action-btn off"
|
||||
v-if="goodsDetail.marketEnable === 'UPPER'"
|
||||
@click="handleToggleMarket('DOWN')"
|
||||
>
|
||||
<text>下架商品</text>
|
||||
</view>
|
||||
<view
|
||||
class="market-action-btn on"
|
||||
v-else
|
||||
@click="handleToggleMarket('UPPER')"
|
||||
>
|
||||
<text>立即上架</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, computed } from 'vue'
|
||||
import { onLoad } from '@dcloudio/uni-app'
|
||||
import { getStoreGoodsDetail, getStoreGoodsSkuList, upGoods, downGoods } from '../../api/goods.js'
|
||||
import { parseGoodsImageUrl } from '@/utils/filters.js'
|
||||
|
||||
const getSkuThumb = (sku: any) => {
|
||||
const img = sku.thumbnail || sku.original
|
||||
if (img) {
|
||||
const parsed = parseGoodsImageUrl(img)
|
||||
if (parsed) return parsed
|
||||
}
|
||||
const rawSpec = sku.simpleSpecs || sku.specs
|
||||
if (rawSpec && typeof rawSpec === 'string') {
|
||||
const match = rawSpec.match(/https?:\/\/[^\s"'\\}]+\.(jpeg|jpg|png|webp|gif)/i)
|
||||
if (match) return match[0]
|
||||
}
|
||||
return galleryImages.value[0] || '/static/tabbar/home.png'
|
||||
}
|
||||
|
||||
|
||||
const goodsId = ref('')
|
||||
const goodsDetail = ref<any>(null)
|
||||
const skuList = ref<any[]>([])
|
||||
const currentSwiperIndex = ref(0)
|
||||
|
||||
onLoad((options: any) => {
|
||||
if (options?.id) {
|
||||
goodsId.value = options.id
|
||||
fetchGoodsDetail()
|
||||
}
|
||||
})
|
||||
|
||||
const galleryImages = computed(() => {
|
||||
if (!goodsDetail.value) return []
|
||||
if (Array.isArray(goodsDetail.value.goodsGalleryList) && goodsDetail.value.goodsGalleryList.length > 0) {
|
||||
return goodsDetail.value.goodsGalleryList
|
||||
}
|
||||
const defaultImg = goodsDetail.value.original || goodsDetail.value.thumbnail
|
||||
return defaultImg ? [defaultImg] : ['/static/tabbar/home.png']
|
||||
})
|
||||
|
||||
const fetchGoodsDetail = async () => {
|
||||
uni.showLoading({ title: '加载中...' })
|
||||
try {
|
||||
const res: any = await getStoreGoodsDetail(goodsId.value)
|
||||
uni.hideLoading()
|
||||
if (res?.data && res.data.success && res.data.result) {
|
||||
goodsDetail.value = res.data.result
|
||||
skuList.value = res.data.result.skuList || []
|
||||
if (skuList.value.length === 0) {
|
||||
fetchSkuList()
|
||||
}
|
||||
} else {
|
||||
uni.showToast({ title: '获取商品详情失败', icon: 'none' })
|
||||
}
|
||||
} catch (e) {
|
||||
uni.hideLoading()
|
||||
uni.showToast({ title: '网络连接异常', icon: 'none' })
|
||||
}
|
||||
}
|
||||
|
||||
const fetchSkuList = async () => {
|
||||
try {
|
||||
const skuRes: any = await getStoreGoodsSkuList(goodsId.value)
|
||||
if (skuRes?.data && skuRes.data.success && Array.isArray(skuRes.data.result)) {
|
||||
skuList.value = skuRes.data.result
|
||||
}
|
||||
} catch (e) {}
|
||||
}
|
||||
|
||||
const onSwiperChange = (e: any) => {
|
||||
currentSwiperIndex.value = e.detail.current
|
||||
}
|
||||
|
||||
const previewGallery = (current: number) => {
|
||||
uni.previewImage({
|
||||
urls: galleryImages.value,
|
||||
current,
|
||||
})
|
||||
}
|
||||
|
||||
// 智能清洗并优雅格式化规格文本(过滤 images 等系统 JSON 冗余)
|
||||
const formatSpecs = (sku: any, index: number) => {
|
||||
// 1. 优先使用规范的 specList 数组
|
||||
if (sku.specList && Array.isArray(sku.specList) && sku.specList.length > 0) {
|
||||
const listStr = sku.specList
|
||||
.map((s: any) => {
|
||||
if (s.specName && s.specValue) return `${s.specName}: ${s.specValue}`
|
||||
return s.specValue || s.specName
|
||||
})
|
||||
.filter(Boolean)
|
||||
.join(' / ')
|
||||
if (listStr) return listStr
|
||||
}
|
||||
|
||||
// 2. 深度清洗 simpleSpecs 或 specs 中的复杂复合 JSON
|
||||
const rawSpec = sku.simpleSpecs || sku.specs
|
||||
if (rawSpec && typeof rawSpec === 'string') {
|
||||
const trimmed = rawSpec.trim()
|
||||
if (trimmed.startsWith('{') || trimmed.startsWith('[')) {
|
||||
try {
|
||||
const obj = JSON.parse(trimmed)
|
||||
const ignoreKeys = ['images', 'code', 'message', 'result', 'success', 'showProgress', 'url', 'status', 'specImage', 'specType']
|
||||
const pairs: string[] = []
|
||||
for (const [k, v] of Object.entries(obj)) {
|
||||
if (!ignoreKeys.includes(k) && typeof v === 'string' && !v.startsWith('http') && v.length < 50) {
|
||||
pairs.push(`${k}: ${v}`)
|
||||
}
|
||||
}
|
||||
if (pairs.length > 0) return pairs.join(' / ')
|
||||
} catch (e) {}
|
||||
|
||||
// JSON 解析失败时正则提取真实的规格键值对
|
||||
const matches = [...trimmed.matchAll(/"([^"]{1,20})"\s*:\s*"([^"]{1,30})"/g)]
|
||||
const ignoreKeys = ['code', 'message', 'success', 'url', 'result', 'showProgress', 'status', 'name']
|
||||
const pairs: string[] = []
|
||||
for (const m of matches) {
|
||||
const k = m[1]
|
||||
const v = m[2]
|
||||
if (!ignoreKeys.includes(k) && !v.startsWith('http')) {
|
||||
pairs.push(`${k}: ${v}`)
|
||||
}
|
||||
}
|
||||
if (pairs.length > 0) return pairs.join(' / ')
|
||||
} else {
|
||||
// 纯文本规格
|
||||
return trimmed
|
||||
}
|
||||
}
|
||||
|
||||
// 3. 提取不同于 SPU 主标题的商品名称差异
|
||||
if (sku.goodsName && sku.goodsName !== goodsDetail.value?.goodsName) {
|
||||
return sku.goodsName
|
||||
}
|
||||
|
||||
// 4. 最终兜底
|
||||
return skuList.value.length > 1 ? `规格 ${index + 1}` : '统一规格'
|
||||
}
|
||||
|
||||
// 格式化分类展示:将原始 JSON 数组 [ "数码办公", "手机通讯", "手机" ] 转为层级面包屑 "数码办公 > 手机通讯 > 手机"
|
||||
const formatCategoryName = (cat: any) => {
|
||||
if (!cat) return '--'
|
||||
if (Array.isArray(cat)) {
|
||||
return cat.filter(Boolean).join(' > ')
|
||||
}
|
||||
if (typeof cat === 'string') {
|
||||
try {
|
||||
const parsed = JSON.parse(cat)
|
||||
if (Array.isArray(parsed)) {
|
||||
return parsed.filter(Boolean).join(' > ')
|
||||
}
|
||||
} catch (e) {}
|
||||
// 处理带引号或逗号的非标准字符串
|
||||
return cat.replace(/[\[\]"']/g, '').split(',').map((s: string) => s.trim()).filter(Boolean).join(' > ')
|
||||
}
|
||||
return String(cat)
|
||||
}
|
||||
|
||||
const getAuthText = (flag: string) => {
|
||||
const map: Record<string, string> = {
|
||||
PASS: '审核通过',
|
||||
AUDIT: '待审核',
|
||||
REFUSE: '审核驳回',
|
||||
}
|
||||
return map[flag] || flag || '已通过'
|
||||
}
|
||||
|
||||
const formatRichText = (html: string) => {
|
||||
if (!html) return ''
|
||||
return html
|
||||
.replace(/<img[^>]*>/gi, (match) => {
|
||||
return match
|
||||
.replace(/style="[^"]*"/gi, '')
|
||||
.replace(/width="[^"]*"/gi, '')
|
||||
.replace(/height="[^"]*"/gi, '')
|
||||
})
|
||||
.replace(/\<img/gi, '<img style="max-width:100%;height:auto;display:block;border-radius:12rpx;margin:16rpx 0;"')
|
||||
}
|
||||
|
||||
// 上下架切换
|
||||
const handleToggleMarket = (targetStatus: string) => {
|
||||
const isUp = targetStatus === 'UPPER'
|
||||
const actionText = isUp ? '上架' : '下架'
|
||||
|
||||
uni.showModal({
|
||||
title: `${actionText}商品`,
|
||||
content: `确定要${actionText}当前商品?`,
|
||||
success: async (res) => {
|
||||
if (res.confirm) {
|
||||
uni.showLoading({ title: `正在${actionText}...` })
|
||||
try {
|
||||
const apiCall = isUp ? upGoods(goodsId.value) : downGoods(goodsId.value)
|
||||
const resp: any = await apiCall
|
||||
uni.hideLoading()
|
||||
if (resp?.data && resp.data.success) {
|
||||
uni.showToast({ title: `${actionText}成功`, icon: 'success' })
|
||||
fetchGoodsDetail()
|
||||
} else {
|
||||
uni.showToast({
|
||||
title: resp?.data?.message || `${actionText}失败`,
|
||||
icon: 'none',
|
||||
})
|
||||
}
|
||||
} catch (e) {
|
||||
uni.hideLoading()
|
||||
uni.showToast({ title: '网络异常,请稍后重试', icon: 'none' })
|
||||
}
|
||||
}
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
// 前往买家端预览
|
||||
const previewInMall = () => {
|
||||
uni.navigateTo({
|
||||
url: `/pages/product/goods?id=${goodsId.value}`,
|
||||
})
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.merchant-goods-detail {
|
||||
min-height: 100vh;
|
||||
background-color: #f4f5f7;
|
||||
/* 预留出底部固定操作栏的高以及全面屏安全区,彻底解决内容被底部遮挡 */
|
||||
padding-bottom: calc(160rpx + env(safe-area-inset-bottom));
|
||||
}
|
||||
|
||||
.gallery-wrapper {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
height: 680rpx;
|
||||
background: #ffffff;
|
||||
|
||||
.gallery-swiper {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
|
||||
.swiper-img {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
.swiper-indicator {
|
||||
position: absolute;
|
||||
right: 28rpx;
|
||||
bottom: 44rpx;
|
||||
background: rgba(0, 0, 0, 0.55);
|
||||
color: #ffffff;
|
||||
font-size: 22rpx;
|
||||
font-weight: 500;
|
||||
padding: 6rpx 20rpx;
|
||||
border-radius: 20rpx;
|
||||
backdrop-filter: blur(4px);
|
||||
}
|
||||
}
|
||||
|
||||
.info-card {
|
||||
margin: 20rpx 28rpx;
|
||||
background: #ffffff;
|
||||
border-radius: 24rpx;
|
||||
padding: 30rpx;
|
||||
box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.03);
|
||||
|
||||
.card-head {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 24rpx;
|
||||
padding-bottom: 16rpx;
|
||||
border-bottom: 1rpx solid #f9fafb;
|
||||
|
||||
.head-left {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 16rpx;
|
||||
}
|
||||
|
||||
.card-title {
|
||||
font-size: 30rpx;
|
||||
font-weight: 700;
|
||||
color: #111827;
|
||||
}
|
||||
|
||||
.sku-count-pill {
|
||||
font-size: 22rpx;
|
||||
color: #6b7280;
|
||||
background: #f3f4f6;
|
||||
padding: 4rpx 14rpx;
|
||||
border-radius: 12rpx;
|
||||
}
|
||||
}
|
||||
|
||||
&.core-card {
|
||||
margin-top: -30rpx;
|
||||
position: relative;
|
||||
z-index: 10;
|
||||
|
||||
.price-row {
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
justify-content: space-between;
|
||||
|
||||
.main-price {
|
||||
color: #ef4444;
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
|
||||
.symbol {
|
||||
font-size: 28rpx;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.num {
|
||||
font-size: 48rpx;
|
||||
font-weight: 700;
|
||||
margin-left: 4rpx;
|
||||
}
|
||||
}
|
||||
|
||||
.sub-price {
|
||||
font-size: 24rpx;
|
||||
color: #9ca3af;
|
||||
margin-left: 16rpx;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.status-tags {
|
||||
display: flex;
|
||||
gap: 12rpx;
|
||||
|
||||
.badge {
|
||||
font-size: 22rpx;
|
||||
padding: 6rpx 16rpx;
|
||||
border-radius: 10rpx;
|
||||
font-weight: 600;
|
||||
|
||||
&.on-sale {
|
||||
background: #ecfdf5;
|
||||
color: #059669;
|
||||
}
|
||||
|
||||
&.off-sale {
|
||||
background: #f3f4f6;
|
||||
color: #9ca3af;
|
||||
}
|
||||
|
||||
&.auth-pass {
|
||||
background: #eff6ff;
|
||||
color: #2563eb;
|
||||
}
|
||||
|
||||
&.auth-pending {
|
||||
background: #fffbeb;
|
||||
color: #d97706;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.title-row {
|
||||
margin-top: 20rpx;
|
||||
|
||||
.goods-title {
|
||||
font-size: 32rpx;
|
||||
font-weight: 700;
|
||||
color: #111827;
|
||||
line-height: 1.45;
|
||||
}
|
||||
}
|
||||
|
||||
.meta-stats-grid {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
background: #f9fafb;
|
||||
border-radius: 16rpx;
|
||||
padding: 22rpx 0;
|
||||
margin-top: 26rpx;
|
||||
|
||||
.stat-col {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
text-align: center;
|
||||
|
||||
.stat-num {
|
||||
font-size: 28rpx;
|
||||
font-weight: 700;
|
||||
color: #111827;
|
||||
}
|
||||
|
||||
.stat-label {
|
||||
font-size: 22rpx;
|
||||
color: #9ca3af;
|
||||
margin-top: 4rpx;
|
||||
}
|
||||
}
|
||||
|
||||
.stat-sep {
|
||||
width: 1rpx;
|
||||
height: 38rpx;
|
||||
background: #e5e7eb;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.sku-list {
|
||||
.sku-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 20rpx 0;
|
||||
border-bottom: 1rpx solid #f3f4f6;
|
||||
|
||||
&:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
.sku-thumb {
|
||||
width: 104rpx;
|
||||
height: 104rpx;
|
||||
border-radius: 14rpx;
|
||||
background: #f9fafb;
|
||||
border: 1rpx solid #f3f4f6;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.sku-info {
|
||||
flex: 1;
|
||||
margin-left: 22rpx;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
.sku-spec {
|
||||
font-size: 28rpx;
|
||||
font-weight: 600;
|
||||
color: #111827;
|
||||
line-height: 1.35;
|
||||
}
|
||||
|
||||
.sku-sn {
|
||||
font-size: 22rpx;
|
||||
color: #9ca3af;
|
||||
margin-top: 6rpx;
|
||||
}
|
||||
|
||||
.sku-nums {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: baseline;
|
||||
margin-top: 10rpx;
|
||||
|
||||
.sku-price {
|
||||
font-size: 24rpx;
|
||||
color: #6b7280;
|
||||
|
||||
.val {
|
||||
font-size: 28rpx;
|
||||
font-weight: 700;
|
||||
color: #ef4444;
|
||||
}
|
||||
}
|
||||
|
||||
.sku-stock {
|
||||
font-size: 24rpx;
|
||||
color: #6b7280;
|
||||
|
||||
.val {
|
||||
font-weight: 600;
|
||||
color: #111827;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.prop-row {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
justify-content: space-between;
|
||||
padding: 18rpx 0;
|
||||
border-bottom: 1rpx solid #f9fafb;
|
||||
|
||||
&:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
.prop-label {
|
||||
font-size: 26rpx;
|
||||
color: #6b7280;
|
||||
width: 160rpx;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.prop-val {
|
||||
flex: 1;
|
||||
text-align: right;
|
||||
font-size: 26rpx;
|
||||
color: #111827;
|
||||
font-weight: 500;
|
||||
line-height: 1.45;
|
||||
|
||||
&.cat-val {
|
||||
color: #2563eb;
|
||||
background: #eff6ff;
|
||||
display: inline-block;
|
||||
padding: 6rpx 16rpx;
|
||||
border-radius: 8rpx;
|
||||
font-size: 24rpx;
|
||||
font-weight: 500;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
&.intro-card {
|
||||
.intro-html {
|
||||
margin-top: 16rpx;
|
||||
font-size: 28rpx;
|
||||
color: #374151;
|
||||
line-height: 1.6;
|
||||
word-break: break-all;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.bottom-action-bar {
|
||||
position: fixed;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
background: #ffffff;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 16rpx 28rpx calc(16rpx + env(safe-area-inset-bottom)) 28rpx;
|
||||
box-shadow: 0 -4rpx 20rpx rgba(0, 0, 0, 0.06);
|
||||
z-index: 100;
|
||||
gap: 20rpx;
|
||||
|
||||
.preview-btn {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 0 20rpx;
|
||||
|
||||
text {
|
||||
font-size: 20rpx;
|
||||
color: #4b5563;
|
||||
margin-top: 4rpx;
|
||||
}
|
||||
}
|
||||
|
||||
.market-action-btn {
|
||||
flex: 1;
|
||||
height: 84rpx;
|
||||
border-radius: 16rpx;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: 28rpx;
|
||||
font-weight: 600;
|
||||
|
||||
&.off {
|
||||
background: #fef2f2;
|
||||
color: #dc2626;
|
||||
border: 1rpx solid #fecaca;
|
||||
}
|
||||
|
||||
&.on {
|
||||
background: #111827;
|
||||
color: #ffffff;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
472
pages-sub/merchant/pages/goods/list.vue
Normal file
472
pages-sub/merchant/pages/goods/list.vue
Normal file
@@ -0,0 +1,472 @@
|
||||
<template>
|
||||
<view class="merchant-goods-page">
|
||||
<!-- 顶部吸顶搜索栏与 Tab -->
|
||||
<view class="sticky-header">
|
||||
<view class="search-bar">
|
||||
<u-icon name="search" size="18" color="#9ca3af"></u-icon>
|
||||
<input
|
||||
class="search-input"
|
||||
type="text"
|
||||
v-model="keywords"
|
||||
placeholder="搜索商品名称"
|
||||
placeholder-class="placeholder"
|
||||
@confirm="onSearch"
|
||||
/>
|
||||
<view class="clear-btn" v-if="keywords" @click="clearSearch">
|
||||
<u-icon name="close-circle-fill" size="16" color="#d1d5db"></u-icon>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="tab-scroll-wrap">
|
||||
<view
|
||||
class="tab-item"
|
||||
v-for="item in tabList"
|
||||
:key="item.key"
|
||||
:class="{ active: currentTab === item.key }"
|
||||
@click="switchTab(item.key)"
|
||||
>
|
||||
<text class="tab-label">{{ item.label }}</text>
|
||||
<view class="indicator" v-if="currentTab === item.key"></view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 商品列表主体 -->
|
||||
<view class="goods-list-body">
|
||||
<view
|
||||
class="goods-card"
|
||||
v-for="goods in goodsList"
|
||||
:key="goods.id"
|
||||
@click="goToDetail(goods.id)"
|
||||
>
|
||||
<view class="card-main">
|
||||
<image
|
||||
class="goods-img"
|
||||
:src="goods.thumbnail || goods.original || '/static/tabbar/home.png'"
|
||||
mode="aspectFill"
|
||||
></image>
|
||||
<view class="goods-meta">
|
||||
<view class="title-row">
|
||||
<text class="goods-title">{{ goods.goodsName }}</text>
|
||||
</view>
|
||||
<view class="stock-sales-row">
|
||||
<text class="meta-tag">库存: {{ goods.quantity ?? 0 }}</text>
|
||||
<text class="meta-tag">销量: {{ goods.buyCount ?? 0 }}</text>
|
||||
</view>
|
||||
<view class="price-status-row">
|
||||
<view class="price-box">
|
||||
<text class="symbol">¥</text>
|
||||
<text class="price-num">{{ goods.price || goods.sellingPrice || '0.00' }}</text>
|
||||
</view>
|
||||
<view class="status-badge" :class="goods.marketEnable === 'UPPER' ? 'on-sale' : 'off-sale'">
|
||||
{{ goods.marketEnable === 'UPPER' ? '出售中' : '已下架' }}
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 底部快捷操作条 -->
|
||||
<view class="card-footer">
|
||||
<text class="goods-sn" v-if="goods.sn">商品货号:{{ goods.sn }}</text>
|
||||
<view class="actions-group">
|
||||
<view
|
||||
class="action-btn off"
|
||||
v-if="goods.marketEnable === 'UPPER'"
|
||||
@click.stop="toggleMarket(goods, 'DOWN')"
|
||||
>
|
||||
<text>下架商品</text>
|
||||
</view>
|
||||
<view
|
||||
class="action-btn on"
|
||||
v-else
|
||||
@click.stop="toggleMarket(goods, 'UPPER')"
|
||||
>
|
||||
<text>立即上架</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 空状态 -->
|
||||
<view class="empty-state" v-if="!loading && goodsList.length === 0">
|
||||
<u-icon name="bag" size="56" color="#d1d5db"></u-icon>
|
||||
<text class="empty-text">暂无相关商品</text>
|
||||
</view>
|
||||
|
||||
<!-- 加载提示 -->
|
||||
<view class="loading-more" v-if="loading">
|
||||
<text>正在加载商品列表...</text>
|
||||
</view>
|
||||
<view class="no-more" v-else-if="finished && goodsList.length > 0">
|
||||
<text>没有更多了</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref } from 'vue'
|
||||
import { onLoad, onPullDownRefresh, onReachBottom } from '@dcloudio/uni-app'
|
||||
import { getStoreGoodsList, upGoods, downGoods } from '../../api/goods.js'
|
||||
|
||||
const keywords = ref('')
|
||||
const currentTab = ref('ALL')
|
||||
const loading = ref(false)
|
||||
const finished = ref(false)
|
||||
const pageNumber = ref(1)
|
||||
const pageSize = ref(10)
|
||||
const goodsList = ref([])
|
||||
|
||||
const tabList = [
|
||||
{ key: 'ALL', label: '全部' },
|
||||
{ key: 'UPPER', label: '出售中' },
|
||||
{ key: 'DOWN', label: '已下架' },
|
||||
]
|
||||
|
||||
onLoad((options) => {
|
||||
if (options?.tab) {
|
||||
currentTab.value = options.tab
|
||||
}
|
||||
fetchGoods(true)
|
||||
})
|
||||
|
||||
onPullDownRefresh(async () => {
|
||||
await fetchGoods(true)
|
||||
uni.stopPullDownRefresh()
|
||||
})
|
||||
|
||||
onReachBottom(() => {
|
||||
if (!finished.value && !loading.value) {
|
||||
pageNumber.value++
|
||||
fetchGoods(false)
|
||||
}
|
||||
})
|
||||
|
||||
const fetchGoods = async (reset = false) => {
|
||||
if (reset) {
|
||||
pageNumber.value = 1
|
||||
goodsList.value = []
|
||||
finished.value = false
|
||||
}
|
||||
|
||||
loading.value = true
|
||||
const params = {
|
||||
pageNumber: pageNumber.value,
|
||||
pageSize: pageSize.value,
|
||||
}
|
||||
|
||||
if (keywords.value.trim()) {
|
||||
params.goodsName = keywords.value.trim()
|
||||
}
|
||||
|
||||
if (currentTab.value !== 'ALL') {
|
||||
params.marketEnable = currentTab.value
|
||||
}
|
||||
|
||||
try {
|
||||
const res = await getStoreGoodsList(params)
|
||||
loading.value = false
|
||||
if (res.data && res.data.success && res.data.result) {
|
||||
const records = res.data.result.records || []
|
||||
if (reset) {
|
||||
goodsList.value = records
|
||||
} else {
|
||||
goodsList.value = [...goodsList.value, ...records]
|
||||
}
|
||||
if (records.length < pageSize.value) {
|
||||
finished.value = true
|
||||
}
|
||||
} else {
|
||||
finished.value = true
|
||||
}
|
||||
} catch (e) {
|
||||
loading.value = false
|
||||
finished.value = true
|
||||
}
|
||||
}
|
||||
|
||||
const switchTab = (tabKey) => {
|
||||
if (currentTab.value === tabKey) return
|
||||
currentTab.value = tabKey
|
||||
fetchGoods(true)
|
||||
}
|
||||
|
||||
const onSearch = () => {
|
||||
fetchGoods(true)
|
||||
}
|
||||
|
||||
const clearSearch = () => {
|
||||
keywords.value = ''
|
||||
fetchGoods(true)
|
||||
}
|
||||
|
||||
const goToDetail = (id) => {
|
||||
uni.navigateTo({
|
||||
url: `/pages-sub/merchant/pages/goods/detail?id=${id}`,
|
||||
})
|
||||
}
|
||||
|
||||
// 快捷上下架切换
|
||||
const toggleMarket = (goods, targetStatus) => {
|
||||
const isUp = targetStatus === 'UPPER'
|
||||
const actionText = isUp ? '上架' : '下架'
|
||||
|
||||
uni.showModal({
|
||||
title: `${actionText}提示`,
|
||||
content: `确定要${actionText}商品「${goods.goodsName}」吗?`,
|
||||
success: async (res) => {
|
||||
if (res.confirm) {
|
||||
uni.showLoading({ title: `正在${actionText}...` })
|
||||
try {
|
||||
const apiCall = isUp ? upGoods(goods.id) : downGoods(goods.id)
|
||||
const resp = await apiCall
|
||||
uni.hideLoading()
|
||||
if (resp.data && resp.data.success) {
|
||||
uni.showToast({ title: `${actionText}成功`, icon: 'success' })
|
||||
fetchGoods(true)
|
||||
} else {
|
||||
uni.showToast({
|
||||
title: resp.data?.message || `${actionText}失败`,
|
||||
icon: 'none',
|
||||
})
|
||||
}
|
||||
} catch (e) {
|
||||
uni.hideLoading()
|
||||
uni.showToast({ title: '网络连接异常', icon: 'none' })
|
||||
}
|
||||
}
|
||||
},
|
||||
})
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.merchant-goods-page {
|
||||
min-height: 100vh;
|
||||
background-color: #f3f4f6;
|
||||
padding-bottom: 40rpx;
|
||||
}
|
||||
|
||||
.sticky-header {
|
||||
position: sticky;
|
||||
top: 0;
|
||||
z-index: 100;
|
||||
background: #ffffff;
|
||||
box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.04);
|
||||
|
||||
.search-bar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
background: #f3f4f6;
|
||||
margin: 20rpx 28rpx;
|
||||
padding: 16rpx 24rpx;
|
||||
border-radius: 16rpx;
|
||||
|
||||
.search-input {
|
||||
flex: 1;
|
||||
margin-left: 16rpx;
|
||||
font-size: 26rpx;
|
||||
color: #111827;
|
||||
}
|
||||
|
||||
.placeholder {
|
||||
color: #9ca3af;
|
||||
font-size: 26rpx;
|
||||
}
|
||||
}
|
||||
|
||||
.tab-scroll-wrap {
|
||||
display: flex;
|
||||
border-bottom: 1rpx solid #f0f0f0;
|
||||
padding: 0 16rpx;
|
||||
|
||||
.tab-item {
|
||||
flex: 1;
|
||||
text-align: center;
|
||||
padding: 20rpx 0;
|
||||
position: relative;
|
||||
|
||||
.tab-label {
|
||||
font-size: 28rpx;
|
||||
color: #6b7280;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
&.active {
|
||||
.tab-label {
|
||||
color: #111827;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.indicator {
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
width: 40rpx;
|
||||
height: 6rpx;
|
||||
background: #111827;
|
||||
border-radius: 3rpx;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.goods-list-body {
|
||||
padding: 24rpx 28rpx;
|
||||
|
||||
.goods-card {
|
||||
background: #ffffff;
|
||||
border-radius: 20rpx;
|
||||
padding: 24rpx;
|
||||
margin-bottom: 24rpx;
|
||||
box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.03);
|
||||
|
||||
.card-main {
|
||||
display: flex;
|
||||
|
||||
.goods-img {
|
||||
width: 170rpx;
|
||||
height: 170rpx;
|
||||
border-radius: 16rpx;
|
||||
background: #f3f4f6;
|
||||
}
|
||||
|
||||
.goods-meta {
|
||||
flex: 1;
|
||||
margin-left: 20rpx;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: space-between;
|
||||
|
||||
.title-row {
|
||||
.goods-title {
|
||||
font-size: 28rpx;
|
||||
font-weight: 600;
|
||||
color: #111827;
|
||||
line-height: 1.4;
|
||||
display: -webkit-box;
|
||||
-webkit-line-clamp: 2;
|
||||
-webkit-box-orient: vertical;
|
||||
overflow: hidden;
|
||||
}
|
||||
}
|
||||
|
||||
.stock-sales-row {
|
||||
display: flex;
|
||||
gap: 16rpx;
|
||||
margin-top: 8rpx;
|
||||
|
||||
.meta-tag {
|
||||
font-size: 22rpx;
|
||||
color: #6b7280;
|
||||
background: #f3f4f6;
|
||||
padding: 4rpx 12rpx;
|
||||
border-radius: 8rpx;
|
||||
}
|
||||
}
|
||||
|
||||
.price-status-row {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-top: 12rpx;
|
||||
|
||||
.price-box {
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
color: #ff3c2a;
|
||||
|
||||
.symbol {
|
||||
font-size: 22rpx;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.price-num {
|
||||
font-size: 34rpx;
|
||||
font-weight: 700;
|
||||
margin-left: 4rpx;
|
||||
}
|
||||
}
|
||||
|
||||
.status-badge {
|
||||
font-size: 22rpx;
|
||||
padding: 4rpx 14rpx;
|
||||
border-radius: 8rpx;
|
||||
font-weight: 500;
|
||||
|
||||
&.on-sale {
|
||||
background: #ecfdf5;
|
||||
color: #059669;
|
||||
}
|
||||
|
||||
&.off-sale {
|
||||
background: #f3f4f6;
|
||||
color: #9ca3af;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.card-footer {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-top: 20rpx;
|
||||
padding-top: 20rpx;
|
||||
border-top: 1rpx solid #f9fafb;
|
||||
|
||||
.goods-sn {
|
||||
font-size: 22rpx;
|
||||
color: #9ca3af;
|
||||
}
|
||||
|
||||
.actions-group {
|
||||
display: flex;
|
||||
gap: 16rpx;
|
||||
|
||||
.action-btn {
|
||||
padding: 10rpx 28rpx;
|
||||
border-radius: 12rpx;
|
||||
font-size: 24rpx;
|
||||
font-weight: 600;
|
||||
|
||||
&.off {
|
||||
background: #fef2f2;
|
||||
color: #dc2626;
|
||||
border: 1rpx solid #fecaca;
|
||||
}
|
||||
|
||||
&.on {
|
||||
background: #111827;
|
||||
color: #ffffff;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.empty-state {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
padding: 120rpx 0;
|
||||
|
||||
.empty-text {
|
||||
font-size: 26rpx;
|
||||
color: #9ca3af;
|
||||
margin-top: 20rpx;
|
||||
}
|
||||
}
|
||||
|
||||
.loading-more,
|
||||
.no-more {
|
||||
text-align: center;
|
||||
padding: 24rpx 0;
|
||||
font-size: 22rpx;
|
||||
color: #9ca3af;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
812
pages-sub/merchant/pages/index/index.vue
Normal file
812
pages-sub/merchant/pages/index/index.vue
Normal file
@@ -0,0 +1,812 @@
|
||||
<template>
|
||||
<view class="workbench-page">
|
||||
<!-- 顶部商家信息栏 -->
|
||||
<view class="store-hero">
|
||||
<view class="store-info-row">
|
||||
<view class="store-avatar">
|
||||
<image
|
||||
class="avatar-img"
|
||||
:src="storeInfo.settings?.storeLogo || '/static/tabbar/home.png'"
|
||||
mode="aspectFill"
|
||||
></image>
|
||||
</view>
|
||||
<view class="store-meta">
|
||||
<view class="name-row">
|
||||
<text class="store-name">{{ storeInfo.settings?.storeName || storeInfo.store?.storeName || '商家移动工作台' }}</text>
|
||||
<view class="badge" :class="isClerk ? 'clerk-badge' : 'owner-badge'">
|
||||
{{ isClerk ? '店员' : '店主' }}
|
||||
</view>
|
||||
</view>
|
||||
<text class="clerk-name">当前操作员:{{ operatorName }}</text>
|
||||
</view>
|
||||
<view class="logout-btn" @click="handleLogout">
|
||||
<text>退出</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 核心操作区(快速核销) -->
|
||||
<view class="core-actions-card">
|
||||
<view class="card-header">
|
||||
<text class="card-title">快速核销</text>
|
||||
<text class="card-subtitle">支持预约单、自提单与虚拟卡密</text>
|
||||
</view>
|
||||
|
||||
<!-- 扫码主按钮 -->
|
||||
<view class="scan-hero-btn" @click="handleScanCode">
|
||||
<view class="scan-icon-circle">
|
||||
<u-icon name="scan" size="38" color="#ffffff"></u-icon>
|
||||
</view>
|
||||
<view class="scan-text-box">
|
||||
<text class="main-text">扫码快速核销</text>
|
||||
<text class="sub-text">扫描顾客出示的核销码/订单码</text>
|
||||
</view>
|
||||
<u-icon name="arrow-right" size="18" color="rgba(255,255,255,0.6)"></u-icon>
|
||||
</view>
|
||||
|
||||
<!-- 手动输码 -->
|
||||
<view class="manual-input-box">
|
||||
<view class="input-wrap">
|
||||
<u-icon name="edit-pen" size="20" color="#9ca3af"></u-icon>
|
||||
<input
|
||||
class="code-input"
|
||||
type="number"
|
||||
maxlength="12"
|
||||
v-model="manualCode"
|
||||
placeholder="输入8位数字核销码"
|
||||
placeholder-class="placeholder"
|
||||
@confirm="handleManualVerify"
|
||||
/>
|
||||
<view class="clear-icon" v-if="manualCode" @click="clearManualCode">
|
||||
<u-icon name="close-circle-fill" size="16" color="#d1d5db"></u-icon>
|
||||
</view>
|
||||
</view>
|
||||
<view
|
||||
class="verify-btn"
|
||||
:class="{ active: manualCode.trim().length >= 6 }"
|
||||
@click="handleManualVerify"
|
||||
>
|
||||
<text>核销</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 核心业务四大板块 -->
|
||||
<view class="business-grid-card">
|
||||
<view class="grid-card-header">
|
||||
<text class="grid-card-title">经营管理</text>
|
||||
</view>
|
||||
<view class="business-grid">
|
||||
<!-- 订单管理 -->
|
||||
<view class="biz-item" @click="navigateTo('/pages-sub/merchant/pages/order/list?tab=ALL')">
|
||||
<view class="biz-icon-box bg-blue">
|
||||
<u-icon name="order" size="26" color="#2563eb"></u-icon>
|
||||
</view>
|
||||
<text class="biz-title">订单管理</text>
|
||||
</view>
|
||||
|
||||
<!-- 商品管理 -->
|
||||
<view class="biz-item" @click="navigateTo('/pages-sub/merchant/pages/goods/list')">
|
||||
<view class="biz-icon-box bg-emerald">
|
||||
<u-icon name="bag" size="26" color="#059669"></u-icon>
|
||||
</view>
|
||||
<text class="biz-title">商品管理</text>
|
||||
</view>
|
||||
|
||||
<!-- 评价管理 -->
|
||||
<view class="biz-item" @click="navigateTo('/pages-sub/merchant/pages/evaluation/list')">
|
||||
<view class="biz-icon-box bg-amber">
|
||||
<u-icon name="chat" size="26" color="#d97706"></u-icon>
|
||||
</view>
|
||||
<text class="biz-title">评价管理</text>
|
||||
</view>
|
||||
|
||||
<!-- 待核销专区 -->
|
||||
<view class="biz-item" @click="navigateTo('/pages-sub/merchant/pages/order/list?tab=TAKE')">
|
||||
<view class="biz-icon-box bg-orange">
|
||||
<u-icon name="checkmark-circle" size="26" color="#ea580c"></u-icon>
|
||||
</view>
|
||||
<text class="biz-title">待核销单</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
|
||||
|
||||
<!-- 核销确认弹窗 -->
|
||||
<view class="modal-mask" v-if="showModal" @click.self="closeModal">
|
||||
<view class="modal-card">
|
||||
<view class="modal-header">
|
||||
<text class="modal-title">核销信息确认</text>
|
||||
<view class="close-btn" @click="closeModal">
|
||||
<u-icon name="close" size="18" color="#9ca3af"></u-icon>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 订单概览 -->
|
||||
<view class="order-summary" v-if="verifyingOrder">
|
||||
<view class="summary-row">
|
||||
<text class="label">核销码:</text>
|
||||
<text class="value highlight-code">{{ currentCode }}</text>
|
||||
</view>
|
||||
<view class="summary-row">
|
||||
<text class="label">订单编号:</text>
|
||||
<text class="value">{{ verifyingOrder.sn || verifyingOrder.orderSn || '--' }}</text>
|
||||
</view>
|
||||
<view class="summary-row" v-if="verifyingOrder.consigneeMobile || verifyingOrder.memberPhone">
|
||||
<text class="label">顾客电话:</text>
|
||||
<text class="value">{{ maskPhone(verifyingOrder.consigneeMobile || verifyingOrder.memberPhone) }}</text>
|
||||
</view>
|
||||
<view class="summary-row" v-if="verifyingOrder.goodsName || verifyingOrder.orderItems?.[0]?.goodsName">
|
||||
<text class="label">商品名称:</text>
|
||||
<text class="value goods-text">
|
||||
{{ verifyingOrder.goodsName || verifyingOrder.orderItems?.[0]?.goodsName }}
|
||||
</text>
|
||||
</view>
|
||||
<view class="summary-row" v-if="verifyingOrder.num">
|
||||
<text class="label">购买数量:</text>
|
||||
<text class="value">{{ verifyingOrder.num }} 件</text>
|
||||
</view>
|
||||
|
||||
<!-- 预约服务专属选项:选择服务人员 -->
|
||||
<view class="staff-picker-box" v-if="isAppointmentOrder">
|
||||
<text class="staff-label">指派/核销服务人员:</text>
|
||||
<picker
|
||||
class="picker-ctrl"
|
||||
mode="selector"
|
||||
:range="staffList"
|
||||
range-key="name"
|
||||
:value="selectedStaffIndex"
|
||||
@change="onStaffChange"
|
||||
>
|
||||
<view class="picker-display">
|
||||
<text>{{ currentStaffName }}</text>
|
||||
<u-icon name="arrow-down" size="14" color="#6b7280"></u-icon>
|
||||
</view>
|
||||
</picker>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 弹窗操作 -->
|
||||
<view class="modal-footer">
|
||||
<view class="modal-btn cancel" @click="closeModal">取消</view>
|
||||
<view
|
||||
class="modal-btn confirm"
|
||||
:class="{ loading: confirming }"
|
||||
@click="submitConfirmVerification"
|
||||
>
|
||||
{{ confirming ? '核销中...' : '确认核销' }}
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, computed, onMounted } from 'vue'
|
||||
import storage from '@/utils/storage.js'
|
||||
import {
|
||||
previewStoreVerification,
|
||||
storeOrderTake,
|
||||
confirmStoreVerification,
|
||||
getAppointmentOrderByCode,
|
||||
verifyAppointmentCode,
|
||||
getEnabledServiceStaff,
|
||||
} from '../../api/order.js'
|
||||
import { storeLogout } from '../../api/passport.js'
|
||||
|
||||
const storeInfo = ref({})
|
||||
|
||||
const operatorName = computed(() => {
|
||||
const u = storeInfo.value?.user
|
||||
return u?.nickName || u?.username || '当前操作员'
|
||||
})
|
||||
|
||||
const isClerk = computed(() => {
|
||||
const u = storeInfo.value?.user
|
||||
if (u && (u.isSuper === false || u.shopkeeper === false)) return true
|
||||
return false
|
||||
})
|
||||
const manualCode = ref('')
|
||||
const showModal = ref(false)
|
||||
const confirming = ref(false)
|
||||
const currentCode = ref('')
|
||||
const verifyingOrder = ref(null)
|
||||
const isAppointmentOrder = ref(false)
|
||||
|
||||
const staffList = ref([])
|
||||
const selectedStaffIndex = ref(0)
|
||||
|
||||
const currentStaffName = computed(() => {
|
||||
if (staffList.value.length > 0 && staffList.value[selectedStaffIndex.value]) {
|
||||
return staffList.value[selectedStaffIndex.value].name
|
||||
}
|
||||
return '未指派 / 默认'
|
||||
})
|
||||
|
||||
onMounted(() => {
|
||||
const token = storage.getStoreAccessToken()
|
||||
if (!token) {
|
||||
uni.redirectTo({ url: '/pages-sub/merchant/pages/login/index' })
|
||||
return
|
||||
}
|
||||
storeInfo.value = storage.getStoreInfo() || {}
|
||||
loadStaffList()
|
||||
})
|
||||
|
||||
const loadStaffList = async () => {
|
||||
try {
|
||||
const res = await getEnabledServiceStaff()
|
||||
if (res.data && res.data.success && Array.isArray(res.data.result)) {
|
||||
staffList.value = res.data.result
|
||||
}
|
||||
} catch (e) {
|
||||
// 忽略加载异常
|
||||
}
|
||||
}
|
||||
|
||||
const maskPhone = (phone) => {
|
||||
if (!phone || phone.length < 7) return phone || ''
|
||||
return phone.replace(/(\d{3})\d{4}(\d{4})/, '$1****$2')
|
||||
}
|
||||
|
||||
// 扫码快速核销
|
||||
const handleScanCode = () => {
|
||||
uni.scanCode({
|
||||
onlyFromCamera: true,
|
||||
scanType: ['qrCode', 'barCode'],
|
||||
success: (res) => {
|
||||
let code = res.result || ''
|
||||
if (code.includes('code=')) {
|
||||
const match = code.match(/code=([a-zA-Z0-9]+)/)
|
||||
if (match && match[1]) {
|
||||
code = match[1]
|
||||
}
|
||||
}
|
||||
if (code) {
|
||||
queryAndShowVerify(code.trim())
|
||||
} else {
|
||||
uni.showToast({ title: '未能识别核销码', icon: 'none' })
|
||||
}
|
||||
},
|
||||
fail: () => {},
|
||||
})
|
||||
}
|
||||
|
||||
// 手动输码核销
|
||||
const clearManualCode = () => {
|
||||
manualCode.value = ''
|
||||
}
|
||||
|
||||
const handleManualVerify = () => {
|
||||
const code = manualCode.value.trim()
|
||||
if (!code || code.length < 6) {
|
||||
uni.showToast({ title: '请输入有效的核销码', icon: 'none' })
|
||||
return
|
||||
}
|
||||
queryAndShowVerify(code)
|
||||
}
|
||||
|
||||
// 预检核销码并展示弹窗
|
||||
const queryAndShowVerify = async (code) => {
|
||||
currentCode.value = code
|
||||
uni.showLoading({ title: '正在查询订单...' })
|
||||
|
||||
try {
|
||||
let isAppoint = false
|
||||
let orderData = null
|
||||
|
||||
try {
|
||||
const appointRes = await getAppointmentOrderByCode(code)
|
||||
if (appointRes.data && appointRes.data.success && appointRes.data.result) {
|
||||
isAppoint = true
|
||||
orderData = appointRes.data.result
|
||||
}
|
||||
} catch (e) {}
|
||||
|
||||
if (!orderData) {
|
||||
const previewRes = await previewStoreVerification(code)
|
||||
if (previewRes.data && previewRes.data.success && previewRes.data.result) {
|
||||
orderData = previewRes.data.result
|
||||
}
|
||||
}
|
||||
|
||||
uni.hideLoading()
|
||||
|
||||
if (orderData) {
|
||||
verifyingOrder.value = orderData
|
||||
isAppointmentOrder.value = isAppoint
|
||||
showModal.value = true
|
||||
} else {
|
||||
verifyingOrder.value = { sn: '以提交核销为准' }
|
||||
isAppointmentOrder.value = false
|
||||
showModal.value = true
|
||||
}
|
||||
} catch (err) {
|
||||
uni.hideLoading()
|
||||
verifyingOrder.value = { sn: '以提交核销为准' }
|
||||
isAppointmentOrder.value = false
|
||||
showModal.value = true
|
||||
}
|
||||
}
|
||||
|
||||
const onStaffChange = (e) => {
|
||||
selectedStaffIndex.value = e.detail.value
|
||||
}
|
||||
|
||||
const closeModal = () => {
|
||||
showModal.value = false
|
||||
verifyingOrder.value = null
|
||||
manualCode.value = ''
|
||||
}
|
||||
|
||||
// 确认核销提交
|
||||
const submitConfirmVerification = async () => {
|
||||
if (confirming.value) return
|
||||
confirming.value = true
|
||||
uni.showLoading({ title: '核销中...' })
|
||||
|
||||
try {
|
||||
let success = false
|
||||
let message = ''
|
||||
|
||||
if (isAppointmentOrder.value) {
|
||||
const staff = staffList.value[selectedStaffIndex.value]
|
||||
const params = {
|
||||
orderSn: verifyingOrder.value?.orderSn || verifyingOrder.value?.sn,
|
||||
code: currentCode.value,
|
||||
serviceStaffId: staff ? staff.id : undefined,
|
||||
}
|
||||
const res = await verifyAppointmentCode(params)
|
||||
success = res.data && res.data.success
|
||||
message = res.data?.message
|
||||
} else {
|
||||
const sn = verifyingOrder.value?.orderSn || verifyingOrder.value?.sn
|
||||
if (sn && sn !== '以提交核销为准') {
|
||||
const res = await storeOrderTake(sn, currentCode.value)
|
||||
success = res.data && res.data.success
|
||||
message = res.data?.message
|
||||
} else {
|
||||
const res = await confirmStoreVerification(currentCode.value)
|
||||
success = res.data && res.data.success
|
||||
message = res.data?.message
|
||||
}
|
||||
}
|
||||
|
||||
uni.hideLoading()
|
||||
confirming.value = false
|
||||
|
||||
if (success) {
|
||||
try {
|
||||
uni.vibrateShort()
|
||||
} catch (e) {}
|
||||
uni.showToast({ title: '核销成功!', icon: 'success' })
|
||||
closeModal()
|
||||
} else {
|
||||
uni.showToast({
|
||||
title: message || '核销失败,请核对核销码',
|
||||
icon: 'none',
|
||||
})
|
||||
}
|
||||
} catch (e) {
|
||||
uni.hideLoading()
|
||||
confirming.value = false
|
||||
uni.showToast({ title: '请求失败,请稍后重试', icon: 'none' })
|
||||
}
|
||||
}
|
||||
|
||||
// 退出登录
|
||||
const handleLogout = () => {
|
||||
uni.showModal({
|
||||
title: '退出商家工作台',
|
||||
content: '退出后将清除本店登录凭证,确认退出?',
|
||||
success: async (res) => {
|
||||
if (res.confirm) {
|
||||
try {
|
||||
await storeLogout()
|
||||
} catch (e) {}
|
||||
storage.clearStoreAuth()
|
||||
uni.redirectTo({
|
||||
url: '/pages-sub/merchant/pages/login/index',
|
||||
})
|
||||
}
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
const navigateTo = (url) => {
|
||||
uni.navigateTo({ url })
|
||||
}
|
||||
|
||||
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.workbench-page {
|
||||
min-height: 100vh;
|
||||
background-color: #f3f4f6;
|
||||
padding-bottom: 60rpx;
|
||||
}
|
||||
|
||||
.store-hero {
|
||||
background: linear-gradient(135deg, #1f2937 0%, #111827 100%);
|
||||
padding: 60rpx 36rpx 100rpx 36rpx;
|
||||
color: #ffffff;
|
||||
|
||||
.store-info-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
|
||||
.store-avatar {
|
||||
width: 96rpx;
|
||||
height: 96rpx;
|
||||
border-radius: 20rpx;
|
||||
overflow: hidden;
|
||||
background: #ffffff;
|
||||
border: 2rpx solid rgba(255, 255, 255, 0.2);
|
||||
|
||||
.avatar-img {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
.store-meta {
|
||||
flex: 1;
|
||||
margin-left: 24rpx;
|
||||
|
||||
.name-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12rpx;
|
||||
|
||||
.store-name {
|
||||
font-size: 34rpx;
|
||||
font-weight: 700;
|
||||
color: #ffffff;
|
||||
}
|
||||
|
||||
.badge {
|
||||
font-size: 20rpx;
|
||||
padding: 4rpx 14rpx;
|
||||
border-radius: 8rpx;
|
||||
font-weight: 500;
|
||||
|
||||
&.owner-badge {
|
||||
background: rgba(255, 255, 255, 0.2);
|
||||
color: #ffffff;
|
||||
}
|
||||
|
||||
&.clerk-badge {
|
||||
background: #ecfdf5;
|
||||
color: #059669;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.clerk-name {
|
||||
display: block;
|
||||
font-size: 24rpx;
|
||||
color: rgba(255, 255, 255, 0.65);
|
||||
margin-top: 8rpx;
|
||||
}
|
||||
}
|
||||
|
||||
.logout-btn {
|
||||
padding: 10rpx 24rpx;
|
||||
background: rgba(255, 255, 255, 0.12);
|
||||
border-radius: 12rpx;
|
||||
font-size: 24rpx;
|
||||
color: rgba(255, 255, 255, 0.85);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.core-actions-card {
|
||||
margin: -60rpx 32rpx 28rpx 32rpx;
|
||||
background: #ffffff;
|
||||
border-radius: 28rpx;
|
||||
padding: 36rpx;
|
||||
box-shadow: 0 10rpx 30rpx rgba(0, 0, 0, 0.06);
|
||||
|
||||
.card-header {
|
||||
margin-bottom: 28rpx;
|
||||
|
||||
.card-title {
|
||||
font-size: 32rpx;
|
||||
font-weight: 700;
|
||||
color: #111827;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.card-subtitle {
|
||||
font-size: 22rpx;
|
||||
color: #9ca3af;
|
||||
margin-top: 6rpx;
|
||||
display: block;
|
||||
}
|
||||
}
|
||||
|
||||
.scan-hero-btn {
|
||||
background: linear-gradient(135deg, #10b981 0%, #059669 100%);
|
||||
border-radius: 22rpx;
|
||||
padding: 32rpx 28rpx;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
box-shadow: 0 10rpx 24rpx rgba(16, 185, 129, 0.3);
|
||||
|
||||
.scan-icon-circle {
|
||||
width: 80rpx;
|
||||
height: 80rpx;
|
||||
border-radius: 40rpx;
|
||||
background: rgba(255, 255, 255, 0.2);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.scan-text-box {
|
||||
flex: 1;
|
||||
margin-left: 24rpx;
|
||||
|
||||
.main-text {
|
||||
font-size: 34rpx;
|
||||
font-weight: 700;
|
||||
color: #ffffff;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.sub-text {
|
||||
font-size: 22rpx;
|
||||
color: rgba(255, 255, 255, 0.8);
|
||||
margin-top: 6rpx;
|
||||
display: block;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.manual-input-box {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
margin-top: 28rpx;
|
||||
gap: 16rpx;
|
||||
|
||||
.input-wrap {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
background: #f9fafb;
|
||||
border: 1rpx solid #e5e7eb;
|
||||
border-radius: 16rpx;
|
||||
padding: 18rpx 24rpx;
|
||||
|
||||
.code-input {
|
||||
flex: 1;
|
||||
margin-left: 16rpx;
|
||||
font-size: 28rpx;
|
||||
color: #111827;
|
||||
}
|
||||
|
||||
.placeholder {
|
||||
color: #9ca3af;
|
||||
font-size: 26rpx;
|
||||
}
|
||||
}
|
||||
|
||||
.verify-btn {
|
||||
padding: 20rpx 36rpx;
|
||||
background: #e5e7eb;
|
||||
color: #9ca3af;
|
||||
border-radius: 16rpx;
|
||||
font-size: 28rpx;
|
||||
font-weight: 600;
|
||||
|
||||
&.active {
|
||||
background: #111827;
|
||||
color: #ffffff;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.business-grid-card {
|
||||
margin: 0 32rpx 24rpx 32rpx;
|
||||
background: #ffffff;
|
||||
border-radius: 28rpx;
|
||||
padding: 32rpx 24rpx;
|
||||
box-shadow: 0 6rpx 20rpx rgba(0, 0, 0, 0.04);
|
||||
|
||||
.grid-card-header {
|
||||
margin-bottom: 24rpx;
|
||||
padding-left: 8rpx;
|
||||
|
||||
.grid-card-title {
|
||||
font-size: 30rpx;
|
||||
font-weight: 700;
|
||||
color: #111827;
|
||||
}
|
||||
}
|
||||
|
||||
.business-grid {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
|
||||
.biz-item {
|
||||
width: 50%;
|
||||
box-sizing: border-box;
|
||||
padding: 20rpx;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
text-align: center;
|
||||
|
||||
.biz-icon-box {
|
||||
width: 96rpx;
|
||||
height: 96rpx;
|
||||
border-radius: 24rpx;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
margin-bottom: 16rpx;
|
||||
|
||||
&.bg-blue {
|
||||
background: #eff6ff;
|
||||
}
|
||||
&.bg-emerald {
|
||||
background: #ecfdf5;
|
||||
}
|
||||
&.bg-amber {
|
||||
background: #fffbeb;
|
||||
}
|
||||
&.bg-orange {
|
||||
background: #fff7ed;
|
||||
}
|
||||
}
|
||||
|
||||
.biz-title {
|
||||
font-size: 28rpx;
|
||||
font-weight: 700;
|
||||
color: #1f2937;
|
||||
}
|
||||
|
||||
.biz-sub {
|
||||
font-size: 22rpx;
|
||||
color: #9ca3af;
|
||||
margin-top: 4rpx;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/* 弹窗遮罩 */
|
||||
.modal-mask {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background: rgba(0, 0, 0, 0.6);
|
||||
z-index: 999;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 40rpx;
|
||||
|
||||
.modal-card {
|
||||
background: #ffffff;
|
||||
width: 100%;
|
||||
max-width: 620rpx;
|
||||
border-radius: 28rpx;
|
||||
padding: 36rpx;
|
||||
|
||||
.modal-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 28rpx;
|
||||
|
||||
.modal-title {
|
||||
font-size: 32rpx;
|
||||
font-weight: 700;
|
||||
color: #111827;
|
||||
}
|
||||
}
|
||||
|
||||
.order-summary {
|
||||
background: #f9fafb;
|
||||
border-radius: 16rpx;
|
||||
padding: 24rpx;
|
||||
margin-bottom: 32rpx;
|
||||
|
||||
.summary-row {
|
||||
display: flex;
|
||||
font-size: 26rpx;
|
||||
margin-bottom: 14rpx;
|
||||
|
||||
&:last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.label {
|
||||
color: #6b7280;
|
||||
width: 150rpx;
|
||||
}
|
||||
|
||||
.value {
|
||||
color: #111827;
|
||||
flex: 1;
|
||||
|
||||
&.highlight-code {
|
||||
font-size: 32rpx;
|
||||
font-weight: 700;
|
||||
color: #10b981;
|
||||
}
|
||||
|
||||
&.goods-text {
|
||||
word-break: break-all;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.staff-picker-box {
|
||||
margin-top: 20rpx;
|
||||
padding-top: 20rpx;
|
||||
border-top: 1rpx dashed #e5e7eb;
|
||||
|
||||
.staff-label {
|
||||
font-size: 24rpx;
|
||||
color: #6b7280;
|
||||
display: block;
|
||||
margin-bottom: 12rpx;
|
||||
}
|
||||
|
||||
.picker-display {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
background: #ffffff;
|
||||
border: 1rpx solid #d1d5db;
|
||||
border-radius: 12rpx;
|
||||
padding: 16rpx 20rpx;
|
||||
font-size: 26rpx;
|
||||
color: #111827;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.modal-footer {
|
||||
display: flex;
|
||||
gap: 20rpx;
|
||||
|
||||
.modal-btn {
|
||||
flex: 1;
|
||||
height: 84rpx;
|
||||
border-radius: 16rpx;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: 30rpx;
|
||||
font-weight: 600;
|
||||
|
||||
&.cancel {
|
||||
background: #f3f4f6;
|
||||
color: #4b5563;
|
||||
}
|
||||
|
||||
&.confirm {
|
||||
background: #111827;
|
||||
color: #ffffff;
|
||||
|
||||
&.loading {
|
||||
opacity: 0.7;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
550
pages-sub/merchant/pages/login/index.vue
Normal file
550
pages-sub/merchant/pages/login/index.vue
Normal file
@@ -0,0 +1,550 @@
|
||||
<template>
|
||||
<view class="merchant-login-page">
|
||||
<!-- 顶部状态栏沉浸背景 -->
|
||||
<view class="header-bg">
|
||||
<view class="brand-box">
|
||||
<view class="badge-icon">
|
||||
<u-icon name="bag" size="32" color="#ffffff"></u-icon>
|
||||
</view>
|
||||
<text class="brand-title">商家管理工作台</text>
|
||||
<text class="brand-desc">随时随地 · 快捷扫码核销与订单管理</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 登录卡片 -->
|
||||
<view class="login-card">
|
||||
<!-- 模式切换 Tab -->
|
||||
<view class="tab-header">
|
||||
<view
|
||||
class="tab-item"
|
||||
:class="{ active: loginType === 'account' }"
|
||||
@click="switchTab('account')"
|
||||
>
|
||||
<text>账号密码登录</text>
|
||||
<view class="active-indicator" v-if="loginType === 'account'"></view>
|
||||
</view>
|
||||
<view
|
||||
class="tab-item"
|
||||
:class="{ active: loginType === 'sms' }"
|
||||
@click="switchTab('sms')"
|
||||
>
|
||||
<text>短信验证码登录</text>
|
||||
<view class="active-indicator" v-if="loginType === 'sms'"></view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 账号密码表单 -->
|
||||
<view class="form-container" v-if="loginType === 'account'">
|
||||
<view class="input-item">
|
||||
<u-input
|
||||
v-model="accountForm.username"
|
||||
placeholder="请输入商家账号/手机号"
|
||||
border="surround"
|
||||
prefixIcon="account"
|
||||
:prefixIconStyle="{ color: '#8c8c8c', fontSize: '36rpx', marginRight: '16rpx' }"
|
||||
:customStyle="customInputStyle"
|
||||
clearable
|
||||
/>
|
||||
</view>
|
||||
|
||||
<view class="input-item">
|
||||
<u-input
|
||||
v-model="accountForm.password"
|
||||
placeholder="请输入登录密码"
|
||||
type="password"
|
||||
border="surround"
|
||||
prefixIcon="lock"
|
||||
:prefixIconStyle="{ color: '#8c8c8c', fontSize: '36rpx', marginRight: '16rpx' }"
|
||||
:customStyle="customInputStyle"
|
||||
clearable
|
||||
/>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 短信验证码表单 -->
|
||||
<view class="form-container" v-else>
|
||||
<view class="input-item">
|
||||
<u-input
|
||||
v-model="smsForm.mobile"
|
||||
placeholder="请输入店主手机号"
|
||||
type="number"
|
||||
maxlength="11"
|
||||
border="surround"
|
||||
prefixIcon="phone"
|
||||
:prefixIconStyle="{ color: '#8c8c8c', fontSize: '36rpx', marginRight: '16rpx' }"
|
||||
:customStyle="customInputStyle"
|
||||
clearable
|
||||
/>
|
||||
</view>
|
||||
|
||||
<view class="input-item">
|
||||
<u-input
|
||||
v-model="smsForm.code"
|
||||
placeholder="请输入 6 位短信验证码"
|
||||
type="number"
|
||||
maxlength="6"
|
||||
border="surround"
|
||||
prefixIcon="email"
|
||||
:prefixIconStyle="{ color: '#8c8c8c', fontSize: '36rpx', marginRight: '16rpx' }"
|
||||
:customStyle="customInputStyle"
|
||||
clearable
|
||||
>
|
||||
<template #suffix>
|
||||
<view
|
||||
class="send-btn"
|
||||
:class="{ disabled: smsCount > 0 || !smsForm.mobile }"
|
||||
@click="handleSendSms"
|
||||
>
|
||||
<text>{{ smsCount > 0 ? `${smsCount}s后重试` : '获取验证码' }}</text>
|
||||
</view>
|
||||
</template>
|
||||
</u-input>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 登录提交按钮 -->
|
||||
<view class="action-btn" :class="{ loading: submitting }" @click="handleLogin">
|
||||
<text class="btn-text">{{ submitting ? '正在登录...' : '立即进入工作台' }}</text>
|
||||
</view>
|
||||
|
||||
<view class="notice-tip">
|
||||
<u-icon name="info-circle" size="14" color="#8c8c8c"></u-icon>
|
||||
<text class="notice-text">仅限已入驻商城的店主/店员账号登录</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
|
||||
|
||||
<!-- 安全滑块拼图验证码弹窗 -->
|
||||
<myVerification
|
||||
v-if="codeFlag"
|
||||
ref="verificationRef"
|
||||
apiType="store"
|
||||
business="LOGIN"
|
||||
@send="handleVerificationSuccess"
|
||||
/>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, reactive, onBeforeUnmount, nextTick } from 'vue'
|
||||
import { onLoad } from '@dcloudio/uni-app'
|
||||
import storage from '@/utils/storage.js'
|
||||
import myVerification from '@/components/verification/verification.vue'
|
||||
import {
|
||||
userLogin,
|
||||
smsLogin,
|
||||
sendStoreSms,
|
||||
getStoreSettings,
|
||||
getStoreUserInfo,
|
||||
getStoreDetail,
|
||||
} from '../../api/passport.js'
|
||||
|
||||
const loginType = ref<'account' | 'sms'>('account')
|
||||
const submitting = ref(false)
|
||||
const smsCount = ref(0)
|
||||
let timer: any = null
|
||||
|
||||
// 滑块验证码相关控制
|
||||
const codeFlag = ref(false)
|
||||
const verificationRef = ref<any>(null)
|
||||
const verifyAction = ref<'login' | 'sms'>('login')
|
||||
|
||||
const customInputStyle = {
|
||||
backgroundColor: '#f9fafb',
|
||||
borderRadius: '16rpx',
|
||||
height: '84rpx',
|
||||
paddingLeft: '16rpx',
|
||||
fontSize: '28rpx',
|
||||
}
|
||||
|
||||
const accountForm = reactive({
|
||||
username: '',
|
||||
password: '',
|
||||
})
|
||||
|
||||
const smsForm = reactive({
|
||||
mobile: '',
|
||||
code: '',
|
||||
})
|
||||
|
||||
onLoad(() => {
|
||||
// 如果已存在商家 token,直接进入工作台
|
||||
if (storage.getStoreAccessToken()) {
|
||||
uni.redirectTo({
|
||||
url: '/pages-sub/merchant/pages/index/index',
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
if (timer) {
|
||||
clearInterval(timer)
|
||||
timer = null
|
||||
}
|
||||
})
|
||||
|
||||
function switchTab(type: 'account' | 'sms') {
|
||||
loginType.value = type
|
||||
}
|
||||
|
||||
// 弹出滑块拼图验证码
|
||||
function openVerification(action: 'login' | 'sms') {
|
||||
verifyAction.value = action
|
||||
codeFlag.value = true
|
||||
nextTick(() => {
|
||||
verificationRef.value?.show()
|
||||
verificationRef.value?.getCode()
|
||||
})
|
||||
}
|
||||
|
||||
// 点击获取短信验证码
|
||||
const handleSendSms = () => {
|
||||
if (smsCount.value > 0) return
|
||||
if (!/^1[3-9]\d{9}$/.test(smsForm.mobile)) {
|
||||
uni.showToast({ title: '请输入正确的11位手机号', icon: 'none' })
|
||||
return
|
||||
}
|
||||
|
||||
// 发送短信验证码前先通过滑块拼图验证
|
||||
openVerification('sms')
|
||||
}
|
||||
|
||||
// 点击“立即进入工作台”按钮
|
||||
const handleLogin = () => {
|
||||
if (submitting.value) return
|
||||
|
||||
if (loginType.value === 'account') {
|
||||
if (!accountForm.username.trim()) {
|
||||
uni.showToast({ title: '请输入商家账号', icon: 'none' })
|
||||
return
|
||||
}
|
||||
if (!accountForm.password) {
|
||||
uni.showToast({ title: '请输入登录密码', icon: 'none' })
|
||||
return
|
||||
}
|
||||
|
||||
// 账号密码登录:必须先通过安全滑块拼图验证
|
||||
openVerification('login')
|
||||
} else {
|
||||
// 短信验证码登录
|
||||
if (!/^1[3-9]\d{9}$/.test(smsForm.mobile)) {
|
||||
uni.showToast({ title: '请输入有效的手机号', icon: 'none' })
|
||||
return
|
||||
}
|
||||
if (!smsForm.code.trim()) {
|
||||
uni.showToast({ title: '请输入验证码', icon: 'none' })
|
||||
return
|
||||
}
|
||||
// 短信验证码登录直接提交
|
||||
doSmsLogin()
|
||||
}
|
||||
}
|
||||
|
||||
// 滑块验证码成功回调
|
||||
const handleVerificationSuccess = () => {
|
||||
if (verifyAction.value === 'login') {
|
||||
doAccountLogin()
|
||||
} else if (verifyAction.value === 'sms') {
|
||||
doSendSms()
|
||||
}
|
||||
}
|
||||
|
||||
// 执行账号密码登录
|
||||
const doAccountLogin = async () => {
|
||||
submitting.value = true
|
||||
uni.showLoading({ title: '正在登录...' })
|
||||
|
||||
try {
|
||||
const res: any = await userLogin({
|
||||
username: accountForm.username.trim(),
|
||||
password: accountForm.password,
|
||||
})
|
||||
|
||||
uni.hideLoading()
|
||||
submitting.value = false
|
||||
|
||||
if (res?.data && res.data.success && res.data.result) {
|
||||
codeFlag.value = false
|
||||
const { accessToken, refreshToken } = res.data.result
|
||||
storage.setStoreAccessToken(accessToken)
|
||||
if (refreshToken) {
|
||||
storage.setStoreRefreshToken(refreshToken)
|
||||
}
|
||||
|
||||
// 获取店铺与店员信息
|
||||
try {
|
||||
const [settingsRes, userRes, storeRes] = (await Promise.all([
|
||||
getStoreSettings().catch(() => null),
|
||||
getStoreUserInfo().catch(() => null),
|
||||
getStoreDetail().catch(() => null),
|
||||
])) || []
|
||||
|
||||
const storeInfo = {
|
||||
settings: settingsRes?.data?.result || {},
|
||||
user: userRes?.data?.result || {},
|
||||
store: storeRes?.data?.result || {},
|
||||
}
|
||||
storage.setStoreInfo(storeInfo)
|
||||
} catch (e) {
|
||||
console.warn('获取店铺额外信息失败', e)
|
||||
}
|
||||
|
||||
uni.showToast({ title: '登录成功', icon: 'success' })
|
||||
setTimeout(() => {
|
||||
uni.redirectTo({
|
||||
url: '/pages-sub/merchant/pages/index/index',
|
||||
})
|
||||
}, 500)
|
||||
} else {
|
||||
uni.showToast({
|
||||
title: res?.data?.message || '登录失败,请检查账号密码',
|
||||
icon: 'none',
|
||||
})
|
||||
verificationRef.value?.getCode()
|
||||
}
|
||||
} catch (err: any) {
|
||||
uni.hideLoading()
|
||||
submitting.value = false
|
||||
verificationRef.value?.getCode()
|
||||
uni.showToast({
|
||||
title: err?.data?.message || '网络连接异常或账号密码错误',
|
||||
icon: 'none',
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// 执行发送短信验证码
|
||||
const doSendSms = async () => {
|
||||
try {
|
||||
uni.showLoading({ title: '发送中...' })
|
||||
const res = await sendStoreSms(smsForm.mobile, 'LOGIN')
|
||||
uni.hideLoading()
|
||||
if (res?.data && res.data.success) {
|
||||
codeFlag.value = false
|
||||
uni.showToast({ title: '验证码已发送', icon: 'success' })
|
||||
smsCount.value = 60
|
||||
timer = setInterval(() => {
|
||||
smsCount.value--
|
||||
if (smsCount.value <= 0) {
|
||||
clearInterval(timer)
|
||||
timer = null
|
||||
}
|
||||
}, 1000)
|
||||
} else {
|
||||
verificationRef.value?.getCode()
|
||||
uni.showToast({
|
||||
title: res?.data?.message || '发送失败,请稍后重试',
|
||||
icon: 'none',
|
||||
})
|
||||
}
|
||||
} catch (e: any) {
|
||||
uni.hideLoading()
|
||||
verificationRef.value?.getCode()
|
||||
uni.showToast({ title: e?.data?.message || '网络异常,发送失败', icon: 'none' })
|
||||
}
|
||||
}
|
||||
|
||||
// 执行短信登录
|
||||
const doSmsLogin = async () => {
|
||||
submitting.value = true
|
||||
uni.showLoading({ title: '正在登录...' })
|
||||
|
||||
try {
|
||||
const res: any = await smsLogin({
|
||||
mobile: smsForm.mobile.trim(),
|
||||
code: smsForm.code.trim(),
|
||||
})
|
||||
|
||||
uni.hideLoading()
|
||||
submitting.value = false
|
||||
|
||||
if (res?.data && res.data.success && res.data.result) {
|
||||
const { accessToken, refreshToken } = res.data.result
|
||||
storage.setStoreAccessToken(accessToken)
|
||||
if (refreshToken) {
|
||||
storage.setStoreRefreshToken(refreshToken)
|
||||
}
|
||||
|
||||
try {
|
||||
const [settingsRes, userRes, storeRes] = (await Promise.all([
|
||||
getStoreSettings().catch(() => null),
|
||||
getStoreUserInfo().catch(() => null),
|
||||
getStoreDetail().catch(() => null),
|
||||
])) || []
|
||||
|
||||
const storeInfo = {
|
||||
settings: settingsRes?.data?.result || {},
|
||||
user: userRes?.data?.result || {},
|
||||
store: storeRes?.data?.result || {},
|
||||
}
|
||||
storage.setStoreInfo(storeInfo)
|
||||
} catch (e) {
|
||||
console.warn('获取店铺额外信息失败', e)
|
||||
}
|
||||
|
||||
uni.showToast({ title: '登录成功', icon: 'success' })
|
||||
setTimeout(() => {
|
||||
uni.redirectTo({
|
||||
url: '/pages-sub/merchant/pages/index/index',
|
||||
})
|
||||
}, 500)
|
||||
} else {
|
||||
uni.showToast({
|
||||
title: res?.data?.message || '登录失败,请检查验证码',
|
||||
icon: 'none',
|
||||
})
|
||||
}
|
||||
} catch (err: any) {
|
||||
uni.hideLoading()
|
||||
submitting.value = false
|
||||
uni.showToast({ title: err?.data?.message || '网络连接异常', icon: 'none' })
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.merchant-login-page {
|
||||
min-height: 100vh;
|
||||
background-color: #f7f8fa;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.header-bg {
|
||||
background: linear-gradient(135deg, #1f2937 0%, #111827 100%);
|
||||
padding: 100rpx 40rpx 140rpx 40rpx;
|
||||
color: #ffffff;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
|
||||
.brand-box {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
text-align: center;
|
||||
|
||||
.badge-icon {
|
||||
width: 100rpx;
|
||||
height: 100rpx;
|
||||
border-radius: 24rpx;
|
||||
background: rgba(255, 255, 255, 0.12);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
margin-bottom: 24rpx;
|
||||
}
|
||||
|
||||
.brand-title {
|
||||
font-size: 38rpx;
|
||||
font-weight: 700;
|
||||
letter-spacing: 2rpx;
|
||||
margin-bottom: 12rpx;
|
||||
}
|
||||
|
||||
.brand-desc {
|
||||
font-size: 24rpx;
|
||||
color: rgba(255, 255, 255, 0.65);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.login-card {
|
||||
margin: -80rpx 32rpx 40rpx 32rpx;
|
||||
background: #ffffff;
|
||||
border-radius: 28rpx;
|
||||
padding: 40rpx 36rpx;
|
||||
box-shadow: 0 12rpx 36rpx rgba(0, 0, 0, 0.06);
|
||||
|
||||
.tab-header {
|
||||
display: flex;
|
||||
border-bottom: 1rpx solid #f0f0f0;
|
||||
margin-bottom: 36rpx;
|
||||
|
||||
.tab-item {
|
||||
flex: 1;
|
||||
text-align: center;
|
||||
padding-bottom: 24rpx;
|
||||
font-size: 30rpx;
|
||||
color: #8c8c8c;
|
||||
font-weight: 500;
|
||||
position: relative;
|
||||
|
||||
&.active {
|
||||
color: #111827;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.active-indicator {
|
||||
position: absolute;
|
||||
bottom: -1rpx;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
width: 48rpx;
|
||||
height: 6rpx;
|
||||
background: #111827;
|
||||
border-radius: 3rpx;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.form-container {
|
||||
.input-item {
|
||||
margin-bottom: 28rpx;
|
||||
|
||||
.send-btn {
|
||||
padding: 10rpx 20rpx;
|
||||
background: #111827;
|
||||
color: #ffffff;
|
||||
border-radius: 10rpx;
|
||||
font-size: 24rpx;
|
||||
white-space: nowrap;
|
||||
|
||||
&.disabled {
|
||||
background: #d1d5db;
|
||||
color: #9ca3af;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.action-btn {
|
||||
background: #111827;
|
||||
border-radius: 18rpx;
|
||||
height: 92rpx;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
margin-top: 32rpx;
|
||||
box-shadow: 0 8rpx 20rpx rgba(17, 24, 39, 0.2);
|
||||
|
||||
.btn-text {
|
||||
color: #ffffff;
|
||||
font-size: 32rpx;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
&.loading {
|
||||
opacity: 0.7;
|
||||
}
|
||||
}
|
||||
|
||||
.notice-tip {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
margin-top: 28rpx;
|
||||
gap: 8rpx;
|
||||
|
||||
.notice-text {
|
||||
font-size: 22rpx;
|
||||
color: #9ca3af;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
</style>
|
||||
586
pages-sub/merchant/pages/order/detail.vue
Normal file
586
pages-sub/merchant/pages/order/detail.vue
Normal file
@@ -0,0 +1,586 @@
|
||||
<template>
|
||||
<view class="merchant-order-detail">
|
||||
<!-- 状态头部 -->
|
||||
<view class="status-banner" :class="getStatusClass(orderDetail?.order?.orderStatus)">
|
||||
<view class="status-icon">
|
||||
<u-icon :name="getStatusIcon(orderDetail?.order?.orderStatus)" size="28" color="#ffffff"></u-icon>
|
||||
</view>
|
||||
<view class="status-text-box">
|
||||
<text class="status-title">{{ getStatusText(orderDetail?.order?.orderStatus) }}</text>
|
||||
<view class="sn-row" @click="copySn(orderSn)">
|
||||
<text class="status-sub">订单编号:{{ orderSn }}</text>
|
||||
<u-icon name="file-text" size="13" color="rgba(255,255,255,0.8)"></u-icon>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 核销码专属卡片 -->
|
||||
<view class="verify-code-card" v-if="orderDetail?.order?.verificationCode || isAppointment">
|
||||
<view class="card-title-row">
|
||||
<text class="card-title">核销凭证</text>
|
||||
<view class="code-badge">
|
||||
{{ isAppointment ? '预约核销' : '自提核销' }}
|
||||
</view>
|
||||
</view>
|
||||
<view class="code-box">
|
||||
<text class="code-number">{{ orderDetail?.order?.verificationCode || '--' }}</text>
|
||||
<view
|
||||
class="verify-now-btn"
|
||||
v-if="orderDetail?.order?.orderStatus === 'TAKE'"
|
||||
@click="handleDirectVerify"
|
||||
>
|
||||
立即核销
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 买家 / 收货信息 -->
|
||||
<view class="info-card">
|
||||
<view class="card-title-row">
|
||||
<text class="card-title">买家信息</text>
|
||||
</view>
|
||||
<view class="info-row">
|
||||
<text class="info-label">收货人/自提人:</text>
|
||||
<text class="info-value">{{ orderDetail?.order?.consigneeName || '匿名买家' }}</text>
|
||||
</view>
|
||||
<view class="info-row">
|
||||
<text class="info-label">联系电话:</text>
|
||||
<text class="info-value">{{ maskPhone(orderDetail?.order?.consigneeMobile) }}</text>
|
||||
</view>
|
||||
<view class="info-row" v-if="orderDetail?.order?.consigneeAddressPath">
|
||||
<text class="info-label">地址:</text>
|
||||
<text class="info-value">{{ orderDetail?.order?.consigneeAddressPath }} {{ orderDetail?.order?.consigneeDetail || '' }}</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 商品清单(干净规范,拒绝裸露 JSON) -->
|
||||
<view class="info-card">
|
||||
<view class="card-title-row">
|
||||
<text class="card-title">商品清单</text>
|
||||
</view>
|
||||
<view
|
||||
class="goods-row"
|
||||
v-for="(item, idx) in (orderDetail?.orderItems || [])"
|
||||
:key="item.id || item.goodsId || idx"
|
||||
>
|
||||
<image class="goods-img" :src="getGoodsImage(item)" mode="aspectFill"></image>
|
||||
<view class="goods-detail">
|
||||
<text class="goods-title">{{ getGoodsTitle(item) }}</text>
|
||||
<view class="sku-tag" v-if="getCleanSpecs(item)">
|
||||
<text>{{ getCleanSpecs(item) }}</text>
|
||||
</view>
|
||||
<view class="goods-bottom">
|
||||
<text class="price">¥{{ item.unitPrice || item.goodsPrice || '0.00' }}</text>
|
||||
<text class="qty">x{{ item.num || 1 }}</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 订单财务明细 -->
|
||||
<view class="info-card">
|
||||
<view class="card-title-row">
|
||||
<text class="card-title">费用明细</text>
|
||||
</view>
|
||||
<view class="fee-row">
|
||||
<text class="fee-label">商品总价</text>
|
||||
<text class="fee-val">¥{{ orderDetail?.order?.goodsPrice || '0.00' }}</text>
|
||||
</view>
|
||||
<view class="fee-row" v-if="orderDetail?.order?.discountPrice">
|
||||
<text class="fee-label">优惠金额</text>
|
||||
<text class="fee-val discount">-¥{{ orderDetail?.order?.discountPrice }}</text>
|
||||
</view>
|
||||
<view class="fee-row" v-if="orderDetail?.order?.freightPrice">
|
||||
<text class="fee-label">运费</text>
|
||||
<text class="fee-val">+¥{{ orderDetail?.order?.freightPrice }}</text>
|
||||
</view>
|
||||
<view class="fee-divider"></view>
|
||||
<view class="fee-row total">
|
||||
<text class="fee-label">实收金额</text>
|
||||
<text class="fee-val total-price">¥{{ orderDetail?.order?.flowPrice || '0.00' }}</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 订单参数(支付方式中文人性化映射) -->
|
||||
<view class="info-card">
|
||||
<view class="info-row">
|
||||
<text class="info-label">下单时间:</text>
|
||||
<text class="info-value">{{ orderDetail?.order?.createTime || '--' }}</text>
|
||||
</view>
|
||||
<view class="info-row" v-if="orderDetail?.order?.paymentTime">
|
||||
<text class="info-label">支付时间:</text>
|
||||
<text class="info-value">{{ orderDetail?.order?.paymentTime }}</text>
|
||||
</view>
|
||||
<view class="info-row" v-if="orderDetail?.order?.paymentMethod">
|
||||
<text class="info-label">支付方式:</text>
|
||||
<text class="info-value pay-method-val">{{ formatPaymentMethod(orderDetail?.order?.paymentMethod) }}</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, computed } from 'vue'
|
||||
import { onLoad } from '@dcloudio/uni-app'
|
||||
import { getStoreOrderDetail, storeOrderTake } from '../../api/order.js'
|
||||
import { parseGoodsImageUrl } from '@/utils/filters.js'
|
||||
|
||||
const orderSn = ref('')
|
||||
const orderDetail = ref<any>(null)
|
||||
|
||||
const isAppointment = computed(() => {
|
||||
return orderDetail.value?.order?.orderType === 'APPOINTMENT_GOODS'
|
||||
})
|
||||
|
||||
onLoad((options: any) => {
|
||||
if (options?.sn) {
|
||||
orderSn.value = options.sn
|
||||
fetchDetail()
|
||||
}
|
||||
})
|
||||
|
||||
const fetchDetail = async () => {
|
||||
uni.showLoading({ title: '加载中...' })
|
||||
try {
|
||||
const res: any = await getStoreOrderDetail(orderSn.value)
|
||||
uni.hideLoading()
|
||||
if (res?.data && res.data.success && res.data.result) {
|
||||
orderDetail.value = res.data.result
|
||||
} else {
|
||||
uni.showToast({ title: '获取订单详情失败', icon: 'none' })
|
||||
}
|
||||
} catch (e) {
|
||||
uni.hideLoading()
|
||||
uni.showToast({ title: '网络连接异常', icon: 'none' })
|
||||
}
|
||||
}
|
||||
|
||||
// 复制单号
|
||||
const copySn = (sn: string) => {
|
||||
if (!sn) return
|
||||
uni.setClipboardData({
|
||||
data: sn,
|
||||
success: () => {
|
||||
uni.showToast({ title: '单号已复制', icon: 'none' })
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
// 提取商品标题
|
||||
const getGoodsTitle = (item: any) => {
|
||||
if (item.goodsName && item.goodsName.trim()) return item.goodsName
|
||||
if (item.name && item.name.trim()) return item.name
|
||||
if (orderDetail.value?.order?.orderName) return orderDetail.value.order.orderName
|
||||
return '精选商品'
|
||||
}
|
||||
|
||||
// 智能提取商品图片,过滤并兼顾富文本/JSON 结构
|
||||
const getGoodsImage = (item: any) => {
|
||||
if (item.image) {
|
||||
const parsed = parseGoodsImageUrl(item.image)
|
||||
if (parsed) return parsed
|
||||
}
|
||||
// 若 image 为空,尝试从 specs JSON 里抓取合法的图片 url
|
||||
if (item.specs && typeof item.specs === 'string') {
|
||||
const match = item.specs.match(/https?:\/\/[^\s"'\\}]+\.(jpeg|jpg|png|webp|gif)/i)
|
||||
if (match) return match[0]
|
||||
}
|
||||
return '/static/tabbar/home.png'
|
||||
}
|
||||
|
||||
// 智能提炼清洁规格,绝不裸露冗长的原始 JSON
|
||||
const getCleanSpecs = (item: any) => {
|
||||
const specs = item.specs
|
||||
if (!specs || !String(specs).trim()) return ''
|
||||
const trimmed = String(specs).trim()
|
||||
|
||||
// 若为 JSON 格式
|
||||
if (trimmed.startsWith('{') || trimmed.startsWith('[')) {
|
||||
try {
|
||||
const obj = JSON.parse(trimmed)
|
||||
const ignoreKeys = ['images', 'code', 'message', 'result', 'success', 'showProgress', 'url', 'status']
|
||||
const pairs: string[] = []
|
||||
for (const [k, v] of Object.entries(obj)) {
|
||||
if (!ignoreKeys.includes(k) && typeof v === 'string' && !v.startsWith('http') && v.length < 50) {
|
||||
pairs.push(`${k}: ${v}`)
|
||||
}
|
||||
}
|
||||
if (pairs.length > 0) return pairs.join(' / ')
|
||||
} catch (e) {}
|
||||
|
||||
// 解析失败正则提取业务键值对
|
||||
const matches = [...trimmed.matchAll(/"([^"]{1,20})"\s*:\s*"([^"]{1,30})"/g)]
|
||||
const ignoreKeys = ['code', 'message', 'success', 'url', 'result', 'showProgress', 'status', 'name']
|
||||
const pairs: string[] = []
|
||||
for (const m of matches) {
|
||||
const k = m[1]
|
||||
const v = m[2]
|
||||
if (!ignoreKeys.includes(k) && !v.startsWith('http')) {
|
||||
pairs.push(`${k}: ${v}`)
|
||||
}
|
||||
}
|
||||
if (pairs.length > 0) return pairs.join(' / ')
|
||||
|
||||
return ''
|
||||
}
|
||||
|
||||
// 纯文本规格
|
||||
return trimmed
|
||||
}
|
||||
|
||||
// 支付方式中文映射
|
||||
const formatPaymentMethod = (method: string) => {
|
||||
if (!method) return '--'
|
||||
const map: Record<string, string> = {
|
||||
WALLET: '余额支付',
|
||||
ALIPAY: '支付宝支付',
|
||||
ALIPAY_PC: '支付宝支付',
|
||||
ALIPAY_WAP: '支付宝支付',
|
||||
ALIPAY_APP: '支付宝支付',
|
||||
WECHAT: '微信支付',
|
||||
WEIXIN: '微信支付',
|
||||
WECHAT_MP: '微信支付',
|
||||
WEIXIN_MP: '微信支付',
|
||||
WX_JSAPI: '微信支付',
|
||||
WX_APP: '微信支付',
|
||||
WX_NATIVE: '微信支付',
|
||||
WX_H5: '微信支付',
|
||||
BANK_TRANSFER: '银行转账',
|
||||
POINT: '积分兑换',
|
||||
CASH: '现金支付',
|
||||
OFFLINE: '线下支付',
|
||||
FREE: '免费免付',
|
||||
}
|
||||
const key = String(method).toUpperCase().trim()
|
||||
return map[key] || method
|
||||
}
|
||||
|
||||
const maskPhone = (phone: string) => {
|
||||
if (!phone || phone.length < 7) return phone || ''
|
||||
return phone.replace(/(\d{3})\d{4}(\d{4})/, '$1****$2')
|
||||
}
|
||||
|
||||
const getStatusText = (status: string) => {
|
||||
const map: Record<string, string> = {
|
||||
UNPAID: '待付款',
|
||||
PAID: '已付款',
|
||||
UNDELIVERED: '待发货',
|
||||
DELIVERED: '待收货',
|
||||
COMPLETED: '已完成',
|
||||
CANCELLED: '已取消',
|
||||
TAKE: '待核销',
|
||||
}
|
||||
return map[status] || status || '处理中'
|
||||
}
|
||||
|
||||
const getStatusClass = (status: string) => {
|
||||
if (status === 'TAKE') return 'bg-take'
|
||||
if (status === 'COMPLETED') return 'bg-done'
|
||||
if (status === 'CANCELLED') return 'bg-cancel'
|
||||
return 'bg-normal'
|
||||
}
|
||||
|
||||
const getStatusIcon = (status: string) => {
|
||||
if (status === 'TAKE') return 'checkmark-circle-fill'
|
||||
if (status === 'COMPLETED') return 'checkmark'
|
||||
if (status === 'CANCELLED') return 'close'
|
||||
return 'clock'
|
||||
}
|
||||
|
||||
// 直接在详情页核销
|
||||
const handleDirectVerify = async () => {
|
||||
const code = orderDetail.value?.order?.verificationCode
|
||||
if (!code) {
|
||||
uni.showToast({ title: '该订单暂无可核销码', icon: 'none' })
|
||||
return
|
||||
}
|
||||
|
||||
uni.showModal({
|
||||
title: '确认核销',
|
||||
content: `确认核销此单?核销码:${code}`,
|
||||
success: async (res) => {
|
||||
if (res.confirm) {
|
||||
uni.showLoading({ title: '正在核销...' })
|
||||
try {
|
||||
const takeRes: any = await storeOrderTake(orderSn.value, code)
|
||||
uni.hideLoading()
|
||||
if (takeRes?.data && takeRes.data.success) {
|
||||
uni.showToast({ title: '核销成功', icon: 'success' })
|
||||
fetchDetail()
|
||||
} else {
|
||||
uni.showToast({
|
||||
title: takeRes?.data?.message || '核销失败',
|
||||
icon: 'none',
|
||||
})
|
||||
}
|
||||
} catch (e) {
|
||||
uni.hideLoading()
|
||||
uni.showToast({ title: '核销异常,请稍后重试', icon: 'none' })
|
||||
}
|
||||
}
|
||||
},
|
||||
})
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.merchant-order-detail {
|
||||
min-height: 100vh;
|
||||
background-color: #f4f5f7;
|
||||
padding-bottom: calc(50rpx + env(safe-area-inset-bottom));
|
||||
}
|
||||
|
||||
.status-banner {
|
||||
padding: 44rpx 36rpx;
|
||||
color: #ffffff;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
|
||||
&.bg-take {
|
||||
background: linear-gradient(135deg, #10b981 0%, #059669 100%);
|
||||
}
|
||||
&.bg-normal {
|
||||
background: linear-gradient(135deg, #1f2937 0%, #111827 100%);
|
||||
}
|
||||
&.bg-done {
|
||||
background: #6b7280;
|
||||
}
|
||||
&.bg-cancel {
|
||||
background: #9ca3af;
|
||||
}
|
||||
|
||||
.status-icon {
|
||||
width: 68rpx;
|
||||
height: 68rpx;
|
||||
border-radius: 34rpx;
|
||||
background: rgba(255, 255, 255, 0.2);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
margin-right: 20rpx;
|
||||
}
|
||||
|
||||
.status-text-box {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
.status-title {
|
||||
font-size: 36rpx;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.sn-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8rpx;
|
||||
margin-top: 8rpx;
|
||||
|
||||
.status-sub {
|
||||
font-size: 24rpx;
|
||||
color: rgba(255, 255, 255, 0.85);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.verify-code-card {
|
||||
margin: -24rpx 28rpx 24rpx 28rpx;
|
||||
background: #ffffff;
|
||||
border-radius: 24rpx;
|
||||
padding: 28rpx;
|
||||
box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.05);
|
||||
|
||||
.card-title-row {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 20rpx;
|
||||
|
||||
.card-title {
|
||||
font-size: 28rpx;
|
||||
font-weight: 700;
|
||||
color: #111827;
|
||||
}
|
||||
|
||||
.code-badge {
|
||||
font-size: 22rpx;
|
||||
font-weight: 500;
|
||||
color: #059669;
|
||||
background: #ecfdf5;
|
||||
padding: 4rpx 14rpx;
|
||||
border-radius: 8rpx;
|
||||
}
|
||||
}
|
||||
|
||||
.code-box {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
background: #f9fafb;
|
||||
border-radius: 16rpx;
|
||||
padding: 20rpx 28rpx;
|
||||
|
||||
.code-number {
|
||||
font-size: 44rpx;
|
||||
font-weight: 700;
|
||||
color: #10b981;
|
||||
letter-spacing: 4rpx;
|
||||
}
|
||||
|
||||
.verify-now-btn {
|
||||
background: #111827;
|
||||
color: #ffffff;
|
||||
padding: 14rpx 32rpx;
|
||||
border-radius: 14rpx;
|
||||
font-size: 26rpx;
|
||||
font-weight: 600;
|
||||
box-shadow: 0 4rpx 12rpx rgba(17, 24, 39, 0.2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.info-card {
|
||||
margin: 0 28rpx 24rpx 28rpx;
|
||||
background: #ffffff;
|
||||
border-radius: 24rpx;
|
||||
padding: 28rpx;
|
||||
box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.02);
|
||||
|
||||
.card-title-row {
|
||||
margin-bottom: 20rpx;
|
||||
padding-bottom: 14rpx;
|
||||
border-bottom: 1rpx solid #f9fafb;
|
||||
|
||||
.card-title {
|
||||
font-size: 28rpx;
|
||||
font-weight: 700;
|
||||
color: #111827;
|
||||
}
|
||||
}
|
||||
|
||||
.info-row {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
font-size: 26rpx;
|
||||
margin-bottom: 16rpx;
|
||||
|
||||
&:last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.info-label {
|
||||
color: #6b7280;
|
||||
width: 180rpx;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.info-value {
|
||||
color: #111827;
|
||||
flex: 1;
|
||||
font-weight: 500;
|
||||
line-height: 1.4;
|
||||
|
||||
&.pay-method-val {
|
||||
color: #2563eb;
|
||||
font-weight: 600;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.goods-row {
|
||||
display: flex;
|
||||
padding: 18rpx 0;
|
||||
border-bottom: 1rpx solid #f9fafb;
|
||||
|
||||
&:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
.goods-img {
|
||||
width: 140rpx;
|
||||
height: 140rpx;
|
||||
border-radius: 14rpx;
|
||||
background: #f9fafb;
|
||||
border: 1rpx solid #f3f4f6;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.goods-detail {
|
||||
flex: 1;
|
||||
margin-left: 20rpx;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: space-between;
|
||||
|
||||
.goods-title {
|
||||
font-size: 28rpx;
|
||||
color: #111827;
|
||||
font-weight: 600;
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
.sku-tag {
|
||||
margin-top: 6rpx;
|
||||
|
||||
text {
|
||||
font-size: 22rpx;
|
||||
color: #6b7280;
|
||||
background: #f3f4f6;
|
||||
padding: 4rpx 12rpx;
|
||||
border-radius: 6rpx;
|
||||
}
|
||||
}
|
||||
|
||||
.goods-bottom {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: baseline;
|
||||
margin-top: 10rpx;
|
||||
|
||||
.price {
|
||||
font-size: 30rpx;
|
||||
font-weight: 700;
|
||||
color: #111827;
|
||||
}
|
||||
|
||||
.qty {
|
||||
font-size: 22rpx;
|
||||
color: #9ca3af;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.fee-row {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
font-size: 26rpx;
|
||||
margin-bottom: 14rpx;
|
||||
color: #6b7280;
|
||||
|
||||
.discount {
|
||||
color: #10b981;
|
||||
}
|
||||
|
||||
&.total {
|
||||
margin-top: 16rpx;
|
||||
margin-bottom: 0;
|
||||
font-size: 28rpx;
|
||||
font-weight: 700;
|
||||
color: #111827;
|
||||
|
||||
.total-price {
|
||||
font-size: 36rpx;
|
||||
font-weight: 700;
|
||||
color: #ef4444;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.fee-divider {
|
||||
height: 1rpx;
|
||||
background: #f3f4f6;
|
||||
margin: 16rpx 0;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
653
pages-sub/merchant/pages/order/list.vue
Normal file
653
pages-sub/merchant/pages/order/list.vue
Normal file
@@ -0,0 +1,653 @@
|
||||
<template>
|
||||
<view class="merchant-order-page">
|
||||
<!-- 顶部吸顶搜索栏与 Tab -->
|
||||
<view class="sticky-header">
|
||||
<!-- 搜索栏 -->
|
||||
<view class="search-box">
|
||||
<view class="search-input-wrap">
|
||||
<u-icon name="search" size="18" color="#9ca3af"></u-icon>
|
||||
<input
|
||||
class="search-input"
|
||||
type="text"
|
||||
v-model="keywords"
|
||||
placeholder="搜索订单号 / 买家手机号"
|
||||
placeholder-class="placeholder"
|
||||
confirm-type="search"
|
||||
@confirm="onSearch"
|
||||
/>
|
||||
<view class="clear-btn" v-if="keywords" @click="clearSearch">
|
||||
<u-icon name="close-circle-fill" size="16" color="#d1d5db"></u-icon>
|
||||
</view>
|
||||
</view>
|
||||
<view class="search-action-btn" v-if="keywords" @click="onSearch">
|
||||
<text>搜索</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 状态横向滑动 Tab 栏(绝不折行) -->
|
||||
<scroll-view class="tab-scroll" scroll-x :show-scrollbar="false" :scroll-with-animation="true">
|
||||
<view class="tab-inner">
|
||||
<view
|
||||
class="tab-item"
|
||||
v-for="item in tabList"
|
||||
:key="item.key"
|
||||
:class="{ active: currentTab === item.key }"
|
||||
@click="switchTab(item.key)"
|
||||
>
|
||||
<text class="tab-label">{{ item.label }}</text>
|
||||
<view class="indicator" v-if="currentTab === item.key"></view>
|
||||
</view>
|
||||
</view>
|
||||
</scroll-view>
|
||||
</view>
|
||||
|
||||
<!-- 订单列表主体 -->
|
||||
<view class="order-list-body">
|
||||
<!-- 列表数据 -->
|
||||
<view
|
||||
class="order-card"
|
||||
v-for="order in orderList"
|
||||
:key="order.sn"
|
||||
@click="goToDetail(order.sn)"
|
||||
>
|
||||
<!-- 头部:单号与状态 -->
|
||||
<view class="card-head">
|
||||
<view class="sn-box" @click.stop="copySn(order.sn)">
|
||||
<text class="order-sn">单号:{{ order.sn }}</text>
|
||||
<u-icon name="file-text" size="14" color="#9ca3af"></u-icon>
|
||||
</view>
|
||||
<view class="status-badge" :class="getStatusClass(order.orderStatus)">
|
||||
{{ getStatusText(order.orderStatus) }}
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 商品信息 -->
|
||||
<view class="goods-container">
|
||||
<view
|
||||
class="goods-item"
|
||||
v-for="goods in (order.orderItems || [])"
|
||||
:key="goods.id || goods.goodsId"
|
||||
>
|
||||
<image class="goods-thumb" :src="goods.image || '/static/tabbar/home.png'" mode="aspectFill"></image>
|
||||
<view class="goods-info">
|
||||
<text class="goods-name">{{ getGoodsName(goods, order) }}</text>
|
||||
<view class="spec-pill" v-if="getSpecText(goods)">
|
||||
<text>{{ getSpecText(goods) }}</text>
|
||||
</view>
|
||||
<view class="price-qty-row">
|
||||
<text class="goods-price">¥{{ goods.unitPrice || goods.goodsPrice || '0.00' }}</text>
|
||||
<text class="goods-qty">x{{ goods.num || 1 }}</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 订单金额与买家信息 -->
|
||||
<view class="card-foot">
|
||||
<view class="buyer-info" v-if="order.consigneeMobile || order.memberPhone">
|
||||
<u-icon name="account" size="14" color="#9ca3af"></u-icon>
|
||||
<text class="buyer-tel">{{ maskPhone(order.consigneeMobile || order.memberPhone) }}</text>
|
||||
</view>
|
||||
<view class="buyer-info" v-else>
|
||||
<text class="order-type-tag" v-if="order.orderType === 'APPOINTMENT_GOODS'">预约商品单</text>
|
||||
<text class="order-type-tag" v-else-if="order.verificationCode">自提单</text>
|
||||
</view>
|
||||
|
||||
<view class="total-bar">
|
||||
<text class="total-label">实付:</text>
|
||||
<text class="total-symbol">¥</text>
|
||||
<text class="total-price">{{ order.flowPrice || '0.00' }}</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 核销专属快捷动作 -->
|
||||
<view class="card-actions" v-if="order.verificationCode || order.orderType === 'APPOINTMENT_GOODS' || order.orderStatus === 'TAKE'">
|
||||
<view class="action-btn verify" @click.stop="quickVerify(order)">
|
||||
<u-icon name="scan" size="15" color="#ffffff"></u-icon>
|
||||
<text class="btn-lbl">扫码/输码核销</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 空状态 -->
|
||||
<view class="empty-state" v-if="!loading && orderList.length === 0">
|
||||
<u-icon name="order" size="64" color="#d1d5db"></u-icon>
|
||||
<text class="empty-text">暂无相关订单记录</text>
|
||||
</view>
|
||||
|
||||
<!-- 加载提示 -->
|
||||
<view class="loading-more" v-if="loading">
|
||||
<text>正在加载订单数据...</text>
|
||||
</view>
|
||||
<view class="no-more" v-else-if="finished && orderList.length > 0">
|
||||
<text>— 没有更多了 —</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref } from 'vue'
|
||||
import { onLoad, onPullDownRefresh, onReachBottom } from '@dcloudio/uni-app'
|
||||
import { getStoreOrderList } from '../../api/order.js'
|
||||
|
||||
const keywords = ref('')
|
||||
const currentTab = ref('ALL')
|
||||
const loading = ref(false)
|
||||
const finished = ref(false)
|
||||
const pageNumber = ref(1)
|
||||
const pageSize = ref(10)
|
||||
const orderList = ref<any[]>([])
|
||||
|
||||
// 优化 Tab 标题,保持精练统一、绝不换行
|
||||
const tabList = [
|
||||
{ key: 'ALL', label: '全部' },
|
||||
{ key: 'TAKE', label: '待核销' },
|
||||
{ key: 'UNDELIVERED', label: '待发货' },
|
||||
{ key: 'DELIVERED', label: '待收货' },
|
||||
{ key: 'COMPLETED', label: '已完成' },
|
||||
]
|
||||
|
||||
onLoad((options: any) => {
|
||||
if (options?.tab) {
|
||||
currentTab.value = options.tab
|
||||
}
|
||||
fetchOrders(true)
|
||||
})
|
||||
|
||||
onPullDownRefresh(async () => {
|
||||
await fetchOrders(true)
|
||||
uni.stopPullDownRefresh()
|
||||
})
|
||||
|
||||
onReachBottom(() => {
|
||||
if (!finished.value && !loading.value) {
|
||||
pageNumber.value++
|
||||
fetchOrders(false)
|
||||
}
|
||||
})
|
||||
|
||||
const fetchOrders = async (reset = false) => {
|
||||
if (reset) {
|
||||
pageNumber.value = 1
|
||||
orderList.value = []
|
||||
finished.value = false
|
||||
}
|
||||
|
||||
loading.value = true
|
||||
|
||||
const params: any = {
|
||||
pageNumber: pageNumber.value,
|
||||
pageSize: pageSize.value,
|
||||
keywords: keywords.value.trim() || undefined,
|
||||
}
|
||||
|
||||
if (currentTab.value !== 'ALL') {
|
||||
params.orderStatus = currentTab.value
|
||||
}
|
||||
|
||||
try {
|
||||
const res: any = await getStoreOrderList(params)
|
||||
loading.value = false
|
||||
|
||||
if (res?.data && res.data.success) {
|
||||
const records = res.data.result?.records || []
|
||||
if (reset) {
|
||||
orderList.value = records
|
||||
} else {
|
||||
orderList.value = [...orderList.value, ...records]
|
||||
}
|
||||
|
||||
if (records.length < pageSize.value) {
|
||||
finished.value = true
|
||||
}
|
||||
} else {
|
||||
uni.showToast({
|
||||
title: res?.data?.message || '获取订单列表失败',
|
||||
icon: 'none',
|
||||
})
|
||||
}
|
||||
} catch (e) {
|
||||
loading.value = false
|
||||
uni.showToast({ title: '网络连接异常', icon: 'none' })
|
||||
}
|
||||
}
|
||||
|
||||
const switchTab = (key: string) => {
|
||||
if (currentTab.value === key) return
|
||||
currentTab.value = key
|
||||
fetchOrders(true)
|
||||
}
|
||||
|
||||
const onSearch = () => {
|
||||
fetchOrders(true)
|
||||
}
|
||||
|
||||
const clearSearch = () => {
|
||||
keywords.value = ''
|
||||
fetchOrders(true)
|
||||
}
|
||||
|
||||
const goToDetail = (sn: string) => {
|
||||
uni.navigateTo({
|
||||
url: `/pages-sub/merchant/pages/order/detail?sn=${sn}`,
|
||||
})
|
||||
}
|
||||
|
||||
// 快捷核销
|
||||
const quickVerify = (order: any) => {
|
||||
uni.navigateTo({
|
||||
url: `/pages-sub/merchant/pages/order/detail?sn=${order.sn}&autoVerify=1`,
|
||||
})
|
||||
}
|
||||
|
||||
// 复制单号
|
||||
const copySn = (sn: string) => {
|
||||
if (!sn) return
|
||||
uni.setClipboardData({
|
||||
data: sn,
|
||||
success: () => {
|
||||
uni.showToast({ title: '单号已复制', icon: 'none' })
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
// 提取商品名(容错兜底)
|
||||
const getGoodsName = (goods: any, order: any) => {
|
||||
if (goods.goodsName && goods.goodsName.trim()) return goods.goodsName
|
||||
if (goods.name && goods.name.trim()) return goods.name
|
||||
if (order.orderName && order.orderName.trim()) return order.orderName
|
||||
if (goods.specs && goods.specs.trim()) return goods.specs
|
||||
return '精选商品'
|
||||
}
|
||||
|
||||
// 提取规格文本(智能剔除多余字段)
|
||||
const getSpecText = (goods: any) => {
|
||||
const specs = goods.specs
|
||||
if (!specs || !String(specs).trim()) return ''
|
||||
if (specs === goods.goodsName) return ''
|
||||
|
||||
// 处理 JSON 字符串形式
|
||||
if (typeof specs === 'string' && (specs.startsWith('{') || specs.startsWith('['))) {
|
||||
try {
|
||||
const obj = JSON.parse(specs)
|
||||
if (typeof obj === 'object') {
|
||||
const values = Object.values(obj).filter(Boolean)
|
||||
if (values.length) return values.join(' / ')
|
||||
}
|
||||
} catch (e) {}
|
||||
}
|
||||
return String(specs)
|
||||
}
|
||||
|
||||
// 手机号脱敏
|
||||
const maskPhone = (phone: string) => {
|
||||
if (!phone) return ''
|
||||
const str = String(phone).trim()
|
||||
if (str.length === 11) {
|
||||
return str.substring(0, 3) + '****' + str.substring(7)
|
||||
}
|
||||
return str
|
||||
}
|
||||
|
||||
// 状态文字映射
|
||||
const getStatusText = (status: string) => {
|
||||
const map: Record<string, string> = {
|
||||
UNPAID: '待付款',
|
||||
PAID: '已付款',
|
||||
UNDELIVERED: '待发货',
|
||||
DELIVERED: '待收货',
|
||||
COMPLETED: '已完成',
|
||||
CANCELLED: '已取消',
|
||||
TAKE: '待核销',
|
||||
}
|
||||
return map[status] || status || '处理中'
|
||||
}
|
||||
|
||||
// 状态样式类
|
||||
const getStatusClass = (status: string) => {
|
||||
switch (status) {
|
||||
case 'TAKE':
|
||||
return 'status-take'
|
||||
case 'COMPLETED':
|
||||
return 'status-done'
|
||||
case 'CANCELLED':
|
||||
return 'status-cancel'
|
||||
default:
|
||||
return 'status-normal'
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.merchant-order-page {
|
||||
min-height: 100vh;
|
||||
background-color: #f4f5f7;
|
||||
padding-bottom: calc(40rpx + env(safe-area-inset-bottom));
|
||||
}
|
||||
|
||||
.sticky-header {
|
||||
position: sticky;
|
||||
top: 0;
|
||||
z-index: 50;
|
||||
background: #ffffff;
|
||||
box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.04);
|
||||
|
||||
.search-box {
|
||||
padding: 16rpx 28rpx 10rpx 28rpx;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 16rpx;
|
||||
|
||||
.search-input-wrap {
|
||||
flex: 1;
|
||||
height: 72rpx;
|
||||
background: #f3f4f6;
|
||||
border-radius: 36rpx;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 0 24rpx;
|
||||
|
||||
.search-input {
|
||||
flex: 1;
|
||||
margin-left: 12rpx;
|
||||
font-size: 26rpx;
|
||||
color: #111827;
|
||||
}
|
||||
|
||||
.placeholder {
|
||||
color: #9ca3af;
|
||||
font-size: 26rpx;
|
||||
}
|
||||
|
||||
.clear-btn {
|
||||
padding: 6rpx;
|
||||
}
|
||||
}
|
||||
|
||||
.search-action-btn {
|
||||
font-size: 28rpx;
|
||||
color: #2563eb;
|
||||
font-weight: 600;
|
||||
padding: 0 8rpx;
|
||||
}
|
||||
}
|
||||
|
||||
.tab-scroll {
|
||||
width: 100%;
|
||||
white-space: nowrap;
|
||||
|
||||
.tab-inner {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 0 16rpx;
|
||||
min-width: 100%;
|
||||
box-sizing: border-box;
|
||||
|
||||
.tab-item {
|
||||
flex: 1;
|
||||
min-width: 130rpx;
|
||||
text-align: center;
|
||||
padding: 22rpx 12rpx;
|
||||
position: relative;
|
||||
white-space: nowrap;
|
||||
|
||||
.tab-label {
|
||||
font-size: 28rpx;
|
||||
color: #6b7280;
|
||||
font-weight: 500;
|
||||
transition: all 0.2s ease;
|
||||
}
|
||||
|
||||
&.active {
|
||||
.tab-label {
|
||||
color: #111827;
|
||||
font-weight: 700;
|
||||
font-size: 30rpx;
|
||||
}
|
||||
|
||||
.indicator {
|
||||
position: absolute;
|
||||
bottom: 4rpx;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
width: 44rpx;
|
||||
height: 6rpx;
|
||||
background: #111827;
|
||||
border-radius: 3rpx;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.order-list-body {
|
||||
padding: 24rpx 28rpx;
|
||||
|
||||
.order-card {
|
||||
background: #ffffff;
|
||||
border-radius: 24rpx;
|
||||
padding: 28rpx;
|
||||
margin-bottom: 24rpx;
|
||||
box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.03);
|
||||
|
||||
.card-head {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding-bottom: 20rpx;
|
||||
border-bottom: 1rpx solid #f3f4f6;
|
||||
|
||||
.sn-box {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8rpx;
|
||||
|
||||
.order-sn {
|
||||
font-size: 24rpx;
|
||||
color: #6b7280;
|
||||
font-weight: 500;
|
||||
}
|
||||
}
|
||||
|
||||
.status-badge {
|
||||
font-size: 22rpx;
|
||||
font-weight: 600;
|
||||
padding: 6rpx 16rpx;
|
||||
border-radius: 10rpx;
|
||||
|
||||
&.status-take {
|
||||
background: #ecfdf5;
|
||||
color: #059669;
|
||||
}
|
||||
&.status-done {
|
||||
background: #f3f4f6;
|
||||
color: #6b7280;
|
||||
}
|
||||
&.status-cancel {
|
||||
background: #f9fafb;
|
||||
color: #9ca3af;
|
||||
}
|
||||
&.status-normal {
|
||||
background: #fff7ed;
|
||||
color: #ea580c;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.goods-container {
|
||||
padding: 10rpx 0;
|
||||
|
||||
.goods-item {
|
||||
display: flex;
|
||||
padding: 16rpx 0;
|
||||
border-bottom: 1rpx solid #fafafa;
|
||||
|
||||
&:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
.goods-thumb {
|
||||
width: 140rpx;
|
||||
height: 140rpx;
|
||||
border-radius: 14rpx;
|
||||
background: #f9fafb;
|
||||
border: 1rpx solid #f3f4f6;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.goods-info {
|
||||
flex: 1;
|
||||
margin-left: 20rpx;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: space-between;
|
||||
|
||||
.goods-name {
|
||||
font-size: 28rpx;
|
||||
font-weight: 600;
|
||||
color: #111827;
|
||||
line-height: 1.4;
|
||||
display: -webkit-box;
|
||||
-webkit-line-clamp: 2;
|
||||
-webkit-box-orient: vertical;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.spec-pill {
|
||||
margin-top: 6rpx;
|
||||
|
||||
text {
|
||||
font-size: 22rpx;
|
||||
color: #6b7280;
|
||||
background: #f3f4f6;
|
||||
padding: 4rpx 12rpx;
|
||||
border-radius: 6rpx;
|
||||
}
|
||||
}
|
||||
|
||||
.price-qty-row {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: baseline;
|
||||
margin-top: 10rpx;
|
||||
|
||||
.goods-price {
|
||||
font-size: 28rpx;
|
||||
font-weight: 700;
|
||||
color: #111827;
|
||||
}
|
||||
|
||||
.goods-qty {
|
||||
font-size: 22rpx;
|
||||
color: #9ca3af;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.card-foot {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding-top: 20rpx;
|
||||
border-top: 1rpx solid #f9fafb;
|
||||
|
||||
.buyer-info {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8rpx;
|
||||
|
||||
.buyer-tel {
|
||||
font-size: 24rpx;
|
||||
color: #6b7280;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.order-type-tag {
|
||||
font-size: 20rpx;
|
||||
color: #2563eb;
|
||||
background: #eff6ff;
|
||||
padding: 4rpx 12rpx;
|
||||
border-radius: 6rpx;
|
||||
}
|
||||
}
|
||||
|
||||
.total-bar {
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
|
||||
.total-label {
|
||||
font-size: 24rpx;
|
||||
color: #6b7280;
|
||||
}
|
||||
|
||||
.total-symbol {
|
||||
font-size: 24rpx;
|
||||
font-weight: 700;
|
||||
color: #ef4444;
|
||||
}
|
||||
|
||||
.total-price {
|
||||
font-size: 34rpx;
|
||||
font-weight: 700;
|
||||
color: #ef4444;
|
||||
margin-left: 2rpx;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.card-actions {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
padding-top: 20rpx;
|
||||
margin-top: 16rpx;
|
||||
border-top: 1rpx dashed #e5e7eb;
|
||||
|
||||
.action-btn {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8rpx;
|
||||
padding: 14rpx 28rpx;
|
||||
border-radius: 36rpx;
|
||||
font-size: 26rpx;
|
||||
font-weight: 600;
|
||||
|
||||
&.verify {
|
||||
background: #111827;
|
||||
color: #ffffff;
|
||||
box-shadow: 0 4rpx 12rpx rgba(17, 24, 39, 0.15);
|
||||
|
||||
.btn-lbl {
|
||||
font-size: 24rpx;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.empty-state {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 120rpx 0;
|
||||
|
||||
.empty-text {
|
||||
font-size: 28rpx;
|
||||
color: #9ca3af;
|
||||
margin-top: 24rpx;
|
||||
}
|
||||
}
|
||||
|
||||
.loading-more,
|
||||
.no-more {
|
||||
text-align: center;
|
||||
padding: 30rpx 0;
|
||||
font-size: 24rpx;
|
||||
color: #9ca3af;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
155
pages-sub/merchant/utils/storeRequest.js
Normal file
155
pages-sub/merchant/utils/storeRequest.js
Normal file
@@ -0,0 +1,155 @@
|
||||
import api from "@/config/api.js";
|
||||
import Request from "@/lib/request/index.js";
|
||||
import Foundation from "@/utils/Foundation.js";
|
||||
import { md5 } from "@/utils/md5.js";
|
||||
import storage from "@/utils/storage.js";
|
||||
import uuid from "@/utils/uuid.modified.js";
|
||||
|
||||
let isStoreNavigateTo = false;
|
||||
|
||||
function cleanStoreAuth() {
|
||||
uni.showToast({
|
||||
title: "商家登录状态已过期,请重新登录",
|
||||
icon: "none",
|
||||
duration: 1800,
|
||||
});
|
||||
|
||||
storage.clearStoreAuth();
|
||||
|
||||
if (!isStoreNavigateTo) {
|
||||
isStoreNavigateTo = true;
|
||||
setTimeout(() => {
|
||||
isStoreNavigateTo = false;
|
||||
uni.reLaunch({
|
||||
url: "/pages-sub/merchant/pages/login/index",
|
||||
});
|
||||
}, 1200);
|
||||
}
|
||||
}
|
||||
|
||||
const storeHttp = new Request();
|
||||
|
||||
const ensureUuid = () => {
|
||||
if (!storage.getUuid()) {
|
||||
storage.setUuid(uuid.v1());
|
||||
}
|
||||
};
|
||||
|
||||
storeHttp.setConfig((config) => {
|
||||
ensureUuid();
|
||||
config.baseURL = api.store;
|
||||
config.header = {
|
||||
...config.header,
|
||||
};
|
||||
config.validateStatus = () => true;
|
||||
return config;
|
||||
});
|
||||
|
||||
storeHttp.interceptors.request.use(
|
||||
(config) => {
|
||||
ensureUuid();
|
||||
const token = storage.getStoreAccessToken();
|
||||
if (token) {
|
||||
const nonce = Foundation.randomString(6);
|
||||
const timestamp = parseInt(new Date().getTime() / 1000);
|
||||
const sign = md5(nonce + timestamp + token);
|
||||
const _params = { nonce, timestamp, sign };
|
||||
config.params = { ...(config.params || {}), ..._params };
|
||||
config.header.accessToken = token;
|
||||
}
|
||||
config.header = {
|
||||
...config.header,
|
||||
uuid: storage.getUuid(),
|
||||
};
|
||||
return config;
|
||||
},
|
||||
(config) => Promise.reject(config)
|
||||
);
|
||||
|
||||
let isStoreRefreshing = false;
|
||||
let storeRequests = [];
|
||||
|
||||
function refreshTokenApi(refreshToken) {
|
||||
return uni.request({
|
||||
url: `${api.store}/passport/login/refresh/${refreshToken}`,
|
||||
method: "GET",
|
||||
header: {
|
||||
uuid: storage.getUuid(),
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
storeHttp.interceptors.response.use(
|
||||
async (response) => {
|
||||
isStoreNavigateTo = false;
|
||||
try {
|
||||
uni.hideLoading();
|
||||
} catch (e) {}
|
||||
|
||||
const token = storage.getStoreAccessToken();
|
||||
const refreshToken = storage.getStoreRefreshToken();
|
||||
|
||||
// 403 / 401 并且有 refreshToken,尝试刷新
|
||||
if (
|
||||
token &&
|
||||
refreshToken &&
|
||||
(response.statusCode === 403 || response.statusCode === 401 || response.data?.code === 403)
|
||||
) {
|
||||
if (!isStoreRefreshing) {
|
||||
isStoreRefreshing = true;
|
||||
storage.removeStoreAccessToken();
|
||||
try {
|
||||
const [err, res] = await refreshTokenApi(refreshToken);
|
||||
const data = res?.data || err?.data;
|
||||
if (data && data.success && data.result) {
|
||||
const { accessToken: newAccessToken, refreshToken: newRefreshToken } = data.result;
|
||||
storage.setStoreAccessToken(newAccessToken);
|
||||
if (newRefreshToken) {
|
||||
storage.setStoreRefreshToken(newRefreshToken);
|
||||
}
|
||||
response.header = response.header || {};
|
||||
response.header.accessToken = `${newAccessToken}`;
|
||||
storeRequests.forEach((cb) => cb(newAccessToken));
|
||||
storeRequests = [];
|
||||
return storeHttp.request(response.config);
|
||||
} else {
|
||||
cleanStoreAuth();
|
||||
return Promise.reject(data);
|
||||
}
|
||||
} catch (e) {
|
||||
cleanStoreAuth();
|
||||
return Promise.reject(e);
|
||||
} finally {
|
||||
isStoreRefreshing = false;
|
||||
}
|
||||
} else {
|
||||
return new Promise((resolve) => {
|
||||
storeRequests.push((newToken) => {
|
||||
response.header = response.header || {};
|
||||
response.header.accessToken = `${newToken}`;
|
||||
resolve(storeHttp.request(response.config));
|
||||
});
|
||||
});
|
||||
}
|
||||
} else if (
|
||||
(!token && (response.statusCode === 403 || response.statusCode === 401)) ||
|
||||
response.data?.code === 403 ||
|
||||
response.data?.code === 401
|
||||
) {
|
||||
cleanStoreAuth();
|
||||
} else if ((response.statusCode === 200 && response.data && !response.data.success) || response.statusCode === 400) {
|
||||
if (response.data?.message) {
|
||||
uni.showToast({
|
||||
title: response.data.message,
|
||||
icon: "none",
|
||||
duration: 2000,
|
||||
});
|
||||
}
|
||||
}
|
||||
return response;
|
||||
},
|
||||
(error) => error
|
||||
);
|
||||
|
||||
export { storeHttp };
|
||||
export default storeHttp;
|
||||
Reference in New Issue
Block a user