Files
smt-used-car-h5/pages/index/detils.vue
T

721 lines
16 KiB
Vue
Raw Normal View History

2026-03-11 11:15:33 +08:00
<template>
<view class="page">
<!-- 自定义导航(pages.json 里已设置 navigationStyle: custom) -->
<!-- <uni-nav-bar leftText=" " @clickLeft="goBack" leftIcon="back" :fixed="true" :border="false" color="#fff" backgroundColor="#3F435B" :statusBar="true" title="车辆详情"></uni-nav-bar> -->
<view class="content">
<!-- 基础信息卡片 -->
<view class="card">
<view class="heard">
<view class="">
编号:{{detail.code?detail.code:'~'}}
</view>
<view>
<u-icon @click="openPriceDialog()" name="download" size="25" />
</view>
</view>
<view class="title-row">
<text class="name">{{ detail.product_name }}</text>
</view>
<view class="kv">
<!-- <view class="kv-item" @click="copyIfHas('车辆识别码', detail.vin)">
<text class="k">车辆识别码</text>
<text class="v ellipsis">{{ detail.vin }}</text>
<text class="copy" v-if="detail.vin">复制</text>
</view> -->
<view class="kv-item">
<text class="k">车价(¥)</text>
<text class="v">{{ detail.price }}</text>
</view>
<view class="kv-item">
<text class="k">车源地</text>
<text class="v">{{ detail.source_place}}</text>
</view>
<!-- <view class="kv-item">
<text class="k">上牌地</text>
<text class="v">{{ detail.plate_place }}</text>
</view> -->
<view class="kv-item">
<text class="k">上牌时间</text>
<text class="v">{{ detail.plate_time }}</text>
</view>
<view class="kv-item">
<text class="k">排量</text>
<text class="v">{{ detail.displacement }}</text>
</view>
<view class="kv-item">
<text class="k">里程</text>
<text class="v">{{ detail.mileage }}<text v-if="detail.mileage">Km</text></text>
</view>
<view class="kv-item">
<text class="k">马力</text>
<text class="v">{{ detail.power }}</text>
</view>
<view class="kv-item">
<text class="k">车身颜色</text>
<text class="v">{{ detail.body_color }}</text>
</view>
<view class="kv-item">
<text class="k">创建时间</text>
<text class="v">{{ detail.created_at }}</text>
</view>
</view>
</view>
<!-- 车况介绍 -->
<view class="card">
<view class="section-title">车况介绍</view>
<text class="desc" v-if="detail.condition_desc!=''">{{ detail.condition_desc }}</text>
<view class="noneview" v-else>
<img src="/static/image/none.png" alt="">
</view>
</view>
<view class="hero">
<view class="section-title">产品图</view>
<!-- 有图:九宫格/多行平铺;无图:占位 -->
<view class="img-grid">
<image
v-for="(src, i) in detail.images_pull"
:key="i"
class="grid-img"
:src="src"
mode="aspectFill"
@click="previewImages(i)"
/>
</view>
</view>
<view class="hero">
<view class="section-title">附件</view>
<view v-if="detail.attachment_pull.length>0">
<view v-for="(file, i) in detail.attachment_pull" :key="i" class="fujian" @click="reviewFile(file)">
<p>{{file.name}}</p>
<view>查看</view>
</view>
</view>
<view class="noneview" v-else>
<img src="/static/image/none.png" alt="">
</view>
</view>
</view>
<uni-popup ref="inputDialog" type="dialog">
<view class="price-dialog">
<view class="pd-title">设置价格</view>
<view class="pd-row">
<view class="pd-label">贸易条款</view>
<view class="pd-price-line">
<uni-data-select
v-model="priceForm.trade_term"
class="tradeTerm"
:localdata="tradeTermOptions"
:clear="false"
/>
</view>
</view>
<view class="pd-row">
<view class="pd-label">价格</view>
<view class="pd-price-line">
<view class="pd-input-suffix-wrap">
<input
class="pd-input pd-input-price pd-input-with-suffix"
v-model="priceForm.price"
type="number"
inputmode="decimal"
placeholder="请输入数字"
@input="onPriceInput"
/>
<!-- 币种下拉:放在输入框内部右侧(无边框) -->
<view class="pd-currency-suffix">
<uni-data-select
v-model="priceForm.currency"
:localdata="currencyOptions"
:clear="false"
/>
</view>
</view>
</view>
</view>
<!-- 语言单选 -->
<view class="pd-row">
<view class="pd-label">语言</view>
<radio-group class="pd-radio-group" @change="onLangChange">
<label class="pd-radio" v-for="l in langOptions" :key="l.value">
<radio :value="l.value" :checked="priceForm.lang === l.value" />
<text class="pd-radio-text">{{ l.text }}</text>
</label>
</radio-group>
</view>
<!-- 操作按钮 -->
<view class="pd-actions">
<view class="pd-btn pd-cancel" @tap="closePriceDialog">取消</view>
<view class="pd-btn pd-confirm" @tap="confirmPriceDialog">确认</view>
</view>
</view>
</uni-popup>
</view>
</template>
<script>
import { request, showToast } from '@/api/apiT.js'
export default {
data() {
return {
id: '',
appid: '',
detail: {},
currentImageIndex: 0,
priceForm: {
price: "", // 只存数字字符串
currency: "USD", // USD | RUB | AED | EUR
lang: "en" // en | ru | es | ar
},
currencyOptions: [
{ value: "USD", text: "美元" },
{ value: "CNY", text: "人民币" },
{ value: "RUB", text: "卢布" },
{ value: "AED", text: "迪拉姆" },
{ value: "EUR", text: "欧元" }
],
langOptions: [
{ text: "英语", value: "en" },
{ text: "俄语", value: "ru" },
{ text: "西班牙语", value: "es" },
{ text: "阿拉伯语", value: "ar" }
],
tradeTermOptions: [
{ value: "FOB", text: "FOB" },
{ value: "CIF", text: "CIF" },
{ value: "EXW", text: "EXW" },
{ value: "DDP", text: "DDP" },
{ value: "CIP", text: "CIP" },
{ value: "FCA", text: "FCA" },
{ value: "CFR", text: "CFR" }
]
}
},
computed: {
images() {
// 兼容:images 可能是数组、逗号字符串、或后端不同字段
const raw =
this.detail.images_pull ||[]
if (Array.isArray(raw)) {
return raw.filter(Boolean)
}
if (typeof raw === 'string') {
return raw
.split(',')
.map(s => (s || '').trim())
.filter(Boolean)
}
return []
}
},
onLoad(options) {
// 1) 支持通过 id 打开:/pages/index/detils?id=123
this.id = options?.id || ''
// 2) 分享链接里会带 appid,用于未登录时拉起飞书免登
const appid = options?.appid || uni.getStorageSync('fsappid') || ''
if (appid) uni.setStorageSync('fsappid', appid)
// 3) 如果未登录:先去登录页,登录成功后再回到当前详情页
const token = uni.getStorageSync('token')
if (!token) {
const redirect = `/pages/index/detils?id=${this.id}${appid ? `&appid=${encodeURIComponent(appid)}` : ''}`
uni.setStorageSync('post_login_redirect', redirect)
// 使用 reLaunch,避免用户打开分享链接后历史栈混乱
uni.reLaunch({
url: `/pages/login/index?appid=${encodeURIComponent(appid)}&redirect=${encodeURIComponent(redirect)}`
})
return
}
this.getshows()
},
methods: {
//获取详情
getshows(){
let that = this;
request({
url:'common/usedcar/show',
method:'GET',
data:{
id:that.id
}
}).then(res => {
if (res.data.code == 200) {
this.detail = res.data.data
}
})
},
goBack() {
uni.navigateBack({
delta: 1,
fail: () => {
// 某些环境下没有历史栈,兜底回首页
uni.reLaunch({ url: '/pages/index/index' })
}
})
},
previewImages(startIndex) {
if (!this.images || this.images.length === 0) return
this.currentImageIndex = startIndex || 0
uni.previewImage({
current: this.images[this.currentImageIndex],
urls: this.images
})
},
downloadByAnchor(url, filename) {
try {
const a = document.createElement('a')
a.href = url
a.download = filename || ''
a.target = '_blank'
document.body.appendChild(a)
a.click()
document.body.removeChild(a)
} catch (e) {
// 兜底:直接打开
if (typeof window !== 'undefined') window.open(url, '_blank')
}
},
reviewFile(file){
this.downloadByAnchor(file.src_pull, file.name)
},
// 打开弹框时调用:可传默认值(可选)
openPriceDialog() {
this.priceForm = {
trade_term:'',
price: "",
currency: "USD",
lang: "en"
}
this.$refs.inputDialog.open()
},
closePriceDialog() {
this.$refs.inputDialog.close()
},
// 只允许数字 + 可选1个小数点(你要“纯整数”也行,我后面给你一行改法)
onPriceInput(e) {
let v = (e.detail && e.detail.value) ? String(e.detail.value) : String(this.priceForm.price || "")
// 过滤掉非数字和点
v = v.replace(/[^\d.]/g, "")
// 只保留第一个小数点
const parts = v.split(".")
if (parts.length > 2) {
v = parts[0] + "." + parts.slice(1).join("")
}
// 去掉开头多余 0(保留 0.xxx)
v = v.replace(/^0+(\d)/, "$1")
if (v.startsWith(".")) v = "0" + v
this.priceForm.price = v
},
onCurrencyPickerChange(e) {
const idx = Number(e.detail.value || 0)
this.currencyIndex = idx
this.priceForm.currency = this.currencyOptions[idx]?.value || "USD"
},
onLangChange(e) {
this.priceForm.lang = e.detail.value
},
confirmPriceDialog() {
// 校验
if (!this.priceForm.trade_term) {
return uni.showToast({ title: "请选择贸易条款", icon: "none" })
}
if (!this.priceForm.price) {
return uni.showToast({ title: "请输入价格", icon: "none" })
}
const payload = {
trade_term:this.priceForm.trade_term,
price: this.priceForm.price, // 数字字符串
currency: this.priceForm.currency, // USD/RUB/AED/EUR
lang: this.priceForm.lang // en/ru/es/ar
}
console.log(payload)
this.closePriceDialog()
this.dialogInputConfirm(payload)
},
dialogInputConfirm(val) {
if (!val.price) {
uni.showToast({ title: '请输入价格', icon: 'none' })
return
}
request({
url: 'common/usedcar/produce/pdf',
method: 'get',
data: { id: this.id, price:val.price,currency:val.currency,lang:val.lang,trade_term:val.trade_term }
}).then(res => {
if (res.data.code == 200) {
this.downloadpdf(this.id)
} else {
uni.showToast({ title: res.data.msg || '生成失败', icon: 'none' })
}
})
},
// H5 下载:用 a 标签触发
downloadByAnchor(url, filename) {
try {
const a = document.createElement('a')
a.href = url
a.download = filename || ''
a.target = '_blank'
document.body.appendChild(a)
a.click()
document.body.removeChild(a)
} catch (e) {
// 兜底:直接打开
if (typeof window !== 'undefined') window.open(url, '_blank')
}
},
downloadpdf(item) {
request({
url: 'common/usedcar/pdf',
method: 'get',
data: { id: item }
}).then(res => {
if (res.data.code == 200) {
this.downloadByAnchor(res.data.data.pdf_url, res.data.data.file_name)
}
})
}
}
}
</script>
<style scoped lang="scss">
.tradeTerm{
border: 1px solid #eae9e9;
border-radius: 6px;
}
.heard{
padding: 5px 0px;
color: #666;
font-size: 12px;
display: flex;
align-items: center;
justify-content: space-between;
}
.page {
min-height: 100vh;
background: #f6f7fb;
}
.content {
padding: 18rpx;
box-sizing: border-box;
}
.hero {
position: relative;
border-radius: 18rpx;
overflow: hidden;
margin-top: 16rpx;
background: #fff;
padding: 18rpx 18rpx;
box-shadow: 0 10rpx 30rpx rgba(0, 0, 0, 0.06);
}
.img-grid {
display: flex;
flex-wrap: wrap;
gap: 10rpx;
padding: 10rpx;
box-sizing: border-box;
}
.grid-img {
width: calc((100% - 20rpx) / 3);
height: 220rpx;
border-radius: 14rpx;
background: #f3f4f6;
}
.grid-img-single {
width: 100%;
height: 420rpx;
border-radius: 14rpx;
}
.hero-badges {
position: absolute;
left: 14rpx;
bottom: 14rpx;
display: flex;
gap: 10rpx;
}
.badge {
padding: 10rpx 14rpx;
border-radius: 999rpx;
font-size: 24rpx;
color: #fff;
background: rgba(255, 151, 47, 0.95);
}
.badge-ghost {
background: rgba(0, 0, 0, 0.4);
}
.card {
margin-top: 16rpx;
background: #fff;
border-radius: 18rpx;
padding: 18rpx 18rpx;
box-shadow: 0 10rpx 30rpx rgba(0, 0, 0, 0.05);
box-sizing: border-box;
}
.title-row {
display: flex;
align-items: center;
justify-content: space-between;
}
.name {
font-size: 34rpx;
font-weight: 700;
color: #111827;
line-height: 1.2;
}
.sub-row {
margin-top: 10rpx;
display: flex;
justify-content: space-between;
gap: 12rpx;
flex-wrap: wrap;
}
.sub {
font-size: 24rpx;
color: #6b7280;
}
.kv {
display: flex;
flex-direction: column;
}
.kv-item {
padding: 16rpx 0;
display: flex;
align-items: center;
justify-content: space-between;
border-bottom: 1rpx solid #f1f5f9;
}
.kv-item:last-child {
border-bottom: none;
padding-bottom: 0;
}
.k {
width: 180rpx;
font-size: 26rpx;
color: #374151;
flex-shrink: 0;
}
.v {
font-size: 26rpx;
color: #111827;
text-align: right;
flex: 1;
margin-left: 12rpx;
}
.ellipsis {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.copy {
margin-left: 12rpx;
font-size: 22rpx;
color: #ff972f;
flex-shrink: 0;
}
.section-title {
font-size: 28rpx;
font-weight: 700;
color: #111827;
margin-bottom: 10rpx;
}
.desc {
font-size: 26rpx;
color: #374151;
line-height: 1.7;
white-space: pre-wrap;
}
.footer {
padding: 28rpx 0 40rpx;
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
gap: 14rpx;
}
.footer-text {
font-size: 24rpx;
color: #6b7280;
}
.retry {
padding: 14rpx 26rpx;
border-radius: 999rpx;
background: rgba(255, 151, 47, 0.12);
color: #ff972f;
font-size: 24rpx;
}
.fujian{
display: flex;
align-items: center;
justify-content: space-between;
border: 1px solid #ebebeb;
padding: 8px 10px;
border-radius: 4px;
}
.noneview{
text-align: center;
}
.price-dialog{
width: 640rpx;
background: #fff;
border-radius: 24rpx;
padding: 28rpx;
}
.pd-title{
font-size: 34rpx;
font-weight: 600;
color: #111;
margin-bottom: 20rpx;
text-align: center;
}
.pd-row{
display:flex;
align-items:center;
margin-top: 40rpx;
}
.pd-row-col{
flex-direction: column;
align-items: flex-start;
}
.pd-label{
width: 120rpx;
font-size: 28rpx;
color:#333;
}
.pd-input{
flex:1;
height: 66rpx;
border: 1px solid #eee;
border-radius: 16rpx;
padding: 0 18rpx;
font-size: 30rpx;
}
.pd-input-suffix-wrap{
position: relative;
flex: 1;
}
.pd-input-with-suffix{
padding-right: 180rpx; /* 给右侧币种留空间 */
}
.pd-currency-suffix{
position: absolute;
right: 14rpx;
top: 50%;
transform: translateY(-50%);
width: 140rpx;
height: 80rpx;
display: flex;
align-items: center;
justify-content: flex-end;
}
::v-deep .uni-select{
border: none !important;
}
.pd-radio-group{
display:flex;
flex-wrap: wrap;
gap: 16rpx 22rpx;
margin-top: 12rpx;
}
.pd-radio{
display:flex;
align-items:center;
}
.pd-radio-text{
margin-left: 10rpx;
font-size: 26rpx;
color:#333;
}
.pd-actions{
display:flex;
gap: 18rpx;
margin-top: 40rpx;
}
.pd-btn{
flex:1;
height: 84rpx;
border-radius: 18rpx;
display:flex;
align-items:center;
justify-content:center;
font-size: 30rpx;
}
.pd-cancel{
background:#f5f5f5;
color:#333;
}
.pd-confirm{
background:#3F435B; /* 你喜欢绿色风格 */
color:#fff;
font-weight:600;
}
.pd-price-line{
flex: 1;
display: flex;
align-items: center;
gap: 16rpx;
}
.pd-input-price{
flex: 1;
min-width: 240rpx;
}
</style>