Files
hs-usedcar-miniapp/pages/carinfo/index.vue
T
2025-09-19 09:54:43 +08:00

548 lines
15 KiB
Vue

<template>
<view>
<uni-nav-bar leftText=" " :fixed="true" :border="false" leftIcon="back" @clickLeft="leftClick" color="#000000" backgroundColor="#fff" :statusBar="true" :title="$t('navbar.newcar')"></uni-nav-bar>
<view class="content">
<view class="cell">
<view>{{$t('carinfo.productName')}} <text class="red">*</text></view>
<view class="right">
<input :placeholder="$t('carinfo.inputproduct')" v-model="carinfo.name" />
</view>
</view>
<view class="cell">
<view>{{$t('carinfo.product_image')}}</view>
<view class="right">
<uni-file-picker fileMediatype="image" limit="1" @select="select" @delete="delfn" :del-icon="false" disable-preview :imageStyles="imageStyles">
<!-- <image src="/static/image/img.png" mode="" class="addimg"></image> -->
</uni-file-picker>
</view>
</view>
<view class="cell">
<view>{{$t('carinfo.vin')}}</view>
<view class="right">
<input :placeholder="$t('carinfo.inputVIN')" v-model="carinfo.vin" />
</view>
</view>
<view class="cell">
<view>{{$t('carinfo.brand')}}</view>
<view class="right select" @click="showbrand = true">
<input :placeholder="$t('carinfo.selectbrand')" disabled v-model="brandname" />
<!-- <u-picker :cancel-text="$t('cancel')" :confirm-text="$t('confirm')" :show="showbrand" @cancel="cancel('showbrand')" :columns="brandList" keyName="name" @confirm="changeHandler"></u-picker> -->
<!-- <ld-select :list="brandList" label-key="name" value-key="brand_id" placeholder="请选择" v-model="carinfo.brand" @change="brandChange"></ld-select> -->
<uni-icons type="right" size="18" color="#747474"></uni-icons>
</view>
</view>
<view class="cell">
<view>{{$t('carinfo.model')}}</view>
<view class="right select" @click="showmodel = true">
<input :placeholder="$t('carinfo.selectmodel')" disabled v-model="model" />
<u-picker :cancel-text="$t('cancel')" :confirm-text="$t('confirm')" :show="showmodel" @cancel="cancel('showmodel')" :columns="modelList" keyName="name" @confirm="modelChange"></u-picker>
<!-- <ld-select :list="typesList" label-key="name" value-key="energy_id" placeholder="选择车辆类型" v-model="carinfo.type" @change="typesChange"></ld-select> -->
<uni-icons type="right" size="18" color="#747474"></uni-icons>
</view>
</view>
<view class="cell">
<view>{{$t('carinfo.price')}}</view>
<view class="right">
<input :placeholder="$t('carinfo.inputprice')" type="digit" v-model="carinfo.price" />
</view>
</view>
<view class="cell">
<view>{{$t('carinfo.type')}}</view>
<view class="right select" @click="showtype = true">
<input :placeholder="$t('carinfo.selecttype')" disabled v-model="type" />
<u-picker :defaultIndex="defaultIndex2" :cancel-text="$t('cancel')" :confirm-text="$t('confirm')" :show="showtype" @cancel="cancel('showtype')" :columns="typesList" keyName="name" @confirm="typesChange"></u-picker>
<!-- <ld-select :list="typesList" label-key="name" value-key="energy_id" placeholder="选择车辆类型" v-model="carinfo.type" @change="typesChange"></ld-select> -->
<uni-icons type="right" size="18" color="#747474"></uni-icons>
</view>
</view>
<view class="cell">
<view>{{$t('carinfo.energy')}}</view>
<view class="right select" @click="showenergy = true">
<input :placeholder="$t('carinfo.selectenergy')" disabled v-model="energy" />
<u-picker :defaultIndex="defaultIndex2" :cancel-text="$t('cancel')" :confirm-text="$t('confirm')" :show="showenergy" @cancel="cancel('showenergy')" :columns="energyList" keyName="name" @confirm="energyChange"></u-picker>
<!-- <ld-select :list="energyList" label-key="name" value-key="energy_id" placeholder="选择能源类型" v-model="carinfo.energy" @change="energyChange"></ld-select> -->
<uni-icons type="right" size="18" color="#747474"></uni-icons>
</view>
</view>
<view class="cell">
<view>{{$t('carinfo.store_status')}}</view>
<view class="right select" @click="showstatus = true">
<input :placeholder="$t('carinfo.select')" disabled v-model="store_status" />
<u-picker :defaultIndex="defaultIndex2" :cancel-text="$t('cancel')" :confirm-text="$t('confirm')" :show="showstatus" @cancel="cancel('showstatus')" :columns="statusList" keyName="name" @confirm="statusChange"></u-picker>
<uni-icons type="right" size="18" color="#747474"></uni-icons>
</view>
</view>
<view class="cell">
<view>{{$t('carinfo.location')}}</view>
<view class="right select" @click="showlocation = true">
<input :placeholder="$t('carinfo.select')" disabled v-model="location" />
<u-picker :defaultIndex="defaultIndex2" :cancel-text="$t('cancel')" :confirm-text="$t('confirm')" :show="showlocation" @cancel="cancel('showlocation')" :columns="locationList" keyName="name" @confirm="locationChange"></u-picker>
<uni-icons type="right" size="18" color="#747474"></uni-icons>
</view>
</view>
<view class="cell">
<view>{{$t('carinfo.mileage')}}</view>
<view class="right">
<input :placeholder="$t('carinfo.inputmileage')" type="digit" v-model="carinfo.mileage"/>
</view>
</view>
<view class="cell1">
<view>{{$t('carinfo.age')}}</view>
<view class="right">
<input :placeholder="$t('carinfo.inputage')" type="digit" v-model="carinfo.vehicle_age" />
</view>
</view>
</view>
<view class="">
<movable-area class="movable-area">
<movable-view class="movable-view" :x="x" :y="y" direction="all">
<view class="index" @tap="draftadd" >
<image v-if="i18locale=='zh'" src="/static/image/cg.png" mode="widthFix">
<image v-if="i18locale=='en'" src="/static/image/cge.png" mode="widthFix">
<image v-if="i18locale=='ru'" src="/static/image/cgr.png" mode="widthFix">
</view>
</movable-view>
</movable-area>
</view>
<view class="zw"></view>
<view class="foot">
<button class="btn" @click="nextFn">{{$t('button.next')}}</button>
</view>
<u-popup closeOnClickOverlay :show="showbrand" mode="bottom" :round="10" @close="cancel('showbrand')">
<view class="text">
<view class="qx" @click="cancel('showbrand') ">{{$t('cancel')}}</view>
<view class="qd" @click="changeHandler">{{$t('confirm')}}</view>
</view>
<view class="popup-content">
<!-- 搜索框 -->
<u-input
v-model="searchKeyword"
:placeholder="$t('keyword')"
@input="handleSearch"
></u-input>
<!-- 选项列表 -->
<scroll-view scroll-y class="option-list">
<view
v-for="(item, index) in filteredOptions"
:key="index"
class="option-item"
@click="handleSelect(item)"
:class="actives==item.id?'actives':''"
>
{{ item.name }}
</view>
<view v-if="filteredOptions.length === 0" class="no-data">
{{$t('noresults')}}
</view>
</scroll-view>
</view>
</u-popup>
</view>
</template>
<script>
import { request,showToast } from '@/api/apiT.js'
// import ldSelect from '@/components/ld-select/ld-select.vue'
export default {
data() {
return {
imageStyles: {
width: 50,
height: 50,
},
showbrand: false,
showtype: false,
showenergy: false,
showmodel: false,
showstatus: false,
showlocation: false,
actives:'',
searchKeyword: "", // 搜索关键词
selectedLabel: "", // 选中的值(显示在输入框中)
filteredOptions: [], // 过滤后的数据
x: 300, //x坐标
y: 550, //y坐标
brandList:[],
energyList:[],
typesList:[],
modelList:[],
locationList:[],
statusList:[[{
name: this.$t('carinfo.in_stock'),
id: '1'
}, {
name: this.$t('carinfo.in_transit'),
id: '2'
},{
name: this.$t('carinfo.on_order'),
id: '3'
}]],
brandname:'',
model:'',
location:'',
type:'',
energy:'',
store_status:'',
defaultIndex2:[0],
i18locale:uni.getStorageSync('i18locale')?uni.getStorageSync('i18locale'):'zh',
carinfo:{
name:'',
brand:'',
price:0,
cover:'',
type:'',
energy:'',
mileage :'',
model:'',
location:'',
store_status:'',
vehicle_age:'',
condition_desc:'',
front_45_degree:'',
front_left_45_degree:'',
front_left_headlight:'',
front_view:'',
lower_front:'',
wheel_hub:'',
front_right_seat:'',
right_lower_side:'',
rear_right_taillight:'',
rear_right_45_degree:'',
lower_rear:'',
trunk:'',
left_lower_side:'',
rear_seats:'',
center_console:'',
control_panel:'',
gear_shift:'',
car_key:'',
steering_wheel:'',
dashboard:'',
odometer_reading:'',
front_left_door_panel:'',
front_left_door_function_area:'',
front_left_seat:'',
interior_ceiling:'',
}
}
},
onLoad() {
this.getbrand()
this.getenergy()
this.gettypes()
this.getlocation()
const { windowWidth, windowHeight } = uni.getSystemInfoSync();
this.x = windowWidth-70
this.y = windowHeight-185
},
methods: {
uploadfn(imgUrl){
var that = this;
uni.uploadFile({
url: 'https://usedcar.server.hnxinyouhe.com/applet/upload/image',
filePath: imgUrl,
name: 'image',
header:{'lang':this.i18locale,'Authorization': 'Bearer ' + uni.getStorageSync('token')},
success: (uploadFileRes) => {
const path=JSON.parse(uploadFileRes.data)
that.carinfo.cover = path.data.image_name
console.log(that.carinfo)
}
});
},
delfn(){
that.carinfo.cover =''
},
select(e){
const tempFilePaths = e.tempFilePaths;
const imgUrl=tempFilePaths[0]
this.uploadfn(imgUrl)
},
// 搜索处理函数
handleSearch() {
var that = this
if (this.searchKeyword) {
console.log(this.searchKeyword)
this.filteredOptions = this.brandList.filter((item) => item.name.includes(this.searchKeyword));
console.log(this.filteredOptions)
} else {
// 如果搜索框为空,显示全部数据
this.filteredOptions = this.brandList;
}
},
// 选择选项
handleSelect(item) {
this.selectedLabel = item.name; // 回显选中的值
// this.searchKeyword = item.name
this.actives = item.id
// this.showPicker = false; // 关闭弹窗
console.log("选中的值:", item.id);
console.log("选中的值:", item.name);
},
getbrand(){
request({
url:'brand',
method:'get',
}).then(res => {
var list = res.data.data
this.brandList = list
this.filteredOptions = list;
this.brandname = list[0].name
this.carinfo.brand = list[0].id
this.getmodel(this.carinfo.brand)
// this.brandList = [list]
})
},
getenergy(){
request({
url:'energy',
method:'get',
}).then(res => {
var list = res.data.data
this.energyList = [list]
this.energy = list[0].name
this.carinfo.energy = list[0].id
})
},
getmodel(brand_id){
request({
url:'models',
method:'get',
data:{
brand_id:brand_id
}
}).then(res => {
var list = res.data.data
this.modelList = [list]
if(list.length>0){
this.model = list[0].name
this.carinfo.model = list[0].id
}else{
this.model =''
this.carinfo.model =''
}
})
},
gettypes(){
request({
url:'types',
method:'get'
}).then(res => {
var list = res.data.data
this.typesList = [list]
this.type = list[0].name
this.carinfo.type = list[0].id
})
},
getlocation(){
request({
url:'location/presets',
method:'get'
}).then(res => {
var list = res.data.data
this.locationList = [list]
this.location = list[0].name
this.carinfo.location = list[0].id
console.log(this.locationList)
})
},
draftadd(){
if(uni.getStorageSync('draftid')){
request({
url:'draft/update/'+uni.getStorageSync('draftid'),
method:'post',
data:this.carinfo
}).then(res => {
uni.showToast({
title: res.data.message,
icon: 'none'
});
})
}else{
request({
url:'draft/add',
method:'post',
data:this.carinfo
}).then(res => {
uni.showToast({
title: res.data.message,
icon: 'none'
});
if(res.data.code ==0){
uni.setStorageSync('draftid', res.data.data.id);
}
console.log(res.data)
})
}
},
changeHandler(){
this.showbrand = false; // 关闭弹窗
this.brandname = this.selectedLabel
this.carinfo.brand = this.actives
this.getmodel(this.actives)
},
energyChange(val){
this.carinfo.energy = val.value[0].energy_id
this.energy = val.value[0].name
this.showenergy = false
},
typesChange(val){
this.carinfo.type = val.value[0].energy_id
this.type = val.value[0].name
this.showtype = false
},
modelChange(val){
this.carinfo.model = val.value[0].id
this.model = val.value[0].name
this.showmodel = false
},
statusChange(val){
this.carinfo.store_status = val.value[0].id
this.store_status = val.value[0].name
this.showstatus = false
},
locationChange(val){
this.carinfo.location = val.value[0].id
this.location = val.value[0].name
this.showlocation = false
},
cancel(val){
this[val] = false
},
leftClick(){
uni.navigateBack({})
},
nextFn(){
if(this.carinfo.name==''){
uni.showToast({
title:this.$t('message'),
icon: 'none'
});
return false
}
const carinfo = JSON.stringify(this.carinfo);
uni.setStorageSync('carinfo', carinfo);
uni.navigateTo({
url: '/pages/carinfo/info'
});
}
}
}
</script>
<style lang="scss">
.uniui-right{
position: absolute;
top: 2px;
}
.red{
color: red;
}
.content{
margin: 20px 12px;
background: #FFFFFF;
border-radius: 10px;
}
.zw{
height: 120px;
}
.cell{
position: relative;
display: flex;
justify-content:space-between;
padding: 18px 20px;
/* border-bottom: 1px solid #C3C3C3; */
align-items: center;
font-weight: 500;
}
.cell::after{
content : '';
position : absolute;
width : 200%;
height : 200%;
top : 0;
left : 0;
transform-origin: 0 0;
border-width: 0;
border-bottom-width:1px;
border-style : solid;
transform : scale(0.5, 0.5);
border-radius : 1px;
box-sizing : border-box;
pointer-events : none;
border-color:#C3C3C3;
}
.cell1{
display: flex;
justify-content:space-between;
padding: 18px 20px;
align-items: center;
font-weight: 500;
}
.right{
text-align: right;
}
.select{
display: flex;
position: relative;
margin-right: 10px;
}
.foot{
position: fixed;
bottom: 0px;
width: 100%;
height: 120px;
background: #FFFFFF;
z-index: 2;
}
.btn{
background-color: #3F435B;
color: white;
border-radius: 50px;
width: 92%;
margin-bottom: 40px;
margin: 15px 4%;
}
.actives{
background-color: #dfdfdf;
}
.text{
display: flex;
align-items: center;
justify-content: space-between;
line-height: 30px;
padding: 10px 15px 0px;
.qd{
color: #3471FF;
}
}
.popup-content {
padding: 20px;
background-color: #fff;
}
.option-list {
max-height: 400rpx;
margin-top: 20rpx;
}
.option-item {
padding: 20rpx;
border-bottom: 1rpx solid #eee;
}
.option-item:last-child {
border-bottom: none;
}
.no-data {
text-align: center;
padding: 20rpx;
color: #999;
}
</style>