diff --git a/pages/charge/visitsAndFees/createaVisit.vue b/pages/charge/visitsAndFees/createaVisit.vue
index ae64d1b..e4fc3c7 100644
--- a/pages/charge/visitsAndFees/createaVisit.vue
+++ b/pages/charge/visitsAndFees/createaVisit.vue
@@ -199,12 +199,12 @@
+ @confirm="confirm" @keywordChange="keywordChange">
+ @cancel="gsShow = false" @close="gsShow = false" keyName="label" @confirm="gsConfirm" placeholder="输入公司名称查询"
+ @change="changeHandler" @keywordChange="gsKeyWordChange" @clear="gsKeyWordClear">
{
- // return uni.$u.test.digits(value)
- // },
- // message: '用户编号不正确',
- // trigger: ['change', 'blur'],
- // }
+ required: false,
+ message: '请填写用户编号',
+ trigger: ['blur', 'change']
+ },
+ {
+ validator: (rule, value, callback) => {
+ if (!value) {
+ return true
+ }
+ return uni.$u.test.enOrNum(value)
+ },
+ message: '用户编号不正确',
+ trigger: ['change', 'blur'],
+ }
],
userIdCard: [{
required: true,
@@ -462,11 +465,16 @@
datetimeShow: false,
dataTimeValue: Number(new Date()),
columns: [],
+ copyColumns: [],
gsColumns: [],
regionName: [],
groupName: [],
companyName: [],
companyCode: [],
+ // 还原类
+ regionNames: [],
+ groupNames: [],
+ companyNames: [],
currentName: "", //弹窗后赋值name
companyOption: [],
fileList: [],
@@ -480,6 +488,10 @@
regionLoading: false,
pickerValue: [0, 0, 0, 0],
defaultValue: [11, 1101, 110101, 110101001],
+ defaultRegion: "",
+ defaultGroup: "",
+ openKeyword: false, //是否输入公司名称查询
+ gsChangeIndexs: [],
// 基本信息
basisData: [{
label: '财年',
@@ -696,7 +708,7 @@
type: "input",
key: "userCode",
show: true,
- mode: "number",
+ mode: "text",
max: '10'
}, {
label: '身份证号',
@@ -953,16 +965,34 @@
},
async getCompanyCascader() {
this.companyOption = (await getCompanyCascader()).data;
- this.companyOption.forEach(item1 => {
+ this.companyOption.forEach((item1, index1) => {
this.regionName.push(item1);
- item1.children.forEach(item2 => {
+ item1.children.forEach((item2, index2) => {
this.groupName.push(item2);
- item2.children.forEach(item3 => {
+ item2.children.forEach((item3, index3) => {
this.companyName.push(item3);
});
});
});
+
+ this.regionName.map((item1, index1) => {
+ item1.index = index1;
+ item1.children.map((item2, index2) => {
+ item2.index = index2;
+ item2.children.map((item3, index3) => {
+ item3.index = index3;
+ })
+ })
+ })
+ this.regionNames = this.regionName;
+ this.groupNames = this.groupName;
+ this.companyNames = this.companyName;
+ this.defaultRegion = this.regionName[0].label;
+ this.defaultGroup = this.groupName[0].label;
console.log("当前公司类", this.companyOption);
+ console.log("区域", this.regionNames);
+ console.log("集团", this.groupNames);
+ console.log("公司", this.companyNames);
},
// 选择弹出层
async handleSelect(item) {
@@ -973,10 +1003,14 @@
this.currentName = item.key;
// 项目公司单独弹窗
if (item.key === 'company') {
- this.gsColumns = [this.regionName, this.groupName, this.companyName];
- if (this.regionName.length) {
+ // this.gsColumns = [this.regionName, this.groupName, this.companyName];
+ if (this.regionName.length || this.regionName) {
this.gsName = `${this.regionName[0].label}`;
this.gsShow = true;
+ let defaultIndex = this.defaultIndex[this.currentName];
+ console.log("选择公司默认值", defaultIndex)
+ this.$refs.gsPicker.setIndexs(defaultIndex ? defaultIndex : [0, 0, 0], true)
+ this.$refs.gsPicker.handleClear();
} else {
uni.$u.toast('未查询到项目公司');
}
@@ -999,7 +1033,7 @@
uni.$u.toast('未查询相关小区');
return
}
- let col = result.data.map(item => ({
+ let col = result.data.map((item, index) => ({
value: item.vlgOrCmty,
label: `${item.vlgOrCmty}(${item.urbRurCls})`,
urbRurCls: item.urbRurCls,
@@ -1007,9 +1041,11 @@
city: item.city,
district: item.district,
street: item.street,
- address: `${item.province}${item.city}${item.district}${item.street}`
+ address: `${item.province}${item.city}${item.district}${item.street}`,
+ index: index
}));
this.columns = [col];
+ this.copyColumns = this.columns;
} else if (item.key === 'userName') {
if (!this.model.vlgOrCmty) {
uni.$u.toast('请先选择村(小区)');
@@ -1024,12 +1060,14 @@
uni.$u.toast('未查询相关用户');
return
}
- let col = result.rows.map(item => ({
+ let col = result.rows.map((item, index) => ({
value: item.userName,
label: item.userName,
- obj: item
+ obj: item,
+ index: index
}));
this.columns = [col];
+ this.copyColumns = this.columns;
// 省市区单独弹窗
} else if (item.key === 'address') {
this.provinces = cityData.sort((left, right) => (Number(left.code) > Number(right.code) ? 1 : -1));
@@ -1041,6 +1079,7 @@
let dict = item.dict;
let dictArr = this.getDictDatas(dict);
this.columns = [dictArr];
+ this.copyColumns = this.columns;
}
let defaultIndex = this.defaultIndex[this.currentName];
console.log("是否有默认值", defaultIndex)
@@ -1070,11 +1109,123 @@
this.model.userStreet = "";
this.model.userDetailedAddress = "";
},
+ // 关键词搜索
+ keywordChange(keyword) {
+ console.log("关键词", keyword)
+ console.log("columns", this.copyColumns)
+ let data = this.copyColumns[0]
+ let queryData = data.filter(item => item.value && item.value.includes(keyword));
+ console.log("筛选", queryData)
+ this.columns = [queryData];
+ },
+ // 关键词搜索
+ gsKeyWordChange(keyword) {
+ if (!keyword) {
+ this.regionName = this.regionNames;
+ this.groupName = this.groupNames;
+ this.companyName = this.companyNames;
+ this.defaultRegion = this.regionNames[0].label;
+ this.defaultGroup = this.groupNames[0].label;
+ this.openKeyword = false;
+ return;
+ }
+ this.gsChangeIndexs = [];
+ this.openKeyword = true;
+ console.log("公司关键词", keyword);
+ console.log("regionNames", this.regionNames)
+ const hierarchies = this.findCompanyHierarchy(keyword, this.regionNames);
+ console.log("返回结果", hierarchies);
+ if (hierarchies[2].length > 0) { // 如果找到了至少一个公司
+ this.regionName = hierarchies[0];
+ this.groupName = hierarchies[1];
+ this.companyName = hierarchies[2];
+ } else {
+ uni.$u.toast('未查询到该公司');
+ this.regionName = [{
+ value: this.defaultRegion,
+ label: this.defaultRegion
+ }];
+ this.groupName = [{
+ value: this.defaultGroup,
+ label: this.defaultGroup
+ }];
+ // this.companyName = this.companyNames;
+ }
+ },
+ // 关键词清空后
+ gsKeyWordClear() {
+ console.log("清除关键词触发")
+ this.defaultRegion = this.regionNames[0].label
+ this.defaultGroup = this.groupNames[0].label
+ },
+ // 查找公司对应关系
+ findCompanyHierarchy(keyword, nodes = data) {
+ const regionHierarchy = [];
+ const groupHierarchy = [];
+ const companyHierarchy = [];
+ // console.log(1, this.regionNames)
+ // console.log(2, this.groupNames)
+ // console.log(3, this.companyNames)
+ console.log("当前选择区域", this.defaultRegion);
+ console.log("当前选择集团", this.defaultGroup);
+ nodes.forEach(item1 => {
+ item1.children.forEach(item2 => {
+ item2.children.forEach(item3 => {
+ if (item1.label == this.defaultRegion && item2.label == this.defaultGroup) {
+ if (item3.label.includes(keyword)) {
+ if (!regionHierarchy.some(region => region.label === item1.label)) {
+ regionHierarchy.push(item1);
+ }
+ if (!groupHierarchy.some(group => group.label === item2.label)) {
+ groupHierarchy.push(item2);
+ }
+ companyHierarchy.push(item3);
+ }
+ }
+ });
+ });
+ });
+ return [regionHierarchy, groupHierarchy, companyHierarchy];
+ },
+ // 项目公司独立弹窗,防止共用报错
+ gsConfirm(e) {
+ console.log("公司", e);
+ // this.$refs.gsPicker.handleClear();
+ if (this.currentName === 'company') {
+ this.emptyFill(1);
+ this.model[this.currentName] = `${e.value[2].label}`;
+ this.model.regionName = e.value[0]?.value;
+ this.model.groupName = e.value[1]?.value;
+ this.model.companyName = e.value[2]?.label;
+ this.model.companyCode = e.value[2]?.value;
+ // if (this.openKeyword) {
+ // console.log("关键词查询后的原始index", this.gsChangeIndexs)
+ // this.defaultIndex[this.currentName] = this.gsChangeIndexs;
+ // } else {
+ this.defaultIndex[this.currentName] = e.indexs;
+ // }
+ this.regionName = this.regionNames;
+ this.groupName = this.groupNames;
+ this.companyName = this.companyNames;
+ // this.regionName = this.regionNames;
+ // this.groupName = [{
+ // value: e.value[1]?.value,
+ // label: e.value[1]?.value
+ // }];
+ // this.companyName = [{
+ // value: e.value[2]?.value,
+ // label: e.value[2]?.label
+ // }];
+ }
+ this.openKeyword = false;
+ this.gsShow = false;
+ },
handleSFSelect(item) {
this.currentName = item.key;
let dict = item.dict;
let dictArr = this.getDictDatas(dict);
this.columns = [dictArr];
+ this.copyColumns = this.columns;
let defaultIndex = this.defaultIndex[this.currentName];
console.log("是否有默认值", defaultIndex)
this.$refs.uPicker.setIndexs(defaultIndex ? [defaultIndex] : [0], true)
@@ -1120,7 +1271,12 @@
} else {
this.model[this.currentName] = e.value[0].value
}
- this.defaultIndex[this.currentName] = e.indexs[0];
+ if (this.currentName === 'vlgOrCmty' || this.currentName === 'userName') {
+ this.defaultIndex[this.currentName] = e.value[0].index;
+ this.$refs.uPicker.handleClear();
+ } else {
+ this.defaultIndex[this.currentName] = e.indexs[0];
+ }
console.log("默认值", this.defaultIndex)
this.pickerShow = false;
},
@@ -1134,21 +1290,25 @@
indexs
// 微信小程序无法将picker实例传出来,只能通过ref操作
} = e
- console.log(e);
+ console.log("公司切换", e);
// 当第一列值发生变化时,变化第二列(后一列)对应的选项
+ // this.gsChangeIndexs = [value[0].index,value[1].index,value[2].index];
let [regionIndex, groupIndex, companyIndex] = indexs;
if (columnIndex === 0) {
this.gsName = value[0].label;
- console.log(0, this.regionName)
+ // console.log(0, this.regionName)
// this.regionName = this.regionName[index]?.children || [];
this.groupName = this.regionName[index]?.children || [];
this.companyName = this.groupName[0]?.children || [];
- console.log(1, this.regionName)
- console.log(2, this.groupName)
- console.log(3, this.companyName)
+ this.defaultRegion = this.regionName[index].label;
+ this.defaultGroup = this.groupName[0].label;
+ // console.log(1, this.regionName)
+ // console.log(2, this.groupName)
+ // console.log(3, this.companyName)
this.$refs.gsPicker.setIndexs([index, 0, 0], true)
} else if (columnIndex === 1) {
this.gsName = value[1].label;
+ this.defaultGroup = this.regionName[index].label;
this.groupName = this.regionName[index]?.children || [];
this.companyName = this.groupName[0]?.children || [];
this.$refs.gsPicker.setIndexs(indexs, true)
@@ -1159,20 +1319,7 @@
// let data3 = data2[0].children;
// picker为选择器this实例,变化第二列对应的选项
// this.gsColumns = [this.regionName, data2, data3]
- console.log("选择后", this.gsColumns);
- },
- // 项目公司独立弹窗,防止共用报错
- gsConfirm(e) {
- console.log("公司", e);
- if (this.currentName === 'company') {
- this.emptyFill(1);
- this.model[this.currentName] = `${e.value[2].label}`;
- this.model.regionName = e.value[0]?.value;
- this.model.groupName = e.value[1]?.value;
- this.model.companyName = e.value[2]?.label;
- this.model.companyCode = e.value[2]?.value;
- }
- this.gsShow = false;
+ // console.log("选择后", this.gsColumns);
},
// 设置默认省市区街道
handlePickValueDefault() {
diff --git a/uni_modules/uview-ui/components/u-picker/props.js b/uni_modules/uview-ui/components/u-picker/props.js
index 7b5d091..5bd3346 100644
--- a/uni_modules/uview-ui/components/u-picker/props.js
+++ b/uni_modules/uview-ui/components/u-picker/props.js
@@ -10,6 +10,15 @@ export default {
type: Boolean,
default: uni.$u.props.picker.showToolbar
},
+ placeholder:{
+ type: String,
+ default: '输入关键词可自动查询'
+ },
+ // 是否展示顶部的搜索栏
+ showSearch: {
+ type: Boolean,
+ default: uni.$u.props.picker.showSearch
+ },
// 顶部标题
title: {
type: String,
diff --git a/uni_modules/uview-ui/components/u-picker/u-picker.vue b/uni_modules/uview-ui/components/u-picker/u-picker.vue
index 8885917..6151df2 100644
--- a/uni_modules/uview-ui/components/u-picker/u-picker.vue
+++ b/uni_modules/uview-ui/components/u-picker/u-picker.vue
@@ -14,6 +14,9 @@
@cancel="cancel"
@confirm="confirm"
>
+
item[this.innerIndex[index]])
- }
+ },
+ handleChange(e){
+ this.$emit("keywordChange",e)
+ },
+ handleCustom(e){
+ this.$emit("keywordChange",e)
+ },
+ handleClear(){
+ this.keyword = "";
+ this.$emit('clear')
+ }
},
}
--
libgit2 0.21.2