新增地区选择组件

This commit is contained in:
weipengfei 2023-07-28 16:02:37 +08:00
parent 1833482d80
commit 631fbdd246
4 changed files with 289 additions and 231 deletions

View File

@ -0,0 +1,241 @@
<template>
<view>
<u--form labelPosition="left" :model="formData" :rules="rules" ref="uForm">
<u-form-item label="省" required prop="province" @click="changeCity('province')" borderBottom>
<u--input :value="formDataText.province" disabled disabledColor="#fff" placeholder="请选择省"></u--input>
<u-icon slot="right" name="arrow-right"></u-icon>
</u-form-item>
<u-form-item label="市" required prop="city" @click="changeCity('city')" borderBottom>
<u--input :value="formDataText.city" disabled disabledColor="#fff" placeholder="请选择市"></u--input>
<u-icon slot="right" name="arrow-right"></u-icon>
</u-form-item>
<u-form-item label="区县" required prop="area" @click="changeCity('area')" borderBottom>
<u--input :value="formDataText.area" disabled disabledColor="#fff" placeholder="请选择区县"></u--input>
<u-icon slot="right" name="arrow-right"></u-icon>
</u-form-item>
<u-form-item label="乡镇" required prop="street" @click="changeCity('street')" borderBottom>
<u--input :value="formDataText.street" disabled disabledColor="#fff" placeholder="请选择镇"></u--input>
<u-icon slot="right" name="arrow-right"></u-icon>
</u-form-item>
<u-form-item label="村社" required prop="village" @click="changeCity('village')" borderBottom>
<u--input :value="formDataText.village" disabled disabledColor="#fff" placeholder="请选择村"></u--input>
<u-icon slot="right" name="arrow-right"></u-icon>
</u-form-item>
<u-form-item label="小队" required prop="brigade" @click="changeCity('brigade')" borderBottom>
<u--input :value="formDataText.brigade" disabled disabledColor="#fff" placeholder="请选择小队"></u--input>
<u-icon slot="right" name="arrow-right"></u-icon>
</u-form-item>
</u--form>
<u-picker :show="showProvince" :columns="[changeList()]" :keyName="changeType+'_name'" @confirm="confirm"
@cancel="showProvince = false" @close="showProvince = false"></u-picker>
</view>
</template>
<script>
import { commonProvince, commonCity, commonArea, commonStreet, commonVillage, commonBrigade } from "@/api/oaPbulic.js"
import { Toast } from "../../libs/uniApi"
export default {
name:"districtSelector",
data() {
return {
showProvince: false,
formData: {
province: '',
city: '',
area: '',
street: '',
village: '',
brigade: '',
},
formDataText: {
province: '',
city: '',
area: '',
street: '',
village: '',
brigade: '',
},
rules:{
province: {
required: true,
message: '不能为空',
trigger: ['change', 'blur']
},
city: {
required: true,
message: '不能为空',
trigger: ['change', 'blur']
},
area: {
required: true,
message: '不能为空',
trigger: ['change', 'blur']
},
street: {
required: true,
message: '不能为空',
trigger: ['change', 'blur']
},
village: {
required: true,
message: '不能为空',
trigger: ['change', 'blur']
},
brigade: {
type: 'any',
required: true,
message: '不能为空',
trigger: ['change', 'blur']
},
},
provinceList: [],
cityList: [],
areaList: [],
streetList: [],
villageList: [],
brigadeList: [],
changeType: '', //
};
},
mounted() {
this.initProvinceAndCity();
},
methods:{
validate(){
return new Promise((resolve, reject)=>{
this.$refs.uForm.validate().then(res=>{
if(res)resolve(true);
else reject(false);
})
})
},
//
async initProvinceAndCity() {
let res = await commonProvince();
this.provinceList = res.data;
this.provinceList.forEach(item => {
if (item.province_name.indexOf('四川') !== -1) {
this.formData.province = item.province_code;
this.formDataText.province = item.province_name;
commonCity({
city: item.province_code
}).then(cityRes => {
this.cityList = cityRes.data;
this.cityList.forEach(item => {
if (item.city_name.indexOf('泸州') !== -1) {
this.formData.city = item.city_code;
this.formDataText.city = item.city_name;
commonArea({
area: item.city_code
}).then(areaRes => {
this.areaList = areaRes.data;
})
}
})
})
}
})
},
//
changeCity(type) {
if (this[type + 'List'].length == 0) return Toast('请先选择上一级地区');
this.changeType = type;
this.showProvince = true;
},
//
changeList() {
return this[this.changeType + 'List'];
},
//
confirm(e) {
let flag = false;//
if(this.formData[this.changeType] != e.value[0][this.changeType + '_code'])flag = true;
if (this.changeType == 'brigade') {
this.formData.brigade = e.value[0].id;
this.formDataText.brigade = e.value[0].brigade_name;
this.showProvince = false;
return ;
}
this.formData[this.changeType] = e.value[0][this.changeType + '_code'];
this.formDataText[this.changeType] = e.value[0][this.changeType + '_name'];
//
switch (this.changeType) {
case 'province':
this.loadCity(this.formData['province']);
break;
case 'city':
this.loadArea(this.formData['city']);
break;
case 'area':
this.loadStreet(this.formData['area']);
break;
case 'street':
this.loadVillage(this.formData['street']);
break;
case 'village':
this.loadBrigade(this.formData['village']);
break;
}
//
if(flag) switch (this.changeType) {
case 'province':
this.formData.city = '';
this.formDataText.city = ''
case 'city':
this.formData.area = '';
this.formDataText.area = ''
case 'area':
this.formData.street = '';
this.formDataText.street = ''
case 'street':
this.formData.village = '';
this.formDataText.village = ''
case 'village':
this.formData.brigade = '';
this.formDataText.brigade = ''
}
this.showProvince = false;
},
loadCity(code) {
commonCity({
city: code
}).then(res => {
this.cityList = res.data;
})
},
loadArea(code) {
commonArea({
area: code
}).then(res => {
this.areaList = res.data;
})
},
loadStreet(code) {
commonStreet({
street: code
}).then(res => {
this.streetList = res.data;
})
},
loadVillage(code) {
commonVillage({
village: code
}).then(res => {
this.villageList = res.data;
})
},
loadBrigade(code) {
commonBrigade({
brigade: code
}).then(res => {
this.brigadeList = res.data;
})
},
}
}
</script>
<style>
</style>

