当前位置: 代码网 > it编程>编程语言>Javascript > uniapp实现省市区三级级联选择功能(含地区json文件)

uniapp实现省市区三级级联选择功能(含地区json文件)

2024年06月11日 Javascript 我要评论
前言最近被安排做小程序用uniapp进行项目开发,有点惨啊。很烦。遇到一个需求需要选择地址,还是省市区级联选择,这里经过调查思考,最终做出来了,太不容易了。直接上代码一.项目结构二.相关代码引入imp

前言

最近被安排做小程序用uniapp进行项目开发,有点惨啊。很烦。

遇到一个需求需要选择地址,还是省市区级联选择,这里经过调查思考,最终做出来了,太不容易了。直接上代码

一.项目结构

二.相关代码

引入

	import provincedata from '../../static/js/area-full.json';
				oldpprovincedatalist: provincedata,
				newprovincedatalist: [
					[],
					[],
					[]
				],
				multiindex: [0, 0, 0],
				select: '请选择省市区',
				addressdata: {
					name: '',
					phone: '',
					address: ''
				},
				binhao: '1',
		onload() {
			let savedinfo = uni.getstoragesync('vehicleinfo');
			console.log('savedinfo', savedinfo)
			if (savedinfo) {
				this.saveinfo = savedinfo
			}
			// console.log('area', provincedata)
			// console.log(this.oldpprovincedatalist);
			for (let i = 0; i < this.oldpprovincedatalist.length; i++) {
				// console.log(this.oldpprovincedatalist[i].name);
				this.newprovincedatalist[0].push(this.oldpprovincedatalist[i].name);
			}
			for (let i = 0; i < this.oldpprovincedatalist[0].districts.length; i++) {
				// console.log(this.oldpprovincedatalist[0].city[i].name)
				this.newprovincedatalist[1].push(this.oldpprovincedatalist[0].districts[i].name);
			}
			for (let i = 0; i < this.oldpprovincedatalist[0].districts[0].districts.length; i++) {
				// console.log(this.oldpprovincedatalist[0].city[0].area)
				this.newprovincedatalist[2].push(this.oldpprovincedatalist[0].districts[0].districts[i].name);
			}


		},
	// 省市区确认事件
			pickerchange(e) {
				this.multiindex = e.detail.value;
				this.select =
					`${this.newprovincedatalist[0][this.multiindex[0]]},${this.newprovincedatalist[1][this.multiindex[1]]},${this.newprovincedatalist[2][this.multiindex[2]]}`
				// console.log('666',this.newprovincedatalist[2][this.multiindex[2]])
				if (this.addresstype == 1) {
					this.saveinfo.vehiclelocation = this.select
					
				} else if (this.addresstype == 2) {
					this.saveinfo.placeofbelonging = this.select
					
				}
				// this.$forceupdate()
			},
			pickercolumnchange(e) {
				// 第几列滑动
				// console.log(e.detail.column);
				// 第几列滑动的下标
				// console.log(e.detail.value)
				// 第一列滑动
				if (e.detail.column === 0) {
					this.multiindex[0] = e.detail.value
					// console.log('第一列滑动');
					// this.newprovincedatalist[1] = [];
					this.newprovincedatalist[1] = this.oldpprovincedatalist[this.multiindex[0]].districts.map((item,
						index) => {
						// console.log('1',item)
						return item.name
					})
					// console.log(this.multiindex)
					if (this.oldpprovincedatalist[this.multiindex[0]].districts.length === 1) {
						this.newprovincedatalist[2] = this.oldpprovincedatalist[this.multiindex[0]].districts[0].districts
							.map((item, index) => {
								// console.log('2',item)
								return item.name
							})
					} else {
						// console.log('444',this.oldpprovincedatalist[this.multiindex[0]].districts[this.multiindex[1]].districts);
						this.newprovincedatalist[2] = this.oldpprovincedatalist[this.multiindex[0]].districts[this
							.multiindex[1]].districts.map((item, index) => {
							// console.log('3',item)
							return item.name
						})
					}

					// 第一列滑动  第二列 和第三列 都变为第一个
					this.multiindex.splice(1, 1, 0)
					this.multiindex.splice(2, 1, 0)
				}
				// 第二列滑动
				if (e.detail.column === 1) {
					this.multiindex[1] = e.detail.value
					// console.log('第二列滑动');
					// console.log(this.multiindex)
					this.newprovincedatalist[2] = this.oldpprovincedatalist[this.multiindex[0]].districts[this.multiindex[
						1]].districts.map((item, index) => {
						// console.log(item)
						return item.name
					})
					// 第二列 滑动 第三列 变成第一个
					this.multiindex.splice(2, 1, 0)
				}
				// 第三列滑动
				if (e.detail.column === 2) {
					this.multiindex[2] = e.detail.value
					// console.log('第三列滑动')
					// console.log(this.multiindex)
				}

			},
			openselectitems(type) {
				this.addresstype = type
				if (type == 1) {
					this.select = this.saveinfo.vehiclelocation
				} else if (type == 2) {
					this.select = this.saveinfo.placeofbelonging
				}
				this.$refs.popup2.open()
			},

