html代码
<v`<van-dropdown-menu class="van-hairline--bottom">
<van-dropdown-item value="{{ value1 }}" options="{{ third_cat_option }}" bind:change="changeThirdCat"/>
<van-dropdown-item value="{{ value2 }}" options="{{ option2 }}" bind:change="changeSort"/>
</van-dropdown-menu>`
js代码
var is_loading_more = !1, is_no_more = !1;
Page({
data: {
cat_id: "",
page: 1,
cat_list: [],
goods_list: [],
sort: 0,
sort_type: -1,
quick_icon: !0,
selectid: "",
showthirdcat: !1,//显示某一项的对勾
showallicon: !0,//全选的对勾
third_cat_option: [],
option2: [
{ text: '默认排序', value: 0 },
{ text: '时间排序', value: 1 },
{ text: '价格排序', value: 2 },
{ text: '销量排序', value: 3 }
],
value1: 0,
value2: 0
},
showthirdcatlist: function (t) {
this.setData({
selectid: "",
showthirdcat: !0,
});
},
all: function (t) {
this.setData({
showallicon: !0,
showthirdcat: !1,
cat_id: this.data.cat_id,
});
},
thirdcatitem: function (t) {
var myid = t.currentTarget.dataset.id
this.setData({
selectid: myid,
cat_id: myid,
showthirdcat: !1,
showallicon: !1
});
},
changeThirdCat(e) {
console.log(e)
let cat_id = e.detail;
console.log(this.data.value1);
if (cat_id > 0) {
this.setData({
value1: cat_id
})
this.reloadGoodsList()
}
},
changeSort(e) {
let sort = e.detail
this.setData({
sort: sort
})
this.reloadGoodsList()
},
onLoad: function (t) {
getApp().page.onLoad(this, t), this.loadData(t);
},
loadData: function (t) {
var a = getApp().core.getStorageSync(getApp().const.CAT_LIST), e = "";
if (t.cat_id) for (var i in a) {
var o = !1;
for (var s in a[i].id == t.cat_id && (a[i].checked = !0, 0 < a[i].list.length && (e = "height-bar")),
a[i].list) a[i].list[s].id == t.cat_id && (o = a[i].list[s].checked = !0, e = "height-bar");
o && (a[i].checked = !0);
}
if (t.goods_id) var r = t.goods_id;
this.setData({
value1: t.cat_id || "",
third_cat_option: [{ text: '全部分类', value: t.cat_id || "" }],
cat_list: a,
cat_id: t.cat_id || "",
height_bar: e,
goods_id: r || ""
}), this.reloadGoodsList();
},
catClick: function (t) {
console.log(t)
var a = this, e = "", i = t.currentTarget.dataset.index, o = a.data.cat_list;
for (var s in o) {
for (var r in o[s].list) o[s].list[r].checked = !1;
s == i ? (o[s].checked = !0, e = o[s].id) : o[s].checked = !1;
}
var d = "";
0 < o[i].list.length && (d = "height-bar"), a.setData({
cat_list: o,
cat_id: e,
height_bar: d
}), a.reloadGoodsList();
},
quickNavigation: function () {
this.setData({
quick_icon: !this.data.quick_icon
});
this.data.store;
var t = getApp().core.createAnimation({
duration: 300,
timingFunction: "ease-out"
});
this.data.quick_icon ? t.opacity(0).step() : t.translateY(-55).opacity(1).step(),
this.setData({
animationPlus: t.export()
});
},
subCatClick: function (t) {
var a = this, e = "", i = t.currentTarget.dataset.index, o = t.currentTarget.dataset.parentIndex, s = a.data.cat_list;
for (var r in s) for (var d in s[r].list) r == o && d == i ? (s[r].list[d].checked = !0,
e = s[r].list[d].id) : s[r].list[d].checked = !1;
a.setData({
cat_list: s,
cat_id: e
}), a.reloadGoodsList();
},
allClick: function () {
var t = this, a = t.data.cat_list;
for (var e in a) {
for (var i in a[e].list) a[e].list[i].checked = !1;
a[e].checked = !1;
}
t.setData({
cat_list: a,
cat_id: "",
height_bar: ""
}), t.reloadGoodsList();
},
reloadGoodsList: function () {
var a = this;
is_no_more = !1, a.setData({
page: 1,
goods_list: [],
show_no_data_tip: !1
});
var t = a.data.cat_id || "", e = a.data.page || 1;
getApp().request({
url: getApp().api.default.goods_list,
data: {
cat_id: a.data.value1,
page: e,
parent_id: t,
sort: a.data.sort,
sort_type: a.data.sort_type,
goods_id: a.data.goods_id,
},
success: function (t) {
0 == t.code && (0 == t.data.list.length && (is_no_more = !0), a.setData({
page: e + 1
}), a.setData({
goods_list: t.data.list
})), a.setData({
show_no_data_tip: 0 == a.data.goods_list.length
});
let third_cat_option = [{ text: '全部分类', value: a.data.cat_id }]
console.log(third_cat_option)
if (t.data.third_cat.length > 0) {
t.data.third_cat.map(function (item, index) {
third_cat_option.push({ text: item.name, value: item.id })
})
}
a.setData({
third_cat_option: third_cat_option
});
},
complete: function () { }
});
},
loadMoreGoodsList: function () {
var e = this;
if (!is_loading_more) {
e.setData({
show_loading_bar: !0
}), is_loading_more = !0;
var t = e.data.cat_id || "", i = e.data.page || 2, a = e.data.goods_id;
getApp().request({
url: getApp().api.default.goods_list,
data: {
page: i,
cat_id: t,
sort: e.data.sort,
sort_type: e.data.sort_type,
goods_id: a
},
success: function (t) {
0 == t.data.list.length && (is_no_more = !0);
var a = e.data.goods_list.concat(t.data.list);
e.setData({
goods_list: a,
page: i + 1
});
},
complete: function () {
is_loading_more = !1, e.setData({
show_loading_bar: !1
});
}
});
}
},
onReachBottom: function () {
getApp().page.onReachBottom(this), is_no_more || this.loadMoreGoodsList();
},
onShow: function (t) {
getApp().page.onShow(this);
var a = this;
if (getApp().core.getStorageSync(getApp().const.LIST_PAGE_RELOAD)) {
var e = getApp().core.getStorageSync(getApp().const.LIST_PAGE_OPTIONS);
getApp().core.removeStorageSync(getApp().const.LIST_PAGE_OPTIONS), getApp().core.removeStorageSync(getApp().const.LIST_PAGE_RELOAD);
var i = e.cat_id || "";
a.setData({
cat_id: i
});
var o = a.data.cat_list;
for (var s in o) {
var r = !1;
for (var d in o[s].list) o[s].list[d].id == i ? r = o[s].list[d].checked = !0 : o[s].list[d].checked = !1;
r || i == o[s].id ? (o[s].checked = !0, o[s].list && 0 < o[s].list.length && a.setData({
height_bar: "height-bar"
})) : o[s].checked = !1;
}
a.setData({
cat_list: o
}), a.reloadGoodsList();
}
},
sortClick: function (t) {
var a = this, e = t.currentTarget.dataset.sort, i = null == t.currentTarget.dataset.default_sort_type ? -1 : t.currentTarget.dataset.default_sort_type, o = a.data.sort_type;
if (a.data.sort == e) {
if (-1 == i) return;
o = -1 == a.data.sort_type ? i : 0 == o ? 1 : 0;
} else o = i;
a.setData({
sort: e,
sort_type: o
}), a.reloadGoodsList();
},
onShareAppMessage: function (t) {
return getApp().page.onShareAppMessage(this), {
path: "/pages/list/list?user_id=" + getApp().getUser().id + "&cat_id=" + this.data.cat_id,
success: function (t) { }
};
}
});