修改
This commit is contained in:
+180
-278
@@ -1,88 +1,62 @@
|
||||
<template>
|
||||
<view class="page">
|
||||
<uni-nav-bar leftText=" " :fixed="true" :border="false" color="#fff" backgroundColor="#3F435B" :statusBar="true" title="我的"></uni-nav-bar>
|
||||
<!-- 顶部:标题 + 搜索(不想要搜索可直接删除这一块) -->
|
||||
<view class="page-head">
|
||||
<view class="head-search">
|
||||
<u-search
|
||||
v-model="keyword"
|
||||
placeholder="请输入关键词"
|
||||
:show-action="false"
|
||||
shape="round"
|
||||
@search="onSearch"
|
||||
@clear="onSearch"
|
||||
/>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 列表 -->
|
||||
<view class="list-wrap">
|
||||
<uni-swipe-action-item
|
||||
:threshold="0"
|
||||
:right-options="options1"
|
||||
@click="bindClick"
|
||||
>
|
||||
<view
|
||||
v-for="(item, idx) in list"
|
||||
:key="item.id || item.car_id || item.product_id || idx"
|
||||
class="car-card"
|
||||
@tap="goDetail(item)"
|
||||
>
|
||||
<image class="thumb" src="/static/image/car.png" mode="aspectFill" />
|
||||
<view class="info">
|
||||
<view class="row row1">
|
||||
<text class="name u-line-1">{{ item.name }}</text>
|
||||
</view>
|
||||
|
||||
<view class="row row2">
|
||||
<view class="kv">
|
||||
<text class="k">车源地</text>
|
||||
<text class="v u-line-1">{{ item.source }}</text>
|
||||
</view>
|
||||
<view class="kv">
|
||||
<text class="k">车身颜色</text>
|
||||
<text class="v u-line-1">{{ item.color }}</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="row row3">
|
||||
<view class="kv">
|
||||
<text class="k">上牌时间</text>
|
||||
<text class="v">{{ item.plate_time }}</text>
|
||||
</view>
|
||||
<view class="kv">
|
||||
<text class="k">里程</text>
|
||||
<text class="v">{{ item.mileage }}</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<z-paging ref="paging" v-model="list" @query="queryList" empty-view-text="暂无数据!">
|
||||
<!-- <uni-nav-bar leftText=" " :fixed="true" :border="false" color="#fff" backgroundColor="#3F435B" :statusBar="true" title="首页"></uni-nav-bar> -->
|
||||
<!-- 顶部:标题 + 搜索(不想要搜索可直接删除这一块) -->
|
||||
<view class="page-head">
|
||||
<view class="head-search">
|
||||
<u-search
|
||||
v-model="keyword"
|
||||
placeholder="请输入关键词"
|
||||
:show-action="false"
|
||||
shape="round"
|
||||
@change="onKeywordChange"
|
||||
@search="onSearch"
|
||||
@clear="onSearch"
|
||||
/>
|
||||
</view>
|
||||
</uni-swipe-action-item>
|
||||
|
||||
|
||||
<!-- 空状态 -->
|
||||
<u-empty v-if="!loading && list.length === 0" text="暂无数据" mode="data" />
|
||||
|
||||
<!-- 底部加载状态 -->
|
||||
<view v-if="list.length > 0" class="loadmore">
|
||||
<u-loadmore :status="loadStatus" />
|
||||
</view>
|
||||
</view>
|
||||
<view class="list-wrap">
|
||||
<uni-swipe-action-item
|
||||
v-for="item in list"
|
||||
:key="item.id"
|
||||
:right-options="options1"
|
||||
@click="swipeClick($event, item)"
|
||||
>
|
||||
<CarCard
|
||||
:item="item"
|
||||
@pdfchange="onSearch"
|
||||
@request-price="onRequestPrice"
|
||||
/>
|
||||
</uni-swipe-action-item>
|
||||
</view>
|
||||
</z-paging>
|
||||
<uni-popup ref="inputDialog" type="dialog">
|
||||
<uni-popup-dialog
|
||||
mode="input"
|
||||
title="请输入价格"
|
||||
:value="priceDialogValue"
|
||||
placeholder="请输入车辆价格"
|
||||
@confirm="dialogInputConfirm"
|
||||
/>
|
||||
</uni-popup>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { request } from '@/api/apiT.js'
|
||||
|
||||
/**
|
||||
* 首页列表接口(你如果后端接口不是这个路径,改这里即可)
|
||||
* 兼容分页:page/per_page(或 page/page_size)
|
||||
*/
|
||||
const LIST_API = 'car/list'
|
||||
import CarCard from '@/components/CarCard/CarCard.vue'
|
||||
|
||||
export default {
|
||||
components: {
|
||||
CarCard
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
priceDialogItem: null,
|
||||
priceDialogIndex: -1,
|
||||
priceDialogValue: '',
|
||||
options1: [{
|
||||
text: '编辑',
|
||||
style: {
|
||||
@@ -101,140 +75,142 @@
|
||||
pageSize: 10,
|
||||
loading: false,
|
||||
finished: false,
|
||||
list: [
|
||||
{
|
||||
name:'奥迪Q3 2013款 35 TFSI 舒适型',
|
||||
source:'北京',
|
||||
color:'黑色',
|
||||
plate_time:'2013-07',
|
||||
mileage:'11万公里'
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
loadStatus() {
|
||||
if (this.loading && this.page === 1) return 'loading'
|
||||
if (this.loading) return 'loading'
|
||||
if (this.finished) return 'nomore'
|
||||
return 'loadmore'
|
||||
list: []
|
||||
}
|
||||
},
|
||||
onLoad() {
|
||||
this.fetchList(true)
|
||||
},
|
||||
onPullDownRefresh() {
|
||||
this.fetchList(true).finally(() => {
|
||||
uni.stopPullDownRefresh()
|
||||
})
|
||||
},
|
||||
onReachBottom() {
|
||||
if (!this.loading && !this.finished) {
|
||||
this.fetchList(false)
|
||||
}
|
||||
// H5:处理分享兜底参数 r(如果路由没命中/经历登录回跳,会先落到首页)
|
||||
// #ifdef H5
|
||||
try {
|
||||
const u = new URL(window.location.href)
|
||||
const r = u.searchParams.get('r')
|
||||
if (r) {
|
||||
const target = decodeURIComponent(r)
|
||||
// 清理地址栏的 r,避免反复跳转
|
||||
u.searchParams.delete('r')
|
||||
window.history.replaceState({}, '', u.toString())
|
||||
// 让首页加载完再跳
|
||||
setTimeout(() => {
|
||||
uni.navigateTo({ url: target })
|
||||
}, 50)
|
||||
}
|
||||
} catch (e) {}
|
||||
// #endif
|
||||
},
|
||||
methods: {
|
||||
onSearch() {
|
||||
this.fetchList(true)
|
||||
},
|
||||
async fetchList(reset = false) {
|
||||
if (this.loading) return
|
||||
this.loading = true
|
||||
try {
|
||||
if (reset) {
|
||||
this.page = 1
|
||||
this.finished = false
|
||||
}
|
||||
|
||||
const res = await request({
|
||||
url: LIST_API,
|
||||
method: 'GET',
|
||||
data: {
|
||||
page: this.page,
|
||||
per_page: this.pageSize,
|
||||
keyword: this.keyword || ''
|
||||
}
|
||||
})
|
||||
|
||||
const payload = (res && res.data) ? res.data : {}
|
||||
const data = payload.data || payload || {}
|
||||
|
||||
// 兼容不同后端结构:list / data / items / rows / records
|
||||
let rows =
|
||||
data.list ||
|
||||
data.data ||
|
||||
data.items ||
|
||||
data.rows ||
|
||||
data.records ||
|
||||
[]
|
||||
|
||||
if (!Array.isArray(rows)) {
|
||||
rows = []
|
||||
}
|
||||
|
||||
if (reset) this.list = []
|
||||
this.list = this.list.concat(rows)
|
||||
|
||||
// 兼容 total / last_page / has_more 等字段
|
||||
const hasMore =
|
||||
(data.has_more === true) ||
|
||||
(data.next_page_url ? true : false) ||
|
||||
(false)
|
||||
|
||||
if (rows.length < this.pageSize && !hasMore) {
|
||||
this.finished = true
|
||||
} else {
|
||||
this.page += 1
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('[home fetchList] error:', e)
|
||||
uni.showToast({ title: e?.message || '加载失败', icon: 'none' })
|
||||
} finally {
|
||||
this.loading = false
|
||||
}
|
||||
},
|
||||
|
||||
goDetail(item) {
|
||||
// 你后续详情页如果要接 id,这里按后端字段改一下即可
|
||||
const id = item.id || item.car_id || item.product_id || ''
|
||||
uni.navigateTo({
|
||||
url: `/pages/index/detils?id=${encodeURIComponent(id)}`
|
||||
onRequestPrice(payload) {
|
||||
// payload: { item, index }
|
||||
this.priceDialogItem = payload && payload.item ? payload.item : null
|
||||
this.priceDialogIndex = payload && typeof payload.index === 'number' ? payload.index : -1
|
||||
this.priceDialogValue = ''
|
||||
this.$nextTick(() => {
|
||||
this.$refs.inputDialog && this.$refs.inputDialog.open()
|
||||
})
|
||||
},
|
||||
formatPlate(v) {
|
||||
if (!v || v === '-') return '-'
|
||||
// 允许:时间戳 / yyyy-mm-dd / yyyy/mm/dd / yyyyMMdd
|
||||
let d
|
||||
if (typeof v === 'number' || /^\d+$/.test(String(v))) {
|
||||
const n = Number(v)
|
||||
// 秒/毫秒都兼容
|
||||
d = new Date(n < 1e12 ? n * 1000 : n)
|
||||
} else {
|
||||
const s = String(v)
|
||||
const s2 = s.replace(/\//g, '-').trim()
|
||||
if (/^\d{8}$/.test(s2)) {
|
||||
const y = s2.slice(0, 4)
|
||||
const m = s2.slice(4, 6)
|
||||
const dd = s2.slice(6, 8)
|
||||
d = new Date(`${y}-${m}-${dd}T00:00:00`)
|
||||
dialogInputConfirm(val) {
|
||||
const item = this.priceDialogItem
|
||||
const index = this.priceDialogIndex
|
||||
const price = String(val || '').trim()
|
||||
|
||||
if (!item) return
|
||||
if (!price) {
|
||||
uni.showToast({ title: '请输入价格', icon: 'none' })
|
||||
return
|
||||
}
|
||||
if (isNaN(price) || Number(price) <= 0) {
|
||||
uni.showToast({ title: '请输入有效的价格', icon: 'none' })
|
||||
return
|
||||
}
|
||||
|
||||
request({
|
||||
url: 'common/usedcar/produce/pdf',
|
||||
method: 'get',
|
||||
data: { id: item.id, price }
|
||||
}).then(res => {
|
||||
if (res.data.code == 200) {
|
||||
// 通知刷新列表(你原来就是靠这个事件刷新)
|
||||
this.onSearch()
|
||||
|
||||
// 直接调用对应卡片实例的下载方法(如果 ref 数组存在的话)
|
||||
const cards = this.$refs.carCard
|
||||
const card = Array.isArray(cards) ? cards[index] : cards
|
||||
if (card && typeof card.downloadpdf === 'function') {
|
||||
card.downloadpdf(item)
|
||||
}
|
||||
} else {
|
||||
d = new Date(s2)
|
||||
uni.showToast({ title: res.data.msg || '生成失败', icon: 'none' })
|
||||
}
|
||||
}
|
||||
if (isNaN(d.getTime())) return String(v)
|
||||
const y = d.getFullYear()
|
||||
const m = String(d.getMonth() + 1).padStart(2, '0')
|
||||
return `${y}-${m}`
|
||||
})
|
||||
},
|
||||
formatMileage(v) {
|
||||
if (v === '-' || v === undefined || v === null || String(v).trim() === '') return '-'
|
||||
const n = Number(v)
|
||||
if (isNaN(n)) return String(v)
|
||||
// < 10000:直接显示;>= 10000:转万
|
||||
if (n >= 10000) {
|
||||
return `${(n / 10000).toFixed(1)}万 km`
|
||||
onKeywordChange(val) {
|
||||
// val 是输入值(uView 通常会传)
|
||||
this.keyword = val
|
||||
|
||||
// 防抖:300ms 内持续输入只触发一次
|
||||
if (this._kwTimer) clearTimeout(this._kwTimer)
|
||||
this._kwTimer = setTimeout(() => {
|
||||
this.onSearch()
|
||||
}, 300)
|
||||
},
|
||||
onSearch() {
|
||||
this.queryList(this.page,this.pageSize)
|
||||
},
|
||||
queryList(pageNo, pageSize, from) {
|
||||
this.loading = true;
|
||||
var that = this;
|
||||
const params = {
|
||||
current:pageNo,
|
||||
status:1,
|
||||
size:10
|
||||
};
|
||||
params.keyword = this.keyword;
|
||||
params.scene = 'self';
|
||||
request({
|
||||
url:'common/usedcar/list',
|
||||
method:'get',
|
||||
data: params
|
||||
}).then(res => {
|
||||
if(res.data.code ==200){
|
||||
var datas = res.data.data.records;
|
||||
this.$refs.paging.complete(datas);
|
||||
}else{
|
||||
}
|
||||
uni.stopPullDownRefresh();
|
||||
//
|
||||
})
|
||||
},
|
||||
swipeClick(e,item){
|
||||
let {
|
||||
content
|
||||
} = e;
|
||||
if (content.text === '删除') {
|
||||
uni.showModal({
|
||||
title: '提示',
|
||||
content: '是否删除',
|
||||
success: res => {
|
||||
if (res.confirm) {
|
||||
request({
|
||||
url:'common/usedcar/destroy',
|
||||
method:'post',
|
||||
data: {id:item.id}
|
||||
}).then(res => {
|
||||
uni.showToast({
|
||||
title: res.data.message,
|
||||
icon: 'none'
|
||||
});
|
||||
this.queryList()
|
||||
})
|
||||
} else if (res.cancel) {
|
||||
console.log('用户点击取消');
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
const id = item.id
|
||||
uni.navigateTo({
|
||||
url: `/pages/index/publishedit?id=${id}`
|
||||
})
|
||||
}
|
||||
return `${Math.round(n)} km`
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -247,13 +223,18 @@
|
||||
}
|
||||
|
||||
.page-head {
|
||||
// position: fixed;
|
||||
// width: 100%;
|
||||
position: fixed;
|
||||
width: 100%;
|
||||
bottom: 50px;
|
||||
z-index: 99;
|
||||
// padding: 28rpx 24rpx 18rpx;
|
||||
// background: linear-gradient(180deg, rgba(255, 151, 47, 0.22) 0%, rgba(255, 151, 47, 0.06) 55%, #f4f6f8 100%);
|
||||
}
|
||||
|
||||
.head-search {
|
||||
background: rgba(255, 255, 255, 0.9);
|
||||
// border-radius: 18rpx;
|
||||
padding: 6rpx;
|
||||
background: rgba(255, 255, 255, 1);
|
||||
border-radius: 18rpx;
|
||||
padding: 20rpx 10px;
|
||||
box-shadow: 0 10rpx 28rpx rgba(0, 0, 0, 0.06);
|
||||
}
|
||||
|
||||
@@ -261,85 +242,6 @@
|
||||
padding: 18rpx 24rpx 40rpx;
|
||||
}
|
||||
|
||||
.car-card {
|
||||
display: flex;
|
||||
align-items: stretch;
|
||||
padding: 18rpx;
|
||||
border-radius: 18rpx;
|
||||
background: rgba(255, 255, 255, 0.95);
|
||||
box-shadow: 0 10rpx 30rpx rgba(0, 0, 0, 0.06);
|
||||
// margin-bottom: 18rpx;
|
||||
}
|
||||
|
||||
.thumb {
|
||||
width: 190rpx;
|
||||
height: 140rpx;
|
||||
border-radius: 14rpx;
|
||||
background: #eef2f7;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.info {
|
||||
flex: 1;
|
||||
margin-left: 18rpx;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.row1 {
|
||||
justify-content: space-between;
|
||||
margin-bottom: 10rpx;
|
||||
}
|
||||
|
||||
.name {
|
||||
font-size: 30rpx;
|
||||
font-weight: 700;
|
||||
color: #111827;
|
||||
max-width: 420rpx;
|
||||
}
|
||||
|
||||
.tag {
|
||||
font-size: 22rpx;
|
||||
padding: 6rpx 12rpx;
|
||||
border-radius: 999rpx;
|
||||
background: rgba(255, 151, 47, 0.14);
|
||||
color: #b45309;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.row2,
|
||||
.row3 {
|
||||
justify-content: space-between;
|
||||
gap: 16rpx;
|
||||
}
|
||||
|
||||
.kv {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
}
|
||||
|
||||
.k {
|
||||
font-size: 22rpx;
|
||||
color: #6b7280;
|
||||
margin-right: 10rpx;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.v {
|
||||
font-size: 24rpx;
|
||||
color: #374151;
|
||||
font-weight: 600;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.loadmore {
|
||||
padding: 18rpx 0 6rpx;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user