模板代码

			<view class="row-item fx-spt">
				<view class="fs-16 fw-500  color-0 ">车辆停放地区</view>
				<view class="input-content" @click="openselectitems(1)">
					<text class="fs-16 fw-500 mr-6 color-6 op-8">{{saveinfo.vehiclelocation?saveinfo.vehiclelocation:'请选择'}}</text>
					<uni-icons type="right" size="16" color="#666"></uni-icons>
				</view>
			</view>
			<view class="row-item fx-spt">
				<view class="fs-16 fw-500  color-0 ">车辆停放详细地址</view>
				<view class="input-content">
					<uni-easyinput :inputborder="false" :clearable="false" v-model="saveinfo.detailaddress"
						placeholderstyle="text-align:right" placeholder="请输入" cursorspacing="60px" />
				</view>
			</view>
			<view class="row-item fx-spt">
				<view class="fs-16 fw-500  color-0 ">归属地区</view>
				<view class="input-content" @click="openselectitems(2)">
					<text class="fs-16 fw-500 mr-6 color-6 op-8">{{saveinfo.placeofbelonging?saveinfo.placeofbelonging:'请选择'}}</text>
					<uni-icons type="right" size="16" color="#666"></uni-icons>
				</view>
			</view>
		</view>

三.完整代码实现

里面包含一些其它代码,看重点即可