View File

@ -301,6 +301,24 @@
"navigationBarTextStyle": "white" "navigationBarTextStyle": "white"
} }
}, {
"path": "archives/archives",
"style": {
"navigationBarTitleText": "档案管理",
"enablePullDownRefresh": false,
"navigationBarBackgroundColor": "#3175f9",
"navigationBarTextStyle": "white"
}
}, {
"path": "newArchives/newArchives",
"style": {
"navigationBarTitleText": "新增档案",
"enablePullDownRefresh": false,
"navigationBarBackgroundColor": "#3175f9",
"navigationBarTextStyle": "white"
}
}] }]
}], }],
"globalStyle": { "globalStyle": {

View File

@ -217,21 +217,21 @@ export const oaHomeData = [
url: '/subpkg/companyAdmin/companyAdmin' url: '/subpkg/companyAdmin/companyAdmin'
}, },
{ {
text: '片区经理', text: '档案管理',
icon: prefix + 'oa/yzsq@2x.png', icon: prefix + 'oa/bxsq@2x.png',
url: '/pages/oaManager/oaManager' url: '/subpkg/archives/archives'
}, },
// {
// text: '片区经理',
// icon: prefix + 'oa/yzsq@2x.png',
// url: '/pages/oaManager/oaManager'
// },
{ {
text: '财务管理', text: '财务管理',
icon: prefix + 'oa/gengduo@2x.png', icon: prefix + 'oa/gengduo@2x.png',
url: '/subpkg/finance/finance' url: '/subpkg/finance/finance'
}, },
// { // {
// text: 'gong',
// icon: prefix + 'oa/qjsq@2x.png',
// url: '/pages/views/leave_request'
// },
// {
// text: '出差申请', // text: '出差申请',
// icon: prefix + 'oa/ccsq@2x.png' // icon: prefix + 'oa/ccsq@2x.png'
// }, // },

View File

@ -33,30 +33,7 @@
<u--input v-model="formData.password_confirm" placeholder="不输入密码则默认为手机号" password></u--input> <u--input v-model="formData.password_confirm" placeholder="不输入密码则默认为手机号" password></u--input>
</u-form-item> --> </u-form-item> -->
<view class="title">地区信息</view> <view class="title">地区信息</view>
<u-form-item label="省" required prop="province" @click="changeCity('province')" borderBottom> <districtSelector ref="districtSelectorRef"></districtSelector>
<u--input :value="formDataText.province" disabled disabledColor="#fff" placeholder="请选择省"></u--input>
<u-icon slot="right" name="arrow-right"></u-icon>
</u-form-item>
<u-form-item label="市" required prop="city" @click="changeCity('city')" borderBottom>
<u--input :value="formDataText.city" disabled disabledColor="#fff" placeholder="请选择市"></u--input>
<u-icon slot="right" name="arrow-right"></u-icon>
</u-form-item>
<u-form-item label="区县" required prop="area" @click="changeCity('area')" borderBottom>
<u--input :value="formDataText.area" disabled disabledColor="#fff" placeholder="请选择区县"></u--input>
<u-icon slot="right" name="arrow-right"></u-icon>
</u-form-item>
<u-form-item label="乡镇" required prop="street" @click="changeCity('street')" borderBottom>
<u--input :value="formDataText.street" disabled disabledColor="#fff" placeholder="请选择镇"></u--input>
<u-icon slot="right" name="arrow-right"></u-icon>
</u-form-item>
<u-form-item label="村社" required prop="village" @click="changeCity('village')" borderBottom>
<u--input :value="formDataText.village" disabled disabledColor="#fff" placeholder="请选择村"></u--input>
<u-icon slot="right" name="arrow-right"></u-icon>
</u-form-item>
<u-form-item label="小队" required prop="brigade" @click="changeCity('brigade')" borderBottom>
<u--input :value="formDataText.brigade" disabled disabledColor="#fff" placeholder="请选择小队"></u--input>
<u-icon slot="right" name="arrow-right"></u-icon>
</u-form-item>
<view class="title">资质信息</view> <view class="title">资质信息</view>
<u-form-item label="身份证正面" required labelPosition="top" labelWidth="200rpx" prop="qualification.id_card" <u-form-item label="身份证正面" required labelPosition="top" labelWidth="200rpx" prop="qualification.id_card"
borderBottom> borderBottom>
@ -101,8 +78,6 @@
</u-upload> </u-upload>
</u-form-item> </u-form-item>
</u--form> </u--form>
<u-picker :show="showProvince" :columns="[changeList()]" :keyName="changeType+'_name'" @confirm="confirm"
@cancel="showProvince = false" @close="showProvince = false"></u-picker>
<button @click="addAcountNum" type="primary" class="btn">创建</button> <button @click="addAcountNum" type="primary" class="btn">创建</button>
</view> </view>
</view> </view>
@ -110,13 +85,12 @@
<script> <script>
import { upLoadImage } from "@/api/file.js" import { upLoadImage } from "@/api/file.js"
import { commonProvince, commonCity, commonArea, commonStreet, commonVillage, commonBrigade } from "@/api/oaPbulic.js"
import { loginAdd } from "@/api/oaUser.js" import { loginAdd } from "@/api/oaUser.js"
import { Toast } from "../../libs/uniApi" import districtSelector from "@/components/districtSelector/districtSelector.vue" //
export default { export default {
components: { districtSelector },
data() { data() {
return { return {
showProvince: false,
formData: { formData: {
account: '', // account: '', //
password: '123456', // password: '123456', //
@ -126,12 +100,6 @@
sex: '', sex: '',
avatar: '', avatar: '',
nickname: '', nickname: '',
province: '',
city: '',
area: '',
street: '',
village: '',
brigade: '',
address: '测试地址', address: '测试地址',
qualification: { qualification: {
id_card: "", id_card: "",
@ -142,14 +110,6 @@
bank_account_b: "" bank_account_b: ""
}, },
}, },
formDataText: {
province: '',
city: '',
area: '',
street: '',
village: '',
brigade: '',
},
rules: { rules: {
account: { account: {
required: true, required: true,
@ -182,37 +142,6 @@
message: '姓名不能为空', message: '姓名不能为空',
trigger: ['change', 'blur'] trigger: ['change', 'blur']
}, },
province: {
required: true,
message: '不能为空',
trigger: ['change', 'blur']
},
city: {
required: true,
message: '不能为空',
trigger: ['change', 'blur']
},
area: {
required: true,
message: '不能为空',
trigger: ['change', 'blur']
},
street: {
required: true,
message: '不能为空',
trigger: ['change', 'blur']
},
village: {
required: true,
message: '不能为空',
trigger: ['change', 'blur']
},
brigade: {
type: 'any',
required: true,
message: '不能为空',
trigger: ['change', 'blur']
},
'qualification.id_card': { 'qualification.id_card': {
type: 'string', type: 'string',
required: true, required: true,
@ -250,146 +179,15 @@
trigger: ['change', 'blur'] trigger: ['change', 'blur']
}, },
}, },
provinceList: [],
cityList: [],
areaList: [],
streetList: [],
villageList: [],
brigadeList: [],
changeType: '', //
} }
}, },
onLoad() { onLoad() {},
this.initProvinceAndCity()
},
onReady() { onReady() {
//setRules //setRules
this.$refs.uForm.setRules(this.rules) this.$refs.uForm.setRules(this.rules)
}, },
onShow() {}, onShow() {},
methods: { methods: {
async initProvinceAndCity() {
let res = await commonProvince();
this.provinceList = res.data;
this.provinceList.forEach(item => {
if (item.province_name.indexOf('四川') !== -1) {
this.formData.province = item.province_code;
this.formDataText.province = item.province_name;
commonCity({
city: item.province_code
}).then(cityRes => {
this.cityList = cityRes.data;
this.cityList.forEach(item => {
if (item.city_name.indexOf('泸州') !== -1) {
this.formData.city = item.city_code;
this.formDataText.city = item.city_name;
commonArea({
area: item.city_code
}).then(areaRes => {
this.areaList = areaRes.data;
})
}
})
})
}
})
},
//
changeCity(type) {
if (this[type + 'List'].length == 0) return Toast('请先选择上一级地区');
this.changeType = type;
this.showProvince = true;
},
//
changeList() {
return this[this.changeType + 'List'];
},
//
confirm(e) {
let flag = false;//
if(this.formData[this.changeType] != e.value[0][this.changeType + '_code'])flag = true;
if (this.changeType == 'brigade') {
this.formData.brigade = e.value[0].id;
this.formDataText.brigade = e.value[0].brigade_name;
this.showProvince = false;
return ;
}
this.formData[this.changeType] = e.value[0][this.changeType + '_code'];
this.formDataText[this.changeType] = e.value[0][this.changeType + '_name'];
//
switch (this.changeType) {
case 'province':
this.loadCity(this.formData['province']);
break;
case 'city':
this.loadArea(this.formData['city']);
break;
case 'area':
this.loadStreet(this.formData['area']);
break;
case 'street':
this.loadVillage(this.formData['street']);
break;
case 'village':
this.loadBrigade(this.formData['village']);
break;
}
//
if(flag) switch (this.changeType) {
case 'province':
this.formData.city = '';
this.formDataText.city = ''
case 'city':
this.formData.area = '';
this.formDataText.area = ''
case 'area':
this.formData.street = '';
this.formDataText.street = ''
case 'street':
this.formData.village = '';
this.formDataText.village = ''
case 'village':
this.formData.brigade = '';
this.formDataText.brigade = ''
}
this.showProvince = false;
},
loadCity(code) {
commonCity({
city: code
}).then(res => {
this.cityList = res.data;
})
},
loadArea(code) {
commonArea({
area: code
}).then(res => {
this.areaList = res.data;
})
},
loadStreet(code) {
commonStreet({
street: code
}).then(res => {
this.streetList = res.data;
})
},
loadVillage(code) {
commonVillage({
village: code
}).then(res => {
this.villageList = res.data;
})
},
loadBrigade(code) {
commonBrigade({
brigade: code
}).then(res => {
this.brigadeList = res.data;
})
},
// //
async afterReadAvatar(event) { async afterReadAvatar(event) {
upLoadImage({ upLoadImage({
@ -414,23 +212,24 @@
}, },
// //
addAcountNum() { addAcountNum() {
this.$refs.uForm.validate().then(async (e) => { this.$refs.uForm.validate().then((e) => {
if(e){ if (e) this.$refs.districtSelectorRef.validate().then(async (e) => {
uni.showLoading() if (e) {
let res = await loginAdd(this.formData); uni.showLoading()
uni.hideLoading() let res = await loginAdd({...this.formData, ...this.$refs.districtSelectorRef.formData});
uni.showToast({ uni.hideLoading()
icon:"none", uni.showToast({
title:"添加成功", icon: "none",
success: () => { title: "添加成功",
setTimeout(()=>{ success: () => {
uni.navigateBack() setTimeout(() => {
},1000) uni.navigateBack()
} }, 1000)
}) }
} })
}
})
}) })
}, },
// // ,[1- 2- 3-H5 4-PC 5-APP 6-APP] // // ,[1- 2- 3-H5 4-PC 5-APP 6-APP]
// initTerminal() { // initTerminal() {
@ -490,7 +289,7 @@
} }
} }
.btn{ .btn {
margin-top: 32rpx; margin-top: 32rpx;
// margin-bottom: 40rpx; // margin-bottom: 40rpx;
width: 100%; width: 100%;