292 lines
8.6 KiB
JavaScript
292 lines
8.6 KiB
JavaScript
const ROOT_WIDTH = '560rpx'
|
||
const CARD_BG = '#F8FAFF'
|
||
|
||
function cardWrapper(views) {
|
||
return {
|
||
css: { width: ROOT_WIDTH },
|
||
views: [{
|
||
type: 'view',
|
||
css: {
|
||
width: ROOT_WIDTH,
|
||
borderRadius: '16rpx',
|
||
paddingBottom: '68rpx',
|
||
paddingTop: '30rpx',
|
||
backgroundColor: CARD_BG,
|
||
},
|
||
views,
|
||
}],
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 按门店 type 返回诊所/药店文案(0诊所 1药店)
|
||
* @param {number|string} storeType
|
||
* @returns {string}
|
||
*/
|
||
function storeKindLabel(storeType) {
|
||
return Number(storeType) === 1 ? '药店' : '诊所'
|
||
}
|
||
|
||
/**
|
||
* 强化居中组件 (仅用于诊所/推广员的标题,不影响医生)
|
||
*/
|
||
function centerText(text, css = {}) {
|
||
return {
|
||
type: 'view',
|
||
css: { width: ROOT_WIDTH, textAlign: 'center', marginTop: '8rpx', ...css },
|
||
views: [{ type: 'text', text: text || '', css: { color: '#333', fontSize: '28rpx', textAlign: 'center', ...css } }],
|
||
}
|
||
}
|
||
|
||
// ----------------------------------------------------------------
|
||
// 医生海报 - 100% 还原为你最初始的代码,未作任何更改
|
||
// ----------------------------------------------------------------
|
||
function buildDoctorPoster(info) {
|
||
const doctor = info.DoctorInfo || {}
|
||
const store = (info.store && info.store.store) ? info.store.store : {}
|
||
const depart = (doctor.depart && doctor.depart.name) ? doctor.depart.name : ''
|
||
const titleName = (doctor.title && doctor.title.name) ? doctor.title.name : ''
|
||
let sex = 1
|
||
if (doctor.idcard) {
|
||
sex = doctor.idcard.charAt(16)
|
||
}
|
||
const defaultAvatar = `/static/image/${sex % 2 === 0 ? 'nv' : 'nan'}.png`
|
||
const avatar = doctor.avatar || defaultAvatar
|
||
const qrUrl = doctor.qr_code || ''
|
||
|
||
return cardWrapper([
|
||
{
|
||
type: 'image',
|
||
src: avatar,
|
||
css: {
|
||
width: '180rpx',
|
||
height: '180rpx',
|
||
borderRadius: '50%',
|
||
marginLeft: '190rpx',
|
||
},
|
||
},
|
||
{
|
||
type: 'view',
|
||
css: { textAlign: 'center', marginTop: '8rpx' },
|
||
views: [
|
||
{ type: 'text', text: doctor.name || '', css: { color: '#000', fontSize: '36rpx' } },
|
||
{
|
||
type: 'text',
|
||
text: titleName,
|
||
css: { color: '#1E293B', fontSize: '28rpx', paddingTop: '10rpx', marginLeft: '8rpx' },
|
||
},
|
||
],
|
||
},
|
||
{
|
||
type: 'view',
|
||
css: { textAlign: 'center', marginTop: '8rpx' },
|
||
views: [
|
||
{ type: 'text', text: store.name || '', css: { color: '#475569', fontSize: '24rpx' } },
|
||
{ type: 'text', text: depart, css: { color: '#475569', fontSize: '24rpx', marginLeft: '10rpx' } },
|
||
],
|
||
},
|
||
{
|
||
type: 'view',
|
||
css: { textAlign: 'center', marginTop: '20rpx', marginBottom: '20rpx' },
|
||
views: [{
|
||
type: 'image',
|
||
src: qrUrl,
|
||
css: { width: '388rpx', height: '388rpx' },
|
||
}],
|
||
},
|
||
{
|
||
type: 'view',
|
||
css: { paddingLeft: '20rpx', paddingRight: '20rpx' },
|
||
views: [
|
||
{
|
||
type: 'text',
|
||
text: '专业擅长',
|
||
css: { color: '#6ACDBB', fontSize: '28rpx', textAlign: 'center', marginLeft: '56rpx' },
|
||
},
|
||
{
|
||
type: 'text',
|
||
text: doctor.good_at || '',
|
||
css: { color: '#000', fontSize: '24rpx', marginLeft: '8rpx', marginTop: '4rpx' },
|
||
},
|
||
],
|
||
},
|
||
])
|
||
}
|
||
|
||
// ----------------------------------------------------------------
|
||
// 推广员海报 - 修复文本居中、图片居中、Label同行不换行
|
||
// ----------------------------------------------------------------
|
||
function buildSalespersonPoster(payload) {
|
||
const store = (payload.qr_code && payload.qr_code.store) ? payload.qr_code.store : {}
|
||
const qrUrl = (payload.qr_code && payload.qr_code.qr_code) ? payload.qr_code.qr_code : ''
|
||
const storeName = store.name || ''
|
||
const position = store.position || ''
|
||
const nickName = payload.nick_name || ''
|
||
const kind = storeKindLabel(store.type)
|
||
|
||
return cardWrapper([
|
||
// 店铺名居中
|
||
centerText(storeName, { fontSize: '36rpx', fontWeight: 'bold', marginTop: '20rpx' }),
|
||
|
||
// 地址 Label 按门店类型显示诊所|药店,具体地址单独一行居中
|
||
centerText(kind + '地址:', { color: '#3a8ee6', fontSize: '24rpx', marginTop: '20rpx' }),
|
||
{
|
||
type: 'view',
|
||
css: { width: ROOT_WIDTH, marginTop: '8rpx' },
|
||
views: [
|
||
{
|
||
type: 'text',
|
||
text: position,
|
||
css: {
|
||
color: '#333',
|
||
fontSize: '24rpx',
|
||
textAlign: 'center',
|
||
width: '512rpx',
|
||
marginLeft: '24rpx',
|
||
maxLines: 2,
|
||
lineHeight: '36rpx'
|
||
}
|
||
}
|
||
],
|
||
},
|
||
|
||
// 还原回初始的图片容器写法:依靠 textAlign 居中图片,不干预 width
|
||
{
|
||
type: 'view',
|
||
css: { textAlign: 'center', marginTop: '24rpx', marginBottom: '24rpx' },
|
||
views: [{
|
||
type: 'image',
|
||
src: qrUrl,
|
||
css: { width: '388rpx', height: '388rpx' },
|
||
}],
|
||
},
|
||
|
||
// 推广员信息:保持在同一行(不换行),整体水平居中
|
||
{
|
||
type: 'view',
|
||
css: { width: ROOT_WIDTH, textAlign: 'center' },
|
||
views: [
|
||
{ type: 'text', text: '推广员:', css: { color: '#3a8ee6', fontSize: '24rpx', display: 'inline-block' } },
|
||
{ type: 'text', text: nickName, css: { color: '#333', fontSize: '28rpx', display: 'inline-block' } },
|
||
]
|
||
}
|
||
])
|
||
}
|
||
|
||
// ----------------------------------------------------------------
|
||
// 门店(诊所/药店)管理员海报
|
||
// ----------------------------------------------------------------
|
||
function buildClinicPoster(payload) {
|
||
const title = payload.title || ''
|
||
const address = payload.address || ''
|
||
const qrUrl = payload.qr_code || ''
|
||
const kind = storeKindLabel(payload.store_type)
|
||
|
||
return cardWrapper([
|
||
// 门店名称居中
|
||
centerText(title, { fontSize: '36rpx', fontWeight: 'bold', marginTop: '20rpx' }),
|
||
|
||
// 还原回初始的图片容器写法:依靠 textAlign 居中图片
|
||
{
|
||
type: 'view',
|
||
css: { textAlign: 'center', marginTop: '24rpx', marginBottom: '24rpx' },
|
||
views: [{
|
||
type: 'image',
|
||
src: qrUrl,
|
||
css: { width: '388rpx', height: '388rpx' },
|
||
}],
|
||
},
|
||
|
||
// 地址标签按门店类型切换诊所|药店
|
||
centerText(kind + '地址:', { color: '#3a8ee6', fontSize: '24rpx' }),
|
||
{
|
||
type: 'view',
|
||
css: { width: ROOT_WIDTH, marginTop: '8rpx' },
|
||
views: [
|
||
{
|
||
type: 'text',
|
||
text: address,
|
||
css: {
|
||
color: '#333',
|
||
fontSize: '24rpx',
|
||
textAlign: 'center',
|
||
width: '512rpx',
|
||
marginLeft: '24rpx',
|
||
maxLines: 2,
|
||
lineHeight: '36rpx'
|
||
}
|
||
}
|
||
],
|
||
},
|
||
])
|
||
}
|
||
|
||
export function buildQrOnlyPoster(qrUrl) {
|
||
return {
|
||
css: { width: '420rpx' },
|
||
views: [{
|
||
type: 'view',
|
||
css: {
|
||
width: '420rpx',
|
||
padding: '24rpx',
|
||
backgroundColor: '#fff',
|
||
borderRadius: '16rpx',
|
||
textAlign: 'center',
|
||
},
|
||
views: [{
|
||
type: 'image',
|
||
src: qrUrl || '',
|
||
css: { width: '388rpx', height: '388rpx' },
|
||
}],
|
||
}],
|
||
}
|
||
}
|
||
|
||
export function buildPosterBoard(type, payload) {
|
||
if (type === 'salesperson') {
|
||
return buildSalespersonPoster(payload || {})
|
||
}
|
||
if (type === 'clinic') {
|
||
return buildClinicPoster(payload || {})
|
||
}
|
||
const info = payload || uni.getStorageSync('doctorInfo') || {}
|
||
return buildDoctorPoster(info)
|
||
}
|
||
|
||
export function resolveQrImageUrl(type, payload) {
|
||
if (type === 'salesperson') {
|
||
return (payload && payload.qr_code && payload.qr_code.qr_code) ? payload.qr_code.qr_code : ''
|
||
}
|
||
if (type === 'clinic') {
|
||
return (payload && payload.qr_code) ? payload.qr_code : ''
|
||
}
|
||
const info = payload || uni.getStorageSync('doctorInfo') || {}
|
||
return (info.DoctorInfo && info.DoctorInfo.qr_code) ? info.DoctorInfo.qr_code : ''
|
||
}
|
||
|
||
/**
|
||
* 导航标题:门店码按 store_type 显示诊所|药店二维码
|
||
* @param {string} type
|
||
* @param {object} [payload]
|
||
*/
|
||
export function navTitleForType(type, payload) {
|
||
if (type === 'salesperson') return '推广二维码'
|
||
if (type === 'clinic') {
|
||
return storeKindLabel(payload && payload.store_type) + '二维码'
|
||
}
|
||
return '医生码'
|
||
}
|
||
|
||
/**
|
||
* 底部按钮文案:门店码按类型切换诊所|药店
|
||
* @param {string} type
|
||
* @param {object} [payload]
|
||
*/
|
||
export function buttonLabelsForType(type, payload) {
|
||
if (type === 'clinic') {
|
||
const kind = storeKindLabel(payload && payload.store_type)
|
||
return { card: '保存' + kind + '卡片图片', qr: '保存' + kind + '二维码图片' }
|
||
}
|
||
return { card: '二维码卡片下载', qr: '二维码下载' }
|
||
}
|