117 lines
2.6 KiB
JavaScript
117 lines
2.6 KiB
JavaScript
import { getParkList } from "../../service/park"
|
|
import { getParkSimpleMeterList } from "../../service/meter"
|
|
import { alertInfo } from "../../utils/index";
|
|
import request from "../../utils/request"
|
|
import { payWays } from "../../utils/data";
|
|
|
|
const { OK } = request;
|
|
|
|
// components/searchSelect/index.js
|
|
Component({
|
|
|
|
/**
|
|
* 组件的属性列表
|
|
*/
|
|
properties: {
|
|
title: String,
|
|
type: String,
|
|
show: Boolean,
|
|
park: String,
|
|
},
|
|
observers: {
|
|
"show,type": function(newShow, newType) {
|
|
if (newShow && newType) {
|
|
this.onSearch()
|
|
}
|
|
}
|
|
},
|
|
/**
|
|
* 组件的初始数据
|
|
*/
|
|
data: {
|
|
columns: [],
|
|
searchText: "",
|
|
payWays,
|
|
},
|
|
lifetimes: {
|
|
attached() {
|
|
|
|
}
|
|
},
|
|
|
|
/**
|
|
* 组件的方法列表
|
|
*/
|
|
methods: {
|
|
onChangeSearch(e) {
|
|
this.setData({
|
|
searchText: e.detail,
|
|
})
|
|
},
|
|
onCancel() {
|
|
this.setData({
|
|
columns: [],
|
|
list: [],
|
|
searchText: ""
|
|
})
|
|
this.triggerEvent("cancel")
|
|
},
|
|
onConfirm(event) {
|
|
const { index } = event.detail;
|
|
const { list = [], type } = this.data;
|
|
const item = list[index];
|
|
this.setData({
|
|
columns: [],
|
|
list: [],
|
|
searchText: ""
|
|
})
|
|
this.triggerEvent("confirm", { data: item, type } );
|
|
},
|
|
onPayConfirm(event) {
|
|
const { index } = event.detail;
|
|
const { payWays = [], type } = this.data;
|
|
const item = payWays[index];
|
|
this.setData({
|
|
columns: [],
|
|
list: [],
|
|
searchText: ""
|
|
})
|
|
this.triggerEvent("confirm", { data: item, way: index, type } );
|
|
},
|
|
onSearch() {
|
|
const { type } = this.data;
|
|
switch(type) {
|
|
case "park":
|
|
this.onSearchPark();
|
|
return;
|
|
case "meter":
|
|
this.onSearchMeter();
|
|
return;
|
|
}
|
|
},
|
|
async onSearchPark() {
|
|
const { searchText = "" } = this.data;
|
|
const { code, message, data: parks = [] } = await getParkList({keyword: searchText});
|
|
if (code !== OK) {
|
|
alertInfo(message)
|
|
return
|
|
}
|
|
this.setData({
|
|
columns: parks?.map(item => item?.name),
|
|
list: parks,
|
|
})
|
|
},
|
|
async onSearchMeter() {
|
|
const { searchText = "", park } = this.data;
|
|
const { code, message, data: parks = [] } = await getParkSimpleMeterList({keyword: searchText, park});
|
|
if (code !== OK) {
|
|
alertInfo(message)
|
|
return
|
|
}
|
|
this.setData({
|
|
columns: parks?.map(item => `${item.meterNo}-${item.address}${item.tenement?.name ? '-' + item.tenement?.name : ''}`),
|
|
list: parks,
|
|
})
|
|
}
|
|
}
|
|
}) |