<template>
	<view class="veh-info-container">
		<view class="page-content">
			<view class="row-item fx-spt">
				<view class="fs-16 fw-500  color-0 ">车辆类型</view>
				<view class="input-content" @click="openselect(1)">
					<text class="fs-16 fw-500 mr-6 color-6 op-8">{{saveinfo.modelname?saveinfo.modelname:'请选择'}}</text>
					<uni-icons type="right" size="16" color="#666"></uni-icons>
				</view>
			</view>
			<view class="row-item fx-spt">
				<view class="fs-16 fw-500  color-0 ">车辆品牌</view>
				<view class="input-content" @click="openselect(2)">
					<text class="fs-16 fw-500 mr-6 color-6 op-8">{{saveinfo.brandname?saveinfo.brandname:'请选择'}}</text>
					<uni-icons type="right" size="16" color="#666"></uni-icons>
				</view>
			</view>
			<view class="row-item fx-spt">
				<view class="fs-16 fw-500  color-0 ">车辆车系</view>
				<view class="input-content" @click="openselect(3)">
					<text class="fs-16 fw-500 mr-6 color-6 op-8">{{saveinfo.seriename?saveinfo.seriename:'请选择'}}</text>
					<uni-icons type="right" size="16" color="#666" :disabled="true"></uni-icons>
				</view>
			</view>
			<view class="row-item fx-spt">
				<view class="fs-16 fw-500  color-0 ">水淹等级</view>
				<view class="input-content" @click="openselect(4)">
					<text class="fs-16 fw-500 mr-6 color-6 op-8">{{saveinfo.watername?saveinfo.watername:'请选择'}}</text>
					<uni-icons type="right" size="16" color="#666"></uni-icons>
				</view>
			</view>
			<view class="row-item fx-spt">
				<view class="fs-16 fw-500  color-0 ">交强险至</view>
				<view class="input-content" @click="opendate(1)">
					<text class="fs-16 fw-500 mr-6 color-6 op-8">{{saveinfo.jqxname?saveinfo.jqxname:'请选择'}}</text>
					<uni-icons type="right" size="16" color="#666"></uni-icons>
				</view>
			</view>
			<view class="row-item fx-spt">
				<view class="fs-16 fw-500  color-0 ">年审至</view>
				<view class="input-content" @click="opendate(2)">
					<text class="fs-16 fw-500 mr-6 color-6 op-8">{{saveinfo.nsname?saveinfo.nsname:'请选择'}}</text>
					<uni-icons type="right" size="16" color="#666"></uni-icons>
				</view>
			</view>
			<view class="row-item fx-spt">
				<view class="fs-16 fw-500  color-0 ">车辆登记日期</view>
				<view class="input-content" @click="opendate(3)">
					<text class="fs-16 fw-500 mr-6 color-6 op-8">{{saveinfo.djname?saveinfo.djname:'请选择'}}</text>
					<uni-icons type="right" size="16" color="#666"></uni-icons>
				</view>
			</view>
			<view class="row-item fx-spt">
				<view class="fs-16 fw-500  color-0">过户次数</view>
				<view class="input-content">
					<uni-easyinput :inputborder="false" :clearable="false" v-model="saveinfo.numberoftransfers"
						placeholderstyle="text-align:right" placeholder="请输入" cursorspacing="60px" />
				</view>
			</view>
			<view class="row-item fx-spt">
				<view class="fs-16 fw-500  color-0 ">是否有二次事故</view>
				<view class="input-content" @click="openselect(5)">
					<text class="fs-16 fw-500 mr-6 color-6 op-8">{{saveinfo.esgname?saveinfo.esgname:'请选择'}}</text>
					<uni-icons type="right" size="16" color="#666"></uni-icons>
				</view>
			</view>


			<view class="row-item fx-spt">
				<view class="fs-16 fw-500  color-0 ">是否有登记证书</view>
				<view class="input-content" @click="openselect(6)">
					<text class="fs-16 fw-500 mr-6 color-6 op-8">{{saveinfo.djzname?saveinfo.djzname:'请选择'}}</text>
					<uni-icons type="right" size="16" color="#666"></uni-icons>
				</view>
			</view>
			<view class="row-item fx-spt">
				<view class="fs-16 fw-500  color-0 ">是否有行驶证</view>
				<view class="input-content" @click="openselect(7)">
					<text class="fs-16 fw-500 mr-6 color-6 op-8">{{saveinfo.xszname?saveinfo.xszname:'请选择'}}</text>
					<uni-icons type="right" size="16" color="#666"></uni-icons>
				</view>
			</view>
			<view class="row-item fx-spt">
				<view class="fs-16 fw-500  color-0">行驶公里数</view>
				<view class="input-content">
					<uni-easyinput :inputborder="false" :clearable="false" type="number"
						v-model="saveinfo.kilometerstraveled" placeholderstyle="text-align:right" placeholder="请输入"
						cursorspacing="60px" />
				</view>
			</view>
			<view class="row-item fx-spt">
				<view class="fs-16 fw-500  color-0">排量</view>
				<view class="input-content">
					<uni-easyinput :inputborder="false" :clearable="false" v-model="saveinfo.displacement"
						placeholderstyle="text-align:right" placeholder="请输入" cursorspacing="60px" />
				</view>
			</view>
			<view class="row-item fx-spt">
				<view class="fs-16 fw-500  color-0 ">变速方式</view>
				<view class="input-content" @click="openselect(8)">
					<text class="fs-16 fw-500 mr-6 color-6 op-8">{{saveinfo.bsname?saveinfo.bsname:'请选择'}}</text>
					<uni-icons type="right" size="16" color="#666"></uni-icons>
				</view>
			</view>


			<view class="row-item fx-spt">
				<view class="fs-16 fw-500  color-0 ">联系电话</view>
				<view class="input-content">
					<uni-easyinput :inputborder="false" :clearable="false" v-model="saveinfo.phone"
						placeholderstyle="text-align:right" placeholder="请输入" cursorspacing="60px" />
				</view>
			</view>
			<view class="row-item fx-spt">
				<view class="fs-16 fw-500  color-0 ">车辆停放地区</view>
				<view class="input-content" @click="openselectitems(1)">
					<text class="fs-16 fw-500 mr-6 color-6 op-8">{{saveinfo.vehiclelocation?saveinfo.vehiclelocation:'请选择'}}</text>
					<uni-icons type="right" size="16" color="#666"></uni-icons>
				</view>
			</view>
			<view class="row-item fx-spt">
				<view class="fs-16 fw-500  color-0 ">车辆停放详细地址</view>
				<view class="input-content">
					<uni-easyinput :inputborder="false" :clearable="false" v-model="saveinfo.detailaddress"
						placeholderstyle="text-align:right" placeholder="请输入" cursorspacing="60px" />
				</view>
			</view>
			<view class="row-item fx-spt">
				<view class="fs-16 fw-500  color-0 ">归属地区</view>
				<view class="input-content" @click="openselectitems(2)">
					<text class="fs-16 fw-500 mr-6 color-6 op-8">{{saveinfo.placeofbelonging?saveinfo.placeofbelonging:'请选择'}}</text>
					<uni-icons type="right" size="16" color="#666"></uni-icons>
				</view>
			</view>
		</view>
		<view class="save-btn">
			<view class="save" @click="save">保存</view>
		</view>
		<uni-calendar ref="calendar" :insert="false" @confirm="confirm" />
		<uni-popup ref="popup" type="bottom" background-color="#fff">
			<view class="pop-content">
				<view class="list" v-if="current==1">
					<view class="txt-cnter fs-16 fw-500 mb-12" v-for="(item,index) in rangemodels" :key="index"
						@click="closeselect(item,1)">{{item.text}}</view>

				</view>
				<view class="list" v-if="current==2">
					<view class="txt-cnter fs-16 fw-500 mb-12" v-for="(item,index) in rangebrands" :key="index"
						@click="closeselect(item,2)">{{item.text}}</view>

				</view>

				<view class="list" v-if="current==3">
					<view class="txt-cnter fs-16 fw-500 mb-12" v-for="(item,index) in rangeseries" :key="index"
						@click="closeselect(item,3)">{{item.text}}</view>

				</view>

				<view class="list" v-if="current==4">
					<view class="txt-cnter fs-16 fw-500 mb-12" v-for="(item,index) in rangewater" :key="index"
						@click="closeselect(item,4)">{{item.text}}</view>

				</view>

				<view class="list" v-if="current==5">
					<view class="txt-cnter fs-16 fw-500 mb-12" v-for="(item,index) in rangesg" :key="index"
						@click="closeselect(item,5)">{{item.text}}</view>
				</view>
				<view class="list" v-if="current==6">
					<view class="txt-cnter fs-16 fw-500 mb-12" v-for="(item,index) in rangesg" :key="index"
						@click="closeselect(item,6)">{{item.text}}</view>
				</view>
				<view class="list" v-if="current==7">
					<view class="txt-cnter fs-16 fw-500 mb-12" v-for="(item,index) in rangesg" :key="index"
						@click="closeselect(item,7)">{{item.text}}</view>
				</view>
				<view class="list" v-if="current==8">
					<view class="txt-cnter fs-16 fw-500 mb-12" v-for="(item,index) in rangebs" :key="index"
						@click="closeselect(item,8)">{{item.text}}</view>
				</view>
			</view>
		</uni-popup>

		<uni-popup ref="popup2" type="bottom" background-color="#fff">
			<view class="pop-content">
				<view class="goods-type-content">
					<view class="fs-16 fw-700 color-0 txt-cnter pd-18">地区</view>
					<view class="pop-list">
						<picker class="picker-view" mode="multiselector" :range="newprovincedatalist"
							:value="multiindex" @change="pickerchange" @columnchange="pickercolumnchange">
							<view style="text-align: center;">{{select}}</view>
						</picker>
					</view>
				</view>
			</view>
		</uni-popup>
	</view>
