168 lines
3.2 KiB
JavaScript
168 lines
3.2 KiB
JavaScript
// components/brandSelect/index.js
|
|
import _ from '../../commons/js/commons'
|
|
const app = getApp()
|
|
let debouncetimer = null; //函数防抖-间隔时间
|
|
Component({
|
|
|
|
/**
|
|
* 组件的属性列表
|
|
*/
|
|
properties: {
|
|
show: {
|
|
type: Boolean,
|
|
value: false
|
|
},
|
|
duration: {
|
|
type: Number,
|
|
value: 500
|
|
},
|
|
position: {
|
|
type: String,
|
|
value: 'right'
|
|
},
|
|
round: {
|
|
type: Boolean,
|
|
value: false
|
|
},
|
|
overlay: {
|
|
type: Boolean,
|
|
value: true
|
|
},
|
|
customStyle: {
|
|
type: String,
|
|
value: ''
|
|
},
|
|
overlayStyle: {
|
|
type: String,
|
|
value: 'background-color: rgba(0, 0, 0, 0.7)'
|
|
},
|
|
},
|
|
attached(){
|
|
debouncetimer = null
|
|
},
|
|
observers: {
|
|
'show': function (value) {
|
|
// 在 numberA 或者 numberB 被设置时,执行这个函数
|
|
this.setData({
|
|
show_page: value,
|
|
cur: -1,
|
|
item: {}
|
|
})
|
|
}
|
|
},
|
|
|
|
/**
|
|
* 组件的初始数据
|
|
*/
|
|
data: {
|
|
show_page: false,
|
|
list: [],
|
|
// list: [{
|
|
// id: 1,
|
|
// name: '宝马'
|
|
// },{
|
|
// id: 1,
|
|
// name: '宝马'
|
|
// },{
|
|
// id: 1,
|
|
// name: '宝马'
|
|
// },{
|
|
// id: 1,
|
|
// name: '宝马'
|
|
// },{
|
|
// id: 1,
|
|
// name: '宝马'
|
|
// },{
|
|
// id: 1,
|
|
// name: '宝马'
|
|
// }],
|
|
cur: -1,
|
|
keyword: '',
|
|
item: {}
|
|
},
|
|
|
|
/**
|
|
* 组件的方法列表
|
|
*/
|
|
methods: {
|
|
onBeforeEnter(res) {
|
|
// console.log(res)
|
|
},
|
|
onEnter(res) {
|
|
// console.log(res)
|
|
this.triggerEvent('enter')
|
|
},
|
|
onAfterEnter(res) {
|
|
// console.log(res)
|
|
},
|
|
onBeforeLeave(res) {
|
|
// console.log(res)
|
|
},
|
|
onLeave(res) {
|
|
console.log(this.data.item)
|
|
this.triggerEvent('leave', {index: this.data.cur,item: this.data.list[this.data.cur]})
|
|
},
|
|
onAfterLeave(res) {
|
|
// console.log(res)
|
|
},
|
|
|
|
onClickOverlay(res) {
|
|
// console.log(res)
|
|
},
|
|
exit() {
|
|
this.setData({ show_page: false })
|
|
},
|
|
cancel() {
|
|
this.setData({ show_page: false, cur: -1,item: {} })
|
|
},
|
|
bindInputKeyword(e){
|
|
let that = this
|
|
that.debounce(function(){
|
|
that.setData({
|
|
keyword: e.detail.value,
|
|
cur: -1,
|
|
item: {}
|
|
})
|
|
if(e.detail.value){
|
|
that.apiGetMbrand(e.detail.value)
|
|
}
|
|
},500)
|
|
},
|
|
bindSelectIndex(e){
|
|
console.log(e)
|
|
this.setData({
|
|
cur: e.currentTarget.dataset.index
|
|
})
|
|
|
|
},
|
|
/**
|
|
* 函数防抖
|
|
* @param {*} fn
|
|
* @param {*} wait
|
|
* @returns
|
|
*/
|
|
debounce(fn, wait) {
|
|
var gapTime = wait || 200; //间隔时间,如果interval不传,则默认200ms
|
|
return (function () {
|
|
var context = this
|
|
var args = arguments
|
|
if (debouncetimer) {
|
|
clearTimeout(debouncetimer);
|
|
debouncetimer = null;
|
|
}
|
|
debouncetimer = setTimeout(function () {
|
|
fn.apply(context, args) //保持this和参数
|
|
}, gapTime)
|
|
})()
|
|
},
|
|
|
|
//app/series/mbrand
|
|
apiGetMbrand(keyword){
|
|
_.apiQuery.getMbrand({keyword}).then(res => {
|
|
this.setData({
|
|
list: res.data.list
|
|
})
|
|
})
|
|
}
|
|
}
|
|
}) |