You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
229 lines
5.6 KiB
229 lines
5.6 KiB
import { wxRequestPost } from "@utils/promise-wx-api";
|
|
|
|
const app = getApp();
|
|
let tempReslove = () => {};
|
|
|
|
Component({
|
|
properties: {
|
|
minFloor: {
|
|
type: Number,
|
|
value: 5,
|
|
},
|
|
maxFloor: {
|
|
type: Number,
|
|
value: 5,
|
|
},
|
|
defaultIdArray: {
|
|
type: Array,
|
|
value: ['37', '3717', '371721'],
|
|
},
|
|
},
|
|
data: {
|
|
hidden: true,
|
|
showCancel: true,
|
|
confirmText: "确认",
|
|
|
|
areaCollection: [[], [], [], [], []],
|
|
currentIndexList: [-1, -1, -1, -1, -1],
|
|
|
|
currentFloor: 0,
|
|
|
|
showName: "",
|
|
pathCode: "",
|
|
|
|
selectedItemList: [
|
|
{
|
|
name: "请选择",
|
|
code: "",
|
|
level: "",
|
|
},
|
|
],
|
|
},
|
|
|
|
lifetimes: {
|
|
async attached() {
|
|
await app.doAfterLogin();
|
|
await this.getAreaList();
|
|
|
|
const {defaultIdArray} = this.data
|
|
|
|
|
|
// if(defaultIdArray.length>0){
|
|
// defaultIdArray.forEach(item => {
|
|
|
|
// const {currentFloor,areaCollection} = this.data
|
|
// debugger
|
|
// let index=null
|
|
// for(let i=0;i<areaCollection[currentFloor].length;i++){
|
|
// let areaItem=areaCollection[currentFloor][i]
|
|
// if(item===areaItem.code){
|
|
// index=i
|
|
|
|
// }
|
|
// }
|
|
// this.selectItem(index);
|
|
// });
|
|
// }
|
|
|
|
},
|
|
},
|
|
|
|
methods: {
|
|
show(opts) {
|
|
this.setData({
|
|
...opts,
|
|
hidden: false,
|
|
});
|
|
return new Promise((reslove) => {
|
|
tempReslove = reslove;
|
|
});
|
|
},
|
|
hide() {
|
|
this.setData({ hidden: true });
|
|
},
|
|
confirm() {
|
|
const { showName, pathCode, selectedItemList } = this.data;
|
|
|
|
tempReslove({
|
|
status: "success",
|
|
data: {
|
|
showName,
|
|
pathCode,
|
|
code:
|
|
selectedItemList[selectedItemList.length - 1]["code"] ||
|
|
selectedItemList[selectedItemList.length - 2]["code"],
|
|
selectedItemList,
|
|
},
|
|
});
|
|
this.hide();
|
|
},
|
|
cancel() {
|
|
tempReslove({ status: "cancel", data: null });
|
|
this.hide();
|
|
},
|
|
handleTapFloor(e) {
|
|
console.log(e);
|
|
const {
|
|
currentTarget: {
|
|
dataset: { id },
|
|
},
|
|
} = e;
|
|
this.selectFloor(id);
|
|
},
|
|
selectFloor(id) {
|
|
this.setData({
|
|
currentFloor: id,
|
|
});
|
|
},
|
|
handleTapItem(e) {
|
|
console.log(e);
|
|
const {
|
|
currentTarget: {
|
|
dataset: { id },
|
|
},
|
|
} = e;
|
|
this.selectItem(id);
|
|
},
|
|
async selectItem(id) {
|
|
let { currentFloor, currentIndexList, areaCollection, maxFloor } =
|
|
this.data;
|
|
currentIndexList[currentFloor] = id;
|
|
|
|
this.setData({
|
|
currentIndexList: currentIndexList.map((item, index) => {
|
|
if (index > currentFloor) {
|
|
return -1;
|
|
} else {
|
|
return item;
|
|
}
|
|
}),
|
|
areaCollection: areaCollection.map((item, index) => {
|
|
if (index > currentFloor) {
|
|
return [];
|
|
} else {
|
|
return item;
|
|
}
|
|
}),
|
|
});
|
|
this.computeSelectedItem();
|
|
if (currentFloor + 1 >= maxFloor) {
|
|
return this.confirm();
|
|
} else {
|
|
this.setData({
|
|
currentFloor: currentFloor + 1,
|
|
});
|
|
await this.getAreaList();
|
|
}
|
|
},
|
|
computeSelectedItem() {
|
|
const { currentIndexList, areaCollection, maxFloor } = this.data;
|
|
let selectedItemList = [];
|
|
currentIndexList.forEach((id, index) => {
|
|
if (id != -1) {
|
|
selectedItemList[index] = areaCollection[index][id];
|
|
}
|
|
});
|
|
if (selectedItemList.length < maxFloor) {
|
|
selectedItemList.push({ name: "请选择", code: "", level: "" });
|
|
}
|
|
this.setData({
|
|
selectedItemList,
|
|
showName: selectedItemList
|
|
.filter((item) => item.code !== "")
|
|
.map((item) => item.name)
|
|
.join("-"),
|
|
pathCode: selectedItemList
|
|
.filter((item) => item.code !== "")
|
|
.map((item) => item.code)
|
|
.join(","),
|
|
});
|
|
},
|
|
|
|
async getAreaList() {
|
|
let { currentFloor, selectedItemList, areaCollection } = this.data;
|
|
|
|
const item =
|
|
selectedItemList.length > 1
|
|
? selectedItemList[selectedItemList.length - 2]
|
|
: selectedItemList[selectedItemList.length - 1];
|
|
|
|
const {
|
|
data: {
|
|
data: { code, data },
|
|
},
|
|
msg,
|
|
} = await wxRequestPost(
|
|
"commonservice/areacode/nextarea",
|
|
{
|
|
parentAreaCode: item.code || "",
|
|
parentLevel: item.level || "",
|
|
},
|
|
{
|
|
isMock: false,
|
|
}
|
|
);
|
|
if (msg == "success" && code == 0) {
|
|
areaCollection[currentFloor] = data.map((item) => {
|
|
return {
|
|
name: item.areaName,
|
|
code: item.areaCode,
|
|
level: item.level,
|
|
};
|
|
});
|
|
// areaCollection[currentFloor] = [
|
|
// { name: "北京", code: 0 },
|
|
// { name: "山山东山东山东山东山东东", code: 1 },
|
|
// { name: "山东", code: 1 },
|
|
// { name: "山东山东", code: 1 },
|
|
// { name: "山东", code: 1 },
|
|
// { name: "山东", code: 1 },
|
|
// { name: "山东", code: 1 },
|
|
// { name: "山东", code: 1 },
|
|
// ];
|
|
this.setData({
|
|
areaCollection,
|
|
});
|
|
}
|
|
},
|
|
},
|
|
});
|
|
|