</template>
<script>
	import provincedata from '../../static/js/area-full.json';
	export default {
		data() {
			return {
				oldpprovincedatalist: provincedata,
				newprovincedatalist: [
					[],
					[],
					[]
				],
				multiindex: [0, 0, 0],
				select: '请选择省市区',
				addressdata: {
					name: '',
					phone: '',
					address: ''
				},
				binhao: '1',

				// ..........
				current: 0,
				// watername: null,
				// modelname: null,
				// brandname: null,
				// seriename: null,
				// djname: null,
				// jqxname: null,
				// nsname: null,
				// esgname: null,
				// bsname: null,
				// tfname: null,
				// xszname: null,
				// djzname: null,
				// gsname: null,
				addresstype: null,
				saveinfo: {
					watername: null,
					modelname: null,
					brandname: null,
					seriename: null,
					djname: null,
					jqxname: null,
					nsname: null,
					esgname: null,
					bsname: null,
					tfname: null,
					xszname: null,
					djzname: null,
					gsname: null,
					compulsorytrafficinsuranceexpirationdate: null,
					annualreviewexpirationdate: null,
					modelid: null,
					vehiclesbrandid: null,
					seriesid: null,
					waterlevel: null,
					secondaryaccident: null,
					numberoftransfers: null,
					phone: null,
					detailaddress: null,
					addressarea: null,
					placeofbelonging: '请选择',
					vehiclelocation: '请选择',
				},
				rangebrands: [],
				rangemodels: [],
				rangeseries: [],
				rangesg: [{
						text: '是',
						value: 1
					},
					{
						text: '否',
						value: 2
					},
				],
				rangebs: [{
						text: '手动',
						value: '手动'
					},
					{
						text: '自动',
						value: '自动'
					},
				],
				rangewater: [{
						text: '一级',
						value: 0
					},
					{
						text: '二级',
						value: 1
					},
					{
						text: '三级',
						value: 2
					},
				],

			}
		},
		onload() {
			let savedinfo = uni.getstoragesync('vehicleinfo');
			console.log('savedinfo', savedinfo)
			if (savedinfo) {
				this.saveinfo = savedinfo
			}
			// console.log('area', provincedata)
			// console.log(this.oldpprovincedatalist);
			for (let i = 0; i < this.oldpprovincedatalist.length; i++) {
				// console.log(this.oldpprovincedatalist[i].name);
				this.newprovincedatalist[0].push(this.oldpprovincedatalist[i].name);
			}
			for (let i = 0; i < this.oldpprovincedatalist[0].districts.length; i++) {
				// console.log(this.oldpprovincedatalist[0].city[i].name)
				this.newprovincedatalist[1].push(this.oldpprovincedatalist[0].districts[i].name);
			}
			for (let i = 0; i < this.oldpprovincedatalist[0].districts[0].districts.length; i++) {
				// console.log(this.oldpprovincedatalist[0].city[0].area)
				this.newprovincedatalist[2].push(this.oldpprovincedatalist[0].districts[0].districts[i].name);
			}
			// console.log(this.newprovincedatalist)

			//''''''''''''
			this.getbrands();
			this.getmodels();

		},
		onshow() {

		},
		methods: {
			// 省市区确认事件
			pickerchange(e) {
				this.multiindex = e.detail.value;
				this.select =
					`${this.newprovincedatalist[0][this.multiindex[0]]},${this.newprovincedatalist[1][this.multiindex[1]]},${this.newprovincedatalist[2][this.multiindex[2]]}`
				// console.log('666',this.newprovincedatalist[2][this.multiindex[2]])
				if (this.addresstype == 1) {
					this.saveinfo.vehiclelocation = this.select
					
				} else if (this.addresstype == 2) {
					this.saveinfo.placeofbelonging = this.select
					
				}
				// this.$forceupdate()
			},
			pickercolumnchange(e) {
				// 第几列滑动
				// console.log(e.detail.column);
				// 第几列滑动的下标
				// console.log(e.detail.value)
				// 第一列滑动
				if (e.detail.column === 0) {
					this.multiindex[0] = e.detail.value
					// console.log('第一列滑动');
					// this.newprovincedatalist[1] = [];
					this.newprovincedatalist[1] = this.oldpprovincedatalist[this.multiindex[0]].districts.map((item,
						index) => {
						// console.log('1',item)
						return item.name
					})
					// console.log(this.multiindex)
					if (this.oldpprovincedatalist[this.multiindex[0]].districts.length === 1) {
						this.newprovincedatalist[2] = this.oldpprovincedatalist[this.multiindex[0]].districts[0].districts
							.map((item, index) => {
								// console.log('2',item)
								return item.name
							})
					} else {
						// console.log('444',this.oldpprovincedatalist[this.multiindex[0]].districts[this.multiindex[1]].districts);
						this.newprovincedatalist[2] = this.oldpprovincedatalist[this.multiindex[0]].districts[this
							.multiindex[1]].districts.map((item, index) => {
							// console.log('3',item)
							return item.name
						})
					}

					// 第一列滑动  第二列 和第三列 都变为第一个
					this.multiindex.splice(1, 1, 0)
					this.multiindex.splice(2, 1, 0)
				}
				// 第二列滑动
				if (e.detail.column === 1) {
					this.multiindex[1] = e.detail.value
					// console.log('第二列滑动');
					// console.log(this.multiindex)
					this.newprovincedatalist[2] = this.oldpprovincedatalist[this.multiindex[0]].districts[this.multiindex[
						1]].districts.map((item, index) => {
						// console.log(item)
						return item.name
					})
					// 第二列 滑动 第三列 变成第一个
					this.multiindex.splice(2, 1, 0)
				}
				// 第三列滑动
				if (e.detail.column === 2) {
					this.multiindex[2] = e.detail.value
					// console.log('第三列滑动')
					// console.log(this.multiindex)
				}

			},

			//''''''''''
			openselectitems(type) {
				this.addresstype = type
				if (type == 1) {
					this.select = this.saveinfo.vehiclelocation
				} else if (type == 2) {
					this.select = this.saveinfo.placeofbelonging
				}
				this.$refs.popup2.open()
			},
			openselect(i) {
				this.current = i
				this.$refs.popup.open()
			},
			//获取品牌
			async getbrands() {
				const url = '/vehiclesmanagement/brand'
				const res = await this.$api.postkeyvalue(url, {})
				if (res.code == 200) {
					this.rangebrands = res.data.map(item => ({
						text: item.name,
						value: item.vehiclesbrandid,
					}));

				}
			},
			//获取车型
			async getmodels() {
				const url = '/vehiclesmanagement/model'
				const res = await this.$api.postkeyvalue(url, {})
				if (res.code == 200) {
					this.rangemodels = res.data.map(item => ({
						text: item.name,
						value: item.modelid,
					}));

				}
			},
			opendate(e) {
				console.log(e)
				this.currenttype = e
				this.$refs.calendar.open();
			},
			confirm(e) {
				console.log(e);
				switch (this.currenttype) {
					case 1:
						this.saveinfo.compulsorytrafficinsuranceexpirationdate = e.fulldate;
						this.saveinfo.jqxname = e.fulldate;
						break;
					case 2:
						this.saveinfo.annualreviewexpirationdate = e.fulldate;
						this.saveinfo.nsname = e.fulldate;
						break;
					case 3:
						this.saveinfo.vehicleregistrationdate = e.fulldate;
						this.saveinfo.djname = e.fulldate;
						break;
					default:
						break;
				}
			},
			closeselect(item, i) {
				//current
				console.log(item)
				switch (i) {
					case 1:
						this.saveinfo.modelid = item.value;
						this.saveinfo.modelname = item.text;
						break;
					case 2:
						this.saveinfo.vehiclesbrandid = item.value;
						this.saveinfo.brandname = item.text;
						//查询对应系列
						this.getseriesbyid(item.value);
						break;
					case 3:
						this.saveinfo.seriesid = item.value
						this.saveinfo.seriename = item.text;

						break;
					case 4:
						this.saveinfo.waterlevel = item.value;
						this.saveinfo.watername = item.text;
						break;
					case 5:
						this.saveinfo.secondaryaccident = item.value;
						this.saveinfo.esgname = item.text;
						break;
					case 6:
						this.saveinfo.certificate = item.value;
						this.saveinfo.djzname = item.text;
						break;
					case 7:
						this.saveinfo.drivinglicense = item.value;
						this.saveinfo.xszname = item.text;
						break;
					case 8:
						this.saveinfo.gearstype = item.value;
						this.saveinfo.bsname = item.text;
						break;
					default:
						break;

				}
				this.$forceupdate()
				this.$refs.popup.close()
			},
			async getseriesbyid(id) {
				const url = '/vehiclesmanagement/series'
				const res = await await this.$api.postkeyvalue(url, {
					id: id
				})
				if (res.code == 200) {
					this.rangeseries = res.data.map(item => ({
						text: item.name,
						value: item.seriesid,
					}));;

				}
			},
			save() {
				//字段非空
				if (!this.judgeinfonull()) {
					return;
				}
				//请求接口
				uni.navigateto({
					url: "/pages/publishcar/index"
				})
			},
			judgeinfonull() {
				if (!this.saveinfo.vehiclelocation) {
					uni.showtoast({
						title: '请选择车辆停放区域',
						icon: 'none',
						duration: 2000
					});
					return false;
				}
				if (!this.saveinfo.placeofbelonging) {
					uni.showtoast({
						title: '请选择车辆归属地',
						icon: 'none',
						duration: 2000
					});
					return false;
				}
				if (!this.saveinfo.annualreviewexpirationdate) {
					uni.showtoast({
						title: '请选择年审截至日期',
						icon: 'none',
						duration: 2000
					});
					return false;
				}
				if (!this.saveinfo.compulsorytrafficinsuranceexpirationdate) {
					uni.showtoast({
						title: '请选择交强险截至日期',
						icon: 'none',
						duration: 2000
					});
					return false;
				}
				if (!this.saveinfo.detailaddress) {
					uni.showtoast({
						title: '请输入车辆停放详细地址',
						icon: 'none',
						duration: 2000
					});
					return false;
				}
				if (!this.saveinfo.modelid) {
					uni.showtoast({
						title: '请选择车辆类型',
						icon: 'none',
						duration: 2000
					});
					return false;
				}
				if (!this.saveinfo.numberoftransfers) {
					uni.showtoast({
						title: '请输入过户次数',
						icon: 'none',
						duration: 2000
					});
					return false;
				}
				if (!this.saveinfo.phone) {
					uni.showtoast({
						title: '请输入联系电话',
						icon: 'none',
						duration: 2000
					});
					return false;
				}
				if (this.saveinfo.secondaryaccident == null) {
					uni.showtoast({
						title: '请选择是否有二次事故',
						icon: 'none',
						duration: 2000
					});
					return false;
				}
				if (!this.saveinfo.seriesid) {
					uni.showtoast({
						title: '请选择车系',
						icon: 'none',
						duration: 2000
					});
					return false;
				}
				if (!this.saveinfo.vehiclesbrandid) {
					uni.showtoast({
						title: '请选择品牌',
						icon: 'none',
						duration: 2000
					});
					return false;
				}
				if (!this.saveinfo.waterlevel) {
					uni.showtoast({
						title: '请选择水淹等级',
						icon: 'none',
						duration: 2000
					});
					return false;
				}

				if (!this.saveinfo.vehicleregistrationdate) {
					uni.showtoast({
						title: '请选择登记日期',
						icon: 'none',
						duration: 2000
					});
					return false;
				}
				if (this.saveinfo.drivinglicense == null) {
					uni.showtoast({
						title: '请选择是否有行驶证',
						icon: 'none',
						duration: 2000
					});
					return false;
				}
				if (this.saveinfo.certificate == null) {
					uni.showtoast({
						title: '请选择是否有登记证书',
						icon: 'none',
						duration: 2000
					});
					return false;
				}
				if (!this.saveinfo.kilometerstraveled) {
					uni.showtoast({
						title: '请输入行驶公里数',
						icon: 'none',
						duration: 2000
					});
					return false;
				}
				if (!this.saveinfo.displacement) {
					uni.showtoast({
						title: '请输入排量',
						icon: 'none',
						duration: 2000
					});
					return false;
				}
				if (!this.saveinfo.gearstype) {
					uni.showtoast({
						title: '请选择变速方式',
						icon: 'none',
						duration: 2000
					});
					return false;
				}
				//先存在本地
				uni.setstoragesync('vehicleinfo', this.saveinfo);
				console.log('vehicleinfo', uni.getstoragesync('saveinfokey'))
				return true;

			}
		}
	}
