Commit 536a08da by 姜雷

区域筛选添加截流函数

parent e872a6b4
import { baseFetch } from '../../api/fetch';
import { delay } from '../../utils/util';
// miniprogram/pages/areaSelect/areaSelect.js
Page({
......@@ -43,7 +44,7 @@ Page({
let index = res.data.findIndex(
item => item.id == this.data.selected,
);
console.log(this.data.selected,index)
console.log(this.data.selected, index);
if (index > -1) {
this.setData({
selectedIndex: index,
......@@ -64,10 +65,20 @@ Page({
inputHandle(e) {
const { value } = e.detail;
console.log(e, value);
delay(() => {
this.getFilterListByName(value);
}, 500);
},
confirmHandle(e) {
const { value } = e.detail;
console.log(e, value);
this.getFilterListByName(value);
},
getFilterListByName(name: string) {
let filterList = [];
if (value) {
if (name) {
filterList = this.data.areaList.filter(item =>
item['areaName'].includes(value),
item['areaName'].includes(name),
);
} else {
filterList = this.data.areaList;
......
<!-- miniprogram/pages/areaSelect/areaSelect.wxml -->
<view class="areaselect-pickBox">
<view class="areaselect-pickFilter">
<input class="areaselect-pickInput" type="text" bindconfirm="inputHandle" />
<input class="areaselect-pickInput" type="text" bindinput="inputHandle" bindconfirm="confirmHandle" />
<view class="areaselect-pickBtn" bindtap="bindPickerChange">确认</view>
</view>
<view class="areaselect-list">
......
import { delay } from "../../../utils/util";
// pages/components/AreaSelect/AreaSelect.js
Component({
properties: {
......@@ -70,15 +72,24 @@ Component({
inputHandle(e) {
const { value } = e.detail;
console.log(e, value);
delay(() => {
this.getFilterListByName(value);
}, 500);
},
confirmHandle(e) {
const { value } = e.detail;
console.log(e, value);
this.getFilterListByName(value);
},
getFilterListByName(name: string) {
let filterList = [];
if (value) {
if (name) {
filterList = this.data.range.filter(item =>
item[this.data.rangeKey].includes(value),
item[this.data.rangeKey].includes(name),
);
} else {
filterList = this.data.range;
}
this.setData({
filterList,
});
......
......@@ -12,7 +12,7 @@
<view class="areaselect-pickView {{showPickerView?'show':''}}" bindtap="maskClickHandle">
<view class="areaselect-pickBox {{showPickerView?'show':''}}" catchtap="innerClickHandle">
<view wx:if="{{showPickerView}}" class="areaselect-pickFilter">
<input class="areaselect-pickInput" type="text" bindconfirm="inputHandle" />
<input class="areaselect-pickInput" type="text" bindinput="inputHandle" bindconfirm="confirmHandle" />
<view class="areaselect-pickBtn" bindtap="bindPickerChange">确认</view>
</view>
<view class="areaselect-list">
......
......@@ -33,4 +33,11 @@ var joinComma = function (num) {
}
return result.join('');
};
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidXRpbC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInV0aWwudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7QUFBQSxvQkFBMkIsSUFBVTtJQUNuQyxJQUFNLElBQUksR0FBRyxJQUFJLENBQUMsV0FBVyxFQUFFLENBQUM7SUFDaEMsSUFBTSxLQUFLLEdBQUcsSUFBSSxDQUFDLFFBQVEsRUFBRSxHQUFHLENBQUMsQ0FBQztJQUNsQyxJQUFNLEdBQUcsR0FBRyxJQUFJLENBQUMsT0FBTyxFQUFFLENBQUM7SUFDM0IsSUFBTSxJQUFJLEdBQUcsSUFBSSxDQUFDLFFBQVEsRUFBRSxDQUFDO0lBQzdCLElBQU0sTUFBTSxHQUFHLElBQUksQ0FBQyxVQUFVLEVBQUUsQ0FBQztJQUNqQyxJQUFNLE1BQU0sR0FBRyxJQUFJLENBQUMsVUFBVSxFQUFFLENBQUM7SUFFakMsTUFBTSxDQUFDLENBQ0wsQ0FBQyxJQUFJLEVBQUUsS0FBSyxFQUFFLEdBQUcsQ0FBQyxDQUFDLEdBQUcsQ0FBQyxZQUFZLENBQUMsQ0FBQyxJQUFJLENBQUMsR0FBRyxDQUFDO1FBQzlDLEdBQUc7UUFDSCxDQUFDLElBQUksRUFBRSxNQUFNLEVBQUUsTUFBTSxDQUFDLENBQUMsR0FBRyxDQUFDLFlBQVksQ0FBQyxDQUFDLElBQUksQ0FBQyxHQUFHLENBQUMsQ0FDbkQsQ0FBQztBQUNKLENBQUM7QUF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GpvaW5Db21tYShzdHJBcnJbMF0pICsgJy4nICsgc3RyQXJyWzFdO1xufTtcblxuY29uc3Qgam9pbkNvbW1hID0gKG51bTogc3RyaW5nKSA9PiB7XG4gIHZhciByZXN1bHQgPSBbXSxcbiAgICBjb3VudGVyID0gMDtcbiAgZm9yIChsZXQgaW5kZXggPSBudW0ubGVuZ3RoIC0gMTsgaW5kZXggPj0gMDsgaW5kZXgtLSkge1xuICAgIGNvdW50ZXIrKztcbiAgICBjb25zdCBlbGVtZW50ID0gbnVtW2luZGV4XTtcbiAgICByZXN1bHQudW5zaGlmdChlbGVtZW50KTtcbiAgICBpZiAoIShjb3VudGVyICUgMykgJiYgaW5kZXggIT0gMCkge1xuICAgICAgcmVzdWx0LnVuc2hpZnQoJywnKTtcbiAgICB9XG4gIH1cbiAgcmV0dXJuIHJlc3VsdC5qb2luKCcnKTtcbn07XG4iXX0=
\ No newline at end of file
exports.delay = (function () {
var timer = 0;
return function (callback, ms) {
clearTimeout(timer);
timer = setTimeout(callback, ms);
};
})();
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidXRpbC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInV0aWwudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7QUFBQSxvQkFBMkIsSUFBVTtJQUNuQyxJQUFNLElBQUksR0FBRyxJQUFJLENBQUMsV0FBVyxFQUFFLENBQUM7SUFDaEMsSUFBTSxLQUFLLEdBQUcsSUFBSSxDQUFDLFFBQVEsRUFBRSxHQUFHLENBQUMsQ0FBQztJQUNsQyxJQUFNLEdBQUcsR0FBRyxJQUFJLENBQUMsT0FBTyxFQUFFLENBQUM7SUFDM0IsSUFBTSxJQUFJLEdBQUcsSUFBSSxDQUFDLFFBQVEsRUFBRSxDQUFDO0lBQzdCLElBQU0sTUFBTSxHQUFHLElBQUksQ0FBQyxVQUFVLEVBQUUsQ0FBQztJQUNqQyxJQUFNLE1B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gICAgICByZXN1bHQudW5zaGlmdCgnLCcpO1xuICAgIH1cbiAgfVxuICByZXR1cm4gcmVzdWx0LmpvaW4oJycpO1xufTtcbmV4cG9ydCBjb25zdCBkZWxheSA9IChmdW5jdGlvbigpIHtcbiAgbGV0IHRpbWVyID0gMDtcbiAgcmV0dXJuIGZ1bmN0aW9uKGNhbGxiYWNrOiAoKSA9PiB2b2lkLCBtczogbnVtYmVyKSB7XG4gICAgY2xlYXJUaW1lb3V0KHRpbWVyKTtcbiAgICB0aW1lciA9IHNldFRpbWVvdXQoY2FsbGJhY2ssIG1zKTtcbiAgfTtcbn0pKCk7XG4iXX0=
\ No newline at end of file
......@@ -37,3 +37,10 @@ const joinComma = (num: string) => {
}
return result.join('');
};
export const delay = (function() {
let timer = 0;
return function(callback: () => void, ms: number) {
clearTimeout(timer);
timer = setTimeout(callback, ms);
};
})();
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment