文件
fenleixinxi/uniapp/pages/merchant/info.vue

787 行
19 KiB
Vue

此文件含有模棱两可的 Unicode 字符

此文件含有可能会与其他字符混淆的 Unicode 字符。 如果您是想特意这样的,可以安全地忽略该警告。 使用 Escape 按钮显示他们。

<template>
<view class="merchant-info fc-page">
<!-- 沉浸式导航栏 -->
<fc-navbar :title="pageTitle" theme="gradient" :show-back="true" />
<!-- 加载中 -->
<view v-if="loading" class="merchant-info__loading">
<text class="merchant-info__loading-text">加载中…</text>
</view>
<view v-else class="merchant-info__body">
<!-- 审核状态简短提示 -->
<view v-if="auditStatus === 2" class="merchant-info__notice merchant-info__notice--rejected">
<text class="merchant-info__notice-text">未通过:{{ auditReason || '提交的材料不符合规范,请重新核对后修改提交' }}</text>
</view>
<view v-else-if="auditStatus === 0" class="merchant-info__notice merchant-info__notice--pending">
<text class="merchant-info__notice-text">资质审核中,工作人员将在 1-3 个工作日完成审核</text>
</view>
<view v-else-if="auditStatus === 1" class="merchant-info__notice merchant-info__notice--approved">
<text class="merchant-info__notice-text">已通过官方认证,修改后直接保存生效</text>
</view>
<!-- 单一整洁卡片(不拆碎模块,一气呵成) -->
<view class="fc-card merchant-info__card">
<!-- 1. 店铺名称 -->
<view class="merchant-info__item">
<view class="merchant-info__label">
<text class="merchant-info__req">*</text>店铺名称
</view>
<input
class="merchant-info__input"
v-model="form.name"
placeholder="请输入店铺或企业名称"
placeholder-class="merchant-info__ph"
/>
</view>
<!-- 2. 营业执照照片 -->
<view class="merchant-info__item">
<view class="merchant-info__label">
<text class="merchant-info__req">*</text>营业执照
</view>
<view class="merchant-info__license-box" @click="handleLicenseClick">
<template v-if="form.license">
<image class="merchant-info__license-img" :src="formatMedia(form.license)" mode="aspectFit" />
<view class="merchant-info__license-change" @click.stop="chooseLicense">
<text>更换照片</text>
</view>
</template>
<template v-else>
<view class="merchant-info__license-empty">
<image class="merchant-info__empty-icon" :src="iconUrl('image')" mode="aspectFit" />
<text class="merchant-info__empty-text">点击上传营业执照正面</text>
</view>
</template>
</view>
</view>
<!-- 3. 店铺门头 / Logo -->
<view class="merchant-info__item">
<view class="merchant-info__label">门头 / Logo</view>
<view class="merchant-info__logo-box" @click="chooseLogo">
<image v-if="form.logo" class="merchant-info__logo-img" :src="formatMedia(form.logo)" mode="aspectFill" />
<view v-else class="merchant-info__logo-empty">
<image class="merchant-info__empty-icon merchant-info__empty-icon--sm" :src="iconUrl('login-shop') || iconUrl('image')" mode="aspectFit" />
<text class="merchant-info__logo-empty-text">上传照片</text>
</view>
</view>
</view>
<!-- 4. 联系人 -->
<view class="merchant-info__item">
<view class="merchant-info__label">
<text class="merchant-info__req">*</text>联系人
</view>
<input
class="merchant-info__input"
v-model="form.contactName"
placeholder="请填写联系人姓名"
placeholder-class="merchant-info__ph"
/>
</view>
<!-- 5. 联系电话 -->
<view class="merchant-info__item">
<view class="merchant-info__label">
<text class="merchant-info__req">*</text>联系电话
</view>
<input
class="merchant-info__input"
type="number"
v-model="form.contactPhone"
placeholder="请填写咨询联系电话"
placeholder-class="merchant-info__ph"
/>
</view>
<!-- 6. 实体店地址(支持地图选点) -->
<view class="merchant-info__item">
<view class="merchant-info__label">实体店地址</view>
<view class="merchant-info__addr-box">
<input
class="merchant-info__input merchant-info__input--addr"
v-model="form.address"
placeholder="填写地址或点击右侧地图选点"
placeholder-class="merchant-info__ph"
/>
<view class="merchant-info__loc-btn" @click="chooseLocation">
<image class="merchant-info__loc-icon" :src="iconUrl('location')" mode="aspectFit" />
<text class="merchant-info__loc-btn-text">定位</text>
</view>
</view>
</view>
<!-- 7. 店铺公告 -->
<view class="merchant-info__item merchant-info__item--last">
<view class="merchant-info__label merchant-info__label--row">
<text>店铺公告</text>
<text class="merchant-info__count">{{ (form.notice || '').length }}/200</text>
</view>
<textarea
class="merchant-info__textarea"
v-model="form.notice"
maxlength="200"
placeholder="选填,如营业时间、主营特色等"
placeholder-class="merchant-info__ph"
></textarea>
</view>
</view>
<!-- 底部占位 -->
<view class="merchant-info__bottom-spacer"></view>
</view>
<!-- 底部吸底操作栏 -->
<view class="merchant-info__action-bar">
<button
class="merchant-info__submit-btn"
:class="{ 'merchant-info__submit-btn--disabled': submitting }"
@click="handleSubmit"
>
<text class="merchant-info__submit-text">{{ submitBtnText }}</text>
</button>
</view>
</view>
</template>
<script>
/**
* 商家资质认证与店铺信息管理
*/
import authApi from '@/common/api/auth.js'
import postApi from '@/common/api/post.js'
import { useUserStore } from '@/common/store/index.js'
import { iconUrl } from '@/common/store/ui.js'
import { assetUrl } from '@/common/utils/format.js'
import FcNavbar from '@/components/fc-navbar/fc-navbar.vue'
export default {
components: { FcNavbar },
data() {
return {
loading: true,
submitting: false,
auditStatus: -1, // -1未申请, 0待审核, 1已通过, 2已驳回
auditReason: '',
form: {
name: '',
license: '',
logo: '',
contactName: '',
contactPhone: '',
address: '',
lat: null,
lng: null,
notice: '',
banner: '',
},
}
},
computed: {
/**
* 页面导航标题
* @returns {string}
*/
pageTitle() {
if (this.auditStatus === 1) return '店铺资料管理'
if (this.auditStatus === 0) return '资质审核中'
return '商家资质认证'
},
/**
* 是否为已认证商家
* @returns {boolean}
*/
isApproved() {
return this.auditStatus === 1
},
/**
* 提交按钮文字
* @returns {string}
*/
submitBtnText() {
if (this.submitting) return '正在保存…'
if (this.auditStatus === 1) return '保存店铺资料'
if (this.auditStatus === 0) return '重新提交审核'
return '提交资质认证'
},
},
/**
* 页面加载
*/
onLoad() {
this.fetchData()
},
/**
* 下拉刷新
*/
async onPullDownRefresh() {
try {
await this.fetchData()
} finally {
uni.stopPullDownRefresh()
}
},
methods: {
iconUrl,
/**
* 格式化媒体资源地址
* @param {string} url 资源路径
* @returns {string}
*/
formatMedia(url) {
return assetUrl(url)
},
/**
* 点击营业执照(已上传全屏大图预览,未上传触发相册选择)
*/
handleLicenseClick() {
if (this.form.license) {
const full = this.formatMedia(this.form.license)
uni.previewImage({
urls: [full],
current: full,
})
} else {
this.chooseLicense()
}
},
/**
* 地图选点获取地址与经纬度
*/
chooseLocation() {
uni.chooseLocation({
success: (res) => {
const addr = res.address ? String(res.address).trim() : ''
const name = res.name ? String(res.name).trim() : ''
if (addr && name && !addr.includes(name)) {
this.form.address = `${addr} ${name}`
} else {
this.form.address = addr || name
}
if (typeof res.latitude === 'number' && typeof res.longitude === 'number') {
this.form.lat = res.latitude
this.form.lng = res.longitude
}
uni.showToast({ title: '已同步定位', icon: 'none' })
},
fail: () => {},
})
},
/**
* 获取商家资料与进度
*/
async fetchData() {
this.loading = true
try {
const res = await authApi.getMerchant()
if (res && res.hasApplied && res.merchant) {
this.auditStatus = Number(res.auditStatus)
this.auditReason = res.auditReason || ''
const m = res.merchant
this.form.name = m.name || ''
this.form.license = m.license || ''
this.form.logo = m.logo || ''
this.form.notice = m.notice || ''
this.form.banner = m.banner || ''
this.form.address = m.address || m.category || ''
this.form.lat = m.lat != null ? Number(m.lat) : null
this.form.lng = m.lng != null ? Number(m.lng) : null
const contactStr = String(m.contact || '')
if (contactStr.includes(' ')) {
const parts = contactStr.split(' ')
this.form.contactName = parts[0] || ''
this.form.contactPhone = parts[1] || ''
} else {
this.form.contactName = contactStr
const userStore = useUserStore()
this.form.contactPhone = (userStore.state.userInfo && userStore.state.userInfo.phone) || ''
}
} else {
this.auditStatus = -1
const userStore = useUserStore()
const phone = (userStore.state.userInfo && userStore.state.userInfo.phone) || ''
this.form.contactPhone = phone
}
} catch (err) {
uni.showToast({ title: '拉取商家资料失败', icon: 'none' })
} finally {
this.loading = false
}
},
/**
* 上传营业执照照片
*/
chooseLicense() {
uni.chooseImage({
count: 1,
sizeType: ['compressed'],
success: async (res) => {
const temp = (res.tempFilePaths && res.tempFilePaths[0]) || ''
if (!temp) return
uni.showLoading({ title: '上传中…' })
try {
const up = await postApi.uploadMedia(temp, 'image')
if (up && up.url) {
this.form.license = up.url
uni.showToast({ title: '执照上传成功', icon: 'success' })
}
} catch (e) {
uni.showToast({ title: (e && e.message) || '上传失败', icon: 'none' })
} finally {
uni.hideLoading()
}
},
})
},
/**
* 上传店铺 Logo
*/
chooseLogo() {
uni.chooseImage({
count: 1,
sizeType: ['compressed'],
success: async (res) => {
const temp = (res.tempFilePaths && res.tempFilePaths[0]) || ''
if (!temp) return
uni.showLoading({ title: '上传中…' })
try {
const up = await postApi.uploadMedia(temp, 'image')
if (up && up.url) {
this.form.logo = up.url
uni.showToast({ title: 'Logo上传成功', icon: 'success' })
}
} catch (e) {
uni.showToast({ title: (e && e.message) || '上传失败', icon: 'none' })
} finally {
uni.hideLoading()
}
},
})
},
/**
* 提交资质认证或更新
*/
async handleSubmit() {
if (this.submitting) return
const name = this.form.name.trim()
if (!name) {
uni.showToast({ title: '请填写店铺名称', icon: 'none' })
return
}
if (!this.form.license) {
uni.showToast({ title: '请上传营业执照', icon: 'none' })
return
}
const contactName = this.form.contactName.trim()
if (!contactName) {
uni.showToast({ title: '请填写联系人', icon: 'none' })
return
}
const contactPhone = this.form.contactPhone.trim()
if (!contactPhone) {
uni.showToast({ title: '请填写联系电话', icon: 'none' })
return
}
this.submitting = true
try {
const contact = contactName + ' ' + contactPhone
const payload = {
name,
license: this.form.license,
logo: this.form.logo,
contact,
address: this.form.address.trim(),
category: this.form.address.trim(),
lat: this.form.lat,
lng: this.form.lng,
notice: this.form.notice.trim(),
banner: this.form.banner,
}
const res = await authApi.applyMerchant(payload)
uni.showToast({
title: (res && res.message) || (this.isApproved ? '资料保存成功' : '已提交审核'),
icon: 'success',
})
await useUserStore().fetchProfile()
await this.fetchData()
setTimeout(() => {
if (!this.isApproved) {
uni.navigateBack()
}
}, 1200)
} catch (err) {
uni.showToast({ title: (err && err.message) || '提交失败', icon: 'none' })
} finally {
this.submitting = false
}
},
},
}
</script>
<style lang="scss" scoped>
.merchant-info {
min-height: 100vh;
background-color: $fc-bg;
}
.merchant-info__loading {
padding: 140rpx 0;
display: flex;
align-items: center;
justify-content: center;
}
.merchant-info__loading-text {
color: $fc-text-muted;
font-size: 26rpx;
}
.merchant-info__body {
padding: 20rpx 28rpx 0;
}
/* 简短状态提示条 */
.merchant-info__notice {
padding: 16rpx 24rpx;
border-radius: 14rpx;
margin-bottom: 20rpx;
&--pending {
background: #fff9ee;
border: 1rpx solid #ffe8be;
.merchant-info__notice-text {
color: #aa771c;
}
}
&--rejected {
background: #fff3f3;
border: 1rpx solid #ffd8d9;
.merchant-info__notice-text {
color: #c43237;
}
}
&--approved {
background: #eefcf4;
border: 1rpx solid #c9eed7;
.merchant-info__notice-text {
color: #04874a;
}
}
}
.merchant-info__notice-text {
font-size: 24rpx;
line-height: 1.4;
}
/* ================= 单一整体卡片 ================= */
.merchant-info__card {
background: #ffffff;
border-radius: 20rpx;
padding: 28rpx;
margin-bottom: 20rpx;
box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.03);
}
/* 表单字段项(纵向统一对齐) */
.merchant-info__item {
margin-bottom: 26rpx;
&--last {
margin-bottom: 0;
}
}
.merchant-info__label {
font-size: 28rpx;
font-weight: 600;
color: $fc-text;
margin-bottom: 12rpx;
&--row {
display: flex;
align-items: center;
justify-content: space-between;
}
}
.merchant-info__req {
color: #e5484d;
font-weight: 700;
margin-right: 4rpx;
}
.merchant-info__count {
font-size: 22rpx;
color: $fc-text-muted;
font-weight: normal;
}
/* 统一输入框 */
.merchant-info__input {
width: 100%;
height: 84rpx;
background: #ffffff;
border: 1.5rpx solid #e1eee6;
border-radius: 14rpx;
padding: 0 24rpx;
font-size: 28rpx;
color: $fc-text;
box-sizing: border-box;
transition: all 0.15s ease;
&:focus {
border-color: #00e070;
box-shadow: 0 0 0 3rpx rgba(0, 224, 112, 0.12);
}
&--addr {
flex: 1;
border: none;
height: 80rpx;
padding: 0 20rpx;
}
}
.merchant-info__ph {
color: #a2b5ab;
font-size: 26rpx;
}
/* 地址组合框 */
.merchant-info__addr-box {
width: 100%;
height: 84rpx;
background: #ffffff;
border: 1.5rpx solid #e1eee6;
border-radius: 14rpx;
display: flex;
align-items: center;
box-sizing: border-box;
transition: all 0.15s ease;
&:focus-within {
border-color: #00e070;
box-shadow: 0 0 0 3rpx rgba(0, 224, 112, 0.12);
}
}
.merchant-info__loc-btn {
display: flex;
align-items: center;
padding: 8rpx 18rpx;
margin-right: 10rpx;
background: #eefcf4;
border-radius: $fc-radius-pill;
border: 1rpx solid #c9eed7;
cursor: pointer;
&:active {
opacity: 0.7;
}
}
.merchant-info__loc-icon {
width: 24rpx;
height: 24rpx;
margin-right: 6rpx;
}
.merchant-info__loc-btn-text {
font-size: 22rpx;
color: #04874a;
font-weight: 600;
}
/* ================= 营业执照框 ================= */
.merchant-info__license-box {
width: 100%;
height: 220rpx;
background: #f8fbf9;
border: 1.5rpx dashed #bfe8d0;
border-radius: 14rpx;
display: flex;
align-items: center;
justify-content: center;
position: relative;
overflow: hidden;
cursor: pointer;
box-sizing: border-box;
transition: all 0.15s ease;
&:active {
opacity: 0.85;
}
}
.merchant-info__license-img {
width: 100%;
height: 100%;
}
.merchant-info__license-change {
position: absolute;
right: 14rpx;
bottom: 14rpx;
background: rgba(4, 48, 30, 0.75);
color: #ffffff;
font-size: 20rpx;
padding: 4rpx 16rpx;
border-radius: $fc-radius-pill;
}
.merchant-info__license-empty {
display: flex;
flex-direction: column;
align-items: center;
}
.merchant-info__empty-icon {
width: 44rpx;
height: 44rpx;
margin-bottom: 8rpx;
&--sm {
width: 36rpx;
height: 36rpx;
margin-bottom: 4rpx;
}
}
.merchant-info__empty-text {
font-size: 25rpx;
color: #04874a;
font-weight: 500;
}
/* ================= 门头/Logo 小方块 ================= */
.merchant-info__logo-box {
width: 110rpx;
height: 110rpx;
background: #f8fbf9;
border: 1.5rpx dashed #bfe8d0;
border-radius: 14rpx;
display: flex;
align-items: center;
justify-content: center;
overflow: hidden;
cursor: pointer;
transition: all 0.15s ease;
&:active {
opacity: 0.85;
}
}
.merchant-info__logo-img {
width: 100%;
height: 100%;
}
.merchant-info__logo-empty {
display: flex;
flex-direction: column;
align-items: center;
}
.merchant-info__logo-empty-text {
font-size: 19rpx;
color: #04874a;
font-weight: 500;
}
/* ================= 公告多行文本 ================= */
.merchant-info__textarea {
width: 100%;
height: 130rpx;
background: #ffffff;
border: 1.5rpx solid #e1eee6;
border-radius: 14rpx;
padding: 16rpx 20rpx;
font-size: 26rpx;
color: $fc-text;
line-height: 1.5;
box-sizing: border-box;
transition: all 0.15s ease;
&:focus {
border-color: #00e070;
box-shadow: 0 0 0 3rpx rgba(0, 224, 112, 0.12);
}
}
/* 底部占位 */
.merchant-info__bottom-spacer {
height: 150rpx;
}
/* ================= 底部吸底操作条 ================= */
.merchant-info__action-bar {
position: fixed;
left: 0;
right: 0;
bottom: 0;
background: rgba(255, 255, 255, 0.95);
backdrop-filter: blur(12px);
padding: 16rpx 32rpx calc(16rpx + env(safe-area-inset-bottom));
box-shadow: 0 -4rpx 14rpx rgba(0, 0, 0, 0.04);
z-index: 100;
}
.merchant-info__submit-btn {
width: 100%;
height: 86rpx;
background: #00e070;
border-radius: 43rpx;
display: flex;
align-items: center;
justify-content: center;
border: none;
box-shadow: 0 6rpx 18rpx rgba(0, 224, 112, 0.28);
transition: all 0.15s ease;
&::after {
border: none;
}
&:active {
transform: scale(0.98);
box-shadow: 0 3rpx 10rpx rgba(0, 224, 112, 0.2);
}
&--disabled {
opacity: 0.6;
pointer-events: none;
}
}
.merchant-info__submit-text {
color: #04301e;
font-size: 29rpx;
font-weight: 700;
letter-spacing: 1rpx;
}
</style>