</script>
<style scoped>
	.pop-btns {
		padding: 24rpx 60rpx;
	}

	.btn {
		height: 64rpx;
		width: 300rpx;
		line-height: 64rpx;
		text-align: center;
		border-radius: 16rpx;
		font-size: 14px;
		font-weight: 500;
		background: #f4701f;
		color: #fff;
	}

	.picker-view {
		width: 100%;
		height: 480rpx;
		margin-top: 20rpx;
	}

	.pk-item {
		line-height: 100rpx;
		text-align: center;
	}

	.cancel {
		background: #fff;
		border: 1px solid #eee;
		color: #000;
	}


	.veh-info-container {
		width: 100%;
		height: 100%;
		background: #fff;
		display: flex;
		flex-direction: column;
	}

	.page-content {
		flex: 1;
		box-sizing: border-box;
		padding: 24rpx 32rpx;
		overflow-y: auto;
	}

	.row-item {
		padding: 18rpx 0;
	}

	.input-content {
		flex: 1;
		max-width: 55%;
		text-align: right;
	}

	.input-content>>>.uni-easyinput__content-input {
		text-align: right;
	}

	.save-btn {
		flex-shrink: 0;
		padding: 24rpx 0 48rpx;
		background: #fff;
		border-top: 1px solid #eee;
	}

	.save {
		width: 400rpx;
		height: 64rpx;
		text-align: center;
		line-height: 64rpx;
		border-radius: 16rpx;
		background-color: #f4701f;
		margin: 0 auto;
		color: #fff;
		font-size: 14px;
		font-weight: 500;
	}

	.pop-content {
		padding: 36rpx 0 36rpx;
		background: #fff;
		max-height: 30vh;
		overflow-y: scroll;
	}
</style>

四,效果展示

五.总结

到此这篇关于uniapp实现省市区三级级联选择功能的文章就介绍到这了,更多相关uniapp省市区三级级联选择内容请搜索代码网以前的文章或继续浏览下面的相关文章希望大家以后多多支持代码网!

(0)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2025  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com